当前位置: 首页>>代码示例>>Python>>正文


Python Factory.get_mgmtcenter方法代码示例

本文整理汇总了Python中ovs.extensions.hypervisor.factory.Factory.get_mgmtcenter方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.get_mgmtcenter方法的具体用法?Python Factory.get_mgmtcenter怎么用?Python Factory.get_mgmtcenter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ovs.extensions.hypervisor.factory.Factory的用法示例。


在下文中一共展示了Factory.get_mgmtcenter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_vdisk_name

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
    def update_vdisk_name(volume_id, old_name, new_name):
        """
        Update a vDisk name using Management Center: set new name
        """
        vdisk = None
        for mgmt_center in MgmtCenterList.get_mgmtcenters():
            mgmt = Factory.get_mgmtcenter(mgmt_center = mgmt_center)
            try:
                disk_info = mgmt.get_vdisk_device_info(volume_id)
                device_path = disk_info['device_path']
                vpool_name = disk_info['vpool_name']
                vp = VPoolList.get_vpool_by_name(vpool_name)
                file_name = os.path.basename(device_path)
                vdisk = VDiskList.get_by_devicename_and_vpool(file_name, vp)
                if vdisk:
                    break
            except Exception as ex:
                logger.info('Trying to get mgmt center failed for disk {0} with volume_id {1}. {2}'.format(old_name, volume_id, ex))
        if not vdisk:
            logger.error('No vdisk found for name {0}'.format(old_name))
            return

        vpool = vdisk.vpool
        mutex = VolatileMutex('{}_{}'.format(old_name, vpool.guid if vpool is not None else 'none'))
        try:
            mutex.acquire(wait=5)
            vdisk.name = new_name
            vdisk.save()
        finally:
            mutex.release()
开发者ID:tcpcloud,项目名称:openvstorage,代码行数:32,代码来源:vdisk.py

示例2: sync_with_hypervisor

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
    def sync_with_hypervisor(vmachineguid, storagedriver_id=None):
        """
        Updates a given vmachine with data retrieved from a given pmachine
        :param vmachineguid: Guid of the virtual machine
        :param storagedriver_id: Storage Driver hosting the vmachine
        """
        try:
            vmachine = VMachine(vmachineguid)
        except Exception as ex:
            VMachineController._logger.info('Cannot get VMachine object: {0}'.format(str(ex)))
            raise

        vm_object = None
        if vmachine.pmachine.mgmtcenter and storagedriver_id is not None and vmachine.devicename is not None:
            try:
                mgmt_center = Factory.get_mgmtcenter(vmachine.pmachine)
                storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
                VMachineController._logger.info('Syncing vMachine (name {0}) with Management center {1}'.format(vmachine.name, vmachine.pmachine.mgmtcenter.name))
                vm_object = mgmt_center.get_vm_agnostic_object(devicename=vmachine.devicename,
                                                               ip=storagedriver.storage_ip,
                                                               mountpoint=storagedriver.mountpoint)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from management center: {0}'.format(str(ex)))

        if vm_object is None and storagedriver_id is None and vmachine.hypervisor_id is not None and vmachine.pmachine is not None:
            try:
                # Only the vmachine was received, so base the sync on hypervisor id and pmachine
                hypervisor = Factory.get(vmachine.pmachine)
                VMachineController._logger.info('Syncing vMachine (name {0})'.format(vmachine.name))
                vm_object = hypervisor.get_vm_agnostic_object(vmid=vmachine.hypervisor_id)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from hypervisor: {0}'.format(str(ex)))

        if vm_object is None and storagedriver_id is not None and vmachine.devicename is not None:
            try:
                # Storage Driver id was given, using the devicename instead (to allow hypervisor id updates
                # which can be caused by re-adding a vm to the inventory)
                pmachine = PMachineList.get_by_storagedriver_id(storagedriver_id)
                storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
                hypervisor = Factory.get(pmachine)
                if not hypervisor.file_exists(storagedriver, hypervisor.clean_vmachine_filename(vmachine.devicename)):
                    return
                vmachine.pmachine = pmachine
                vmachine.save()

                VMachineController._logger.info('Syncing vMachine (device {0}, ip {1}, mountpoint {2})'.format(vmachine.devicename,
                                                                                                               storagedriver.storage_ip,
                                                                                                               storagedriver.mountpoint))
                vm_object = hypervisor.get_vm_object_by_devicename(devicename=vmachine.devicename,
                                                                   ip=storagedriver.storage_ip,
                                                                   mountpoint=storagedriver.mountpoint)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from hypervisor using devicename: {0}'.format(str(ex)))

        if vm_object is None:
            message = 'Not enough information to sync vmachine'
            VMachineController._logger.info('Error: {0}'.format(message))
            raise RuntimeError(message)

        VMachineController.update_vmachine_config(vmachine, vm_object)
