googlecloud 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +4 -0
- data/LICENSE +674 -0
- data/Manifest +111 -0
- data/README.md +4 -3
- data/bin/gcutil +53 -0
- data/googlecloud.gemspec +4 -3
- data/packages/gcutil-1.7.1/CHANGELOG +197 -0
- data/packages/gcutil-1.7.1/LICENSE +202 -0
- data/packages/gcutil-1.7.1/VERSION +1 -0
- data/packages/gcutil-1.7.1/gcutil +53 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/LICENSE +23 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/discovery.py +743 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/errors.py +123 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/ext/__init__.py +0 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/http.py +1443 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/mimeparse.py +172 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/model.py +385 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/schema.py +303 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/anyjson.py +32 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/appengine.py +528 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/client.py +1139 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/clientsecrets.py +105 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/crypt.py +244 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/django_orm.py +124 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/file.py +107 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/locked_file.py +343 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.py +379 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/tools.py +174 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/uritemplate/__init__.py +147 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/LICENSE +202 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/__init__.py +3 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/__init__.py +3 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/app.py +356 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/appcommands.py +783 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/basetest.py +1260 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/datelib.py +421 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/debug.py +60 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/file_util.py +181 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/resources.py +67 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/run_script_module.py +217 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/setup_command.py +159 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/shellutil.py +49 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/stopwatch.py +204 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/__init__.py +0 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auth_helper.py +140 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auth_helper_test.py +149 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auto_auth.py +130 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auto_auth_test.py +75 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/basic_cmds.py +128 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/basic_cmds_test.py +111 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.py +1808 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base_test.py +1651 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/compute/v1beta13.json +2851 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/compute/v1beta14.json +3361 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/disk_cmds.py +342 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/disk_cmds_test.py +474 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/firewall_cmds.py +344 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/firewall_cmds_test.py +231 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/flags_cache.py +274 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/gcutil +89 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/gcutil_logging.py +69 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/image_cmds.py +262 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/image_cmds_test.py +172 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/instance_cmds.py +1506 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/instance_cmds_test.py +1904 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/kernel_cmds.py +91 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/kernel_cmds_test.py +56 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/machine_type_cmds.py +106 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/machine_type_cmds_test.py +59 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata.py +96 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata_lib.py +357 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata_test.py +84 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/mock_api.py +420 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/mock_metadata.py +58 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/move_cmds.py +824 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/move_cmds_test.py +307 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/network_cmds.py +178 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/network_cmds_test.py +133 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/operation_cmds.py +181 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/operation_cmds_test.py +196 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/path_initializer.py +38 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/project_cmds.py +173 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/project_cmds_test.py +111 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/scopes.py +61 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/scopes_test.py +50 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/snapshot_cmds.py +276 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/snapshot_cmds_test.py +260 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/ssh_keys.py +266 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/ssh_keys_test.py +128 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/table_formatter.py +563 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.py +188 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool_test.py +88 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/utils.py +208 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/utils_test.py +193 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version.py +17 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version_checker.py +246 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version_checker_test.py +271 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/zone_cmds.py +151 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/zone_cmds_test.py +60 -0
- data/packages/gcutil-1.7.1/lib/httplib2/LICENSE +21 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/__init__.py +1630 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/cacerts.txt +714 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/iri2uri.py +110 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/socks.py +438 -0
- data/packages/gcutil-1.7.1/lib/iso8601/LICENSE +20 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/iso8601.py +102 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/test_iso8601.py +111 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/AUTHORS +2 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/LICENSE +28 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags.py +2862 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags2man.py +544 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags_validators.py +187 -0
- metadata +118 -5
- metadata.gz.sig +0 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
#
|
3
|
+
# Copyright 2012 Google Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
"""Unit tests for the network commands."""
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
import path_initializer
|
22
|
+
path_initializer.InitializeSysPath()
|
23
|
+
|
24
|
+
import copy
|
25
|
+
|
26
|
+
import gflags as flags
|
27
|
+
import unittest
|
28
|
+
|
29
|
+
from gcutil import command_base
|
30
|
+
from gcutil import mock_api
|
31
|
+
from gcutil import network_cmds
|
32
|
+
|
33
|
+
FLAGS = flags.FLAGS
|
34
|
+
|
35
|
+
|
36
|
+
class NetworkCmdsTest(unittest.TestCase):
|
37
|
+
|
38
|
+
def _doTestAddNetworkGeneratesCorrectRequest(self, service_version):
|
39
|
+
flag_values = copy.deepcopy(FLAGS)
|
40
|
+
|
41
|
+
command = network_cmds.AddNetwork('addnetwork', flag_values)
|
42
|
+
|
43
|
+
expected_project = 'test_project'
|
44
|
+
expected_network = 'test-network'
|
45
|
+
expected_range = '192.168.0.0/16'
|
46
|
+
expected_gateway = '192.168.0.1'
|
47
|
+
expected_description = 'test network'
|
48
|
+
flag_values.project = expected_project
|
49
|
+
flag_values.description = expected_description
|
50
|
+
flag_values.range = expected_range
|
51
|
+
flag_values.gateway = expected_gateway
|
52
|
+
flag_values.service_version = service_version
|
53
|
+
|
54
|
+
command.SetFlags(flag_values)
|
55
|
+
command.SetApi(mock_api.MockApi())
|
56
|
+
|
57
|
+
result = command.Handle(expected_network)
|
58
|
+
|
59
|
+
self.assertEqual(result['project'], expected_project)
|
60
|
+
|
61
|
+
response_body = result['body']
|
62
|
+
self.assertEqual(response_body['name'], expected_network)
|
63
|
+
self.assertEqual(response_body['description'], expected_description)
|
64
|
+
|
65
|
+
self.assertEqual(response_body['IPv4Range'], expected_range)
|
66
|
+
self.assertEqual(response_body['gatewayIPv4'], expected_gateway)
|
67
|
+
|
68
|
+
def testAddNetworkGeneratesCorrectRequest(self):
|
69
|
+
for version in command_base.SUPPORTED_VERSIONS:
|
70
|
+
self._doTestAddNetworkGeneratesCorrectRequest(version)
|
71
|
+
|
72
|
+
def testGetNetworkGeneratesCorrectRequest(self):
|
73
|
+
flag_values = copy.deepcopy(FLAGS)
|
74
|
+
|
75
|
+
command = network_cmds.GetNetwork('getnetwork', flag_values)
|
76
|
+
|
77
|
+
expected_project = 'test_project'
|
78
|
+
expected_network = 'test_network'
|
79
|
+
flag_values.project = expected_project
|
80
|
+
|
81
|
+
command.SetFlags(flag_values)
|
82
|
+
command.SetApi(mock_api.MockApi())
|
83
|
+
|
84
|
+
result = command.Handle(expected_network)
|
85
|
+
|
86
|
+
self.assertEqual(result['project'], expected_project)
|
87
|
+
self.assertEqual(result['network'], expected_network)
|
88
|
+
|
89
|
+
def testDeleteNetworkGeneratesCorrectRequest(self):
|
90
|
+
flag_values = copy.deepcopy(FLAGS)
|
91
|
+
|
92
|
+
command = network_cmds.DeleteNetwork('deletenetwork', flag_values)
|
93
|
+
|
94
|
+
expected_project = 'test_project'
|
95
|
+
expected_network = 'test_network'
|
96
|
+
flag_values.project = expected_project
|
97
|
+
|
98
|
+
command.SetFlags(flag_values)
|
99
|
+
command.SetApi(mock_api.MockApi())
|
100
|
+
command._credential = mock_api.MockCredential()
|
101
|
+
|
102
|
+
results, exceptions = command.Handle(expected_network)
|
103
|
+
self.assertEqual(exceptions, [])
|
104
|
+
self.assertEqual(len(results['items']), 1)
|
105
|
+
result = results['items'][0]
|
106
|
+
|
107
|
+
self.assertEqual(result['project'], expected_project)
|
108
|
+
self.assertEqual(result['network'], expected_network)
|
109
|
+
|
110
|
+
def testDeleteMultipleNetworks(self):
|
111
|
+
flag_values = copy.deepcopy(FLAGS)
|
112
|
+
command = network_cmds.DeleteNetwork('deletenetwork', flag_values)
|
113
|
+
|
114
|
+
expected_project = 'test_project'
|
115
|
+
expected_networks = ['test-network-%02d' % x for x in xrange(100)]
|
116
|
+
flag_values.project = expected_project
|
117
|
+
|
118
|
+
command.SetFlags(flag_values)
|
119
|
+
command.SetApi(mock_api.MockApi())
|
120
|
+
command._credential = mock_api.MockCredential()
|
121
|
+
|
122
|
+
results, exceptions = command.Handle(*expected_networks)
|
123
|
+
self.assertEqual(exceptions, [])
|
124
|
+
results = results['items']
|
125
|
+
self.assertEqual(len(results), len(expected_networks))
|
126
|
+
|
127
|
+
for expected_network, result in zip(expected_networks, results):
|
128
|
+
self.assertEqual(result['project'], expected_project)
|
129
|
+
self.assertEqual(result['network'], expected_network)
|
130
|
+
|
131
|
+
|
132
|
+
if __name__ == '__main__':
|
133
|
+
unittest.main()
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# Copyright 2012 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""Commands for interacting with Google Compute Engine operations."""
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
from google.apputils import appcommands
|
20
|
+
import gflags as flags
|
21
|
+
|
22
|
+
from gcutil import command_base
|
23
|
+
|
24
|
+
|
25
|
+
FLAGS = flags.FLAGS
|
26
|
+
|
27
|
+
|
28
|
+
class OperationCommand(command_base.GoogleComputeCommand):
|
29
|
+
"""Base command for working with the operations collection.
|
30
|
+
|
31
|
+
Attributes:
|
32
|
+
default_sort_field: The json field name used to sort list output for the
|
33
|
+
command.
|
34
|
+
summary_fields: A set of tuples of (json field name, human
|
35
|
+
readable name) used to generate a pretty-printed summary description
|
36
|
+
of a list of operation resources.
|
37
|
+
detail_fields: A set of tuples of (json field name, human
|
38
|
+
readable name) used to generate a pretty-printed detailed description
|
39
|
+
of an operation resource.
|
40
|
+
resource_collection_name: The name of the REST API collection handled by
|
41
|
+
this command type.
|
42
|
+
"""
|
43
|
+
|
44
|
+
default_sort_field = (
|
45
|
+
command_base.GoogleComputeCommand.operation_default_sort_field)
|
46
|
+
summary_fields = command_base.GoogleComputeCommand.operation_summary_fields
|
47
|
+
detail_fields = command_base.GoogleComputeCommand.operation_detail_fields
|
48
|
+
|
49
|
+
resource_collection_name = 'operations'
|
50
|
+
|
51
|
+
def __init__(self, name, flag_values):
|
52
|
+
super(OperationCommand, self).__init__(name, flag_values)
|
53
|
+
flags.DEFINE_string('zone',
|
54
|
+
None,
|
55
|
+
'The name of the operation zone or \'%s\' for global '
|
56
|
+
'operations.' % command_base.GLOBAL_ZONE_NAME,
|
57
|
+
flag_values=flag_values)
|
58
|
+
|
59
|
+
def SetApi(self, api):
|
60
|
+
"""Set the Google Compute Engine API for the command.
|
61
|
+
|
62
|
+
Args:
|
63
|
+
api: The Google Compute Engine API used by this command.
|
64
|
+
"""
|
65
|
+
self._zones_api = api.zones()
|
66
|
+
|
67
|
+
if self._IsUsingAtLeastApiVersion('v1beta14'):
|
68
|
+
self._zone_operations_api = api.zoneOperations()
|
69
|
+
self._global_operations_api = api.globalOperations()
|
70
|
+
else:
|
71
|
+
self._global_operations_api = api.operations()
|
72
|
+
|
73
|
+
def _PrepareRequestArgs(self, operation_name, **other_args):
|
74
|
+
"""Gets the dictionary of API method keyword arguments.
|
75
|
+
|
76
|
+
Args:
|
77
|
+
operation_name: The name of the operation.
|
78
|
+
**other_args: Keyword arguments that should be included in the request.
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
Dictionary of keyword arguments that should be passed in the API call,
|
82
|
+
includes all keyword arguments passed in 'other_args' plus
|
83
|
+
common keys such as the name of the resource and the project.
|
84
|
+
"""
|
85
|
+
|
86
|
+
kwargs = {
|
87
|
+
'project': self._project,
|
88
|
+
'operation': self.DenormalizeResourceName(operation_name)
|
89
|
+
}
|
90
|
+
if self._IsUsingAtLeastApiVersion('v1beta14'):
|
91
|
+
if self._flags.zone != command_base.GLOBAL_ZONE_NAME:
|
92
|
+
kwargs['zone'] = self._flags.zone
|
93
|
+
for key, value in other_args.items():
|
94
|
+
kwargs[key] = value
|
95
|
+
return kwargs
|
96
|
+
|
97
|
+
|
98
|
+
class GetOperation(OperationCommand):
|
99
|
+
"""Retrieve an operation resource."""
|
100
|
+
|
101
|
+
positional_args = '<operation-name>'
|
102
|
+
|
103
|
+
def Handle(self, operation_name):
|
104
|
+
"""Get the specified operation.
|
105
|
+
|
106
|
+
Args:
|
107
|
+
operation_name: The name of the operation to get.
|
108
|
+
|
109
|
+
Returns:
|
110
|
+
The json formatted object resulting from retrieving the operation
|
111
|
+
resource.
|
112
|
+
"""
|
113
|
+
# Force asynchronous mode so the caller doesn't wait for this operation
|
114
|
+
# to complete before returning.
|
115
|
+
self._flags.synchronous_mode = False
|
116
|
+
|
117
|
+
kwargs = self._PrepareRequestArgs(operation_name)
|
118
|
+
method = self._global_operations_api.get
|
119
|
+
|
120
|
+
if self._IsUsingAtLeastApiVersion('v1beta14') and 'zone' in kwargs:
|
121
|
+
method = self._zone_operations_api.get
|
122
|
+
|
123
|
+
request = method(**kwargs)
|
124
|
+
return request.execute()
|
125
|
+
|
126
|
+
|
127
|
+
class DeleteOperation(OperationCommand):
|
128
|
+
"""Delete one or more operations."""
|
129
|
+
|
130
|
+
positional_args = '<operation-name-1> ... <operation-name-n>'
|
131
|
+
safety_prompt = 'Delete operation'
|
132
|
+
|
133
|
+
def Handle(self, *operation_names):
|
134
|
+
"""Delete the specified operations.
|
135
|
+
|
136
|
+
Args:
|
137
|
+
*operation_names: The names of the operations to delete.
|
138
|
+
|
139
|
+
Returns:
|
140
|
+
Tuple (results, exceptions) - results of deleting the operations.
|
141
|
+
"""
|
142
|
+
requests = []
|
143
|
+
for operation_name in operation_names:
|
144
|
+
kwargs = self._PrepareRequestArgs(operation_name)
|
145
|
+
method = self._global_operations_api.delete
|
146
|
+
if self._IsUsingAtLeastApiVersion('v1beta14') and 'zone' in kwargs:
|
147
|
+
method = self._zone_operations_api.delete
|
148
|
+
requests.append(method(**kwargs))
|
149
|
+
|
150
|
+
_, exceptions = self.ExecuteRequests(requests)
|
151
|
+
return '', exceptions
|
152
|
+
|
153
|
+
|
154
|
+
class ListOperations(OperationCommand, command_base.GoogleComputeListCommand):
|
155
|
+
"""List the operations for a project."""
|
156
|
+
|
157
|
+
is_global_level_collection = True
|
158
|
+
is_zone_level_collection = True
|
159
|
+
|
160
|
+
def __init__(self, name, flag_values):
|
161
|
+
super(OperationCommand, self).__init__(name, flag_values)
|
162
|
+
flags.DEFINE_string('zone',
|
163
|
+
None,
|
164
|
+
'The zone to list.',
|
165
|
+
flag_values=flag_values)
|
166
|
+
|
167
|
+
def ListFunc(self):
|
168
|
+
"""Returns the function for listing global operations."""
|
169
|
+
return self._global_operations_api.list
|
170
|
+
|
171
|
+
def ListZoneFunc(self):
|
172
|
+
"""Returns the function for listing operations in a zone."""
|
173
|
+
if self._IsUsingAtLeastApiVersion('v1beta14'):
|
174
|
+
return self._zone_operations_api.list
|
175
|
+
return self._global_operations_api.list
|
176
|
+
|
177
|
+
|
178
|
+
def AddCommands():
|
179
|
+
appcommands.AddCmd('getoperation', GetOperation)
|
180
|
+
appcommands.AddCmd('deleteoperation', DeleteOperation)
|
181
|
+
appcommands.AddCmd('listoperations', ListOperations)
|
@@ -0,0 +1,196 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
#
|
3
|
+
# Copyright 2012 Google Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
"""Unit tests for the asynchronous operations commands."""
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
import path_initializer
|
22
|
+
path_initializer.InitializeSysPath()
|
23
|
+
|
24
|
+
import copy
|
25
|
+
|
26
|
+
import gflags as flags
|
27
|
+
import unittest
|
28
|
+
|
29
|
+
from gcutil import command_base
|
30
|
+
from gcutil import mock_api
|
31
|
+
from gcutil import operation_cmds
|
32
|
+
|
33
|
+
FLAGS = flags.FLAGS
|
34
|
+
|
35
|
+
|
36
|
+
class OperationCmdsTest(unittest.TestCase):
|
37
|
+
|
38
|
+
def _DoTestGetOperationGeneratesCorrectRequest(self, service_version):
|
39
|
+
flag_values = copy.deepcopy(FLAGS)
|
40
|
+
|
41
|
+
command = operation_cmds.GetOperation('getoperation', flag_values)
|
42
|
+
|
43
|
+
expected_project = 'test_project'
|
44
|
+
expected_operation = 'test_operation'
|
45
|
+
flag_values.project = expected_project
|
46
|
+
flag_values.service_version = service_version
|
47
|
+
|
48
|
+
command.SetFlags(flag_values)
|
49
|
+
command.SetApi(mock_api.MockApi())
|
50
|
+
if command._IsUsingAtLeastApiVersion('v1beta14'):
|
51
|
+
submitted_zone = 'myzone'
|
52
|
+
flag_values.zone = submitted_zone
|
53
|
+
|
54
|
+
result = command.Handle(expected_operation)
|
55
|
+
|
56
|
+
self.assertEqual(result['project'], expected_project)
|
57
|
+
self.assertEqual(result['operation'], expected_operation)
|
58
|
+
|
59
|
+
api = command._global_operations_api
|
60
|
+
if command._IsUsingAtLeastApiVersion('v1beta14'):
|
61
|
+
api = command._zone_operations_api
|
62
|
+
|
63
|
+
self.assertEquals(1, len(api.requests))
|
64
|
+
request = api.requests[0]
|
65
|
+
if command._IsUsingAtLeastApiVersion('v1beta14'):
|
66
|
+
self.assertEqual(submitted_zone, request.request_payload['zone'])
|
67
|
+
else:
|
68
|
+
self.assertFalse('zone' in request.request_payload)
|
69
|
+
self.assertEqual(expected_project, request.request_payload['project'])
|
70
|
+
self.assertEqual(expected_operation, request.request_payload['operation'])
|
71
|
+
|
72
|
+
def testGetOperationGeneratesCorrectRequest(self):
|
73
|
+
for version in command_base.SUPPORTED_VERSIONS:
|
74
|
+
self._DoTestGetOperationGeneratesCorrectRequest(version)
|
75
|
+
|
76
|
+
def _DoTestDeleteOperationGeneratesCorrectRequest(self, service_version):
|
77
|
+
flag_values = copy.deepcopy(FLAGS)
|
78
|
+
|
79
|
+
command = operation_cmds.DeleteOperation('deleteoperation', flag_values)
|
80
|
+
|
81
|
+
expected_project = 'test_project'
|
82
|
+
expected_operation = 'test_operation'
|
83
|
+
flag_values.project = expected_project
|
84
|
+
flag_values.service_version = service_version
|
85
|
+
|
86
|
+
command.SetFlags(flag_values)
|
87
|
+
command.SetApi(mock_api.MockApi())
|
88
|
+
command._credential = mock_api.MockCredential()
|
89
|
+
if command._IsUsingAtLeastApiVersion('v1beta14'):
|
90
|
+
submitted_zone = 'myzone'
|
91
|
+
flag_values.zone = submitted_zone
|
92
|
+
|
93
|
+
results, exceptions = command.Handle(expected_operation)
|
94
|
+
self.assertEqual(exceptions, [])
|
95
|
+
self.assertEqual(results, '')
|
96
|
+
|
97
|
+
# Verify the request
|
98
|
+
api = command._global_operations_api
|
99
|
+
if command._IsUsingAtLeastApiVersion('v1beta14'):
|
100
|
+
api = command._zone_operations_api
|
101
|
+
|
102
|
+
self.assertEquals(1, len(api.requests))
|
103
|
+
request = api.requests[0]
|
104
|
+
if command._IsUsingAtLeastApiVersion('v1beta14'):
|
105
|
+
self.assertEqual(submitted_zone, request.request_payload['zone'])
|
106
|
+
else:
|
107
|
+
self.assertFalse('zone' in request.request_payload)
|
108
|
+
self.assertEqual(expected_project, request.request_payload['project'])
|
109
|
+
self.assertEqual(expected_operation, request.request_payload['operation'])
|
110
|
+
|
111
|
+
def testDeleteOperationGeneratesCorrectRequest(self):
|
112
|
+
for version in command_base.SUPPORTED_VERSIONS:
|
113
|
+
self._DoTestDeleteOperationGeneratesCorrectRequest(version)
|
114
|
+
|
115
|
+
def _DoTestGetGlobalOperationGeneratesCorrectRequest(self, service_version):
|
116
|
+
flag_values = copy.deepcopy(FLAGS)
|
117
|
+
|
118
|
+
command = operation_cmds.GetOperation('getoperation', flag_values)
|
119
|
+
|
120
|
+
expected_project = 'test_project'
|
121
|
+
expected_operation = 'test_operation'
|
122
|
+
flag_values.project = expected_project
|
123
|
+
flag_values.service_version = service_version
|
124
|
+
flag_values.zone = command_base.GLOBAL_ZONE_NAME
|
125
|
+
|
126
|
+
command.SetFlags(flag_values)
|
127
|
+
command.SetApi(mock_api.MockApi())
|
128
|
+
command._credential = mock_api.MockCredential()
|
129
|
+
if not command._IsUsingAtLeastApiVersion('v1beta14'):
|
130
|
+
return
|
131
|
+
|
132
|
+
command.Handle(expected_operation)
|
133
|
+
|
134
|
+
# Verify the request
|
135
|
+
self.assertEquals(1, len(command._global_operations_api.requests))
|
136
|
+
request = command._global_operations_api.requests[0]
|
137
|
+
self.assertEqual('get', request.method_name)
|
138
|
+
self.assertEqual(expected_project, request.request_payload['project'])
|
139
|
+
self.assertEqual(expected_operation, request.request_payload['operation'])
|
140
|
+
|
141
|
+
def testGetGlobalOperationGeneratesCorrectRequest(self):
|
142
|
+
for version in command_base.SUPPORTED_VERSIONS:
|
143
|
+
self._DoTestGetGlobalOperationGeneratesCorrectRequest(version)
|
144
|
+
|
145
|
+
def _DoTestDeleteGlobalOperationGeneratesCorrectRequest(self,
|
146
|
+
service_version):
|
147
|
+
flag_values = copy.deepcopy(FLAGS)
|
148
|
+
|
149
|
+
command = operation_cmds.DeleteOperation('deleteoperation', flag_values)
|
150
|
+
|
151
|
+
expected_project = 'test_project'
|
152
|
+
expected_operation = 'test_operation'
|
153
|
+
flag_values.project = expected_project
|
154
|
+
flag_values.service_version = service_version
|
155
|
+
flag_values.zone = command_base.GLOBAL_ZONE_NAME
|
156
|
+
|
157
|
+
command.SetFlags(flag_values)
|
158
|
+
command.SetApi(mock_api.MockApi())
|
159
|
+
command._credential = mock_api.MockCredential()
|
160
|
+
if not command._IsUsingAtLeastApiVersion('v1beta14'):
|
161
|
+
return
|
162
|
+
|
163
|
+
results, exceptions = command.Handle(expected_operation)
|
164
|
+
self.assertEqual(exceptions, [])
|
165
|
+
self.assertEqual(results, '')
|
166
|
+
|
167
|
+
# Verify the request
|
168
|
+
self.assertEquals(1, len(command._global_operations_api.requests))
|
169
|
+
request = command._global_operations_api.requests[0]
|
170
|
+
self.assertEqual('delete', request.method_name)
|
171
|
+
self.assertEqual(expected_project, request.request_payload['project'])
|
172
|
+
self.assertEqual(expected_operation, request.request_payload['operation'])
|
173
|
+
|
174
|
+
def testDeleteGlobalOperationGeneratesCorrectRequest(self):
|
175
|
+
for version in command_base.SUPPORTED_VERSIONS:
|
176
|
+
self._DoTestDeleteGlobalOperationGeneratesCorrectRequest(version)
|
177
|
+
|
178
|
+
def testDeleteMultipleOperations(self):
|
179
|
+
flag_values = copy.deepcopy(FLAGS)
|
180
|
+
command = operation_cmds.DeleteOperation('deleteoperation', flag_values)
|
181
|
+
|
182
|
+
expected_project = 'test_project'
|
183
|
+
expected_operations = ['test-operation-%02d' % x for x in xrange(100)]
|
184
|
+
flag_values.project = expected_project
|
185
|
+
|
186
|
+
command.SetFlags(flag_values)
|
187
|
+
command.SetApi(mock_api.MockApi())
|
188
|
+
command._credential = mock_api.MockCredential()
|
189
|
+
|
190
|
+
results, exceptions = command.Handle(*expected_operations)
|
191
|
+
self.assertEqual(exceptions, [])
|
192
|
+
self.assertEqual(results, '')
|
193
|
+
|
194
|
+
|
195
|
+
if __name__ == '__main__':
|
196
|
+
unittest.main()
|