knife-openstack 0.10.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +20 -22
  5. data/Gemfile +11 -1
  6. data/README.md +6 -4
  7. data/Rakefile +33 -0
  8. data/knife-openstack.gemspec +7 -8
  9. data/lib/chef/knife/cloud/openstack_server_create_options.rb +75 -0
  10. data/lib/chef/knife/cloud/openstack_service.rb +62 -0
  11. data/lib/chef/knife/cloud/openstack_service_options.rb +50 -0
  12. data/lib/chef/knife/openstack_flavor_list.rb +37 -51
  13. data/lib/chef/knife/openstack_group_list.rb +38 -45
  14. data/lib/chef/knife/openstack_helpers.rb +30 -0
  15. data/lib/chef/knife/openstack_image_list.rb +42 -59
  16. data/lib/chef/knife/openstack_network_list.rb +25 -21
  17. data/lib/chef/knife/openstack_server_create.rb +166 -452
  18. data/lib/chef/knife/openstack_server_delete.rb +26 -106
  19. data/lib/chef/knife/openstack_server_list.rb +37 -59
  20. data/lib/chef/knife/openstack_server_show.rb +57 -0
  21. data/lib/knife-openstack/version.rb +1 -1
  22. data/spec/functional/flavor_list_func_spec.rb +45 -0
  23. data/spec/functional/group_list_func_spec.rb +67 -0
  24. data/spec/functional/image_list_func_spec.rb +51 -0
  25. data/spec/functional/network_list_func_spec.rb +44 -0
  26. data/spec/functional/server_create_func_spec.rb +118 -0
  27. data/spec/functional/server_delete_func_spec.rb +84 -0
  28. data/spec/functional/server_list_func_spec.rb +95 -0
  29. data/spec/functional/server_show_func_spec.rb +46 -0
  30. data/spec/integration/cleanup.rb +91 -0
  31. data/spec/integration/config/environment.yml.sample +13 -0
  32. data/spec/integration/openstack_spec.rb +618 -0
  33. data/spec/spec_helper.rb +126 -0
  34. data/spec/unit/openstack_flavor_list_spec.rb +30 -0
  35. data/spec/unit/openstack_group_list_spec.rb +43 -0
  36. data/spec/unit/openstack_image_list_spec.rb +32 -0
  37. data/spec/unit/openstack_network_list_spec.rb +39 -0
  38. data/spec/unit/openstack_server_create_spec.rb +344 -182
  39. data/spec/unit/openstack_server_delete_spec.rb +43 -0
  40. data/spec/unit/openstack_server_list_spec.rb +32 -0
  41. data/spec/unit/openstack_server_show_spec.rb +42 -0
  42. data/spec/unit/openstack_service_spec.rb +89 -0
  43. data/spec/unit/validate_spec.rb +55 -0
  44. metadata +95 -51
  45. data/lib/chef/knife/openstack_base.rb +0 -182
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13492963594dd97e5007238a36319adbe3b86135
4
+ data.tar.gz: 95480b2805c8ff46602929ee7f240d35a7447aa7
5
+ SHA512:
6
+ metadata.gz: 4eb2ee6abd59a5836b33bd8fa692b858e3708afbec35b44759ef04679e7fb97ad4bd9d6531282d8747670448a148641e1431c28de3b7e0ccb73745fafe56e40e
7
+ data.tar.gz: d0b82f89495c66b4efda371a08bd5b40d7e4292cf24abcb74c734e01c79182cf776d2b161a319285883b9b6757a031875270325d069fcace8373b2053bfddebc
data/.gitignore CHANGED
@@ -2,4 +2,26 @@
2
2
  .bundle
3
3
  .rvmrc
4
4
  Gemfile.lock
