mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(POOLER-142) Add running host to vm API data
This change adds the running host for a VM to the API data available via /vm/hostname. Without this change the running host would be logged to vmpooler log, but not available any other way. Additionally, the data will specify if a machine has been migrated. Without this change parent host data for a vmpooler machine is not available via the vmpooler API.
This commit is contained in:
parent
9d48bc1b7e
commit
9c5a0d114b
7 changed files with 19 additions and 4 deletions
|
|
@ -51,6 +51,7 @@ def create_running_vm(template, name, token = nil, user = nil)
|
|||
redis.sadd("vmpooler__running__#{template}", name)
|
||||
redis.hset("vmpooler__vm__#{name}", 'template', template)
|
||||
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
||||
redis.hset("vmpooler__vm__#{name}", 'host', 'host1')
|
||||
end
|
||||
|
||||
def create_pending_vm(template, name, token = nil)
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ describe Vmpooler::API::V1 do
|
|||
expect(response_body["end_time"]).to eq(current_time.to_datetime.rfc3339)
|
||||
expect(response_body["state"]).to eq("running")
|
||||
expect(response_body["ip"]).to eq("")
|
||||
expect(response_body["host"]).to eq("host1")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ EOT
|
|||
let(:connection_options) {{}}
|
||||
let(:connection) { mock_RbVmomi_VIM_Connection(connection_options) }
|
||||
let(:vmname) { 'vm1' }
|
||||
let(:redis) { MockRedis.new }
|
||||
|
||||
subject { Vmpooler::PoolManager::Provider::VSphere.new(config, logger, metrics, 'vsphere', provider_options) }
|
||||
|
||||
|
|
@ -138,7 +139,6 @@ EOT
|
|||
let(:power_off_task) { mock_RbVmomi_VIM_Task() }
|
||||
let(:destroy_task) { mock_RbVmomi_VIM_Task() }
|
||||
let(:data_ttl) { 1 }
|
||||
let(:redis) { MockRedis.new }
|
||||
let(:finish) { '0.00' }
|
||||
let(:now) { Time.now }
|
||||
|
||||
|
|
@ -2572,6 +2572,7 @@ EOT
|
|||
subject.connection_pool.with_metrics do |pool_object|
|
||||
expect(subject).to receive(:ensured_vsphere_connection).with(pool_object).and_return(connection)
|
||||
expect(subject).to receive(:get_vm_details).and_return(vm_details)
|
||||
allow($redis).to receive(:hset)
|
||||
expect(subject).to receive(:run_select_hosts).with(poolname, {})
|
||||
expect(subject).to receive(:vm_in_target?).and_return false
|
||||
expect(subject).to receive(:migration_enabled?).and_return true
|
||||
|
|
@ -2601,6 +2602,7 @@ EOT
|
|||
subject.connection_pool.with_metrics do |pool_object|
|
||||
expect(subject).to receive(:ensured_vsphere_connection).with(pool_object).and_return(connection)
|
||||
expect(subject).to receive(:get_vm_details).and_return(vm_details)
|
||||
expect($redis).to receive(:hset).with("vmpooler__vm__#{vmname}", 'host', parent_host)
|
||||
expect(subject).to receive(:run_select_hosts).with(poolname, {})
|
||||
expect(subject).to receive(:vm_in_target?).and_return true
|
||||
expect(subject).to receive(:migration_enabled?).and_return true
|
||||
|
|
@ -2690,6 +2692,8 @@ EOT
|
|||
it' migrates a vm' do
|
||||
expect($redis).to receive(:sadd).with('vmpooler__migration', vmname)
|
||||
expect(subject).to receive(:select_next_host).and_return(new_host)
|
||||
expect($redis).to receive(:hset).with("vmpooler__vm__#{vmname}", 'host', new_host)
|
||||
expect($redis).to receive(:hset).with("vmpooler__vm__#{vmname}", 'migrated', true)
|
||||
expect(subject).to receive(:find_host_by_dnsname).and_return(new_host_object)
|
||||
expect(subject).to receive(:migrate_vm_and_record_timing).and_return(format('%.2f', (Time.now - (Time.now - 15))))
|
||||
expect(logger).to receive(:log).with('s', "[>] [#{poolname}] '#{vmname}' migrated from host1 to host2 in 15.00 seconds")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue