Module: Chef::Knife::OvhBase

Included in:
OvhPccTemplateList, OvhPccVmClone, OvhPccVmDelete, OvhPccVmList
Defined in:
lib/chef/knife/ovh_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 :(



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
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/chef/knife/ovh_base.rb', line 18

def self.included(includer)
  includer.class_eval do

    deps do
      require 'socket'
      require 'net/ssh/multi'
      require 'readline'
      require 'chef/json_compat'
    end
    
    option :vsphere_user,
    :short => "-u USERNAME",
    :long => "--user USERNAME",
    :description => "The username for the host"

    option :password,
    :short => "-p PASSWORD",
    :long => "--password PASSWORD",
    :description => "The password for the host"

    option :datacenter,
    :short => "-d DATACENTER",
    :long => "--datacenter DATACENTER",
    :description => "The Datacenter to create the VM in"

    option :path,
    :long => "--path SOAP_PATH",
    :description => "The SOAP endpoint path",
    :proc => Proc.new { |p| Chef::Config[:knife][:path] = p },
    :default => "/sdk"

    option :port,
    :long => "--port PORT",
    :description => "The VI SDK port number to use",
    :proc => Proc.new { |p| Chef::Config[:knife][:port] = p },
    :default => 443

    option :use_ssl,
    :long => "--ssl USE_SSL",
    :description => "Whether to use SSL connection",
    :default => true

    option :insecure,
    :short => "-i USE_INSECURE_SSL",
    :long => "--insecure USE_INSECURE_SSL",
    :description => "Determines whether SSL certificate verification is skipped",
    :default => true
  end
end

Instance Method Details

#fatal_exit(msg) ⇒ Object



102
103
104
105
# File 'lib/chef/knife/ovh_base.rb', line 102

def fatal_exit(msg)
  ui.fatal(msg)
  exit 1
end

#find_all_in_folders(folder, type) ⇒ Object



89
90
91
92
93
# File 'lib/chef/knife/ovh_base.rb', line 89

def find_all_in_folders(folder, type)
  get_folders(folder).
    collect { |f| f.childEntity.grep(type) }.
    flatten
end

#find_in_folders(folder, type, name) ⇒ Object



95
96
97
98
99
100
# File 'lib/chef/knife/ovh_base.rb', line 95

def find_in_folders(folder, type, name)
  get_folders(folder).
    collect { |f| f.childEntity.grep(type) }.
    flatten.
    find { |o| o.name == name }
end

#get_folders(folder) ⇒ Object



85
86
87
# File 'lib/chef/knife/ovh_base.rb', line 85

def get_folders(folder)
  folder.childEntity.grep(RbVmomi::VIM::Folder) << folder
end

#get_vim_connectionObject



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

def get_vim_connection
  
  conn_opts = {
    :host => config[:host] || Chef::Config[:knife][:vsphere_host],
    :path => config[:path],
    :port => config[:port],
    :use_ssl => config[:ssl],
    :user => config[:vsphere_user] || Chef::Config[:knife][:vsphere_user],
    :password => config[:password] || Chef::Config[:knife][:vsphere_pass],
    :insecure => config[:insecure]
  }

  vim = RbVmomi::VIM.connect conn_opts
  
  return vim
end