Revision d7dfc401

b/snfOCCI/compute.py
1
from snfOCCI.config import SERVER_CONFIG
2

  
1 3
from kamaki.clients.compute import ComputeClient
2 4
from kamaki.clients.cyclades import CycladesClient
3 5
from kamaki.config  import Config
......
15 17
    '''
16 18

  
17 19
    def update(self, old, new, extras):
18
        # here you can check what information from new_entity you wanna bring
19
        # into old_entity
20

  
21
        # trigger your hypervisor and push most recent information
22
        print('Updating a resource with id: ' + old.identifier)
23
        for item in new.attributes.keys():
24
            old.attributes[item] = new.attributes[item]
20
        raise AttributeError("This action is currently no applicable.")
25 21

  
26 22
    def replace(self, old, new, extras):
27
        print('Replacing a resource with id: ' + old.identifier)
28
        old.attributes = {}
29
        for item in new.attributes.keys():
30
            old.attributes[item] = new.attributes[item]
31
        old.attributes['occi.compute.state'] = 'inactive'
23
        raise AttributeError("This action is currently no applicable.")
32 24

  
33 25

  
34 26
class ComputeBackend(MyBackend):
......
46 38
                flavor = mixin
47 39
                flavor_id = mixin.attributes['occi.core.id']
48 40
                
49
        entity.attributes['occi.compute.state'] = 'active'
50
        entity.actions = [STOP, SUSPEND, RESTART]
41
        entity.attributes['occi.compute.state'] = 'inactive'
42
        entity.actions = [START]
51 43

  
52 44
        #Registry identifier is the uuid key occi.handler assigns
53 45
        #attribute 'occi.core.id' will be the snf-server id
......
59 51
        vm_name = entity.attributes['occi.compute.hostname']
60 52
        info = snf.create_server(vm_name, flavor_id, image_id)
61 53
        entity.attributes['occi.core.id'] = str(info['id'])
54
        entity.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch']
62 55
        entity.attributes['occi.compute.cores'] = flavor.attributes['occi.compute.cores']
63 56
        entity.attributes['occi.compute.memory'] = flavor.attributes['occi.compute.memory']
57
        entity.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':info['id']}
64 58

  
65 59
    def retrieve(self, entity, extras):
66 60
        
......
127 121

  
128 122

  
129 123
        elif action == SUSPEND:
130
            #TODO VM suspending
131
            print "Suspending VM"
124
            raise AttributeError("This actions is currently no applicable")
b/snfOCCI/config.py
1
SERVER_CONFIG = {
2
    'port': 8888,
3
    'hostname': 'snf-%(id)d.vm.okeanos.grnet.gr',
4
    'compute_arch': 'x86'
5
    }
6

  
7
        
8

  
9
    
b/snfOCCI/snf-occi-server.py
2 2

  
3 3
from snfOCCI.registry import snfRegistry
4 4
from snfOCCI.compute import ComputeBackend
5
from snfOCCI.config import SERVER_CONFIG
5 6

  
6 7
from kamaki.clients.compute import ComputeClient
7 8
from kamaki.clients.cyclades import CycladesClient
......
36 37
if __name__ == '__main__':
37 38

  
38 39
    APP = MyAPP(registry = snfRegistry())
39

  
40 40
    COMPUTE_BACKEND = ComputeBackend()
41 41

  
42 42
    APP.register_backend(COMPUTE, COMPUTE_BACKEND)
......
67 67

  
68 68
 
69 69
    VALIDATOR_APP = validator(APP)
70
    HTTPD = make_server('', 8888, VALIDATOR_APP)
70
    HTTPD = make_server('', SERVER_CONFIG['port'], VALIDATOR_APP)
71 71
    HTTPD.serve_forever()
72 72

  

Also available in: Unified diff