# # Copyright 2020 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from org.xebialabs.community.googlecloud import GoogleCloudCompute print("Connecting to google cloud with {0} email".format(deployed.container.clientEmail)) googleCompute = GoogleCloudCompute(deployed.container.clientEmail, deployed.container.privateKey, deployed.container.projectId) templateName = deployed.templateName zone = deployed.zone instanceName = deployed.name print("Create new instance {} ...".format(instanceName)) operationSelfLink = googleCompute.createInstancesFromTemplate(instanceName, templateName, zone, 1) deployed.operationSelfLink = operationSelfLink
# # Copyright 2020 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from org.xebialabs.community.googlecloud import GoogleCloudCompute googleCompute = GoogleCloudCompute(previousDeployed.container.clientEmail, previousDeployed.container.privateKey, previousDeployed.container.projectId) instanceName = previousDeployed.instanceName if previousDeployed.instanceName else previousDeployed.name zone = previousDeployed.zone print("Wait for the end of {} {}...".format(instanceName, zone)) if not googleCompute.isOperationDone(previousDeployed.operationSelfLink, zone): result = "RETRY" else: print("instance {0} is destroyed".format(instanceName))
# # Copyright 2020 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from org.xebialabs.community.googlecloud import GoogleCloudCompute print("Connecting to google cloud with {0} email".format( previousDeployed.container.clientEmail)) googleCompute = GoogleCloudCompute(previousDeployed.container.clientEmail, previousDeployed.container.privateKey, previousDeployed.container.projectId) instanceName = previousDeployed.instanceName if previousDeployed.instanceName else previousDeployed.name print("Destroy instance {} ...".format(instanceName)) operationSelfLink = googleCompute.deleteInstance(instanceName, previousDeployed.zone) previousDeployed.operationSelfLink = operationSelfLink
# # Copyright 2020 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from org.xebialabs.community.googlecloud import GoogleCloudCompute print("Check Connection on '%s'" % thisCi.name) print("Using %s client email" % thisCi.clientEmail) googleCompute = GoogleCloudCompute(thisCi.clientEmail, thisCi.privateKey, thisCi.projectId) print("____instances____") names = googleCompute.getInstanceNames() print("--") for name in names: print(name) print("-done-")
local_status = local_instance.getStatus() print("Status {0}".format(local_status)) if wait_for_running: if "RUNNING" == local_status: print("Running !") return local_instance else: print("Wait for {0} running".format(instance_name)) time.sleep(5) return get_instance(google_compute, instance_name, True) else: return local_instance googleCompute = GoogleCloudCompute(deployed.container.clientEmail, deployed.container.privateKey, deployed.container.projectId) groupName = deployed.name zone = deployed.zone print("Wait for a new instance {} in {} ...".format(groupName, zone)) if not googleCompute.isOperationDone(deployed.operationSelfLink, zone): result = "RETRY" else: instanceGroup = googleCompute.getInstanceByGroupName(groupName, zone) print("instanceGroup = {0} ".format(instanceGroup)) managedInstancesByGroupName = googleCompute.getManagedInstancesSelfLinkByGroupName( zone, instanceGroup.getName()) for s in managedInstancesByGroupName: print("instance group name is {0}".format(s))
# # Copyright 2020 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from org.xebialabs.community.googlecloud import GoogleCloudCompute print("Connecting to google cloud with {0} email".format( deployed.container.clientEmail)) googleCompute = GoogleCloudCompute(deployed.container.clientEmail, deployed.container.privateKey, deployed.container.projectId) machine = deployed.machine zone = deployed.zone image = deployed.image imageProject = deployed.imageProject externalAddress = deployed.externalAddress metadata = deployed.metadata instanceName = deployed.instanceName if deployed.instanceName else deployed.name print("Create new instance {} ...".format(instanceName)) operationSelfLink = googleCompute.createInstance(instanceName, image, imageProject, machine, zone, externalAddress, metadata)
# # Copyright 2020 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from org.xebialabs.community.googlecloud import GoogleCloudCompute googleCompute = GoogleCloudCompute(deployed.container.clientEmail, deployed.container.privateKey, deployed.container.projectId) instanceName = deployed.instanceName if deployed.instanceName else deployed.name zone = deployed.zone print("Wait for a new instance {} in {} ...".format(instanceName, zone)) if not googleCompute.isOperationDone(deployed.operationSelfLink, zone): result = "RETRY" else: instance = googleCompute.getInstanceByName(instanceName, zone) print("instance is {0}".format(instance)) deployed.instanceId = str(instance.getSelfLink()) deployed.privateIp = instance.getNetworkInterfaces().get(0).getNetworkIP() if instance.getNetworkInterfaces().get(0).getAccessConfigs(): deployed.publicIp = instance.getNetworkInterfaces().get( 0).getAccessConfigs().get(0).getNatIP() print("instance ID is {0}".format(deployed.instanceId))