Skip to content

Commit 683af37

Browse files
Merge branch 'master' into orderingDocUpdates
2 parents 3cbda2a + f350a98 commit 683af37

File tree

17 files changed

+451
-37
lines changed

17 files changed

+451
-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
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Manages Object Storage S3 Credentials."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import importlib
5+
import os
6+
7+
import click
8+
9+
CONTEXT = {'help_option_names': ['-h', '--help'],
10+
'max_content_width': 999}
11+
12+
13+
class CapacityCommands(click.MultiCommand):
14+
"""Loads module for object storage S3 credentials related commands."""
15+
16+
def __init__(self, **attrs):
17+
click.MultiCommand.__init__(self, **attrs)
18+
self.path = os.path.dirname(__file__)
19+
20+
def list_commands(self, ctx):
21+
"""List all sub-commands."""
22+
commands = []
23+
for filename in os.listdir(self.path):
24+
if filename == '__init__.py':
25+
continue
26+
if filename.endswith('.py'):
27+
commands.append(filename[:-3].replace("_", "-"))
28+
commands.sort()
29+
return commands
30+
31+
def get_command(self, ctx, cmd_name):
32+
"""Get command for click."""
33+
path = "%s.%s" % (__name__, cmd_name)
34+
path = path.replace("-", "_")
35+
module = importlib.import_module(path)
36+
return getattr(module, 'cli')
37+
38+
39+
# Required to get the sub-sub-sub command to work.
40+
@click.group(cls=CapacityCommands, context_settings=CONTEXT)
41+
def cli():
42+
"""Base command for all object storage credentials S3 related concerns"""
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Create credentials for an IBM Cloud Object Storage Account."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Create credentials for an IBM Cloud Object Storage Account"""
16+
17+
mgr = SoftLayer.ObjectStorageManager(env.client)
18+
credential = mgr.create_credential(identifier)
19+
table = formatting.Table(['id', 'password', 'username', 'type_name'])
20+
table.sortby = 'id'
21+
table.add_row([
22+
credential['id'],
23+
credential['password'],
24+
credential['username'],
25+
credential['type']['name']
26+
])
27+
28+
env.fout(table)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Delete the credential of an Object Storage Account."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
9+
10+
@click.command()
11+
@click.argument('identifier')
12+
@click.option('--credential_id', '-c', type=click.INT,
13+
help="This is the credential id associated with the volume")
14+
@environment.pass_env
15+
def cli(env, identifier, credential_id):
16+
"""Delete the credential of an Object Storage Account."""
17+
18+
mgr = SoftLayer.ObjectStorageManager(env.client)
19+
credential = mgr.delete_credential(identifier, credential_id=credential_id)
20+
21+
env.fout(credential)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
""" Credential limits for this IBM Cloud Object Storage account."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Credential limits for this IBM Cloud Object Storage account."""
16+
17+
mgr = SoftLayer.ObjectStorageManager(env.client)
18+
credential_limit = mgr.limit_credential(identifier)
19+
table = formatting.Table(['limit'])
20+
table.add_row([
21+
credential_limit,
22+
])
23+
24+
env.fout(table)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Retrieve credentials used for generating an AWS signature. Max of 2."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Retrieve credentials used for generating an AWS signature. Max of 2."""
16+
17+
mgr = SoftLayer.ObjectStorageManager(env.client)
18+
credential_list = mgr.list_credential(identifier)
19+
table = formatting.Table(['id', 'password', 'username', 'type_name'])
20+
21+
for credential in credential_list:
22+
table.add_row([
23+
credential['id'],
24+
credential['password'],
25+
credential['username'],
26+
credential['type']['name']
27+
])
28+
29+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@
190190
('nas:credentials', 'SoftLayer.CLI.nas.credentials:cli'),
191191

192192
('object-storage', 'SoftLayer.CLI.object_storage'),
193+
193194
('object-storage:accounts', 'SoftLayer.CLI.object_storage.list_accounts:cli'),
194195
('object-storage:endpoints', 'SoftLayer.CLI.object_storage.list_endpoints:cli'),
196+
('object-storage:credential', 'SoftLayer.CLI.object_storage.credential:cli'),
195197

196198
('order', 'SoftLayer.CLI.order'),
197199
('order:category-list', 'SoftLayer.CLI.order.category_list:cli'),

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'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
credentialCreate = {
2+
"accountId": "12345",
3+
"createDate": "2019-04-05T13:25:25-06:00",
4+
"id": 11111,
5+
"password": "nwUEUsx6PiEoN0B1Xe9z9hUCyXMkAFhDOjHqYJva",
6+
"username": "XfHhBNBPlPdlWyaPPJAI",
7+
"type": {
8+
"description": "A credential for generating S3 Compatible Signatures.",
9+
"keyName": "S3_COMPATIBLE_SIGNATURE",
10+
"name": "S3 Compatible Signature"
11+
}
12+
}
13+
14+
getCredentials = [
15+
{
16+
"accountId": "12345",
17+
"createDate": "2019-04-05T13:25:25-06:00",
18+
"id": 11111,
19+
"password": "nwUEUsx6PiEoN0B1Xe9z9hUCyXMkAFhDOjHqYJva",
20+
"username": "XfHhBNBPlPdlWyaPPJAI",
21+
"type": {
22+
"description": "A credential for generating S3 Compatible Signatures.",
23+
"keyName": "S3_COMPATIBLE_SIGNATURE",
24+
"name": "S3 Compatible Signature"
25+
}
26+
},
27+
{
28+
"accountId": "12345",
29+
"createDate": "2019-04-05T13:25:25-06:00",
30+
"id": 11111,
31+
"password": "nwUEUsx6PiEoN0B1Xe9z9hUCyXMkAFhDOjHqYJva",
32+
"username": "XfHhBNBPlPdlWyaPPJAI",
33+
"type": {
34+
"description": "A credential for generating S3 Compatible Signatures.",
35+
"keyName": "S3_COMPATIBLE_SIGNATURE",
36+
"name": "S3 Compatible Signature"
37+
}
38+
}
39+
]

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

0 commit comments

Comments
 (0)