From 771f6cd9d24fc6c73423e1203a617041c6a7ddf0 Mon Sep 17 00:00:00 2001 From: rajeshk2013 <43401283+rajeshk2013@users.noreply.github.com> Date: Wed, 14 Nov 2018 17:59:55 +0530 Subject: [PATCH] [VP-1184, VP-1201] Provided command line support for convert to advanced 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 2: Enable distributed routing vcd gateway enable-distributed-routing --distributed-routing-enabled/--distributed-routing-disabled Testing Done: Added test case for both the use cases * removed extra character * Incorporated review comments --- system_tests/gateway_tests.py | 70 ++++++++++++++++++++++++----------- vcd_cli/gateway.py | 68 ++++++++++++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 26 deletions(-) diff --git a/system_tests/gateway_tests.py b/system_tests/gateway_tests.py index 25d4cb3f..86076323 100644 --- a/system_tests/gateway_tests.py +++ b/system_tests/gateway_tests.py @@ -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 -e " - "--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. @@ -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 -e " + "--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() diff --git a/vcd_cli/gateway.py b/vcd_cli/gateway.py index 4d4aa3ec..6df55d43 100644 --- a/vcd_cli/gateway.py +++ b/vcd_cli/gateway.py @@ -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 @@ -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 @@ -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 @@ -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='', 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 + 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='', required=True) +@click.option( + '--enable/--disable', + 'is_enabled', + default=False, + metavar='', + 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 + --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)