1212# under the License.
1313
1414from openstack import resource
15+ from openstack import utils
16+ from openstack import exceptions
1517
1618
1719class Image (resource .Resource ):
@@ -21,9 +23,11 @@ class Image(resource.Resource):
2123
2224 allow_create = True
2325 allow_list = True
26+ allow_commit = True
2427
2528 #: Method for creating a resource (POST, PUT)
2629 create_method = "POST"
30+ commit_method = "PATCH"
2731
2832 _query_mapping = resource .QueryParameters ('limit' , 'id' ,
2933 'name' , 'status' ,
@@ -59,9 +63,9 @@ class Image(resource.Resource):
5963 'enterprise_project_id' )
6064
6165 name = resource .Body ('name' )
62- description = resource .Body ('description ' )
66+ description = resource .Body ('__description ' )
6367 os_type = resource .Body ('os_type' )
64- os_version = resource .Body ('os_version ' )
68+ os_version = resource .Body ('__os_version ' )
6569 image_url = resource .Body ('image_url' )
6670 instance_id = resource .Body ('instance_id' )
6771 min_disk = resource .Body ('min_disk' , type = int )
@@ -85,7 +89,54 @@ class Image(resource.Resource):
8589 virtual_env_type = resource .Body ('virtual_env_type' )
8690 enterprise_project_id = resource .Body ('enterprise_project_id' )
8791 protected = resource .Body ('protected' , type = bool )
92+ virtual_size = resource .Body ('virtual_size' )
93+ hw_firmware_type = resource .Body ('hw_firmware_type' )
94+ disk_format = resource .Body ('disk_format' )
95+ container_format = resource .Body ('container_format' )
96+ hw_vif_multiqueue_enabled = resource .Body ('hw_vif_multiqueue_enabled' )
97+ checksum = resource .Body ('checksum' )
98+ size = resource .Body ('size' )
99+ file = resource .Body ('file' )
100+ os_bit = resource .Body ('__os_bit' )
101+ platform = resource .Body ('__platform' )
102+ is_registered = resource .Body ('__is_registered' )
103+ os_type = resource .Body ('__os_type' )
104+ image_source_type = resource .Body ('__image_source_type' )
105+ imagetype = resource .Body ('__imagetype' )
106+ originalimagename = resource .Body ('__originalimagename' )
107+ backup_id = resource .Body ('__backup_id' )
108+ productcode = resource .Body ('__productcode' )
109+ image_size = resource .Body ('__image_size' )
110+ support_fc_inject = resource .Body ('__support_fc_inject' )
111+ data_origin = resource .Body ('__data_origin' )
88112
89113 def create (self , session , prepend_key = False , base_path = None ):
90114 # Override here to override prepend_key default value
91115 return super (Image , self ).create (session , prepend_key , base_path )
116+
117+ def _action (self , session , request_body , image_id ):
118+ url = utils .urljoin (self .base_path , image_id )
119+ response = session .patch (url , json = request_body )
120+ exceptions .raise_from_response (response )
121+ return response
122+
123+ def update_image_details (self , session , image_id , command_list ):
124+ request_body = command_list
125+ response = self ._action (
126+ session = session ,
127+ request_body = request_body ,
128+ image_id = image_id )
129+ return self ._to_object (session , response )
130+
131+ def _to_object (self , session , response ):
132+ has_body = (
133+ self .has_body
134+ if self .create_returns_body is None
135+ else self .create_returns_body
136+ )
137+ microversion = self ._get_microversion (session , action = 'create' )
138+ self .microversion = microversion
139+ self ._translate_response (response , has_body = has_body )
140+ if self .has_body and self .create_returns_body is False :
141+ return self .fetch (session )
142+ return self
0 commit comments