def create(self, link, extras): """ Creates a link from a compute instance to a storage volume. The user must specify what the device id is to be. """ context = extras['nova_ctx'] instance_id = link.source.attributes['occi.core.id'] volume_id = link.target.attributes['occi.core.id'] if 'occi.storagelink.deviceid' in link.attributes: mount_point = link.attributes['occi.storagelink.deviceid'] else: # get the list of linked mount points mp = [] for sl in link.source.links: if 'occi.storagelink.mountpoint' in sl.attributes: mp.append(sl.attributes['occi.storagelink.mountpoint']) # generate a mount point who is not already in use i = 100 # Start from d mount_point = "/dev/vd" + chr(i) while mount_point in mp: i = i + 1 mount_point = "/dev/vd" + chr(i) # If hostname is set and state is not, this mean that we are requesting # a new instance with links, so the instance does not exist yet if ('occi.compute.hostname' not in link.source.attributes or 'occi.compute.state' in link.source.attributes): vm.attach_volume(instance_id, volume_id, mount_point, context) link.attributes['occi.core.id'] = str(uuid.uuid4()) link.attributes['occi.storagelink.deviceid'] = mount_point link.attributes['occi.storagelink.mountpoint'] = mount_point link.attributes['occi.storagelink.state'] = 'active'
def create(self, link, extras): """ Creates a link from a compute instance to a storage volume. The user must specify what the device id is to be. """ volume_id = link.target.attributes.get('occi.core.id', '') instance_id = link.source.attributes.get('occi.core.id', '') link_id = '_'.join([instance_id, volume_id]) link.identifier = infrastructure.STORAGELINK.location + link_id link.attributes['occi.core.id'] = link_id link.attributes['occi.storagelink.state'] = 'active' registry = extras['registry'] try: registry.get_resource('/compute/%s' % instance_id, extras) except KeyError: # image is not in the registry -> link created with the VM # will be handled elsewhere pass else: context = extras['nova_ctx'] device_id = link.attributes.get('occi.storagelink.deviceid') device_name = vm.attach_volume(instance_id, volume_id, device_id, context) link.attributes['occi.storagelink.deviceid'] = device_name
def create(self, link, extras): """ Creates a link from a compute instance to a storage volume. The user must specify what the device id is to be. """ context = extras['nova_ctx'] instance_id = link.source.attributes['occi.core.id'] volume_id = link.target.attributes['occi.core.id'] mount_point = link.attributes['occi.storagelink.deviceid'] vm.attach_volume(instance_id, volume_id, mount_point, context) link.attributes['occi.core.id'] = str(uuid.uuid4()) link.attributes['occi.storagelink.deviceid'] = \ link.attributes['occi.storagelink.deviceid'] link.attributes['occi.storagelink.mountpoint'] = '' link.attributes['occi.storagelink.state'] = 'active'