예제 #1
0
    def list_sizes(self, location=None):
        """
        List sizes on a provider.

        Abiquo does not work with sizes. However, this method
        returns a list of predefined ones (copied from :class:`DummyNodeDriver`
        but without price neither bandwidth) to help the users to create their
        own.

        If you call the method :class:`AbiquoNodeDriver.create_node` with the
        size informed, it will just override the 'ram' value of the 'image'
        template. So it is no too much usefull work with sizes...

        :return: The list of sizes
        :rtype:  ``list`` of :class:`NodeSizes`
        """
        return [
            NodeSize(id=1,
                     name='Small',
                     ram=128,
                     disk=4,
                     bandwidth=None,
                     price=None,
                     driver=self),
            NodeSize(id=2,
                     name='Medium',
                     ram=512,
                     disk=16,
                     bandwidth=None,
                     price=None,
                     driver=self),
            NodeSize(id=3,
                     name='Big',
                     ram=4096,
                     disk=32,
                     bandwidth=None,
                     price=None,
                     driver=self),
            NodeSize(id=4,
                     name="XXL Big",
                     ram=4096 * 2,
                     disk=32 * 4,
                     bandwidth=None,
                     price=None,
                     driver=self)
        ]
예제 #2
0
 def _to_size(self, data):
     return NodeSize(id=data['id'],
                     name=data['name'],
                     ram=data['ram'],
                     disk=data['disk_size'],
                     bandwidth=0,
                     price=0,
                     driver=self)
예제 #3
0
 def _to_size(self, plan):
     return NodeSize(id=plan['pricing_plan_code'],
                     name=plan['pricing_plan_description'],
                     ram=plan['minimum_memory_mb'],
                     disk=plan['minimum_disk_gb'],
                     bandwidth=plan['minimum_data_transfer_allowance_gb'],
                     price=plan['monthly_recurring_amt']['amt_usd'],
                     driver=self.connection.driver)
예제 #4
0
    def list_sizes(self, location=None):
        """
        VCL does not choosing sizes for node creation.
        Size of images are statically set by administrators.

        @inherits: :class:`NodeDriver.list_sizes`
        """
        return [NodeSize('t1.micro', 'none', '512', 0, 0, 0, self)]
예제 #5
0
    def list_sizes(self, **kwargs):
        sizes = []
        for key, values in self._sizes.items():
            attributes = copy.deepcopy(values)
            attributes.update({'price': self._get_size_price(size_id=key)})
            sizes.append(NodeSize(driver=self.connection.driver, **attributes))

        return sizes
예제 #6
0
 def _get_test_512Mb_node_size(self):
     return NodeSize(id='512Mb',
                     name=None,
                     ram=None,
                     disk=None,
                     bandwidth=None,
                     price=None,
                     driver=self.driver)
예제 #7
0
 def test_base_node_size(self):
     NodeSize(id=0,
              name=0,
              ram=0,
              disk=0,
              bandwidth=0,
              price=0,
              driver=FakeDriver())
 def list_sizes(self, location=None):
     szs = self._sync_request('listAvailableProductTypes')
     sizes = []
     for sz in szs['producttypes']:
         sizes.append(
             NodeSize(sz['diskofferingid'], sz['diskofferingdesc'], 0, 0, 0,
                      0, self))
     return sizes
예제 #9
0
 def test_create_node(self):
     image = NodeImage(id=11, name='ubuntu 8.10', driver=self.driver)
     size = NodeSize(
         1, '256 slice', None, None, None, None, driver=self.driver)
     node = self.driver.create_node(
         name='slicetest', image=image, size=size)
     self.assertEqual(node.name, 'slicetest')
     self.assertEqual(node.extra.get('password'), 'fooadfa1231')
예제 #10
0
    def __init__(self, **kwargs):
        """
        This init create one fixture node
        """

        self._images = {}
        self._images['u16-jhub-usernotebook'] = NodeImage(id=1, 
                                                          name="u16-jhub-usernotebook",
                                                          driver=self)
        self._images['deb8-jhub-usernotebook'] = NodeImage(id=2,
                                                           name="deb8-jhub-usernotebook",
                                                           driver=self)
        self._sizes = {}
        self._sizes['n0-small'] = NodeSize(id=1,
                     name="n0-small",
                     ram=128,
                     disk=4,
                     bandwidth=500,
                     price=4,
                     driver=self)
        self._sizes['n0-medium'] = NodeSize(id=2,
                     name="n0-medium",
                     ram=512,
                     disk=16,
                     bandwidth=1500,
                     price=8,
                     driver=self),

        self._networks = {}
        self._networks['provider-network'] = {'name': 'provider-network'}
        self._networks['project-network'] = {'name': 'project-network'}

        # Node List
        self.nl = []
        self.nl.append(Node(id=1,
                            name='dummy-%d' % (1),
                            state=NodeState.RUNNING,
                            public_ips=['172.16.42.1'],
                            private_ips=[],
                            driver=self,
                            size=self._sizes['n0-small'],
                            image=self._images['deb8-jhub-usernotebook'])
                       )

        self.connection = VaporConnection(kwargs)
