Revision 2bd4ca03 snfOCCI/APIserver.py

b/snfOCCI/APIserver.py
57 57
        resources = self.registry.resources
58 58
        occi_keys = resources.keys()
59 59
        
60
        #Compute instances in synnefo not available in registry
60 61
        diff = [x for x in snf_keys if '/compute/'+x not in occi_keys]
61 62
        for key in diff:
62 63

  
63 64
            details = snf.get_server_details(int(key))
64 65
            flavor = snf.get_flavor_details(details['flavorRef'])
66
            image = snf.get_image_details(details['imageRef'])
65 67

  
66
            resource = Resource(key, COMPUTE, [])
68
            for i in self.registry.backends:
69
                if i.term == str(image['name']):
70
                    rel_image = i
71
                if i.term == str(flavor['name']):
72
                    rel_flavor = i
73

  
74
            resource = Resource(key, COMPUTE, [rel_flavor, rel_image])
67 75
            resource.actions = [START]
68 76
            resource.attributes['occi.core.id'] = key
69 77
            resource.attributes['occi.compute.state'] = 'inactive'
......
71 79
            resource.attributes['occi.compute.cores'] = flavor['cpu']
72 80
            resource.attributes['occi.compute.memory'] = flavor['ram']
73 81
            resource.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':int(key)}
74
  
75 82
            self.registry.add_resource(key, resource, None)
76 83

  
84
        #Compute instances in registry not available in synnefo
77 85
        diff = [x for x in occi_keys if x[9:] not in snf_keys]
78 86
        for key in diff:
79 87
            self.registry.delete_resource(key, None)
......
87 95
        cyclClient = CycladesClient(conf)
88 96

  
89 97
        #Up-to-date flavors and images
90
        self.refresh_compute_instances(compClient)
91 98
        self.refresh_images(compClient, cyclClient)
92 99
        self.refresh_flavors(compClient, cyclClient)
100
        self.refresh_compute_instances(compClient)
101

  
93 102

  
94 103
        # token will be represented in self.extras
95 104
        return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'], snf = compClient, client = cyclClient)

Also available in: Unified diff