當前位置: 首頁>>代碼示例>>Python>>正文


Python vmodl.MethodFault方法代碼示例

本文整理匯總了Python中pyVmomi.vmodl.MethodFault方法的典型用法代碼示例。如果您正苦於以下問題:Python vmodl.MethodFault方法的具體用法?Python vmodl.MethodFault怎麽用?Python vmodl.MethodFault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyVmomi.vmodl的用法示例。


在下文中一共展示了vmodl.MethodFault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _vmware_connect

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def _vmware_connect(self, vsphere_host, section):
        """
        Connect to Vcenter and get connection
        """
        vsphere_user = self.config[section].get('vsphere_user')
        vsphere_password = self.config[section].get('vsphere_password')

        context = None
        if self.config[section].get('ignore_ssl') and \
                hasattr(ssl, "_create_unverified_context"):
            context = ssl._create_unverified_context()

        try:
            vmware_connect = connect.Connect(vsphere_host, 443,
                                             vsphere_user,
                                             vsphere_password,
                                             sslContext=context
                                             )

            return vmware_connect

        except vmodl.MethodFault as error:
            log("Caught vmodl fault: " + error.msg)
            return None 
開發者ID:rverchere,項目名稱:vmware_exporter,代碼行數:26,代碼來源:vmware_exporter.py

示例2: upload_disks

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def upload_disks(self, lease, host):
        """
        Uploads all the disks, with a progress keep-alive.
        """
        self.lease = lease
        try:
            self.start_timer()
            for fileItem in self.spec.fileItem:
                self.upload_disk(fileItem, lease, host)
            lease.Complete()
            print("Finished deploy successfully.")
            return 0
        except vmodl.MethodFault as e:
            print("Hit an error in upload: %s" % e)
            lease.Abort(e)
        except Exception as e:
            print("Lease: %s" % lease.info)
            print("Hit an error in upload: %s" % e)
            lease.Abort(vmodl.fault.SystemError(reason=str(e)))
            raise
        return 1 
開發者ID:vmware,項目名稱:pyvmomi-community-samples,代碼行數:23,代碼來源:deploy_ova.py

示例3: create_datacenter

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def create_datacenter(context, module):
    datacenter_name = module.params.get('datacenter_name')
    folder = context.rootFolder

    try:
        datacenter = get_datacenter(context, module)
        if not datacenter:
            changed = True
            if not module.check_mode:
                folder.CreateDatacenter(name=datacenter_name)
        module.exit_json(changed=changed)
    except vim.fault.DuplicateName:
        module.fail_json(msg="A datacenter with the name %s already exists" % datacenter_name)
    except vim.fault.InvalidName:
        module.fail_json(msg="%s is an invalid name for a cluster" % datacenter_name)
    except vmodl.fault.NotSupported:
        # This should never happen
        module.fail_json(msg="Trying to create a datacenter on an incorrect folder object")
    except vmodl.RuntimeFault as runtime_fault:
        module.fail_json(msg=runtime_fault.msg)
    except vmodl.MethodFault as method_fault:
        module.fail_json(msg=method_fault.msg) 
開發者ID:shapeblue,項目名稱:Trillian,代碼行數:24,代碼來源:vmware-datacenter.py

示例4: destroy_datacenter

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def destroy_datacenter(context, module):
    result = None

    try:
        datacenter = get_datacenter(context, module)
        if datacenter:
            changed = True
            if not module.check_mode:
                task = datacenter.Destroy_Task()
                changed, result = wait_for_task(task)
        module.exit_json(changed=changed, result=result)
    except vim.fault.VimFault as vim_fault:
        module.fail_json(msg=vim_fault.msg)
    except vmodl.RuntimeFault as runtime_fault:
        module.fail_json(msg=runtime_fault.msg)
    except vmodl.MethodFault as method_fault:
        module.fail_json(msg=method_fault.msg) 
開發者ID:shapeblue,項目名稱:Trillian,代碼行數:19,代碼來源:vmware-datacenter.py

示例5: process_state

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def process_state(self):
        try:
            # Currently state_update_dvs is not implemented.
            host_states = {
                'absent': {
                    'present': self.state_remove_host,
                    'absent': self.state_exit_unchanged,
                },
                'present': {
                    'present': self.state_exit_unchanged,
                    'absent': self.state_add_host,
                }
            }

            host_states[self.state][self.check_host_state()]()

        except vmodl.RuntimeFault as runtime_fault:
            self.module.fail_json(msg=runtime_fault.msg)
        except vmodl.MethodFault as method_fault:
            self.module.fail_json(msg=method_fault.msg)
        except Exception as e:
            self.module.fail_json(msg=str(e)) 