5
+ .autotest
6
+ coverage
7
+ .DS_Store
8
+ pkg
9
+ */tags
10
+
11
+ # ignore some common Bundler 'binstubs' directory names
12
+ # http://gembundler.com/man/bundle-exec.1.html
13
+ b/
14
+ binstubs/
15
+
16
+ # RVM and RBENV ruby version files
17
+ .rbenv-version
18
+ .rvmrc
19
+
20
+ # Documentation
21
+ _site/*
22
+ .yardoc/
23
+ doc/
5
24
  pkg/*
25
+
26
+ #keys
27
+ *.pem
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.2
5
+
6
+ script: bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -1,36 +1,18 @@
1
- ## v0.10.0
2
- DONE
3
- * KNIFE-368 Ability to specify metadata during OpenStack server create
4
- * KNIFE-423 Add ability for knife-openstack to specify network IDs to attach
5
- * KNIFE-428 Added Availability zone to knife openstack
6
- * KNIFE-467 --no-network fails to find first network IP address
7
- * KNIFE-471 Explicitly define NIC for private network when creating server
8
- * KNIFE-474 knife openstack group list throws a fog deprecation warning
9
- * KNIFE-475 json-attributes option wasnt actually getting passed to bootstrap
10
- * KNIFE-477 Delete openstack instance by name
11
- * KNIFE-478 Generated SSH password not passed to bootstrap
12
- * add support for working with names instead of ids, updated listing accordingly
13
1
 
14
- ## v0.9.1
15
- * KNIFE-462 missing user_data throws stack
16
-
17
- ## v0.9.0
18
- * KNIFE-231 added ability to specify arbitrary bootstrap network ID
19
- * KNIFE-264 Add support for --json-attributes
20
- * KNIFE-277 knife openstack "ERROR: No IP address available for bootstrapping."
2
+ * Implementation using knife-cloud gem
21
3
  * KNIFE-310 "knife openstack server list" will fail with boot from volume instances
22
- * KNIFE-435 Support user data for OpenStack server create
23
- * KNIFE-436 Support fixed network type for OpenStack server create
24
- * https://github.com/opscode/chef-rfc/pull/7/ create/delete enhancements
25
4
 
26
5
  ## v0.8.1
6
+
27
7
  * KNIFE-296 knife-windows overrides -i, -p, -P and -x options with winrm values
28
8
  * KNIFE-304 enable setting the ssh port for knife-openstack
29
9
 
30
10
  ## v0.8.0
11
+
31
12
  * KNIFE-221 Windows bootstrapping (winrm-based) support for knife-openstack (Chirag Jog)
32
13
 
33
14
  ## v0.7.1
15
+
34
16
  * KNIFE-261 file permissions fixed
35
17
 
36
18
  ## v0.7.0
@@ -76,3 +58,19 @@ DONE
76
58
 
77
59
  ## V0.5.2
78
60
  * initial Cactus release using EC2 API
61
+
62
+ # BACKLOG/ISSUES #
63
+ This is a list of missing(?) features and open questions currently under development consideration:
64
+
65
+ * Basic availability zones support (Jarek Zmudzinski) NEED TESTING ACCESS FOR AVAILABILITY ZONES
66
+ * purge only works when names match up with clients
67
+ * `knife openstack floating list|associate|release NODE` with --floating-ip-pool also
68
+ * KNIFE-229 Allow specifying the name of the pool when using floating IPs
69
+ * attempt to allocate a floating ipaddress if none if free, currently missing in Fog
70
+ * KNIFE-76 take either the flavor ID or the flavor name
71
+ * take either the image ID or the image name (similar for KNIFE-76)
72
+ * KNIFE-86 server create with expired password hangs
73
+ * KNIFE-231 added ability to specify arbitrary network ID
74
+ * assumption of only single floating IP (and fog uses the last as the public_ip_address)
75
+ * probably other places public network is assumed that could cause issues
76
+ * fog is putting the original public IP address into the private_ip_address method when you get a floating_ip, this is wrong. Remove KNIFE-248 code once fixed.
data/Gemfile CHANGED
@@ -1,4 +1,14 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in knife-openstack.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'rspec', '>= 2.7.0'
8
+ gem 'guard-rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rake'
11
+ gem 'mixlib-shellout'
12
+ gem 'knife-cloud', :git => 'https://github.com/opscode/knife-cloud.git'
13
+ gem 'knife-windows', :git => 'https://github.com/opscode/knife-windows.git'
14
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/opscode/knife-openstack.png)](https://travis-ci.org/opscode/knife-openstack)
2
+
1
3
  Knife OpenStack
2
4
  ===============
3
5
 
@@ -27,9 +29,9 @@ In order to communicate with an OpenStack API you will need to tell Knife your O
27
29
  knife[:openstack_password] = "Your OpenStack Dashboard password"
28
30
  knife[:openstack_tenant] = "Your OpenStack tenant name"
29
31
 
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:
32
+ 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. For example, using the conventions of [OpenStack's RC file](http://docs.openstack.org/user-guide/content/cli_openrc.html) (note the `openstack_auth_url`):
31
33
 
32
- knife[:openstack_auth_url] = "#{ENV['OS_AUTH_URL']}"
34
+ knife[:openstack_auth_url] = "#{ENV['OS_AUTH_URL']}/tokens"
33
35
  knife[:openstack_username] = "#{ENV['OS_USERNAME']}"
34
36
  knife[:openstack_password] = "#{ENV['OS_PASSWORD']}"
35
37
  knife[:openstack_tenant] = "#{ENV['OS_TENANT_NAME']}"
@@ -56,7 +58,7 @@ Additionally the following options may be set in your `knife.rb`:
56
58
 
57
59
  # Working with Floating IPs #
58
60
 
59
- To use a floating IP address while bootstrapping nodes, use the `-a` or `--floating-ip` option.
61
+ To use a floating IP address while bootstrapping nodes, use the `-a` or `--openstack-floating-ip` option.
60
62
 
61
63
  # Working with Windows Images #
62
64
 
@@ -108,7 +110,7 @@ Provides a list of the security groups available to the currently configured Ope
108
110
  knife openstack network list
109
111
  --------------------
110
112
 
111
- Lists the networks available to the currently configured OpenStack account. This data may be useful when choosing your networks to pass to the `knife openstack server create` subcommand. This command is only available with OpenStack deployments using the Neutron network service (not nova-network). Please see `knife openstack server delete --help` for all of the supported options.
113
+ Lists the networks available to the currently configured OpenStack account. This data may be useful when choosing your networks to pass to the `knife openstack server create` subcommand. This command is only available with OpenStack deployments using the Neutron network service (not nova-network). Please see `knife openstack server create --help` for all of the supported options.
112
114
 
113
115
  # License #
114
116
 
data/Rakefile CHANGED
@@ -1,2 +1,35 @@
1
+ # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
2
+ # Copyright:: Copyright (c) 2013 Chef Software, Inc.
3
+
1
4
  require 'bundler'
2
5
  Bundler::GemHelper.install_tasks
6
+
7
+ require 'rubygems'
8
+ require 'rubygems/package_task'
9
+
10
+ task :default => :all
11
+ task :all => [:spec, :uninstall, :install]
12
+
13
+ # Packaging
14
+ GEM_NAME = "knife-openstack"
15
+ require File.dirname(__FILE__) + '/lib/knife-openstack/version'
16
+ spec = eval(File.read("knife-openstack.gemspec"))
17
+ Gem::PackageTask.new(spec) do |pkg|
18
+ pkg.gem_spec = spec
19
+ end
20
+
21
+ desc "uninstall #{GEM_NAME}-#{Knife::OpenStack::VERSION}.gem from system..."
22
+ task :uninstall do
23
+ sh %{gem uninstall #{GEM_NAME} -x -v #{Knife::OpenStack::VERSION} }
24
+ end
25
+
26
+ # rspec
27
+ begin
28
+ require 'rspec/core/rake_task'
29
+ desc "Run all specs in spec directory"
30
+ RSpec::Core::RakeTask.new(:spec) do |t|
31
+ t.pattern = 'spec/unit/**/*_spec.rb'
32
+ end
33
+ rescue LoadError
34
+ STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
35
+ end
@@ -8,21 +8,20 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.has_rdoc = true
10
10
  s.extra_rdoc_files = ["README.md", "LICENSE" ]
