Skip to content

Commit 0b1f637

Browse files
committed
Add export/import capabilities to/from IBM Cloud Object Storage
Change image manager to include IBM Cloud Object Storage support and add unit tests for it.
1 parent 058c5ed commit 0b1f637

File tree

3 files changed

+98
-11
lines changed

3 files changed

+98
-11
lines changed

SoftLayer/fixtures/SoftLayer_Virtual_Guest_Block_Device_Template_Group.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,11 @@
2929
'id': 100,
3030
'name': 'test_image',
3131
}]
32-
32+
createFromIcos = [{
33+
'createDate': '2013-12-05T21:53:03-06:00',
34+
'globalIdentifier': '0B5DEAF4-643D-46CA-A695-CECBE8832C9D',
35+
'id': 100,
36+
'name': 'test_image',
37+
}]
3338
copyToExternalSource = True
39+
copyToIcos = True

SoftLayer/managers/image.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,68 @@ def edit(self, image_id, name=None, note=None, tag=None):
120120

121121
return bool(name or note or tag)
122122

123-
def import_image_from_uri(self, name, uri, os_code=None, note=None):
123+
def import_image_from_uri(self, name, uri, os_code=None, note=None,
124+
ibm_api_key=None, root_key_id=None,
125+
wrapped_dek=None, kp_id=None, cloud_init=None,
126+
byol=None, is_encrypted=None):
124127
"""Import a new image from object storage.
125128
126129
:param string name: Name of the new image
127130
:param string uri: The URI for an object storage object
128131
(.vhd/.iso file) of the format:
129132
swift://<objectStorageAccount>@<cluster>/<container>/<objectPath>
133+
or (.vhd/.iso/.raw file) of the format:
134+
cos://<clusterName>/<bucketName>/<objectPath> if using IBM Cloud
135+
Object Storage
130136
:param string os_code: The reference code of the operating system
131137
:param string note: Note to add to the image
138+
:param string ibm_api_key: Ibm Api Key needed to communicate with ICOS
139+
and Key Protect
140+
:param string root_key_id: ID of the root key in Key Protect
141+
:param string wrapped_dek: Wrapped Decryption Key provided by IBM
142+
KeyProtect
143+
:param string kp_id: ID of the IBM Key Protect Instance
144+
:param bool cloud_init: Specifies if image is cloud init
145+
:param bool byol: Specifies if image is bring your own license
146+
:param bool is_encrypted: Specifies if image is encrypted
132147
"""
133-
return self.vgbdtg.createFromExternalSource({
134-
'name': name,
135-
'note': note,
136-
'operatingSystemReferenceCode': os_code,
137-
'uri': uri,
138-
})
139-
140-
def export_image_to_uri(self, image_id, uri):
148+
if 'cos://' in uri:
149+
return self.vgbdtg.createFromIcos({
150+
'name': name,
151+
'note': note,
152+
'operatingSystemReferenceCode': os_code,
153+
'uri': uri,
154+
'ibmApiKey': ibm_api_key,
155+
'rootKeyid': root_key_id,
156+
'wrappedDek': wrapped_dek,
157+
'keyProtectId': kp_id,
158+
'cloudInit': cloud_init,
159+
'byol': byol,
160+
'isEncrypted': is_encrypted
161+
})
162+
else:
163+
return self.vgbdtg.createFromExternalSource({
164+
'name': name,
165+
'note': note,
166+
'operatingSystemReferenceCode': os_code,
167+
'uri': uri,
168+
})
169+
170+
def export_image_to_uri(self, image_id, uri, ibm_api_key=None):
141171
"""Export image into the given object storage
142172
143173
:param int image_id: The ID of the image
144174
:param string uri: The URI for object storage of the format
145175
swift://<objectStorageAccount>@<cluster>/<container>/<objectPath>
176+
or cos://<clusterName>/<bucketName>/<objectPath> if using IBM Cloud
177+
Object Storage
178+
:param string ibm_api_key: Ibm Api Key needed to communicate with IBM
179+
Cloud Object Storage
146180
"""
147-
return self.vgbdtg.copyToExternalSource({'uri': uri}, id=image_id)
181+
if 'cos://' in uri:
182+
return self.vgbdtg.copyToIcos({
183+
'uri': uri,
184+
'ibmApiKey': ibm_api_key
185+
}, id=image_id)
186+
else:
187+
return self.vgbdtg.copyToExternalSource({'uri': uri}, id=image_id)

tests/managers/image_tests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,36 @@ def test_import_image(self):
145145
'uri': 'someuri',
146146
'operatingSystemReferenceCode': 'UBUNTU_LATEST'},))
147147

148+
def test_import_image_cos(self):
149+
self.image.import_image_from_uri(name='test_image',
150+
note='testimage',
151+
uri='cos://some_uri',
152+
os_code='UBUNTU_LATEST',
153+
ibm_api_key='some_ibm_key',
154+
root_key_id='some_root_key_id',
155+
wrapped_dek='some_dek',
156+
kp_id='some_id',
157+
cloud_init=False,
158+
byol=False,
159+
is_encrypted=False
160+
)
161+
162+
self.assert_called_with(
163+
IMAGE_SERVICE,
164+
'createFromIcos',
165+
args=({'name': 'test_image',
166+
'note': 'testimage',
167+
'operatingSystemReferenceCode': 'UBUNTU_LATEST',
168+
'uri': 'cos://some_uri',
169+
'ibmApiKey': 'some_ibm_key',
170+
'rootKeyid': 'some_root_key_id',
171+
'wrappedDek': 'some_dek',
172+
'keyProtectId': 'some_id',
173+
'cloudInit': False,
174+
'byol': False,
175+
'isEncrypted': False
176+
},))
177+
148178
def test_export_image(self):
149179
self.image.export_image_to_uri(1234, 'someuri')
150180

@@ -153,3 +183,14 @@ def test_export_image(self):
153183
'copyToExternalSource',
154184
args=({'uri': 'someuri'},),
155185
identifier=1234)
186+
187+
def test_export_image_cos(self):
188+
self.image.export_image_to_uri(1234,
189+
'cos://someuri',
190+
ibm_api_key='someApiKey')
191+
192+
self.assert_called_with(
193+
IMAGE_SERVICE,
194+
'copyToIcos',
195+
args=({'uri': 'cos://someuri', 'ibmApiKey': 'someApiKey'},),
196+
identifier=1234)

0 commit comments

Comments
 (0)