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


Python VIServer.get_api_version方法代码示例

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


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

示例1: test_vmware_version_vcenter

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
 def test_vmware_version_vcenter(self):
     """ Is the Vmware version at 5.1?"""
     server = VIServer()
     server.connect(CREDS.get('Vcenter', 'server'),
                    CREDS.get('Vcenter', 'user'),
                    CREDS.get('Vcenter', 'pass'))
     api = server.get_api_version()
     self.assertEqual('5.1', api)
     server.disconnect()
开发者ID:gcavalcante8808,项目名称:vunit,代码行数:11,代码来源:vmwtest.py

示例2: conexion_viserver

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
    def conexion_viserver(self):
        self.logger.debug(self)
        esxi = VIServer()
        esxi.connect(self.creds['ip'], self.creds['user'],
                     self.creds['pw'], trace_file=self.config.logpysphere)

        self.logger.debug("Conectado a %s %s", esxi.get_server_type(),
                          esxi.get_api_version())
        return esxi
开发者ID:dvinazza,项目名称:esxi-tools,代码行数:11,代码来源:host.py

示例3: setupConnection

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
def setupConnection(host, user, password):
        server = VIServer()

        try:
                server.connect(host, user, password)
                print "Host: " + host
                print "Version: " + server.get_server_type() + " " + server.get_api_version() + "\n"
                return server
        except Exception, err:
                print "Cannot connect to host: "+host+" error message: " +err.message
                sys.exit(2)
开发者ID:phpsystems,项目名称:vsphereenum,代码行数:13,代码来源:vsphere-enumvms.py

示例4: vConnect

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
def vConnect(VIHost, VIUser, VIPassword):
    """Verbindungs Funktion zum Server
    Baut eine Verbindung mit VCS Server auf und speichert die Verbindungsinformationen in der VISerever variable des Typs "VIServer".
    """
    logger.info("Connecting to vSphere: " + VIHost)
    VirtualServerInstance = VIServer()
    VirtualServerInstance.connect(VIHost, VIUser, VIPassword)
    if VirtualServerInstance:
        logger.info("Connected to vSphere: " + VIHost)
        logger.info(VirtualServerInstance.get_api_type() + " API " + VirtualServerInstance.get_api_version())
        return VirtualServerInstance
    else:
        logger.error("Connection to the vSphere failed.")
        sys.exit(2)
开发者ID:Lord-Simon,项目名称:Scripts,代码行数:16,代码来源:sdvmbc.py

示例5: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [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

示例6: main

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
def main():
    if len(sys.argv) <> 3:
        print ("Usage:")
        print (sys.argv[0], "<username> <password")

    username = sys.argv[1]
    password = sys.argv[2]

    vcenter = "ecnshmw1001.sh.cn.ao.ericsson.se"


    server = VIServer()
    server.connect( vcenter, username, password )
    print ("Login .....")
    type = server.get_api_type()
    version = server.get_api_version()

    print ("You are now connecting with {0} with API version {1}".format(type, version))


    select(server)
    server.disconnect()
开发者ID:leitu,项目名称:vmware,代码行数:24,代码来源:vmware_hostname.py

示例7: VIServer

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
    'verbose': False       # optional, defaults to False
}

vmindex = {}

server = VIServer()

default_context = ssl._create_default_https_context

try:
        ssl._create_default_https_context = ssl._create_unverified_context
        server.connect(esxurl, esxiserver['username'], esxiserver['password'])
finally:
    ##DO NOT DO the following line or else you'll get "ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed" error
    ##ssl._create_default_https_context = default_context
    print "vserver: AFTER CONNECTION - [{}] [{}]".format(server.get_server_type(), server.get_api_version())

def initargs():
    """ initialize variables with command-line arguments """
    parser = argparse.ArgumentParser(description='input -f [file]')
    parser.add_argument('-s', '--shutdown', \
        help='Shutdown ESX host', \
        action='store_true')
    parser.add_argument('-o', '--on', \
        help='Start Machines')

    arg = parser.parse_args()

    return arg