11
- s.authors = ["Seth Chisamore", "Matt Ray"]
12
- s.email = ["schisamo@getchef.com", "matt@getchef.com"]
11
+ s.authors = ["Clogeny"]
12
+ s.email = ["contact@clogeny.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
- s.description = s.summary
15
+ s.description = %q{OpenStack Compute Support for Chef's Knife Command using knife-cloud gem}
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
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", ">= 1.10.0"
23
- s.add_dependency "chef", ">= 0.10.10"
24
- s.add_dependency "knife-windows"
22
+ s.add_dependency "fog", "~> 1.23"
23
+ s.add_dependency "chef", ">= 11"
24
+ s.add_dependency "knife-cloud", "~> 1.0"
25
25
 
26
- %w(rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem }
27
- s.require_paths = ["lib"]
26
+ %w(rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem }
28
27
  end
@@ -0,0 +1,75 @@
1
+
2
+ require 'chef/knife/cloud/server/create_options'
3
+
4
+ class Chef
5
+ class Knife
6
+ class Cloud
7
+ module OpenstackServerCreateOptions
8
+ def self.included(includer)
9
+ includer.class_eval do
10
+ include ServerCreateOptions
11
+
12
+ # Openstack Server create params.
13
+ option :private_network,
14
+ :long => "--openstack-private-network",
15
+ :description => "Use the private IP for bootstrapping rather than the public IP",
16
+ :boolean => true,
17
+ :default => false
18
+
19
+ option :openstack_floating_ip,
20
+ :short => "-a [IP]",
21
+ :long => "--openstack-floating-ip [IP]",
22
+ :default => "-1",
23
+ :description => "Request to associate a floating IP address to the new OpenStack node. Assumes IPs have been allocated to the project. Specific IP is optional."
24
+
25
+ option :openstack_security_groups,
26
+ :short => "-G X,Y,Z",
27
+ :long => "--openstack-groups X,Y,Z",
28
+ :description => "The security groups for this server",
29
+ :default => ["default"],
30
+ :proc => Proc.new { |groups| groups.split(',') }
31
+
32
+ option :openstack_ssh_key_id,
33
+ :short => "-S KEY",
34
+ :long => "--openstack-ssh-key-id KEY",
35
+ :description => "The OpenStack SSH keypair id",
36
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_ssh_key_id] = key }
37
+
38
+ option :user_data,
39
+ :long => "--user-data USER_DATA",
40
+ :description => "The file path containing user data information for this server",
41
+ :proc => Proc.new { |user_data| open(user_data) { |f| f.read } }
42
+
43
+ option :bootstrap_network,
44
+ :long => '--bootstrap-network NAME',
45
+ :default => 'public',
46
+ :description => "Specify network for bootstrapping. Default is 'public'."
47
+
48
+ option :network,
49
+ :long => "--no-network",
50
+ :boolean => true,
51
+ :default => true,
52
+ :description => "Use first available network for bootstrapping if 'public' and 'private' are unavailable."
53
+
54
+ option :network_ids,
55
+ :long => "--network-ids NETWORK_ID_1,NETWORK_ID_2,NETWORK_ID_3",
56
+ :description => "Comma separated list of the UUID(s) of the network(s) for the server to attach",
57
+ :proc => Proc.new { |networks| networks.split(',') }
58
+
59
+ option :availability_zone,
60
+ :short => "-Z ZONE_NAME",
61
+ :long => "--availability-zone ZONE_NAME",
62
+ :description => "The availability zone for this server",
63
+ :proc => Proc.new { |z| Chef::Config[:knife][:availability_zone] = z }
64
+
65
+ option :metadata,
66
+ :short => "-M X=1",
67
+ :long => "--metadata X=1",
68
+ :description => "Metadata information for this server (may pass multiple times)",
69
+ :proc => Proc.new { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!({data.split('=')[0]=>data.split('=')[1]})}
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
3
+ # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
4
+ # Copyright:: Copyright (c) 2013 Chef Software, Inc.
5
+ #
6
+
7
+ require 'chef/knife/cloud/fog/service'
8
+
9
+ class Chef
10
+ class Knife
11
+ class Cloud
12
+ class OpenstackService < FogService
13
+
14
+ def initialize(options = {})
15
+ Chef::Log.debug("openstack_username #{Chef::Config[:knife][:openstack_username]}")
16
+ Chef::Log.debug("openstack_auth_url #{Chef::Config[:knife][:openstack_auth_url]}")
17
+ Chef::Log.debug("openstack_tenant #{Chef::Config[:knife][:openstack_tenant]}")
18
+ Chef::Log.debug("openstack_endpoint_type #{Chef::Config[:knife][:openstack_endpoint_type] || 'publicURL' }")
19
+ Chef::Log.debug("openstack_insecure #{Chef::Config[:knife][:openstack_insecure].to_s}")
20
+
21
+ super(options.merge({
22
+ :auth_params => {
23
+ :provider => 'OpenStack',
24
+ :openstack_username => Chef::Config[:knife][:openstack_username],
25
+ :openstack_api_key => Chef::Config[:knife][:openstack_password],
26
+ :openstack_auth_url => Chef::Config[:knife][:openstack_auth_url],
27
+ :openstack_endpoint_type => Chef::Config[:knife][:openstack_endpoint_type],
28
+ :openstack_tenant => Chef::Config[:knife][:openstack_tenant],
29
+ :connection_options => {
30
+ :ssl_verify_peer => !Chef::Config[:knife][:openstack_insecure]
31
+ }
32
+ }}))
33
+ end
34
+
35
+ # add alternate user defined api_endpoint value.
36
+ def add_api_endpoint
37
+ @auth_params.merge!({:openstack_auth_url => Chef::Config[:knife][:api_endpoint]}) unless Chef::Config[:knife][:api_endpoint].nil?
38
+ end
39
+
40
+ def get_server(search_term)
41
+ begin
42
+ if server = connection.servers.get(search_term)
43
+ return server
44
+ end
45
+
46
+ if servers = connection.servers.all(:name => search_term)
47
+ if servers.length > 1
48
+ error_message = "Multiple server matches found for '#{search_term}', use an instance_id to be more specific."
49
+ ui.fatal(error_message)
50
+ raise CloudExceptions::ValidationError, error_message
51
+ else
52
+ servers.first
53
+ end
54
+ end
55
+ rescue Excon::Errors::BadRequest => e
56
+ handle_excon_exception(CloudExceptions::KnifeCloudError, e)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,50 @@
1
+ require 'chef/knife/cloud/fog/options'
2
+ class Chef
3
+ class Knife
4
+ class Cloud
5
+ module OpenstackServiceOptions
6
+
7
+ def self.included(includer)
8
+ includer.class_eval do
9
+ include FogOptions
10
+ # Openstack Connection params.
11
+ option :openstack_username,
12
+ :short => "-A USERNAME",
13
+ :long => "--openstack-username KEY",
14
+ :description => "Your OpenStack Username",
15
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_username] = key }
16
+
17
+ option :openstack_password,
18
+ :short => "-K SECRET",
19
+ :long => "--openstack-password SECRET",
20
+ :description => "Your OpenStack Password",
21
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_password] = key }
22
+
23
+ option :openstack_tenant,
24
+ :short => "-T NAME",
25
+ :long => "--openstack-tenant NAME",
26
+ :description => "Your OpenStack Tenant NAME",
27
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_tenant] = key }
28
+
29
+ option :openstack_auth_url,
30
+ :long => "--openstack-api-endpoint ENDPOINT",
31
+ :description => "Your OpenStack API endpoint",
32
+ :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_auth_url] = endpoint }
33
+
34
+ option :openstack_endpoint_type,
35
+ :long => "--openstack-endpoint-type ENDPOINT_TYPE",
36
+ :description => "OpenStack endpoint type to use (publicURL, internalURL, adminURL)",
37
+ :proc => Proc.new { |type| Chef::Config[:knife][:openstack_endpoint_type] = type }
38
+
39
+ option :openstack_insecure,
40
+ :long => "--insecure",
41
+ :description => "Ignore SSL certificate on the Auth URL",
42
+ :boolean => true,
43
+ :default => false,
44
+ :proc => Proc.new { |key| Chef::Config[:knife][:openstack_insecure] = key }
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,58 +1,44 @@
1
- #
2
- # Author:: Seth Chisamore (<schisamo@getchef.com>)
3
- # Author:: Matt Ray (<matt@getchef.com>)
4
- # Copyright:: Copyright (c) 2011-2014 Chef Software, 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/openstack_base'
1
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
2
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
3
+
4
+ require 'chef/knife/cloud/list_resource_command'
5
+ require 'chef/knife/openstack_helpers'
6
+ require 'chef/knife/cloud/openstack_service_options'
21
7
 
