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.
data/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ ## v0.6.0
2
+ * Switched to OpenStack API from OpenStack EC2 API.
3
+ * Updated to point to Fog 1.4.0 for latest `OpenStack` provider
4
+ * testing with Diablo & Essex
5
+ * knife openstack server create (KNIFE_OPENSTACK-1)
6
+ * knife openstack server delete (KNIFE_OPENSTACK-2)
7
+ * Support for unenven_columns for prettier output (KNIFE_OPENSTACK-5)
8
+ * Added chef gem dependency (KNIFE_OPENSTACK-6)
9
+ * Added virtual cpus to 'knife openstack flavor list'
10
+ * Removed unsupported features to match current state of plugin (public_key, kernel, architecture, cores, location)
11
+ * Added support for openstack_tenant (Rob Hirschfeld & Alexander Gordeev)
12
+ * Server list supports many more states
13
+ * Added support for associating floating IPs on server create and verified they are automatically disassociated on server delete
14
+ * Added /etc/chef/ohai/hints/openstack.json, the `openstack` Ohai plugin keys off of it and pulls from the meta-data service.
15
+ * Automated naming of nodes if `--node-name` is not passed
16
+ * Added support for `--no-host-key-verify` (Lamont Granquist)
17
+ * Added support for `--private-network` for bootstrapping private network
18
+
19
+ ## v0.5.2
20
+ * initial Cactus release using EC2 API
21
+
22
+ # BACKLOG/ISSUES #
23
+ This is a list of features currently lacking and (eventually) under development:
24
+
25
+ * security groups are still broken, appear to be broken in Fog. Add `-G` support for security groups other than 'default'
26
+ * purge only works when names match up with clients
27
+ * `knife openstack floating list|associate|disassociate ip|node`
28
+ * take either the flavor ID or the flavor name
29
+ * take either the image ID or the image name
30
+ * more information in `knife openstack image list`
31
+ * get DNS names working
32
+ * availability zones
33
+ * filter out the *-initrd and *-kernel from 'openstack image list'. Fog -> container_format={aki|ari} or disk_format on the same params
34
+ * assumption of only single floating IP (and fog uses the last as the public_ip_address)
35
+ * probably other places public network is assumed that could cause issues
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ Knife OpenStack
2
+ ===============
3
+
4
+ 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. It has been tested against the `Diablo` and `Essex` releases in configurations using Keystone against the OpenStack API (as opposed to the EC2 API).
5
+
6
+ Please refer to the CHANGELOG.md for version history and known limitations. If you are using Floating IP addresses, please refer to the "Working with Floating IPs" section below.
7
+
8
+ # Installation #
9
+
10
+ Be sure you are running the latest version Chef. Versions earlier than 0.10.0 don't support plugins:
11
+
12
+ $ gem install chef
13
+
14
+ This plugin is distributed as a Ruby Gem. To install it, run:
15
+
16
+ $ gem install knife-openstack
17
+
18
+ Depending on your system's configuration, you may need to run this command with root privileges.
19
+
20
+ # Configuration #
21
+
22
+ In order to communicate with an OpenStack Compute cloud's OpenStack API you will need to tell Knife your OpenStack Compute API endpoint, your Dashboard username and password (tenant is optional). The easiest way to accomplish this is to create these entries in your `knife.rb` file:
23
+
24
+ knife[:openstack_username] = "Your OpenStack Dashboard username"
25
+ knife[:openstack_password] = "Your OpenStack Dashboard password"
26
+ ### Note: If you are not proxying HTTPS to the OpenStack auth port, the scheme should be HTTP
27
+ knife[:openstack_auth_url] = "http://cloud.mycompany.com:5000/v2.0/tokens"
28
+ knife[:openstack_tenant] = "Your OpenStack tenant name"
29
+
30
+ 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:
31
+
32
+ knife[:openstack_username] = "#{ENV['OS_USERNAME']}"
33
+ knife[:openstack_password] = "#{ENV['OS_PASSWORD']}"
34
+ knife[:openstack_auth_url] = "#{ENV['OS_AUTH_URL']}"
35
+ knife[:openstack_tenant] = "#{ENV['OS_TENANT_NAME']}"
36
+
37
+ You also have the option of passing your OpenStack API Username/Password into the individual knife subcommands using the `-A` (or `--openstack-username`) `-K` (or `--openstack-password`) command options
38
+
39
+ # provision a new image named kb01
40
+ knife openstack server create -A 'MyUsername' -K 'MyPassword' --openstack-api-endpoint 'http://cloud.mycompany.com:5000/v2.0/tokens' -f 1 -I 13 -S trystack -i ~/.ssh/trystack.pem -r 'role[webserver]'
41
+
42
+ Additionally the following options may be set in your `knife.rb`:
43
+
44
+ * flavor
45
+ * image
46
+ * openstack_ssh_key_id
47
+ * template_file
48
+
49
+ # Working with Floating IPs #
50
+
51
+ To use a floating IP address while bootstrapping nodes, use the `-a` or `--floating-ip` option. For the node to have the floating IP address after bootstrapping, it is required to use the new `openstack.rb` Ohai plugin, waiting for the next Ohai release or installed using the [ohai cookbook](https://github.com/opscode-cookbooks/ohai). https://github.com/mattray/ohai/tree/OHAI-381 is the ticket for this.
52
+
53
+ # Subcommands #
54
+
55
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a `--help` option.
56
+
57
+ knife openstack server create
58
+ -----------------------------
59
+
60
+ 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 [chef-full](https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/chef-full.erb) template (default after the 10.10 release). This may be overridden using the `-d` or `--template-file` command options. If you do not have public IP addresses, use the `--private-network` option to use the private IP address for bootstrapping.
61
+
62
+ knife openstack server delete
63
+ -----------------------------
64
+
65
+ Deletes an existing server in the currently configured OpenStack Compute cloud account. If a floating IP address has been assigned to the node, it is disassociated automatically by the OpenStack server. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef server without using the `-P` option to purge the client.
66
+
67
+ knife openstack server list
68
+ ---------------------------
69
+
70
+ 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.
71
+
72
+ knife openstack flavor list
73
+ ---------------------------
74
+
75
+ 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 virtual cpus, disk space and memory capacity. This data can be useful when choosing a flavor id to pass to the `knife openstack server create` subcommand.
76
+
77
+ knife openstack image list
78
+ --------------------------
79
+
80
+ 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 `knife openstack server create` subcommand.
81
+
82
+ # License #
83
+
84
+ Author:: Seth Chisamore (<schisamo@opscode.com>)
85
+
86
+ Author:: Matt Ray (<matt@opscode.com>)
87
+
88
+ Copyright:: Copyright (c) 2011-2012 Opscode, Inc.
89
+
90
+ License:: Apache License, Version 2.0
91
+
92
+ Licensed under the Apache License, Version 2.0 (the "License");
93
+ you may not use this file except in compliance with the License.
94
+ You may obtain a copy of the License at
95
+
96
+ http://www.apache.org/licenses/LICENSE-2.0
97
+
98
+ Unless required by applicable law or agreed to in writing, software
99
+ distributed under the License is distributed on an "AS IS" BASIS,
100
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101
+ See the License for the specific language governing permissions and
102
+ limitations under the License.
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
7
7
  s.version = Knife::OpenStack::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.has_rdoc = true
10
- s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
11
- s.authors = ["Seth Chisamore"]
12
- s.email = ["schisamo@opscode.com"]
10
+ s.extra_rdoc_files = ["README.md", "LICENSE" ]
11
+ s.authors = ["Seth Chisamore", "Matt Ray"]
12
+ s.email = ["schisamo@opscode.com", "matt@opscode.com"]
13
13
  s.homepage = "https://github.com/opscode/knife-openstack"
14
14
  s.summary = %q{OpenStack Compute Support for Chef's Knife Command}
15
15
  s.description = s.summary
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "fog", "~> 0.7.2"
23
- s.add_dependency "net-ssh", "~> 2.1.3"
24
- s.add_dependency "net-ssh-multi", "~> 1.0.1"
22
+ s.add_dependency "fog", "~> 1.4.0"
23
+ s.add_dependency "chef", ">= 0.10.10"
25
24
  end
@@ -0,0 +1,108 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Author:: Matt Ray (<matt@opscode.com>)
4
+ # Copyright:: Copyright (c) 2011-2012 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef/knife'
21
+
22
+ class Chef
23
+ class Knife
24
+ module OpenstackBase
25
+
26
+ # :nodoc:
27
+ # Would prefer to do this in a rational way, but can't be done b/c of
28
+ # Mixlib::CLI's design :(
29
+ def self.included(includer)
30
+ includer.class_eval do
31
+
32
+ deps do
33
+ require 'fog'
34
+ require 'readline'
35
+ require 'chef/json_compat'
36
+ end
37
+
38
+ option :openstack_username,
39
+ :short => "-A USERNAME",
40
+ :long => "--openstack-username KEY",
41
+ :description => "Your OpenStack Username",
42
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_username] = key }
43
+
44
+ option :openstack_password,
45
+ :short => "-K SECRET",
46
+ :long => "--openstack-password SECRET",
47
+ :description => "Your OpenStack Password",
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_password] = key }
49
+
50
+ option :openstack_tenant,
51
+ :short => "-T NAME",
52
+ :long => "--openstack-tenant NAME",
53
+ :description => "Your OpenStack Tenant NAME",
54
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_tenant] = key }
55
+
56
+ option :openstack_auth_url,
57
+ :long => "--openstack-api-endpoint ENDPOINT",
58
+ :description => "Your OpenStack API endpoint",
59
+ :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_auth_url] = endpoint }
60
+ end
61
+ end
62
+
63
+ def connection
64
+ Chef::Log.debug("openstack_username #{Chef::Config[:knife][:openstack_username]}")
65
+ Chef::Log.debug("openstack_auth_url #{Chef::Config[:knife][:openstack_auth_url]}")
66
+ Chef::Log.debug("openstack_tenant #{Chef::Config[:knife][:openstack_tenant]}")
67
+ @connection ||= begin
68
+ connection = Fog::Compute.new(
69
+ :provider => 'OpenStack',
70
+ :openstack_username => Chef::Config[:knife][:openstack_username],
71
+ :openstack_api_key => Chef::Config[:knife][:openstack_password],
72
+ :openstack_auth_url => Chef::Config[:knife][:openstack_auth_url],
73
+ :openstack_tenant => Chef::Config[:knife][:openstack_tenant]
74
+ )
75
+ end
76
+ end
77
+
78
+ def locate_config_value(key)
79
+ key = key.to_sym
80
+ Chef::Config[:knife][key] || config[key]
81
+ end
82
+
83
+ def msg_pair(label, value, color=:cyan)
84
+ if value && !value.to_s.empty?
85
+ puts "#{ui.color(label, color)}: #{value}"
86
+ end
87
+ end
88
+
89
+ def validate!(keys=[:openstack_username, :openstack_password, :openstack_auth_url])
90
+ errors = []
91
+
92
+ keys.each do |k|
93
+ pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
94
+ if Chef::Config[:knife][k].nil?
95
+ errors << "You did not provided a valid '#{pretty_key}' value."
96
+ end
97
+ end
98
+
99
+ if errors.each{|e| ui.error(e)}.any?
100
+ exit 1
101
+ end
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+
108
+
@@ -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,67 +17,35 @@
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 OpenstackFlavorList < Knife
24
25
 