開發者ID:shapeblue,項目名稱:Trillian,代碼行數:24,代碼來源:vmware_host.py

示例6: connection

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def connection(self):
        """
        Connect to Vcenter and get connection
        """
        context = None
        if self.ignore_ssl:
            context = ssl._create_unverified_context()

        try:
            vmware_connect = yield threads.deferToThread(
                connect.SmartConnect,
                host=self.host,
                user=self.username,
                pwd=self.password,
                sslContext=context,
            )
            return vmware_connect

        except vmodl.MethodFault as error:
            logging.error("Caught vmodl fault: {error}".format(error=error.msg))
            return None 
開發者ID:pryorda,項目名稱:vmware_exporter,代碼行數:23,代碼來源:vmware_exporter.py

示例7: hello_vcenter

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def hello_vcenter(vchost,username,password,port):
    try:
        si = SmartConnectNoSSL(
            host=vchost,
            user=username,
            pwd=password,
            port=port)

        atexit.register(Disconnect, si)
        return True, "ok"
    except vmodl.MethodFault as error:
        return False, error.msg
    except Exception as e:
        return False, str(e) 
開發者ID:freedomkk-qfeng,項目名稱:vsphere-monitor,代碼行數:16,代碼來源:vsphere-monitor.py

示例8: makeConnect

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def makeConnect(parser):
    """
    :return:
    """
    try:
        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        context.verify_mode = ssl.CERT_NONE

        service_instance = connect.SmartConnect(
            host=parser.vcenterip,
            user=parser.user,
            pwd=parser.password,
            port=parser.port,
            sslContext=context
        )
        if not service_instance:
            print("Could not connect to the specified host using specified "
                  "username and password")
            return -1

        atexit.register(connect.Disconnect, service_instance)

        parse_service_instance(parser.clustername, service_instance)

    except vmodl.MethodFault as e:
        return -1
    return 0 
開發者ID:nutanix,項目名稱:blueprints,代碼行數:29,代碼來源:01_get_vmware_vm_info.py

示例9: get_all_vms

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def get_all_vms(self):
        try:
            content = self.service_instance.RetrieveContent()
            container = content.rootFolder
            viewType = [vim.VirtualMachine]
            recursive = True
            containerView = content.viewManager.CreateContainerView(
                container, viewType, recursive
            )
            children = containerView.view
            return children
        except vmodl.MethodFault as error:
            return -1 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:15,代碼來源:vmware.py

示例10: get_vm_monitor

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def get_vm_monitor(self,vm):
        try:
            content = self.service_instance.RetrieveContent()
            perfManager = content.perfManager
            metricId = vim.PerformanceManager.MetricId(counterId=2, instance="*")
            import datetime
            startTime = datetime.datetime.now() - datetime.timedelta(hours=3)
            endTime = datetime.datetime.now()
            # query = vim.PerformanceManager.QuerySpec(maxSample=1,
            #                                          entity=vm,
            #                                          metricId=[metricId],
            #                                          startTime=startTime,
            #                                          endTime=endTime)
            # query = vim.PerformanceManager.QueryAvailablePerfMetric(entity=vm,
            #                                                         startTime=startTime,
            #                                                         endTime=endTime)
            query = perfManager.QueryPerfProviderSummary(entity=vm)
            print(query)
            # print(perfManager.QueryPerf(querySpec=[query]))
            # print(perfManager.QueryPerfCounter(counterId=[24,]))
            # print(perfManager.QueryPerfCounterByLevel(level=1))
            '''
                2 CPU 在該時間間隔內的使用情況(百分比) CPU
                24 內存使用情況,表示為占總的配置或可用內存的百分比 MEMORY
                136 收集時間間隔內每秒鍾磁盤平均讀取次數 DISK OUT
                137 收集時間間隔內每秒鍾磁盤平均寫入次數 DISK IN
                146 該時間間隔內收到的數據包數 NETWORK
            '''
        except vmodl.MethodFault as e:
            print("Caught vmodl fault : " + e.msg)
            return -1
        except Exception as e:
            print("Caught exception : " + str(e))
        return -1 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:36,代碼來源:vmware.py

