Example #1
0
    def store_key(self, ctxt, key, **kwargs):
        """Stores (i.e., registers) a key with the key manager.
        """
        if ctxt is None:
            raise exception.NotAuthorized()

        # generate UUID and ensure that it isn't in use
        key_id = uuidutils.generate_uuid()
        while key_id in self.keys:
            key_id = uuidutils.generate_uuid()

        self.keys[key_id] = key

        return key_id
Example #2
0
    def store_key(self, ctxt, key, **kwargs):
        """Stores (i.e., registers) a key with the key manager.
        """
        if ctxt is None:
            raise exception.NotAuthorized()

        # generate UUID and ensure that it isn't in use
        key_id = uuidutils.generate_uuid()
        while key_id in self.keys:
            key_id = uuidutils.generate_uuid()

        self.keys[key_id] = key

        return key_id
Example #3
0
def fetch_qcow2_image(context, timeout_secs, image_service, image_id, **kwargs):
    """Download flat image from the glance image server."""
    LOG.debug("Downloading image: %s from glance image server as a flat vmdk"
              " file." % image_id)
    read_iter = image_service.download(context, image_id)
    read_handle = rw_util.GlanceFileRead(read_iter)
    file_size = int(kwargs.get('image_size'))
    
    tmp_directory=CONF.image_conversion_dir
    if tmp_directory is None:
        tmp_directory='/tmp'
    tmp_file_name = tmp_directory +"/"+ uuidutils.generate_uuid()  
    fp = open(tmp_file_name, "wb")
    
    start_transfer(context, timeout_secs,read_handle, file_size,
                   write_file_handle=fp)
    #convert the qcow2 to vmdk
    converted_file_name = _disk_qcow2_to_vmdk(tmp_file_name)
    
    if converted_file_name is not None and os.path.exists(converted_file_name):
        file_size = os.path.getsize(converted_file_name)
        read_file_handle_local = rw_util.HybridFileHandle(converted_file_name, "rb")
        write_handle = rw_util.VMwareHTTPWriteFile(kwargs.get('host'),
                                               kwargs.get('data_center_name'),
                                               kwargs.get('datastore_name'),
                                               kwargs.get('cookies'),
                                               kwargs.get('file_path'),
                                               file_size)
        start_transfer(context,
                    timeout_secs,
                    read_file_handle_local,
                    file_size,
                    write_file_handle=write_handle)
        os.remove(converted_file_name)
        LOG.info(_("Downloaded image: %s from glance image server.") % image_id)
Example #4
0
 def __init__(self, name, parents=None, uuid=None):
     self._name = str(name)
     # The state of this flow.
     self._state = states.PENDING
     # If this flow has a parent flow/s which need to be reverted if
     # this flow fails then please include them here to allow this child
     # to call the parents...
     if parents:
         self.parents = tuple(parents)
     else:
         self.parents = ()
     # Any objects that want to listen when a wf/task starts/stops/completes
     # or errors should be registered here. This can be used to monitor
     # progress and record tasks finishing (so that it becomes possible to
     # store the result of a task in some persistent or semi-persistent
     # storage backend).
     self.notifier = utils.TransitionNotifier()
     self.task_notifier = utils.TransitionNotifier()
     # Ensure that modifications and/or multiple runs aren't happening
     # at the same time in the same flow at the same time.
     self._lock = threading.RLock()
     # Assign this flow a unique identifer.
     if uuid:
         self._id = str(uuid)
     else:
         self._id = uuidutils.generate_uuid()
Example #5
0
 def __init__(self, name, parents=None, uuid=None):
     self._name = str(name)
     # The state of this flow.
     self._state = states.PENDING
     # If this flow has a parent flow/s which need to be reverted if
     # this flow fails then please include them here to allow this child
     # to call the parents...
     if parents:
         self.parents = tuple(parents)
     else:
         self.parents = ()
     # Any objects that want to listen when a wf/task starts/stops/completes
     # or errors should be registered here. This can be used to monitor
     # progress and record tasks finishing (so that it becomes possible to
     # store the result of a task in some persistent or semi-persistent
     # storage backend).
     self.notifier = utils.TransitionNotifier()
     self.task_notifier = utils.TransitionNotifier()
     # Ensure that modifications and/or multiple runs aren't happening
     # at the same time in the same flow at the same time.
     self._lock = threading.RLock()
     # Assign this flow a unique identifer.
     if uuid:
         self._id = str(uuid)
     else:
         self._id = uuidutils.generate_uuid()
Example #6
0
 def __init__(self, *args, **kwargs):
     self.db = kwargs.get('db')
     self.target_helper = self.get_target_helper(self.db)
     super(VIOSLVMISCSIDriver, self).__init__(*args, **kwargs)
     self.backend_name =\
         self.configuration.safe_get('volume_backend_name') or 'LVM_iSCSI'
     self.protocol = 'viSCSI'
     self.target_name = self.configuration.safe_get('host') or uuidutils.generate_uuid()[8]
