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


Python DoManager.all_domains方法代碼示例

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


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

示例1: load_all_data_from_digital_ocean

# 需要導入模塊: from dopy.manager import DoManager [as 別名]
# 或者: from dopy.manager.DoManager import all_domains [as 別名]
    def load_all_data_from_digital_ocean(self):
        ''' Use dopy to get all the information from DigitalOcean and save data in cache files '''
        manager  = DoManager(None, self.access_token, api_version=2)

        self.data = {}
        self.data['droplets'] = manager.all_active_droplets()
        self.data['regions']  = manager.all_regions()
        self.data['images']   = manager.all_images(filter=None)
        self.data['sizes']    = manager.sizes()
        self.data['ssh_keys'] = manager.all_ssh_keys()
        self.data['domains']  = manager.all_domains()
        self.index = {}
        self.index['region_to_name']  = self.build_index(self.data['regions'], 'name', 'slug')
        self.index['size_to_name']    = self.build_index(self.data['sizes'], 'memory', 'slug')
        self.index['image_to_name']   = self.build_index(self.data['images'], 'id', 'name')
        self.index['image_to_distro'] = self.build_index(self.data['images'], 'id', 'distribution')
	self.index['host_to_droplet'] = self.build_index(self.data['droplets'], 'ip_address', 'id', False)
        self.build_inventory()

        self.write_to_cache()
開發者ID:galal-hussein,項目名稱:ansible-for-devops,代碼行數:22,代碼來源:digital_ocean_v2.py

示例2: DigitalOceanInventory

# 需要導入模塊: from dopy.manager import DoManager [as 別名]
# 或者: from dopy.manager.DoManager import all_domains [as 別名]

#.........這裏部分代碼省略.........
            self.args.list = True


    ###########################################################################
    # Data Management
    ###########################################################################

    def load_from_digital_ocean(self, resource=None):
        '''Get JSON from DigitalOcean API'''
        if self.args.force_cache:
            return
        # We always get fresh droplets
        if self.is_cache_valid() and not (resource=='droplets' or resource is None):
            return
        if self.args.refresh_cache:
            resource=None

        if resource == 'droplets' or resource is None:
            self.data['droplets'] = self.manager.all_active_droplets()
            self.cache_refreshed = True
        if resource == 'regions' or resource is None:
            self.data['regions'] = self.manager.all_regions()
            self.cache_refreshed = True
        if resource == 'images' or resource is None:
            self.data['images'] = self.manager.all_images(filter=None)
            self.cache_refreshed = True
        if resource == 'sizes' or resource is None:
            self.data['sizes'] = self.manager.sizes()
            self.cache_refreshed = True
        if resource == 'ssh_keys' or resource is None:
            self.data['ssh_keys'] = self.manager.all_ssh_keys()
            self.cache_refreshed = True
        if resource == 'domains' or resource is None:
            self.data['domains'] = self.manager.all_domains()
            self.cache_refreshed = True


    def build_inventory(self):
        '''Build Ansible inventory of droplets'''
        self.inventory = {}

        # add all droplets by id and name
        for droplet in self.data['droplets']:
            #when using private_networking, the API reports the private one in "ip_address".
            if 'private_networking' in droplet['features'] and not self.use_private_network:
                for net in droplet['networks']['v4']:
                    if net['type']=='public':
                        dest=net['ip_address']
                    else:
                        continue
            else:
                dest = droplet['ip_address']

            dest = { 'hosts': [ dest ], 'vars': self.group_variables }

            self.inventory[droplet['id']] = dest
            self.inventory[droplet['name']] = dest
            self.inventory['region_' + droplet['region']['slug']] = dest
            self.inventory['image_' + str(droplet['image']['id'])] = dest
            self.inventory['size_' + droplet['size']['slug']] = dest

            image_slug = droplet['image']['slug']
            if image_slug:
                self.inventory['image_' + self.to_safe(image_slug)] = dest
            else:
                image_name = droplet['image']['name']
開發者ID:ChrisSSocha,項目名稱:chris.socha.technology,代碼行數:70,代碼來源:digital_ocean.py

示例3: DigitalOceanInventory

# 需要導入模塊: from dopy.manager import DoManager [as 別名]
# 或者: from dopy.manager.DoManager import all_domains [as 別名]

#.........這裏部分代碼省略.........
        ):
            self.args.list = True

    ###########################################################################
    # Data Management
    ###########################################################################

    def load_from_digital_ocean(self, resource=None):
        """Get JSON from DigitalOcean API"""
        if self.args.force_cache:
            return
        # We always get fresh droplets
        if self.is_cache_valid() and not (resource == "droplets" or resource is None):
            return
        if self.args.refresh_cache:
            resource = None

        if resource == "droplets" or resource is None:
            self.data["droplets"] = self.manager.all_active_droplets()
            self.cache_refreshed = True
        if resource == "regions" or resource is None:
            self.data["regions"] = self.manager.all_regions()
            self.cache_refreshed = True
        if resource == "images" or resource is None:
            self.data["images"] = self.manager.all_images(filter=None)
            self.cache_refreshed = True
        if resource == "sizes" or resource is None:
            self.data["sizes"] = self.manager.sizes()
            self.cache_refreshed = True
        if resource == "ssh_keys" or resource is None:
            self.data["ssh_keys"] = self.manager.all_ssh_keys()
            self.cache_refreshed = True
        if resource == "domains" or resource is None:
            self.data["domains"] = self.manager.all_domains()
            self.cache_refreshed = True

    def build_inventory(self):
        """Build Ansible inventory of droplets"""
        self.inventory = {}

        # add all droplets by id and name
        for droplet in self.data["droplets"]:
            dest = droplet["ip_address"]

            self.inventory[droplet["id"]] = [dest]
            self.push(self.inventory, droplet["name"], dest)
            self.push(self.inventory, "region_" + droplet["region"]["slug"], dest)
            self.push(self.inventory, "image_" + str(droplet["image"]["id"]), dest)
            self.push(self.inventory, "size_" + droplet["size"]["slug"], dest)

            image_slug = droplet["image"]["slug"]
            if image_slug:
                self.push(self.inventory, "image_" + self.to_safe(image_slug), dest)
            else:
                image_name = droplet["image"]["name"]
                if image_name:
                    self.push(self.inventory, "image_" + self.to_safe(image_name), dest)

            self.push(self.inventory, "distro_" + self.to_safe(droplet["image"]["distribution"]), dest)
            self.push(self.inventory, "status_" + droplet["status"], dest)

    def load_droplet_variables_for_host(self):
        """Generate a JSON response to a --host call"""
        host = int(self.args.host)

        droplet = self.manager.show_droplet(host)
開發者ID:ferhaty,項目名稱:ansible,代碼行數:70,代碼來源:digital_ocean.py


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