Skip to content

add new feature on vlan #1572

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

Merged
merged 4 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -354,6 +354,7 @@

('vlan', 'SoftLayer.CLI.vlan'),
('vlan:create', 'SoftLayer.CLI.vlan.create:cli'),
('vlan:create-options', 'SoftLayer.CLI.vlan.create_options:cli'),
('vlan:detail', 'SoftLayer.CLI.vlan.detail:cli'),
('vlan:edit', 'SoftLayer.CLI.vlan.edit:cli'),
('vlan:list', 'SoftLayer.CLI.vlan.list:cli'),
Expand Down
33 changes: 33 additions & 0 deletions SoftLayer/CLI/vlan/create_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Vlan order options."""
# :license: MIT, see LICENSE for more details.
# pylint: disable=too-many-statements
import click

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


@click.command(short_help="Get options to use for creating Vlan servers.")
@environment.pass_env
def cli(env):
"""List all the options for creating VLAN"""

mgr = SoftLayer.NetworkManager(env.client)
datacenters = mgr.get_list_datacenter()

table = formatting.Table(['Options', 'Value'], title="Datacenters")
router_table = formatting.Table(['Datacenter', 'Router/Pod'])
dc_table = formatting.Table(['Datacenters'])
table.add_row(['VLAN type', 'Private, Public'])

for datacenter in datacenters:
dc_table.add_row([datacenter['name']])
routers = mgr.get_routers(datacenter['id'])
for router in routers:
router_table.add_row([datacenter['name'], router['hostname']])

table.add_row(['Datacenters', dc_table])
table.add_row(['Routers', router_table])

env.fout(table)
2 changes: 2 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Location_Datacenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
"name": "dal09"
}
]

getHardwareRouters = []
14 changes: 14 additions & 0 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,17 @@ def get_pods(self, datacenter=None):
_filter = {"datacenterName": {"operation": datacenter}}

return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', filter=_filter)

def get_list_datacenter(self):
"""Calls SoftLayer_Location::getDatacenters()

returns all datacenter locations.
"""
return self.client.call('SoftLayer_Location_Datacenter', 'getDatacenters')

def get_routers(self, identifier):
"""Calls SoftLayer_Location::getRouters()

returns all routers locations.
"""
return self.client.call('SoftLayer_Location_Datacenter', 'getHardwareRouters', id=identifier)
4 changes: 4 additions & 0 deletions docs/cli/vlan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ VLANs
:prog: vlan create
:show-nested:

.. click:: SoftLayer.CLI.vlan.create_options:cli
:prog: vlan create-options
:show-nested:

.. click:: SoftLayer.CLI.vlan.detail:cli
:prog: vlan detail
:show-nested:
Expand Down
4 changes: 4 additions & 0 deletions tests/CLI/modules/vlan_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def test_detail(self):
result = self.run_command(['vlan', 'detail', '1234'])
self.assert_no_fail(result)

def test_create_options(self):
result = self.run_command(['vlan', 'create-options'])
self.assert_no_fail(result)

def test_detail_no_vs(self):
result = self.run_command(['vlan', 'detail', '1234', '--no-vs'])
self.assert_no_fail(result)
Expand Down