1- from typing import BinaryIO , Tuple
1+ from typing import BinaryIO , List , Optional , Tuple , Union
22
33import requests
44
55from linode_api4 .errors import UnexpectedResponseError
66from linode_api4 .groups import Group
7- from linode_api4 .objects import Base , Image
7+ from linode_api4 .objects import Base , Disk , Image
88from linode_api4 .util import drop_null_keys
99
1010
@@ -29,39 +29,45 @@ def __call__(self, *filters):
2929 """
3030 return self .client ._get_and_filter (Image , * filters )
3131
32- def create (self , disk , label = None , description = None , cloud_init = False ):
32+ def create (
33+ self ,
34+ disk : Union [Disk , int ],
35+ label : str = None ,
36+ description : str = None ,
37+ cloud_init : bool = False ,
38+ tags : Optional [List [str ]] = None ,
39+ ):
3340 """
3441 Creates a new Image from a disk you own.
3542
3643 API Documentation: https://techdocs.akamai.com/linode-api/reference/post-image
3744
3845 :param disk: The Disk to imagize.
39- :type disk: Disk or int
46+ :type disk: Union[ Disk, int]
4047 :param label: The label for the resulting Image (defaults to the disk's
4148 label.
4249 :type label: str
4350 :param description: The description for the new Image.
4451 :type description: str
4552 :param cloud_init: Whether this Image supports cloud-init.
4653 :type cloud_init: bool
54+ :param tags: A list of customized tags of this new Image.
55+ :type tags: Optional[List[str]]
4756
4857 :returns: The new Image.
4958 :rtype: Image
5059 """
5160 params = {
5261 "disk_id" : disk .id if issubclass (type (disk ), Base ) else disk ,
62+ "label" : label ,
63+ "description" : description ,
64+ "tags" : tags ,
5365 }
5466
55- if label is not None :
56- params ["label" ] = label
57-
58- if description is not None :
59- params ["description" ] = description
60-
6167 if cloud_init :
6268 params ["cloud_init" ] = cloud_init
6369
64- result = self .client .post ("/images" , data = params )
70+ result = self .client .post ("/images" , data = drop_null_keys ( params ) )
6571
6672 if not "id" in result :
6773 raise UnexpectedResponseError (
@@ -78,6 +84,7 @@ def create_upload(
7884 region : str ,
7985 description : str = None ,
8086 cloud_init : bool = False ,
87+ tags : Optional [List [str ]] = None ,
8188 ) -> Tuple [Image , str ]:
8289 """
8390 Creates a new Image and returns the corresponding upload URL.
@@ -92,11 +99,18 @@ def create_upload(
9299 :type description: str
93100 :param cloud_init: Whether this Image supports cloud-init.
94101 :type cloud_init: bool
102+ :param tags: A list of customized tags of this Image.
103+ :type tags: Optional[List[str]]
95104
96105 :returns: A tuple containing the new image and the image upload URL.
97106 :rtype: (Image, str)
98107 """
99- params = {"label" : label , "region" : region , "description" : description }
108+ params = {
109+ "label" : label ,
110+ "region" : region ,
111+ "description" : description ,
112+ "tags" : tags ,
113+ }
100114
101115 if cloud_init :
102116 params ["cloud_init" ] = cloud_init
@@ -114,7 +128,12 @@ def create_upload(
114128 return Image (self .client , result_image ["id" ], result_image ), result_url
115129
116130 def upload (
117- self , label : str , region : str , file : BinaryIO , description : str = None
131+ self ,
132+ label : str ,
133+ region : str ,
134+ file : BinaryIO ,
135+ description : str = None ,
136+ tags : Optional [List [str ]] = None ,
118137 ) -> Image :
119138 """
120139 Creates and uploads a new image.
@@ -128,12 +147,16 @@ def upload(
128147 :param file: The BinaryIO object to upload to the image. This is generally obtained from open("myfile", "rb").
129148 :param description: The description for the new Image.
130149 :type description: str
150+ :param tags: A list of customized tags of this Image.
151+ :type tags: Optional[List[str]]
131152
132153 :returns: The resulting image.
133154 :rtype: Image
134155 """
135156
136- image , url = self .create_upload (label , region , description = description )
157+ image , url = self .create_upload (
158+ label , region , description = description , tags = tags
159+ )
137160
138161 requests .put (
139162 url ,
0 commit comments