示例#1
0
    def __create_advanced_gateway(self):
        """Creates a gateway."""

        ext_config = TestIpSecVpn._config['external_network']
        vdc_reource = TestIpSecVpn._vdc_resource
        api_version = TestIpSecVpn._config['vcd']['api_version']
        vdc = VDC(TestIpSecVpn._client, resource=vdc_reource)
        gateway = vdc.get_gateway(TestIpSecVpn._gateway_name)
        if self.__does_exist_gateway(TestIpSecVpn._gateway_name):
            return

        if float(api_version) <= float(
                ApiVersion.VERSION_30.value):
            gateway = vdc.create_gateway_api_version_30(
                TestIpSecVpn._gateway_name, [ext_config['name']])
        elif float(api_version) == float(ApiVersion.VERSION_31.value):
            gateway = vdc.create_gateway_api_version_31(
                TestIpSecVpn._gateway_name,
                [ext_config['name']],
                should_create_as_advanced=True)
        elif float(api_version) >= float(ApiVersion.VERSION_32.value):
            gateway = vdc.create_gateway_api_version_32(
                TestIpSecVpn._gateway_name, [ext_config['name']],
                should_create_as_advanced=True)

        TestIpSecVpn._client.get_task_monitor(). \
            wait_for_success(task=gateway.Tasks.Task[0])
        TestIpSecVpn._gateway_href = gateway.get('href')
        TestIpSecVpn._gateway_obj = Gateway(TestIpSecVpn._client,
                                            href=TestIpSecVpn._gateway_href)
        TestIpSecVpn._gateway_resource = TestIpSecVpn. \
            _gateway_obj.get_resource()
示例#2
0
    def __create_advanced_gateway(self):
        """Creates a gateway."""

        ext_config = TestIpSecVpn._config['external_network']
        vdc_reource = TestIpSecVpn._vdc_resource
        api_version = TestIpSecVpn._config['vcd']['api_version']
        vdc = VDC(TestIpSecVpn._client, resource=vdc_reource)
        gateway = vdc.get_gateway(TestIpSecVpn._gateway_name)
        if self.__does_exist_gateway(TestIpSecVpn._gateway_name):
            return

        if float(api_version) <= float(
                ApiVersion.VERSION_30.value):
            gateway = vdc.create_gateway_api_version_30(
                TestIpSecVpn._gateway_name, [ext_config['name']])
        elif float(api_version) == float(ApiVersion.VERSION_31.value):
            gateway = vdc.create_gateway_api_version_31(
                TestIpSecVpn._gateway_name,
                [ext_config['name']],
                should_create_as_advanced=True)
        elif float(api_version) >= float(ApiVersion.VERSION_32.value):
            gateway = vdc.create_gateway_api_version_32(
                TestIpSecVpn._gateway_name, [ext_config['name']],
                should_create_as_advanced=True)

        TestIpSecVpn._client.get_task_monitor(). \
            wait_for_success(task=gateway.Tasks.Task[0])
        TestIpSecVpn._gateway_href = gateway.get('href')
        TestIpSecVpn._gateway_obj = Gateway(TestIpSecVpn._client,
                                            href=TestIpSecVpn._gateway_href)
        TestIpSecVpn._gateway_resource = TestIpSecVpn. \
            _gateway_obj.get_resource()
