예제 #1
0
    def _initialize_connection(self, volume, connector):
        """Get information of volume's backing.

        If the volume does not have a backing yet. It will be created.

        :param volume: Volume object
        :param connector: Connector information
        :return: Return connection information
        """
        connection_info = {'driver_volume_type': 'vmdk'}

        backing = self.volumeops.get_backing(volume['name'])
        if 'instance' in connector:
            # The instance exists
            instance = vim.get_moref(connector['instance'], 'VirtualMachine')
            LOG.debug(
                _("The instance: %s for which initialize connection "
                  "is called, exists.") % instance)
            # Get host managing the instance
            host = self.volumeops.get_host(instance)
            if not backing:
                # Create a backing in case it does not exist under the
                # host managing the instance.
                LOG.info(
                    _("There is no backing for the volume: %s. "
                      "Need to create one.") % volume['name'])
                backing = self._create_backing(volume, host)
            else:
                # Relocate volume is necessary
                self._relocate_backing(volume['size'], backing, host)
        else:
            # The instance does not exist
            LOG.debug(
                _("The instance for which initialize connection "
                  "is called, does not exist."))
            if not backing:
                # Create a backing in case it does not exist. It is a bad use
                # case to boot from an empty volume.
                LOG.warn(
                    _("Trying to boot from an empty volume: %s.") %
                    volume['name'])
                # Create backing
                backing = self._create_backing_in_inventory(volume)

        # Set volume's moref value and name
        connection_info['data'] = {
            'volume': backing.value,
            'volume_id': volume['id']
        }

        LOG.info(
            _("Returning connection_info: %(info)s for volume: "
              "%(volume)s with connector: %(connector)s.") % {
                  'info': connection_info,
                  'volume': volume['name'],
                  'connector': connector
              })

        return connection_info
예제 #2
0
파일: vmdk.py 프로젝트: DijonLin/cinder
    def _initialize_connection(self, volume, connector):
        """Get information of volume's backing.

        If the volume does not have a backing yet. It will be created.

        :param volume: Volume object
        :param connector: Connector information
        :return: Return connection information
        """
        connection_info = {'driver_volume_type': 'vmdk'}

        backing = self.volumeops.get_backing(volume['name'])
        if 'instance' in connector:
            # The instance exists
            instance = vim.get_moref(connector['instance'], 'VirtualMachine')
            LOG.debug(_("The instance: %s for which initialize connection "
                        "is called, exists.") % instance)
            # Get host managing the instance
            host = self.volumeops.get_host(instance)
            if not backing:
                # Create a backing in case it does not exist under the
                # host managing the instance.
                LOG.info(_("There is no backing for the volume: %s. "
                           "Need to create one.") % volume['name'])
                backing = self._create_backing(volume, host)
            else:
                # Relocate volume is necessary
                self._relocate_backing(volume['size'], backing, host)
        else:
            # The instance does not exist
            LOG.debug(_("The instance for which initialize connection "
                        "is called, does not exist."))
            if not backing:
                # Create a backing in case it does not exist. It is a bad use
                # case to boot from an empty volume.
                LOG.warn(_("Trying to boot from an empty volume: %s.") %
                         volume['name'])
                # Create backing
                backing = self._create_backing_in_inventory(volume)

        # Set volume's moref value and name
        connection_info['data'] = {'volume': backing.value,
                                   'volume_id': volume['id']}

        LOG.info(_("Returning connection_info: %(info)s for volume: "
                   "%(volume)s with connector: %(connector)s.") %
                 {'info': connection_info,
                  'volume': volume['name'],
                  'connector': connector})

        return connection_info
예제 #3
0
파일: pbm.py 프로젝트: wputra/MOS-centos
    def __init__(self, vimSession, pbm_wsdl, protocol='https',
                 host='localhost'):
        """Constructs a PBM client object.

        :param vimSession: an authenticated api.VMwareAPISession object
        :param pbm_wsdl: URL path to where pbmService.wsdl file is located.
        :param protocol: http or https
        :param host: Server IPAddress[:port] or Hostname[:port]
        """
        self._vimSession = vimSession
        self._url = vim_util.get_soap_url(protocol, host, 'pbm')
        # create the pbm client
        self._client = suds.client.Client(pbm_wsdl, location=self._url)
        PBMClient._copy_client_cookie(self._vimSession, self._client)
        # Get the PBM service content
        si_moref = vim_module.get_moref(SERVICE_INSTANCE, SERVICE_TYPE)
        self._sc = self._client.service.PbmRetrieveServiceContent(si_moref)