knife-openstack 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- # Copyright:: Copyright (c) 2011 Opscode, Inc.
3
+ # Author:: Matt Ray (<matt@opscode.com>)
4
+ # Copyright:: Copyright (c) 2011-2012 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,82 +17,86 @@
16
17
  # limitations under the License.
17
18
  #
18
19
 
19
- require 'chef/knife'
20
+ require 'chef/knife/openstack_base'
21
+
22
+ # These two are needed for the '--purge' deletion case
23
+ require 'chef/node'
24
+ require 'chef/api_client'
20
25
 
21
26
  class Chef
22
27
  class Knife
23
28
  class OpenstackServerDelete < Knife
24
29
 
25
- deps do
26
- require 'fog'
27
- require 'net/ssh/multi'
28
- require 'readline'
29
- require 'chef/json_compat'
30
- end
30
+ include Knife::OpenstackBase
31
31
 
32
32
  banner "knife openstack server delete SERVER [SERVER] (options)"
33
33
 
34
- option :openstack_access_key_id,
35
- :short => "-A ID",
36
- :long => "--openstack-access-key-id KEY",
37
- :description => "Your OpenStack Access Key ID",
38
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
39
-
40
- option :openstack_secret_access_key,
41
- :short => "-K SECRET",
42
- :long => "--openstack-secret-access-key SECRET",
43
- :description => "Your OpenStack API Secret Access Key",
44
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
45
-
46
- option :openstack_api_endpoint,
47
- :long => "--openstack-api-endpoint ENDPOINT",
48
- :description => "Your OpenStack API endpoint",
49
- :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
50
-
51
- option :region,
52
- :long => "--region REGION",
53
- :description => "Your OpenStack region",
54
- :proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
34
+ option :purge,
35
+ :short => "-P",
36
+ :long => "--purge",
37
+ :boolean => true,
38
+ :default => false,
39
+ :description => "Destroy corresponding node and client on the Chef Server, in addition to destroying the OpenStack node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
40
+
41
+ option :chef_node_name,
42
+ :short => "-N NAME",
43
+ :long => "--node-name NAME",
44
+ :description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
45
+
46
+ # Extracted from Chef::Knife.delete_object, because it has a
47
+ # confirmation step built in... By specifying the '--purge'
48
+ # flag (and also explicitly confirming the server destruction!)
49
+ # the user is already making their intent known. It is not
50
+ # necessary to make them confirm two more times.
51
+ def destroy_item(klass, name, type_name)
52
+ begin
53
+ object = klass.load(name)
54
+ object.destroy
55
+ ui.warn("Deleted #{type_name} #{name}")
56
+ rescue Net::HTTPServerException
57
+ ui.warn("Could not find a #{type_name} named #{name} to delete!")
58
+ end
59
+ end
55
60
 
56
61
  def run
57
- connection = Fog::Compute.new(
58
- :provider => 'AWS',
59
- :aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
60
- :aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
61
- :endpoint => Chef::Config[:knife][:openstack_api_endpoint],
62
- :region => Chef::Config[:knife][:region] || config[:region]
63
- )
64
-
65
- @name_args.each do |instance_id|
66
- server = connection.servers.get(instance_id)
67
-
68
- msg("Instance ID", server.id)
69
- msg("Flavor", server.flavor_id)
70
- msg("Image", server.image_id)
71
- msg("Availability Zone", server.availability_zone)
72
- msg("Security Groups", server.groups.join(", "))
73
- msg("SSH Key", server.key_name)
74
- msg("Public DNS Name", server.dns_name)
75
- msg("Public IP Address", server.public_ip_address)
76
- msg("Private DNS Name", server.private_dns_name)
77
- msg("Private IP Address", server.private_ip_address)
78
-
79
- puts "\n"
80
- confirm("Do you really want to delete this server")
81
-
82
- server.destroy
83
62
 
84
- ui.warn("Deleted server #{server.id}")
85
- end
86
- end
63
+ validate!
87
64
 
