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


Python api.API类代码示例

本文整理汇总了Python中ovirtsdk.api.API的典型用法代码示例。如果您正苦于以下问题:Python API类的具体用法?Python API怎么用?Python API使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _initialize_api

def _initialize_api(hostname, username, password, ca, insecure):
    """
    Initialize the oVirt RESTful API
    """
    url = 'https://{hostname}/ovirt-engine/api'.format(
        hostname=hostname,
    )
    api = API(url=url,
              username=username,
              password=password,
              ca_file=ca,
              validate_cert_chain=not insecure)
    pi = api.get_product_info()
    if pi is not None:
        vrm = '%s.%s.%s' % (
            pi.get_version().get_major(),
            pi.get_version().get_minor(),
            pi.get_version().get_revision()
        )
        logging.debug("API Vendor(%s)\tAPI Version(%s)" % (
            pi.get_vendor(), vrm)
        )
    else:
        api.test(throw_exception=True)
    return api
开发者ID:nijinashok,项目名称:ovirt-log-collector,代码行数:25,代码来源:hypervisors.py

示例2: run

def run(**kwargs):
    """Calls all the functions needed to upload new template to RHEVM.
       This is called either by template_upload_all script, or by main function.

    Args:
        **kwargs: Kwargs generated from cfme_data['template_upload']['template_upload_rhevm'].
    """
    ovaname = get_ova_name(kwargs.get('image_url'))

    mgmt_sys = cfme_data['management_systems'][kwargs.get('provider')]

    rhevurl = mgmt_sys['hostname']
    rhevm_credentials = mgmt_sys['credentials']
    username = credentials[rhevm_credentials]['username']
    password = credentials[rhevm_credentials]['password']
    ssh_rhevm_creds = mgmt_sys['hosts'][0]['credentials']
    sshname = credentials[ssh_rhevm_creds]['username']
    sshpass = credentials[ssh_rhevm_creds]['password']
    rhevip = mgmt_sys['ipaddress']

    apiurl = 'https://%s:443/api' % rhevurl

    ssh_client = make_ssh_client(rhevip, sshname, sshpass)
    api = API(url=apiurl, username=username, password=password,
              insecure=True, persistent_auth=False)

    template_name = kwargs.get('template_name', None)
    if template_name is None:
        template_name = cfme_data['basic_info']['appliance_template']

    kwargs = update_params_api(api, **kwargs)

    check_kwargs(**kwargs)

    if api.templates.get(template_name) is not None:
        print "RHEVM: Found finished template with this name."
        print "RHEVM: The script will now end."
    else:
        print "RHEVM: Downloading .ova file..."
        download_ova(ssh_client, kwargs.get('image_url'))
        try:
            print "RHEVM: Templatizing .ova file..."
            template_from_ova(api, username, password, rhevip, kwargs.get('edomain'),
                              ovaname, ssh_client)
            print "RHEVM: Importing new template..."
            import_template(api, kwargs.get('edomain'), kwargs.get('sdomain'),
                            kwargs.get('cluster'))
            print "RHEVM: Making a temporary VM from new template..."
            make_vm_from_template(api, kwargs.get('cluster'))
            print "RHEVM: Adding disk to created VM..."
            add_disk_to_vm(api, kwargs.get('sdomain'), kwargs.get('disk_size'),
                           kwargs.get('disk_format'), kwargs.get('disk_interface'))
            print "RHEVM: Templatizing VM..."
            templatize_vm(api, template_name, kwargs.get('cluster'))
        finally:
            cleanup(api, kwargs.get('edomain'), ssh_client, ovaname)
            ssh_client.close()
            api.disconnect()

    print "RHEVM: Done."
开发者ID:seandst,项目名称:cfme_tests,代码行数:60,代码来源:template_upload_rhevm.py

示例3: conn

def conn(url, user, password):
    api = API(url=url, username=user, password=password, insecure=True)
    try:
        value = api.test()
    except:
        print "error connecting to the oVirt API"
        sys.exit(1)
    return api
开发者ID:conlini,项目名称:frozen-ansible,代码行数:8,代码来源:ovirt.py

示例4: get_connection

