Skip to content

Commit 248a52a

Browse files
Merge pull request #1698 from caberos/issue1696
New command ipsec order
2 parents 0c0c799 + dec28cb commit 248a52a

File tree

8 files changed

+149
-0
lines changed

8 files changed

+149
-0
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
('ipsec:translation-remove', 'SoftLayer.CLI.vpn.ipsec.translation.remove:cli'),
213213
('ipsec:translation-update', 'SoftLayer.CLI.vpn.ipsec.translation.update:cli'),
214214
('ipsec:update', 'SoftLayer.CLI.vpn.ipsec.update:cli'),
215+
('ipsec:order', 'SoftLayer.CLI.vpn.ipsec.order:cli'),
215216

216217
('loadbal', 'SoftLayer.CLI.loadbal'),
217218
('loadbal:detail', 'SoftLayer.CLI.loadbal.detail:cli'),

SoftLayer/CLI/vpn/ipsec/order.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Order a IPSec VPN tunnel."""
2+
# :licenses: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import exceptions
10+
from SoftLayer.CLI import formatting
11+
12+
13+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
14+
@click.option('--datacenter', '-d', required=True, prompt=True, help="Datacenter shortname")
15+
@environment.pass_env
16+
def cli(env, datacenter):
17+
"""Order/create a IPSec VPN tunnel instance."""
18+
19+
ipsec_manager = SoftLayer.IPSECManager(env.client)
20+
21+
if not (env.skip_confirmations or formatting.confirm(
22+
"This action will incur charges on your account. Continue?")):
23+
raise exceptions.CLIAbort('Aborting ipsec order.')
24+
25+
result = ipsec_manager.order(datacenter, ['IPSEC_STANDARD'])
26+
27+
table = formatting.KeyValueTable(['Name', 'Value'])
28+
table.align['name'] = 'r'
29+
table.align['value'] = 'l'
30+
table.add_row(['Id', result['orderId']])
31+
table.add_row(['Created', result['orderDate']])
32+
table.add_row(['Name', result['placedOrder']['items'][0]['description']])
33+
34+
env.fout(table)

SoftLayer/fixtures/SoftLayer_Product_Order.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,21 @@
303303
"id": 1071,
304304
"keyName": "PUBLIC_NETWORK_VLAN"}}
305305
]}
306+
307+
ipsec_placeOrder = {
308+
"orderDate": "2022-07-14T16:09:08-06:00",
309+
"orderId": 123456,
310+
"placedOrder": {
311+
"items": [
312+
{
313+
"categoryCode": "network_tunnel",
314+
"description": "IPSEC - Standard",
315+
"id": 931479898,
316+
"itemId": 1092,
317+
"itemPriceId": "2048",
318+
319+
}
320+
]
321+
322+
}
323+
}

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,3 +2171,48 @@
21712171
}]
21722172
}
21732173
]
2174+
2175+
getAllObjectsIPSEC = [{
2176+
"firstOrderStepId": 1,
2177+
"id": 0,
2178+
"isActive": 1,
2179+
"keyName": "ADDITIONAL_PRODUCTS",
2180+
"name": "Additional Products"}]
2181+
2182+
getItems_IPSEC = [{
2183+
"description": "IPSEC - Standard",
2184+
"id": 1092,
2185+
"keyName": "IPSEC_STANDARD",
2186+
"categories": [
2187+
{
2188+
"categoryCode": "network_tunnel",
2189+
"id": 117,
2190+
"name": "Network Tunnel",
2191+
"quantityLimit": 0,
2192+
},
2193+
{
2194+
"categoryCode": "one_time_charge",
2195+
"id": 33,
2196+
"name": "One Time Charge",
2197+
"quantityLimit": 0,
2198+
}
2199+
],
2200+
"itemCategory": {
2201+
"categoryCode": "network_tunnel",
2202+
"id": 117,
2203+
"name": "Network Tunnel",
2204+
"quantityLimit": 0,
2205+
},
2206+
"prices": [
2207+
{
2208+
"id": 51379,
2209+
"itemId": 1092,
2210+
"laborFee": "0",
2211+
"locationGroupId": 503,
2212+
"oneTimeFee": "0",
2213+
"recurringFee": "102",
2214+
"setupFee": "0",
2215+
"sort": 0,
2216+
}
2217+
]
2218+
}]

SoftLayer/managers/ipsec.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from SoftLayer.exceptions import SoftLayerAPIError
10+
from SoftLayer.managers import ordering
1011
from SoftLayer import utils
1112

1213

@@ -284,3 +285,17 @@ def update_tunnel_context(self, context_id, friendly_name=None,
284285
if phase2_key_ttl is not None:
285286
context['phaseTwoKeylife'] = phase2_key_ttl
286287
return self.context.editObject(context, id=context_id)
288+
289+
def order(self, datacenter, item_package):
290+
"""Create a ipsec.
291+
292+
:param string datacenter: the datacenter shortname
293+
:param string[] item_package: items array
294+
"""
295+
complex_type = 'SoftLayer_Container_Product_Order_Network_Tunnel_Ipsec'
296+
ordering_manager = ordering.OrderingManager(self.client)
297+
return ordering_manager.place_order(package_keyname='ADDITIONAL_PRODUCTS',
298+
location=datacenter,
299+
item_keynames=item_package,
300+
complex_type=complex_type,
301+
hourly=False)

docs/cli/ipsec.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,7 @@ The following is an example of updating an existing address translation entry.
272272

273273
$ slcli ipsec translation-update 445 --translation-id 15924 --static-ip 10.1.249.86 --remote-ip 50.100.0.8 --note 'new email server'
274274
Updated translation #15924
275+
276+
.. click:: SoftLayer.CLI.vpn.ipsec.order:cli
277+
:prog: ipsec order
278+
:show-nested:

tests/CLI/modules/ipsec_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
import json
99

10+
1011
from SoftLayer.CLI.exceptions import ArgumentError
1112
from SoftLayer.CLI.exceptions import CLIHalt
13+
from SoftLayer.fixtures import SoftLayer_Product_Order
14+
from SoftLayer.fixtures import SoftLayer_Product_Package
1215
from SoftLayer import testing
1316
from SoftLayer import utils
1417

@@ -508,3 +511,12 @@ def test_ipsec_translation_update(self):
508511
'internalIpAddress': '10.50.0.1',
509512
'customerIpAddress': '50.50.0.1',
510513
'notes': 'lost'},))
514+
515+
def test_ipsec_order(self):
516+
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
517+
_mock.return_value = SoftLayer_Product_Package.getItems_IPSEC
518+
519+
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
520+
order_mock.return_value = SoftLayer_Product_Order.ipsec_placeOrder
521+
result = self.run_command(['ipsec', 'order', '-d', 'dal13'])
522+
self.assert_no_fail(result)

tests/managers/ipsec_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import SoftLayer
1010
from SoftLayer.exceptions import SoftLayerAPIError
11+
from SoftLayer.fixtures import SoftLayer_Product_Order
12+
from SoftLayer.fixtures import SoftLayer_Product_Package
13+
1114
from SoftLayer import testing
1215

1316

@@ -299,3 +302,20 @@ def test_update_tunnel_context(self):
299302
'phaseTwoKeylife': 240,
300303
'phaseTwoPerfectForwardSecrecy': 1},),
301304
identifier=445)
305+
306+
def test_order(self):
307+
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
308+
_mock.return_value = SoftLayer_Product_Package.getItems_IPSEC
309+
310+
_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
311+
_mock.return_value = SoftLayer_Product_Order.ipsec_placeOrder
312+
result = self.ipsec.order('dal13', ['IPSEC_STANDARD'])
313+
order = {
314+
'orderDate': '2022-07-14T16:09:08-06:00',
315+
'orderId': 123456, 'placedOrder': {'items': [
316+
{'categoryCode': 'network_tunnel',
317+
'description': 'IPSEC - Standard',
318+
'id': 931479898,
319+
'itemId': 1092,
320+
'itemPriceId': '2048'}]}}
321+
self.assertEqual(result, order)

0 commit comments

Comments
 (0)