Module: Chef::Knife::SoftlayerBase

Constant Summary collapse

USER_AGENT =
"Chef Knife Softlayer Plugin #{::Knife::Softlayer::VERSION}"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object

:nodoc:



18
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
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/knife/softlayer_base.rb', line 18

def self.included(includer)
  includer.class_eval do

    deps do
      require 'fog/softlayer'
      require 'net/ssh'
      require 'net/ssh/multi'
      require 'chef/monkey_patches/net-ssh-multi'
      require 'readline'
      require 'chef/exceptions'
      require 'chef/search/query'
      require 'chef/mixin/command'
      require 'chef/mixin/shell_out'
      require 'mixlib/shellout'
      require 'chef/json_compat'
    end

    # Make the base bootstrap options available on topo bootstrap
    self.options = (Chef::Knife::Bootstrap.options).merge(self.options)

    option :softlayer_credential_file,
           :long => "--softlayer-credential-file FILE",
           :description => "File containing SoftLayer credentials as used by `softlayer_api` Ruby gem.",
           :proc => Proc.new { |key| Chef::Config[:knife][:softlayer_credential_file] = key }

    option :softlayer_username,
           :short => "-U USERNAME",
           :long => "--softlayer-username KEY",
           :description => "Your SoftLayer Username",
           :proc => Proc.new { |key| Chef::Config[:knife][:softlayer_access_key_id] = key }

    option :softlayer_api_key,
           :short => "-K SECRET",
           :long => "--softlayer-api-key SECRET",
           :description => "Your SoftLayer API Key",
           :proc => Proc.new { |key| Chef::Config[:knife][:softlayer_secret_access_key] = key }
  end
end

Instance Method Details

#computeObject



65
66
67
68
69
70
71
72
73
# File 'lib/chef/knife/softlayer_base.rb', line 65

def compute
  @compute_connection ||= Fog::Compute.new(
      :provider => :softlayer,
      :softlayer_username => Chef::Config[:knife][:softlayer_username],
      :softlayer_api_key => Chef::Config[:knife][:softlayer_api_key],
      :softlayer_default_datacenter => Chef::Config[:knife][:softlayer_default_datacenter],
      :softlayer_default_domain => Chef::Config[:knife][:softlayer_default_domain],
  )
end

#connection(service = :compute) ⇒ SoftLayer::Service

Returns a connection to a SoftLayer API Service Endpoint.

Parameters:

  • service (Symbol) (defaults to: :compute)

Returns:

  • (SoftLayer::Service)


61
62
63
# File 'lib/chef/knife/softlayer_base.rb', line 61

def connection(service=:compute)
  self.send(service)
end

#locate_config_value(key) ⇒ String

Locates a config value.

Parameters:

  • key (String)

Returns:

  • (String)


87
88
89
90
# File 'lib/chef/knife/softlayer_base.rb', line 87

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

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

A CLI output formatting wrapper.

Parameters:

  • label (String)
  • value (String)
  • color (Symbol) (defaults to: :cyan)

Returns:

  • (String)


98
99
100
101
102
# File 'lib/chef/knife/softlayer_base.rb', line 98

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

#networkObject



75
76
77
78
79
80
81
# File 'lib/chef/knife/softlayer_base.rb', line 75

def network
  @network_connection ||= Fog::Network.new(
    :provider => :softlayer,
    :softlayer_username => Chef::Config[:knife][:softlayer_username],
    :softlayer_api_key => Chef::Config[:knife][:softlayer_api_key],
  )
end