def get_connection(location):
    api = API(  url="https://" + locations.get(location, "host"),
                username=locations.get(location, "username"),
                password=locations.get(location, "password"),
                ca_file=locations.get(location, "certificate")
                )

    print "Connected to %s successfully!" % api.get_product_info().name
    return api
开发者ID:fatherlinux,项目名称:service-cart,代码行数:9,代码来源:helpers.py

示例5: main

def main():
    url='https://vm-rhevm01.infoplus-ot.ris:443/api'
    username='[email protected]'
    password=getpass.getpass("Supply password for user %s: " % username)

    api = API(url=url, username=username, password=password,insecure=True)
    vm_list=api.vms.list()
    for vm in vm_list:
        print vm.name
    api.disconnect()
开发者ID:Fabian1976,项目名称:python-ovirt-foreman-api,代码行数:10,代码来源:ovirt_list-vm.py

示例6: main

def main():
    URL='https://<ovirt-host>:443/api'
    USERNAME='[email protected]'
    PASSWORD='secretpass'

    api = API(url=URL, username=USERNAME, password=PASSWORD,insecure=True)
    vm_list=api.vms.list()
    for vm in vm_list:
        print vm.name
    api.disconnect()
开发者ID:DKrul,项目名称:python-hypervisor-api,代码行数:10,代码来源:ovirt_list-vm.py

示例7: main

def main():
	URL = 'https://192.168.1.112:443/api'
	USERNAME = '[email protected]'
	PASSWORD = 'mprc'
	api = API(url=URL, username=USERNAME, password=PASSWORD, insecure=True)
	vm = api.vms.get(name="ubuntu14.04")
	print vm.name
	#vm_list = api.vms.list()
	#for vm in vm_list:
	#	print vm.name
	api.disconnect()
开发者ID:zhjwpku,项目名称:myscripts,代码行数:11,代码来源:list_vm.py

示例8: start_vm

def start_vm(vm_name, host_ip):
    try:
        api = API(url="https://engine167.eayun.com", username="[email protected]", password="abc123", ca_file="ca.crt")

        vm = api.vms.get(name=vm_name)
        try:
            vm.start(action=params.Action(vm=params.VM(host=params.Host(address=host_ip))))
            print "Started '%s'." % vm.get_name()
        except Exception as ex:
            print "Unable to start '%s': %s" % (vm.get_name(), ex)

        api.disconnect()

    except Exception as ex:
        print "Unexpected error: %s" % ex
开发者ID:eayun,项目名称:eayunos-testscript,代码行数:15,代码来源:start_vm.py

示例9: on_pass

    def on_pass(self, button):
        self.api = API(url='https://127.0.0.1/api',
            username='[email protected]',
            password=self.w_password.edit_text.encode("ascii", "ignore"),
            insecure=True)
        if not self.api.vms.get(name=self.vm_name) == None:
            self.widget.set_popup_text("Vm named '%s' exists, please remove or rename it and try again" % self.vm_name)
            self.widget.open_pop_up()
            return

        divider = urwid.Divider("-")
        self.w_mgmt_profile = VnicProfileSelector(self.api, True, self.vnic_profile_changed_mgmt)
        self.w_int_profile = VnicProfileSelector(self.api, True, self.vnic_profile_changed_int)
        self.w_int_profile.set_ip_info(False)
        self.w_ext_profile = VnicProfileSelector(self.api, False, None)
        self.w_vm_pass = urwid.Edit(u"vm root password: ", mask="*")
        self.w_keystone_pass = urwid.Edit(u"keystone admin password: ", mask="*")
        self.widget.original_widget = urwid.Pile([
            urwid.Text(u"Deploying neutron appliance under datacenter 'Default'"),
            divider,
            urwid.Text("Choose profile for management network:"),
            self.w_mgmt_profile,
            divider,
            urwid.Text("Choose profile for internal network:"),
            self.w_int_profile,
            divider,
            urwid.Text("Choose profile for external network:"),
            self.w_ext_profile,
            divider,
            self.w_vm_pass,
            self.w_keystone_pass,
            divider,
            urwid.Button(u"OK", on_press=self.begin_deploy)
        ])
开发者ID:spofa,项目名称:eayunos-console,代码行数:34,代码来源:tabneutron.py

示例10: process