88
- def msg(label, value)
89
- if value && !value.empty?
90
- puts "#{ui.color(label, :cyan)}: #{value}"
65
+ @name_args.each do |instance_id|
66
+ begin
67
+ server = connection.servers.get(instance_id)
68
+
69
+ msg_pair("Instance ID", server.id)
70
+ msg_pair("Instance Name", server.name)
71
+ msg_pair("Flavor", server.flavor['id'])
72
+ msg_pair("Image", server.image['id'])
73
+ # msg_pair("Availability Zone", server.availability_zone)
74
+ # msg_pair("Security Groups", server.groups.join(", "))
75
+ # msg_pair("SSH Key", server.key_name)
76
+ msg_pair("Public IP Address", server.public_ip_address['addr'])
77
+ msg_pair("Private IP Address", server.private_ip_address['addr'])
78
+
79
+ puts "\n"
80
+ confirm("Do you really want to delete this server")
81
+
82
+ server.destroy
83
+
84
+ ui.warn("Deleted server #{server.id}")
85
+
86
+ if config[:purge]
87
+ thing_to_delete = config[:chef_node_name] || instance_id
88
+ destroy_item(Chef::Node, thing_to_delete, "node")
89
+ destroy_item(Chef::ApiClient, thing_to_delete, "client")
90
+ else
91
+ ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server")
92
+ end
93
+
94
+ rescue NoMethodError
95
+ ui.error("Could not locate server '#{instance_id}'.")
96
+ end
91
97
  end
92
98
  end
93
99
 
94
100
  end
95
101
  end
96
102
  end
97
-
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- # Copyright:: Copyright (c) 2011 Opscode, Inc.
3
+ # Author:: Matt Ray (<matt@opscode.com>)
4
+ # Copyright:: Copyright (c) 2011-2012 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,75 +17,60 @@
16
17
  # limitations under the License.
17
18
  #
18
19
 
19
- require 'chef/knife'
20
+ require 'chef/knife/openstack_base'
20
21
 
21
22
  class Chef
22
23
  class Knife
23
24
  class OpenstackServerList < Knife
24
25
 
25
- deps do
26
- require 'fog'
27
- require 'net/ssh/multi'
28
- require 'readline'
29
- require 'chef/json_compat'
30
- end
26
+ include Knife::OpenstackBase
31
27
 
32
28
  banner "knife openstack server list (options)"
33
29
 
34
- option :openstack_access_key_id,
35
- :short => "-A ID",
36
- :long => "--openstack-access-key-id KEY",
37
- :description => "Your OpenStack Access Key ID",
38
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
39
-
40
- option :openstack_secret_access_key,
41
- :short => "-K SECRET",
42
- :long => "--openstack-secret-access-key SECRET",
43
- :description => "Your OpenStack API Secret Access Key",
44
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
45
-
46
- option :openstack_api_endpoint,
47
- :long => "--openstack-api-endpoint ENDPOINT",
48
- :description => "Your OpenStack API endpoint",
49
- :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
50
-
51
- option :region,
52
- :long => "--region REGION",
53
- :description => "Your OpenStack region",
54
- :proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
55
-
56
30
  def run
57
-
58
31
  $stdout.sync = true
59
32
 
60
- connection = Fog::Compute.new(
61
- :provider => 'AWS',
62
- :aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
63
- :aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
64
- :endpoint => Chef::Config[:knife][:openstack_api_endpoint],
65
- :region => Chef::Config[:knife][:region] || config[:region]
66
- )
33
+ validate!
67
34
 
68
35
  server_list = [
69
36
  ui.color('Instance ID', :bold),
37
+ ui.color('Name', :bold),
70
38
  ui.color('Public IP', :bold),
71
39
  ui.color('Private IP', :bold),
72
40
  ui.color('Flavor', :bold),
73
41
  ui.color('Image', :bold),
74
- ui.color('Security Groups', :bold),
42
+ ui.color('Keypair', :bold),
75
43
  ui.color('State', :bold)
76
44
  ]
77
- connection.servers.all.each do |server|
45
+ connection.servers.all.sort_by(&:id).each do |server|
78
46
  server_list << server.id.to_s