예제 #11
0
 def _to_node_size(self, plan, plan_price, location):
     extra = self._copy_dict(('core_number', 'storage_tier'), plan)
     return NodeSize(id=plan['name'], name=plan['name'],
                     ram=plan['memory_amount'],
                     disk=plan['storage_size'],
                     bandwidth=plan['public_traffic_out'],
                     price=plan_price.get_price(plan['name'], location),
                     driver=self,
                     extra=extra)
예제 #12
0
 def _to_node_size(self, object):
     # Converts to an SCE InstanceType to a Libcloud NodeSize
     return NodeSize(object.findtext('ID'),
                     object.findtext('Label'),
                     None,
                     None,
                     None,
                     object.findtext('Price/Rate'),
                     self.connection.driver)
예제 #13
0
 def _to_size(self, num):
     size = NodeSize(id=num,
                     name="%d Node" % (num,),
                     ram=RAM_PER_NODE * num,
                     disk=DISK_PER_NODE,
                     bandwidth=BANDWIDTH_PER_NODE * num,
                     price=self._get_price_per_node(num) * num,
                     driver=self.connection.driver)
     return size
예제 #14
0
 def _size_from_id(self, size_id):
     size = NodeSize(id=size_id,
                     name="",
                     ram=None,
                     disk=None,
                     bandwidth=None,
                     price=None,
                     driver="")
     return size
예제 #15
0
 def _to_size(self, ram):
     ns = NodeSize(id=None,
                   name="%s Ram" % ram,
                   ram=ram,
                   disk=None,
                   bandwidth=None,
                   price=None,
                   driver=self.connection.driver)
     return ns
 def _service_offer_to_size(self, service_offer):
     return NodeSize(id=service_offer.get('id'),
                     name=service_offer.get('name'),
                     ram=service_offer.get('resource:ram'),
                     disk=service_offer.get('resource:disk'),
                     bandwidth=None,
                     price=service_offer.get('price:unitCost'),
                     driver=self,
                     extra=service_offer)
예제 #17
0
 def _to_size(self, element):
     s = NodeSize(id=int(element.findtext('id')),
                  name=str(element.findtext('name')),
                  ram=int(element.findtext('ram')),
                  disk=None, # XXX: needs hardcode
                  bandwidth=None, # XXX: needs hardcode
                  price=float(element.findtext('price'))/(100*24*30),
                  driver=self.connection.driver)
     return s
예제 #18
0
 def _to_size(self, size):
     # type (dict) -> Size
     sizes = []
     for disk in size["disks"]:
         sizes.append(NodeSize(id=str(size["id"]), name=size["name"],
                               ram=size["memory"], disk=disk,
                               driver=self, extra={"vcpus": size["vcpus"]},
                               bandwidth=0, price=0))
     return sizes
예제 #19
0
 def _to_size(self, el):
     s = NodeSize(id=el.get('id'),
                  name=el.get('name'),
                  ram=int(el.get('ram')),
                  disk=int(el.get('disk')),
                  bandwidth=None,  # XXX: needs hardcode
                  price=self._get_size_price(el.get('id')),  # Hardcoded,
                  driver=self.connection.driver)
     return s
예제 #20
0
파일: dummy.py 프로젝트: wandera/libcloud
    def list_sizes(self, location=None):
        """
        Returns a list of node sizes as a cloud provider might have

        >>> from libcloud.compute.drivers.dummy import DummyNodeDriver
        >>> driver = DummyNodeDriver(0)
        >>> sorted([size.ram for size in driver.list_sizes()])
        [128, 512, 4096, 8192]

        @inherits: :class:`NodeDriver.list_images`
        """

        return [
            NodeSize(
                id=1, name="Small", ram=128, disk=4, bandwidth=500, price=4, driver=self
            ),
            NodeSize(
                id=2,
                name="Medium",
                ram=512,
                disk=16,
                bandwidth=1500,
                price=8,
                driver=self,
            ),
            NodeSize(
                id=3,
                name="Big",
                ram=4096,
                disk=32,
                bandwidth=2500,
                price=32,
                driver=self,
            ),
            NodeSize(
                id=4,
                name="XXL Big",
                ram=4096 * 2,
                disk=32 * 4,
                bandwidth=2500 * 3,
                price=32 * 2,
                driver=self,
            ),
        ]
