def retrieve(self, entity, extras): """ Retrieve a VM. """ uid = entity.attributes['occi.core.id'] context = extras['nova_ctx'] instance = vm.get_vm(uid, context) LOG.debug('Retrieving an Virtual machine: ', uid) # set state and applicable actions! state, actions = vm.get_occi_state(uid, context) entity.attributes['occi.compute.state'] = state entity.actions = actions # set up to date attributes entity.attributes['occi.compute.cores'] = str(instance['vcpus']) value = str(float(instance['memory_mb']) / 1024) entity.attributes['occi.compute.memory'] = value #Now we have the instance state, get its updated network info net_info = net.get_adapter_info(uid, context) attach_to_default_network(net_info, entity, extras) # add consoles and storage links set_console_info(entity, uid, extras)
def create(self, entity, extras): """ Create a VM. """ LOG.debug('Creating an Virtual machine') # ignore some attributes - done via templating if 'occi.compute.cores' in entity.attributes or \ 'occi.compute.speed' in entity.attributes or \ 'occi.compute.memory' in entity.attributes or \ 'occi.compute.architecture' in entity.attributes: raise AttributeError('There are unsupported attributes in the ' 'request.') # create the VM context = extras['nova_ctx'] instance = vm.create_vm(entity, context) uid = instance['uuid'] # deal with some networking stuff net_info = net.get_adapter_info(uid, context) attach_to_default_network(net_info, entity, extras) # add consoles and storage links set_console_info(entity, uid, extras) # set some attributes entity.attributes['occi.core.id'] = instance['uuid'] entity.attributes['occi.compute.hostname'] = instance['hostname'] entity.attributes['occi.compute.architecture'] = \ vol.get_image_architecture(uid, extras['nova_ctx']) entity.attributes['occi.compute.cores'] = str(instance['vcpus']) entity.attributes['occi.compute.speed'] = str(0.0) # N/A in instance value = str(float(instance['memory_mb']) / 1024) entity.attributes['occi.compute.memory'] = value entity.attributes['occi.compute.state'] = 'inactive' # set valid actions entity.actions = [infrastructure.STOP, infrastructure.SUSPEND, infrastructure.RESTART, openstack.OS_REVERT_RESIZE, openstack.OS_CONFIRM_RESIZE, openstack.OS_CREATE_IMAGE]