Module: Chef::Knife::WhiskBase

Included in:
WhiskGenerate, WhiskMixinList, WhiskMixinShow, WhiskServerList, WhiskServerShow
Defined in:
lib/chef/knife/knife-whisk.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
29
30
31
32
33
34
35
# File 'lib/chef/knife/knife-whisk.rb', line 7

def self.included(includer)
  includer.class_eval do

    option :whisk_config_file,
      :short => '-C PATH',
      :long => '--whisk-config PATH',
      :description => "Specify path to your whisk.yml file",
      :proc => Proc.new { |path| Chef::Config[:knife][:whisk_config_file] = path }
    
    option :mixins,
      :short => '-M MIXINS',
      :long => '--mixins MIXINS',
      :description => "Overrides server mixins, takes comma seperated list of mixins",
      :proc => Proc.new { |input| input.split(",") }
    
    option :overrides,
      :short => '-O STRING',
      :long => '--overrides STRING',
      :description => "Override flags, takes string containing flags and values",
      :proc => Proc.new { |string|
        # checks if the flags have -- in front, if not error, if so strip them before returning
        if Hash[*string.split].keys.select { |n| n[0..1] != "--" }.size == 0
          Hash[Hash[*string.split].map {|key, val|[key.sub(/^--/, ''), val]}]
        else
          false
        end
      }
  end
end

Instance Method Details

#add_quotes(val) ⇒ Object



70
71
72
# File 'lib/chef/knife/knife-whisk.rb', line 70

def add_quotes(val)
  "\"#{val}\""
end

#exit_with_message(message) ⇒ Object



37
38
39
40
# File 'lib/chef/knife/knife-whisk.rb', line 37

def exit_with_message(message)
  ui.fatal message 
  Kernel.exit(1) 
end

#get_configObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef/knife/knife-whisk.rb', line 42

def get_config
  if Chef::Config[:knife][:whisk_config_file].nil?
    if File.exists?(::Chef::Knife::chef_config_dir+"/whisk.yml")
      YAML.load_file(::Chef::Knife::chef_config_dir+"/whisk.yml")
    else
      return false
    end
  else
    YAML.load_file(Chef::Config[:knife][:whisk_config_file])
  end
end

#get_security_groups(groups) ⇒ Object



54
55
56
# File 'lib/chef/knife/knife-whisk.rb', line 54

def get_security_groups(groups)
  groups.split(',').map! { |name| name.replace(get_config["provider_config"]["aws"]["security-groups"][name]) }.join(',')
end

#mixin_exists?(mixin) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/chef/knife/knife-whisk.rb', line 62

def mixin_exists?(mixin)
  ! get_config["mixins"][mixin].nil?
end

#security_group_exists?(group) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/chef/knife/knife-whisk.rb', line 58

def security_group_exists?(group) 
  ! get_config["provider_config"]["aws"]["security-groups"][group].nil?
end

#server_exists?(server) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/chef/knife/knife-whisk.rb', line 66

def server_exists?(server)
  ! get_config["servers"][server].nil?
end