25
- deps do
26
- require 'fog'
27
- require 'chef/json_compat'
28
- end
29
-
30
- banner "knife openstack flavor list (options)"
31
-
32
- option :openstack_access_key_id,
33
- :short => "-A ID",
34
- :long => "--openstack-access-key-id KEY",
35
- :description => "Your OpenStack Access Key ID",
36
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
37
-
38
- option :openstack_secret_access_key,
39
- :short => "-K SECRET",
40
- :long => "--openstack-secret-access-key SECRET",
41
- :description => "Your OpenStack API Secret Access Key",
42
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
26
+ include Knife::OpenstackBase
43
27
 
44
- option :openstack_api_endpoint,
45
- :long => "--openstack-api-endpoint ENDPOINT",
46
- :description => "Your OpenStack API endpoint",
47
- :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
48
-
49
- option :region,
50
- :long => "--region REGION",
51
- :description => "Your OpenStack region",
52
- :proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
28
+ banner "knife openstack flavor list (options)"
53
29
 
54
30
  def run
55
- connection = Fog::Compute.new(
56
- :provider => 'AWS',
57
- :aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
58
- :aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
59
- :endpoint => Chef::Config[:knife][:openstack_api_endpoint],
60
- :region => Chef::Config[:knife][:region] || config[:region]
61
- )
31
+
32
+ validate!
62
33
 
