Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
[VP-1184, VP-1201] Provided command line support for convert to advan…
Browse files Browse the repository at this point in the history
…ced gateway and enable distributed routing (#260)

* VP-1184, 1201 Provided command line support for convert to advanced gateway and enable distributed routing

This will enable the command line support for
1: Convert legacy gateway to advanced gateway
	vcd gateway convert-to-advanced <name>
2: Enable distributed routing
	vcd gateway enable-distributed-routing <gw_name> --distributed-routing-enabled/--distributed-routing-disabled

Testing Done: Added test case for both the use cases

* removed extra character

* Incorporated review comments
  • Loading branch information
rajeshk2013 authored Nov 14, 2018
1 parent ec512e2 commit 771f6cd
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 26 deletions.
70 changes: 48 additions & 22 deletions system_tests/gateway_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,7 @@ def test_0003_create_gateway_with_sub_allocate_ip_and_subnet(self):
self.assertEqual(0, result_create3.exit_code)
self._delete_gateway()

def test_0004_create_gateway_with_configure_rate_limit(self):
"""Create gateway with options --configure-rate-limit.
It will delete the gateway after creation
"""
result_create4 = GatewayTest._runner.invoke(
gateway,
args=[
'create', self._name, '-e', GatewayTest._ext_network_name,
'--configure-rate-limit', GatewayTest._ext_network_name, 100,
101
])
GatewayTest._logger.debug("vcd gateway create <name> -e <ext nw> "
"--configure-rate-limit', {0}, 100, "
"101]: {1}".format(
GatewayTest._ext_network_name,
result_create4.output))
self.assertEqual(0, result_create4.exit_code)
self._delete_gateway()

def test_0005_create_gateway_with_default_gateway_and_dns_relay_enabled(
def test_0004_create_gateway_with_default_gateway_and_dns_relay_enabled(
self):
"""Create gateway with options --default-gateway --default-gw-ip
--dns-relay-enabled --advanced-enabled.
Expand All @@ -196,11 +176,57 @@ def test_0005_create_gateway_with_default_gateway_and_dns_relay_enabled(
self.assertEqual(0, result_create5.exit_code)
self._delete_gateway()

def test_0005_create_gateway_with_configure_rate_limit(self):
"""Create gateway with options --configure-rate-limit.
It will delete the gateway after creation
"""
result_create4 = GatewayTest._runner.invoke(
gateway,
args=[
'create', self._name, '-e', GatewayTest._ext_network_name,
'--configure-rate-limit', GatewayTest._ext_network_name, 100,
101
])
GatewayTest._logger.debug("vcd gateway create <name> -e <ext nw> "
"--configure-rate-limit', {0}, 100, "
"101]: {1}".format(
GatewayTest._ext_network_name,
result_create4.output))
self.assertEqual(0, result_create4.exit_code)

def _delete_gateway(self):
result_delete1 = GatewayTest._runner.invoke(
gateway, args=['delete', self._name])
self.assertEqual(0, result_delete1.exit_code)

def test_0006_tearDown(self):
def test_0006_convert_to_advanced_gateway(self):
"""Convert legacy gateway to advance gateway.
It will trigger the cli command with option convert-to-advanced
"""
result_advanced_gateway = self._runner.invoke(gateway,
args=[
'convert-to-advanced',
'test_gateway1'])
self.assertEqual(0, result_advanced_gateway.exit_code)

def test_0007_enable_distributed_routing(self):
"""Enable Distributed routing for advanced gateway.
It will trigger the cli command with option enable-distributed-routing
"""
result_advanced_gateway = self._runner.invoke(gateway,
args=[
'enable-distributed-routing',
'test_gateway1',
'--enable'])
self.assertEqual(0, result_advanced_gateway.exit_code)


def test_0098_tearDown(self):
result_delete = self._runner.invoke(gateway, args=['delete',
'test_gateway1'])
self.assertEqual(0, result_delete.exit_code)
"""Logout ignoring any errors to ensure test session is gone."""
self._logout()
68 changes: 64 additions & 4 deletions vcd_cli/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from vcd_cli.utils import stderr
from vcd_cli.utils import stdout
from vcd_cli.vcd import vcd
from pyvcloud.vcd.gateway import Gateway
from vcd_cli.utils import tuple_to_dict


Expand Down Expand Up @@ -174,8 +175,7 @@ def create_gateway(ctx, name, external_networks_name, description,
"""Create a gateway.
\b
Note
Both System Administrators and Organization Administrators can
create gateway.
System Administrators can create gateway.
\b
Examples
Expand Down Expand Up @@ -311,8 +311,7 @@ def delete_gateway(ctx, name):
"""delete a gateway.
\b
Note
Both System Administrators and Organization Administrators can
delete gateway.
System Administrators can delete gateway.
\b
Examples
vcd gateway delete <gateway-name>
Expand All @@ -327,3 +326,64 @@ def delete_gateway(ctx, name):
stdout(task, ctx)
except Exception as e:
stderr(e, ctx)

@gateway.command('convert-to-advanced', short_help='convert to advanced '
'gateway')
@click.pass_context
@click.argument('name', metavar='<gateway name>', required=True)
def convert_to_advanced_gateway(ctx, name):
"""Convert to advanced gateway.
\b
Note
System Administrators and Organization Administrator can
convert legacy gateway to advanced.
\b
Examples
vcd gateway convert-to-advanced <gateway-name>
Convert gateway to advanced by providing gateway name
"""
try:
restore_session(ctx, vdc_required=True)
client = ctx.obj['client']
vdc_href = ctx.obj['profiles'].get('vdc_href')
vdc = VDC(client, href=vdc_href)
gateway = vdc.get_gateway(name)
gateway_resource = Gateway(client, href=gateway.get('href'))
task = gateway_resource.convert_to_advanced()
stdout(task, ctx)
except Exception as e:
stderr(e, ctx)

@gateway.command('enable-distributed-routing', short_help='enable '
'distributed '
'routing for '
'gateway')
@click.pass_context
@click.argument('name', metavar='<gateway name>', required=True)
@click.option(
'--enable/--disable',
'is_enabled',
default=False,
metavar='<is_distributed>',
help='Enable distributed routing for networks connected to this gateway.')
def enable_distributed_routing(ctx, name, is_enabled=False):
"""Enable Distributed routing for gateway.
\b
Examples
vcd gateway enable-distributed-routing <gateway-name>
--enable/--disable
Enable/Disable Distributed routing for gateway.
"""
try:
restore_session(ctx, vdc_required=True)
client = ctx.obj['client']
vdc_href = ctx.obj['profiles'].get('vdc_href')
vdc = VDC(client, href=vdc_href)
gateway = vdc.get_gateway(name)
gateway_resource = Gateway(client, href=gateway.get('href'))
task = gateway_resource.enable_distributed_routing(is_enabled)
stdout(task, ctx)
except Exception as e:
stderr(e, ctx)

0 comments on commit 771f6cd

Please sign in to comment.