79
- # HACK these should all be server.blah.to_s as nil.to_s == ''
80
- server_list << (server.public_ip_address == nil ? "" : server.public_ip_address)
81
- server_list << (server.private_ip_address == nil ? "" : server.private_ip_address)
82
- server_list << (server.flavor_id == nil ? "" : server.flavor_id)
83
- server_list << (server.image_id == nil ? "" : server.image_id)
84
- server_list << server.groups.join(", ")
85
- server_list << server.state
47
+ server_list << server.name
48
+ if server.public_ip_address.nil?
49
+ server_list << ''
50
+ else
51
+ server_list << server.public_ip_address['addr'].to_s
52
+ end
53
+ if server.private_ip_address.nil?
54
+ server_list << ''
55
+ else
56
+ server_list << server.private_ip_address['addr'].to_s
57
+ end
58
+ server_list << server.flavor['id'].to_s
59
+ server_list << server.image['id'].to_s
60
+ server_list << server.key_name
61
+ server_list << begin
62
+ state = server.state.to_s.downcase
63
+ case state
64
+ when 'shutting-down','terminated','stopping','stopped','error'
65
+ ui.color(state, :red)
66
+ when 'pending','build','paused','suspended','hard_reboot'
67
+ ui.color(state, :yellow)
68
+ else
69
+ ui.color(state, :green)
70
+ end
71
+ end
86
72
  end
87
- puts ui.list(server_list, :columns_across, 7)
73
+ puts ui.list(server_list, :uneven_columns_across, 8)
88
74
 
89
75
  end
90
76
  end
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module OpenStack
3
- VERSION = "0.5.4"
3
+ VERSION = "0.6.0"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,101 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: knife-openstack
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
4
5
  prerelease:
5
- version: 0.5.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Seth Chisamore
9
+ - Matt Ray
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2011-05-02 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2012-06-29 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: fog
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70295645863080 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
19
+ requirements:
22
20
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: 0.7.2
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.0
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: net-ssh
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70295645863080
26
+ - !ruby/object:Gem::Dependency
27
+ name: chef
28
+ requirement: &70295645862580 !ruby/object:Gem::Requirement
31
29
  none: false
32
- requirements:
33
- - - ~>
34
- - !ruby/object:Gem::Version
35
- version: 2.1.3
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.10
36
34
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: net-ssh-multi
40
35
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ~>
45
- - !ruby/object:Gem::Version
46
- version: 1.0.1
47
- type: :runtime
48
- version_requirements: *id003
36
+ version_requirements: *70295645862580
49
37
  description: OpenStack Compute Support for Chef's Knife Command
50
- email:
38
+ email:
51
39
  - schisamo@opscode.com
40
+ - matt@opscode.com
52
41
  executables: []
53
-
54
42
  extensions: []
55
-
56
- extra_rdoc_files:
57
- - README.rdoc
43
+ extra_rdoc_files:
44
+ - README.md
58
45
  - LICENSE
59
- files:
46
+ files:
60
47
  - .gitignore
48
+ - CHANGELOG.md
61
49
  - Gemfile
62
50
  - LICENSE
63
- - README.rdoc
51
+ - README.md
64
52
  - Rakefile
65
53
  - knife-openstack.gemspec
54
+ - lib/chef/knife/openstack_base.rb
66
55
  - lib/chef/knife/openstack_flavor_list.rb
67
56
  - lib/chef/knife/openstack_image_list.rb
68
57
  - lib/chef/knife/openstack_server_create.rb
69
58
  - lib/chef/knife/openstack_server_delete.rb
70
59
  - lib/chef/knife/openstack_server_list.rb
71
60
  - lib/knife-openstack/version.rb
72
- has_rdoc: true
73
61
  homepage: https://github.com/opscode/knife-openstack
74
62
  licenses: []
75
-
76
63
  post_install_message:
77
64
  rdoc_options: []
78
-
79
- require_paths:
65
+ require_paths:
80
66
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
82
68
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
87
- required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
74
  none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
93
79
  requirements: []
94
-
95
80
  rubyforge_project:
96
- rubygems_version: 1.6.2
81
+ rubygems_version: 1.8.15
97
82
  signing_key:
98
83
  specification_version: 3
99
84
  summary: OpenStack Compute Support for Chef's Knife Command
100
85
  test_files: []