63
34
  flavor_list = [
64
35
  ui.color('ID', :bold),
65
36
  ui.color('Name', :bold),
66
- ui.color('Architecture', :bold),
37
+ ui.color('Virtual CPUs', :bold),
67
38
  ui.color('RAM', :bold),
68
39
  ui.color('Disk', :bold),
69
- ui.color('Cores', :bold)
70
40
  ]
71
41
  connection.flavors.sort_by(&:id).each do |flavor|
72
42
  flavor_list << flavor.id.to_s
73
43
  flavor_list << flavor.name
74
- flavor_list << "#{flavor.bits.to_s}-bit"
75
- flavor_list << "#{flavor.ram.to_s}"
44
+ flavor_list << flavor.vcpus.to_s
45
+ flavor_list << "#{flavor.ram.to_s} MB"
76
46
  flavor_list << "#{flavor.disk.to_s} GB"
77
- flavor_list << flavor.cores.to_s
78
47
  end
79
- puts ui.list(flavor_list, :columns_across, 6)
48
+ puts ui.list(flavor_list, :uneven_columns_across, 5)
80
49
  end
81
50
  end
82
51
  end
@@ -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,45 @@
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 OpenstackImageList < Knife
24
25
 
25
- deps do
26
- require 'fog'
27
- require 'chef/json_compat'
28
- end
26
+ include Knife::OpenstackBase
29
27
 
