Module: Chef::Knife::AcropolisBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



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
# File 'lib/chef/knife/acropolis_base.rb', line 8

def self.included(includer)
    includer.class_eval do
  
      deps do
        require 'chef/knife'
        require 'rest-client'
      end
    
      option :a_host,
      :short => "-H HOST",
      :long => "--acropolis-host HOST",
      :description => "Please enter the IP/hostname of the Nutanix Management API host.",
      :proc => Proc.new { |key| Chef::Config[:knife][:a_host] = key }
  
      option :a_user,
      :short => "-U USER",
      :long => "--acropolis-user USER",
      :description => "Please enter the IP/hostname of the Nutanix Management API host.",
      :proc => Proc.new { |key| Chef::Config[:knife][:a_user] = key }
  
      option :a_pass,
      :short => "-P PASS",
      :long => "--acropolis-password PASS",
      :description => "Please enter the password of the Nutanix Management API user.",
      :proc => Proc.new { |key| Chef::Config[:knife][:a_pass] = key }
  end
end

Instance Method Details

#delete(url, data) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/chef/knife/acropolis_base.rb', line 75

def delete(url,data)
    validate
  base_url = "https://"+ Chef::Config[:knife][:a_host] +":9440/api/nutanix/v0.8"+url
  puts "Trying to connect Acropolis on "+base_url 
  RestClient::Request.execute(
    :method => :delete, 
    :url => base_url + "/" + data,
    #Please note the change in the headers, POST will not work with other options (Error 512).
    :headers => {:accept => :json},
    :headers => {:content_type => :json},
    :user => Chef::Config[:knife][:a_user], 
    :password => Chef::Config[:knife][:a_pass], 
    :verify_ssl => false
    ) 
end

#get(url) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chef/knife/acropolis_base.rb', line 43

def get(url)
  validate
    base_url = "https://"+ Chef::Config[:knife][:a_host] +":9440/api/nutanix/v0.8"+url
    puts "Trying to connect Acropolis on "+base_url 
    RestClient::Request.execute(
      :method => :get, 
      :url => base_url, 
      :content_type => 'json', 
      :accept => 'json', 
      :user => Chef::Config[:knife][:a_user], 
      :password => Chef::Config[:knife][:a_pass], 
      :verify_ssl => false
    ) 
end

#post(url, data) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chef/knife/acropolis_base.rb', line 58

def post(url,data)
validate
  base_url = "https://"+ Chef::Config[:knife][:a_host] +":9440/api/nutanix/v0.8"+url
  puts "Trying to connect Acropolis on "+base_url 
  RestClient::Request.execute(
    :method => :post, 
    :url => base_url, 
    :payload => data,
    #Please note the change in the headers, POST will not work with other options (Error 512).
    :headers => {:accept => :json},
    :headers => {:content_type => :json},
    :user => Chef::Config[:knife][:a_user], 
    :password => Chef::Config[:knife][:a_pass], 
    :verify_ssl => false
    ) 
end

#validateObject



36
37
38
39
40
41
# File 'lib/chef/knife/acropolis_base.rb', line 36

def validate
  unless Chef::Config[:knife][:a_user] && Chef::Config[:knife][:a_pass] && Chef::Config[:knife][:a_host]
    ui.error("Missing Credentials and/or host. Please use --help to see all available options.")
    exit 1
  end
end