Merge lp:~james-page/openstack-charm-testing/ext-port-configuration into lp:openstack-charm-testing

Proposed by James Page
Status: Merged
Merged at revision: 215
Proposed branch: lp:~james-page/openstack-charm-testing/ext-port-configuration
Merge into: lp:openstack-charm-testing
Diff against target: 103 lines (+58/-38)
1 file modified
bin/post-deploy-config (+58/-38)
To merge this branch: bzr merge lp:~james-page/openstack-charm-testing/ext-port-configuration
Reviewer Review Type Date Requested Status
OpenStack Charm Testing Maintainers Pending
Review via email: mp+297035@code.launchpad.net
To post a comment you must log in.
216. By James Page

Drop keystoneclient usage

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/post-deploy-config'
2--- bin/post-deploy-config 2016-05-09 14:04:13 +0000
3+++ bin/post-deploy-config 2016-06-10 09:26:21 +0000
4@@ -5,41 +5,61 @@
5 import os
6 import sys
7
8-cmd_out = subprocess.check_output(['neutron', 'net-list'])
9-
10-net_id = os.environ.get('NET_ID')
11-
12-if net_id:
13- # Use OSCI / Jenkins environment variable if defined.
14- print 'Using NET_ID environment variable: {}'.format(net_id)
15-else:
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'):
20- if net_name in line:
21- net_id = line.split('|')[1].replace(' ', '')
22-
23-service = sys.argv[1]
24-
25-ext_port = 'eth1'
26-if len(sys.argv) >= 3:
27- ext_port = sys.argv[2]
28-
29-service_config = yaml.load(
30- subprocess.check_output(['juju', 'status', service])
31-)
32-
33-uuids = []
34-for machine in service_config['machines']:
35- uuids.append(service_config['machines'][machine]['instance-id'])
36-
37-if len(uuids) > 0:
38- for uuid in uuids:
39- print("Attaching interface to instance {}".format(uuid))
40- subprocess.check_call(
41- ['nova', 'interface-attach', '--net-id', net_id, uuid]
42- )
43-
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)])
46+from neutronclient.v2_0 import client as ne_client
47+from novaclient import client as no_client
48+
49+if __name__ == '__main__':
50+ neutron = ne_client.Client(username=os.environ['OS_USERNAME'],
51+ password=os.environ['OS_PASSWORD'],
52+ tenant_name=os.environ['OS_TENANT_NAME'],
53+ auth_url=os.environ['OS_AUTH_URL'],
54+ region_name=os.environ['OS_REGION_NAME'])
55+ nova = no_client.Client('2',
56+ os.environ['OS_USERNAME'],
57+ os.environ['OS_PASSWORD'],
58+ os.environ['OS_TENANT_NAME'],
59+ os.environ['OS_AUTH_URL'],
60+ os.environ['OS_REGION_NAME'])
61+
62+ net_id = os.environ.get('NET_ID')
63+ if net_id:
64+ # Use OSCI / Jenkins environment variable if defined.
65+ print('Using NET_ID environment variable: {}'.format(net_id))
66+ else:
67+ # Preserve existing default behavior (eg. manual testing)
68+ net_name = os.environ['OS_USERNAME'] + '_admin_net'
69+ print('Using default network name: {}'.format(net_name))
70+ try:
71+ network = neutron.list_networks(name=net_name)['networks'][0]
72+ net_id = network['id']
73+ except IndexError:
74+ print('Unable to find local network {}'.format(net_name))
75+ raise ValueError('Unable to find local network {}'.format(net_name))
76+
77+ service = sys.argv[1]
78+
79+ service_config = yaml.load(
80+ subprocess.check_output(['juju', 'status', service])
81+ )
82+
83+ uuids = []
84+ for machine in service_config['machines']:
85+ uuids.append(service_config['machines'][machine]['instance-id'])
86+
87+ ext_port = []
88+ if len(sys.argv) >= 3:
89+ ext_port = [sys.argv[2]]
90+
91+ if len(uuids) > 0:
92+ for uuid in uuids:
93+ print("Attaching interface to instance {}".format(uuid))
94+ server = nova.servers.get(uuid)
95+ result = server.interface_attach(port_id=None,
96+ net_id=net_id,
97+ fixed_ip=None).to_dict()
98+ ext_port.append(result['mac_addr'])
99+
100+ ports = " ".join(ext_port)
101+ print("Setting ext-port configuration on {} to {}".format(service, ports))
102+ subprocess.check_call(['juju', 'set', service, 'ext-port={}'.format(ports)])
103+

Subscribers

People subscribed via source and target branches

to status/vote changes: