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


Python VIServer.get_vm_by_path方法代码示例

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


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

示例1: revert

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def revert(datastore):
  #vmsphear username and password
  server = VIServer()
  server.connect("101.91.1.21", "root", "Vsphear_root_password")

  vm1 = server.get_vm_by_path(datastore)
  print "Cuurrent Status",vm1.get_status()
  print "Reverting VM:", datastore 
  vm1.revert_to_snapshot()
  print "Vm reverted"
开发者ID:BwRy,项目名称:sandy,代码行数:12,代码来源:pysph.py

示例2: VirtualMachine_List

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def VirtualMachine_List(VIServer, VirtualMachineList):
    """
    Listet Virtuelle Maschienen
    """
    logger.info("Listing found Virtual Machines using provided information")
    logger.info("Virtual Machine count is " + str(len(VirtualMachineList)))

    for VirtualMachineEntry in range(len(VirtualMachineList)):
        VirtualMachine = VIServer.get_vm_by_path(VirtualMachineList[VirtualMachineEntry])
        logger.info("("+ str(VirtualMachineEntry+1) +"/"+ str(len(VirtualMachineList)) +") " + VirtualMachine.get_property("name"))
开发者ID:Lord-Simon,项目名称:Scripts,代码行数:12,代码来源:sdvmbc.py

示例3: VirtualMachine_PowerOff

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def VirtualMachine_PowerOff(VIServer, VirtualMachineList):
    """VMs Power Off Funktion
    Faehrt VMs mit dem Befehl "Power Off" asyncron runter.
    """
    for VirtualMachineEntry in VirtualMachineList:
        VirtualMachine = VIServer.get_vm_by_path(VirtualMachineEntry)
        if VirtualMachine.is_powered_on():
            try:
                logger.info("Sending Power-Off signal to " + VirtualMachine.get_property("name"))
                VirtualMachine.power_off(sync_run=False)
            except:
                logger.critical("Power-Off signal failed on " + VirtualMachine.get_property("name"))
开发者ID:Lord-Simon,项目名称:Scripts,代码行数:14,代码来源:sdvmbc.py

示例4: VirtualMachine_Start

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def VirtualMachine_Start(VIServer, VirtualMachineList):
    """VMs Start Funktion
    Faehrt die OS auf den VMs asyncron hoch.
    Wenn die VMWare Tools nich installiert sind, werden die VMs ignoriert und dieser vorfall gelogt.
    """
    for VirtualMachineEntry in VirtualMachineList:
        VirtualMachine = VIServer.get_vm_by_path(VirtualMachineEntry)
        if VirtualMachine.is_powered_off():
            try:
                logger.info("Sending Power-On signal to " + VirtualMachine.get_property("name"))
                VirtualMachine.power_on()
            except:
                logger.error(VirtualMachine.get_property("name") + " could not be turned on")
开发者ID:Lord-Simon,项目名称:Scripts,代码行数:15,代码来源:sdvmbc.py

示例5: VirtualMachine_Shutdown

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def VirtualMachine_Shutdown(VIServer, VirtualMachineList):
    """VMs Shutdown Funktion
    Faehrt die OS auf den VMs asyncron runter.
    Wenn die VMWare Tools nich installiert sind, werden die VMs mit dem Befehl "Power Off" heruntergefahren.
    """
    for VirtualMachineEntry in VirtualMachineList:
        VirtualMachine = VIServer.get_vm_by_path(VirtualMachineEntry)
        if VirtualMachine.is_powered_on():
            try:
                logger.info("Sending Guest Shutdown signal to " + VirtualMachine.get_property("name"))
                VirtualMachine.shutdown_guest()
            except:
                logger.error("Problem with VMWare Tools on " + VirtualMachine.get_property("name"))
                logger.warn("Switching to Power-Off sequence on " + VirtualMachine.get_property("name"))
                VirtualMachine.power_off(sync_run=False)
开发者ID:Lord-Simon,项目名称:Scripts,代码行数:17,代码来源:sdvmbc.py

