示例#1
0
    def upgrade(self, instance_id, cpus=None, memory=None,
                nic_speed=None, public=True):
        """Upgrades a VS instance.

        :param int instance_id: Instance id of the VS to be upgraded
        :param int cpus: The number of virtual CPUs to upgrade to
                            of a VS instance.
        :param bool public: CPU will be in Private/Public Node.
        :param int memory: RAM of the VS to be upgraded to.
        :param int nic_speed: The port speed to set

        :returns: bool
        Example::

           # Upgrade instance 12345 to 4 CPUs and 4 GB of memory
           import SoftLayer
           client = SoftLayer.create_client_from_env()
           mgr = SoftLayer.VSManager(client)
           mgr.upgrade(12345, cpus=4, memory=4)

        """
        package_items = self._get_package_items()
        prices = []
        if cpus:
            prices.append({
                'id': self._get_item_id_for_upgrade(package_items,
                                                    'cpus',
                                                    cpus,
                                                    public)})
        if memory:
            prices.append({
                'id': self._get_item_id_for_upgrade(package_items,
                                                    'memory',
                                                    memory)})
        if nic_speed:
            prices.append({
                'id': self._get_item_id_for_upgrade(package_items,
                                                    'nic_speed',
                                                    nic_speed)})

        maintenance_window = datetime.datetime.now(utils.UTC())
        order = {
            'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest_'
                           'Upgrade',
            'prices': prices,
            'properties': [{
                'name': 'MAINTENANCE_WINDOW',
                'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
            }],
            'virtualGuests': [{'id': int(instance_id)}],
        }
        if prices:
            self.client['Product_Order'].placeOrder(order)
            return True
        return False
示例#2
0
    def upgrade(self, instance_id, cpus=None, memory=None,
                nic_speed=None, public=True):
        """Upgrades a VS instance.

        Example::

           # Upgrade instance 12345 to 4 CPUs and 4 GB of memory
           import SoftLayer
           client = SoftLayer.create_client_from_env()
           mgr = SoftLayer.VSManager(client)
           mgr.upgrade(12345, cpus=4, memory=4)

        :param int instance_id: Instance id of the VS to be upgraded
        :param int cpus: The number of virtual CPUs to upgrade to
                            of a VS instance.
        :param int memory: RAM of the VS to be upgraded to.
        :param int nic_speed: The port speed to set
        :param bool public: CPU will be in Private/Public Node.

        :returns: bool
        """
        upgrade_prices = self._get_upgrade_prices(instance_id)
        prices = []

        for option, value in {'cpus': cpus,
                              'memory': memory,
                              'nic_speed': nic_speed}.items():
            if not value:
                continue
            price_id = self._get_price_id_for_upgrade_option(upgrade_prices,
                                                             option,
                                                             value,
                                                             public)
            if not price_id:
                # Every option provided is expected to have a price
                raise exceptions.SoftLayerError(
                    "Unable to find %s option with value %s" % (option, value))

            prices.append({'id': price_id})

        maintenance_window = datetime.datetime.now(utils.UTC())
        order = {
            'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest_'
                           'Upgrade',
            'prices': prices,
            'properties': [{
                'name': 'MAINTENANCE_WINDOW',
                'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
            }],
            'virtualGuests': [{'id': int(instance_id)}],
        }
        if prices:
            self.client['Product_Order'].placeOrder(order)
            return True
        return False
示例#3
0
    def upgrade(self,
                instance_id,
                cpus=None,
                memory=None,
                nic_speed=None,
                public=True,
                preset=None):
        """Upgrades a VS instance.

        Example::

           # Upgrade instance 12345 to 4 CPUs and 4 GB of memory
           import SoftLayer
           client = SoftLayer.create_client_from_env()
           mgr = SoftLayer.VSManager(client)
           mgr.upgrade(12345, cpus=4, memory=4)

        :param int instance_id: Instance id of the VS to be upgraded
        :param int cpus: The number of virtual CPUs to upgrade to
                            of a VS instance.
        :param string preset: preset assigned to the vsi
        :param int memory: RAM of the VS to be upgraded to.
        :param int nic_speed: The port speed to set
        :param bool public: CPU will be in Private/Public Node.

        :returns: bool
        """
        upgrade_prices = self._get_upgrade_prices(instance_id)
        prices = []

        data = {'nic_speed': nic_speed}

        if cpus is not None and preset is not None:
            raise exceptions.SoftLayerError(
                "Do not use cpu, private and memory if you are using flavors")
        data['cpus'] = cpus

        if memory is not None and preset is not None:
            raise exceptions.SoftLayerError(
                "Do not use memory, private or cpu if you are using flavors")
        data['memory'] = memory

        maintenance_window = datetime.datetime.now(utils.UTC())
        order = {
            'complexType':
            'SoftLayer_Container_Product_Order_Virtual_Guest_'
            'Upgrade',
            'properties': [{
                'name':
                'MAINTENANCE_WINDOW',
                'value':
                maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
            }],
            'virtualGuests': [{
                'id': int(instance_id)
            }],
        }

        for option, value in data.items():
            if not value:
                continue
            price_id = self._get_price_id_for_upgrade_option(
                upgrade_prices, option, value, public)
            if not price_id:
                # Every option provided is expected to have a price
                raise exceptions.SoftLayerError(
                    "Unable to find %s option with value %s" % (option, value))

            prices.append({'id': price_id})
        order['prices'] = prices

        if preset is not None:
            vs_object = self.get_instance(
                instance_id)['billingItem']['package']
            order['presetId'] = self.ordering_manager.get_preset_by_key(
                vs_object['keyName'], preset)['id']

        if prices or preset:
            self.client['Product_Order'].placeOrder(order)
            return True
        return False