Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command ipsec order #1698

Merged
merged 4 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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
29 changes: 29 additions & 0 deletions SoftLayer/CLI/vpn/ipsec/order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""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 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)

result = ipsec_manager.order(datacenter, ['IPSEC_STANDARD'])
caberos marked this conversation as resolved.
Show resolved Hide resolved

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):
caberos marked this conversation as resolved.
Show resolved Hide resolved
"""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)