示例6: start_vm

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def start_vm(vcenter_fqdn):
    server = VIServer()
    vcenter_state = False
    end_time = time.time()+600
    while time.time() < end_time:
        try:
            server.connect(vcenter_fqdn, "login", "password")
            vm = server.get_vm_by_path("[datastore1] DHCP-server/DHCP-server.vmx")
            #vm.power_on()
            vcenter_state = True
            print vm.get_status()
            return
        except:
            print ("Waiting for vCenter vm to boot...")
            time.sleep(10)
    if not vcenter_state:
        print "Time out waiting for vCenter vm to boot."
        kill_vpn()
开发者ID:ashumski,项目名称:CloudShare,代码行数:20,代码来源:test.py

示例7: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
class VMRUNNer:
    def __init__(self, hostname, username, password):
        self.server = VIServer()         
        self.server.connect(hostname, username, password)

    def get_vm(self, vm_path_name):
        self.vm = self.server.get_vm_by_path(vm_path_name)
        return self.vm
    
    def list_vms(self):
        vmlist = self.server.get_registered_vms()
        for vm in vmlist:
            print vm    
        return vmlist

    def get_vmserver_version(self):
        type = self.server.get_server_type()
        version = self.server.get_api_version()
        print 'Server Type: ' + type
        print 'Server API Version: ' + version 
开发者ID:dkentw,项目名称:pi-tester,代码行数:22,代码来源:VMRUN.py

示例8: revert_and_start

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
def revert_and_start():
    try:
        for host in get_hosts():
            server = VIServer()
            server.connect(host.ip, host.user, host.pwd)
            
            for vm_path in host.vms:
                try:
                    vm = server.get_vm_by_path(vm_path.strip())
                    vm.revert_to_snapshot()
                    if not vm.is_powered_on():
                        vm.power_on()
                except Exception, e:
                    print "[ERROR] Error happened when revert and start test lab %s" % vm_path
                    print e

            server.disconnect()
    except Exception, e:
        print "[ERROR] Error happened when prepare test enviroment(revert and start test labs)."
        print e
开发者ID:ArthurWu,项目名称:TestController,代码行数:22,代码来源:vm_tool.py

示例9: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
class vSphere:
    hostname = ""
    username = ""
    password = ""

    def __init__(self, vm_path):
        self.vm_path = vm_path

    def __enter__(self):
        self.server   = VIServer()
        self.server.connect(self.hostname, self.username, self.password)
        print "DBG connect"
        vm  = self.server.get_vm_by_path(self.vm_path)
        return vm

    def __exit__(self, type, value, traceback):
        try:
            self.server.disconnect()
            print "DBG disconnect"
        except VIException as e:
            print "DBG problem in disconnection. Fault is: %s" % e.fault
            pass
开发者ID:BwRy,项目名称:test-av2,代码行数:24,代码来源:VMManager.py

示例10: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
class vSphere:
    def __init__(self, vm_path, sdk_host, sdk_user, sdk_domain, sdk_passwd):
        self.vm_path = vm_path
        self.sdk_host = sdk_host
        self.sdk_user = sdk_domain + "\\" + sdk_user
        self.sdk_passwd = sdk_passwd

    def __enter__(self):
        self.server = VIServer()
        self.server.connect(self.sdk_host, self.sdk_user, self.sdk_passwd)
        if config.verbose:
            logging.debug("connected to vSphere")
        vm = self.server.get_vm_by_path(self.vm_path)
        return vm

    def __exit__(self, type, value, traceback):
        try:
            self.server.disconnect()
            if config.verbose:
                logging.debug("disconnected from vSphere")
        except VIException as e:
            logging.debug("Problem in disconnection. Fault is: %s" % e.fault)
            pass
开发者ID:BwRy,项目名称:test-av2,代码行数:25,代码来源:VMRun.py

示例11: VIServer

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
# create server object
server = VIServer()
# connect to server
server.connect(host, username, password)

# get registered vms
vm_list = server.get_registered_vms()

# list for storing vm dictionaries
vm_obj_list = []

