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
@@ -1,182 +0,0 @@
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 'fog'
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 'chef/json_compat'
34
- require 'chef/knife'
35
- require 'readline'
36
- Chef::Knife.load_deps
37
- end
38
-
39
- option :openstack_username,
40
- :short => "-A USERNAME",
41
- :long => "--openstack-username KEY",
42
- :description => "Your OpenStack Username",
43
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_username] = key }
44
-
45
- option :openstack_password,
46
- :short => "-K SECRET",
47
- :long => "--openstack-password SECRET",
48
- :description => "Your OpenStack Password",
49
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_password] = key }
50
-
51
- option :openstack_tenant,
52
- :short => "-T NAME",
53
- :long => "--openstack-tenant NAME",
54
- :description => "Your OpenStack Tenant NAME",
55
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_tenant] = key }
56
-
57
- option :openstack_auth_url,
58
- :long => "--openstack-api-endpoint ENDPOINT",
59
- :description => "Your OpenStack API endpoint",
60
- :proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_auth_url] = endpoint }
61
-
62
- option :openstack_endpoint_type,
63
- :long => "--openstack-endpoint-type ENDPOINT_TYPE",
64
- :description => "OpenStack endpoint type to use (publicURL, internalURL, adminURL)",
65
- :proc => Proc.new { |type| Chef::Config[:knife][:openstack_endpoint_type] = type }
66
-
67
- option :openstack_insecure,
68
- :long => "--insecure",
69
- :description => "Ignore SSL certificate on the Auth URL",
70
- :boolean => true,
71
- :default => false,
72
- :proc => Proc.new { |key| Chef::Config[:knife][:openstack_insecure] = key }
73
-
74
- option :availability_zone,
75
- :short => "-Z ZONE_NAME",
76
- :long => "--availability-zone ZONE_NAME",
77
- :description => "The availability zone for this server",
78
- :proc => Proc.new { |z| Chef::Config[:knife][:availability_zone] = z }
79
- end
80
- end
81
-
82
- def connection
83
- Chef::Log.debug("openstack_username #{Chef::Config[:knife][:openstack_username]}")
84
- Chef::Log.debug("openstack_auth_url #{Chef::Config[:knife][:openstack_auth_url]}")
85
- Chef::Log.debug("openstack_endpoint_type #{Chef::Config[:knife][:openstack_endpoint_type] || 'publicURL' }")
86
- Chef::Log.debug("openstack_tenant #{Chef::Config[:knife][:openstack_tenant]}")
87
- Chef::Log.debug("openstack_insecure #{Chef::Config[:knife][:openstack_insecure].to_s}")
88
-
89
- @connection ||= begin
90
- connection = Fog::Compute.new(
91
- :provider => 'OpenStack',
92
- :openstack_username => Chef::Config[:knife][:openstack_username],
93
- :openstack_api_key => Chef::Config[:knife][:openstack_password],
94
- :openstack_auth_url => Chef::Config[:knife][:openstack_auth_url],
95
- :openstack_endpoint_type => Chef::Config[:knife][:openstack_endpoint_type],
96
- :openstack_tenant => Chef::Config[:knife][:openstack_tenant],
97
- :connection_options => {
98
- :ssl_verify_peer => !Chef::Config[:knife][:openstack_insecure]
99
- }
100
- )
101
- rescue Excon::Errors::Unauthorized => e
102
- ui.fatal("Connection failure, please check your OpenStack username and password.")
103
- exit 1
104
- rescue Excon::Errors::SocketError => e
105
- ui.fatal("Connection failure, please check your OpenStack authentication URL.")
106
- exit 1
107
- end
108
- end
109
-
110
- def network
111
- Chef::Log.debug("openstack_username #{Chef::Config[:knife][:openstack_username]}")
112
- Chef::Log.debug("openstack_auth_url #{Chef::Config[:knife][:openstack_auth_url]}")
113
- Chef::Log.debug("openstack_tenant #{Chef::Config[:knife][:openstack_tenant]}")
114
- Chef::Log.debug("openstack_insecure #{Chef::Config[:knife][:openstack_insecure].to_s}")
115
-
116
- @network ||= begin
117
- network = Fog::Network.new(
118
- :provider => 'OpenStack',
119
- :openstack_username => Chef::Config[:knife][:openstack_username],
120
- :openstack_api_key => Chef::Config[:knife][:openstack_password],
121
- :openstack_auth_url => Chef::Config[:knife][:openstack_auth_url],
122
- :openstack_tenant => Chef::Config[:knife][:openstack_tenant],
123
- :connection_options => {
124
- :ssl_verify_peer => !Chef::Config[:knife][:openstack_insecure]
125
- }
126
- )
127
- rescue Excon::Errors::Unauthorized => e
128
- ui.fatal("Connection failure, please check your OpenStack username and password.")
129
- exit 1
130
- rescue Excon::Errors::SocketError => e
131
- ui.fatal("Connection failure, please check your OpenStack authentication URL.")
132
- exit 1
133
- rescue Fog::Errors::NotFound => e
134
- ui.fatal("No OpenStack Network service found. This command is unavailable with nova-network.")
135
- exit 1
136
- end
137
- end
138
-
139
- def locate_config_value(key)
140
- key = key.to_sym
141
- Chef::Config[:knife][key] || config[key]
142
- end
143
-
144
- def msg_pair(label, value, color=:cyan)
145
- if value && !value.to_s.empty?
146
- puts "#{ui.color(label, color)}: #{value}"
147
- end
148
- end
149
-
150
- def validate!(keys=[:openstack_username, :openstack_password, :openstack_auth_url])
151
- errors = []
152
-
153
- keys.each do |k|
154
- pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
155
- if Chef::Config[:knife][k].nil?
156
- errors << "You did not provided a valid '#{pretty_key}' value."
157
- end
158
- end
159
-
160
- if errors.each{|e| ui.error(e)}.any?
161
- exit 1
162
- end
163
- end
164
-
165
- def primary_private_ip_address(addresses)
166
- primary_network_ip_address(addresses, 'private')
167
- end
168
-
169
- #we use last since the floating IP goes there
170
- def primary_public_ip_address(addresses)
171
- primary_network_ip_address(addresses, 'public')
172
- end
173
-
174
- def primary_network_ip_address(addresses, network_name)
175
- if addresses[network_name]
176
- return addresses[network_name].last['addr']
177
- end
178
- end
179
-
180
- end
181
- end
182
- end