Class: Chef::Provider::OneVnetLease

Inherits:
LWRPBase
  • Object
show all
Defined in:
lib/chef/provider/one_vnet_lease.rb

Overview

Implementation of Provider class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_vnetObject (readonly)

Returns the value of attribute current_vnet.



31
32
33
# File 'lib/chef/provider/one_vnet_lease.rb', line 31

def current_vnet
  @current_vnet
end

Instance Method Details

#action_handlerObject



33
34
35
# File 'lib/chef/provider/one_vnet_lease.rb', line 33

def action_handler
  @action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
end

#exists?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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