8
cmd_out = subprocess.check_output(['neutron', 'net-list'])
10
net_id = os.environ.get('NET_ID')
13
# Use OSCI / Jenkins environment variable if defined.
14
print 'Using NET_ID environment variable: {}'.format(net_id)
16
# Preserve existing default behavior (eg. manual testing)
17
net_name = os.environ['OS_USERNAME'] + '_admin_net'
18
print('Using default network name: {}'.format(net_name))
19
for line in cmd_out.split('\n'):
21
net_id = line.split('|')[1].replace(' ', '')
26
if len(sys.argv) >= 3:
27
ext_port = sys.argv[2]
29
service_config = yaml.load(
30
subprocess.check_output(['juju', 'status', service])
34
for machine in service_config['machines']:
35
uuids.append(service_config['machines'][machine]['instance-id'])
39
print("Attaching interface to instance {}".format(uuid))
40
subprocess.check_call(
41
['nova', 'interface-attach', '--net-id', net_id, uuid]
44
print("Setting ext-port configuration on neutron-gateway to {}".format(ext_port))
45
subprocess.check_call(['juju', 'set', service, 'ext-port={}'.format(ext_port)])
8
from neutronclient.v2_0 import client as ne_client
9
from novaclient import client as no_client
11
if __name__ == '__main__':
12
neutron = ne_client.Client(username=os.environ['OS_USERNAME'],
13
password=os.environ['OS_PASSWORD'],
14
tenant_name=os.environ['OS_TENANT_NAME'],
15
auth_url=os.environ['OS_AUTH_URL'],
16
region_name=os.environ['OS_REGION_NAME'])
17
nova = no_client.Client('2',
18
os.environ['OS_USERNAME'],
19
os.environ['OS_PASSWORD'],
20
os.environ['OS_TENANT_NAME'],
21
os.environ['OS_AUTH_URL'],
22
os.environ['OS_REGION_NAME'])
24
net_id = os.environ.get('NET_ID')
26
# Use OSCI / Jenkins environment variable if defined.
27
print('Using NET_ID environment variable: {}'.format(net_id))
29
# Preserve existing default behavior (eg. manual testing)
30
net_name = os.environ['OS_USERNAME'] + '_admin_net'
31
print('Using default network name: {}'.format(net_name))
33
network = neutron.list_networks(name=net_name)['networks'][0]
34
net_id = network['id']
36
print('Unable to find local network {}'.format(net_name))
37
raise ValueError('Unable to find local network {}'.format(net_name))
41
service_config = yaml.load(
42
subprocess.check_output(['juju', 'status', service])
46
for machine in service_config['machines']:
47
uuids.append(service_config['machines'][machine]['instance-id'])
50
if len(sys.argv) >= 3:
51
ext_port = [sys.argv[2]]
55
print("Attaching interface to instance {}".format(uuid))
56
server = nova.servers.get(uuid)
57
result = server.interface_attach(port_id=None,
59
fixed_ip=None).to_dict()
60
ext_port.append(result['mac_addr'])
62
ports = " ".join(ext_port)
63
print("Setting ext-port configuration on {} to {}".format(service, ports))
64
subprocess.check_call(['juju', 'set', service, 'ext-port={}'.format(ports)])