def poweronvm(vmpath):
开发者ID:suidroot,项目名称:Misc,代码行数:33,代码来源:LabManager.py

示例8: VMWareSystem

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]

#.........这里部分代码省略.........
            vm.power_on()
            ack = vm.get_status()
            if ack == 'POWERED ON':
                return True
        return False

    def stop_vm(self, vm_name):
        vm = self._get_vm(vm_name)
        if vm.is_powered_off():
            return True
        else:
            vm.power_off()
            ack = vm.get_status()
            if ack == 'POWERED OFF':
                return True
        return False

    def delete_vm(self, vm_name):
        vm = self._get_vm(vm_name)

        if vm.is_powered_on():
            self.stop_vm(vm_name)

        # When pysphere moves up to 0.1.8, we can just do:
        # vm.destroy()
        request = VI.Destroy_TaskRequestMsg()
        _this = request.new__this(vm._mor)
        _this.set_attribute_type(vm._mor.get_attribute_type())
        request.set_element__this(_this)
        rtn = self.api._proxy.Destroy_Task(request)._returnval

        task = VITask(rtn, self.api)
        status = task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR])
        if status == task.STATE_SUCCESS:
            return True
        else:
            return False

    def create_vm(self, vm_name):
        raise NotImplementedError('This function has not yet been implemented.')

    def restart_vm(self, vm_name):
        if not self.stop_vm(vm_name):
            return False
        else:
            return self.start_vm(vm_name)

    def list_vm(self, **kwargs):
        vm_list = self.api.get_registered_vms(**kwargs)

        # The vms come back in an unhelpful format, so run them through a regex
        # Example vm name: '[datastore] vmname/vmname.vmx'
        def vm_name_generator():
            for vm in vm_list:
                match = re.match(r'\[.*\] (.*)/\1\..*', vm)
                if match:
                    yield match.group(1)

        # Unroll the VM name generator, and sort it to be more user-friendly
        return sorted(list(vm_name_generator()))

    def info(self):
        return '%s %s' % (self.api.get_server_type(), self.api.get_api_version())

    def disconnect(self):
        self.api.disconnect()

    def vm_status(self, vm_name):
        state = self._get_vm(vm_name).get_status()
        print "vm " + vm_name + " status is " + state
        return state

    def is_vm_running(self, vm_name):
        state = self.vm_status(vm_name)
        return "POWERED ON" == state

    def is_vm_stopped(self, vm_name):
        state = self.vm_status(vm_name)
        return "POWERED OFF" == state

    def is_vm_suspended(self, vm_name):
        state = self.vm_status(vm_name)
        return "SUSPENDED" == state

    def suspend_vm(self, vm_name):
        vm = self._get_vm(vm_name)
        if vm.is_powered_off():
            raise Exception('Could not suspend %s because it\'s not running.' % vm_name)
        else:
            vm.suspend()
            return self.is_vm_suspended(vm_name)

    def clone_vm(self, source_name, vm_name, resourcepool=None):
        vm = self._get_vm(source_name)
        if vm:
            clone = vm.clone(vm_name, sync_run=True,
                resourcepool=self._get_resource_pool(resourcepool))
            return self._find_ip(clone)
        else:
            raise Exception('Could not clone %s' % source_name)
开发者ID:apagac,项目名称:cfme_pages,代码行数:104,代码来源:mgmt_system.py

示例9: VIServer

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
Install:

pip install pysphere

