cs_vpn_connection: fix wrong connection used (#34937)
* cs_vpn_connection: fix wrong connection used * fix vpn_customer_gateway is required * fix tests as we have a new required param * code styling
This commit is contained in:
parent
6351eff74e
commit
3b7136c5ab
2 changed files with 25 additions and 17 deletions
|
@ -27,20 +27,20 @@ options:
|
||||||
required: true
|
required: true
|
||||||
vpn_customer_gateway:
|
vpn_customer_gateway:
|
||||||
description:
|
description:
|
||||||
- Name of the VPN connection.
|
- Name of the VPN customer gateway.
|
||||||
- Required when C(state=present).
|
required: true
|
||||||
passive:
|
passive:
|
||||||
description:
|
description:
|
||||||
- State of the VPN connection.
|
- State of the VPN connection.
|
||||||
- Only considered when C(state=present).
|
- Only considered when C(state=present).
|
||||||
default: no
|
default: no
|
||||||
choices: [ yes, no ]
|
type: bool
|
||||||
force:
|
force:
|
||||||
description:
|
description:
|
||||||
- Activate the VPN gateway if not already activated on C(state=present).
|
- Activate the VPN gateway if not already activated on C(state=present).
|
||||||
- Also see M(cs_vpn_gateway).
|
- Also see M(cs_vpn_gateway).
|
||||||
default: no
|
default: no
|
||||||
choices: [ yes, no ]
|
type: bool
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the VPN connection.
|
- State of the VPN connection.
|
||||||
|
@ -58,7 +58,8 @@ options:
|
||||||
poll_async:
|
poll_async:
|
||||||
description:
|
description:
|
||||||
- Poll async jobs until job has finished.
|
- Poll async jobs until job has finished.
|
||||||
default: true
|
default: yes
|
||||||
|
type: bool
|
||||||
extends_documentation_fragment: cloudstack
|
extends_documentation_fragment: cloudstack
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ EXAMPLES = r'''
|
||||||
- name: Remove a vpn connection
|
- name: Remove a vpn connection
|
||||||
local_action:
|
local_action:
|
||||||
module: cs_vpn_connection
|
module: cs_vpn_connection
|
||||||
|
vpn_customer_gateway: my vpn connection
|
||||||
vpc: my vpc
|
vpc: my vpc
|
||||||
state: absent
|
state: absent
|
||||||
'''
|
'''
|
||||||
|
@ -197,10 +199,8 @@ class AnsibleCloudStackVpnConnection(AnsibleCloudStack):
|
||||||
}
|
}
|
||||||
self.vpn_customer_gateway = None
|
self.vpn_customer_gateway = None
|
||||||
|
|
||||||
def get_vpn_customer_gateway(self, key=None):
|
def get_vpn_customer_gateway(self, key=None, identifier=None, refresh=False):
|
||||||
vpn_customer_gateway = self.module.params.get('vpn_customer_gateway')
|
if not refresh and self.vpn_customer_gateway:
|
||||||
|
|
||||||
if self.vpn_customer_gateway:
|
|
||||||
return self._get_by_key(key, self.vpn_customer_gateway)
|
return self._get_by_key(key, self.vpn_customer_gateway)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
|
@ -209,6 +209,7 @@ class AnsibleCloudStackVpnConnection(AnsibleCloudStack):
|
||||||
'projectid': self.get_project(key='id')
|
'projectid': self.get_project(key='id')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vpn_customer_gateway = identifier or self.module.params.get('vpn_customer_gateway')
|
||||||
vcgws = self.query_api('listVpnCustomerGateways', **args)
|
vcgws = self.query_api('listVpnCustomerGateways', **args)
|
||||||
if vcgws:
|
if vcgws:
|
||||||
for vcgw in vcgws['vpncustomergateway']:
|
for vcgw in vcgws['vpncustomergateway']:
|
||||||
|
@ -247,7 +248,9 @@ class AnsibleCloudStackVpnConnection(AnsibleCloudStack):
|
||||||
|
|
||||||
vpn_conns = self.query_api('listVpnConnections', **args)
|
vpn_conns = self.query_api('listVpnConnections', **args)
|
||||||
if vpn_conns:
|
if vpn_conns:
|
||||||
return vpn_conns['vpnconnection'][0]
|
for vpn_conn in vpn_conns['vpnconnection']:
|
||||||
|
if self.get_vpn_customer_gateway(key='id') == vpn_conn['s2scustomergatewayid']:
|
||||||
|
return vpn_conn
|
||||||
|
|
||||||
def present_vpn_connection(self):
|
def present_vpn_connection(self):
|
||||||
vpn_conn = self.get_vpn_connection()
|
vpn_conn = self.get_vpn_connection()
|
||||||
|
@ -294,16 +297,19 @@ class AnsibleCloudStackVpnConnection(AnsibleCloudStack):
|
||||||
self.result['cidrs'] = vpn_conn['cidrlist'].split(',') or [vpn_conn['cidrlist']]
|
self.result['cidrs'] = vpn_conn['cidrlist'].split(',') or [vpn_conn['cidrlist']]
|
||||||
# Ensure we return a bool
|
# Ensure we return a bool
|
||||||
self.result['force_encap'] = True if vpn_conn['forceencap'] else False
|
self.result['force_encap'] = True if vpn_conn['forceencap'] else False
|
||||||
|
args = {
|
||||||
self.module.params['vpn_customer_gateway'] = vpn_conn['s2scustomergatewayid']
|
'key': 'name',
|
||||||
self.result['vpn_customer_gateway'] = self.get_vpn_customer_gateway(key='name')
|
'identifier': vpn_conn['s2scustomergatewayid'],
|
||||||
|
'refresh': True,
|
||||||
|
}
|
||||||
|
self.result['vpn_customer_gateway'] = self.get_vpn_customer_gateway(**args)
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = cs_argument_spec()
|
argument_spec = cs_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
vpn_customer_gateway=dict(),
|
vpn_customer_gateway=dict(required=True),
|
||||||
vpc=dict(required=True),
|
vpc=dict(required=True),
|
||||||
domain=dict(),
|
domain=dict(),
|
||||||
account=dict(),
|
account=dict(),
|
||||||
|
@ -318,9 +324,6 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
required_together=cs_required_together(),
|
required_together=cs_required_together(),
|
||||||
required_if=[
|
|
||||||
('state', 'present', ['vpn_customer_gateway']),
|
|
||||||
],
|
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
- name: setup remove vpn connection
|
- name: setup remove vpn connection
|
||||||
cs_vpn_connection:
|
cs_vpn_connection:
|
||||||
|
vpn_customer_gateway: my_vpn_customer_gateway
|
||||||
vpc: my_vpc
|
vpc: my_vpc
|
||||||
zone: "{{ cs_common_zone_adv }}"
|
zone: "{{ cs_common_zone_adv }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -104,6 +105,7 @@
|
||||||
|
|
||||||
- name: test remove vpn connection in check mode
|
- name: test remove vpn connection in check mode
|
||||||
cs_vpn_connection:
|
cs_vpn_connection:
|
||||||
|
vpn_customer_gateway: my_vpn_customer_gateway
|
||||||
vpc: my_vpc
|
vpc: my_vpc
|
||||||
zone: "{{ cs_common_zone_adv }}"
|
zone: "{{ cs_common_zone_adv }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -118,6 +120,7 @@
|
||||||
|
|
||||||
- name: test remove vpn connection
|
- name: test remove vpn connection
|
||||||
cs_vpn_connection:
|
cs_vpn_connection:
|
||||||
|
vpn_customer_gateway: my_vpn_customer_gateway
|
||||||
vpc: my_vpc
|
vpc: my_vpc
|
||||||
zone: "{{ cs_common_zone_adv }}"
|
zone: "{{ cs_common_zone_adv }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -131,6 +134,7 @@
|
||||||
|
|
||||||
- name: test remove vpn connection idempotence
|
- name: test remove vpn connection idempotence
|
||||||
cs_vpn_connection:
|
cs_vpn_connection:
|
||||||
|
vpn_customer_gateway: my_vpn_customer_gateway
|
||||||
vpc: my_vpc
|
vpc: my_vpc
|
||||||
zone: "{{ cs_common_zone_adv }}"
|
zone: "{{ cs_common_zone_adv }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -190,6 +194,7 @@
|
||||||
|
|
||||||
- name: cleanup remove vpn connection
|
- name: cleanup remove vpn connection
|
||||||
cs_vpn_connection:
|
cs_vpn_connection:
|
||||||
|
vpn_customer_gateway: my_vpn_customer_gateway
|
||||||
vpc: my_vpc
|
vpc: my_vpc
|
||||||
zone: "{{ cs_common_zone_adv }}"
|
zone: "{{ cs_common_zone_adv }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
Loading…
Reference in a new issue