Module: Chef::Knife::VoxelBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



6
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
36
37
# File 'lib/chef/knife/voxel_base.rb', line 6

def self.included(includer)
  includer.class_eval do

    deps do
      require 'hapi'
    end

    option :voxel_api_key,
      :short       => "-K KEY",
      :long        => "--voxel-api-key KEY",
      :description => "Voxel hAPI Key",
      :proc        => Proc.new { |key| Chef::Config[:knife][:voxel_api_key] = key }

    option :voxel_api_secret,
      :short       => "-S SECRET",
      :long        => "--voxel-api-secret SECRET",
      :description => "Voxel hAPI Secret",
      :proc        => Proc.new { |secret| Chef::Config[:knife][:voxel_api_secret] = secret }

    option :voxel_api_username,
      :long        => "--voxel-api-username USERNAME",
      :description => "Voxel hAPI Username",
      :proc        => Proc.new { |username| Chef::Config[:knife][:voxel_api_username] = username }

    option :voxel_api_password,
      :long        => "--voxel-api-password PASSWORD",
      :description => "Voxel hAPI Password",
      :proc        => Proc.new { |password| Chef::Config[:knife][:voxel_api_password] = password }


  end
end

Instance Method Details

#hapiObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/chef/knife/voxel_base.rb', line 39

def hapi
  @hapi ||= begin
    if Chef::Config[:knife].has_key?(:voxel_api_username)
      unless Chef::Config[:knife].has_key?(:voxel_api_password)
        ui.error( "--voxel-api-password is required when using --voxel-api-username" )
        exit 1
      end

      hapi = HAPI.new(
        :useauthkey     => false,
        :username       => Chef::Config[:knife][:voxel_api_username],
        :password       => Chef::Config[:knife][:voxel_api_password],
        :default_format => :ruby,
        :debug          => false
      )
    elsif Chef::Config[:knife].has_key?(:voxel_api_key)
      unless Chef::Config[:knife].has_key?(:voxel_api_secret)
        ui.error( "--voxel-api-secret is required when using --voxel-api-key" )
        exit 1
      end

      hapi = HAPI.new(
        :useauthkey     => true,
        :username       => Chef::Config[:knife][:voxel_api_key],
        :password       => Chef::Config[:knife][:voxel_api_secret],
        :default_format => :ruby,
        :debug          => false
      )
    else
      ui.error( "--voxel-api-key or --voxel-api-username must be specified" )
      exit 1
    end
  end
end