Skip to content

Commit 17cae65

Browse files
Merge pull request #1053 from mikewurtz/icosImageSupport
Icos image support
2 parents c15db0e + 3a6b7b3 commit 17cae65

File tree

5 files changed

+147
-16
lines changed

5 files changed

+147
-16
lines changed

SoftLayer/CLI/image/export.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@
1212
@click.command()
1313
@click.argument('identifier')
1414
@click.argument('uri')
15+
@click.option('--ibm-api-key',
16+
default=None,
17+
help="The IBM Cloud API Key with access to IBM Cloud Object "
18+
"Storage instance. For help creating this key see "
19+
"https://console.bluemix.net/docs/services/cloud-object-"
20+
"storage/iam/users-serviceids.html#serviceidapikeys")
1521
@environment.pass_env
16-
def cli(env, identifier, uri):
22+
def cli(env, identifier, uri, ibm_api_key):
1723
"""Export an image to object storage.
1824
1925
The URI for an object storage object (.vhd/.iso file) of the format:
2026
swift://<objectStorageAccount>@<cluster>/<container>/<objectPath>
27+
or cos://<clusterName>/<bucketName>/<objectPath> if using IBM Cloud
28+
Object Storage
2129
"""
2230

2331
image_mgr = SoftLayer.ImageManager(env.client)
2432
image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image')
25-
result = image_mgr.export_image_to_uri(image_id, uri)
33+
result = image_mgr.export_image_to_uri(image_id, uri, ibm_api_key)
2634

2735
if not result:
2836
raise exceptions.CLIAbort("Failed to export Image")

SoftLayer/CLI/image/import.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,44 @@
1616
default="",
1717
help="The note to be applied to the imported template")
1818
@click.option('--os-code',
19-
default="",
2019
help="The referenceCode of the operating system software"
21-
" description for the imported VHD")
20+
" description for the imported VHD, ISO, or RAW image")
21+
@click.option('--ibm-api-key',
22+
default=None,
23+
help="The IBM Cloud API Key with access to IBM Cloud Object "
24+
"Storage instance and IBM KeyProtect instance. For help "
25+
"creating this key see https://console.bluemix.net/docs/"
26+
"services/cloud-object-storage/iam/users-serviceids.html"
27+
"#serviceidapikeys")
28+
@click.option('--root-key-id',
29+
default=None,
30+
help="ID of the root key in Key Protect")
31+
@click.option('--wrapped-dek',
32+
default=None,
33+
help="Wrapped Data Encryption Key provided by IBM KeyProtect. "
34+
"For more info see https://console.bluemix.net/docs/"
35+
"services/key-protect/wrap-keys.html#wrap-keys")
36+
@click.option('--kp-id',
37+
default=None,
38+
help="ID of the IBM Key Protect Instance")
39+
@click.option('--cloud-init',
40+
is_flag=True,
41+
help="Specifies if image is cloud-init")
42+
@click.option('--byol',
43+
is_flag=True,
44+
help="Specifies if image is bring your own license")
45+
@click.option('--is-encrypted',
46+
is_flag=True,
47+
help="Specifies if image is encrypted")
2248
@environment.pass_env
23-
def cli(env, name, note, os_code, uri):
49+
def cli(env, name, note, os_code, uri, ibm_api_key, root_key_id, wrapped_dek,
50+
kp_id, cloud_init, byol, is_encrypted):
2451
"""Import an image.
2552
2653
The URI for an object storage object (.vhd/.iso file) of the format:
2754
swift://<objectStorageAccount>@<cluster>/<container>/<objectPath>
55+
or cos://<clusterName>/<bucketName>/<objectPath> if using IBM Cloud
56+
Object Storage
2857
"""
2958

3059
image_mgr = SoftLayer.ImageManager(env.client)
@@ -33,6 +62,13 @@ def cli(env, name, note, os_code, uri):
3362
note=note,
3463
os_code=os_code,
3564
uri=uri,
65+
ibm_api_key=ibm_api_key,
66+
root_key_id=root_key_id,
67+
wrapped_dek=wrapped_dek,
68+
kp_id=kp_id,
69+
cloud_init=cloud_init,
70+
byol=byol,
71+
is_encrypted=is_encrypted
3672
)
3773

3874
if not result:

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=False,
126+
byol=False, is_encrypted=False):
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 Data Encryption Key provided by
142+
IBM KeyProtect
143+
:param string kp_id: ID of the IBM Key Protect Instance
144+
:param boolean cloud_init: Specifies if image is cloud-init
145+
:param boolean byol: Specifies if image is bring your own license
146+
:param boolean 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)