22
8
  class Chef
23
9
  class Knife
24
- class OpenstackFlavorList < Knife
25
-
26
- include Knife::OpenstackBase
27
-
28
- banner "knife openstack flavor list (options)"
29
-
30
- def run
31
-
32
- validate!
33
-
34
- flavor_list = [
35
- ui.color('Name', :bold),
36
- ui.color('ID', :bold),
37
- ui.color('Virtual CPUs', :bold),
38
- ui.color('RAM', :bold),
39
- ui.color('Disk', :bold),
40
- ]
41
- begin
42
- connection.flavors.sort_by(&:name).each do |flavor|
43
- flavor_list << flavor.name
44
- flavor_list << flavor.id.to_s
45
- flavor_list << flavor.vcpus.to_s
46
- flavor_list << "#{flavor.ram.to_s} MB"
47
- flavor_list << "#{flavor.disk.to_s} GB"
48
- end
49
- rescue Excon::Errors::BadRequest => e
50
- response = Chef::JSONCompat.from_json(e.response.body)
51
- ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
52
- raise e
10
+ class Cloud
11
+ class OpenstackFlavorList < ResourceListCommand
12
+ include OpenstackHelpers
13
+ include OpenstackServiceOptions
14
+
15
+ banner "knife openstack flavor list (options)"
16
+
17
+ def before_exec_command
18
+ #set columns_with_info map
19
+ @columns_with_info = [
20
+ {:label => 'Name', :key => 'name'},
21
+ {:label => 'ID', :key => 'id'},
22
+ {:label => 'Virtual CPUs', :key => 'vcpus'},
23
+ {:label => 'RAM', :key => 'ram', :value_callback => method(:ram_in_mb)},
24
+ {:label => 'Disk', :key => 'disk', :value_callback => method(:disk_in_gb)}
25
+ ]
26
+ @sort_by_field = "name"
27
+ end
28
+
29
+ def query_resource
30
+ @service.list_resource_configurations
53
31
  end
54
- puts ui.list(flavor_list, :uneven_columns_across, 5)
32
+
33
+ def ram_in_mb(ram)
34
+ "#{ram} MB"
35
+ end
36
+
37
+ def disk_in_gb(disk)
38
+ "#{disk} GB"
39
+ end
40
+
55
41
  end
56
42
  end
57
43
  end
58
- end
44
+ end