"""

from pysphere import VIServer
server = VIServer()

server.connect("serverip","adminuser","pass")

#Get server characteristics
print server.get_server_type()

print server.get_api_version()

print server.get_clusters()

print server._get_resource_pools

#Get all the hosts
print server.get_hosts()

#Get VM`s in Prod resource pool which are in poweredon state

vmachines = server.get_registered_vms()
vmachines = server.get_registered_vms(resource_pool='Prod', status='poweredOn')

#Get virtual machine status
vm1 = server.get_vm_by_name('rhel5.3_prod')
开发者ID:atassumer,项目名称:pycheat,代码行数:32,代码来源:api_vsphere.py

示例10: print

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
for s in envs:
    try:
        print(" Env: %s, vSphere Server: %s" %(s.upper(), urls[s]['suffix']))
    except Exception, e:
        continue

    try:
        server = VIServer()
        server.connect(r"%s" %urls[s]['suffix'], urls[s]['user'], urls[s]['pswrd'])
    except Exception, e:
        print(Fore.RED + Style.BRIGHT + " %s" %str(e))
        print

    try:
        print(Fore.GREEN + Style.BRIGHT + "  Server Type: %s" %server.get_server_type())
        print(Fore.GREEN + Style.BRIGHT + "  API Version: %s" %server.get_api_version())
    except Exception, e:
        print(Fore.RED + Style.BRIGHT + " %s" %str(e))
        print

    try:
        lstvms = server.get_registered_vms()
    except Exception, e:
        print(Fore.RED + Style.BRIGHT + " %s" %str(e))
        print

    for k in lnxrls:
        hstlst = []
        for v in lstvms:
            hstnme = v.split()[1].split('/')[0].lower()
            if hstnme.startswith(lnxrls[k]['role']):
开发者ID:richnusgeeks,项目名称:devops,代码行数:33,代码来源:get_vsphere_vms.py

示例11: print_verbose

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
server = args.server[0]
template = args.template[0]
username = args.username[0]
verbose = args.verbose
maxwait = args.maxwait[0]

# Asking Users password for server
password = getpass.getpass(prompt="Enter password for vCenter %s for user %s: " % (server, username))

# Connecting to server
print_verbose("Connecting to server %s with username %s" % (server, username))
con = VIServer()
con.connect(server, username, password)
print_verbose("Connected to server %s" % server)
print_verbose("Server type: %s" % con.get_server_type())
print_verbose("API version: %s" % con.get_api_version())

# Verify the template exists
print_verbose("Finding template %s" % template)
template_vm = find_vm(template)
if template_vm is None:
    print "ERROR: %s not found" % template
    sys.exit(1)
print_verbose("Template %s found" % template)

# Verify the target Resource Pool exists
resource_pool_mor = None
if resource_pool is not None:
    print_verbose("Finding resource pool %s" % resource_pool)
    resource_pool_mor = find_resource_pool(resource_pool)
    if resource_pool_mor is None:
开发者ID:justvarshney,项目名称:vSphere-Python,代码行数:33,代码来源:multi-clone.py

示例12: VMWareSystem

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]

#.........这里部分代码省略.........
            return True
        else:
            vm.power_off()
            ack = vm.get_status()
            if ack == 'POWERED OFF':
                return True
        return False

    def delete_vm(self, vm_name):
        vm = self._get_vm(vm_name)

        if vm.is_powered_on():
            self.stop_vm(vm_name)

        # When pysphere moves up to 0.1.8, we can just do:
        # vm.destroy()
        request = VI.Destroy_TaskRequestMsg()
        _this = request.new__this(vm._mor)
        _this.set_attribute_type(vm._mor.get_attribute_type())
        request.set_element__this(_this)
        rtn = self.api._proxy.Destroy_Task(request)._returnval

        task = VITask(rtn, self.api)
        status = task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR])
        if status == task.STATE_SUCCESS:
            return True
        else:
            return False

    def create_vm(self, vm_name):
        raise NotImplementedError('This function has not yet been implemented.')

    def restart_vm(self, vm_name):
        if not self.stop_vm(vm_name):
            return False
        else:
            return self.start_vm(vm_name)

    def list_vm(self):
        return self._get_list_vms()

    def list_template(self):
        return self._get_list_vms(get_template=True)

    def list_flavor(self):
        raise NotImplementedError('This function is not supported on this platform.')

    def list_host(self):
        return self.api.get_hosts()

    def list_datastore(self):
        return self.api.get_datastores()

    def list_cluster(self):
        return self.api.get_clusters()

    def info(self):
        return '%s %s' % (self.api.get_server_type(), self.api.get_api_version())

    def disconnect(self):
        self.api.disconnect()

    def vm_status(self, vm_name):
        state = self._get_vm(vm_name).get_status()
        print "vm " + vm_name + " status is " + state
        return state

    def is_vm_running(self, vm_name):
        state = self.vm_status(vm_name)
        return "POWERED ON" == state

    def is_vm_stopped(self, vm_name):
        state = self.vm_status(vm_name)
        return "POWERED OFF" == state

    def is_vm_suspended(self, vm_name):
        state = self.vm_status(vm_name)
        return "SUSPENDED" == state

    def suspend_vm(self, vm_name):
        vm = self._get_vm(vm_name)
        if vm.is_powered_off():
            raise Exception('Could not suspend %s because it\'s not running.' % vm_name)
        else:
            vm.suspend()
            return self.is_vm_suspended(vm_name)

    def clone_vm(self):
        raise NotImplementedError('clone_vm not implemented.')

    def deploy_template(self, template, *args, **kwargs):
        if 'resourcepool' not in kwargs:
            kwargs['resourcepool'] = None
        vm = self._get_vm(template)
        if vm:
            vm.clone(kwargs['vm_name'], sync_run=True,
                resourcepool=self._get_resource_pool(kwargs['resourcepool']))
            return kwargs['vm_name']
        else:
            raise Exception('Could not clone %s' % template)
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:104,代码来源:mgmt_system.py

示例13: setupConnection

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
def setupConnection(host, user, password, release):
        global Found
        global Fails

        try:
                server = VIServer()
                server.connect(host, user, password)
                print "[+] Password Found: " +password
                print "[+] Host: " + host + " Version: " + server.get_server_type() + " " + server.get_api_version() + "\n"
                closeConnection(server)
                Found =  True
        except Exception, err:
                if 'read_nonblocking' in str(err):
                        Fails += 1
                        time.sleep(5)
                        connect(host, user, password, False)
                elif 'synchronize with original prompt' in str(err):
                        time.sleep(1)
                        connect(host, user, password, False)
开发者ID:phpsystems,项目名称:vsphereenum,代码行数:21,代码来源:vsphere-brute.py

示例14: getserver_type_api

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
def getserver_type_api():
    """Display's the server type(vCenter or ESX) and also the VMWare API version"""
    s = VIServer()
    print 'Server Type: ', s.get_server_type()
    print 'API Version: ', s.get_api_version()
开发者ID:jonarm,项目名称:vm-mgmt,代码行数:7,代码来源:vm-mgmt.py

示例15: VIServer

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_api_version [as 别名]
# Asking Users password for server
if password is None:
	logger.debug('No command line password received, requesting password from user')
        password = getpass.getpass(prompt='Enter password for vCenter %s for user %s: ' % (servervctr,username))

# Connecting to server
logger.info('Connecting to server %s with username %s' % (servervctr,username))

server = VIServer()
try:
	logger.debug('Trying to connect with provided credentials')
	server.connect(servervctr,username,password)
	logger.info('Connected to server %s' % servervctr)
	logger.debug('Server type: %s' % server.get_server_type())
	logger.debug('API version: %s' % server.get_api_version())
except VIException as ins:
	logger.error(ins)
	logger.debug('Loggin error. Program will exit now.')
	sys.exit()
	
if dcname is None:
    logger.error('No datacenter name. Progam will exit now.')
    sys.exit()

# Setting up properties
logger.debug('Getting properties to query')

properties  = create_vm_props()
logger.debug('First set of properties: %s' %properties) 
开发者ID:jm66,项目名称:vsphere_inventory_report,代码行数:31,代码来源:vsphere_inventory_report.py


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