in src/ansible_collections/alibaba/apsarastack/plugins/modules/ali_route_entry.py [0:0]
def main():
argument_spec = common_argument_spec()
argument_spec.update(dict(
state=dict(default='present', choices=['present', 'absent']),
destination_cidrblock=dict(type='str', aliases=['dest_cidrblock', 'cidr_block']),
nexthop_type=dict(default='Instance', aliases=['hop_type'], choices=['Instance', 'Tunnel', 'HaVip', 'RouterInterface', 'VpnGateway']),
nexthop_id=dict(aliases=['hop_id']),
route_table_id=dict(type='str', required=True),
router_id=dict(aliases=['route_entry_id']),
name=dict(aliases=['route_entry_name']),
))
module = AnsibleModule(argument_spec=argument_spec)
if HAS_FOOTMARK is False:
module.fail_json(msg='footmark required for the module ali_route_entry.')
# Get values of variable
state = module.params['state']
name = module.params['name']
route_entry = None
if str(name).startswith('http://') or str(name).startswith('https://'):
module.fail_json(msg='router_entry_name can not start with http:// or https://')
changed = False
if state == 'present':
try:
route_entry = create_route_entry(module)
module.exit_json(changed=False, route_entry=route_entry)
except VPCResponseError as e:
module.fail_json(msg='failed to create route entry {0}, error: {1}'.format(route_entry["route_entry_id"], e))
else:
if route_entry:
try:
if do_delete_route_entry(module, route_entry):
module.exit_json(changed=False, route_entry={})
except VPCResponseError as e:
module.fail_json(msg='failed to delete route entry, error: {0}'.format(e))
module.exit_json(changed=changed, msg="Please specify a route entry by using 'destination_cidrblock', and "
"expected ""vpcs: {0}".format({"route_table_id": route_entry["route_table_id"],
"destination_cidrblock": route_entry["destination_cidrblock"]}))
return