Patch anwenden
This commit is contained in:
parent
0133ea085b
commit
9fbe0a129c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
openrc.sh
|
36
setup_tunnel.py
Normal file → Executable file
36
setup_tunnel.py
Normal file → Executable file
@ -5,6 +5,7 @@ from ipaddress import ip_address
|
|||||||
from os import environ as env
|
from os import environ as env
|
||||||
from os import system
|
from os import system
|
||||||
from os.path import exists, expanduser
|
from os.path import exists, expanduser
|
||||||
|
from time import sleep
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import novaclient.client
|
import novaclient.client
|
||||||
@ -39,35 +40,54 @@ sess = Session(v3.Password(
|
|||||||
project_id=env['OS_TENANT_ID'],
|
project_id=env['OS_TENANT_ID'],
|
||||||
user_domain_name=env['OS_USER_DOMAIN_NAME']))
|
user_domain_name=env['OS_USER_DOMAIN_NAME']))
|
||||||
|
|
||||||
|
print('Logging in...')
|
||||||
nova: novaclient.v2.client.Client = novaclient.client.Client(
|
nova: novaclient.v2.client.Client = novaclient.client.Client(
|
||||||
"2.1", session=sess, region_name=env['OS_REGION_NAME'])
|
"2.1", session=sess, region_name=env['OS_REGION_NAME'])
|
||||||
|
|
||||||
if not exists(expanduser('~/.ssh/id_ovh')):
|
if not exists(expanduser('~/.ssh/id_ovh')):
|
||||||
system("ssh-keygen -f ~/.ssh/id_ovh")
|
system("ssh-keygen -f ~/.ssh/id_ovh")
|
||||||
|
|
||||||
|
print('Making sure keypair is present...')
|
||||||
keypairs: List[Keypair] = nova.keypairs.list()
|
keypairs: List[Keypair] = nova.keypairs.list()
|
||||||
keyname = 'ovh_' + platform.uname()[1].split('.', 1)[0]
|
keyname = 'ovh_' + platform.uname()[1].split('.', 1)[0]
|
||||||
if keyname not in (k.name for k in keypairs):
|
if keyname not in (k.name for k in keypairs):
|
||||||
with open(expanduser('~/.ssh/id_ovh')) as f:
|
with open(expanduser('~/.ssh/id_ovh')) as f:
|
||||||
|
print('Uploading keypair...')
|
||||||
nova.keypairs.create(keyname, f.read())
|
nova.keypairs.create(keyname, f.read())
|
||||||
|
|
||||||
flavor = nova.flavors.find(name='s1-2')
|
flavor = nova.flavors.find(name='s1-2')
|
||||||
image = nova.glance.find_image('Debian 10')
|
image = nova.glance.find_image('Debian 10')
|
||||||
net = nova.neutron.find_network('Ext-Net')
|
net = nova.neutron.find_network('Ext-Net')
|
||||||
|
|
||||||
|
print('Creating server...')
|
||||||
nova.servers.create(SERVER_NAME, image, flavor,
|
nova.servers.create(SERVER_NAME, image, flavor,
|
||||||
nics=[{'net-id': net.id}], key_name=keyname)
|
nics=[{'net-id': net.id}], key_name=keyname)
|
||||||
sv: Server = nova.servers.find(name=SERVER_NAME)
|
sv: Server = nova.servers.find(name=SERVER_NAME)
|
||||||
ips = []
|
|
||||||
for x in sv.interface_list():
|
|
||||||
for i in x.fixed_ips:
|
|
||||||
ips.append(i['ip_address'])
|
|
||||||
|
|
||||||
|
|
||||||
|
while sv.status != 'ACTIVE':
|
||||||
|
print('Waiting for server to POST...')
|
||||||
|
sleep(5)
|
||||||
|
sv = nova.servers.find(name=SERVER_NAME)
|
||||||
|
pass
|
||||||
|
|
||||||
|
ips = []
|
||||||
|
|
||||||
|
interface = None
|
||||||
|
while not interface:
|
||||||
|
interfaces = sv.interface_list()
|
||||||
|
ext_interface = [k for k in interfaces if k.net_id == net.id]
|
||||||
|
if ext_interface and ext_interface[0].port_state == 'ACTIVE':
|
||||||
|
interface = ext_interface[0]
|
||||||
|
else:
|
||||||
|
sleep(2)
|
||||||
|
|
||||||
|
for i in interface.fixed_ips:
|
||||||
|
ips.append(i['ip_address'])
|
||||||
ip = list(filter(lambda x: ip_address(x).version == 4, ips))[0]
|
ip = list(filter(lambda x: ip_address(x).version == 4, ips))[0]
|
||||||
|
|
||||||
while sv.status != 'ACTIVE' and not try_connect(ip):
|
while not try_connect(ip):
|
||||||
print('Waiting for server to come online...')
|
print('Waiting for SSH service to become available...')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
open_conn(ip)
|
open_conn(ip)
|
||||||
@ -75,7 +95,7 @@ open_conn(ip)
|
|||||||
exit = False
|
exit = False
|
||||||
while not exit:
|
while not exit:
|
||||||
choice = pick(['Reconnect', 'Destroy server and exit', 'Keep server online and exit'],
|
choice = pick(['Reconnect', 'Destroy server and exit', 'Keep server online and exit'],
|
||||||
'The connection has ended. How do you want to proceed?')
|
'The connection has ended. How do you want to proceed?')[0]
|
||||||
if choice == 'Reconnect':
|
if choice == 'Reconnect':
|
||||||
open_conn(ip)
|
open_conn(ip)
|
||||||
elif choice == 'Destroy server and exit':
|
elif choice == 'Destroy server and exit':
|
||||||
|
4
start.sh
Normal file → Executable file
4
start.sh
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
if [ ! -e openrc.sh ]; then
|
if [ ! -e openrc.sh ]; then
|
||||||
echo "'openrc.sh' is missing. Cannot operate without OpenStack environment file."
|
echo "'openrc.sh' is missing. Cannot operate without OpenStack environment file."
|
||||||
fi
|
fi
|
||||||
source openrc.sh
|
source openrc.sh
|
||||||
./setup_tunnel.py
|
./setup_tunnel.py
|
||||||
|
Loading…
Reference in New Issue
Block a user