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,181 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # Copyright:: Copyright (c) 2013 RightScale, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # This file is modified from the knife-ec2 plugin project code
7
+ # That project is located at https://github.com/opscode/knife-ec2
8
+ # Author:: Adam Jacob (<adam@opscode.com>)
9
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
10
+ # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
11
+ # License:: Apache License, Version 2.0
12
+ #
13
+ # Licensed under the Apache License, Version 2.0 (the "License");
14
+ # you may not use this file except in compliance with the License.
15
+ # You may obtain a copy of the License at
16
+ #
17
+ # http://www.apache.org/licenses/LICENSE-2.0
18
+ #
19
+ # Unless required by applicable law or agreed to in writing, software
20
+ # distributed under the License is distributed on an "AS IS" BASIS,
21
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ # See the License for the specific language governing permissions and
23
+ # limitations under the License.
24
+ #
25
+
26
+ require 'chef/knife/rightscale_base'
27
+
28
+ class Chef
29
+ class Knife
30
+ class RightscaleServerCreate < Knife
31
+
32
+ include Knife::RightscaleBase
33
+
34
+ deps do
35
+ require 'right_api_client'
36
+ end
37
+
38
+ banner "knife rightscale server create (options)"
39
+
40
+ @@inputs = { }
41
+
42
+ option :cloud_name,
43
+ :short => "-c CLOUD",
44
+ :long => "--cloud CLOUD",
45
+ :description => "What cloud to create the server for (ec2, rackspace, gce, azure, cloudstack, openstack, etc.)",
46
+ :proc => Proc.new { |f| Chef::Config[:knife][:cloud_name] = f },
47
+ :default => "ec2"
48
+
49
+ option :server_template,
50
+ :short => "-s NAME",
51
+ :long => "--server-template NAME",
52
+ :description => "The name of the ServerTemplate or ID to use for the server",
53
+ :proc => Proc.new { |i| Chef::Config[:knife][:server_template] = i },
54
+ :required => true
55
+
56
+ option :server_name,
57
+ :short => "-n SERVERNAME",
58
+ :long => "--name SERVERNAME",
59
+ :description => "The name for the server to create",
60
+ :proc => Proc.new { |i| Chef::Config[:knife][:server_name] = i },
61
+ :default => "knife_provisioned"
62
+
63
+ option :deployment_name,
64
+ :short => "-d NAME",
65
+ :long => "--deployment NAME",
66
+ :description => "The name of the deployment to place the server in",
67
+ :proc => Proc.new { |i| Chef::Config[:knife][:deployment_name] = i },
68
+ :default => "default"
69
+
70
+ option :server_inputs,
71
+ :short => "-j JSON",
72
+ :long => "--json-inputs JSON",
73
+ :description => "A JSON string of server input values",
74
+ :proc => lambda { |o| JSON.parse(o) }
75
+
76
+ option :input,
77
+ :short => "-i NAME:VALUE",
78
+ :long => "--input NAME:VALUE",
79
+ :description => "An input name and value",
80
+ :proc => lambda { |o| k,v=o.split(":",2); @@inputs[k]=v }
81
+
82
+ option :ssh_key_name,
83
+ :short => "-S KEY_UUID",
84
+ :long => "--ssh-key KEY_UUID",
85
+ :description => "The AWS SSH key resource UUIS",
86
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_key_uuid] = key }
87
+
88
+ # Gets applied to chef/client/roles input of ServerTemplate, if it exists
89
+ # option :run_list,
90
+ # :short => "-r RUN_LIST",
91
+ # :long => "--run-list RUN_LIST",
92
+ # :description => "Comma separated list of roles/recipes to apply.",
93
+ # :proc => lambda { |o| o.split(/[\s,]+/) }
94
+ #
95
+ # option :json_attributes,
96
+ # :short => "-j JSON",
97
+ # :long => "--json-attributes JSON",
98
+ # :description => "A JSON string to be added to the first run of chef-client",
99
+ # :proc => lambda { |o| JSON.parse(o) }
100
+ #
101
+ # option :bootstrap_version,
102
+ # :long => "--bootstrap-version VERSION",
103
+ # :description => "The version of Chef to install",
104
+ # :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
105
+ #
106
+ # option :chef_node_name,
107
+ # :short => "-N NAME",
108
+ # :long => "--node-name NAME",
109
+ # :description => "The Chef node name for your new node",
110
+ # :proc => Proc.new { |key| Chef::Config[:knife][:chef_node_name] = key }
111
+ #
112
+ # option :flavor,
113
+ # :short => "-f FLAVOR",
114
+ # :long => "--flavor FLAVOR",
115
+ # :description => "The flavor of server (m1.small, m1.medium, etc)",
116
+ # :proc => Proc.new { |f| Chef::Config[:knife][:flavor] = f }
117
+ #
118
+ # option :image,
119
+ # :short => "-I IMAGE",
120
+ # :long => "--image IMAGE",
121
+ # :description => "The AMI for the server",
122
+ # :proc => Proc.new { |i| Chef::Config[:knife][:image] = i }
123
+ #
124
+ option :security_groups,
125
+ :short => "-G X,Y,Z",
126
+ :long => "--groups X,Y,Z",
127
+ :description => "The security groups for this server; not allowed when using VPC",
128
+ :proc => Proc.new { |groups| groups.split(',') }
129
+
130
+ def run
131
+ $stdout.sync = true
132
+
133
+ validate!
134
+
135
+ # create and launch server
136
+ print "#{ui.color("Provisioning server with RightScale.", :green)}"
137
+ print "\n#{ui.color("ServerTemplate:", :magenta)} #{config[:server_template]}"
138
+ print "\n#{ui.color("Server name:", :magenta)} #{config[:server_name]}"
139
+ print "\n#{ui.color("Cloud:", :magenta)} #{config[:cloud_name]}"
140
+ print "\n#{ui.color("Deployment name:", :magenta)} #{config[:deployment_name]}"
141
+ print "\n#{ui.color("Inputs:", :magenta)} #{@@inputs}"
142
+ print "\n"
143
+
144
+ rightscale = ::RightApiProvision::Provisioner.new(connection)
145
+ rightscale.provision(
146
+ config[:server_template],
147
+ config[:server_name],
148
+ config[:cloud_name],
149
+ config[:deployment_name],
150
+ @@inputs,
151
+ config[:ssh_key_name],
152
+ config[:security_groups]
153
+ )
154
+
155
+ if rightscale.server_ready?
156
+ print "#{ui.color("Server already running", :green)}"
157
+ else
158
+ print "\n#{ui.color("Waiting for RightScale to configure server\n", :yellow)}"
159
+ rightscale.wait_for_operational
160
+ print "\n"
161
+ end
162
+
163
+ # output connection information
164
+ print "#{ui.color("Querying server info...\n", :magenta)}"
165
+ info = rightscale.server_info
166
+ print "\n"
167
+ msg_pair("Public DNS Name", info.public_dns_names.first)
168
+ msg_pair("Public IP Address", info.public_ip_addresses.first)
169
+ msg_pair("Private DNS Name", info.private_dns_names.first)
170
+ msg_pair("Private IP Address", info.private_ip_addresses.first)
171
+ end
172
+
173
+ private
174
+
175
+ def validate!
176
+ super([:cloud_name, :deployment_name, :server_template, :rightscale_user, :rightscale_password, :rightscale_account_id])
177
+ end
178
+
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,52 @@
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 'chef/knife/rightscale_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class RightscaleServerDelete < Knife
24
+
25
+ include Knife::RightscaleBase
26
+
27
+ banner "knife rightscale server delete SERVER"
28
+
29
+ def run
30
+ validate!
31
+
32
+ @server_name = @name_args[0]
33
+
34
+ if @server_name.nil?
35
+ show_usage
36
+ ui.fatal("You must specify a server name")
37
+ exit 1
38
+ end
39
+
40
+ confirm("Do you really want to delete #{@server_name}")
41
+ connection.delete_server(@server_name)
42
+ end
43
+
44
+ private
45
+
46
+ def validate!
47
+ super([:rightscale_user, :rightscale_password, :rightscale_account_id])
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,73 @@
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 'chef/knife/rightscale_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class RightscaleServerList < Knife
24
+
25
+ include Knife::RightscaleBase
26
+
27
+ deps do
28
+ require 'right_api_client'
29
+ require 'timeout'
30
+ end
31
+
32
+ banner "knife rightscale server list (options)"
33
+
34
+ option :server_name,
35
+ :short => "-n SERVERNAME",
36
+ :long => "--name SERVERNAME",
37
+ :description => "The name of the server to search for",
38
+ :proc => Proc.new { |i| Chef::Config[:knife][:server_name] = i }
39
+
40
+ def run
41
+ $stdout.sync = true
42
+
43
+ validate!
44
+
45
+ @servers = connection.list_servers(:by_name, config[:server_name])
46
+
47
+ server_list = [
48
+ ui.color('Name', :bold),
49
+ ui.color('Description', :bold),
50
+ ui.color('State', :bold)
51
+ ].flatten.compact
52
+
53
+ output_column_count = server_list.length
54
+
55
+ @servers.each do |server|
56
+ server_list << server.name
57
+ server_list << server.description
58
+ server_list << server.state
59
+ end
60
+
61
+ puts ui.list(server_list, :uneven_columns_across, output_column_count)
62
+
63
+ end
64
+
65
+ private
66
+
67
+ def validate!
68
+ super([:rightscale_user, :rightscale_password, :rightscale_account_id])
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,73 @@
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 'chef/knife/rightscale_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class RightscaleServertemplateList < Knife
24
+
25
+ include Knife::RightscaleBase
26
+
27
+ deps do
28
+ require 'right_api_client'
29
+ end
30
+
31
+ option :server_template_name,
32
+ :short => "-n SERVERTEMPLATE_NAME",
33
+ :long => "--name SERVERTEMPLATE_NAME",
34
+ :description => "The partial name of the ServerTemplate to search for",
35
+ :proc => Proc.new { |i| Chef::Config[:knife][:server_template_name] = i }
36
+
37
+ banner "knife rightscale servertemplate list (options)"
38
+
39
+ def run
40
+ $stdout.sync = true
41
+
42
+ validate!
43
+
44
+ @servertemplates = connection.list_servertemplates(:by_name, config[:server_template_name])
45
+
46
+ servertemplate_list = [
47
+ ui.color('Name', :bold),
48
+ ui.color('Revision', :bold),
49
+ ui.color('ID', :bold)
50
+ ].flatten.compact
51
+
52
+ output_column_count = servertemplate_list.length
53
+
54
+ @servertemplates.each do |servertemplate|
55
+ revision = servertemplate.revision.to_s
56
+ servertemplate_list << servertemplate.name
57
+ servertemplate_list << ((revision == "0") ? "HEAD" : revision)
58
+ servertemplate_list << servertemplate.href.to_s.delete("/api/server_templates/")
59
+ end
60
+
61
+ puts ui.list(servertemplate_list, :uneven_columns_across, output_column_count)
62
+
63
+ end
64
+
65
+ private
66
+
67
+ def validate!
68
+ super([:rightscale_user, :rightscale_password, :rightscale_account_id])
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,30 @@
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 "knife-rightscale/version"
20
+
21
+ require "right_api_provision/api15"
22
+ require "right_api_provision/provisioner"
23
+
24
+ require "chef/knife/rightscale_cloud_list"
25
+ require "chef/knife/rightscale_deployment_list"
26
+ require "chef/knife/rightscale_image_list"
27
+ require "chef/knife/rightscale_securitygroup_list"
28
+ require "chef/knife/rightscale_server_create"
29
+ require "chef/knife/rightscale_server_list"
30
+ require "chef/knife/rightscale_servertemplate_list"
@@ -0,0 +1,22 @@
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
+ module Knife
19
+ module Rightscale
20
+ VERSION = "0.0.2"
21
+ end
22
+ end
@@ -0,0 +1,92 @@
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
+ # returns dto object
20
+ list_clouds(name) => id, name, description
21
+ list_deployemnt(name) => id, name, description
22
+ list_mci(st_id, name) => id, name
23
+ list_mci_cs(mci_id) => id, name, default_instance_type # can we filter by cloud id?
24
+ list_secgroups(cloud_id, name) => id, name, resource_uid
25
+
26
+ # returns object_id
27
+ find_cloud(name) => id
28
+ find_st(name) => id
29
+
30
+
31
+ #
32
+ # Provisioner Object
33
+ #
34
+
35
+ # Provision a server using RightScale
36
+ #
37
+ # @param name [String] the name to give the server that will be created.
38
+ # @param servertemplate [String] the name or ID of the ServerTemplate to create the server from.
39
+ # @param cloud [String] name of cloud to provision on.
40
+ # @param deployment [String] name of deployment to add server to.
41
+ # This will be created if it does not exist.
42
+ # @param
43
+ # @param delay[Integer] seconds to sleep between polling attempts
44
+ # @param pending_block[Block] block to execute before each attempt.
45
+ #
46
+ # @returns [Object] a provisioner object for the created server
47
+ #
48
+ # @raises RightApiProvisionException if anything goes wrong
49
+ provision(
50
+ name,
51
+ st_name,
52
+ cloud_name,
53
+ deploy_name,
54
+ inputs,
55
+ ssh_key_uid,
56
+ secgroup_id,
57
+ &pending_block)
58
+
59
+ # Check to see if the server is ready
60
+ #
61
+ # @returns true[TrueFalse] if the server operational
62
+ server_operational?
63
+
64
+ # Wait for the server to be ready
65
+ #
66
+ # Blocks execution until the server state is operational
67
+ # Use pending_block param to provide custom progress UI output.
68
+ #
69
+ # @param delay[Integer] seconds to sleep between polling attempts
70
+ # @param pending_block[Block] block to execute before each attempt.
71
+ #
72
+ # @raises RightApiProvisionExceptionUNEXPECTED_STATE if invalid server
73
+ # state is received.
74
+ wait_for_operational(delay, &pending_block)
75
+
76
+ # Get server information
77
+ #
78
+ # Grabs the DNS and IP information from an operational server.
79
+ # This will poll until the information is available from the cloud.
80
+ # Use pending_block param to provide custom progress UI output.
81
+ #
82
+ # @param delay[Integer] seconds to sleep between polling attempts
83
+ # @param pending_block[Block] block to execute before each attempt.
84
+ #
85
+ # @returns
86
+ server_info(delay, &pending_block)
87
+
88
+
89
+
90
+
91
+
92
+