コード例 #1
0
    def create_new_volume(self, size_gb, name, desc, region, snapshot_id):
        """
        Used for creating a new volume in block storage

        :param api_object:
        :param size_gb:
        :param name:
        :param desc:
        :param region:
        :param snapshot_id:

        :type api_object: object
        :type size_gb: integer
        :type name: string
        :type desc: string
        :type region: string
        :type snapshot_id: string

        :return:
        :rtype: string
        """

        payload = {
            'size_gigabytes': size_gb,
            'name': name,
            'description': desc,
            'region': region,
            'snapshot-id': snapshot_id
        }

        return DigitalOceanAPI.post(self.api_object, 'volumes', payload)
コード例 #2
0
    def rezise_volume(self, volume_id, size_gb, region, type='resize'):
        """

        :param self:
        :param volume_id:
        :param size_gb:
        :param region:
        :param type:
        :return:
        """
        return DigitalOceanAPI.post(self.api_object,
                                    'volumes/' + volume_id + '/actions', {
                                        'type': type,
                                        'size_gigabytes': size_gb,
                                        'region': region
                                    })
コード例 #3
0
    def remove_volume_from_droplet_byname(self,
                                          droplet_id,
                                          volume_name,
                                          region,
                                          type='attach'):
        """

        :param droplet_id:
        :param volume_name:
        :param region:
        :return:
        """
        return DigitalOceanAPI.post(
            self.api_object, 'volumes/' + 'actions', {
                'type': type,
                'droplet_id': droplet_id,
                'volume_name': volume_name,
                'region': region
            })
コード例 #4
0
    def attach_volume_to_droplet(self,
                                 volume_id,
                                 droplet_id,
                                 region,
                                 type='attach'):
        """
        Used to attach a existing volume to a droplet

        :param volume_id:
        :param droplet_id:
        :param region:
        :param type:

        :return:
        :rtype: JSON object
        """

        return DigitalOceanAPI.post(self.api_object,
                                    'volumes/' + volume_id + '/actions', {
                                        'type': type,
                                        'droplet_id': droplet_id,
                                        'region': region
                                    })
コード例 #5
0
    def attach_volume_to_droplet_by_name(self,
                                         droplet_id,
                                         volume_name,
                                         region,
                                         type='attach'):
        """
        Used for attaching a volume to a droplet by a name

        :param droplet_id:
        :param volume_name:
        :param region:
        :param type:

        :return:
        :rtype:
        """

        return DigitalOceanAPI.post(
            self.api_object, 'volumes/actions', {
                'type': type,
                'droplet_id': droplet_id,
                'volume_name': volume_name,
                'region': region
            })