Class: Bosh::Clouds::Dummy::CommandTransport

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

Overview

Example file system layout for arranging commands information. Currently uses file system as transport but could be switch to use NATS.

base_dir/cpi/create_vm/next -> {"something": true}

Instance Method Summary collapse

Constructor Details

#initialize(base_dir, logger) ⇒ CommandTransport

Returns a new instance of CommandTransport.



479
480
481
482
# File 'lib/cloud/dummy.rb', line 479

def initialize(base_dir, logger)
  @cpi_commands = File.join(base_dir, 'cpi_commands')
  @logger = logger
end

Instance Method Details

#allow_create_vm_to_succeedObject



533
534
535
536
# File 'lib/cloud/dummy.rb', line 533

def allow_create_vm_to_succeed
  @logger.info("Allowing create_vm method to succeed (removing any mandatory failures)")
  FileUtils.rm(failed_path)
end

#make_create_vm_always_failObject



527
528
529
530
531
# File 'lib/cloud/dummy.rb', line 527

def make_create_vm_always_fail
  @logger.info("Making create_vm method always fail")
  FileUtils.mkdir_p(File.dirname(failed_path))
  File.write(failed_path, "")
end

#make_create_vm_always_use_dynamic_ip(ip_address) ⇒ Object



515
516
517
518
519
# File 'lib/cloud/dummy.rb', line 515

def make_create_vm_always_use_dynamic_ip(ip_address)
  @logger.info("Making create_vm method to set ip address #{ip_address}")
  FileUtils.mkdir_p(File.dirname(always_path))
  File.write(always_path, ip_address)
end

#next_create_vm_cmdObject



538
539
540
541
542
543
544
# File 'lib/cloud/dummy.rb', line 538

def next_create_vm_cmd
  @logger.info('Reading create_vm configuration')
  ip_address = File.read(always_path) if File.exists?(always_path)
  azs_to_ip = File.exists?(azs_path) ? JSON.load(File.read(azs_path)) : {}
  failed = File.exists?(failed_path)
  CreateVmCommand.new(ip_address, azs_to_ip, failed)
end

#pause_delete_vmsObject



484
485
486
487
488
489
# File 'lib/cloud/dummy.rb', line 484

def pause_delete_vms
  @logger.info("Pausing delete_vms")
  path = File.join(@cpi_commands, 'pause_delete_vms')
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, 'marker')
end

#set_dynamic_ips_for_azs(az_to_ips) ⇒ Object



521
522
523
524
525
# File 'lib/cloud/dummy.rb', line 521

def set_dynamic_ips_for_azs(az_to_ips)
  @logger.info("Making create_vm method to set #{az_to_ips.inspect}")
  FileUtils.mkdir_p(File.dirname(azs_path))
  File.write(azs_path, JSON.generate(az_to_ips))
end

#unpause_delete_vmsObject



491
492
493
494
495
# File 'lib/cloud/dummy.rb', line 491

def unpause_delete_vms
  @logger.info("Unpausing delete_vms")
  FileUtils.rm_rf File.join(@cpi_commands, 'pause_delete_vms')
  FileUtils.rm_rf File.join(@cpi_commands, 'wait_for_unpause_delete_vms')
end

#wait_for_delete_vmsObject



497
498
499
500
501
# File 'lib/cloud/dummy.rb', line 497

def wait_for_delete_vms
  @logger.info("Wait for delete_vms")
  path = File.join(@cpi_commands, 'wait_for_unpause_delete_vms')
  sleep(0.1) until File.exists?(path)
end

#wait_for_unpause_delete_vmsObject



503
504
505
506
507
508
509
510
511
512
513
# File 'lib/cloud/dummy.rb', line 503

def wait_for_unpause_delete_vms
  path = File.join(@cpi_commands, 'wait_for_unpause_delete_vms')
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, 'marker')

  path = File.join(@cpi_commands, 'pause_delete_vms')
  if File.exists?(path)
    @logger.info("Wait for unpausing delete_vms")
  end
  sleep(0.1) while File.exists?(path)
end