Module: Chef::Knife::DigitalOceanBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chef/knife/digital_ocean_base.rb', line 19

def self.included(includer)
  includer.class_eval do
    category 'digital_ocean'

    deps do
      require 'digital_ocean'
      require 'highline'
      require 'net/ssh/multi'
      require 'readline'
      require 'chef/json_compat'
      require 'chef/knife/bootstrap'
      Chef::Knife::Bootstrap.load_deps
    end

    option :digital_ocean_client_id,
      :short       => '-K CLIENT_ID',
      :long        => '--digital_ocean_client_id CLIENT_ID',
      :description => 'Your DigitalOcean client_id',
      :proc        => Proc.new { |client_id| Chef::Config[:knife][:digital_ocean_client_id] = client_id }

    option :digital_ocean_api_key,
      :short       => '-A API_KEY',
      :long        => '--digital_ocean_api_key API_KEY',
      :description => 'Your DigitalOcean API_KEY',
      :proc        => Proc.new { |api_key| Chef::Config[:knife][:digital_ocean_api_key] = api_key }
  end
end

Instance Method Details

#clientObject



51
52
53
54
# File 'lib/chef/knife/digital_ocean_base.rb', line 51

def client
  DigitalOcean::API.new(:client_id => Chef::Config[:knife][:digital_ocean_client_id],
                        :api_key   => Chef::Config[:knife][:digital_ocean_api_key])
end

#hObject



47
48
49
# File 'lib/chef/knife/digital_ocean_base.rb', line 47

def h
  @highline ||= HighLine.new
end

#locate_config_value(key) ⇒ Object



70
71
72
73
# File 'lib/chef/knife/digital_ocean_base.rb', line 70

def locate_config_value(key)
  key = key.to_sym
  config[key] || Chef::Config[:knife][key]
end

#validate!(keys = [:digital_ocean_client_id, :digital_ocean_api_key]) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/knife/digital_ocean_base.rb', line 56

def validate!(keys=[:digital_ocean_client_id, :digital_ocean_api_key])
  errors = []

  keys.each do |k|
    if locate_config_value(k).nil?
      errors << "You did not provide a valid '#{k}' value. Please set knife[:#{k}] in your knife.rb or pass as an option."
    end
  end

  if errors.each{|e| ui.error(e)}.any?
    exit 1
  end
end