예제 #21
0
 def _to_node(self, data):
     """
     Convert an API node data object to a `Node` object
     """
     ID = data["metadata"]["uid"]
     name = data["metadata"]["name"]
     driver = self.connection.driver
     memory = data["status"].get("capacity", {}).get("memory", "0K")
     cpu = data["status"].get("capacity", {}).get("cpu", "1")
     if isinstance(cpu, str) and not cpu.isnumeric():
         cpu = to_n_cpus(cpu)
     image_name = data["status"]["nodeInfo"].get("osImage")
     image = NodeImage(image_name, image_name, driver)
     size_name = f"{cpu} vCPUs, {memory} Ram"
     size_id = hashlib.md5(size_name.encode("utf-8")).hexdigest()
     extra_size = {"cpus": cpu}
     size = NodeSize(
         id=size_id,
         name=size_name,
         ram=memory,
         disk=0,
         bandwidth=0,
         price=0,
         driver=driver,
         extra=extra_size,
     )
     extra = {"memory": memory, "cpu": cpu}
     extra["os"] = data["status"]["nodeInfo"].get("operatingSystem")
     extra["kubeletVersion"] = data["status"]["nodeInfo"]["kubeletVersion"]
     extra["provider_id"] = data.get("spec", {}).get("providerID")
     for condition in data["status"]["conditions"]:
         if condition["type"] == "Ready" and condition["status"] == "True":
             state = NodeState.RUNNING
             break
     else:
         state = NodeState.UNKNOWN
     public_ips, private_ips = [], []
     for address in data["status"]["addresses"]:
         if address["type"] == "InternalIP":
             private_ips.append(address["address"])
         elif address["type"] == "ExternalIP":
             public_ips.append(address["address"])
     created_at = datetime.datetime.strptime(
         data["metadata"]["creationTimestamp"], "%Y-%m-%dT%H:%M:%SZ")
     return Node(
         id=ID,
         name=name,
         state=state,
         public_ips=public_ips,
         private_ips=private_ips,
         driver=driver,
         image=image,
         size=size,
         extra=extra,
         created_at=created_at,
     )
예제 #22
0
    def _to_size(self, data):
        ram = data['name'].lower()

        if 'mb' in ram:
            ram = int(ram.replace('mb', ''))
        elif 'gb' in ram:
            ram = int(ram.replace('gb', '')) * 1024

        return NodeSize(id=data['id'], name=data['name'], ram=ram, disk=0,
                        bandwidth=0, price=0, driver=self)
예제 #23
0
 def _to_size(self, id, size):
     return NodeSize(
         id=id,
         name=size['name'],
         ram=size['ram'],
         disk=size['disk'],
         bandwidth=size.get('bandwidth'),
         price=self._get_size_price(str(id)),
         driver=self.connection.driver,
     )
예제 #24
0
 def list_sizes(self, location=None):
     """
     :rtype ``list`` of :class:`NodeSize`
     """
     szs = self._sync_request('listServiceOfferings')
     sizes = []
     for sz in szs['serviceoffering']:
         sizes.append(
             NodeSize(sz['id'], sz['name'], sz['memory'], 0, 0, 0, self))
     return sizes
예제 #25
0
 def _to_size(self, id, size):
     return NodeSize(
         id=id,
         name="%s cores" % id,
         ram=size["memory"],
         disk=size["disk"],
         bandwidth=size["bandwidth"],
         price=(self._get_size_price(size_id="1") * id),
         driver=self.connection.driver,
     )
예제 #26
0
 def _to_size(self, id, size):
     return NodeSize(
         id=id,
         name='%s cores' % id,
         ram=size['memory'],
         disk=size['disk'],
         bandwidth=size['bandwidth'],
         price=(self._get_size_price(size_id='1') * id),
         driver=self.connection.driver,
     )
예제 #27
0
 def _instance_type_to_size(self, instance):
     return NodeSize(
         id=instance['id'],
         name=instance['name'],
         ram=instance['memory'],
         disk=instance['disk'],
         bandwidth=instance['bandwidth'],
         price=self._get_size_price(size_id=instance['id']),
         driver=self.connection.driver,
     )
예제 #28
0
 def _instance_type_to_size(self, instance):
     return NodeSize(
         id=instance["id"],
         name=instance["name"],
         ram=instance["memory"],
         disk=instance["disk"],
         bandwidth=instance["bandwidth"],
         price=self._get_size_price(size_id=instance["id"]),
         driver=self.connection.driver,
     )
예제 #29
0
 def list_sizes(self, location=None):
     return [
         NodeSize(id=1,
                  name="default",
                  ram=0,
                  disk=0,
                  bandwidth=0,
                  price=0,
                  driver=self.connection.driver),
     ]
예제 #30
0
파일: ec2.py 프로젝트: firefoxxy8/libcloud
 def _get_sizes(self, include_cluser_instances=False):
     sizes = []
     for key, values in self._instance_types.iteritems():
         if not include_cluser_instances and\
            key in CLUSTER_INSTANCES_IDS:
             continue
         attributes = copy.deepcopy(values)
         attributes.update({'price': self._get_size_price(size_id=key)})
         sizes.append(NodeSize(driver=self, **attributes))
     return sizes