Skip to content

Commit

Permalink
Add route_rules to UrlMap for Traffic Director
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
Ty Larrabee authored and modular-magician committed Nov 25, 2019
1 parent 660b063 commit b84a78c
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 74 deletions.
133 changes: 85 additions & 48 deletions plugins/modules/gcp_compute_url_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@
type: str
default_service:
description:
- A reference to BackendService resource if none of the hostRules match.
- The BackendService resource to which traffic is directed if none of the hostRules
match. If defaultRouteAction is additionally specified, advanced routing actions
like URL Rewrites, etc. take effect prior to sending the request to the backend.
However, if defaultService is specified, defaultRouteAction cannot contain any
weightedBackendServices. Conversely, if routeAction specifies any weightedBackendServices,
service must not be specified. Only one of defaultService, defaultUrlRedirect
or defaultRouteAction.weightedBackendService must be set.
- 'This field represents a link to a BackendService resource in GCP. It can be
specified in two ways. First, you can place a dictionary with key ''selfLink''
and value of your resource''s selfLink Alternatively, you can add `register:
name-of-resource` to a gcp_compute_backend_service task and then set this default_service
field to "{{ name-of-resource }}"'
required: true
required: false
type: dict
description:
description:
Expand All @@ -73,7 +79,7 @@
suboptions:
description:
description:
- An optional description of this HostRule. Provide this property when you
- An optional description of this resource. Provide this property when you
create the resource.
required: false
type: str
Expand Down Expand Up @@ -108,25 +114,33 @@
suboptions:
default_service:
description:
- A reference to a BackendService resource. This will be used if none of the
pathRules defined by this PathMatcher is matched by the URL's path portion.
- 'The BackendService resource. This will be used if none of the pathRules
or routeRules defined by this PathMatcher are matched. For example, the
following are all valid URLs to a BackendService resource: - http s://U(www.googleapis.com/compute/v1/projects/project/global/backendServices/backen)
dService - compute/v1/projects/project/global/backendServices/backendService
- global/backendServices/backendService If defaultRouteAction is additionally
specified, advanced routing actions like URL Rewrites, etc. take effect
prior to sending the request to the backend. However, if defaultService
is specified, defaultRouteAction cannot contain any weightedBackendServices.
Conversely, if defaultRouteAction specifies any weightedBackendServices,
defaultService must not be specified. Only one of defaultService, defaultUrlRedirect
or defaultRouteAction.weightedBackendService must be set. Authorization
requires one or more of the following Google IAM permissions on the specified
resource default_service: - compute.backendBuckets.use - compute.backendServices.use
.'
- 'This field represents a link to a BackendService resource in GCP. It can
be specified in two ways. First, you can place a dictionary with key ''selfLink''
and value of your resource''s selfLink Alternatively, you can add `register:
name-of-resource` to a gcp_compute_backend_service task and then set this
default_service field to "{{ name-of-resource }}"'
required: true
required: false
type: dict
description:
description:
- An optional description of this resource.
- An optional description of this resource. Provide this property when you
create the resource.
required: false
type: str
name:
description:
- The name to which this PathMatcher is referred by the HostRule.
required: true
type: str
path_rules:
description:
- The list of path rules.
Expand All @@ -151,10 +165,16 @@
task and then set this service field to "{{ name-of-resource }}"'
required: true
type: dict
name:
description:
- The name to which this PathMatcher is referred by the HostRule.
required: true
type: str
tests:
description:
- The list of expected URL mappings. Requests to update this UrlMap will succeed
only if all of the test cases pass.
- The list of expected URL mapping tests. Request to update this UrlMap will succeed
only if all of the test cases pass. You can specify a maximum of 100 tests per
UrlMap.
required: false
type: list
suboptions:
Expand All @@ -175,8 +195,7 @@
type: str
service:
description:
- A reference to expected BackendService resource the given URL should be
mapped to.
- Expected BackendService resource the given URL should be mapped to.
- 'This field represents a link to a BackendService resource in GCP. It can
be specified in two ways. First, you can place a dictionary with key ''selfLink''
and value of your resource''s selfLink Alternatively, you can add `register:
Expand Down Expand Up @@ -272,14 +291,25 @@
'''

RETURN = '''
id:
description:
- The unique identifier for the resource.
returned: success
type: int
creationTimestamp:
description:
- Creation timestamp in RFC3339 text format.
returned: success
type: str
defaultService:
description:
- A reference to BackendService resource if none of the hostRules match.
- The BackendService resource to which traffic is directed if none of the hostRules
match. If defaultRouteAction is additionally specified, advanced routing actions
like URL Rewrites, etc. take effect prior to sending the request to the backend.
However, if defaultService is specified, defaultRouteAction cannot contain any
weightedBackendServices. Conversely, if routeAction specifies any weightedBackendServices,
service must not be specified. Only one of defaultService, defaultUrlRedirect
or defaultRouteAction.weightedBackendService must be set.
returned: success
type: dict
description:
Expand All @@ -288,6 +318,12 @@
the resource.
returned: success
type: str
fingerprint:
description:
- Fingerprint of this resource. A hash of the contents stored in this object. This
field is used in optimistic locking.
returned: success
type: str
hostRules:
description:
- The list of HostRules to use against the URL.
Expand All @@ -296,7 +332,7 @@
contains:
description:
description:
- An optional description of this HostRule. Provide this property when you create
- An optional description of this resource. Provide this property when you create
the resource.
returned: success
type: str
Expand All @@ -313,17 +349,6 @@
the hostRule matches the URL's host portion.
returned: success
type: str
id:
description:
- The unique identifier for the resource.
returned: success
type: int
fingerprint:
description:
- Fingerprint of this resource. This field is used internally during updates of
this resource.
returned: success
type: str
name:
description:
- Name of the resource. Provided by the client when the resource is created. The
Expand All @@ -342,18 +367,25 @@
contains:
defaultService:
description:
- A reference to a BackendService resource. This will be used if none of the
pathRules defined by this PathMatcher is matched by the URL's path portion.
- 'The BackendService resource. This will be used if none of the pathRules or
routeRules defined by this PathMatcher are matched. For example, the following
are all valid URLs to a BackendService resource: - http s://U(www.googleapis.com/compute/v1/projects/project/global/backendServices/backen)
dService - compute/v1/projects/project/global/backendServices/backendService
- global/backendServices/backendService If defaultRouteAction is additionally
specified, advanced routing actions like URL Rewrites, etc. take effect prior
to sending the request to the backend. However, if defaultService is specified,
defaultRouteAction cannot contain any weightedBackendServices. Conversely,
if defaultRouteAction specifies any weightedBackendServices, defaultService
must not be specified. Only one of defaultService, defaultUrlRedirect or defaultRouteAction.weightedBackendService
must be set. Authorization requires one or more of the following Google IAM
permissions on the specified resource default_service: - compute.backendBuckets.use
- compute.backendServices.use .'
returned: success
type: dict
description:
description:
- An optional description of this resource.
returned: success
type: str
name:
description:
- The name to which this PathMatcher is referred by the HostRule.
- An optional description of this resource. Provide this property when you create
the resource.
returned: success
type: str
pathRules:
Expand All @@ -375,10 +407,16 @@
- A reference to the BackendService resource if this rule is matched.
returned: success
type: dict
name:
description:
- The name to which this PathMatcher is referred by the HostRule.
returned: success
type: str
tests:
description:
- The list of expected URL mappings. Requests to update this UrlMap will succeed
only if all of the test cases pass.
- The list of expected URL mapping tests. Request to update this UrlMap will succeed
only if all of the test cases pass. You can specify a maximum of 100 tests per
UrlMap.
returned: success
type: complex
contains:
Expand All @@ -399,8 +437,7 @@
type: str
service:
description:
- A reference to expected BackendService resource the given URL should be mapped
to.
- Expected BackendService resource the given URL should be mapped to.
returned: success
type: dict
'''
Expand Down Expand Up @@ -431,7 +468,7 @@ def main():
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
default_service=dict(required=True, type='dict'),
default_service=dict(type='dict'),
description=dict(type='str'),
host_rules=dict(
type='list',
Expand All @@ -445,14 +482,14 @@ def main():
type='list',
elements='dict',
options=dict(
default_service=dict(required=True, type='dict'),
default_service=dict(type='dict'),
description=dict(type='str'),
name=dict(required=True, type='str'),
path_rules=dict(
type='list',
elements='dict',
options=dict(paths=dict(required=True, type='list', elements='str'), service=dict(required=True, type='dict')),
),
name=dict(required=True, type='str'),
),
),
tests=dict(
Expand Down Expand Up @@ -588,12 +625,12 @@ def is_different(module, response):
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'id': response.get(u'id'),
u'creationTimestamp': response.get(u'creationTimestamp'),
u'defaultService': response.get(u'defaultService'),
u'description': response.get(u'description'),
u'hostRules': UrlMapHostrulesArray(response.get(u'hostRules', []), module).from_response(),
u'id': response.get(u'id'),
u'fingerprint': response.get(u'fingerprint'),
u'hostRules': UrlMapHostrulesArray(response.get(u'hostRules', []), module).from_response(),
u'name': module.params.get('name'),
u'pathMatchers': UrlMapPathmatchersArray(response.get(u'pathMatchers', []), module).from_response(),
u'tests': UrlMapTestsArray(response.get(u'tests', []), module).from_response(),
Expand Down Expand Up @@ -687,8 +724,8 @@ def _request_for_item(self, item):
{
u'defaultService': replace_resource_dict(item.get(u'default_service', {}), 'selfLink'),
u'description': item.get('description'),
u'name': item.get('name'),
u'pathRules': UrlMapPathrulesArray(item.get('path_rules', []), self.module).to_request(),
u'name': item.get('name'),
}
)

Expand All @@ -697,8 +734,8 @@ def _response_from_item(self, item):
{
u'defaultService': item.get(u'defaultService'),
u'description': item.get(u'description'),
u'name': item.get(u'name'),
u'pathRules': UrlMapPathrulesArray(item.get(u'pathRules', []), self.module).from_response(),
u'name': item.get(u'name'),
}
)

Expand Down
Loading

0 comments on commit b84a78c

Please sign in to comment.