Class: Bosh::Clouds::Dummy
Defined Under Namespace
Classes: CommandTransport, ConfigureNetworksCommand, CreateVmCommand, NotImplemented
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
- #agent_log_path(agent_id) ⇒ Object
- #attach_disk(vm_id, disk_id) ⇒ Object
- #configure_networks(vm_id, networks) ⇒ Object
- #create_disk(size, cloud_properties, vm_locality = nil) ⇒ Object
- #create_stemcell(image, _) ⇒ Object
-
#create_vm(agent_id, stemcell, resource_pool, networks, disk_locality = nil, env = nil) ⇒ Object
rubocop:disable ParameterLists.
- #delete_disk(disk_id) ⇒ Object
- #delete_snapshot(snapshot_id) ⇒ Object
- #delete_stemcell(stemcell_cid) ⇒ Object
- #delete_vm(vm_name) ⇒ Object
- #detach_disk(vm_id, disk_id) ⇒ Object
- #disk_cids ⇒ Object
- #has_disk?(disk_id) ⇒ Boolean
- #has_vm?(vm_id) ⇒ Boolean
-
#initialize(options) ⇒ Dummy
constructor
A new instance of Dummy.
- #kill_agents ⇒ Object
- #reboot_vm(vm_id) ⇒ Object
- #set_vm_metadata(vm, metadata) ⇒ Object
- #snapshot_disk(_, metadata) ⇒ Object
-
#vm_cids ⇒ Object
Additional Dummy test helpers.
Constructor Details
#initialize(options) ⇒ Dummy
Returns a new instance of Dummy.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cloud/dummy.rb', line 12 def initialize() @options = @base_dir = ['dir'] if @base_dir.nil? raise ArgumentError, 'Must specify dir' end @running_vms_dir = File.join(@base_dir, 'running_vms') @logger = Logging::Logger.new('DummyCPI') @logger.add_appenders(Logging.appenders.io( 'DummyCPIIO', ['log_buffer'] || STDOUT )) @commands = CommandTransport.new(@base_dir, @logger) FileUtils.mkdir_p(@base_dir) rescue Errno::EACCES raise ArgumentError, "cannot create dummy cloud base directory #{@base_dir}" end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
10 11 12 |
# File 'lib/cloud/dummy.rb', line 10 def commands @commands end |
Instance Method Details
#agent_log_path(agent_id) ⇒ Object
172 173 174 |
# File 'lib/cloud/dummy.rb', line 172 def agent_log_path(agent_id) "#{@base_dir}/agent.#{agent_id}.log" end |
#attach_disk(vm_id, disk_id) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cloud/dummy.rb', line 105 def attach_disk(vm_id, disk_id) file = (vm_id, disk_id) FileUtils.mkdir_p(File.dirname(file)) FileUtils.touch(file) agent_id = agent_id_for_vm_id(vm_id) settings = read_agent_settings(agent_id) settings['disks']['persistent'][disk_id] = 'attached' write_agent_settings(agent_id, settings) end |
#configure_networks(vm_id, networks) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cloud/dummy.rb', line 94 def configure_networks(vm_id, networks) cmd = commands.next_configure_networks_cmd(vm_id) # The only configure_networks test so far only tests the negative case. # If a positive case is added, the agent will need to be re-started. # Normally runit would handle that. if cmd.not_supported || true raise NotSupported, 'Dummy CPI was configured to return NotSupported' end end |
#create_disk(size, cloud_properties, vm_locality = nil) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/cloud/dummy.rb', line 125 def create_disk(size, cloud_properties, vm_locality = nil) disk_id = SecureRandom.hex file = disk_file(disk_id) FileUtils.mkdir_p(File.dirname(file)) File.write(file, size.to_s) disk_id end |
#create_stemcell(image, _) ⇒ Object
35 36 37 38 39 |
# File 'lib/cloud/dummy.rb', line 35 def create_stemcell(image, _) stemcell_id = Digest::SHA1.hexdigest(File.read(image)) File.write(stemcell_file(stemcell_id), image) stemcell_id end |
#create_vm(agent_id, stemcell, resource_pool, networks, disk_locality = nil, env = nil) ⇒ Object
rubocop:disable ParameterLists
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cloud/dummy.rb', line 46 def create_vm(agent_id, stemcell, resource_pool, networks, disk_locality = nil, env = nil) # rubocop:enable ParameterLists @logger.info('Dummy: create_vm') cmd = commands.next_create_vm_cmd write_agent_default_network(agent_id, cmd.ip_address) if cmd.ip_address write_agent_settings(agent_id, { agent_id: agent_id, blobstore: @options['agent']['blobstore'], ntp: [], disks: { persistent: {} }, networks: networks, vm: { name: "vm-#{agent_id}" }, mbus: @options['nats'], }) agent_pid = spawn_agent_process(agent_id) FileUtils.mkdir_p(@running_vms_dir) File.write(vm_file(agent_pid), agent_id) agent_pid.to_s end |
#delete_disk(disk_id) ⇒ Object
133 134 135 |
# File 'lib/cloud/dummy.rb', line 133 def delete_disk(disk_id) FileUtils.rm(disk_file(disk_id)) end |
#delete_snapshot(snapshot_id) ⇒ Object
145 146 147 |
# File 'lib/cloud/dummy.rb', line 145 def delete_snapshot(snapshot_id) FileUtils.rm(snapshot_file(snapshot_id)) end |
#delete_stemcell(stemcell_cid) ⇒ Object
41 42 43 |
# File 'lib/cloud/dummy.rb', line 41 def delete_stemcell(stemcell_cid) FileUtils.rm(stemcell_file(stemcell_cid)) end |
#delete_vm(vm_name) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/cloud/dummy.rb', line 72 def delete_vm(vm_name) agent_pid = vm_name.to_i Process.kill('INT', agent_pid) # rubocop:disable HandleExceptions rescue Errno::ESRCH # rubocop:enable HandleExceptions ensure FileUtils.rm_rf(File.join(@base_dir, 'running_vms', vm_name)) end |
#detach_disk(vm_id, disk_id) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/cloud/dummy.rb', line 116 def detach_disk(vm_id, disk_id) FileUtils.rm((vm_id, disk_id)) agent_id = agent_id_for_vm_id(vm_id) settings = read_agent_settings(agent_id) settings['disks']['persistent'].delete(disk_id) write_agent_settings(agent_id, settings) end |
#disk_cids ⇒ Object
156 157 158 159 |
# File 'lib/cloud/dummy.rb', line 156 def disk_cids # Shuffle so that no one relies on the order of disks Dir.glob(disk_file('*')).map { |disk| File.basename(disk) }.shuffle end |
#has_disk?(disk_id) ⇒ Boolean
90 91 92 |
# File 'lib/cloud/dummy.rb', line 90 def has_disk?(disk_id) File.exists?(disk_file(disk_id)) end |
#has_vm?(vm_id) ⇒ Boolean
86 87 88 |
# File 'lib/cloud/dummy.rb', line 86 def has_vm?(vm_id) File.exists?(vm_file(vm_id)) end |
#kill_agents ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/cloud/dummy.rb', line 161 def kill_agents vm_cids.each do |agent_pid| begin Process.kill('INT', agent_pid.to_i) # rubocop:disable HandleExceptions rescue Errno::ESRCH # rubocop:enable HandleExceptions end end end |
#reboot_vm(vm_id) ⇒ Object
82 83 84 |
# File 'lib/cloud/dummy.rb', line 82 def reboot_vm(vm_id) raise NotImplemented, 'Dummy CPI does not implement reboot_vm' end |
#set_vm_metadata(vm, metadata) ⇒ Object
176 |
# File 'lib/cloud/dummy.rb', line 176 def (vm, ); end |
#snapshot_disk(_, metadata) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/cloud/dummy.rb', line 137 def snapshot_disk(_, ) snapshot_id = SecureRandom.hex file = snapshot_file(snapshot_id) FileUtils.mkdir_p(File.dirname(file)) File.write(file, .to_json) snapshot_id end |
#vm_cids ⇒ Object
Additional Dummy test helpers
151 152 153 154 |
# File 'lib/cloud/dummy.rb', line 151 def vm_cids # Shuffle so that no one relies on the order of VMs Dir.glob(File.join(@running_vms_dir, '*')).map { |vm| File.basename(vm) }.shuffle end |