class Chef::Provider::OneVnetLease

Implementation of Provider class.

Attributes

current_vnet[R]

Public Instance Methods

action_handler() click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 33
def action_handler
  @action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
end
exists?() click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 37
def exists?
  new_driver = driver
  filter = { @new_resource.vnet.is_a?(Integer) ? :id : :name => @new_resource.vnet }
  @current_vnet = new_driver.one.get_resource(:virtualnetwork, filter)
  fail "vnet '#{@new_resource.vnet}' does not exist" if @current_vnet.nil?
  @current_vnet.info!
  hash = @current_vnet.to_hash

  lookup = @new_resource.name.include?(':') ? 'MAC' : 'IP'
  ar_pool = [hash['VNET']['AR_POOL']].flatten

  if @new_resource.ar_id && @new_resource.ar_id > -1
    ar_pool = get_ar_pool(ar_pool, @new_resource.ar_id.to_s)
    fail "ar_id not found '#{@new_resource.ar_id}'" if ar_pool.nil?
  end
  lease_available?(ar_pool, lookup)
end

Protected Instance Methods

current_driver() click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 113
def current_driver
  run_context.chef_provisioning.driver_for(run_context.chef_provisioning.current_driver) if run_context.chef_provisioning.current_driver
end
driver() click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 101
def driver
  if current_driver && current_driver.driver_url != new_driver.driver_url
    fail "Cannot move '#{machine_spec.name}' from #{current_driver.driver_url} to #{new_driver.driver_url}: machine moving is not supported.  Destroy and recreate."
  end
  fail "Driver not specified for one_vnet_lease #{new_resource.name}" unless new_driver
  new_driver
end
get_ar_pool(ar_pool, ar_id) click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 81
def get_ar_pool(ar_pool, ar_id)
  ar_pool.each { |a| return [a] if a['AR']['AR_ID'] == ar_id }
  nil
end
lease_available?(ar_pool, lookup) click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 86
def lease_available?(ar_pool, lookup)
  exists = false
  vm = -2
  ar_pool.each do |a|
    next unless a['AR']['LEASES']['LEASE']
    [a['AR']['LEASES']['LEASE']].flatten.each do |l|
      next unless l[lookup] && l[lookup] == @new_resource.name
      exists = true
      vm = l['VM'].to_i
      break
    end
  end
  (exists && vm == -1)
end
new_driver() click to toggle source
# File lib/chef/provider/one_vnet_lease.rb, line 109
def new_driver
  run_context.chef_provisioning.driver_for(new_resource.driver)
end