Module: Chef::Knife::SlBase

Included in:
SlFirewallList, SlServerList
Defined in:
lib/chef/knife/sl_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object

:nodoc: Would prefer to do this in a rational way, but can’t be done b/c of Mixlib::CLI’s design :(



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/knife/sl_base.rb', line 29

def self.included(includer)
  includer.class_eval do

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

    option :sl_api_username,
      :short => "-A ID",
      :long => "--sl_api_username USERNAME",
      :description => "Your SoftLayer Username",
      :proc => Proc.new { |key| Chef::Config[:knife][:sl_api_username] = key }

    option :sl_api_key,
      :short => "-K KEY",
      :long => "--sl_api_key KEY",
      :description => "Your SoftLayer API Key",
      :proc => Proc.new { |key| Chef::Config[:knife][:sl_api_key] = key }
      
    option :sl_domain,
      :short => "-D DOMAIN",
      :long => "--domain DOMAIN",
      :description => "Your SoftLayer Domain",
      :proc => Proc.new { |key| Chef::Config[:knife][:sl_domain] = key }

  end
end

Instance Method Details

#connection(sl_service = "SoftLayer_Account") ⇒ Object



59
60
61
62
63
64
65
# File 'lib/chef/knife/sl_base.rb', line 59

def connection(sl_service = "SoftLayer_Account")
  @connection = SoftLayer::Service.new(
    sl_service,
    :username => locate_config_value(:sl_api_username),
    :api_key => locate_config_value(:sl_api_key)
  )
end

#current_domainObject



82
83
84
# File 'lib/chef/knife/sl_base.rb', line 82

def current_domain
  Chef::Config[:knife][:sl_domain]
end

#list_firewallsObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/chef/knife/sl_base.rb', line 96

def list_firewalls
  object_mask = {
    "networkVlans" => {
      "firewallInterfaces" => ""
    }
  }
  
  firewalls = connection.object_mask(object_mask).getNetworkVlans
  
  active_firewalls = []
  
  firewalls.each do |firewall|
    active_firewalls << firewall if firewall['firewallInterfaces'] != []
  end
  
  return active_firewalls
end

#list_vlansObject



86
87
88
89
90
91
92
93
94
# File 'lib/chef/knife/sl_base.rb', line 86

def list_vlans
  object_mask = {
    "networkVlans" => ""
  }
  
  vlans = connection.object_mask(object_mask).getNetworkVlans
  
  return vlans
end

#locate_config_value(key) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/chef/knife/sl_base.rb', line 67

def locate_config_value(key)
  key = key.to_sym
  set_key = ["set_", key].join.to_sym
  
  ret = Chef::Config[:knife][set_key].nil? ? Chef::Config[:knife][key] : Chef::Config[:knife][set_key]
  ret = ret.nil? ? config[key] : ret
  
  if (ret.nil?)
    ui.error("Required configuration variable not set: #{key}")
    exit 1
  end
  
  return ret
end