Skip to content

Commit 8618d12

Browse files
Merge pull request #1886 from caberos/issue1883
New Command, account hook-create feature
2 parents 2dc1450 + e66689b commit 8618d12

File tree

7 files changed

+64
-0
lines changed

7 files changed

+64
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Order/create a provisioning script."""
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(cls=SoftLayer.CLI.command.SLCommand)
12+
@click.option('--name', '-N', required=True, prompt=True, help="The name of the hook.")
13+
@click.option('--uri', '-U', required=True, prompt=True, help="The endpoint that the script will be downloaded")
14+
@environment.pass_env
15+
def cli(env, name, uri):
16+
"""Order/create a provisioning script."""
17+
18+
manager = SoftLayer.AccountManager(env.client)
19+
20+
provisioning = manager.create_provisioning(name, uri)
21+
22+
table = formatting.KeyValueTable(['name', 'value'])
23+
table.align['name'] = 'r'
24+
table.align['value'] = 'l'
25+
26+
table.add_row(['Id', provisioning.get('id')])
27+
table.add_row(['Name', provisioning.get('name')])
28+
table.add_row(['Created', provisioning.get('createDate')])
29+
table.add_row(['Uri', provisioning.get('uri')])
30+
31+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
('account:orders', 'SoftLayer.CLI.account.orders:cli'),
2626
('account:bandwidth-pools', 'SoftLayer.CLI.account.bandwidth_pools:cli'),
2727
('account:hooks', 'SoftLayer.CLI.account.hooks:cli'),
28+
('account:hook-create', 'SoftLayer.CLI.account.hook_create:cli'),
2829

2930
('virtual', 'SoftLayer.CLI.virt'),
3031
('virtual:bandwidth', 'SoftLayer.CLI.virt.bandwidth:cli'),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
createObject = {
2+
'createDate': '2023-03-22T06:37:45-06:00',
3+
'id': 207054,
4+
'name': 'testslcli',
5+
'uri': 'http://slclitest.com',
6+
'hookType': {}
7+
}

SoftLayer/managers/account.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,15 @@ def get_provisioning_scripts(self):
395395
"""
396396

397397
return self.client.call('Account', 'getPostProvisioningHooks')
398+
399+
def create_provisioning(self, name, uri):
400+
"""create a provisioning script
401+
402+
:param name: Name of the hook.
403+
:param uri: endpoint that the script will be downloaded
404+
"""
405+
template = {
406+
'name': name,
407+
'uri': uri
408+
}
409+
return self.client.call('SoftLayer_Provisioning_Hook', 'createObject', template)

docs/cli/account.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ Account Commands
5555
.. click:: SoftLayer.CLI.account.hooks:cli
5656
:prog: account hooks
5757
:show-nested:
58+
59+
.. click:: SoftLayer.CLI.account.hook_create:cli
60+
:prog: account hook-create
61+
:show-nested:

tests/CLI/modules/account_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,8 @@ def test_acccount_provisioning_hook(self):
164164
result = self.run_command(['account', 'hooks'])
165165
self.assert_no_fail(result)
166166
self.assert_called_with('SoftLayer_Account', 'getPostProvisioningHooks')
167+
168+
def test_created_provisioning_hook(self):
169+
result = self.run_command(['account', 'hook-create', '--name', 'testslcli', '--uri', 'http://slclitest.com'])
170+
self.assert_no_fail(result)
171+
self.assert_called_with('SoftLayer_Provisioning_Hook', 'createObject')

tests/managers/account_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,7 @@ def test_get_bandwidth_pool_counts(self):
180180
def test_get_provisioning_scripts(self):
181181
self.manager.get_provisioning_scripts()
182182
self.assert_called_with("SoftLayer_Account", "getPostProvisioningHooks")
183+
184+
def test_create_provisioning_scripts(self):
185+
self.manager.create_provisioning('testslcli', 'http://slclitest.com')
186+
self.assert_called_with('SoftLayer_Provisioning_Hook', 'createObject')

0 commit comments

Comments
 (0)