Skip to content

Commit d6e7f36

Browse files
Merge pull request #1875 from edsonarios/issue1873
New command `slcli image share-deny`
2 parents 325259d + b12863d commit d6e7f36

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

SoftLayer/CLI/image/share_deny.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Deny share an image template with another 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 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 deny share image template', required=True)
14+
@environment.pass_env
15+
def cli(env, identifier, account_id):
16+
"""Deny share an image template with 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.deny_share_image(image_id, account_id)
21+
22+
if shared_image:
23+
env.fout("Image template {} was deny 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
@@ -209,6 +209,7 @@
209209
('image:import', 'SoftLayer.CLI.image.import:cli'),
210210
('image:export', 'SoftLayer.CLI.image.export:cli'),
211211
('image:datacenter', 'SoftLayer.CLI.image.datacenter:cli'),
212+
('image:share-deny', 'SoftLayer.CLI.image.share_deny:cli'),
212213

213214
('ipsec', 'SoftLayer.CLI.vpn.ipsec'),
214215
('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+
denySharingAccess = 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 deny_share_image(self, image_id, account_id):
242+
"""Deny 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 deny share the image.
246+
"""
247+
248+
return self.vgbdtg.denySharingAccess(account_id, id=image_id)

docs/cli/image.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ Disk Image Commands
3030
.. click:: SoftLayer.CLI.image.datacenter:cli
3131
:prog: image datacenter
3232
:show-nested:
33+
34+
.. click:: SoftLayer.CLI.image.share_deny:cli
35+
:prog: image share-deny
36+
:show-nested:

tests/CLI/modules/image_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,18 @@ 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_deny_share(self):
58+
result = self.run_command(['image', 'share-deny', '123456', '--account-id', '654321'])
59+
self.assert_no_fail(result)
60+
self.assertIn("Image template 123456 was deny shared to account 654321.", result.output)
61+
62+
def test_deny_share_without_id(self):
63+
result = self.run_command(['image', 'share-deny'])
64+
self.assertEqual(2, result.exit_code)
65+
self.assertIn("Error: Missing argument 'IDENTIFIER'.", result.output)
66+
67+
def test_deny_share_without_id_account(self):
68+
result = self.run_command(['image', 'share-deny', "123456"])
69+
self.assertEqual(2, result.exit_code)
70+
self.assertIn("Error: Missing option '--account-id'.", result.output)

tests/managers/image_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,9 @@ def test_get_locations_id_fails(self):
223223
100,
224224
locations
225225
)
226+
227+
def test_deny_share_image(self):
228+
result = self.image.deny_share_image(image_id=123456, account_id=654321)
229+
230+
self.assert_called_with(IMAGE_SERVICE, 'denySharingAccess', identifier=123456, args=(654321,))
231+
self.assertEqual(True, result)

0 commit comments

Comments
 (0)