lib/chef/knife/server_bootstrap_linode.rb in knife-server-1.1.0 vs lib/chef/knife/server_bootstrap_linode.rb in knife-server-1.2.0

- old
+ new

@@ -1,5 +1,6 @@ +# -*- encoding: utf-8 -*- # # Author:: Fletcher Nichol (<fnichol@nichol.ca>) # Copyright:: Copyright (c) 2013 Fletcher Nichol # License:: Apache License, Version 2.0 # @@ -14,32 +15,33 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # -require 'chef/knife/server_bootstrap_base' +require "chef/knife/server_bootstrap_base" class Chef class Knife + # Provisions a Linode instance and sets up an Open Source Chef Server. class ServerBootstrapLinode < Knife banner "knife server bootstrap linode (options)" include Knife::ServerBootstrapBase deps do - require 'knife/server/ssh' - require 'knife/server/credentials' + require "knife/server/ssh" + require "knife/server/credentials" begin - require 'chef/knife/linode_server_create' - require 'fog' + require "chef/knife/linode_server_create" + require "fog" Chef::Knife::LinodeServerCreate.load_deps - current_options = self.options + current_options = options self.options = Chef::Knife::LinodeServerCreate.options.dup - self.options.merge!(current_options) + options.merge!(current_options) rescue LoadError => ex ui.error [ "Knife plugin knife-linode could not be loaded.", "Please add the knife-linode gem to your Gemfile or", "install the gem manually with `gem install knife-linode'.", @@ -48,32 +50,35 @@ exit 1 end end def run - validate! + super linode_bootstrap.run fetch_validation_key create_root_client install_client_key end def linode_bootstrap - ENV['WEBUI_PASSWORD'] = config_val(:webui_password) - ENV['AMQP_PASSWORD'] = config_val(:amqp_password) - ENV['NO_TEST'] = "1" if config[:no_test] + ENV["WEBUI_PASSWORD"] = config_val(:webui_password) + ENV["AMQP_PASSWORD"] = config_val(:amqp_password) + ENV["NO_TEST"] = "1" if config[:no_test] bootstrap = Chef::Knife::LinodeServerCreate.new Chef::Knife::LinodeServerCreate.options.keys.each do |attr| - bootstrap.config[attr] = config_val(attr) + val = config_val(attr) + next if val.nil? + + bootstrap.config[attr] = val end bootstrap.config[:distro] = bootstrap_distro bootstrap end def linode_connection @linode_connection ||= Fog::Compute.new( - :provider => 'Linode', + :provider => "Linode", :linode_api_key => config_val(:linode_api_key) ) end def server_ip_address @@ -85,9 +90,11 @@ end private def validate! + super + if config[:chef_node_name].nil? ui.error "You did not provide a valid --node-name value." exit 1 end if config_val(:platform) == "auto"