forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into sql-settings-version
- Loading branch information
Showing
39 changed files
with
1,042 additions
and
200 deletions.
There are no files selected for viewing
Submodule ansible
updated
39 files
Submodule compute
updated
57 files
Submodule dns
updated
3 files
+2 −6 | resources/managed_zone.rb | |
+2 −6 | resources/project.rb | |
+2 −3 | resources/resource_record_set.rb |
Submodule sql
updated
6 files
+2 −4 | resources/database.rb | |
+1 −5 | resources/flag.rb | |
+2 −4 | resources/instance.rb | |
+2 −6 | resources/ssl_cert.rb | |
+1 −5 | resources/tier.rb | |
+1 −5 | resources/user.rb |
Submodule storage
updated
4 files
+2 −6 | resources/bucket.rb | |
+4 −4 | resources/bucket_access_control.rb | |
+4 −4 | resources/default_object_acl.rb | |
+4 −4 | resources/object_access_control.rb |
Submodule compute
updated
59 files
Submodule dns
updated
3 files
+0 −2 | lib/puppet/provider/gdns_managed_zone/google.rb | |
+0 −2 | lib/puppet/provider/gdns_project/google.rb | |
+2 −3 | lib/puppet/provider/gdns_resource_record_set/google.rb |
Submodule sql
updated
4 files
+0 −2 | lib/puppet/provider/gsql_flag/google.rb | |
+0 −2 | lib/puppet/provider/gsql_ssl_cert/google.rb | |
+0 −2 | lib/puppet/provider/gsql_tier/google.rb | |
+0 −2 | lib/puppet/provider/gsql_user/google.rb |
Submodule terraform
updated
from e4a386 to e6af1c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
products/compute/helpers/python/instancegroup_instances.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<% | ||
# Instance Logic handling for Instance Groups | ||
# This code handles the adding + removing of instances from an instance group. | ||
# It should be run after all normal create/update/delete logic. | ||
|
||
-%> | ||
class InstanceLogic(object): | ||
def __init__(self, module): | ||
self.module = module | ||
self.current_instances = self.list_instances() | ||
self.module_instances = [] | ||
|
||
# Transform module list of instances (dicts of instance responses) into a list of selfLinks. | ||
instances = self.module.params.get('instances') | ||
if instances: | ||
for instance in instances: | ||
self.module_instances.append(replace_resource_dict(instance, 'selfLink')) | ||
|
||
def run(self): | ||
# Find all instances to add and add them | ||
instances_to_add = list(set(self.module_instances) - set(self.current_instances)) | ||
if instances_to_add: | ||
self.add_instances(instances_to_add) | ||
|
||
# Find all instances to remove and remove them | ||
instances_to_remove = list(set(self.current_instances) - set(self.module_instances)) | ||
if instances_to_remove: | ||
self.remove_instances(instances_to_remove) | ||
|
||
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') | ||
|
||
# Transform instance list into a list of selfLinks for diffing with module parameters | ||
instances = [] | ||
for instance in response.get('items', []): | ||
instances.append(instance['instance']) | ||
return instances | ||
|
||
def add_instances(self, instances): | ||
auth = GcpSession(self.module, 'compute') | ||
wait_for_operation(self.module, auth.post(self._add_instances_url(), self._build_request(instances))) | ||
|
||
def remove_instances(self, instances): | ||
auth = GcpSession(self.module, 'compute') | ||
wait_for_operation(self.module, auth.post(self._remove_instances_url(), self._build_request(instances))) | ||
|
||
def _list_instances_url(self): | ||
return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroups/{name}/listInstances".format(**self.module.params) | ||
|
||
def _remove_instances_url(self): | ||
return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroups/{name}/removeInstances".format(**self.module.params) | ||
|
||
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': [] | ||
} | ||
for instance in instances: | ||
request['instances'].append({'instance': instance}) | ||
return request |
Oops, something went wrong.