knife-rightscale 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module RightApiProvision
20
+ VERSION = "0.1.0"
21
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.expand_path('../../../spec_helper', __FILE__)
20
+
21
+ describe Chef::Knife::RightscaleServerCreate do
22
+ before do
23
+
24
+ end
25
+
26
+ pending "run" do
27
+ it "create and launch server" do
28
+ puts "some statement here about good intentions"
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,203 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "right_api_provision/api15"
20
+
21
+ describe "API15 object" do
22
+
23
+ before(:each) do
24
+ @api = RightApiProvision::API15.new()
25
+ apiStub = double("RightApi::Client")
26
+ RightApi::Client.should_receive(:new).and_return(apiStub)
27
+ @conn = @api.connection("someemail", "somepasswd", "someaccountid", "https://my.rightscale.com")
28
+ end
29
+
30
+ describe "requires_ssh_keys?" do
31
+ it "should return true when cloud supports ssh keys" do
32
+ sshKeyStub = stub("sshkeys", :index => ["key1", "key2"])
33
+
34
+ cStub = stub("cloud", :ssh_keys => sshKeyStub)
35
+ csStub = stub("clouds", :show => cStub)
36
+
37
+ @api.requires_ssh_keys?(csStub).should == true
38
+ end
39
+
40
+ it "should return false when cloud doesn't support ssh keys" do
41
+ cStub = stub("cloud", :ssh_keys => "will throw exception if no ssh keys")
42
+ cStub.should_receive(:ssh_keys).and_raise(RightApi::Exceptions::ApiException.new "error")
43
+ csStub = stub("clouds", :show => cStub)
44
+
45
+ @api.requires_ssh_keys?(csStub).should == false
46
+ end
47
+ end
48
+
49
+ describe "find_ssh_key_by_uuid_or_first" do
50
+ it "should find first ssh_key" do
51
+ sshKeyStub = stub("sshkeys", :index => ["key1", "key2"])
52
+
53
+ cStub = stub("cloud", :ssh_keys => sshKeyStub)
54
+ csStub = stub("clouds", :show => cStub)
55
+
56
+ @api.find_ssh_key_by_uuid_or_first(csStub).should == "key1"
57
+ end
58
+ end
59
+
60
+ it "should find deployment by name" do
61
+ deploymentsStub = stub("deployments", :index => [ :name => "my_fake_deployment" ])
62
+ @api.instance_variable_get("@connection").should_receive(:deployments).and_return(deploymentsStub)
63
+ @api.find_deployment_by_name("my_fake_deployment")
64
+ end
65
+
66
+ it "should raise error if deployment not found by name" do
67
+ deploymentsStub = stub("deployments", :index => nil)
68
+ @api.instance_variable_get("@connection").should_receive(:deployments).and_return(deploymentsStub)
69
+ lambda{@api.find_deployment_by_name("my_fake_deployment")}.should raise_error
70
+ end
71
+
72
+ it "should raise error if multiple deployments found by name" do
73
+ deploymentsStub = stub("deployments", :index => [ {:name => "my_fake_deployment"}, {:name => "my_fake_deployment2"} ])
74
+ @api.instance_variable_get("@connection").should_receive(:deployments).and_return(deploymentsStub)
75
+ lambda{@api.find_deployment_by_name("my_fake_deployment")}.should raise_error
76
+ end
77
+
78
+ it "should find server by name" do
79
+ serversStub = stub("servers", :index => [ :name => "my_fake_server" ])
80
+ @api.instance_variable_get("@connection").should_receive(:servers).and_return(serversStub)
81
+ @api.find_server_by_name("my_fake_server")
82
+ end
83
+
84
+ it "should raise error if multiple servers found by name" do
85
+ serversStub = stub("servers", :index => [ {:name => "my_fake_server"}, {:name => "my_fake_server2"} ])
86
+ @api.instance_variable_get("@connection").should_receive(:servers).and_return(serversStub)
87
+ lambda{@api.find_server_by_name("my_fake_server")}.should raise_error
88
+ end
89
+
90
+ it "should find MCI by name" do
91
+ pending ("TODO: add support for multi_cloud_image_name")
92
+ mcisStub = stub("mcis", :index => [ :name => "my_fake_mci" ])
93
+ @api.instance_variable_get("@connection").should_receive(:mcis).and_return(mcisStub)
94
+ @api.find_mci_by_name("my_fake_mci")
95
+ end
96
+
97
+ it "should raise error if multiple MCI found by name" do
98
+ pending ("TODO: add support for multi_cloud_image_name")
99
+ mcisStub = stub("mcis", :index => [ {:name => "my_fake_mci"}, {:name => "my_fake_mci2"} ])
100
+ @api.instance_variable_get("@connection").should_receive(:mcis).and_return(mcisStub)
101
+ lambda{@api.find_mci_by_name("my_fake_mci")}.should raise_error
102
+ end
103
+
104
+ it "should find servertemplate by name" do
105
+ servertemplatesStub = stub("servertemplates", :index => [ stub("servertemplate", :name => "my_fake_servertemplate", :revision => true) ])
106
+ @api.instance_variable_get("@connection").should_receive(:server_templates).and_return(servertemplatesStub)
107
+ @api.find_servertemplate("my_fake_servertemplate")
108
+ end
109
+
110
+ it "should raise error if multiple servertemplates found by name" do
111
+ servertemplatesStub = stub("servertemplates", :index => [ stub("servertemplate", :name => "my_fake_servertemplate"), stub("servertemplate", :name => "my_fake_servertemplate") ])
112
+ @api.instance_variable_get("@connection").should_receive(:server_templates).and_return(servertemplatesStub)
113
+ lambda{@api.find_servertemplate("my_fake_servertemplate")}.should raise_error
114
+ end
115
+
116
+ it "should find servertemplate by id" do
117
+ servertemplatesStub = stub("servertemplates", :index => [ :name => "my_fake_servertemplate" ])
118
+ @api.instance_variable_get("@connection").should_receive(:server_templates).and_return(servertemplatesStub)
119
+ @api.find_servertemplate(1234)
120
+ end
121
+
122
+ it "should create deployment" do
123
+ deploymentsStub = stub("deployments", :create => [ {:name => "my_fake_deployment"} ])
124
+ @api.instance_variable_get("@connection").should_receive(:deployments).and_return(deploymentsStub)
125
+ deploymentsStub.should_receive(:create)
126
+ @api.create_deployment("my_deployment")
127
+ end
128
+
129
+ it "should create server" do
130
+ dStub = stub("deployment", :href => "/some/fake/path")
131
+ dsStub = stub("deployments", :show => dStub)
132
+ @api.should_receive(:create_deployment).and_return(dsStub)
133
+ deployment = @api.create_deployment("my_deployment")
134
+
135
+ stStub = stub("servertemplate", :href => "/some/fake/path", :show => "")
136
+ stsStub = stub("servertemplates", :show => stStub)
137
+ @api.should_receive(:find_servertemplate).and_return(stsStub)
138
+ server_template = @api.find_servertemplate(1234)
139
+
140
+ cStub = stub("cloud", :href => "/some/fake/path")
141
+ csStub = stub("clouds", :show => cStub)
142
+ @api.should_receive(:find_cloud_by_name).and_return(csStub)
143
+ cloud = @api.find_cloud_by_name(1234)
144
+
145
+ serversStub = stub("servers", :create => [ :name => "my_fake_server" ])
146
+ @api.instance_variable_get("@connection").should_receive(:servers).and_return(serversStub)
147
+ @api.create_server(deployment, server_template, nil, cloud, "my_fake_server", nil)
148
+ end
149
+
150
+ it "should launch server with inputs" do
151
+ serverStub = stub("server", :name => "foo")
152
+ serversStub = stub("servers", :launch => true, :show => serverStub, :index => [ :name => "my_fake_server" ])
153
+ @api.should_receive(:create_server).and_return(serversStub)
154
+ server = @api.create_server("foo", "bar", "my_fake_server")
155
+ @api.instance_variable_get("@connection").should_receive(:servers).and_return(serversStub)
156
+ @api.launch_server(server, [ {:name => "input1", :value => 1} ])
157
+ end
158
+
159
+ it "should launch server without inputs" do
160
+ serverStub = stub("server", :name => "foo")
161
+ serversStub = stub("servers", :launch => true, :show => serverStub, :index => [ :name => "my_fake_server" ])
162
+ @api.should_receive(:create_server).and_return(serversStub)
163
+ server = @api.create_server("foo", "bar", "my_fake_server")
164
+ @api.instance_variable_get("@connection").should_receive(:servers).and_return(serversStub)
165
+ @api.launch_server(server)
166
+ end
167
+
168
+ it "returns data_request_url for instance" do
169
+ @user_data = "RS_rn_url=amqp://b915586461:278a854748@orange2-broker.test.rightscale.com/right_net&RS_rn_id=4985249009&RS_server=orange2-moo.test.rightscale.com&RS_rn_auth=d98106775832c174ffd55bd7b7cb175077574adf&RS_token=b233a57d1d24f27bd8650d0f9b6bfd54&RS_sketchy=sketchy1-145.rightscale.com&RS_rn_host=:0"
170
+ @request_data_url = "https://my.rightscale.com/servers/data_injection_payload/d98106775832c174ffd55bd7b7cb175077574adf"
171
+
172
+ @api.data_request_url(@user_data).should == @request_data_url
173
+ end
174
+
175
+ pending "waits for state to change from booting state" do
176
+ currentStub = stub("instance", :state => "booting")
177
+ instanceStub = stub("instance", :show => currentStub)
178
+ serverStub = stub("server", :api_methods => [:current_instance], :current_instance => instanceStub)
179
+ serversStub = stub("servers", :launch => true, :show => serverStub, :index => [ :name => "my_fake_server" ])
180
+
181
+ @api.server_wait_for_state(@server, "booting", 1)
182
+ end
183
+
184
+ it "fails if the server's cloud is not the requested cloud" do
185
+ pending "TODO"
186
+ end
187
+
188
+ it "sets inputs on the next instance" do
189
+ pending "TODO"
190
+ end
191
+
192
+ it "terminates a server" do
193
+ pending "TODO"
194
+ serverStub = stub("server", :name => "foo")
195
+ # serversStub = stub("servers", :launch => true, :show => serverStub, :index => [ :name => "my_fake_server" ])
196
+ # @api.should_receive(:create_server).and_return(serversStub)
197
+ # server = @api.create_server("foo", "bar", "my_fake_server")
198
+ # @api.instance_variable_get("@connection").should_receive(:servers).and_return(serversStub)
199
+ @api.terminate_server(serverStub)
200
+ end
201
+
202
+
203
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ $:.unshift File.expand_path('../../lib', __FILE__)
19
+ require 'chef'
20
+ require 'knife-rightscale'
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ def run(knife_command)
20
+ cmd = "bundle exec #{knife_command} --yes"
21
+ puts "Command: #{cmd}"
22
+ puts `#{cmd}`
23
+ raise "ERROR: #{cmd} failed" unless $? == 0
24
+ end
25
+
26
+ describe "provision a ChefClient on each cloud" do
27
+
28
+ [
29
+ "EC2 us-west-2",
30
+ "CS 2.2.14 Eng - XenServer",
31
+ "Google",
32
+ "HP Cloud",
33
+ "Rackspace Open Cloud - Chicago"
34
+ ].each do |cloud_name|
35
+
36
+ it "can provision on '#{cloud_name}'" do
37
+ begin
38
+ run "knife rightscale server create --cloud '#{cloud_name}' " +
39
+ "--server-template 291069003 --deployment 'KNIFE: test knife-provisioner' " +
40
+ "--name 'KNIFE:ChefClient #{cloud_name}' " +
41
+ "--input 'chef/client/server_url':'text:https://api.opscode.com/organizations/kindsol' " +
42
+ "--input 'chef/client/validation_name':'cred:CKP: validation_client_name' " +
43
+ "--input 'chef/client/validator_pem':'cred:CKP:validator.pem' " +
44
+ "--input 'chef/client/node_name':'text:MyChefClient' " +
45
+ "--input 'chef/client/roles':'text:hello_world'"
46
+ ensure
47
+ begin
48
+ run "knife rightscale server delete 'KNIFE:ChefClient #{cloud_name}'"
49
+ ensure
50
+ run "knife client delete MyChefClient"
51
+ run "knife node delete MyChefClient"
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ def run_list_command(resource_name, options = "")
20
+ cmd = "bundle exec knife rightscale #{resource_name} list #{options}"
21
+ puts `#{cmd}`
22
+ raise "ERROR: #{cmd} failed" unless $? == 0
23
+ end
24
+
25
+ describe "run list actions" do
26
+
27
+ it "lists security groups" do
28
+ run_list_command("securitygroup")
29
+ end
30
+
31
+ it "lists clouds" do
32
+ run_list_command("cloud")
33
+ end
34
+
35
+ it "lists deployments" do
36
+ run_list_command("deployment")
37
+ end
38
+
39
+ it "lists servers" do
40
+ run_list_command("server")
41
+ end
42
+
43
+ it "lists servertemplate" do
44
+ run_list_command("servertemplate")
45
+ end
46
+
47
+ it "lists images" do
48
+ run_list_command("image", "-s 292810003 --cloud 'EC2 us-west-2'")
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-rightscale
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Cary Penniman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: One plugin to provision them all! This plugin allows the Chef developer
14
+ to provision Chef clients on all major clouds using the RightScale platform.
15
+ email:
16
+ - cary@rightscale.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - knife-rightscale.gemspec
28
+ - lib/chef/knife/rightscale_base.rb
29
+ - lib/chef/knife/rightscale_cloud_list.rb
30
+ - lib/chef/knife/rightscale_deployment_list.rb
31
+ - lib/chef/knife/rightscale_image_list.rb
32
+ - lib/chef/knife/rightscale_securitygroup_list.rb
33
+ - lib/chef/knife/rightscale_server_create.rb
34
+ - lib/chef/knife/rightscale_server_delete.rb
35
+ - lib/chef/knife/rightscale_server_list.rb
36
+ - lib/chef/knife/rightscale_servertemplate_list.rb
37
+ - lib/knife-rightscale.rb
38
+ - lib/knife-rightscale/version.rb
39
+ - lib/right_api_provision.rb
40
+ - lib/right_api_provision/api15.rb
41
+ - lib/right_api_provision/exception.rb
42
+ - lib/right_api_provision/provisioner.rb
43
+ - lib/right_api_provision/version.rb
44
+ - spec/chef/knife/rightscale_server_create_spec.rb
45
+ - spec/right_api_provision/api15_spec.rb
46
+ - spec/spec_helper.rb
47
+ - test/create_server_test.rb
48
+ - test/list_actions_test.rb
49
+ homepage: http://github.com/caryp/knife-rightscale
50
+ licenses: []
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.0.3
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: RightScale plugin for Knife
72
+ test_files:
73
+ - spec/chef/knife/rightscale_server_create_spec.rb
74
+ - spec/right_api_provision/api15_spec.rb
75
+ - spec/spec_helper.rb
76
+ - test/create_server_test.rb
77
+ - test/list_actions_test.rb
78
+ has_rdoc: