Skip to content

Commit 8a4587b

Browse files
committed
Added new command - slcli image share, also added unit test for this command
1 parent 0e65657 commit 8a4587b

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

SoftLayer/CLI/image/share.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Get details for an image."""
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 helpers
9+
10+
11+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
12+
@click.argument('identifier')
13+
@click.option('--account-id', help='Account Id for another account to share image template', required=True)
14+
@environment.pass_env
15+
def cli(env, identifier, account_id):
16+
"""Permit share an image template to another account."""
17+
18+
image_mgr = SoftLayer.ImageManager(env.client)
19+
image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image')
20+
shared_image = image_mgr.share_image(image_id, account_id)
21+
22+
if shared_image:
23+
env.fout("Image template {} was shared to account {}.".format(identifier, account_id))

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
('image:import', 'SoftLayer.CLI.image.import:cli'),
209209
('image:export', 'SoftLayer.CLI.image.export:cli'),
210210
('image:datacenter', 'SoftLayer.CLI.image.datacenter:cli'),
211+
('image:share', 'SoftLayer.CLI.image.share:cli'),
211212

212213
('ipsec', 'SoftLayer.CLI.vpn.ipsec'),
213214
('ipsec:configure', 'SoftLayer.CLI.vpn.ipsec.configure:cli'),

SoftLayer/fixtures/SoftLayer_Virtual_Guest_Block_Device_Template_Group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@
5353
{'id': 265592, 'longName': 'Amsterdam 1', 'name': 'ams01', 'statusId': 2},
5454
{'id': 814994, 'longName': 'Amsterdam 3', 'name': 'ams03', 'statusId': 2},
5555
]
56+
permitSharingAccess = True

SoftLayer/managers/image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,12 @@ def get_locations_list(self, image_id, location_names):
237237
locations_ids.append(matching_location)
238238

239239
return locations_ids
240+
241+
def share_image(self, image_id, account_id):
242+
"""Permit sharing image template with another account.
243+
244+
:param int image_id: The ID of the image.
245+
:param int account_id: The ID of the another account to share the image.
246+
"""
247+
248+
return self.vgbdtg.permitSharingAccess(account_id, id=image_id)

tests/CLI/modules/image_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ def test_datacenter_remove(self):
5353
def test_datacenter_remove_fails(self):
5454
result = self.run_command(['image', 'datacenter', '100', '--remove'])
5555
self.assertEqual(2, result.exit_code)
56+
57+
def test_share(self):
58+
result = self.run_command(['image', 'share', '123456', '--account-id', '654321'])
59+
self.assert_no_fail(result)
60+
61+
def test_share_without_id(self):
62+
result = self.run_command(['image', 'share'])
63+
self.assertEqual(2, result.exit_code)
64+
65+
def test_share_without_id_account(self):
66+
result = self.run_command(['image', 'share', "123456"])
67+
self.assertEqual(2, result.exit_code)

0 commit comments

Comments
 (0)