Example #7
0
def _populate_encryption_types(volume_types, encryption):
    # TODO(joel-coffman): The database currently doesn't enforce uniqueness
    # for volume type names.
    default_encryption_types = {
        'dm-crypt': {
            'cipher': 'aes-xts-plain64',
            'control_location': 'front-end',
            'key_size': 512,  # only half of key is used for cipher in XTS mode
            'provider':
            'nova.volume.encryptors.cryptsetup.CryptsetupEncryptor',
        },
        'LUKS': {
            'cipher': 'aes-xts-plain64',
            'control_location': 'front-end',
            'key_size': 512,  # only half of key is used for cipher in XTS mode
            'provider': 'nova.volume.encryptors.luks.LuksEncryptor',
        },
    }

    try:
        volume_types_insert = volume_types.insert()
        encryption_insert = encryption.insert()

        for key, values in default_encryption_types.iteritems():
            current_time = timeutils.utcnow()
            volume_type = {
                'id': uuidutils.generate_uuid(),
                'name': key,
                'created_at': current_time,
                'updated_at': current_time,
                'deleted': False,
            }
            volume_types_insert.execute(volume_type)

            values['id'] = uuidutils.generate_uuid()
            values['volume_type_id'] = volume_type['id']

            values['created_at'] = timeutils.utcnow()
            values['updated_at'] = values['created_at']
            values['deleted'] = False

            encryption_insert.execute(values)
    except Exception:
        LOG.error(_("Error populating default encryption types!"))
Example #8
0
 def __init__(self, task, uuid=None):
     assert isinstance(task, collections.Callable)
     self.task = task
     self.providers = {}
     self.runs_before = []
     self.result = None
     if not uuid:
         self._id = uuidutils.generate_uuid()
     else:
         self._id = str(uuid)
Example #9
0
def upload_image(context, timeout_secs, image_service, image_id, owner_id,volume,
                 **kwargs):
    """Upload the vm's disk file to Glance image server."""
    LOG.debug("Uploading image: %s to the Glance image server using HttpNfc"
              " export." % image_id)
    file_size = kwargs.get('vmdk_size')
    read_handle = rw_util.VMwareHTTPReadVmdk(kwargs.get('session'),
                                             kwargs.get('host'),
                                             kwargs.get('vm'),
                                             kwargs.get('vmdk_file_path'),
                                             file_size)

    # modified by  liuling                                       
    #Get vmdk to a temp file
    tmp_directory=CONF.image_conversion_dir
    if tmp_directory is None:
        tmp_directory='/tmp'
    tmp_file_name = tmp_directory +"/"+ uuidutils.generate_uuid()   
    fp = open(tmp_file_name, "wb")
    nova_client = compute.API() 
    
    start_transfer(context,timeout_secs, read_handle, file_size,
                   write_file_handle=fp)
 
    #conver vmdk to qcow2
    task_state  =  vcenter_task_states.CONVERTING
    nova_client.update_server_task_state(context,volume,task_state)
    converted_file_name = _disk_vmdk_to_qcow2(tmp_file_name)
    
    if converted_file_name is not None and os.path.exists(converted_file_name):
        file_size = os.path.getsize(converted_file_name)
    
        # The properties and other fields that we need to set for the image.
        # Important to set the 'size' to 0 here. Otherwise the glance client
        # uses the volume size which may not be image size after upload since
        # it is converted to a stream-optimized sparse disk
        image_metadata = {'disk_format': 'qcow2',
                          'is_public': 'false',
                          'name': kwargs.get('image_name'),
                          'status': 'active',
                          'container_format': 'bare',
                          'size': 0,
                          'properties': {'vmware_image_version':
                                         kwargs.get('image_version'),
                                         'owner_id': owner_id}}
        read_file_handle_local = rw_util.HybridFileHandle(converted_file_name, "rb")
        start_transfer(context, timeout_secs, read_file_handle_local, file_size,
                       image_service=image_service, image_id=image_id,
                       image_meta=image_metadata,volume=volume,task_state=vcenter_task_states.UPLOADING)
        
        if os.path.exists(converted_file_name):
            os.remove(converted_file_name) 
           
        LOG.info(_("Uploaded image: %s to the Glance image server.") % image_id)
Example #10
0
    def _generate_key_id(self):
        key_id = uuidutils.generate_uuid()
        while key_id in self.keys:
            key_id = uuidutils.generate_uuid()

        return key_id
Example #11
0
 def __init__(self, host):
     self.uuid = uuidutils.generate_uuid()
     self.host = host
     setattr(self, 'OS-EXT-SRV-ATTR:host', host)
Example #12
0
def generate_request_id():
    return 'req-%s' % uuidutils.generate_uuid()
Example #13
0
def generate_request_id():
    return 'req-%s' % uuidutils.generate_uuid()
Example #14
0
    def _generate_key_id(self):
        key_id = uuidutils.generate_uuid()
        while key_id in self.keys:
            key_id = uuidutils.generate_uuid()

        return key_id