本文整理汇总了Python中pysphere.VIServer.get_server_type方法的典型用法代码示例。如果您正苦于以下问题:Python VIServer.get_server_type方法的具体用法?Python VIServer.get_server_type怎么用?Python VIServer.get_server_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysphere.VIServer
的用法示例。
在下文中一共展示了VIServer.get_server_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: conexion_viserver
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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
示例2: setupConnection
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [as 别名]
def setupConnection(host, user, password):
server = VIServer()
try:
server.connect(host, user, password)
print "[+] Host: " + host + " Version: " + server.get_server_type() + " " + server.get_api_version() + "\n"
closeConnection(server)
return True
except Exception, err:
print "[-] Cannot connect to host: "+host+" error message: " +err.message
return None
示例3: setupConnection
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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)
示例4: setupConnection
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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)
示例5: __init__
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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
示例6: print_verbose
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [as 别名]
if args.vmname:
vmname = args.vmname[0]
server = args.server[0]
username = args.username[0]
verbose = args.verbose
password = args.password[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())
if allvms:
vms = con.get_registered_vms(None, None, None, 'poweredOn', None)
for vmpath in vms:
print_verbose('================================================================================')
vm = con.get_vm_by_path(vmpath)
vmname = vm.get_property('name')
ip = find_ip(vm,ipv6)
if ip:
print '%s : %s' % (vmname,ip)
else:
print 'ERROR: IP for VM %s not found' % vmname
else:
print_verbose('================================================================================')
示例7: VMWareSystem
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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)
示例8: VIServer
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [as 别名]
# Asking Users password for server
if password is None:
logger.debug('No command line password received, requesting plain text password from user.')
password = getpass.getpass(prompt='Enter password for vCenter %s for user %s: ' % (server,username))
logger.debug(password)
# Connecting to server
logger.info('Connecting to server %s with username %s' % (server,username))
con = VIServer()
try:
logger.debug('Trying to connect with provided credentials')
con.connect(server,username,password)
logger.info('Connected to server %s' % server)
logger.debug('Server type: %s' % con.get_server_type())
logger.debug('API version: %s' % con.get_api_version())
except VIException as ins:
logger.error(ins)
logger.debug('Loggin error. Program will exit now.')
sys.exit()
try:
# Getting VM object
vm = find_vm(vmname, con)
if vm:
logger.info('Successfully found %s in %s' % (vm.get_property('name'), vm.get_property('path')))
else:
logger.error("Could not find %s, please verify VM's name and try again." % vm)
con.disconnect()
示例9: VMWareSystem
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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)
示例10: VIServer
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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')
示例11: print
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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()
示例12: print_verbose
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [as 别名]
resource_pool = args.resource_pool[0]
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)
示例13: VIServer
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [as 别名]
# Asking Users password for server
if password is None:
logger.debug("No command line password received, requesting plain text password from user.")
password = getpass.getpass(prompt="Enter password for vCenter %s for user %s: " % (server, username))
logger.debug(password)
# Connecting to server
logger.info("Connecting to server %s with username %s" % (server, username))
con = VIServer()
try:
logger.debug("Trying to connect with provided credentials")
con.connect(server, username, password)
logger.info("Connected to server %s" % server)
logger.debug("Server type: %s" % con.get_server_type())
logger.debug("API version: %s" % con.get_api_version())
except VIException as ins:
logger.error(ins)
logger.debug("Loggin error. Program will exit now.")
sys.exit()
try:
# Getting VM object
vm = find_vm(vmname, con)
if vm:
logger.info("Successfully found %s in %s" % (vm.get_property("name"), vm.get_property("path")))
else:
logger.error("Could not find %s, please verify VM's name and try again." % vm)
con.disconnect()
示例14: VIServer
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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):
示例15: getserver_type_api
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_server_type [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()