예제 #1
0
 def _get_size_price(self, size_id):
     try:
         return get_size_price(driver_type='compute',
                               driver_name=self.api_name,
                               size_id=size_id)
     except KeyError:
         return 0.0
예제 #2
0
 def _get_size_price(self, size_id):
     try:
         return get_size_price(driver_type='compute',
                               driver_name=self.api_name,
                               size_id=size_id)
     except KeyError:
         return 0.0
예제 #3
0
 def _get_size_price(self, size_id):
     """
     Return pricing information for the provided size id.
     """
     return get_size_price(driver_type='compute',
                           driver_name=self.api_name,
                           size_id=size_id)
예제 #4
0
    def _get_size_price(self, size_id):
        if 'openstack' not in PRICING_DATA['compute']:
            return 0.0

        return get_size_price(driver_type='compute',
                              driver_name='openstack',
                              size_id=size_id)
예제 #5
0
 def _list_machines__cost_machine(self, machine, machine_libcloud):
     # Need to get image in order to specify the OS type
     # out of the image id.
     instance_image = machine_libcloud.extra.get('imageId')
     try:
         os_type = CloudImage.objects.get(
             cloud_provider=machine_libcloud.driver.type,
             image_id=instance_image).os_type
     except:
         os_type = 'linux'
     size = machine_libcloud.extra.get('flavorId')
     location = machine_libcloud.driver.region[:3]
     driver_name = 'rackspacenova' + location
     price = get_size_price(driver_type='compute',
                            driver_name=driver_name,
                            size_id=size)
     if price:
         plan_price = price.get(os_type, 'linux')
         # 730 is the number of hours per month as on
         # https://www.rackspace.com/calculator
         return plan_price, float(plan_price) * 730
예제 #6
0
파일: base.py 프로젝트: s0undt3ch/libcloud
 def _get_size_price(self, size_id):
     return get_size_price(driver_type='compute',
                           driver_name=self.api_name,
                           size_id=size_id)
예제 #7
0
파일: base.py 프로젝트: Keisuke69/libcloud
 def _get_size_price(self, size_id):
     return get_size_price(driver_type='compute',
                           driver_name=self.api_name,
                           size_id=size_id)
예제 #8
0
 def _list_machines__cost_machine(self, machine, machine_libcloud):
     size = machine_libcloud.extra.get('plan')
     price = get_size_price(driver_type='compute',
                            driver_name='packet',
                            size_id=size)
     return price or 0, 0
예제 #9
0
    def _list_machines__cost_machine(self, machine, machine_libcloud):
        if machine_libcloud.state == NodeState.TERMINATED:
            return 0, 0
        # https://cloud.google.com/compute/pricing
        size = machine_libcloud.extra.get('machineType').split('/')[-1]
        location = machine_libcloud.extra.get('location')
        # Get the location, locations currently are
        # europe us asia-east asia-northeast
        # all with different pricing
        if 'asia-northeast' in location:
            # eg asia-northeast1-a
            location = 'asia_northeast'
        elif 'asia-east' in location:
            # eg asia-east1-a
            location = 'asia_east'
        else:
            # eg europe-west1-d
            location = location.split('-')[0]
        driver_name = 'google_' + location
        price = get_size_price(driver_type='compute',
                               driver_name=driver_name,
                               size_id=size)

        if not price:
            if size.startswith('custom'):
                cpu_price = 'custom_vcpu'
                ram_price = 'custom_ram'
                if 'preemptible' in size:
                    cpu_price = 'custom_vcpu_preemptible'
                    ram_price = 'custom_ram_preemptible'

                cpu_price = get_size_price(driver_type='compute',
                                           driver_name=driver_name,
                                           size_id=cpu_price)
                ram_price = get_size_price(driver_type='compute',
                                           driver_name=driver_name,
                                           size_id=ram_price)
                # Example custom-4-16384
                try:
                    cpu = int(size.split('-')[1])
                    ram = int(size.split('-')[2]) / 1024
                    price = cpu * cpu_price + ram * ram_price
                except:
                    log.exception("Couldn't parse custom size %s for cloud %s",
                                  size, self.cloud)
                    return 0, 0
            else:
                return 0, 0
        os_type = machine_libcloud.extra.get('os_type')
        os_cost_per_hour = 0
        if os_type == 'sles':
            if size in ('f1-micro', 'g1-small'):
                os_cost_per_hour = 0.02
            else:
                os_cost_per_hour = 0.11
        if os_type == 'win':
            if size in ('f1-micro', 'g1-small'):
                os_cost_per_hour = 0.02
            else:
                cores = size.split('-')[-1]
                os_cost_per_hour = cores * 0.04
        if os_type == 'rhel':
            if size in ('n1-highmem-2', 'n1-highcpu-2', 'n1-highmem-4',
                        'n1-highcpu-4', 'f1-micro', 'g1-small',
                        'n1-standard-1', 'n1-standard-2', 'n1-standard-4'):
                os_cost_per_hour = 0.06
            else:
                os_cost_per_hour = 0.13

        try:
            if 'preemptible' in size:
                # No monthly discount.
                return price + os_cost_per_hour, 0
            else:
                # Monthly discount of 30% if the VM runs all the billing month.
                # Monthly discount on instance size only (not on OS image).
                return 0.7 * price + os_cost_per_hour, 0
            # TODO: better calculate the discounts, taking under consideration
            # when the VM has been initiated.
        except:
            pass
예제 #10
0
 def _list_machines__cost_machine(self, machine, machine_libcloud):
     size = machine_libcloud.extra.get('PLANID')
     price = get_size_price(driver_type='compute',
                            driver_name='linode',
                            size_id=size)
     return 0, price or 0