knife-google 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/.gitignore +22 -0
  2. data/CONTRIB.md +64 -0
  3. data/Gemfile +11 -0
  4. data/README.md +287 -0
  5. data/Rakefile +53 -0
  6. data/knife-google.gemspec +26 -0
  7. data/lib/chef/knife/google_base.rb +39 -68
  8. data/lib/chef/knife/google_disk_create.rb +60 -0
  9. data/lib/chef/knife/google_disk_delete.rb +60 -0
  10. data/lib/chef/knife/google_disk_list.rb +75 -0
  11. data/lib/chef/knife/google_server_create.rb +273 -184
  12. data/lib/chef/knife/google_server_delete.rb +74 -32
  13. data/lib/chef/knife/google_server_list.rb +45 -64
  14. data/lib/chef/knife/google_setup.rb +31 -0
  15. data/lib/chef/knife/google_zone_list.rb +78 -0
  16. data/lib/google/compute.rb +46 -0
  17. data/lib/google/compute/client.rb +188 -0
  18. data/lib/google/compute/config.rb +23 -0
  19. data/lib/google/compute/creatable_resource_collection.rb +38 -0
  20. data/lib/google/compute/deletable_resource_collection.rb +51 -0
  21. data/lib/google/compute/disk.rb +40 -0
  22. data/lib/google/compute/exception.rb +28 -0
  23. data/lib/google/compute/firewall.rb +65 -0
  24. data/lib/google/compute/global_operation.rb +60 -0
  25. data/lib/google/compute/image.rb +30 -0
  26. data/lib/google/compute/kernel.rb +20 -0
  27. data/lib/google/compute/listable_resource_collection.rb +33 -0
  28. data/lib/google/compute/machine_type.rb +36 -0
  29. data/lib/google/compute/mixins/utils.rb +58 -0
  30. data/lib/google/compute/network.rb +29 -0
  31. data/lib/google/compute/project.rb +76 -0
  32. data/lib/google/compute/resource.rb +81 -0
  33. data/lib/google/compute/resource_collection.rb +78 -0
  34. data/lib/google/compute/server.rb +87 -0
  35. data/lib/google/compute/server/attached_disk.rb +39 -0
  36. data/lib/google/compute/server/network_interface.rb +38 -0
  37. data/lib/google/compute/server/network_interface/access_config.rb +35 -0
  38. data/lib/google/compute/server/serial_port_output.rb +31 -0
  39. data/lib/google/compute/snapshot.rb +30 -0
  40. data/lib/google/compute/version.rb +19 -0
  41. data/lib/google/compute/zone.rb +32 -0
  42. data/lib/google/compute/zone_operation.rb +60 -0
  43. data/lib/knife-google/version.rb +18 -2
  44. data/spec/chef/knife/google_base_spec.rb +46 -0
  45. data/spec/chef/knife/google_disk_create_spec.rb +36 -0
  46. data/spec/chef/knife/google_disk_delete_spec.rb +65 -0
  47. data/spec/chef/knife/google_disk_list_spec.rb +36 -0
  48. data/spec/chef/knife/google_server_create_spec.rb +84 -0
  49. data/spec/chef/knife/google_server_delete_spec.rb +105 -0
  50. data/spec/chef/knife/google_server_list_spec.rb +39 -0
  51. data/spec/chef/knife/google_setup_spec.rb +25 -0
  52. data/spec/chef/knife/google_zone_list_spec.rb +32 -0
  53. data/spec/data/client.json +14 -0
  54. data/spec/data/compute-v1beta14.json +3386 -0
  55. data/spec/data/disk.json +15 -0
  56. data/spec/data/firewall.json +13 -0
  57. data/spec/data/global_operation.json +36 -0
  58. data/spec/data/image.json +12 -0
  59. data/spec/data/kernel.json +15 -0
  60. data/spec/data/machine_type.json +24 -0
  61. data/spec/data/network.json +10 -0
  62. data/spec/data/project.json +21 -0
  63. data/spec/data/serial_port_output.json +5 -0
  64. data/spec/data/server.json +46 -0
  65. data/spec/data/snapshot.json +12 -0
  66. data/spec/data/zone.json +30 -0
  67. data/spec/data/zone_operation.json +36 -0
  68. data/spec/google/compute/disk_spec.rb +105 -0
  69. data/spec/google/compute/firewall_spec.rb +128 -0
  70. data/spec/google/compute/global_operation_spec.rb +62 -0
  71. data/spec/google/compute/image_spec.rb +75 -0
  72. data/spec/google/compute/kernel_spec.rb +49 -0
  73. data/spec/google/compute/machine_type_spec.rb +53 -0
  74. data/spec/google/compute/network_spec.rb +68 -0
  75. data/spec/google/compute/project_spec.rb +71 -0
  76. data/spec/google/compute/server_spec.rb +125 -0
  77. data/spec/google/compute/snapshot_spec.rb +69 -0
  78. data/spec/google/compute/zone_operation_spec.rb +62 -0
  79. data/spec/google/compute/zone_spec.rb +50 -0
  80. data/spec/spec_helper.rb +44 -0
  81. data/spec/support/mocks.rb +62 -0
  82. data/spec/support/resource_examples.rb +70 -0
  83. data/spec/support/spec_google_base.rb +56 -0
  84. metadata +121 -31
  85. data/README.rdoc +0 -96