开发者ID:DarumasLegs,项目名称:framework,代码行数:62,代码来源:vmachine.py

示例3: create

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
 def create(self, request):
     """
     Creates a Management Center
     """
     serializer = FullSerializer(
         MgmtCenter,
         instance=MgmtCenter(),
         data=request.DATA,
         allow_passwords=True)
     if serializer.is_valid():
         mgmt_center = serializer.object
         duplicate = MgmtCenterList.get_by_ip(mgmt_center.ip)
         if duplicate is None:
             try:
                 mgmt_center_client = Factory.get_mgmtcenter(
                     mgmt_center=mgmt_center)
                 is_mgmt_center = mgmt_center_client.test_connection()
             except Exception as ex:
                 logger.debug('Management center testing: {0}'.format(ex))
                 raise NotAcceptable('The given information is invalid.')
             if not is_mgmt_center:
                 raise NotAcceptable(
                     'The given information is not for a Management center.'
                 )
             mgmt_center.save()
             return Response(
                 serializer.data, status=status.HTTP_201_CREATED)
         else:
             raise NotAcceptable(
                 'A Mangement Center with this ip already exists.')
     else:
         return Response(
             serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:35,代码来源:mgmtcenters.py

示例4: _hosts

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
 def _hosts(self):
     """
     Returns all hosts (not only those known to OVS) managed by the Management center
     """
     mgmt_center = Factory.get_mgmtcenter(mgmt_center=self)
     if mgmt_center is not None:
         return mgmt_center.get_hosts()
     else:
         return {}
开发者ID:JasperLue,项目名称:openvstorage,代码行数:11,代码来源:mgmtcenter.py

示例5: unconfigure_vpool_for_host

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
 def unconfigure_vpool_for_host(pmachine_guid, vpool_guid):
     pmachine = PMachine(pmachine_guid)
     mgmt_center_client = None
     try:
         mgmt_center_client = Factory.get_mgmtcenter(pmachine=pmachine)
     except Exception as ex:
         logger.error('Cannot get management center client: {0}'.format(ex))
     if mgmt_center_client is not None:
         logger.info('Unconfiguring vPool {0} on host {1}'.format(vpool_guid, pmachine.name))
         mgmt_center_client.unconfigure_vpool_for_host(vpool_guid, False, pmachine.ip)
开发者ID:dawnpower,项目名称:framework,代码行数:12,代码来源:mgmtcenter.py

示例6: _host_status

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
 def _host_status(self):
     """
     Returns the host status as reported by the management center (e.g. vCenter Server)
     """
     mgmtcentersdk = hvFactory.get_mgmtcenter(self)
     if mgmtcentersdk:
         if self.hypervisor_id:
             return mgmtcentersdk.get_host_status_by_pk(self.hypervisor_id)
         if self.ip:
             return mgmtcentersdk.get_host_status_by_ip(self.ip)
     return 'UNKNOWN'
开发者ID:tcpcloud,项目名称:openvstorage,代码行数:13,代码来源:pmachine.py

示例7: is_host_configured

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
    def is_host_configured(pmachine_guid):
        pmachine = PMachine(pmachine_guid)
        mgmt_center_client = None
        try:
            mgmt_center_client = Factory.get_mgmtcenter(pmachine=pmachine)
        except Exception as ex:
            if pmachine.mgmtcenter_guid:
                logger.error('Cannot get management center client: {0}'.format(ex))

        if mgmt_center_client is not None:
            return mgmt_center_client.is_host_configured(pmachine.ip)
        return False
开发者ID:dawnpower,项目名称:framework,代码行数:14,代码来源:mgmtcenter.py

示例8: unconfigure_host

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
 def unconfigure_host(pmachine_guid, mgmtcenter_guid, update_link):
     pmachine = PMachine(pmachine_guid)
     mgmt_center = MgmtCenter(mgmtcenter_guid)
     mgmt_center_client = None
     try:
         mgmt_center_client = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
     except Exception as ex:
         logger.error('Cannot get management center client: {0}'.format(ex))
     if mgmt_center_client is not None:
         logger.info('Unconfiguring host {0} from management center {1}'.format(pmachine.name, mgmt_center.name))
         mgmt_center_client.unconfigure_host(pmachine.ip)
         if update_link is True:
             pmachine.mgmtcenter = None
             pmachine.save()
开发者ID:dawnpower,项目名称:framework,代码行数:16,代码来源:mgmtcenter.py

示例9: test_connection

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
 def test_connection(mgmt_center_guid):
     """
     Test management center connection
     """
     mgmt_center = MgmtCenter(mgmt_center_guid)
     try:
         mgmt_center_client = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
     except Exception as ex:
         logger.error('Cannot get mgmt center client: {0}'.format(ex))
         return None
     try:
         is_mgmt_center = mgmt_center_client.test_connection()
     except Exception as ex:
         logger.error('Cannot test connection: {0}'.format(ex))
         return False
     return is_mgmt_center
开发者ID:dawnpower,项目名称:framework,代码行数:18,代码来源:mgmtcenter.py

示例10: sync_with_mgmtcenter

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
    def sync_with_mgmtcenter(disk, pmachine, storagedriver):
        """
        Update disk info using management center (if available)
         If no management center, try with hypervisor
         If no info retrieved, use devicename
        @param disk: vDisk hybrid (vdisk to be updated)
        @param pmachine: pmachine hybrid (pmachine running the storagedriver)
        @param storagedriver: storagedriver hybrid (storagedriver serving the vdisk)
        """
        disk_name = None
        if pmachine.mgmtcenter is not None:
            logger.debug('Sync vdisk {0} with management center {1} on storagedriver {2}'.format(disk.name, pmachine.mgmtcenter.name, storagedriver.name))
            mgmt = Factory.get_mgmtcenter(mgmt_center = pmachine.mgmtcenter)
            volumepath = disk.devicename
            mountpoint = storagedriver.mountpoint
            devicepath = '{0}/{1}'.format(mountpoint, volumepath)
            try:
                disk_mgmt_center_info = mgmt.get_vdisk_model_by_devicepath(devicepath)
                if disk_mgmt_center_info is not None:
                    disk_name = disk_mgmt_center_info.get('name')
            except Exception as ex:
                logger.error('Failed to sync vdisk {0} with mgmt center {1}. {2}'.format(disk.name, pmachine.mgmtcenter.name, str(ex)))

        if disk_name is None:
            logger.info('Sync vdisk with hypervisor on {0}'.format(pmachine.name))
            try:
                hv = Factory.get(pmachine)
                info = hv.get_vm_agnostic_object(disk.vmachine.hypervisor_id)
                for disk in info['disks']:
                    if disk['filename'] == disk.devicename:
                        disk_name = disk['name']
                        break
            except Exception as ex:
                logger.error('Failed to get vdisk info from hypervisor. %s' % ex)

        if disk_name is None:
            logger.info('No info retrieved from hypervisor, using devicename')
            disk_name = disk.devicename.split('/')[-1].split('.')[0]

        if disk_name is not None:
            disk.name = disk_name
            disk.save()
开发者ID:tcpcloud,项目名称:openvstorage,代码行数:44,代码来源:vdisk.py

示例11: update_vmachine_name

# 需要导入模块: from ovs.extensions.hypervisor.factory import Factory [as 别名]
# 或者: from ovs.extensions.hypervisor.factory.Factory import get_mgmtcenter [as 别名]
    def update_vmachine_name(instance_id, old_name, new_name):
        """
        Update a vMachine name: find vmachine by management center instance id, set new name
        :param instance_id: ID for the virtual machine known by management center
        :param old_name: Old name of the virtual machine
        :param new_name: New name for the virtual machine
        """
        vmachine = None
        for mgmt_center in MgmtCenterList.get_mgmtcenters():
            mgmt = Factory.get_mgmtcenter(mgmt_center = mgmt_center)
            try:
                machine_info = mgmt.get_vmachine_device_info(instance_id)
                file_name = machine_info['file_name']
                host_name = machine_info['host_name']
                vpool_name = machine_info['vpool_name']
                storage_router = StorageRouterList.get_by_name(host_name)
                machine_id = storage_router.machine_id
                device_name = '{0}/{1}'.format(machine_id, file_name)
                vp = VPoolList.get_vpool_by_name(vpool_name)
                vmachine = VMachineList.get_by_devicename_and_vpool(device_name, vp)
                if vmachine:
                    break
                vmachine = VMachineList.get_by_devicename_and_vpool(device_name, None)
                if vmachine:
                    break
            except Exception as ex:
                VMachineController._logger.info('Trying to get mgmt center failed for vmachine {0}. {1}'.format(old_name, ex))
        if not vmachine:
            VMachineController._logger.error('No vmachine found for name {0}'.format(old_name))
            return

        vpool = vmachine.vpool
        mutex = volatile_mutex('{0}_{1}'.format(old_name, vpool.guid if vpool is not None else 'none'))
        try:
            mutex.acquire(wait=5)
            vmachine.name = new_name
            vmachine.save()
        finally:
            mutex.release()
开发者ID:DarumasLegs,项目名称:framework,代码行数:41,代码来源:vmachine.py


注:本文中的ovs.extensions.hypervisor.factory.Factory.get_mgmtcenter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。