-
- for mixin in entity.mixins:
- if mixin.related[0].term == 'os_tpl':
- image = mixin
- image_id = mixin.attributes['occi.core.id']
- if mixin.related[0].term == 'resource_tpl':
- flavor = mixin
- flavor_id = mixin.attributes['occi.core.id']
-
- entity.attributes['occi.compute.state'] = 'inactive'
- entity.actions = [START]
-
- conf = Config()
- conf.set('token',extras['token'])
- snf = ComputeClient(conf)
-
- vm_name = entity.attributes['occi.core.title']
- info = snf.create_server(vm_name, flavor_id, image_id)
- entity.attributes['occi.core.id'] = str(info['id'])
- entity.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch']
- entity.attributes['occi.compute.cores'] = flavor.attributes['occi.compute.cores']
- entity.attributes['occi.compute.memory'] = flavor.attributes['occi.compute.memory']
- entity.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':info['id']}
+
+ try:
+
+ snf = extras['snf']
+
+ for mixin in entity.mixins:
+ if mixin.related[0].term == 'os_tpl':
+ image_id = mixin.attributes['occi.core.id']
+ if mixin.related[0].term == 'resource_tpl':
+ flavor = mixin
+ flavor_id = mixin.attributes['occi.core.id']
+
+ vm_name = entity.attributes['occi.core.title']
+ info = snf.create_server(vm_name, flavor_id, image_id)
+
+ entity.actions = [START]
+ entity.attributes['occi.compute.state'] = 'inactive'
+ entity.attributes['occi.core.id'] = str(info['id'])
+ entity.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch']
+ entity.attributes['occi.compute.cores'] = flavor.attributes['occi.compute.cores']
+ entity.attributes['occi.compute.memory'] = flavor.attributes['occi.compute.memory']
+ entity.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':info['id']}
+
+ except (UnboundLocalError, KeyError) as e:
+ raise HTTPError(406, 'Missing details about compute instance')
+