# get attributes for each vm
for vm in vm_list:

    # get our attributes
    vm_attr = server.get_vm_by_path(vm)
    vm_name = vm_attr.get_property('name')
    vm_ipv4 = vm_attr.get_property('ip_address', from_cache=False)

    # create our connection string
    vm_cmd = connectionstring + str(vm_ipv4)

    # save to dict
    vm_obj = { 'cmd': vm_cmd, 'name': vm_name }

    # add to list
    vm_obj_list.append(vm_obj) 

# close connection
server.disconnect()
开发者ID:hannesadollarsson,项目名称:misc,代码行数:32,代码来源:update_shuttle_file.py

示例12: printlog

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
www_user = 'dimi'
www_pass = 'akiko.103'

def printlog(text):
  fileToBeWriten = "/home/dimi/prog/exsi/exsi_reboot.txt"
  fichierWrite = open(fileToBeWriten,'a')
  fichierWrite.write(text)
  fichierWrite.write('\n')
  fichierWrite.close()

server = VIServer()
server.connect(exsi_ip, exsi_user, exsi_pass)

vms = server.get_registered_vms()

vm = server.get_vm_by_path(vms[0])

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
  ssh.connect(www_ip, username=www_user, password=www_pass)
except:
  printlog(time.asctime())
  printlog('----------------------------')
  printlog('ssh down, trying to reboot www vm')
  vm.power_off()
  vm.power_on()
  printlog(vm.get_property('name',from_cache=False))
  printlog(vm.get_status())

开发者ID:thibaut-fagart,项目名称:domotique,代码行数:31,代码来源:restart_www.py

示例13: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
class Report:
    """Class report. Generate a dictionnary with the VMs and these properties"""

    def __init__(self, config):
        self.login = config['user']
        self.password = config['password']
        self.vcenter = config['vcenter']
        self.server = VIServer()

    def connect(self):
        """Connect to the hypervisor"""
        self.server.connect(self.vcenter, self.login, self.password)

    def disconnect(self):
        """Close the connection with the hypervisor"""
        if self.server:
            self.server.disconnect()

    def generate_report(self):
        """Generate the report of the actual connection"""
        report = []
        # Create the report
        vms_list = self.server.get_registered_vms()
        for vm_path in vms_list:
            virtual_machine = self.server.get_vm_by_path(vm_path)
            if str(virtual_machine.__class__) != "pysphere.vi_virtual_machine.VIVirtualMachine":
                continue
            if re.match(r'rhel', virtual_machine.get_property('guest_id')):
                vm_infos = { 
                    'name': virtual_machine.get_property('name'), 
                    'ip': virtual_machine.get_property('ip_address'),
                    'os': virtual_machine.get_property('guest_id')
                }
            try:
                status = virtual_machine.get_status()
            except Exception, e:
                print "Couldn't do it: %s" % e
                vm_infos['powered'] = 'none'
                report.append(vm_infos)
                continue
            if status == "POWERED ON":
                vm_infos['powered'] = 'on'
                # Get version in ssh 
                ssh = subprocess.Popen([
                  "ssh", 
                  "-i ~/.ssh/id_rsa", 
                  "%s" % vm_infos['name'],
                  "cat /etc/redhat-release"],
                  shell=False,  stdout=subprocess.PIPE, stderr=subprocess.PIPE
                )
                release = ssh.stdout.readlines()
                if release == []:
                    error = ssh.stderr.readlines()
                    vm_infos['release'] = "error: " + error
                else:
                    regex = re.compile("release (\d.*).+\(\D*(\d*)\)")
                    r = regex.search(release[0])
                    release = r.groups()
                    if release[1].strip():
                        vm_infos['release'] = release[0] + "." + release[1]
                    else:
                        vm_infos['release'] = release[0]
            else:
                vm_infos['powered'] = 'off'
        report.append(vm_infos)

        return report
开发者ID:Pryz,项目名称:misc,代码行数:69,代码来源:report.py

