Skip to content

Commit

Permalink
Merge pull request #1698 from caberos/issue1696
Browse files Browse the repository at this point in the history
New command ipsec order
  • Loading branch information
allmightyspiff authored Jul 29, 2022
2 parents 0c0c799 + dec28cb commit 248a52a
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
('ipsec:translation-remove', 'SoftLayer.CLI.vpn.ipsec.translation.remove:cli'),
('ipsec:translation-update', 'SoftLayer.CLI.vpn.ipsec.translation.update:cli'),
('ipsec:update', 'SoftLayer.CLI.vpn.ipsec.update:cli'),
('ipsec:order', 'SoftLayer.CLI.vpn.ipsec.order:cli'),

('loadbal', 'SoftLayer.CLI.loadbal'),
('loadbal:detail', 'SoftLayer.CLI.loadbal.detail:cli'),
Expand Down
34 changes: 34 additions & 0 deletions SoftLayer/CLI/vpn/ipsec/order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Order a IPSec VPN tunnel."""
# :licenses: MIT, see LICENSE for more details.

import click

import SoftLayer

from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting


@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.option('--datacenter', '-d', required=True, prompt=True, help="Datacenter shortname")
@environment.pass_env
def cli(env, datacenter):
"""Order/create a IPSec VPN tunnel instance."""

ipsec_manager = SoftLayer.IPSECManager(env.client)

if not (env.skip_confirmations or formatting.confirm(
"This action will incur charges on your account. Continue?")):
raise exceptions.CLIAbort('Aborting ipsec order.')

result = ipsec_manager.order(datacenter, ['IPSEC_STANDARD'])

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['Id', result['orderId']])
table.add_row(['Created', result['orderDate']])
table.add_row(['Name', result['placedOrder']['items'][0]['description']])

env.fout(table)
18 changes: 18 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Product_Order.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,21 @@
"id": 1071,
"keyName": "PUBLIC_NETWORK_VLAN"}}
]}

ipsec_placeOrder = {
"orderDate": "2022-07-14T16:09:08-06:00",
"orderId": 123456,
"placedOrder": {
"items": [
{
"categoryCode": "network_tunnel",
"description": "IPSEC - Standard",
"id": 931479898,
"itemId": 1092,
"itemPriceId": "2048",

}
]

}
}
45 changes: 45 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Product_Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,3 +2171,48 @@
}]
}
]

getAllObjectsIPSEC = [{
"firstOrderStepId": 1,
"id": 0,
"isActive": 1,
"keyName": "ADDITIONAL_PRODUCTS",
"name": "Additional Products"}]

getItems_IPSEC = [{
"description": "IPSEC - Standard",
"id": 1092,
"keyName": "IPSEC_STANDARD",
"categories": [
{
"categoryCode": "network_tunnel",
"id": 117,
"name": "Network Tunnel",
"quantityLimit": 0,
},
{
"categoryCode": "one_time_charge",
"id": 33,
"name": "One Time Charge",
"quantityLimit": 0,
}
],
"itemCategory": {
"categoryCode": "network_tunnel",
"id": 117,
"name": "Network Tunnel",
"quantityLimit": 0,
},
"prices": [
{
"id": 51379,
"itemId": 1092,
"laborFee": "0",
"locationGroupId": 503,
"oneTimeFee": "0",
"recurringFee": "102",
"setupFee": "0",
"sort": 0,
}
]
}]
15 changes: 15 additions & 0 deletions SoftLayer/managers/ipsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from SoftLayer.exceptions import SoftLayerAPIError
from SoftLayer.managers import ordering
from SoftLayer import utils


Expand Down Expand Up @@ -284,3 +285,17 @@ def update_tunnel_context(self, context_id, friendly_name=None,
if phase2_key_ttl is not None:
context['phaseTwoKeylife'] = phase2_key_ttl
return self.context.editObject(context, id=context_id)

def order(self, datacenter, item_package):
"""Create a ipsec.
:param string datacenter: the datacenter shortname
:param string[] item_package: items array
"""
complex_type = 'SoftLayer_Container_Product_Order_Network_Tunnel_Ipsec'
ordering_manager = ordering.OrderingManager(self.client)
return ordering_manager.place_order(package_keyname='ADDITIONAL_PRODUCTS',
location=datacenter,
item_keynames=item_package,
complex_type=complex_type,
hourly=False)
4 changes: 4 additions & 0 deletions docs/cli/ipsec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,7 @@ The following is an example of updating an existing address translation entry.

$ slcli ipsec translation-update 445 --translation-id 15924 --static-ip 10.1.249.86 --remote-ip 50.100.0.8 --note 'new email server'
Updated translation #15924

.. click:: SoftLayer.CLI.vpn.ipsec.order:cli
:prog: ipsec order
:show-nested:
12 changes: 12 additions & 0 deletions tests/CLI/modules/ipsec_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

import json


from SoftLayer.CLI.exceptions import ArgumentError
from SoftLayer.CLI.exceptions import CLIHalt
from SoftLayer.fixtures import SoftLayer_Product_Order
from SoftLayer.fixtures import SoftLayer_Product_Package
from SoftLayer import testing
from SoftLayer import utils

Expand Down Expand Up @@ -508,3 +511,12 @@ def test_ipsec_translation_update(self):
'internalIpAddress': '10.50.0.1',
'customerIpAddress': '50.50.0.1',
'notes': 'lost'},))

def test_ipsec_order(self):
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
_mock.return_value = SoftLayer_Product_Package.getItems_IPSEC

order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
order_mock.return_value = SoftLayer_Product_Order.ipsec_placeOrder
result = self.run_command(['ipsec', 'order', '-d', 'dal13'])
self.assert_no_fail(result)
20 changes: 20 additions & 0 deletions tests/managers/ipsec_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import SoftLayer
from SoftLayer.exceptions import SoftLayerAPIError
from SoftLayer.fixtures import SoftLayer_Product_Order
from SoftLayer.fixtures import SoftLayer_Product_Package

from SoftLayer import testing


Expand Down Expand Up @@ -299,3 +302,20 @@ def test_update_tunnel_context(self):
'phaseTwoKeylife': 240,
'phaseTwoPerfectForwardSecrecy': 1},),
identifier=445)

def test_order(self):
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
_mock.return_value = SoftLayer_Product_Package.getItems_IPSEC

_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
_mock.return_value = SoftLayer_Product_Order.ipsec_placeOrder
result = self.ipsec.order('dal13', ['IPSEC_STANDARD'])
order = {
'orderDate': '2022-07-14T16:09:08-06:00',
'orderId': 123456, 'placedOrder': {'items': [
{'categoryCode': 'network_tunnel',
'description': 'IPSEC - Standard',
'id': 931479898,
'itemId': 1092,
'itemPriceId': '2048'}]}}
self.assertEqual(result, order)

0 comments on commit 248a52a

Please sign in to comment.