Class: Bosh::Clouds::Dummy::VMRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/dummy.rb

Instance Method Summary collapse

Constructor Details

#initialize(running_vms_dir) ⇒ VMRepo

Returns a new instance of VMRepo.



619
620
621
622
# File 'lib/cloud/dummy.rb', line 619

def initialize(running_vms_dir)
  @running_vms_dir = running_vms_dir
  FileUtils.mkdir_p(@running_vms_dir)
end

Instance Method Details

#exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


629
630
631
# File 'lib/cloud/dummy.rb', line 629

def exists?(id)
  File.exists?(vm_file(id))
end

#load(id) ⇒ Object



624
625
626
627
# File 'lib/cloud/dummy.rb', line 624

def load(id)
  attrs = JSON.parse(File.read(vm_file(id)))
  VM.new(id, attrs.fetch('agent_id'), attrs.fetch('cloud_properties'), attrs.fetch('ips'))
end

#save(vm) ⇒ Object



633
634
635
636
637
638
639
640
641
# File 'lib/cloud/dummy.rb', line 633

def save(vm)
  serialized_vm = JSON.dump({
      'agent_id' => vm.agent_id,
      'cloud_properties' => vm.cloud_properties,
      'ips' => vm.ips,
    })

  File.write(vm_file(vm.id), serialized_vm)
end