當前位置: 首頁>>代碼示例>>Python>>正文


Python VCA.get_vdc_references方法代碼示例

本文整理匯總了Python中pyvcloud.vcloudair.VCA.get_vdc_references方法的典型用法代碼示例。如果您正苦於以下問題:Python VCA.get_vdc_references方法的具體用法?Python VCA.get_vdc_references怎麽用?Python VCA.get_vdc_references使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyvcloud.vcloudair.VCA的用法示例。


在下文中一共展示了VCA.get_vdc_references方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _login_user_to_service

# 需要導入模塊: from pyvcloud.vcloudair import VCA [as 別名]
# 或者: from pyvcloud.vcloudair.VCA import get_vdc_references [as 別名]
 def _login_user_to_service(self, user, host, password, service_type,
                            service_version, service, org_name):
     vca = VCA(host, user, service_type, service_version)
     result = vca.login(password=password)
     if result:
         if service_type == 'subscription':
             if not service:
                 if org_name:
                     service = org_name
                 else:
                     services = vca.services.get_Service()
                     if not services:
                         return None
                     service = services[0].serviceId
             if not org_name:
                 org_name = vca.get_vdc_references(service)[0].name
             result = vca.login_to_org(service, org_name)
         if result:
             return vca
     return
開發者ID:Cloudify-PS,項目名稱:walle-service,代碼行數:22,代碼來源:common.py

示例2: VCAInventory

# 需要導入模塊: from pyvcloud.vcloudair import VCA [as 別名]
# 或者: from pyvcloud.vcloudair.VCA import get_vdc_references [as 別名]

#.........這裏部分代碼省略.........
	for j in vdcs:
            actual_vdc = j.name
            j.name = self.to_safe(j.name)
	    self.results[j.name] = dict(children=[])
	    org_children.append(j.name)
	    vapps = self.get_vapps(self.vca, j.name) 
	    for k in vapps:
                k['vapp_name'] = self.to_safe(k['vapp_name'])
	        self.results[j.name]['children'].append(k['vapp_name'])
	        self.results[k['vapp_name']] = k['vms']
	self.results[self.org] = dict(children=org_children)
	self.results['_meta'] = self.meta
        cache_name = '__inventory_all__' + self.service_type
        self._put_cache(cache_name, self.results)
        return self.results

    def get_inventory_vca(self):

        if not self.vca.login(password=self.password):
            sys.stdout.write("Login Failed: Please check username or password")
            sys.exit(1)
	instances_dict = self.vca.get_instances()
	for i in instances_dict:
	    instance = i['id']
#	    region   = i['id']
	    region   = i['region']
            region   = self.to_safe(region.split('.')[0])
	    region_children = []
	    if len(instance) != 36:
	        continue
	    if not self.vca.login_to_instance(password=self.password, instance=instance, token=None, org_url=None):
	        sys.stdout.write( "Login to Instance failed: Seems like instance provided is wrong .. Please check")
	        sys.exit(1)
	    if not self.vca.login_to_instance(instance=instance, password=None, token=self.vca.vcloud_session.token, 
	                                 org_url=self.vca.vcloud_session.org_url):
	        sys.stdout.write("Error logging into org for the instance %s" %instance)
	    vdcs = self.get_vdcs(self.vca)
	    for j in vdcs:
                j.name = self.to_safe(j.name)
	        self.results[region + '_' + j.name] = dict(children=[])
	        region_children.append(region + '_' + j.name)
	        vapps = self.get_vapps(self.vca, j.name) 
	        for k in vapps:
                    k['vapp_name'] = self.to_safe(k['vapp_name'])
	            self.results[region + '_' + j.name]['children'].append(region + '_' + j.name + '_' + k['vapp_name'])
	            self.results[region + '_' + j.name + '_' + k['vapp_name']] = k['vms']
	    self.results[region] = dict(children=region_children)
	
	self.results['_meta'] = self.meta
        cache_name = '__inventory_all__' + self.service_type
        self._put_cache(cache_name, self.results)
        return self.results
    
    def get_inventory_vchs(self):
        
        if not self.vca.login(password=self.password):
            sys.stdout.write("Login Failed: Please check username or password, errors: %s" %(self.vca.response))
            sys.exit(1)
        
        if not self.vca.login(token=self.vca.token):
            sys.stdout.write("Failed to get the token")
            sys.exit(1)

        if self.vca.services:
            table = []
            for s in self.vca.services.get_Service():
                for vdc in self.vca.get_vdc_references(s.serviceId):
                    table.append(dict(service=s.serviceId, service_type=s.serviceType, region=s.region,\
                                      vdc=vdc.name, status=vdc.status))  
            for i in table:
                if i['service'] != i['vdc']:
                    self.results[i['service']] = dict(children=[i['vdc']])
                region = i['vdc']
                region = self.to_safe(region)
                self.results[region] = dict(children=[])
                if not self.vca.login_to_org(i['service'], i['vdc']):
                    sys.stdout.write("Failed to login to org, Please check the orgname")
	        vapps = self.get_vapps(self.vca, i['vdc']) 
	        for k in vapps:
                    k['vapp_name'] = self.to_safe(k['vapp_name'])
	            self.results[region]['children'].append(region + '_' + k['vapp_name'])
	            self.results[region + '_' + k['vapp_name']] = k['vms']

	self.results['_meta'] = self.meta
        cache_name = '__inventory_all__' + self.service_type
        self._put_cache(cache_name, self.results)
        return self.results
	

    def get_inventory(self):
        cache_name = '__inventory_all__' + self.service_type
        inv = self._get_cache(cache_name, None)
        if inv is not None:
            return inv
        if self.service_type == 'ondemand':
            return self.get_inventory_vca()
        if self.service_type == 'subscription':
            return self.get_inventory_vchs()
        if self.service_type == 'vcd':
            return self.get_inventory_vcd()
開發者ID:vmware,項目名稱:vca-codesamples,代碼行數:104,代碼來源:vca.py


注:本文中的pyvcloud.vcloudair.VCA.get_vdc_references方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。