示例#3
0
class VdcGW(VcdAnsibleModule):
    def __init__(self, **kwargs):
        super(VdcGW, self).__init__(**kwargs)
        self.vdc_name = self.params.get('vdc_name')
        self.org_name = self.params.get('org_name')
        org_resource = self.client.get_org_by_name(self.org_name)
        self.org = Org(self.client, resource=org_resource)
        vdc_resource = self.org.get_vdc(self.vdc_name)
        self.vdc = VDC(self.client, name=self.vdc_name, resource=vdc_resource)

    def manage_states(self):
        state = self.params.get('state')
        if state == "present":
            return self.create_gw()

        if state == "update":
            return self.update_gw()

        if state == "absent":
            return self.delete_gw()

    def get_gateway(self, gateway_name):
        gateway = self.vdc.get_gateway(gateway_name)
        if gateway is None:
            raise EntityNotFoundException(
                "Edge gateway {0} is not present".format(gateway_name))

        return gateway

    def create_gw(self):
        api_version = self.client.get_api_version()
        if api_version == "30.0":
            return self.create_gateway_api_version_30()

        if api_version == "31.0":
            return self.create_gateway_api_version_31()

        if api_version == "32.0":
            return self.create_gateway_api_version_32()

    def create_gateway_api_version_30(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        description = self.params.get('description')
        external_networks = self.params.get('external_networks')
        gateway_backing_config = self.params.get('gateway_backing_config')
        default_gateway = self.params.get('default_gateway')
        extnw_for_default_gw = self.params.get('extnw_for_default_gw')
        default_gateway_ip = self.params.get('default_gateway_ip')
        default_gw_for_dns_relay = self.params.get('default_gw_for_dns_relay')
        ha_enabled = self.params.get('ha_enabled')
        create_as_advanced_gw = self.params.get('create_as_advanced_gw')
        dr_enabled = self.params.get('dr_enabled')
        configure_ip_settings = self.params.get('configure_ip_settings')
        sub_allocate_ip_pools = self.params.get('sub_allocate_ip_pools')
        ext_net_to_rate_limit = self.params.get('ext_net_to_rate_limit')
        ext_net_to_subnet_with_ip_range = self.params.get(
            'ext_net_to_subnet_with_ip_range')
        ext_net_to_participated_subnet_with_ip_settings = self.params.get(
            'ext_net_to_participated_subnet_with_ip_settings')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            create_task = self.vdc.create_gateway_api_version_30(
                name=gateway_name,
                external_networks=external_networks,
                gateway_backing_config=gateway_backing_config,
                desc=description,
                is_default_gateway=default_gateway,
                selected_extnw_for_default_gw=extnw_for_default_gw,
                default_gateway_ip=default_gateway_ip,
                is_default_gw_for_dns_relay_selected=default_gw_for_dns_relay,
                is_ha_enabled=ha_enabled,
                should_create_as_advanced=create_as_advanced_gw,
                is_dr_enabled=dr_enabled,
                is_ip_settings_configured=configure_ip_settings,
                ext_net_to_participated_subnet_with_ip_settings=ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled=sub_allocate_ip_pools,
                ext_net_to_subnet_with_ip_range=ext_net_to_subnet_with_ip_range,
                ext_net_to_rate_limit=ext_net_to_rate_limit)

            self.execute_task(create_task.Tasks.Task[0])
            msg = "Edge Gateway {0} has been created"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True
        else:
            msg = "Edge Gateway {0} is already present"
            response['warnings'] = msg.format(gateway_name)

        return response

    def create_gateway_api_version_31(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        description = self.params.get('description')
        external_networks = self.params.get('external_networks')
        gateway_backing_config = self.params.get('gateway_backing_config')
        default_gateway = self.params.get('default_gateway')
        extnw_for_default_gw = self.params.get('extnw_for_default_gw')
        default_gateway_ip = self.params.get('default_gateway_ip')
        default_gw_for_dns_relay = self.params.get('default_gw_for_dns_relay')
        ha_enabled = self.params.get('ha_enabled')
        create_as_advanced_gw = self.params.get('create_as_advanced_gw')
        dr_enabled = self.params.get('dr_enabled')
        configure_ip_settings = self.params.get('configure_ip_settings')
        sub_allocate_ip_pools = self.params.get('sub_allocate_ip_pools')
        ext_net_to_rate_limit = self.params.get('ext_net_to_rate_limit')
        flips_mode = self.params.get('flips_mode')
        ext_net_to_subnet_with_ip_range = self.params.get(
            'ext_net_to_subnet_with_ip_range')
        ext_net_to_participated_subnet_with_ip_settings = self.params.get(
            'ext_net_to_participated_subnet_with_ip_settings')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            create_task = self.vdc.create_gateway_api_version_31(
                name=gateway_name,
                external_networks=external_networks,
                gateway_backing_config=gateway_backing_config,
                desc=description,
                is_default_gateway=default_gateway,
                selected_extnw_for_default_gw=extnw_for_default_gw,
                default_gateway_ip=default_gateway_ip,
                is_default_gw_for_dns_relay_selected=default_gw_for_dns_relay,
                is_ha_enabled=ha_enabled,
                should_create_as_advanced=create_as_advanced_gw,
                is_dr_enabled=dr_enabled,
                is_ip_settings_configured=configure_ip_settings,
                ext_net_to_participated_subnet_with_ip_settings=ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled=sub_allocate_ip_pools,
                ext_net_to_subnet_with_ip_range=ext_net_to_subnet_with_ip_range,
                ext_net_to_rate_limit=ext_net_to_rate_limit,
                is_flips_mode_enabled=flips_mode)

            self.execute_task(create_task.Tasks.Task[0])
            msg = "Edge Gateway {0} has been created"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True
        else:
            msg = "Edge Gateway {0} is already present"
            response['warnings'] = msg.format(gateway_name)

        return response

    def create_gateway_api_version_32(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        description = self.params.get('description')
        external_networks = self.params.get('external_networks')
        gateway_backing_config = self.params.get('gateway_backing_config')
        default_gateway = self.params.get('default_gateway')
        extnw_for_default_gw = self.params.get('extnw_for_default_gw')
        default_gateway_ip = self.params.get('default_gateway_ip')
        default_gw_for_dns_relay = self.params.get('default_gw_for_dns_relay')
        ha_enabled = self.params.get('ha_enabled')
        create_as_advanced_gw = self.params.get('create_as_advanced_gw')
        dr_enabled = self.params.get('dr_enabled')
        configure_ip_settings = self.params.get('configure_ip_settings')
        sub_allocate_ip_pools = self.params.get('sub_allocate_ip_pools')
        ext_net_to_rate_limit = self.params.get('ext_net_to_rate_limit')
        edge_gateway_type = self.params.get('edge_gateway_type')
        flips_mode = self.params.get('flips_mode')
        ext_net_to_subnet_with_ip_range = self.params.get(
            'ext_net_to_subnet_with_ip_range')
        ext_net_to_participated_subnet_with_ip_settings = self.params.get(
            'ext_net_to_participated_subnet_with_ip_settings')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            create_task = self.vdc.create_gateway_api_version_32(
                name=gateway_name,
                external_networks=external_networks,
                gateway_backing_config=gateway_backing_config,
                desc=description,
                is_default_gateway=default_gateway,
                selected_extnw_for_default_gw=extnw_for_default_gw,
                default_gateway_ip=default_gateway_ip,
                is_default_gw_for_dns_relay_selected=default_gw_for_dns_relay,
                is_ha_enabled=ha_enabled,
                should_create_as_advanced=create_as_advanced_gw,
                is_dr_enabled=dr_enabled,
                is_ip_settings_configured=configure_ip_settings,
                ext_net_to_participated_subnet_with_ip_settings=ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled=sub_allocate_ip_pools,
                ext_net_to_subnet_with_ip_range=ext_net_to_subnet_with_ip_range,
                ext_net_to_rate_limit=ext_net_to_rate_limit,
                is_flips_mode_enabled=flips_mode,
                edgeGatewayType=edge_gateway_type)

            self.execute_task(create_task.Tasks.Task[0])
            msg = "Edge Gateway {0} has been created"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True
        else:
            msg = "Edge Gateway {0} is already present"
            response['warnings'] = msg.format(gateway_name)

        return response

    def update_gw(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        new_gateway_name = self.params.get('new_gateway_name')
        description = self.params.get('description')
        ha_enabled = self.params.get('ha_enabled')
        edge_gateway_href = None

        try:
            gateway = self.get_gateway(gateway_name)
            for key, value in gateway.items():
                if key == "href":
                    edge_gateway_href = value
                    break
            gateway = Gateway(
                self.client, name=gateway_name, href=edge_gateway_href)
            update_task = gateway.edit_gateway(newname=new_gateway_name,
                                               desc=description, ha=ha_enabled)
            self.execute_task(update_task)
            msg = "Edge Gateway {0} has been updated with {1}"
            response['msg'] = msg.format(gateway_name, new_gateway_name)
            response['changed'] = True
        except EntityNotFoundException:
            msg = 'Edge Gateway {0} is not present'
            response['warnings'] = msg.format(gateway_name)

        return response

    def delete_gw(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            msg = "Edge Gateway {0} is not present"
            response['warnings'] = msg.format(gateway_name)
        else:
            delete_task = self.vdc.delete_gateway(gateway_name)
            self.execute_task(delete_task)
            msg = "Edge Gateway {0} has been deleted"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True

        return response
示例#4
0
def create_gateway(ctx, name, external_networks_name, description,
                   default_gateway_external_network, default_gw_ip,
                   is_dns_relay, is_ha, is_advanced, is_distributed_routing,
                   configure_ip_settings, sub_allocated_ext_net_name,
                   sub_allocated_subnet, ip_ranges, configure_rate_limits,
                   is_flip_flop, gateway_config, gateway_type):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        api_version = ctx.obj['profiles'].get('api_version')
        vdc = VDC(client, href=vdc_href)
        is_configured_default_gw = False
        if default_gateway_external_network is not None and len(
                default_gateway_external_network) > 0:
            is_configured_default_gw = True
        is_ip_settings_configured = False
        ext_net_to_participated_subnet_with_ip_settings = {}
        if configure_ip_settings is not None and len(configure_ip_settings) \
                > 0:
            is_ip_settings_configured = True
            ext_net_to_participated_subnet_with_ip_settings = tuple_to_dict(
                configure_ip_settings)
        is_sub_allocate_ip_pools_enabled = False
        ext_net_to_subnet_with_ip_range = {}
        if sub_allocated_ext_net_name is not None and len(
                sub_allocated_ext_net_name) > 0 and sub_allocated_subnet is \
                not None and len(sub_allocated_subnet) > 0 and ip_ranges is \
                not None and len(sub_allocated_subnet) > 0:
            is_sub_allocate_ip_pools_enabled = True
            ext_net_to_subnet_with_ip_range = {
                sub_allocated_ext_net_name: {
                    sub_allocated_subnet: list(ip_ranges)
                }
            }
        ext_net_to_rate_limit = {}
        if configure_rate_limits is not None and len(configure_rate_limits) \
                > 0:
            ext_net_to_rate_limit = tuple_to_dict(configure_rate_limits)

        if float(api_version) <= float(ApiVersion.VERSION_30.value):
            result = vdc.create_gateway_api_version_30(
                name, external_networks_name, gateway_config, description,
                is_configured_default_gw, default_gateway_external_network,
                default_gw_ip, is_dns_relay, is_ha, is_advanced,
                is_distributed_routing, is_ip_settings_configured,
                ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled,
                ext_net_to_subnet_with_ip_range, ext_net_to_rate_limit)
        elif float(api_version) <= float(ApiVersion.VERSION_31.value):
            result = vdc.create_gateway_api_version_31(
                name, external_networks_name, gateway_config, description,
                is_configured_default_gw, default_gateway_external_network,
                default_gw_ip, is_dns_relay, is_ha, is_advanced,
                is_distributed_routing, is_ip_settings_configured,
                ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled,
                ext_net_to_subnet_with_ip_range, ext_net_to_rate_limit,
                is_flip_flop)
        else:
            result = vdc.create_gateway_api_version_32(
                name, external_networks_name, gateway_config, description,
                is_configured_default_gw, default_gateway_external_network,
                default_gw_ip, is_dns_relay, is_ha, is_advanced,
                is_distributed_routing, is_ip_settings_configured,
                ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled,
                ext_net_to_subnet_with_ip_range, ext_net_to_rate_limit,
                is_flip_flop, gateway_type)
        stdout(result.Tasks.Task[0], ctx)
    except Exception as e:
        stderr(e, ctx)
class VdcGW(VcdAnsibleModule):
    def __init__(self, **kwargs):
        super(VdcGW, self).__init__(**kwargs)
        self.vdc_name = self.params.get('vdc_name')
        self.org_name = self.params.get('org_name')
        org_resource = self.client.get_org_by_name(self.org_name)
        self.org = Org(self.client, resource=org_resource)
        vdc_resource = self.org.get_vdc(self.vdc_name)
        self.vdc = VDC(self.client, name=self.vdc_name, resource=vdc_resource)

    def manage_states(self):
        state = self.params.get('state')
        if state == "present":
            return self.create_gw()

        if state == "update":
            return self.update_gw()

        if state == "absent":
            return self.delete_gw()

    def manage_operations(self):
        operation = self.params.get('operation')
        if operation == "update_ip_pool":
            return self.update_sub_allocated_ip_pools()

        if operation == "add_network":
            return self.add_network()

        if operation == "remove_network":
            return self.remove_network()

    def get_gateway(self, gateway_name):
        gateway = self.vdc.get_gateway(gateway_name)
        if gateway is not None:
            for key, value in gateway.items():
                if key == "href":
                    return Gateway(self.client, name=gateway_name, href=value)

        msg = "Edge gateway {0} is not present"
        raise EntityNotFoundException(msg.format(gateway_name))

    def create_gw(self):
        api_version = self.client.get_api_version()
        if api_version == "30.0":
            return self.create_gateway_api_version_30()

        if api_version == "31.0":
            return self.create_gateway_api_version_31()

        if api_version == "32.0":
            return self.create_gateway_api_version_32()

    def create_gateway_api_version_30(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        description = self.params.get('description')
        external_networks = self.params.get('external_networks')
        gateway_backing_config = self.params.get('gateway_backing_config')
        default_gateway = self.params.get('default_gateway')
        extnw_for_default_gw = self.params.get('extnw_for_default_gw')
        default_gateway_ip = self.params.get('default_gateway_ip')
        default_gw_for_dns_relay = self.params.get('default_gw_for_dns_relay')
        ha_enabled = self.params.get('ha_enabled')
        create_as_advanced_gw = self.params.get('create_as_advanced_gw')
        dr_enabled = self.params.get('dr_enabled')
        configure_ip_settings = self.params.get('configure_ip_settings')
        sub_allocate_ip_pools = self.params.get('sub_allocate_ip_pools')
        ext_net_to_rate_limit = self.params.get('ext_net_to_rate_limit')
        ext_net_to_subnet_with_ip_range = self.params.get(
            'ext_net_to_subnet_with_ip_range')
        ext_net_to_participated_subnet_with_ip_settings = self.params.get(
            'ext_net_to_participated_subnet_with_ip_settings')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            create_task = self.vdc.create_gateway_api_version_30(
                name=gateway_name,
                external_networks=external_networks,
                gateway_backing_config=gateway_backing_config,
                desc=description,
                is_default_gateway=default_gateway,
                selected_extnw_for_default_gw=extnw_for_default_gw,
                default_gateway_ip=default_gateway_ip,
                is_default_gw_for_dns_relay_selected=default_gw_for_dns_relay,
                is_ha_enabled=ha_enabled,
                should_create_as_advanced=create_as_advanced_gw,
                is_dr_enabled=dr_enabled,
                is_ip_settings_configured=configure_ip_settings,
                ext_net_to_participated_subnet_with_ip_settings=ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled=sub_allocate_ip_pools,
                ext_net_to_subnet_with_ip_range=ext_net_to_subnet_with_ip_range,
                ext_net_to_rate_limit=ext_net_to_rate_limit)

            self.execute_task(create_task.Tasks.Task[0])
            msg = "Edge Gateway {0} has been created"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True
        else:
            msg = "Edge Gateway {0} is already present"
            response['warnings'] = msg.format(gateway_name)

        return response

    def create_gateway_api_version_31(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        description = self.params.get('description')
        external_networks = self.params.get('external_networks')
        gateway_backing_config = self.params.get('gateway_backing_config')
        default_gateway = self.params.get('default_gateway')
        extnw_for_default_gw = self.params.get('extnw_for_default_gw')
        default_gateway_ip = self.params.get('default_gateway_ip')
        default_gw_for_dns_relay = self.params.get('default_gw_for_dns_relay')
        ha_enabled = self.params.get('ha_enabled')
        create_as_advanced_gw = self.params.get('create_as_advanced_gw')
        dr_enabled = self.params.get('dr_enabled')
        configure_ip_settings = self.params.get('configure_ip_settings')
        sub_allocate_ip_pools = self.params.get('sub_allocate_ip_pools')
        ext_net_to_rate_limit = self.params.get('ext_net_to_rate_limit')
        flips_mode = self.params.get('flips_mode')
        ext_net_to_subnet_with_ip_range = self.params.get(
            'ext_net_to_subnet_with_ip_range')
        ext_net_to_participated_subnet_with_ip_settings = self.params.get(
            'ext_net_to_participated_subnet_with_ip_settings')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            create_task = self.vdc.create_gateway_api_version_31(
                name=gateway_name,
                external_networks=external_networks,
                gateway_backing_config=gateway_backing_config,
                desc=description,
                is_default_gateway=default_gateway,
                selected_extnw_for_default_gw=extnw_for_default_gw,
                default_gateway_ip=default_gateway_ip,
                is_default_gw_for_dns_relay_selected=default_gw_for_dns_relay,
                is_ha_enabled=ha_enabled,
                should_create_as_advanced=create_as_advanced_gw,
                is_dr_enabled=dr_enabled,
                is_ip_settings_configured=configure_ip_settings,
                ext_net_to_participated_subnet_with_ip_settings=ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled=sub_allocate_ip_pools,
                ext_net_to_subnet_with_ip_range=ext_net_to_subnet_with_ip_range,
                ext_net_to_rate_limit=ext_net_to_rate_limit,
                is_flips_mode_enabled=flips_mode)

            self.execute_task(create_task.Tasks.Task[0])
            msg = "Edge Gateway {0} has been created"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True
        else:
            msg = "Edge Gateway {0} is already present"
            response['warnings'] = msg.format(gateway_name)

        return response

    def create_gateway_api_version_32(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        description = self.params.get('description')
        external_networks = self.params.get('external_networks')
        gateway_backing_config = self.params.get('gateway_backing_config')
        default_gateway = self.params.get('default_gateway')
        extnw_for_default_gw = self.params.get('extnw_for_default_gw')
        default_gateway_ip = self.params.get('default_gateway_ip')
        default_gw_for_dns_relay = self.params.get('default_gw_for_dns_relay')
        ha_enabled = self.params.get('ha_enabled')
        create_as_advanced_gw = self.params.get('create_as_advanced_gw')
        dr_enabled = self.params.get('dr_enabled')
        configure_ip_settings = self.params.get('configure_ip_settings')
        sub_allocate_ip_pools = self.params.get('sub_allocate_ip_pools')
        ext_net_to_rate_limit = self.params.get('ext_net_to_rate_limit')
        edge_gateway_type = self.params.get('edge_gateway_type')
        flips_mode = self.params.get('flips_mode')
        ext_net_to_subnet_with_ip_range = self.params.get(
            'ext_net_to_subnet_with_ip_range')
        ext_net_to_participated_subnet_with_ip_settings = self.params.get(
            'ext_net_to_participated_subnet_with_ip_settings')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException:
            create_task = self.vdc.create_gateway_api_version_32(
                name=gateway_name,
                external_networks=external_networks,
                gateway_backing_config=gateway_backing_config,
                desc=description,
                is_default_gateway=default_gateway,
                selected_extnw_for_default_gw=extnw_for_default_gw,
                default_gateway_ip=default_gateway_ip,
                is_default_gw_for_dns_relay_selected=default_gw_for_dns_relay,
                is_ha_enabled=ha_enabled,
                should_create_as_advanced=create_as_advanced_gw,
                is_dr_enabled=dr_enabled,
                is_ip_settings_configured=configure_ip_settings,
                ext_net_to_participated_subnet_with_ip_settings=ext_net_to_participated_subnet_with_ip_settings,
                is_sub_allocate_ip_pools_enabled=sub_allocate_ip_pools,
                ext_net_to_subnet_with_ip_range=ext_net_to_subnet_with_ip_range,
                ext_net_to_rate_limit=ext_net_to_rate_limit,
                is_flips_mode_enabled=flips_mode,
                edgeGatewayType=edge_gateway_type)

            self.execute_task(create_task.Tasks.Task[0])
            msg = "Edge Gateway {0} has been created"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True
        else:
            msg = "Edge Gateway {0} is already present"
            response['warnings'] = msg.format(gateway_name)

        return response

    def update_gw(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')
        new_gateway_name = self.params.get('new_gateway_name')
        description = self.params.get('description')
        ha_enabled = self.params.get('ha_enabled')

        try:
            gateway = self.get_gateway(gateway_name)
        except EntityNotFoundException as ex:
            response['warnings'] = ex
        else:
            update_task = gateway.edit_gateway(
                newname=new_gateway_name, desc=description, ha=ha_enabled)
            self.execute_task(update_task)
            msg = "Edge Gateway {0} has been updated with {1}"
            response['msg'] = msg.format(gateway_name, new_gateway_name)
            response['changed'] = True

        return response

    def delete_gw(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')

        try:
            self.get_gateway(gateway_name)
        except EntityNotFoundException as ex:
            response['warnings'] = ex
        else:
            delete_task = self.vdc.delete_gateway(gateway_name)
            self.execute_task(delete_task)
            msg = "Edge Gateway {0} has been deleted"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True

        return response

    def _get_subnet_participation(self, gw_resource, network):
        for gateway_inf in \
                gw_resource.Configuration.GatewayInterfaces.GatewayInterface:
            if gateway_inf.Name == network:
                return gateway_inf.SubnetParticipation

        return None

    def update_sub_allocated_ip_pools(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')

        try:
            gateway = self.get_gateway(gateway_name)
        except EntityNotFoundException as ex:
            response['warnings'] = ex
        else:
            ip_pool = self.params.get('ext_net_subnet_allocated_ip_pool')
            for network, new_ip_range in ip_pool.items():
                subnet_participation = self._get_subnet_participation(gateway.get_resource(), network)
                if subnet_participation is None:
                    msg = "No subnet ip pools are attached with network {0}"
                    raise Exception(msg.format(network))

                ip_ranges = gateway.get_sub_allocate_ip_ranges_element(subnet_participation)
                old_ip_range = "{0}-{1}".format(ip_ranges.IpRange.StartAddress, ip_ranges.IpRange.EndAddress)
                update_task = gateway.edit_sub_allocated_ip_pools(network, old_ip_range, new_ip_range)
                self.execute_task(update_task)
            msg = "Ip Pools have been updated on edge gatway {0}"
            response['msg'] = msg.format(gateway_name)
            response['changed'] = True

        return response

    def add_network(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')

        try:
            gateway = self.get_gateway(gateway_name)
        except EntityNotFoundException as ex:
            response['warnings'] = ex
        else:
            network_settings = self.params.get('ext_net_to_participated_subnet_with_ip_settings')
            networks_to_attach = network_settings.keys()
            attached_networks = gateway.list_external_network_ip_allocations().keys()
            networks = list()
            for network in networks_to_attach:
                if network not in attached_networks:
                    networks.append(network)
                    for ip_settings in network_settings.values():
                        for subnet, ip in ip_settings.items():
                            add_network_task = gateway.add_external_network(network, [(subnet, ip)])
                            self.execute_task(add_network_task)
            if len(networks) == 0:
                networks = list(networks_to_attach)
                msg = "Networks {0} are already attached to edge gatway {1}"
            else:
                msg = "Networks {0} are added to edge gatway {1}"
            response['msg'] = msg.format(networks, gateway_name)
            response['changed'] = True

        return response

    def remove_network(self):
        response = dict()
        response['changed'] = False
        gateway_name = self.params.get('gateway_name')

        try:
            gateway = self.get_gateway(gateway_name)
        except EntityNotFoundException as ex:
            response['warnings'] = ex
        else:
            external_networks = self.params.get('external_networks')
            for network in external_networks:
                remove_network_task = gateway.remove_external_network(network)
                self.execute_task(remove_network_task)
            msg = "Networks {0} have been removed from edge gatway {1}"
            response['msg'] = msg.format(external_networks, gateway_name)
            response['changed'] = True

        return response