Skip to content

Commit 82359d8

Browse files
author
Fernando Ojeda
committed
2 parents 1b581fa + 9d6bf59 commit 82359d8

File tree

7 files changed

+78
-37
lines changed

7 files changed

+78
-37
lines changed

SoftLayer/CLI/image/import.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@
2525
"creating this key see https://console.bluemix.net/docs/"
2626
"services/cloud-object-storage/iam/users-serviceids.html"
2727
"#serviceidapikeys")
28-
@click.option('--root-key-id',
28+
@click.option('--root-key-crn',
2929
default=None,
30-
help="ID of the root key in Key Protect")
30+
help="CRN of the root key in your KMS instance")
3131
@click.option('--wrapped-dek',
3232
default=None,
3333
help="Wrapped Data Encryption Key provided by IBM KeyProtect. "
3434
"For more info see https://console.bluemix.net/docs/"
3535
"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")
3936
@click.option('--cloud-init',
4037
is_flag=True,
4138
help="Specifies if image is cloud-init")
@@ -46,8 +43,8 @@
4643
is_flag=True,
4744
help="Specifies if image is encrypted")
4845
@environment.pass_env
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):
46+
def cli(env, name, note, os_code, uri, ibm_api_key, root_key_crn, wrapped_dek,
47+
cloud_init, byol, is_encrypted):
5148
"""Import an image.
5249
5350
The URI for an object storage object (.vhd/.iso file) of the format:
@@ -63,9 +60,8 @@ def cli(env, name, note, os_code, uri, ibm_api_key, root_key_id, wrapped_dek,
6360
os_code=os_code,
6461
uri=uri,
6562
ibm_api_key=ibm_api_key,
66-
root_key_id=root_key_id,
63+
root_key_crn=root_key_crn,
6764
wrapped_dek=wrapped_dek,
68-
kp_id=kp_id,
6965
cloud_init=cloud_init,
7066
byol=byol,
7167
is_encrypted=is_encrypted

SoftLayer/CLI/subnet/create.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@click.argument('network', type=click.Choice(['public', 'private']))
1414
@click.argument('quantity', type=click.INT)
1515
@click.argument('vlan-id')
16-
@click.option('--v6', '--ipv6', is_flag=True, help="Order IPv6 Addresses")
16+
@click.option('--ipv6', '--v6', is_flag=True, help="Order IPv6 Addresses")
1717
@click.option('--test',
1818
is_flag=True,
1919
help="Do not order the subnet; just get a quote")
@@ -42,14 +42,10 @@ def cli(env, network, quantity, vlan_id, ipv6, test):
4242
if ipv6:
4343
version = 6
4444

45-
result = mgr.add_subnet(network,
46-
quantity=quantity,
47-
vlan_id=vlan_id,
48-
version=version,
49-
test_order=test)
50-
if not result:
51-
raise exceptions.CLIAbort(
52-
'Unable to place order: No valid price IDs found.')
45+
try:
46+
result = mgr.add_subnet(network, quantity=quantity, vlan_id=vlan_id, version=version, test_order=test)
47+
except SoftLayer.SoftLayerAPIError:
48+
raise exceptions.CLIAbort('There is no price id for {} {} ipv{}'.format(quantity, network, version))
5349

5450
table = formatting.Table(['Item', 'cost'])
5551
table.align['Item'] = 'r'

SoftLayer/managers/image.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def edit(self, image_id, name=None, note=None, tag=None):
121121
return bool(name or note or tag)
122122

123123
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,
124+
ibm_api_key=None, root_key_crn=None,
125+
wrapped_dek=None, cloud_init=False,
126126
byol=False, is_encrypted=False):
127127
"""Import a new image from object storage.
128128
@@ -136,11 +136,14 @@ def import_image_from_uri(self, name, uri, os_code=None, note=None,
136136
:param string os_code: The reference code of the operating system
137137
:param string note: Note to add to the image
138138
: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
139+
and your KMS
140+
:param string root_key_crn: CRN of the root key in your KMS. Go to your
141+
KMS (Key Protect or Hyper Protect) provider to get the CRN for your
142+
root key. An example CRN:
143+
crn:v1:bluemix:public:hs-crypto:us-south:acctID:serviceID:key:keyID'
144+
Used only when is_encrypted is True.
141145
: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
146+
your KMS. Used only when is_encrypted is True.
144147
:param boolean cloud_init: Specifies if image is cloud-init
145148
:param boolean byol: Specifies if image is bring your own license
146149
:param boolean is_encrypted: Specifies if image is encrypted
@@ -152,9 +155,8 @@ def import_image_from_uri(self, name, uri, os_code=None, note=None,
152155
'operatingSystemReferenceCode': os_code,
153156
'uri': uri,
154157
'ibmApiKey': ibm_api_key,
155-
'rootKeyId': root_key_id,
158+
'crkCrn': root_key_crn,
156159
'wrappedDek': wrapped_dek,
157-
'keyProtectId': kp_id,
158160
'cloudInit': cloud_init,
159161
'byol': byol,
160162
'isEncrypted': is_encrypted

SoftLayer/managers/network.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ def add_subnet(self, subnet_type, quantity=None, vlan_id=None, version=4,
153153
price_id = item['prices'][0]['id']
154154
break
155155

156-
if not price_id:
157-
raise TypeError('Invalid combination specified for ordering a'
158-
' subnet.')
159-
160156
order = {
161157
'packageId': 0,
162158
'prices': [{'id': price_id}],

tests/CLI/modules/subnet_tests.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
55
:license: MIT, see LICENSE for more details.
66
"""
7+
from SoftLayer.fixtures import SoftLayer_Product_Order
8+
from SoftLayer.fixtures import SoftLayer_Product_Package
79
from SoftLayer import testing
810

911
import json
12+
import mock
13+
import SoftLayer
1014

1115

1216
class SubnetTests(testing.TestCase):
17+
1318
def test_detail(self):
1419
result = self.run_command(['subnet', 'detail', '1234'])
1520

@@ -39,3 +44,54 @@ def test_detail(self):
3944
def test_list(self):
4045
result = self.run_command(['subnet', 'list'])
4146
self.assert_no_fail(result)
47+
48+
@mock.patch('SoftLayer.CLI.formatting.confirm')
49+
def test_create_subnet_ipv4(self, confirm_mock):
50+
confirm_mock.return_value = True
51+
52+
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
53+
item_mock.return_value = SoftLayer_Product_Package.getItems
54+
55+
place_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
56+
place_mock.return_value = SoftLayer_Product_Order.placeOrder
57+
58+
result = self.run_command(['subnet', 'create', 'private', '8', '12346'])
59+
self.assert_no_fail(result)
60+
61+
output = [
62+
{'Item': 'Total monthly cost', 'cost': '0.00'}
63+
]
64+
65+
self.assertEqual(output, json.loads(result.output))
66+
67+
@mock.patch('SoftLayer.CLI.formatting.confirm')
68+
def test_create_subnet_ipv6(self, confirm_mock):
69+
confirm_mock.return_value = True
70+
71+
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
72+
item_mock.return_value = SoftLayer_Product_Package.getItems
73+
74+
place_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder')
75+
place_mock.return_value = SoftLayer_Product_Order.verifyOrder
76+
77+
result = self.run_command(['subnet', 'create', '--v6', 'public', '64', '12346', '--test'])
78+
self.assert_no_fail(result)
79+
80+
output = [
81+
{'Item': 'this is a thing', 'cost': '2.00'},
82+
{'Item': 'Total monthly cost', 'cost': '2.00'}
83+
]
84+
85+
self.assertEqual(output, json.loads(result.output))
86+
87+
def test_create_subnet_no_prices_found(self):
88+
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
89+
item_mock.return_value = SoftLayer_Product_Package.getItems
90+
91+
verify_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder')
92+
verify_mock.side_effect = SoftLayer.SoftLayerAPIError('SoftLayer_Exception', 'Price not found')
93+
94+
result = self.run_command(['subnet', 'create', '--v6', 'public', '32', '12346', '--test'])
95+
96+
self.assertRaises(SoftLayer.SoftLayerAPIError, verify_mock)
97+
self.assertEqual(result.exception.message, 'There is no price id for 32 public ipv6')

tests/managers/image_tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ def test_import_image_cos(self):
151151
uri='cos://some_uri',
152152
os_code='UBUNTU_LATEST',
153153
ibm_api_key='some_ibm_key',
154-
root_key_id='some_root_key_id',
154+
root_key_crn='some_root_key_crn',
155155
wrapped_dek='some_dek',
156-
kp_id='some_id',
157156
cloud_init=False,
158157
byol=False,
159158
is_encrypted=False
@@ -167,9 +166,8 @@ def test_import_image_cos(self):
167166
'operatingSystemReferenceCode': 'UBUNTU_LATEST',
168167
'uri': 'cos://some_uri',
169168
'ibmApiKey': 'some_ibm_key',
170-
'rootKeyId': 'some_root_key_id',
169+
'crkCrn': 'some_root_key_crn',
171170
'wrappedDek': 'some_dek',
172-
'keyProtectId': 'some_id',
173171
'cloudInit': False,
174172
'byol': False,
175173
'isEncrypted': False

tests/managers/network_tests.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ def test_ip_lookup(self):
2828
'getByIpAddress',
2929
args=('10.0.1.37',))
3030

31-
def test_add_subnet_raises_exception_on_failure(self):
32-
self.assertRaises(TypeError, self.network.add_subnet, ('bad'))
33-
3431
def test_add_global_ip(self):
3532
# Test a global IPv4 order
3633
result = self.network.add_global_ip(test_order=True)

0 commit comments

Comments
 (0)