示例11: main

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def main():

    args = get_args()

    try:
        if args.disable_ssl_verification:
            service_instance = SmartConnectNoSSL(host=args.host,
                                                 user=args.user,
                                                 pwd=args.password,
                                                 port=args.port)
        else:
            service_instance = SmartConnect(host=args.host,
                                            user=args.user,
                                            pwd=args.password,
                                            port=args.port)

        atexit.register(Disconnect, service_instance)

        content = service_instance.RetrieveContent()

        # Assigning destination datastores
        datastore_dest = args.datastore_dest

        # Target compute resource
        host_dest = args.target_esx_host

        relocate_vm(args.vm_name,
                    content=content,
                    host_dest=host_dest,
                    datastore_dest=datastore_dest)

    except vmodl.MethodFault as error:
        print("Caught vmodl fault : " + error.msg)
        return -1

    return 0


# Start program 
開發者ID:vmware,項目名稱:pyvmomi-community-samples,代碼行數:41,代碼來源:relocate_vm.py

示例12: main

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def main():
    """
    Simple command-line program for listing all snapshots of a fcd
    """

    args = get_args()

    try:
        if args.disable_ssl_verification:
            service_instance = connect.SmartConnectNoSSL(host=args.host,
                                                         user=args.user,
                                                         pwd=args.password,
                                                         port=int(args.port))
        else:
            service_instance = connect.SmartConnect(host=args.host,
                                                    user=args.user,
                                                    pwd=args.password,
                                                    port=int(args.port))

        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.RetrieveContent()

        # Retrieve Datastore Object
        datastore = disk.get_obj(content, [vim.Datastore], args.datastore)

        # Retrieve FCD Object
        vdisk = disk.retrieve_fcd(content, datastore, args.vdisk)

        # Retrieve all Snapshots
        list_fcd_snapshots(content, vdisk)

    except vmodl.MethodFault as error:
        print("Caught vmodl fault : " + error.msg)
        return -1

    return 0


# Start program 
開發者ID:vmware,項目名稱:pyvmomi-community-samples,代碼行數:42,代碼來源:fcd_list_vdisk_snapshots.py

示例13: main

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def main():
    """
    Simple command-line program for listing the virtual machines on a system.
    """

    args = cli.get_args()

    try:
        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        context.verify_mode = ssl.CERT_NONE
        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port),
                                                sslContext=context)

        if not service_instance:
            print("Could not connect to the specified host using specified "
                  "username and password")
            return -1

        atexit.register(connect.Disconnect, service_instance)

        # ## Do the actual parsing of data ## #
        parse_service_instance(service_instance)

    except vmodl.MethodFault as e:
        print("Caught vmodl fault : {}".format(e.msg))
        return -1

    return 0

# Start program 
開發者ID:vmware,項目名稱:pyvmomi-community-samples,代碼行數:35,代碼來源:vcenter_details.py

示例14: main

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def main():
    """
   Simple command-line program for listing Datastores in Datastore Cluster
   """

    args = get_args()

    try:
        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))
        if not service_instance:
            print("Could not connect to the specified host using "
                  "specified username and password")
            return -1

        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.RetrieveContent()
        # Search for all Datastore Clusters aka StoragePod
        obj_view = content.viewManager.CreateContainerView(content.rootFolder,
                                                           [vim.StoragePod],
                                                           True)
        ds_cluster_list = obj_view.view
        obj_view.Destroy()

        for ds_cluster in ds_cluster_list:
            if ds_cluster.name == args.dscluster:
                datastores = ds_cluster.childEntity
                print "Datastores: "
                for datastore in datastores:
                    print datastore.name

    except vmodl.MethodFault as error:
        print "Caught vmodl fault : " + error.msg
        return -1

    return 0

# Start program 
開發者ID:vmware,項目名稱:pyvmomi-community-samples,代碼行數:43,代碼來源:list_datastore_cluster.py

示例15: main

# 需要導入模塊: from pyVmomi import vmodl [as 別名]
# 或者: from pyVmomi.vmodl import MethodFault [as 別名]
def main():

    args = get_args()

    try:
        if args.disable_ssl_verification:
            service_instance = SmartConnectNoSSL(host=args.host,
                                                 user=args.user,
                                                 pwd=args.password,
                                                 port=args.port)
        else:
            service_instance = SmartConnect(host=args.host,
                                            user=args.user,
                                            pwd=args.password,
                                            port=args.port)

        atexit.register(Disconnect, service_instance)

        # call configuration of dvs port group
        configure_dvs_pg(service_instance, args.dvs_name, args.dvs_pg_name)

    except vmodl.MethodFault as error:
        print("Caught vmodl fault : {0}".format(error.msg))
        return -1

    return 0


# Start program 
開發者ID:vmware,項目名稱:pyvmomi-community-samples,代碼行數:31,代碼來源:configure_dvs_port_group.py


注:本文中的pyVmomi.vmodl.MethodFault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。