Module: Chef::Knife::GlesysBase

Included in:
GlesysServerCreate, GlesysServerDelete, GlesysServerInfo, GlesysServerList, GlesysTemplateList
Defined in:
lib/chef/knife/glesys_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chef/knife/glesys_base.rb', line 7

def self.included(includer)
  includer.class_eval do

    deps do
      require 'fog'
      require 'readline'
      require 'chef/json_compat'
    end

    option :glesys_api_key,
      :short => "-A KEY",
      :long => "--glesys-api-key KEY",
      :description => "Your Glesys API key",
      :proc => Proc.new { |key| Chef::Config[:knife][:glesys_api_key] = key }

    option :glesys_username,
      :short => "-U USERNAME",
      :long => "--glesys-username USERNAME",
      :description => "Your Glesysusername",
      :proc => Proc.new { |key| Chef::Config[:knife][:glesys_username] = key }
  end
end

Instance Method Details

#color_state(state) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/knife/glesys_base.rb', line 51

def color_state(state)

  return ui.color("unknown", :cyan) if state.nil?

  case state.to_s.downcase
    when 'shutting-down','terminated','stopping','stopped' then ui.color(state, :red)
    when 'pending', 'locked' then ui.color(state, :yellow)
    else ui.color(state, :green)
  end

end

#connectionObject



30
31
32
33
34
35
36
37
38
# File 'lib/chef/knife/glesys_base.rb', line 30

def connection
  @connection ||= begin
    connection = Fog::Compute.new(
      :provider        => 'Glesys',
      :glesys_api_key  => Chef::Config[:knife][:glesys_api_key],
      :glesys_username => Chef::Config[:knife][:glesys_username],
    )
  end
end

#locate_config_value(key) ⇒ Object



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

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

#msg_pair(label, value, color = :cyan) ⇒ Object



40
41
42
43
44
# File 'lib/chef/knife/glesys_base.rb', line 40

def msg_pair(label, value, color=:cyan)
  if value && !value.to_s.empty?
    puts "#{ui.color(label, color)}: #{value}"
  end
end

#validate!Object



63
64
# File 'lib/chef/knife/glesys_base.rb', line 63

def validate!
end