本文整理汇总了Python中pysphere.VIServer类的典型用法代码示例。如果您正苦于以下问题:Python VIServer类的具体用法?Python VIServer怎么用?Python VIServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VIServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv=None):
if argv is None:
argv=sys.argv
server = VIServer()
try:
server.connect(sys.argv[1], sys.argv[2], sys.argv[3])
hosts = server.get_hosts()
for h_mor, h_name in hosts.items():
props = VIProperty(server, h_mor)
try:
f = open("/tmp/esxi_hosts_" + sys.argv[1] + ".txt", "w")
try:
f.write("memorySize=" + str(props.hardware.memorySize) + "\n")
f.write("overallCpuUsage=" + str(props.summary.quickStats.overallCpuUsage) + "\n")
f.write("overallMemoryUsage=" + str(props.summary.quickStats.overallMemoryUsage) + "\n")
f.write("uptime=" + str(props.summary.quickStats.uptime) + "\n")
# $CPUTotalMhz = $_.Summary.hardware.CPUMhz * $_.Summary.Hardware.NumCpuCores
# $row."CpuUsage%" = [math]::round( ($row.CpuUsageMhz / $CPUTotalMhz), 2) * 100
f.write("cpuMhz=" + str(props.summary.hardware.cpuMhz) + "\n")
f.write("numCpuCores=" + str(props.summary.hardware.numCpuCores) + "\n")
finally:
f.close()
except IOError:
print "0"
sys.exit(0)
示例2: viConnect
def viConnect(vCenter,username,password,vmname):
server = VIServer()
server.connect(vCenter,username,password)
#print "vCenter: {} User: {} Pass: {}".format(vCenter,username,password)
#return server
#print viConnect("192.168.219.129","root","vmware")
return getVm(server,vmname)
示例3: esx_connect
def esx_connect(host, user, password):
esx = VIServer()
try:
esx.connect(host, user, password)
except VIApiException, e:
print("There was an error while connecting to esx: %s" % e)
return 1
示例4: connect_VI
def connect_VI(vcenter_hostname, user, password):
# Create the connection to vCenter Server
server = VIServer()
try:
server.connect(vcenter_hostname, user, password)
except VIApiException, err:
module.fail_json(msg="Cannot connect to %s: %s" % (vcenter_hostname, err))
示例5: _connect_server
def _connect_server(bot):
try:
server = VIServer()
server.connect(bot.config.pysphere.server, bot.config.pysphere.login, bot.config.pysphere.password)
except Exception, e:
bot.say("No connection to the server")
return False
示例6: connectToHost
def connectToHost(host,host_user,host_pw):
#create server object
s=VIServer()
#connect to the host
try:
s.connect(host,host_user,host_pw)
return s
示例7: host_connect
def host_connect(host):
""" Connect to a host. """
server = VIServer()
server.connect(host, CREDS.get('Host', 'user'),
CREDS.get('Host', 'pass'))
return server
示例8: main
def main():
u"""Main method
Create session.
Excute subcommand.
"""
# Import
import socket
import getpass
import sys
from pysphere import VIApiException, VIServer
import argument
# Get argument
args = argument.args()
s = VIServer()
# Set information
host = args.host if args.host else raw_input('Host> ')
user = args.user if args.user else raw_input('User> ')
passwd = args.passwd if args.passwd else getpass.getpass('Password> ')
try:
print 'Connecting...'
s.connect(host, user, passwd)
# Execute function
args.func(args, s)
except socket.error:
print >> sys.stderr, "Cannot connected."
except VIApiException:
print >> sys.stderr, "Incorrect user name or password."
except Exception, e:
print >> sys.stderr, e.message
示例9: get_connection
def get_connection(host_ip, username, password):
server = VIServer()
if host_ip is not None and username is not None and password is not None:
server.connect(host_ip, username, password)
else:
return None
return server
示例10: main
def main():
vm = None
module = AnsibleModule(
argument_spec=dict(
vcenter_hostname=dict(required=True, type='str'),
vcenter_username=dict(required=True, type='str'),
vcenter_password=dict(required=True, type='str'),
datacenter_name=dict(required=True, type='str'),
folder_structure=dict(required=True, type='list'),
guest_list=dict(required=True, type='list'),
),
supports_check_mode=False,
)
if not HAS_PYSPHERE:
module.fail_json(msg='pysphere module required')
vcenter_hostname = module.params['vcenter_hostname']
vcenter_username = module.params['vcenter_username']
vcenter_password = module.params['vcenter_password']
guest_list = module.params['guest_list']
folder_structure = module.params['folder_structure']
base_datacenter = module.params['datacenter_name']
# CONNECT TO THE SERVER
viserver = VIServer()
try:
viserver.connect(vcenter_hostname, vcenter_username, vcenter_password)
except VIApiException, err:
module.fail_json(msg="Cannot connect to %s: %s" %
(vcenter_hostname, err))
示例11: vcenter_connect
def vcenter_connect():
""" Connect to the vcenter. """
server = VIServer()
server.connect(CREDS.get('Vcenter', 'server'),
CREDS.get('Vcenter', 'user'),
CREDS.get('Vcenter', 'pass'))
return server
示例12: __init__
def __init__(self, vcip, vcuser, vcpassword, dc, clu):
self.vcip = vcip
self.translation = {'POWERED OFF':'down', 'POWERED ON':'up'}
s = VIServer()
s.connect(vcip, vcuser, vcpassword)
self.s = s
self.clu = clu
self.dc = dc
示例13: VSphereConnection
class VSphereConnection(ConnectionUserAndKey):
def __init__(self, user_id, key, secure=True,
host=None, port=None, url=None, timeout=None, **kwargs):
if host and url:
raise ValueError('host and url arguments are mutually exclusive')
if host:
host_or_url = host
elif url:
host_or_url = url
else:
raise ValueError('Either "host" or "url" argument must be '
'provided')
self.host_or_url = host_or_url
self.client = None
super(VSphereConnection, self).__init__(user_id=user_id,
key=key, secure=secure,
host=host, port=port,
url=url, timeout=timeout,
**kwargs)
def connect(self):
self.client = VIServer()
trace_file = os.environ.get('LIBCLOUD_DEBUG', None)
try:
self.client.connect(host=self.host_or_url, user=self.user_id,
password=self.key,
sock_timeout=DEFAULT_CONNECTION_TIMEOUT,
trace_file=trace_file)
except Exception:
e = sys.exc_info()[1]
message = e.message
if hasattr(e, 'strerror'):
message = e.strerror
fault = getattr(e, 'fault', None)
if fault == 'InvalidLoginFault':
raise InvalidCredsError(message)
raise LibcloudError(value=message, driver=self.driver)
atexit.register(self.disconnect)
def disconnect(self):
if not self.client:
return
try:
self.client.disconnect()
except Exception:
# Ignore all the disconnect errors
pass
def run_client_method(self, method_name, **method_kwargs):
method = getattr(self.client, method_name, None)
return method(**method_kwargs)
示例14: conexion_viserver
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
示例15: connectToHost
def connectToHost(host,host_user,host_pw):
#create server object
s=VIServer()
#connect to the host
try:
s.connect(host,host_user,host_pw)
return s
except VIApiException, err:
print "Cannot connect to host: '%s', error message: %s" %(host,err)