11# -*- coding: utf-8 -*-
22from .baseapi import BaseAPI , POST , DELETE , PUT , NotFoundError
33
4+
45class Image (BaseAPI ):
6+ """
7+ An object representing an DigitalOcean Image.
8+
9+ Attributes accepted at creation time:
10+
11+ Args:
12+ name (str): The name to be given to an image.
13+ url (str): A URL from which the virtual machine image may be retrieved.
14+ region (str): The slug of the region where the image will be available.
15+ distribution (str, optional): The name of the image's distribution.
16+ description (str, optional): Free-form text field to describe an image.
17+ tags (obj:`list` of `str`, optional): List of tag names to apply to
18+ the image.
19+
20+ Attributes returned by API:
21+
22+ id (int): A unique number to identify and reference a image.
23+ name (str): The display name given to an image.
24+ type (str): The kind of image. This will be either "snapshot",
25+ "backup", or "custom".
26+ distribution (str): The name of the image's distribution.
27+ slug (str): A uniquely identifying string that is associated with each
28+ of the DigitalOcean-provided public images.
29+ public (bool): Indicates whether the image is public or not.
30+ regions (obj:`list` of `str`): A list of the slugs of the regions where
31+ the image is available for use.
32+ created_at (str): A time value given in ISO8601 combined date and time
33+ format that represents when the image was created.
34+ min_disk_size (int): The minimum disk size in GB required for a Droplet
35+ to use this image.
36+ size_gigabytes (int): The size of the image in gigabytes.
37+ description (str): Free-form text field to describing an image.
38+ tags (obj:`list` of `str`): List of tag names to applied to the image.
39+ status (str): Indicates the state of a custom image. This may be "NEW",
40+ "available", "pending", or "deleted".
41+ error_message (str): Information about errors that may occur when
42+ importing a custom image.
43+ """
544 def __init__ (self , * args , ** kwargs ):
645 self .id = None
746 self .name = None
@@ -12,6 +51,12 @@ def __init__(self, *args, **kwargs):
1251 self .regions = []
1352 self .created_at = None
1453 self .size_gigabytes = None
54+ self .description = None
55+ self .status = None
56+ self .tags = []
57+ self .error_message = None
58+ self .url = None
59+ self .region = None
1560
1661 super (Image , self ).__init__ (* args , ** kwargs )
1762
@@ -45,6 +90,26 @@ def _is_string(value):
4590 else :
4691 return None
4792
93+ def create (self ):
94+ """
95+ Creates a new custom DigitalOcean Image from the Linux virtual machine
96+ image located at the provided `url`.
97+ """
98+ params = {'name' : self .name ,
99+ 'region' : self .region ,
100+ 'url' : self .url ,
101+ 'distribution' : self .distribution ,
102+ 'description' : self .description ,
103+ 'tags' : self .tags }
104+
105+ data = self .get_data ('images' , type = POST , params = params )
106+
107+ if data :
108+ for attr in data ['image' ].keys ():
109+ setattr (self , attr , data ['image' ][attr ])
110+
111+ return self
112+
48113 def load (self , use_slug = False ):
49114 """
50115 Load slug.
0 commit comments