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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cloud/dummy.rb', line 13 def initialize() = @base_dir = ['dir'] if @base_dir.nil? raise ArgumentError, 'Must specify dir' end @running_vms_dir = File.join(@base_dir, 'running_vms') @logger = MonoLogger.new(['log_device'] || 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.
11 12 13 |
# File 'lib/cloud/dummy.rb', line 11 def commands @commands end |
Instance Method Details
#agent_log_path(agent_id) ⇒ Object
169 170 171 |
# File 'lib/cloud/dummy.rb', line 169 def agent_log_path(agent_id) "#{@base_dir}/agent.#{agent_id}.log" end |
#attach_disk(vm_id, disk_id) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cloud/dummy.rb', line 102 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
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cloud/dummy.rb', line 91 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
122 123 124 125 126 127 128 |
# File 'lib/cloud/dummy.rb', line 122 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
32 33 34 35 36 |
# File 'lib/cloud/dummy.rb', line 32 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cloud/dummy.rb', line 43 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: ['agent']['blobstore'], ntp: [], disks: { persistent: {} }, networks: networks, vm: { name: "vm-#{agent_id}" }, mbus: ['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
130 131 132 |
# File 'lib/cloud/dummy.rb', line 130 def delete_disk(disk_id) FileUtils.rm(disk_file(disk_id)) end |
#delete_snapshot(snapshot_id) ⇒ Object
142 143 144 |
# File 'lib/cloud/dummy.rb', line 142 def delete_snapshot(snapshot_id) FileUtils.rm(snapshot_file(snapshot_id)) end |
#delete_stemcell(stemcell_cid) ⇒ Object
38 39 40 |
# File 'lib/cloud/dummy.rb', line 38 def delete_stemcell(stemcell_cid) FileUtils.rm(stemcell_file(stemcell_cid)) end |
#delete_vm(vm_name) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/cloud/dummy.rb', line 69 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
113 114 115 116 117 118 119 120 |
# File 'lib/cloud/dummy.rb', line 113 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
153 154 155 156 |
# File 'lib/cloud/dummy.rb', line 153 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
87 88 89 |
# File 'lib/cloud/dummy.rb', line 87 def has_disk?(disk_id) File.exists?(disk_file(disk_id)) end |
#has_vm?(vm_id) ⇒ Boolean
83 84 85 |
# File 'lib/cloud/dummy.rb', line 83 def has_vm?(vm_id) File.exists?(vm_file(vm_id)) end |
#kill_agents ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/cloud/dummy.rb', line 158 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
79 80 81 |
# File 'lib/cloud/dummy.rb', line 79 def reboot_vm(vm_id) raise NotImplemented, 'Dummy CPI does not implement reboot_vm' end |
#set_vm_metadata(vm, metadata) ⇒ Object
173 |
# File 'lib/cloud/dummy.rb', line 173 def (vm, ); end |
#snapshot_disk(_, metadata) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/cloud/dummy.rb', line 134 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
148 149 150 151 |
# File 'lib/cloud/dummy.rb', line 148 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 |