Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
InstanceGroup should add/remove instances (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
modular-magician authored and rambleraptor committed May 20, 2019
1 parent a828ad5 commit 16280f2
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 117 deletions.
154 changes: 76 additions & 78 deletions lib/ansible/modules/cloud/google/gcp_compute_instance_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,19 @@
description:
- The port number, which can be a value between 1 and 65535.
required: false
network:
description:
- The network to which all instances in the instance group belong.
- 'This field represents a link to a Network 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_network task and then set this network field to "{{ name-of-resource
}}"'
required: false
region:
description:
- The region where the instance group is located (for regional resources).
required: false
subnetwork:
description:
- The subnetwork to which all instances in the instance group belong.
- 'This field represents a link to a Subnetwork 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_subnetwork task and then set this subnetwork field to "{{ name-of-resource
}}"'
required: false
zone:
description:
- A reference to the zone where the instance group resides.
required: true
instances:
description:
- The list of instances associated with this InstanceGroup.
- All instances must be created before being added to an InstanceGroup.
- All instances not in this list will be removed from the InstanceGroup and will
not be deleted.
- Only the full identifier of the instance will be returned.
required: false
version_added: 2.8
zone:
description:
- A reference to the zone where the instance group resides.
required: true
instances:
description:
- The list of instances associated with this InstanceGroup.
- All instances must be created before being added to an InstanceGroup.
- All instances not in this list will be removed from the InstanceGroup and will not
be deleted.
- Only the full identifier of the instance will be returned.
required: false
version_added: 2.7
extends_documentation_fragment: gcp
'''

Expand Down Expand Up @@ -176,45 +154,62 @@
type: complex
contains:
name:
description:
- The name for this named port.
- The name must be 1-63 characters long, and comply with RFC1035.
returned: success
type: str
port:
description:
- The port number, which can be a value between 1 and 65535.
returned: success
type: int
network:
description:
- The network to which all instances in the instance group belong.
returned: success
type: dict
region:
description:
- The region where the instance group is located (for regional resources).
returned: success
type: str
subnetwork:
description:
- The subnetwork to which all instances in the instance group belong.
returned: success
type: dict
zone:
description:
- A reference to the zone where the instance group resides.
returned: success
type: str
instances:
description:
- The list of instances associated with this InstanceGroup.
- All instances must be created before being added to an InstanceGroup.
- All instances not in this list will be removed from the InstanceGroup and will
not be deleted.
- Only the full identifier of the instance will be returned.
returned: success
type: list
description:
- The name of the instance group.
- The name must be 1-63 characters long, and comply with RFC1035.
returned: success
type: str
named_ports:
description:
- Assigns a name to a port number.
- 'For example: {name: "http", port: 80}.'
- This allows the system to reference ports by the assigned name instead of a port
number. Named ports can also contain multiple ports.
- 'For example: [{name: "http", port: 80},{name: "http", port: 8080}] Named ports
apply to all instances in this instance group.'
returned: success
type: complex
contains:
name:
description:
- The name for this named port.
- The name must be 1-63 characters long, and comply with RFC1035.
returned: success
type: str
port:
description:
- The port number, which can be a value between 1 and 65535.
returned: success
type: int
network:
description:
- The network to which all instances in the instance group belong.
returned: success
type: dict
region:
description:
- The region where the instance group is located (for regional resources).
returned: success
type: str
subnetwork:
description:
- The subnetwork to which all instances in the instance group belong.
returned: success
type: dict
zone:
description:
- A reference to the zone where the instance group resides.
returned: success
type: str
instances:
description:
- The list of instances associated with this InstanceGroup.
- All instances must be created before being added to an InstanceGroup.
- All instances not in this list will be removed from the InstanceGroup and will not
be deleted.
- Only the full identifier of the instance will be returned.
returned: success
type: list
'''

################################################################################
Expand Down Expand Up @@ -244,7 +239,7 @@ def main():
region=dict(type='str'),
subnetwork=dict(type='dict'),
zone=dict(required=True, type='str'),
instances=dict(type='list', elements='dict'),
instances=dict(type='list', elements='dict')
)
)

Expand Down Expand Up @@ -452,7 +447,8 @@ def run(self):

def list_instances(self):
auth = GcpSession(self.module, 'compute')
response = return_if_object(self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}), 'compute#instanceGroupsListInstances')
response = return_if_object(self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}),
'compute#instanceGroupsListInstances')

# Transform instance list into a list of selfLinks for diffing with module parameters
instances = []
Expand All @@ -478,13 +474,15 @@ def _add_instances_url(self):
return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroups/{name}/addInstances".format(**self.module.params)

def _build_request(self, instances):
request = {'instances': []}
request = {
'instances': []
}
for instance in instances:
request['instances'].append({'instance': instance})
return request


class InstanceGroupNamedportsArray(object):
class InstanceGroupNamedPortsArray(object):
def __init__(self, request, module):
self.module = module
if request:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,45 +104,62 @@
type: complex
contains:
name:
description:
- The name for this named port.
- The name must be 1-63 characters long, and comply with RFC1035.
returned: success
type: str
port:
description:
- The port number, which can be a value between 1 and 65535.
returned: success
type: int
network:
description:
- The network to which all instances in the instance group belong.
returned: success
type: dict
region:
description:
- The region where the instance group is located (for regional resources).
returned: success
type: str
subnetwork:
description:
- The subnetwork to which all instances in the instance group belong.
returned: success
type: dict
zone:
description:
- A reference to the zone where the instance group resides.
returned: success
type: str
instances:
description:
- The list of instances associated with this InstanceGroup.
- All instances must be created before being added to an InstanceGroup.
- All instances not in this list will be removed from the InstanceGroup and
will not be deleted.
- Only the full identifier of the instance will be returned.
returned: success
type: list
description:
- The name of the instance group.
- The name must be 1-63 characters long, and comply with RFC1035.
returned: success
type: str
named_ports:
description:
- Assigns a name to a port number.
- 'For example: {name: "http", port: 80}.'
- This allows the system to reference ports by the assigned name instead of a port
number. Named ports can also contain multiple ports.
- 'For example: [{name: "http", port: 80},{name: "http", port: 8080}] Named ports
apply to all instances in this instance group.'
returned: success
type: complex
contains:
name:
description:
- The name for this named port.
- The name must be 1-63 characters long, and comply with RFC1035.
returned: success
type: str
port:
description:
- The port number, which can be a value between 1 and 65535.
returned: success
type: int
network:
description:
- The network to which all instances in the instance group belong.
returned: success
type: dict
region:
description:
- The region where the instance group is located (for regional resources).
returned: success
type: str
subnetwork:
description:
- The subnetwork to which all instances in the instance group belong.
returned: success
type: dict
zone:
description:
- A reference to the zone where the instance group resides.
returned: success
type: str
instances:
description:
- The list of instances associated with this InstanceGroup.
- All instances must be created before being added to an InstanceGroup.
- All instances not in this list will be removed from the InstanceGroup and will not
be deleted.
- Only the full identifier of the instance will be returned.
returned: success
type: list
'''

################################################################################
Expand Down

0 comments on commit 16280f2

Please sign in to comment.