Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module: azure_rm_expressroute #484

Merged
merged 43 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6c2d48f
first commit
Apr 1, 2021
01df7ac
fix file
Apr 1, 2021
460c6af
new changes
Apr 5, 2021
3d813ad
working create/update/delete/get
Apr 8, 2021
09c7279
change username
pravin94ghuge Apr 8, 2021
3b215da
minor changes
Apr 9, 2021
77441cd
Fix sanity issues
ikarldasan Apr 9, 2021
5be124f
Improve integration test
ikarldasan Apr 9, 2021
e83de54
remove return
Apr 9, 2021
2e0da02
remove return
Apr 9, 2021
adafb4d
Merge branch 'dev' into expressroute
praveenghuge Apr 12, 2021
d91c29d
Merge branch 'dev' into expressroute
praveenghuge Apr 15, 2021
7f6dc23
Merge branch 'dev' into expressroute
praveenghuge Apr 19, 2021
20e0182
address changes
pravin94ghuge Apr 19, 2021
f0aa8a9
changes addressed
pravin94ghuge Apr 19, 2021
c1124d9
address changes
pravin94ghuge Apr 20, 2021
03c9308
address changes
pravin94ghuge Apr 20, 2021
e5d7bc9
small change
pravin94ghuge Apr 20, 2021
2eee2d7
Merge branch 'dev' into expressroute
praveenghuge Apr 22, 2021
98558eb
Merge branch 'dev' into expressroute
praveenghuge Apr 23, 2021
bc251bd
Merge branch 'dev' into expressroute
praveenghuge Apr 28, 2021
c3e6d59
fixing update account_enabled bug in azure_rm_aduser.py (#524)
haiyuazhang May 7, 2021
6fdfefe
fixing ad related auth issue when using service pricinpal. (#525)
haiyuazhang May 7, 2021
24b08f7
change class name of azure_rm_aduser (#526)
haiyuazhang May 8, 2021
999aeda
Merge branch 'dev' into expressroute
praveenghuge May 11, 2021
76939cc
Merge branch 'dev' into expressroute
praveenghuge May 13, 2021
51e77c8
address cahnges
pravin94ghuge May 13, 2021
d6ced25
Merge branch 'dev' into expressroute
praveenghuge May 17, 2021
ca170e5
Merge branch 'dev' into expressroute
praveenghuge May 20, 2021
1d0e2d9
Merge branch 'dev' into expressroute
praveenghuge May 21, 2021
81725ed
new changes
pravin94ghuge May 24, 2021
aca57cd
new changes
pravin94ghuge May 24, 2021
98fe38e
addrss changes
pravin94ghuge May 25, 2021
4cd27ef
address changes
pravin94ghuge May 25, 2021
1401a72
address changes
pravin94ghuge May 25, 2021
83b1a31
address changes
May 28, 2021
b92ba9b
merge upstream changes
May 28, 2021
70e4da8
merge upstream changes
May 29, 2021
1c64fef
address changes
May 29, 2021
554383b
Merge branch 'dev' into expressroute
praveenghuge Jun 7, 2021
1692e20
update version
pravin94ghuge Jun 10, 2021
1342dc8
Merge branch 'dev' into expressroute
praveenghuge Jun 10, 2021
c2cd4c2
Merge branch 'dev' into expressroute
praveenghuge Jun 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 361 additions & 0 deletions plugins/modules/azure_rm_expressroute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,361 @@
#!/usr/bin/python
#
# Copyright (c) 2021 Praveen Ghuge (@praveenghuge), Karl Dasan (@ikarldasan), Sakar Mehra (@sakar97)
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: azure_rm_expressroute
version_added: "0.1.2"
short_description: Manage Express Route Circuits
description:
- Create, update and delete instance of Express Route.
options:
resource_group:
description:
- Name of the resource group to which the resource belongs.
required: true
type: str
name:
description:
- Unique name of the app service plan to create or update.
required: true
type: str
location:
description:
- Resource location. If not set, location from the resource group will be used as default.
type: str
service_provider_properties:
type: dict
description:
- The service Provider properties
suboptions:
peering_location:
description:
- The peering location
type: str
bandwidth_in_mbps:
description:
- The bandwidth of the circuit when the circuit is provisioned on an ExpressRoutePort resource.
type: str
service_provider_name:
description:
- Name of service provider
type: str
sku:
description:
- The name of the SKU.
- Please see (https://azure.microsoft.com/en-in/pricing/details/expressroute/)
suboptions:
tier:
description:
- The tier of the SKU
required: true
default: Standard
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument 'tier' in argument_spec found in sku defines default as (None) but documentation defines default as ('Standard')

Suggested change
default: Standard

choices:
- Standard
- Premium
family:
description:
- the family of the SKU
required: true
choices:
- MeteredData
- UnlimitedData
global_reach_enabled:
description: Flag denoting global reach status.
default: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument 'global_reach_enabled' in argument_spec defines default as (None) but documentation defines default as (True)

Suggested change
default: true

type: bool
authorizations:
description:
- The list of authorizations.
suboptions:
name:
description: Name of the authorization.
required: true
type: str
type: list
allow_classic_operations:
description: Support for classic operations.
type: bool
state:
description:
- Assert the state of the express route.
- Use C(present) to create or update an express route and C(absent) to delete it.
type: str
default: present
choices:
- absent
- present
extends_documentation_fragment:
- azure.azcollection.azure

author:
- Praveen Ghuge (@praveenghuge)
- Karl Dasan (@ikarldasan)
- Sakar Mehra (@sakar97)
'''
EXAMPLES = '''
- name: "Create Express route"
azure_rm_expressroute:
resource_group: rg
location: eastus
name: exp
allow_classic_operations: true
global_reach_enabled: false
tags:
- a: b
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- a: b
- a: b
Suggested change
- a: b
a: b

authorizations:
- name: authorization_test
service_provider_properties:
service_provider_name: Aryaka Networks
peering_location: Seattle
bandwidth_in_mbps: '200'
sku:
tier: premium
family: metereddata

- name: Delete Express route
azure_rm_expressroute:
resource_group: rg
name: exp
state: absent

'''

RETURN = '''
sample: {
"additional_properties": {},
"allow_classic_operations": true,
"authorizations": [
{
"authorization_key": "d83e18b5-0200-4e0b-9cdb-6fdf95b00267",
"authorization_use_status": "Available",
"etag": "W/'09572845-c667-410c-b664-ed8e39242c13'",
"id": "/subscriptions/subs_id/resourceGroups/rg/providers/Microsoft.Network/expressRouteCircuits/exp/authorizations/az",
"name": "authorization_test",
"provisioning_state": "Succeeded",
"type": "Microsoft.Network/expressRouteCircuits/authorizations"
}
],
"bandwidth_in_gbps": null,
"circuit_provisioning_state": "Enabled",
"express_route_port": null,
"gateway_manager_etag": "",
"global_reach_enabled": false,
"id": "/subscriptions/subs_id/resourceGroups/rg/providers/Microsoft.Network/expressRouteCircuits/exp",
"location": "eastus",
"name": "exp",
"peerings": [],
"provisioning_state": "Succeeded",
"service_key": "e1956383-63b6-4709-8baa-3615bbf5d22b",
"service_provider_notes": null,
"service_provider_provisioning_state": "NotProvisioned",
"stag": 27,
"status": "Deleted",
"tags": {
"a": "b"
},
"type": "Microsoft.Network/expressRouteCircuits"
}

'''

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from azure.mgmt.network import NetworkManagementClient
except ImportError:
# This is handled in azure_rm_common
pass


class AzureExpressRoute(AzureRMModuleBase):

def __init__(self):
# define user inputs from playbook

self.service_provider_properties_spec = dict(
service_provider_name=dict(type='str'),
peering_location=dict(type='str'),
bandwidth_in_mbps=dict(type='str')
)

self.sku_spec = dict(
tier=dict(type='str', choices=[
'standard', 'premium'], required=True),
family=dict(type='str', choices=[
'unlimiteddata', 'metereddata'], required=True)
)

self.authorizations_spec = dict(
name=dict(type='str', required=True)
)

self.module_arg_spec = dict(
resource_group=dict(type='str', required=True),
name=dict(type='str', required=True),
location=dict(type='str'),
sku=dict(type='dict', options=self.sku_spec),
allow_classic_operations=dict(type='bool'),
authorizations=dict(type='list', options=self.authorizations_spec, elements='dict'),
state=dict(choices=['present', 'absent'],
default='present', type='str'),
service_provider_properties=dict(
type='dict', options=self.service_provider_properties_spec),
global_reach_enabled=dict(type='bool')
)

self.resource_group = None
self.name = None
self.location = None
self.allow_classic_operations = None
self.authorizations = None
self.service_provider_properties = None
self. global_reach_enabled = None
self.sku = None
self.tags = None
self.state = None
self.results = dict(
changed=False,
state=dict()
)

super(AzureExpressRoute, self).__init__(self.module_arg_spec,
supports_check_mode=True,
supports_tags=True)

def exec_module(self, **kwargs):

for key in list(self.module_arg_spec.keys()) + ['tags']:
setattr(self, key, kwargs[key])

self.results['check_mode'] = self.check_mode

# retrieve resource group to make sure it exists
self.get_resource_group(self.resource_group)

results = dict()
changed = False

try:
self.log('Fetching Express Route Circuits {0}'.format(self.name))
express_route_circuit = self.network_client.express_route_circuits.get(
self.resource_group, self.name)

results = express_route_to_dict(express_route_circuit)

# don't change anything if creating an existing zone, but change if deleting it
if self.state == 'present':
changed = False

update_tags, results['tags'] = self.update_tags(
results['tags'])
if update_tags:
changed = True

elif self.state == 'absent':
changed = True

except CloudError:
# the express route does not exist so create it
if self.state == 'present':
changed = True
else:
# you can't delete what is not there
changed = False

self.results['changed'] = changed
self.results['state'] = results

# return the results if your only gathering information
if self.check_mode:
return self.results

if changed:
if self.state == "present":
self.results['state'] = self.create_or_update_express_route(
self.module.params)
elif self.state == "absent":
# delete express route
self.delete_expressroute()
self.results['state']['status'] = 'Deleted'

return self.results

def create_or_update_express_route(self, params):
'''
Create or update Express route.
:return: create or update Express route instance state dictionary
'''
self.log("create or update Express Route {0}".format(self.name))
try:
params["sku"]["name"] = params.get("sku").get("tier") + "_" + params.get("sku").get("family")
poller = self.network_client.express_route_circuits.create_or_update(
resource_group_name=params.get("resource_group"),
circuit_name=params.get("name"),
parameters=params)
result = self.get_poller_result(poller)
self.log("Response : {0}".format(result))
except CloudError as ex:
self.fail("Failed to create express route {0} in resource group {1}: {2}".format(
self.name, self.resource_group, str(ex)))
return express_route_to_dict(result)

def delete_expressroute(self):
'''
Deletes specified express route circuit
:return True
'''
self.log("Deleting the express route {0}".format(self.name))
try:
poller = self.network_client.express_route_circuits.delete(
self.resource_group, self.name)
result = self.get_poller_result(poller)
except CloudError as e:
self.log('Error attempting to delete express route.')
self.fail(
"Error deleting the express route : {0}".format(str(e)))
return result


def express_route_to_dict(item):
# turn express route object into a dictionary (serialization)
express_route = item.as_dict()
result = dict(
additional_properties=express_route.get('additional_properties', {}),
id=express_route.get('id', None),
name=express_route.get('name', None),
type=express_route.get('type', None),
location=express_route.get('location', '').replace(' ', '').lower(),
tags=express_route.get('tags', None),
allow_classic_operations=express_route.get(
'allow_classic_operations', None),
circuit_provisioning_state=express_route.get(
'circuit_provisioning_state', None),
service_provider_provisioning_state=express_route.get(
'service_provider_provisioning_state', None),
authorizations=express_route.get('authorizations', []),
peerings=express_route.get('peerings', []),
service_key=express_route.get('service_key', None),
service_provider_notes=express_route.get(
'service_provider_notes', None),
express_route_port=express_route.get('express_route_port', None),
bandwidth_in_gbps=express_route.get('bandwidth_in_gbps', None),
stag=express_route.get('stag', None),
provisioning_state=express_route.get('provisioning_state', None),
gateway_manager_etag=express_route.get('gateway_manager_etag', ''),
global_reach_enabled=express_route.get('global_reach_enabled', '')
)
return result


def main():
AzureExpressRoute()


if __name__ == '__main__':
main()
Loading