|
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")
|