fix bug in run_instances
[sfa.git] / sfa / openstack / osaggregate.py
index 7eb6e27..241ec0b 100644 (file)
@@ -97,10 +97,11 @@ class OSAggregate:
             #else:
             #    node_xrn = OSXrn('cloud', 'node')
             node_xrn = instance.metadata.get('component_id')
+            node_xrn
             if not node_xrn:
                 node_xrn = OSXrn('cloud', 'node')
             else:
-                node_xrn = OSXrn(node_xrn, 'node') 
+                node_xrn = OSXrn(xrn=node_xrn, 'node') 
 
             rspec_node['component_id'] = node_xrn.urn
             rspec_node['component_name'] = node_xrn.name
@@ -170,7 +171,9 @@ class OSAggregate:
 
 
     def create_instance_key(self, slice_hrn, user):
-        key_name = "%s:%s" (slice_name, Xrn(user['urn']).get_hrn())
+        slice_name = Xrn(slice_hrn).leaf
+        user_name = Xrn(user['urn']).leaf
+        key_name = "%s:%s" % (slice_name, user_name)
         pubkey = user['keys'][0]
         key_found = False
         existing_keys = self.driver.shell.nova_manager.keypairs.findall(name=key_name)
@@ -181,7 +184,7 @@ class OSAggregate:
                 key_found = True
 
         if not key_found:
-            self.driver.shll.nova_manager.keypairs.create(key_name, pubkey)
+            self.driver.shell.nova_manager.keypairs.create(key_name, pubkey)
         return key_name       
         
 
@@ -238,7 +241,8 @@ class OSAggregate:
                 fw_rules = instance.get('fw_rules', [])
                 group_name = self.create_security_group(slicename, fw_rules)
                 metadata['security_groups'] = group_name
-                metadata['component_id'] = node['component_id']
+                if node.get('component_id'):
+                    metadata['component_id'] = node['component_id']
                 try: 
                     self.driver.shell.nova_manager.servers.create(flavor=flavor_id,
                                                             image=image_id,
@@ -257,7 +261,8 @@ class OSAggregate:
         security_group_manager = SecurityGroup(self.driver)
         for instance in instances:
             # deleate this instance's security groups
-            for security_group in instance.metadata.get('security_groups', []):
+            security_group = instance.metadata.get('security_groups', '')
+            if security_group:
                 # dont delete the default security group
                 if security_group != 'default': 
                     security_group_manager.delete_security_group(security_group)