Class: VSphereCloud::VMAttributeManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/vsphere/drs_rules/vm_attribute_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(custom_fields_manager, logger) ⇒ VMAttributeManager

Returns a new instance of VMAttributeManager.



3
4
5
6
# File 'lib/cloud/vsphere/drs_rules/vm_attribute_manager.rb', line 3

def initialize(custom_fields_manager, logger)
  @custom_fields_manager = custom_fields_manager
  @logger = logger
end

Instance Method Details

#create(name) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/cloud/vsphere/drs_rules/vm_attribute_manager.rb', line 12

def create(name)
  @logger.debug("Creating DRS rule attribute: #{name}")
  @custom_fields_manager.add_field_definition(
    name,
    VimSdk::Vim::VirtualMachine,
    policy,
    policy
  )
end

#delete(name) ⇒ Object



22
23
24
25
26
# File 'lib/cloud/vsphere/drs_rules/vm_attribute_manager.rb', line 22

def delete(name)
  @logger.debug("Deleting DRS rule attribute: #{name}")
  custom_field = find_by_name(name)
  @custom_fields_manager.remove_field_definition(custom_field.key) if custom_field
end

#find_by_name(name) ⇒ Object



8
9
10
# File 'lib/cloud/vsphere/drs_rules/vm_attribute_manager.rb', line 8

def find_by_name(name)
  @custom_fields_manager.field.find { |f| f.name == name }
end