示例14: Stack

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
class Stack(SimpleStack):

    state_translation = {"POWERED ON": "STARTED", "POWERED OFF": "STOPPED", "SUSPENDED": "PAUSED"}

    def __init__(self, poolinfo):
        self.connection = False
        self.poolinfo = poolinfo
        self.format_for = Formatter()
        self.connect()

    def libvirt_connect(self):
        self.libvirt_connection = libvirt.open(
            "esx://%[email protected]%s/" % (self.poolinfo.get("username"), self.poolinfo.get("api_server"))
        )

    def connect(self):
        self.connection = VIServer()
        self.connection.connect(
            self.poolinfo.get("api_server"), self.poolinfo.get("username"), self.poolinfo.get("password")
        )
        return

    def pool_info(self):
        return self.format_for.pool(0, 0, self.poolinfo.get("api_server"))

    def guest_list(self):
        return [
            {"id": self.connection.get_vm_by_path(path).properties.name}
            for path in self.connection.get_registered_vms(cluster=self.poolinfo.get("cluster"))
        ]

    def guest_info(self, guest_id):
        vm = self._vm_ref(guest_id)
        return self._vm_info(vm)

    def guest_shutdown(self, guest_id, force=False):
        vm = self._vm_ref(guest_id)
        if force:
            return vm.power_off()
        else:
            return vm.shutdown_guest()

    def guest_start(self, guest_id):
        vm = self._vm_ref(guest_id)
        return vm.power_on()

    def guest_reboot(self, guest_id, force=False):
        vm = self._vm_ref(guest_id)
        if force:
            return vm.reset()
        else:
            return vm.reboot_guest()

    def guest_suspend(self, guest_id):
        vm = self._vm_ref(guest_id)
        return vm.suspend()

    def guest_resume(self, guest_id):
        return self.guest_start(guest_id)

    def guest_update(self, guest_id, guestdata):
        vm = self._vm_ref(guest_id)
        vmware.update_vm(self.connection, vm, guestdata)
        return self._vm_info(self._vm_ref(guest_id))

    def guest_delete(self, guest_id):
        vm = self._vm_ref(guest_id)
        vmware.delete_vm(self.connection, vm)

    def media_mount(self, guest_id, media_data):
        vm = self._vm_ref(guest_id)
        vmware.update_vm(self.connection, vm, {"iso": media_data})

    def media_info(self, guest_id):
        vm = self._vm_ref(guest_id)
        media = vmware.get_cd(vm)
        if media.connectable.connected:
            return {"name": media.backing.fileName}
        else:
            return {"name": None}

    def network_interface_list(self, guest_id):
        vm = self._vm_ref(guest_id)
        vifs = vmware.get_network_interfaces(vm)
        return [self._network_interface_info(n) for n in vifs]

    def network_interface_info(self, guest_id, network_interface_id):
        vm = self._vm_ref(guest_id)
        vifs = vmware.get_network_interfaces(vm)

        for vif in vifs:
            if vif.macAddress == network_interface_id:
                return self._network_interface_info(vif)

        entity_info = "%s - on Guest %s" % (network_interface_id, guest_id)
        raise EntityNotFound("NetworkInterface", entity_info)

    def snapshot_list(self, guest_id):
        vm = self._vm_ref(guest_id)
        snaps = [self._snapshot_info(s) for s in vm.get_snapshots()]
#.........这里部分代码省略.........
开发者ID:akaKuruma,项目名称:simplestack,代码行数:103,代码来源:vmware.py

示例15: VIServer

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_vm_by_path [as 别名]
#!/usr/bin/env python
from pysphere import VIServer

server = VIServer()
server.connect("my.esx.host.example.org", "username", "secret")

vm = server.get_vm_by_path("[datastore] path/to/file.vmx")
vm.wait_for_tools()
vm.login_in_guest("Administrator", "secret")
vm.get_screenshot("vm_screenshot.png", overwrite=True)

server.disconnect()
开发者ID:Alsan,项目名称:pySphere,代码行数:14,代码来源:get_screenshot.py


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