8
from neutronclient.v2_0 import client as ne_client
9
from novaclient import client as no_client
10
from keystoneclient.v2_0 import client as ks_client
11
from keystoneclient.auth import identity
12
from keystoneclient import session
14
if __name__ == '__main__':
15
# use session based authentication
16
ep = os.environ['OS_AUTH_URL']
17
if not ep.endswith('v2.0'):
18
ep = "{}/v2.0".format(ep)
19
auth = identity.v2.Password(username=os.environ['OS_USERNAME'],
20
password=os.environ['OS_PASSWORD'],
21
tenant_name=os.environ['OS_TENANT_NAME'],
23
sess = session.Session(auth=auth)
24
keystone = ks_client.Client(session=sess)
25
keystone.auth_ref = auth.get_access(sess)
27
neutron_ep = keystone.service_catalog.url_for(
28
service_type='network', endpoint_type='publicURL')
29
neutron = ne_client.Client(session=sess)
30
# neutron = ne_client.Client(username=os.environ['OS_USERNAME'],
31
# password=os.environ['OS_PASSWORD'],
32
# tenant_name=os.environ['OS_TENANT_NAME'],
33
# auth_url=os.environ['OS_AUTH_URL'],
34
# region_name=os.environ['OS_REGION_NAME'])
35
nova_ep = keystone.service_catalog.url_for(
36
service_type='compute', endpoint_type='publicURL')
37
nova = no_client.Client('2', session=sess)
38
# nova = no_client.Client('2',
39
# os.environ['OS_USERNAME'],
40
# os.environ['OS_PASSWORD'],
41
# os.environ['OS_TENANT_NAME'],
42
# os.environ['OS_AUTH_URL'],
43
# os.environ['OS_REGION_NAME'])
45
net_id = os.environ.get('NET_ID')
47
# Use OSCI / Jenkins environment variable if defined.
48
print('Using NET_ID environment variable: {}'.format(net_id))
50
# Preserve existing default behavior (eg. manual testing)
51
net_name = os.environ['OS_USERNAME'] + '_admin_net'
52
print('Using default network name: {}'.format(net_name))
54
network = neutron.list_networks(name=net_name)['networks'][0]
55
net_id = network['id']
57
print('Unable to find local network {}'.format(net_name))
58
raise ValueError('Unable to find local network {}'.format(net_name))
62
service_config = yaml.load(
63
subprocess.check_output(['juju', 'status', '--format=yaml', service])
67
for machine in service_config['machines']:
68
uuids.append(service_config['machines'][machine]['instance-id'])
71
if len(sys.argv) >= 3:
72
ext_port = [sys.argv[2]]
76
print("Attaching interface to instance {}".format(uuid))
77
server = nova.servers.get(uuid)
78
result = server.interface_attach(port_id=None,
80
fixed_ip=None).to_dict()
81
ext_port.append("br-ex:{}".format(result['mac_addr']))
83
ports = " ".join(ext_port)
85
juju_version = subprocess.check_output(['juju', '--version'])[0]
86
print("juju_version: '{}'".format(juju_version))
87
command = ['set', 'config'][int(juju_version) - 1]
88
print("Setting data-port configuration on {} to {}".format(service, ports))
89
subprocess.check_call(['juju', command, service, 'data-port={}'.format(ports)])
91
print("Nothing to do with ext-port configuration")