101
-
data/README.rdoc DELETED
@@ -1,90 +0,0 @@
1
- = Knife OpenStack
2
-
3
- = DESCRIPTION:
4
-
5
- This is the official Opscode Knife plugin for OpenStack Compute (Nova). This plugin gives knife the ability to create, bootstrap, and manage instances in OpenStack Compute clouds.
6
-
7
- = INSTALLATION:
8
-
9
- Be sure you are running the beta version of Chef which supports plugins:
10
-
11
- $ gem install chef --version 0.10.0.beta.6
12
-
13
- This plugin is distributed as a Ruby Gem. To install it, run:
14
-
15
- $ gem install knife-openstack
16
-
17
- Depending on your system's configuration, you may need to run this command with root privileges.
18
-
19
- = CONFIGURATION:
20
-
21
- In order to communicate with an OpenStack Compute cloud's EC2 API you will have to tell Knife about your OpenStack Compute cloud API endpoint, OpenStack Access Key and Secret Access Key. The easiest way to accomplish this is to create some entries in your <tt>knife.rb</tt> file:
22
-
23
- ### Note: You may need to append the :openstack_access_key_id with ":$PROJECT_NAME", if it differs from your OpenStack Username.
24
- knife[:openstack_access_key_id] = "Your OpenStack Access Key ID"
25
- knife[:openstack_secret_access_key] = "Your OpenStack Secret Access Key"
26
- ### Note: If you are not proxying HTTPS to the OpenStack EC2 API port, the scheme should be HTTP, and the PORT is 8773.
27
- knife[:openstack_api_endpoint] = "https://cloud.mycompany.com/service/Cloud"
28
-
29
- If your knife.rb file will be checked into a SCM system (ie readable by others) you may want to read the values from environment variables:
30
-
31
- knife[:openstack_access_key_id] = "#{ENV['EC2_ACCESS_KEY']}"
32
- knife[:openstack_secret_access_key] = "#{ENV['EC2_SECRET_KEY']}"
33
- knife[:openstack_api_endpoint] = "#{ENV['EC2_URL']}"
34
-
35
- You also have the option of passing your OpenStack API Key/Secret into the individual knife subcommands using the <tt>-A</tt> (or <tt>--openstack-access-key-id</tt>) <tt>-K</tt> (or <tt>--openstack-secret-access-key</tt>) command options
36
-
37
- # provision a new m1.small Ubuntu 10.04 webserver
38
- knife openstack server create 'role[webserver]' -I ami-7000f019 -f m1.small -A 'Your OpenStack Access Key ID' -K 'Your OpenStack Secret Access Key' --openstack-api-endpoint 'https://cloud.mycompany.com/v1.0'
39
-
40
- Additionally the following options may be set in your `knife.rb`:
41
-
42
- * flavor
43
- * image
44
- * availability_zone
45
- * openstack_ssh_key_id
46
- * region
47
- * distro
48
- * template_file
49
-
50
- = SUBCOMMANDS:
51
-
52
- This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a <tt>--help</tt> flag
53
-
54
- == knife openstack server create
55
-
56
- Provisions a new server in an OpenStack Compute cloud and then perform a Chef bootstrap (using the SSH protocol). The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists (provided by the provisioning). It is primarily intended for Chef Client systems that talk to a Chef server. By default the server is bootstrapped using the {ubuntu10.04-gems}[https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb] template. This can be overridden using the <tt>-d</tt> or <tt>--template-file</tt> command options.
57
-
58
- == knife openstack server delete
59
-
60
- Deletes an existing server in the currently configured OpenStack Compute cloud account. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef server.
61
-
62
- == knife openstack server list
63
-
64
- Outputs a list of all servers in the currently configured OpenStack Compute cloud account. <b>PLEASE NOTE</b> - this shows all instances associated with the account, some of which may not be currently managed by the Chef server.
65
-
66
- == knife openstack flavor list
67
-
68
- Outputs a list of all available flavors (available hardware configuration for a server) available to the currently configured OpenStack Compute cloud account. Each flavor has a unique combination of disk space, memory capacity and priority for CPU time. This data can be useful when choosing a flavor id to pass to the <tt>knife openstack server create</tt> subcommand.
69
-
70
- == knife openstack image list
71
-
72
- Outputs a list of all available images available to the currently configured OpenStack Compute cloud account. An image is a collection of files used to create or rebuild a server. This data can be useful when choosing an image id to pass to the <tt>knife openstack server create</tt> subcommand.
73
-
74
- = LICENSE:
75
-
76
- Author:: Seth Chisamore (<schisamo@opscode.com>)
77
- Copyright:: Copyright (c) 2011 Opscode, Inc.
78
- License:: Apache License, Version 2.0
79
-
80
- Licensed under the Apache License, Version 2.0 (the "License");
81
- you may not use this file except in compliance with the License.
82
- You may obtain a copy of the License at
83
-
84
- http://www.apache.org/licenses/LICENSE-2.0
85
-
86
- Unless required by applicable law or agreed to in writing, software
87
- distributed under the License is distributed on an "AS IS" BASIS,
88
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89
- See the License for the specific language governing permissions and
90
- limitations under the License.