Module: Chef::Provisioning::OpenNebulaDriver

Defined in:
lib/chef/provisioning/opennebula_driver/driver.rb,
lib/chef/provisioning/opennebula_driver/one_lib.rb,
lib/chef/provisioning/opennebula_driver/version.rb,
lib/chef/provisioning/opennebula_driver/flow_lib.rb,
lib/chef/provisioning/opennebula_driver/credentials.rb

Overview

Extending module.

Defined Under Namespace

Classes: Credentials, Driver, FlowLib, OneLib, OpenNebulaException

Constant Summary collapse

VERSION =
'0.4.6'.freeze

Class Method Summary collapse

Class Method Details

.get_onelib(args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/chef/provisioning/opennebula_driver/driver.rb', line 68

def self.get_onelib(args)
  endpoint = args[:endpoint]
  credentials = args[:credentials]
  options = args[:options] || {}
  if args[:driver_url]
    fail "OpenNebula driver_url cannot be #{args[:driver_url].class}, it must be a String" unless args[:driver_url].is_a?(String)
    endpoint, profile = Chef::Provisioning::OpenNebulaDriver.match_driver_url(args[:driver_url])
    one_profile = Chef::Provisioning::OpenNebulaDriver::Credentials.new[profile]
    credentials = one_profile[:credentials]
    options = one_profile[:options] || {}
  end
  fail "OpenNebula credentials cannot be #{credentials.class}, it must be a String" unless credentials.is_a?(String)
  fail "OpenNebula endpoint cannot be #{endpoint.class}, it must be a String" unless endpoint.is_a?(String)
  fail "OpenNebula options cannot be #{options.class}, it must be a Hash" unless options.is_a?(Hash)
  server_version, = Open3.capture2e("ruby #{File.dirname(__FILE__)}/../driver_init/server_version.rb #{endpoint} #{credentials} #{options.to_json.inspect}")
  server_version.strip!
  fail server_version unless server_version =~ /^\d+\.\d+(?:\.\d+)?$/
  begin
    gem 'opennebula', "~> #{server_version}"
    require 'opennebula'
  rescue Gem::LoadError => e
    e_inspect = e.inspect
    raise e unless e_inspect.include?('already activated')
  end
  require 'chef/provisioning/opennebula_driver/one_lib'
  gem_version = Gem.loaded_specs['opennebula'].version.to_s
  if gem_version == server_version
    Chef::Log.debug("You are using OpenNebula gem version #{gem_version} against OpenNebula server version #{server_version}")
  else
    Chef::Log.warn('OPENNEBULA GEM / SERVER VERSION MISMATCH')
    Chef::Log.warn("You are using OpenNebula gem version #{gem_version} against OpenNebula server version #{server_version}")
    Chef::Log.warn('Users may experience issues with this gem.')
  end
  OneLib.new(:credentials => credentials, :endpoint => endpoint, :options => options)
end

.match_driver_url(url, allow_nil_profile = false) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/chef/provisioning/opennebula_driver/driver.rb', line 58

def self.match_driver_url(url, allow_nil_profile = false)
  scan = url.match(%r/opennebula:(https?:\/\/[^:\/]+ (?::[0-9]{2,5})? (?:\/[^:\s]+) ) :?([^:\s]+)?/x)
  fail "'driver_url' option has invalid format: #{url}" if scan.nil?
  endpoint = scan[1]
  profile = scan[2]
  fail "'driver_url' option is missing an endpoint: #{url}" if endpoint.nil?
  fail "'driver_url' option is missing a profile: #{url}" if profile.nil? && !allow_nil_profile
  [endpoint, profile]
end