コード例 #1
0
def main():
    # Define Ansible module argument spec
    module_args = {
        "vmanage_ip": {"required": True, "type": "str"},
        "username": {"required": True, "type": "str"},
        "password": {"required": True, "type": "str", "no_log": True},
        "name": {"required": True, "type": "str"},
        "activate": {"default": True, "type": "bool"},
    }

    # Instantiate Ansible module object
    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    # Load all the Ansible parameters into local variables\
    vmanage_ip = module.params['vmanage_ip']
    username = module.params['username']
    password = module.params['password']
    name = module.params['name']
    activate = module.params['activate']


    # Instantiate vmanage requests session
    obj = rest_api_lib(vmanage_ip, username, password)

    # Create requests playload for Post and Put methods
    payload = {}

    policyId, current_topologyId, isactivated = obj.get_vsmart_policyId_by_name(name)

    # If the Policy  does not exist, create it via post
    if not policyId:
        module.fail_json(msg="Policy Does Not Exist")

    if activate:
        response = obj.post_request('template/policy/vsmart/activate/' + policyId, payload=payload)
        module.exit_json(changed=True, msg="Updating Vsmart Policy")
コード例 #2
0
def main():
    # Define Ansible module argument spec
    module_args = {
        "vmanage_ip": {
            "required": True,
            "type": "str"
        },
        "username": {
            "required": True,
            "type": "str"
        },
        "password": {
            "required": True,
            "type": "str",
            "no_log": True
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "sites": {
            "required": True,
            "type": "list"
        },
        "state": {
            "default": "present",
            "choices": ['present', 'absent'],
            "type": 'str'
        }
    }

    # Instantiate Ansible module object
    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    # Load all the Ansible parameters into local variables\
    vmanage_ip = module.params['vmanage_ip']
    username = module.params['username']
    password = module.params['password']
    name = module.params['name']
    description = module.params['description']
    entries = []
    for site in module.params['sites']:
        entries.append({"siteId": str(site)})
    # Create requests playload for Post and Put methods
    payload = {"name": name, "description": description, "entries": entries}

    # Instantiate vmanage requests session
    obj = rest_api_lib(vmanage_ip, username, password)
    # Check if VPN list already exists and get VPN list entries
    listId, current_entries = obj.get_site_list_by_name(module.params['name'])

    # If the site list does not exist, create it via post
    if not listId:
        if module.check_mode:
            module.exit_json(changed=True)
        response = obj.post_request('template/policy/list/site',
                                    payload=payload)
        if response.status_code == 200:
            listId = response.json()['listId']
            module.exit_json(changed=True, listId=listId)
        else:
            module.fail_json(msg="Error", listId=listId)
    # If the VPN list does exist, compare the VPN entries, and if necessary, update via post
    if listId:
        if current_entries == entries:
            module.exit_json(changed=False,
                             msg="No changes needed",
                             listId=listId)
        else:
            if module.check_mode:
                module.exit_json(changed=True)
            obj.put_request('template/policy/list/site/' + listId,
                            payload=payload)
            module.exit_json(changed=True, msg="Updating list", listId=listId)
コード例 #3
0
def main():
    # Define Ansible module argument spec
    module_args = {
        "vmanage_ip": {
            "required": True,
            "type": "str"
        },
        "username": {
            "required": True,
            "type": "str"
        },
        "password": {
            "required": True,
            "type": "str",
            "no_log": True
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "vpn_list": {
            "required": True,
            "type": "str"
        },
        "hub_site_list": {
            "required": True,
            "type": "str"
        },
        "spoke_site_list": {
            "required": True,
            "type": "str"
        },
        "state": {
            "default": "present",
            "choices": ['present', 'absent'],
            "type": 'str'
        }
    }

    # Instantiate Ansible module object
    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    # Load all the Ansible parameters into local variables\
    vmanage_ip = module.params['vmanage_ip']
    username = module.params['username']
    password = module.params['password']
    name = module.params['name']
    description = module.params['description']
    vpn_list_name = module.params['vpn_list']
    hub_site_list_name = module.params['hub_site_list']
    spoke_site_list_name = module.params['spoke_site_list']

    # Instantiate vmanage requests session
    obj = rest_api_lib(vmanage_ip, username, password)
    # Check if VPN list already exists and get VPN list entries
    vpn_listId, vpn_entries = obj.get_vpn_list_by_name(vpn_list_name)
    hub_listId, hub_entries = obj.get_site_list_by_name(hub_site_list_name)
    spoke_listId, spoke_entries = obj.get_site_list_by_name(
        spoke_site_list_name)

    # Create requests playload for Post and Put methods
    payload = {
        "name": name,
        "type": "hubAndSpoke",
        "description": description,
        "definition": {
            "vpnList":
            vpn_listId,
            "subDefinitions": [{
                "name":
                "My Hub and Spoke",
                # "equalPreference": "true",
                # "advertiseTloc": "false",
                "spokes": [{
                    "siteList":
                    spoke_listId,
                    "hubs": [{
                        "siteList": hub_listId
                        # "prefixLists": []
                    }]
                }]
            }]
        }
    }
    definitionId = obj.get_topology_by_name(name)

    if not definitionId:
        if module.check_mode:
            module.exit_json(changed=True)
        response = obj.post_request('template/policy/definition/hubandspoke',
                                    payload=payload)
        if response.status_code == 200:
            module.exit_json(changed=True)
        else:
            module.fail_json(msg="Error",
                             definitionId=definitionId,
                             payload=payload)

    current_vpnId, current_spokeId, current_hubId = obj.get_topology_details(
        definitionId)
    if current_vpnId == vpn_listId and current_spokeId == spoke_listId and current_hubId == hub_listId:
        module.exit_json(changed=False, msg="No changes needed")
    else:
        if module.check_mode:
            module.exit_json(changed=True)
        obj.put_request('template/policy/definition/hubandspoke/' +
                        definitionId,
                        payload=payload)
        module.exit_json(changed=True,
                         msg="Updating Topology",
                         definitionId=definitionId)
コード例 #4
0
def main():
    # Define Ansible module argument spec
    module_args = {
        "vmanage_ip": {"required": True, "type": "str"},
        "username": {"required": True, "type": "str"},
        "password": {"required": True, "type": "str", "no_log": True},
        "name": {"required": True, "type": "str"},
        "description": {"required": False, "type": "str"},
        "topology_name": {"required": True, "type": "str"},
        "state": {
            "default": "present",
            "choices": ['present', 'absent'],
            "type": 'str'
        }
    }

    # Instantiate Ansible module object
    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    # Load all the Ansible parameters into local variables\
    vmanage_ip = module.params['vmanage_ip']
    username = module.params['username']
    password = module.params['password']
    name = module.params['name']
    description = module.params['description']
    topology_name = module.params['topology_name']


    # Instantiate vmanage requests session
    obj = rest_api_lib(vmanage_ip, username, password)
    # Check if VPN list already exists and get VPN list entries
    topologyId = obj.get_topology_by_name(topology_name)

    # Create requests playload for Post and Put methods
    payload = {
        "policyName": name,
        "policyDescription": description,
        "policyType": "feature",
        "policyDefinition": {
            "assembly": [
                {
                    "definitionId": topologyId,
                    "type": "hubAndSpoke"
                }
            ]
        }
    }

    policyId, current_topologyId, isactivated = obj.get_vsmart_policyId_by_name(name)

    # If the Policy  does not exist, create it via post
    if not policyId:
        if module.check_mode:
            module.exit_json(changed=True)
        response = obj.post_request('template/policy/vsmart', payload=payload)
        if response.status_code == 200:
            module.exit_json(changed=True)
        else:
            module.fail_json(msg="Error", payload=payload)
    # If the VPN list does exist, compare the VPN entries, and if necessary, update via post      
    if policyId:
        if current_topologyId == topologyId:
            module.exit_json(changed=False, msg="No changes needed")
        else:
            if module.check_mode:
                module.exit_json(changed=True)
            response = obj.put_request('template/policy/vsmart/' + policyId, payload=payload)
            module.exit_json(changed=True, msg="Updating Vsmart Policy")