def process(api_url, username, password, cert_file=None):
    api = API(url=api_url,
              username=username,
              password=password,
              cert_file=cert_file,
              insecure=(not cert_file))
    print('Connected to %s' % api_url)

    problematic_vms = list(iter_problematic_vms(api))

    api.disconnect()

    if problematic_vms:
        print(build_search_criteria(problematic_vms, get_single_vm_criteria_by_name))
        print(build_search_criteria(problematic_vms, get_single_vm_criteria_by_id))
    else:
        print('All MAC addresses are in range')
开发者ID:yevgenyz,项目名称:ovirt-python-sdk-scripts,代码行数:17,代码来源:externalMacsVmsV3.py

示例11: __init__

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

        user = module.params.get('user')
        password = module.params.get('password')
        server = module.params.get('server')
        port = module.params.get('port')
        insecure_api = module.params.get('insecure_api')

        url = "https://%s:%s" % (server, port)

        try:
            api = API(url=url, username=user, password=password, insecure=str(insecure_api))
            api.test()
            self.conn = api
        except:
            raise Exception("Failed to connect to RHEV-M.")
开发者ID:awiddersheim,项目名称:ansible,代码行数:17,代码来源:rhevm.py

示例12: _init_api

 def _init_api(self):
     self.log.debug("Doing blocking acquire() on global RHEVM API connection lock")
     self.api_connections_lock.acquire()
     self.log.debug("Got global RHEVM API connection lock")
     url = self.api_details['url']
     username = self.api_details['username']
     password = self.api_details['password']
     self.api = API(url=url, username=username, password=password)
开发者ID:henrysher,项目名称:imagefactory,代码行数:8,代码来源:RHEVMHelper.py

示例13: start_vms

def start_vms(vmObj):
logging.info('Thread to start %s', vmObj.name)
try:
vmObj.start()
#time.sleep(5)
except Exception as e:
logging.debug('Exception caught on VM ( %s) start:\n%s' % (vmObj.name, str(e)))
failedVms.append(vmObj.name)
if __name__ == "__main__":
   try:	
        api = API(url=APIURL,
              username=APIUSER,
              password=APIPASS,
              ca_file=CAFILE)
              print 'Connected to oVIRT API %s Successfully' % APIURL
              logging.info ( 'Successfully Connected to %s' % APIURL)
     try:
print ' \n I am logging in %s \n' % LOGFILENAME
vmsList = api.vms.list()
for i in vmsList:
print i.name
if i.status.state != 'up':
logging.warning('%s is not up, trying to start it' % i.name)
threadMe = Thread(target=start_vms, args=[i])
threadMe.start()
threads.append(threadMe)
     except Exception as e:
         logging.debug('Error:\n%s' % str(e))
    
     logging.warning ('No of VMs to start : %s' % len(threads))
     print 'No of VMs to start: %s' % len(threads)
     for th in threads:
logging.info ('Waiting for %s to join' % th)
th.join (30)
if not th.isAlive():
logging.info ('Thread : %s terminated' % (th.getName()))

else:
logging.debug( 'Thread : %s is still alive, you may check this task..' % (th))
logging.debug (' Below Vms failed to start with an exception:%s' % (failedVms));
     api.disconnect()


   except Exception as ex:
    logging.debug('Unexpected error: %s' % ex)
开发者ID:vikramzmail,项目名称:foss_vm,代码行数:45,代码来源:start-vm.py

示例14: __init__

    def __init__(self, hostname, username, password, **kwargs):
        # generate URL from hostname

        if 'port' in kwargs:
            url = 'https://%s:%s/api' % (hostname, kwargs['port'])
        else:
            url = 'https://%s/api' % hostname

        self.api = API(url=url, username=username, password=password, insecure=True)
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:9,代码来源:mgmt_system.py

示例15: __init__

    def __init__(self, hostname='localhost', username='root', password='rootpwd'):
        """ Initialize RHEVMSystem """
        # sanitize hostname
        if not hostname.startswith('https://'):
            hostname = 'https://%s' % hostname
        if not hostname.endswith('/api'):
            hostname = '%s/api' % hostname

        self.api = API(url=hostname, username=username, password=password, insecure=True)
开发者ID:aweiteka,项目名称:cfme_tests,代码行数:9,代码来源:mgmt_system.py


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