@@ -0,0 +1,62 @@
1
+ # Copyright 2013 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
+ require 'spec_helper'
15
+
16
+ describe Google::Compute::GlobalOperation do
17
+
18
+ before(:each) do
19
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
20
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
21
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
22
+ end
23
+
24
+ let(:client) do
25
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
26
+ end
27
+
28
+ it_should_behave_like Google::Compute::Resource
29
+
30
+ it "#list should return an array of global operations" do
31
+ @mock_api_client.should_receive(:execute).
32
+ with(:api_method=>mock_compute.global_operations.list,
33
+ :parameters=>{ :project=>"mock-project"},:body_object=>nil).
34
+ and_return(mock_response(Google::Compute::GlobalOperation, true))
35
+
36
+ operations = client.globalOperations.list
37
+ operations.should_not be_empty
38
+ operations.all?{|o| o.is_a?(Google::Compute::GlobalOperation)}.should be_true
39
+ end
40
+
41
+ it "#get should return an individual global operation" do
42
+ @mock_api_client.should_receive(:execute).
43
+ with(:api_method=>mock_compute.global_operations.get,
44
+ :parameters=>{"globalOperation"=>"mock-global-operation", :project=>"mock-project"},:body_object=>nil).
45
+ and_return(mock_response(Google::Compute::GlobalOperation))
46
+
47
+ operation = client.globalOperations.get('mock-global-operation')
48
+ operation.should be_a_kind_of Google::Compute::GlobalOperation
49
+ operation.name.should eq('mock-global-operation')
50
+ operation.should respond_to(:progress)
51
+ operation.start_time.should be_a_kind_of(Time)
52
+ end
53
+
54
+ it "#delete should delete an existing global operation" do
55
+ @mock_api_client.should_receive(:execute).
56
+ with(:api_method=>mock_compute.global_operations.delete,
57
+ :parameters=>{"globalOperation"=>"mock-global-operation", :project=>"mock-project"},:body_object=>nil).
58
+ and_return(mock_response)
59
+
60
+ client.globalOperations.delete('mock-global-operation')
61
+ end
62
+ end
@@ -0,0 +1,75 @@
1
+ # Copyright 2013 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
+ require 'spec_helper'
15
+
16
+ describe Google::Compute::Image do
17
+
18
+ before(:each) do
19
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
20
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
21
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
22
+ end
23
+
24
+ let(:client) do
25
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
26
+ end
27
+
28
+ it_should_behave_like Google::Compute::Resource
29
+
30
+ it "#get should return an individual image" do
31
+ @mock_api_client.should_receive(:execute).
32
+ with(:api_method=>mock_compute.images.get,
33
+ :parameters=>{"image"=>"mock-image", :project=>"mock-project"},:body_object=>nil).
34
+ and_return(mock_response(Google::Compute::Image))
35
+ image = client.images.get('mock-image')
36
+ image.should be_a_kind_of Google::Compute::Image
37
+ image.name.should eq('mock-image')
38
+ image.raw_disk.should have_key("source")
39
+ image.raw_disk.should have_key("containerType")
40
+ end
41
+
42
+ it "#list should return an array of images" do
43
+ @mock_api_client.should_receive(:execute).
44
+ with(:api_method=>mock_compute.images.list,
45
+ :parameters=>{ :project=>"mock-project"},:body_object=>nil).
46
+ and_return(mock_response(Google::Compute::Image, true))
47
+ images = client.images.list
48
+ images.should_not be_empty
49
+ images.all?{|i| i.is_a?(Google::Compute::Image)}.should be_true
50
+ end
51
+ it "#create should create a new image" do
52
+ storage = 'https://www.googleapis.com/storage/projects/mock-project/bucket/object'
53
+ @mock_api_client.should_receive(:execute).
54
+ with(:api_method=>mock_compute.images.insert,
55
+ :parameters=>{ :project=>"mock-project"},
56
+ :body_object=>{:name=>"mock-image",
57
+ :rawDisk=>{'containerType'=>'TAR','source'=>storage},
58
+ :sourceType=>'RAW'}).
59
+ and_return(mock_response(Google::Compute::GlobalOperation))
60
+ o = client.images.create(:name=>'mock-image',
61
+ :rawDisk=>{'containerType'=>'TAR','source'=>storage},
62
+ :sourceType=>'RAW')
63
+
64
+ o.should be_a_kind_of Google::Compute::GlobalOperation
65
+ end
66
+
67
+ it "#delete should delete an existing image" do
68
+ @mock_api_client.should_receive(:execute).
69
+ with(:api_method=>mock_compute.images.delete,
70
+ :parameters=>{ :project=>"mock-project",'image'=>'mock-image'},:body_object =>nil).
71
+ and_return(mock_response(Google::Compute::GlobalOperation))
72
+ o = client.images.delete('mock-image')
73
+ o.should be_a_kind_of Google::Compute::GlobalOperation
74
+ end
75
+ end
@@ -0,0 +1,49 @@
1
+ # Copyright 2013 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
+ require 'spec_helper'
15
+
16
+ describe Google::Compute::Kernel do
17
+
18
+ before(:each) do
19
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
20
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
21
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
22
+ end
23
+
24
+ let(:client) do
25
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
26
+ end
27
+
28
+ it_should_behave_like Google::Compute::Resource
29
+
30
+ it "#get should return an individual kernel" do
31
+ @mock_api_client.should_receive(:execute).
32
+ with(:api_method=>mock_compute.kernels.get,
33
+ :parameters=>{"kernel"=>"mock-kernel", :project=>"mock-project"},:body_object=>nil).
34
+ and_return(mock_response(Google::Compute::Kernel))
35
+
36
+ kernel = client.kernels.get('mock-kernel')
37
+ kernel.should be_a_kind_of Google::Compute::Kernel
38
+ kernel.name.should eq('mock-kernel')
39
+ end
40
+
41
+ it "#list should return an array of kernels" do
42
+ @mock_api_client.should_receive(:execute).
43
+ with(:api_method=>mock_compute.kernels.list,
44
+ :parameters=>{ :project=>"mock-project"},:body_object=>nil).
45
+ and_return(mock_response(Google::Compute::Kernel, true))
46
+ kernels = client.kernels.list
47
+ kernels.all?{|kernel| kernel.is_a?(Google::Compute::Kernel)}.should be_true
48
+ end
49
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright 2013 Google Inc. All Rights Reserved.
2
+ #
3
+ # Copyright 2013 Google Inc.
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
+ require 'spec_helper'
17
+
18
+ describe Google::Compute::MachineType do
19
+
20
+ before(:each) do
21
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
22
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
23
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
24
+ end
25
+
26
+ let(:client) do
27
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
28
+ end
29
+
30
+ it_should_behave_like Google::Compute::Resource
31
+
32
+ it "#get should return an individual machine types" do
33
+
34
+ @mock_api_client.should_receive(:execute).
35
+ with(:api_method=>mock_compute.machine_types.get,
36
+ :parameters=>{"machineType"=>"mock-machine-type", :project=>"mock-project"},:body_object=>nil).
37
+ and_return(mock_response(Google::Compute::MachineType))
38
+
39
+ machine_type = client.machine_types.get('mock-machine-type')
40
+ machine_type.should be_a_kind_of Google::Compute::MachineType
41
+ machine_type.name.should eq('mock-machine-type')
42
+ machine_type.guest_cpus.should be_a_kind_of(Fixnum)
43
+ end
44
+ it "#list should return an array of machine types" do
45
+ @mock_api_client.should_receive(:execute).
46
+ with(:api_method=>mock_compute.machine_types.list,
47
+ :parameters=>{ :project=>"mock-project"},:body_object=>nil).
48
+ and_return(mock_response(Google::Compute::MachineType, true))
49
+ mts = client.machine_types.list
50
+ mts.should_not be_empty
51
+ mts.all?{|mt| mt.is_a?(Google::Compute::MachineType)}.should be_true
52
+ end
53
+ end
@@ -0,0 +1,68 @@
1
+ # Copyright 2013 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
+ require 'spec_helper'
15
+
16
+ describe Google::Compute::Network do
17
+
18
+ before(:each) do
19
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
20
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
21
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
22
+ end
23
+
24
+ let(:client) do
25
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
26
+ end
27
+
28
+ it_should_behave_like Google::Compute::Resource
29
+
30
+ it "#get should return an individual network" do
31
+ @mock_api_client.should_receive(:execute).
32
+ with(:api_method=>mock_compute.networks.get,
33
+ :parameters=>{"network"=>"mock-network", :project=>"mock-project"},:body_object=>nil).
34
+ and_return(mock_response(Google::Compute::Network))
35
+ network = client.networks.get('mock-network')
36
+ network.should be_a_kind_of Google::Compute::Network
37
+ network.name.should eq('mock-network')
38
+ network.should respond_to(:ip_v4_range)
39
+ end
40
+
41
+ it "#list should return an array of networks" do
42
+ @mock_api_client.should_receive(:execute).
43
+ with(:api_method=>mock_compute.networks.list,
44
+ :parameters=>{ :project=>"mock-project"},:body_object=>nil).
45
+ and_return(mock_response(Google::Compute::Network, true))
46
+ networks = client.networks.list
47
+ networks.should_not be_empty
48
+ networks.all?{|n| n.is_a?(Google::Compute::Network)}.should be_true
49
+ end
50
+
51
+ it "#create should create a new network" do
52
+ @mock_api_client.should_receive(:execute).
53
+ with(:api_method=>mock_compute.networks.insert,
54
+ :parameters=>{ :project=>"mock-project"},
55
+ :body_object=>{:name=>"mock-network", :IPv4Range=>"122.12.0.0/16"}).
56
+ and_return(mock_response(Google::Compute::GlobalOperation))
57
+ o = client.networks.create(:name=>'mock-network', :IPv4Range=>'122.12.0.0/16')
58
+ o.should be_a_kind_of Google::Compute::GlobalOperation
59
+ end
60
+
61
+ it "#delete should delete an existing network" do
62
+ @mock_api_client.should_receive(:execute).
63
+ with(:api_method=>mock_compute.networks.delete,
64
+ :parameters=>{"network"=>"mock-network", :project=>"mock-project"},:body_object=>nil).
65
+ and_return(mock_response(Google::Compute::GlobalOperation))
66
+ client.networks.delete('mock-network')
67
+ end
68
+ end
@@ -0,0 +1,71 @@
1
+ # Copyright 2013 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
+ require 'spec_helper'
15
+
16
+ describe Google::Compute::Project do
17
+
18
+ before(:each) do
19
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
20
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
21
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
22
+ end
23
+
24
+ let(:client) do
25
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
26
+ end
27
+
28
+ it_should_behave_like Google::Compute::Resource
29
+
30
+ it "#get should return an individual project" do
31
+ @mock_api_client.should_receive(:execute).
32
+ with(:api_method=>mock_compute.projects.get,
33
+ :parameters=>{:project=>"mock-project","project"=>'mock-project'},:body_object=>nil).
34
+ and_return(mock_response(Google::Compute::Project))
35
+ project = client.projects.get('mock-project')
36
+ project.should be_a_kind_of Google::Compute::Project
37
+ end
38
+
39
+ describe "#setCommonInstanceMetadata"
40
+
41
+ before(:each) do
42
+ Google::Compute::Resource.any_instance.stub(:update!)
43
+ end
44
+
45
+ let(:project) do
46
+ Google::Compute::Project.new(mock_hash(Google::Compute::Project).
47
+ merge(:dispatcher=>client.dispatcher))
48
+ end
49
+
50
+ it "should be able to add common instance metadata" do
51
+ @mock_api_client.should_receive(:execute).
52
+ with(:api_method=>mock_compute.projects.set_common_instance_metadata,
53
+ :parameters=>{:project=>"mock-project"},
54
+ :body_object=>{"kind"=>"compute#metadata",
55
+ "items"=>[{"key"=>"mock-key", "value"=>"mock-value"},
56
+ {"key"=>"testKey", "value"=>"testValue"}]}).
57
+ and_return(mock_response)
58
+ project.add_common_instance_metadata!("testKey"=>"testValue")
59
+ end
60
+
61
+ it "should be able to remove common instance metadata" do
62
+ @mock_api_client.should_receive(:execute).
63
+ with(:api_method=>mock_compute.projects.set_common_instance_metadata,
64
+ :parameters=>{:project=>"mock-project"},
65
+ :body_object=>{"kind"=>"compute#metadata",
66
+ "items"=>[]}).
67
+ and_return(mock_response)
68
+ project.remove_common_instance_metadata!("mock-key"=>"mock-value")
69
+ end
70
+ end
71
+
@@ -0,0 +1,125 @@
1
+ # Copyright 2013 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
+ require 'spec_helper'
15
+
16
+ describe Google::Compute::Server do
17
+
18
+ before(:each) do
19
+ @mock_api_client=mock(Google::APIClient, :authorization= =>{}, :auto_refresh_token= =>{})
20
+ @mock_api_client.stub!(:discovered_api).and_return(mock_compute)
21
+ Google::APIClient.stub!(:new).and_return(@mock_api_client)
22
+ end
23
+
24
+ let(:client) do
25
+ Google::Compute::Client.from_json(mock_data_file(Google::Compute::Client))
26
+ end
27
+
28
+ it_should_behave_like Google::Compute::Resource
29
+
30
+ it "#get should return an individual Server" do
31
+ @mock_api_client.should_receive(:execute).
32
+ with(:api_method=>mock_compute.instances.get,
33
+ :parameters=>{:instance=>"mock-instance", :project=>"mock-project", :zone=>"mock-zone"},:body_object=>nil).
34
+ and_return(mock_response(Google::Compute::Server))
35
+ instance = client.instances.get(:name=>'mock-instance', :zone=>"mock-zone")
36
+ instance.should be_a_kind_of Google::Compute::Server
37
+ instance.name.should eq('mock-instance')
38
+ instance.disks.should be_a_kind_of(Array)
39
+ instance.network_interfaces.should be_a_kind_of(Array)
40
+ end
41
+
42
+ it "#list should return an array of Servers" do
43
+ @mock_api_client.should_receive(:execute).
44
+ with(:api_method=>mock_compute.instances.list,
45
+ :parameters=>{:project=>"mock-project", :zone=>"mock-zone"},:body_object=>nil).
46
+ and_return(mock_response(Google::Compute::Server,true))
47
+ instances = client.instances.list(:zone=>"mock-zone")
48
+ instances.should_not be_empty
49
+ instances.all?{|i| i.is_a?(Google::Compute::Server)}.should be_true
50
+ end
51
+
52
+ it "#create should create an server" do
53
+ project_url ='https://www.googleapis.com/compute/v1beta14/projects/google.com:wf-test'
54
+ zone = project_url + '/zones/europe-west1-a'
55
+ disk = project_url + zone + '/disks/temp-disk'
56
+ machine_type = project_url + '/global/machineTypes/n1-highcpu-2'
57
+ image = 'https://www.googleapis.com/compute/v1beta14/projects/google/global/images/centos-6-2-v20120326'
58
+ network = project_url + '/global/networks/api-network'
59
+ access_config = {"name" => "External NAT", "type" => "ONE_TO_ONE_NAT"}
60
+
61
+ @mock_api_client.should_receive(:execute).
62
+ with(:api_method=>mock_compute.instances.insert,
63
+ :parameters=>{:project=>"mock-project", :zone=>"mock-zone"},
64
+ :body_object=>{:name =>'mock-instance',
65
+ :image => image,
66
+ :zone => "mock-zone",
67
+ :disks => [disk],
68
+ :machineType => machine_type,
69
+ :metadata =>{'items'=>[{'key'=>'someKey','value'=>'someValue'}]},
70
+ :networkInterfaces => [{'network'=>network,
71
+ 'accessConfigs' => [access_config]
72
+ }]
73
+ }).
74
+ and_return(mock_response(Google::Compute::ZoneOperation))
75
+
76
+ o = client.instances.create(:name=>'mock-instance',
77
+ :image=> image,
78
+ :machineType =>machine_type,
79
+ :disks=>[disk],
80
+ :metadata=>{'items'=>[{'key'=>'someKey','value'=>'someValue'}]},
81
+ :zone=>"mock-zone",
82
+ :networkInterfaces => [{'network'=>network,
83
+ 'accessConfigs' => [access_config]
84
+ }]
85
+ )
86
+ end
87
+
88
+ it "#delete should delete an server" do
89
+ @mock_api_client.should_receive(:execute).
90
+ with(:api_method=>mock_compute.instances.delete,
91
+ :parameters=>{:project=>"mock-project", :instance=>'mock-instance', :zone=>"mock-zone"},
92
+ :body_object=>nil).
93
+ and_return(mock_response(Google::Compute::ZoneOperation))
94
+ o = client.instances.delete(:instance=>'mock-instance', :zone=>"mock-zone")
95
+ end
96
+
97
+ describe "with a specific server" do
98
+
99
+ before(:each) do
100
+ Google::Compute::Resource.any_instance.stub(:update!)
101
+ end
102
+
103
+ let(:instance) do
104
+ Google::Compute::Server.new(mock_hash(Google::Compute::Server).
105
+ merge(:dispatcher=>client.dispatcher))
106
+ end
107
+
108
+ it "#addAccessConfig should add access config to an existing server" do
109
+ end
110
+
111
+ it "#deleteAccessConfig should delete access config to an existing server" do
112
+ end
113
+
114
+ it "#serialPort should return serial port output of an existing server" do
115
+ zone = "https://www.googleapis.com/compute/v1beta14/projects/mock-project/zones/mock-zone"
116
+ @mock_api_client.should_receive(:execute).
117
+ with(:api_method=>mock_compute.instances.get_serial_port_output,
118
+ :parameters=>{:project=>"mock-project",:instance=>'mock-instance', :zone=>zone},
119
+ :body_object=>nil).
120
+ and_return(mock_response(Google::Compute::SerialPortOutput))
121
+ instance.serial_port_output.should be_a_kind_of(Google::Compute::SerialPortOutput)
122
+ instance.serial_port_output.contents.should_not be_empty
123
+ end
124
+ end
125
+ end