30
28
  banner "knife openstack image list (options)"
31
29
 
32
- option :openstack_access_key_id,
33
- :short => "-A ID",
34
- :long => "--openstack-access-key-id KEY",
35
- :description => "Your OpenStack Access Key ID",
36
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
37
-
38
- option :openstack_secret_access_key,
39
- :short => "-K SECRET",
40
- :long => "--openstack-secret-access-key SECRET",
41
- :description => "Your OpenStack API Secret Access Key",
42
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
43
-
44
- option :openstack_api_endpoint,
45
- :long => "--openstack-api-endpoint ENDPOINT",
46
- :description => "Your OpenStack API endpoint",
47
- :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
48
-
49
- option :region,
50
- :long => "--region REGION",
51
- :description => "Your OpenStack region",
52
- :proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
53
-
54
30
  def run
55
- connection = Fog::Compute.new(
56
- :provider => 'AWS',
57
- :aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
58
- :aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
59
- :endpoint => Chef::Config[:knife][:openstack_api_endpoint],
60
- :region => Chef::Config[:knife][:region] || config[:region]
61
- )
31
+
32
+ validate!
62
33
 
63
34
  image_list = [
64
35
  ui.color('ID', :bold),
65
- ui.color('Kernel ID', :bold),
66
- ui.color('Architecture', :bold),
67
- ui.color('Root Store', :bold),
68
36
  ui.color('Name', :bold),
69
- ui.color('Location', :bold)
37
+ # ui.color('Kernel ID', :bold),
38
+ # ui.color('Architecture', :bold),
39
+ # ui.color('Root Store', :bold),
40
+ # ui.color('Location', :bold)
70
41
  ]
71
42
 
72
43
  connection.images.sort_by do |image|
73
- [image.name, image.id].compact
44
+ [image.name.downcase, image.id].compact
74
45
  end.each do |image|
75
46
  image_list << image.id
76
- image_list << image.kernel_id
77
- image_list << image.architecture
78
- image_list << image.root_device_type
79
47
  image_list << image.name
80
- image_list << image.location
48
+ # image_list << image.kernel_id
49
+ # image_list << image.architecture
50
+ # image_list << image.root_device_type
51
+ # image_list << image.location
81
52
  end
82
53
 
83
54
  image_list = image_list.map do |item|
84
55
  item.to_s
85
56
  end
86
57
 
87
- puts ui.list(image_list, :columns_across, 6)
58
+ puts ui.list(image_list, :uneven_columns_across, 2)
88
59
  end
89
60
  end
90
61
  end