Defer error checking to ansible layer
diff --git a/planetstack/openstack_observer/steps/sync_controller_images.py b/planetstack/openstack_observer/steps/sync_controller_images.py
index 2014a25..17ffe57 100644
--- a/planetstack/openstack_observer/steps/sync_controller_images.py
+++ b/planetstack/openstack_observer/steps/sync_controller_images.py
@@ -32,11 +32,9 @@
'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
}
- res = run_template('sync_controller_images.yaml', image_fields, path='controller_images')
- if (len(res)!=1):
- raise Exception('Could not sync image %s'%controller_image.image.name)
- else:
- image_id = res[0]['id']
- controller_image.glance_image_id = image_id
- controller_image.save()
+ res = run_template('sync_controller_images.yaml', image_fields, path='controller_images', expected_num=1)
+
+ image_id = res[0]['id']
+ controller_image.glance_image_id = image_id
+ controller_image.save()
diff --git a/planetstack/openstack_observer/steps/sync_controller_networks.py b/planetstack/openstack_observer/steps/sync_controller_networks.py
index cb82680..ea888c7 100644
--- a/planetstack/openstack_observer/steps/sync_controller_networks.py
+++ b/planetstack/openstack_observer/steps/sync_controller_networks.py
@@ -35,34 +35,29 @@
def save_controller_network(self, controller_network):
- network_name = controller_network.network.name
- subnet_name = '%s-%d'%(network_name,controller_network.pk)
- cidr = self.alloc_subnet(controller_network.pk)
- slice = controller_network.network.slices.all()[0] # XXX: FIXME!!
+ network_name = controller_network.network.name
+ subnet_name = '%s-%d'%(network_name,controller_network.pk)
+ cidr = self.alloc_subnet(controller_network.pk)
+ slice = controller_network.network.slices.all()[0] # XXX: FIXME!!
- network_fields = {'endpoint':controller_network.controller.auth_url,
- 'admin_user':slice.creator.email, # XXX: FIXME
- 'tenant_name':slice.name, # XXX: FIXME
- 'admin_password':slice.creator.remote_password,
- 'name':network_name,
- 'subnet_name':subnet_name,
- 'ansible_tag':'%s-%s@%s'%(network_name,slice.slicename,controller_network.controller.name),
- 'cidr':cidr
- }
+ network_fields = {'endpoint':controller_network.controller.auth_url,
+ 'admin_user':slice.creator.email, # XXX: FIXME
+ 'tenant_name':slice.name, # XXX: FIXME
+ 'admin_password':slice.creator.remote_password,
+ 'name':network_name,
+ 'subnet_name':subnet_name,
+ 'ansible_tag':'%s-%s@%s'%(network_name,slice.slicename,controller_network.controller.name),
+ 'cidr':cidr
+ }
- res = run_template('sync_controller_networks.yaml', network_fields, path = 'controller_networks')
+ res = run_template('sync_controller_networks.yaml', network_fields, path = 'controller_networks',expected_num=2)
- if (len(res)!=2):
- raise Exception('Could not sync network %s'%controller_network.network.name)
- else:
- network_id = res[0]['id']
- subnet_id = res[1]['id']
- controller_network.net_id = network_id
- controller_network.subnet = cidr
- controller_network.subnet_id = subnet_id
- controller_network.save()
-
- logger.info("sync'ed subnet (%s) for network: %s" % (controller_network.subnet, controller_network.network))
+ network_id = res[0]['id']
+ subnet_id = res[1]['id']
+ controller_network.net_id = network_id
+ controller_network.subnet = cidr
+ controller_network.subnet_id = subnet_id
+ controller_network.save()
def sync_record(self, controller_network):
diff --git a/planetstack/openstack_observer/steps/sync_controller_site_privileges.py b/planetstack/openstack_observer/steps/sync_controller_site_privileges.py
index 99a5987..c87f6d5 100644
--- a/planetstack/openstack_observer/steps/sync_controller_site_privileges.py
+++ b/planetstack/openstack_observer/steps/sync_controller_site_privileges.py
@@ -59,20 +59,15 @@
'tenant':controller_site_privilege.site_privilege.site.login_base}
rendered = template.render(user_fields)
- res = run_template('sync_controller_users.yaml', user_fields,path='controller_site_privileges')
+ expected_length = len(roles) + 1
+ res = run_template('sync_controller_users.yaml', user_fields,path='controller_site_privileges', expected_num=expected_length)
# results is an array in which each element corresponds to an
# "ok" string received per operation. If we get as many oks as
# the number of operations we issued, that means a grand success.
# Otherwise, the number of oks tell us which operation failed.
- expected_length = len(roles) + 1
- if (len(res)==expected_length):
- controller_site_privilege.role_id = res[0]['id']
- controller_site_privilege.save()
- elif (len(res)):
- raise Exception('Could not assign roles for user %s'%user_fields['name'])
- else:
- raise Exception('Could not create or update user %s'%user_fields['name'])
+ controller_site_privilege.role_id = res[0]['id']
+ controller_site_privilege.save()
def delete_record(self, controller_site_privilege):
if controller_site_privilege.role_id:
diff --git a/planetstack/openstack_observer/steps/sync_controller_sites.py b/planetstack/openstack_observer/steps/sync_controller_sites.py
index 71837a3..3aa20d7 100644
--- a/planetstack/openstack_observer/steps/sync_controller_sites.py
+++ b/planetstack/openstack_observer/steps/sync_controller_sites.py
@@ -26,15 +26,10 @@
'tenant_description': controller_site.site.name}
rendered = template.render(tenant_fields)
- res = run_template('sync_controller_sites.yaml', tenant_fields, path='controller_sites')
+ res = run_template('sync_controller_sites.yaml', tenant_fields, path='controller_sites', expected_num=1)
- if (len(res)==1):
- controller_site.tenant_id = res[0]['id']
- controller_site.save()
- elif (len(res)):
- raise Exception('Could not assign roles for user %s'%tenant_fields['tenant'])
- else:
- raise Exception('Could not create or update user %s'%tenant_fields['tenant'])
+ controller_site.tenant_id = res[0]['id']
+ controller_site.save()
def delete_record(self, controller_site):
if controller_site.tenant_id:
diff --git a/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py b/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py
index 94d5d21..5ec434c 100644
--- a/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py
+++ b/planetstack/openstack_observer/steps/sync_controller_slice_privileges.py
@@ -59,20 +59,15 @@
'tenant':controller_slice_privilege.slice_privilege.slice.name}
rendered = template.render(user_fields)
- res = run_template('sync_controller_users.yaml', user_fields,path='controller_slice_privileges')
+ expected_length = len(roles) + 1
+ res = run_template('sync_controller_users.yaml', user_fields, path='controller_slice_privileges', expected_num=expected_length)
# results is an array in which each element corresponds to an
# "ok" string received per operation. If we get as many oks as
# the number of operations we issued, that means a grand success.
# Otherwise, the number of oks tell us which operation failed.
- expected_length = len(roles) + 1
- if (len(res)==expected_length):
- controller_slice_privilege.role_id = res[0]['id']
- controller_slice_privilege.save()
- elif (len(res)):
- raise Exception('Could not assign roles for user %s'%user_fields['name'])
- else:
- raise Exception('Could not create or update user %s'%user_fields['name'])
+ controller_slice_privilege.role_id = res[0]['id']
+ controller_slice_privilege.save()
def delete_record(self, controller_slice_privilege):
if controller_slice_privilege.role_id:
diff --git a/planetstack/openstack_observer/steps/sync_controller_slices.py b/planetstack/openstack_observer/steps/sync_controller_slices.py
index 0f8b6fc..0e37524 100644
--- a/planetstack/openstack_observer/steps/sync_controller_slices.py
+++ b/planetstack/openstack_observer/steps/sync_controller_slices.py
@@ -50,22 +50,19 @@
'ansible_tag':'%s@%s'%(controller_slice.slice.name,controller_slice.controller.name),
'max_instances':max_instances}
- res = run_template('sync_controller_slices.yaml', tenant_fields, path='controller_slices')
expected_num = len(roles)+1
- if (len(res)!=expected_num):
- raise Exception('Could not sync tenants for slice %s'%controller_slice.slice.name)
- else:
- tenant_id = res[0]['id']
- if (not controller_slice.tenant_id):
- try:
- driver = OpenStackDriver().admin_driver(controller=controller_slice.controller)
- driver.shell.nova.quotas.update(tenant_id=controller_slice.tenant_id, instances=int(controller_slice.slice.max_slivers))
- except:
- logger.log_exc('Could not update quota for %s'%controller_slice.slice.name)
- raise Exception('Could not update quota for %s'%controller_slice.slice.name)
+ res = run_template('sync_controller_slices.yaml', tenant_fields, path='controller_slices', expected_num=expected_num)
+ tenant_id = res[0]['id']
+ if (not controller_slice.tenant_id):
+ try:
+ driver = OpenStackDriver().admin_driver(controller=controller_slice.controller)
+ driver.shell.nova.quotas.update(tenant_id=controller_slice.tenant_id, instances=int(controller_slice.slice.max_slivers))
+ except:
+ logger.log_exc('Could not update quota for %s'%controller_slice.slice.name)
+ raise Exception('Could not update quota for %s'%controller_slice.slice.name)
- controller_slice.tenant_id = tenant_id
- controller_slice.save()
+ controller_slice.tenant_id = tenant_id
+ controller_slice.save()
def delete_record(self, controller_slice):
diff --git a/planetstack/openstack_observer/steps/sync_controller_users.py b/planetstack/openstack_observer/steps/sync_controller_users.py
index 0c35047..ca2909c 100644
--- a/planetstack/openstack_observer/steps/sync_controller_users.py
+++ b/planetstack/openstack_observer/steps/sync_controller_users.py
@@ -65,20 +65,12 @@
'tenant':controller_user.user.site.login_base}
rendered = template.render(user_fields)
- res = run_template('sync_controller_users.yaml', user_fields,path='controller_users')
-
- # results is an array in which each element corresponds to an
- # "ok" string received per operation. If we get as many oks as
- # the number of operations we issued, that means a grand success.
- # Otherwise, the number of oks tell us which operation failed.
expected_length = len(roles) + 1
- if (len(res)==expected_length):
- controller_user.kuser_id = res[0]['id']
- controller_user.save()
- elif (len(res)):
- raise Exception('Could not assign roles for user %s'%user_fields['name'])
- else:
- raise Exception('Could not create or update user %s'%user_fields['name'])
+
+ res = run_template('sync_controller_users.yaml', user_fields,path='controller_users', expected_num=expected_length)
+
+ controller_user.kuser_id = res[0]['id']
+ controller_user.save()
def delete_record(self, controller_user):
if controller_user.kuser_id:
diff --git a/planetstack/openstack_observer/steps/sync_slivers.py b/planetstack/openstack_observer/steps/sync_slivers.py
index 8155c10..e31afda 100644
--- a/planetstack/openstack_observer/steps/sync_slivers.py
+++ b/planetstack/openstack_observer/steps/sync_slivers.py
@@ -120,28 +120,35 @@
'key':key_fields,
'user_data':r'%s'%escape(userData)}
- res = run_template('sync_slivers.yaml', tenant_fields,path='slivers')
- if (len(res)!=2):
- raise Exception('Could not sync sliver %s'%sliver.slice.name)
- else:
- sliver_id = res[1]['info']['OS-EXT-SRV-ATTR:instance_name'] # 0 is for the key
- sliver_uuid = res[1]['id'] # 0 is for the key
+ res = run_template('sync_slivers.yaml', tenant_fields,path='slivers', expected_num=2)
+ sliver_id = res[1]['info']['OS-EXT-SRV-ATTR:instance_name'] # 0 is for the key
+ sliver_uuid = res[1]['id'] # 0 is for the key
- try:
- hostname = res[1]['info']['OS-EXT-SRV-ATTR:hypervisor_hostname']
- ip = socket.gethostbyname(hostname)
- sliver.ip = ip
- except:
- pass
+ try:
+ hostname = res[1]['info']['OS-EXT-SRV-ATTR:hypervisor_hostname']
+ ip = socket.gethostbyname(hostname)
+ sliver.ip = ip
+ except:
+ pass
- sliver.instance_id = sliver_id
- sliver.instance_uuid = sliver_uuid
- sliver.instance_name = sliver_name
- sliver.save()
+ sliver.instance_id = sliver_id
+ sliver.instance_uuid = sliver_uuid
+ sliver.instance_name = sliver_name
+ sliver.save()
def delete_record(self, sliver):
- sliver_name = '@'.join([sliver.slice.name,sliver.node.name])
- tenant_fields = {'name':sliver_name,
- 'ansible_tag':sliver_name
- }
- res = run_template('delete_slivers.yaml', tenant_fields, path='slivers')
+ sliver_name = '%s-%d'%(sliver.slice.name,sliver.id)
+ controller = sliver.node.site_deployment.controller
+ tenant_fields = {'endpoint':controller.auth_url,
+ 'admin_user': sliver.creator.email,
+ 'admin_password': sliver.creator.remote_password,
+ 'admin_tenant': sliver.slice.name,
+ 'tenant': sliver.slice.name,
+ 'tenant_description': sliver.slice.description,
+ 'name':sliver_name,
+ 'ansible_tag':sliver_name,
+ 'delete': True}
+
+ res = run_template('sync_slivers.yaml', tenant_fields,path='slivers')
+ if (len(res)!=1):
+ raise Exception('Could not delete sliver %s'%sliver.slice.name)