Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions libcloud/compute/drivers/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3447,6 +3447,36 @@ def ex_destroy_network(self, network):
self.connection.async_request(request, method='DELETE')
return True

def ex_start_node(self, node):
"""
Start a node that is stopped and in TERMINATED state.

:param node: Node object to start
:type node: :class:`Node`

:return: True if successful
:rtype: ``bool``
"""
request = '/zones/%s/instances/%s/start' % (node.extra['zone'].name,
node.name)
self.connection.async_request(request, method='POST')
return True

def ex_stop_node(self, node):
"""
Stop a running node.

:param node: Node object to stop
:type node: :class:`Node`

:return: True if successful
:rtype: ``bool``
"""
request = '/zones/%s/instances/%s/stop' % (node.extra['zone'].name,
node.name)
self.connection.async_request(request, method='POST')
return True

def destroy_node(self, node, destroy_boot_disk=False):
"""
Destroy a node.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"kind": "compute#operation",
"id": "18431811683007150988",
"name": "operation-stopnode",
"zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a",
"operationType": "stop",
"targetLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/node-name",
"targetId": "12335588484913203363",
"status": "PENDING",
"user": "erjohnso@google.com",
"progress": 0,
"insertTime": "2015-01-30T06:55:11.503-08:00",
"startTime": "2015-01-30T06:55:11.847-08:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/operations/operation-stopnode"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"canIpForward": false,
"creationTimestamp": "2013-12-13T10:45:23.351-08:00",
"disks": [
{
"boot": true,
"deviceName": "persistent-disk-0",
"index": 0,
"kind": "compute#attachedDisk",
"mode": "READ_WRITE",
"source": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/disks/lcdisk",
"type": "PERSISTENT"
}
],
"id": "4006034190819017667",
"kind": "compute#instance",
"machineType": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/machineTypes/n1-standard-1",
"metadata": {
"fingerprint": "42WmSpB8rSM=",
"kind": "compute#metadata"
},
"name": "stopped-node",
"networkInterfaces": [
{
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"natIP": "23.236.58.15",
"type": "ONE_TO_ONE_NAT"
}
],
"name": "nic0",
"network": "https://www.googleapis.com/compute/v1/projects/project_name/global/networks/default",
"networkIP": "10.240.72.75"
}
],
"scheduling": {
"automaticRestart": true,
"onHostMaintenance": "MIGRATE"
},
"selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/stopped-node",
"status": "TERMINATED",
"tags": {
"fingerprint": "42WmSpB8rSM="
},
"zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"kind": "compute#operation",
"id": "18431811683007150988",
"name": "operation-startnode",
"zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a",
"operationType": "start",
"targetLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/stopped-node",
"targetId": "12335588484913203363",
"status": "PENDING",
"user": "erjohnso@google.com",
"progress": 0,
"insertTime": "2015-01-30T06:55:11.503-08:00",
"startTime": "2015-01-30T06:55:11.847-08:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/operations/operation-startnode"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"kind": "compute#operation",
"id": "18431811683007150988",
"name": "operation-stopnode",
"zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a",
"operationType": "stop",
"targetLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/stopped-node",
"targetId": "12335588484913203363",
"status": "PENDING",
"user": "erjohnso@google.com",
"progress": 0,
"insertTime": "2015-01-30T06:55:11.503-08:00",
"startTime": "2015-01-30T06:55:11.847-08:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/operations/operation-stopnode"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"kind": "compute#operation",
"id": "18431811683007150988",
"name": "operation-startnode",
"zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a",
"operationType": "start",
"targetLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/stopped-node",
"targetId": "12335588484913203363",
"status": "DONE",
"user": "erjohnso@google.com",
"progress": 100,
"insertTime": "2015-01-30T06:55:11.503-08:00",
"startTime": "2015-01-30T06:55:11.847-08:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/operations/operation-startnode"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"kind": "compute#operation",
"id": "18431811683007150988",
"name": "operation-stopnode",
"zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a",
"operationType": "stop",
"targetLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/node-name",
"targetId": "12335588484913203363",
"status": "DONE",
"user": "erjohnso@google.com",
"progress": 100,
"insertTime": "2015-01-30T06:55:11.503-08:00",
"startTime": "2015-01-30T06:55:11.847-08:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/operations/operation-stopnode"
}
39 changes: 39 additions & 0 deletions libcloud/test/compute/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ def test_ex_create_network(self):
self.assertEqual(network.name, network_name)
self.assertEqual(network.cidr, cidr)

def test_ex_node_start(self):
zone = 'us-central1-a'
node = self.driver.ex_get_node('stopped-node', zone)
self.assertTrue(self.driver.ex_start_node(node))

def test_ex_node_stop(self):
zone = 'us-central1-a'
node = self.driver.ex_get_node('node-name', zone)
self.assertTrue(self.driver.ex_stop_node(node))

# try and stop a stopped node (should work)
zone = 'us-central1-a'
node = self.driver.ex_get_node('stopped-node', zone)
self.assertTrue(self.driver.ex_stop_node(node))

def test_create_node_req(self):
image = self.driver.ex_get_image('debian-7')
size = self.driver.ex_get_size('n1-standard-1')
Expand Down Expand Up @@ -1314,6 +1329,30 @@ def _setUsageExportBucket(self, method, url, body, headers):
body = self.fixtures.load('setUsageExportBucket_post.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_operations_operation_startnode(self, method, url, body, header):
body = self.fixtures.load('zones_us_central1_a_operations_operation_startnode.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_instances_stopped_node_start(self, method, url, body, header):
body = self.fixtures.load('zones_us_central1_a_instances_stopped_node_start.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_instances_stopped_node_stop(self, method, url, body, header):
body = self.fixtures.load('zones_us_central1_a_instances_stopped_node_stop.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_instances_stopped_node(self, method, url, body, headers):
body = self.fixtures.load('zones_us_central1_a_instances_stopped_node.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_operations_operation_stopnode(self, method, url, body, headers):
body = self.fixtures.load('zones_us_central1_a_operations_operation_stopnode.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_instances_node_name_stop(self, method, url, body, headers):
body = self.fixtures.load('zones_us_central1_a_instances_node_name_stop.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])

def _zones_us_central1_a_instances_node_name_setMetadata(self, method, url, body, headers):
body = self.fixtures.load('zones_us_central1_a_instances_node_name_setMetadata_post.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
Expand Down