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
|
|
@ -13,7 +13,8 @@ git logs & PR history.
|
||||||
# [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.6.3...master)
|
# [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.6.3...master)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Add capability to disable linked clones for vsphere provider
|
- Add capability to disable linked clones for vsphere provider (POOLER-147)
|
||||||
|
- Add running host to VM data returned from /vm/hostname (POOLER-142)
|
||||||
|
|
||||||
# [0.6.3](https://github.com/puppetlabs/vmpooler/compare/0.6.2...0.6.3)
|
# [0.6.3](https://github.com/puppetlabs/vmpooler/compare/0.6.2...0.6.3)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,9 @@ $ curl --url vmpooler.example.com/api/v1/vm/pxpmtoonx7fiqg6
|
||||||
"user": "jdoe"
|
"user": "jdoe"
|
||||||
},
|
},
|
||||||
"ip": "192.168.0.1",
|
"ip": "192.168.0.1",
|
||||||
"domain": "example.com"
|
"domain": "example.com",
|
||||||
|
"host": "host1.example.com",
|
||||||
|
"migrated": "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -829,6 +829,10 @@ module Vmpooler
|
||||||
if config['domain']
|
if config['domain']
|
||||||
result[params[:hostname]]['domain'] = config['domain']
|
result[params[:hostname]]['domain'] = config['domain']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result[params[:hostname]]['host'] = rdata['host'] if rdata['host']
|
||||||
|
result[params[:hostname]]['migrated'] = rdata['migrated'] if rdata['migrated']
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
|
|
|
||||||
|
|
@ -939,6 +939,7 @@ module Vmpooler
|
||||||
begin
|
begin
|
||||||
connection = ensured_vsphere_connection(pool_object)
|
connection = ensured_vsphere_connection(pool_object)
|
||||||
vm_hash = get_vm_details(pool_name, vm_name, connection)
|
vm_hash = get_vm_details(pool_name, vm_name, connection)
|
||||||
|
$redis.hset("vmpooler__vm__#{vm_name}", 'host', vm_hash['host_name'])
|
||||||
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
|
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
|
||||||
migration_count = $redis.scard('vmpooler__migration')
|
migration_count = $redis.scard('vmpooler__migration')
|
||||||
if migration_enabled? @config
|
if migration_enabled? @config
|
||||||
|
|
@ -965,9 +966,10 @@ module Vmpooler
|
||||||
def migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
|
def migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
|
||||||
$redis.sadd('vmpooler__migration', vm_name)
|
$redis.sadd('vmpooler__migration', vm_name)
|
||||||
target_host_name = select_next_host(pool_name, @provider_hosts, vm_hash['architecture'])
|
target_host_name = select_next_host(pool_name, @provider_hosts, vm_hash['architecture'])
|
||||||
|
$redis.hset("vmpooler__vm__#{vm_name}", 'host', target_host_name)
|
||||||
|
$redis.hset("vmpooler__vm__#{vm_name}", 'migrated', true)
|
||||||
target_host_object = find_host_by_dnsname(connection, target_host_name)
|
target_host_object = find_host_by_dnsname(connection, target_host_name)
|
||||||
finish = migrate_vm_and_record_timing(pool_name, vm_name, vm_hash, target_host_object, target_host_name)
|
finish = migrate_vm_and_record_timing(pool_name, vm_name, vm_hash, target_host_object, target_host_name)
|
||||||
#logger.log('s', "Provider_hosts is: #{provider.provider_hosts}")
|
|
||||||
logger.log('s', "[>] [#{pool_name}] '#{vm_name}' migrated from #{vm_hash['host_name']} to #{target_host_name} in #{finish} seconds")
|
logger.log('s', "[>] [#{pool_name}] '#{vm_name}' migrated from #{vm_hash['host_name']} to #{target_host_name} in #{finish} seconds")
|
||||||
ensure
|
ensure
|
||||||
$redis.srem('vmpooler__migration', vm_name)
|
$redis.srem('vmpooler__migration', vm_name)
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ def create_running_vm(template, name, token = nil, user = nil)
|
||||||
redis.sadd("vmpooler__running__#{template}", name)
|
redis.sadd("vmpooler__running__#{template}", name)
|
||||||
redis.hset("vmpooler__vm__#{name}", 'template', template)
|
redis.hset("vmpooler__vm__#{name}", 'template', template)
|
||||||
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
||||||
|
redis.hset("vmpooler__vm__#{name}", 'host', 'host1')
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_pending_vm(template, name, token = nil)
|
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["end_time"]).to eq(current_time.to_datetime.rfc3339)
|
||||||
expect(response_body["state"]).to eq("running")
|
expect(response_body["state"]).to eq("running")
|
||||||
expect(response_body["ip"]).to eq("")
|
expect(response_body["ip"]).to eq("")
|
||||||
|
expect(response_body["host"]).to eq("host1")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ EOT
|
||||||
let(:connection_options) {{}}
|
let(:connection_options) {{}}
|
||||||
let(:connection) { mock_RbVmomi_VIM_Connection(connection_options) }
|
let(:connection) { mock_RbVmomi_VIM_Connection(connection_options) }
|
||||||
let(:vmname) { 'vm1' }
|
let(:vmname) { 'vm1' }
|
||||||
|
let(:redis) { MockRedis.new }
|
||||||
|
|
||||||
subject { Vmpooler::PoolManager::Provider::VSphere.new(config, logger, metrics, 'vsphere', provider_options) }
|
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(:power_off_task) { mock_RbVmomi_VIM_Task() }
|
||||||
let(:destroy_task) { mock_RbVmomi_VIM_Task() }
|
let(:destroy_task) { mock_RbVmomi_VIM_Task() }
|
||||||
let(:data_ttl) { 1 }
|
let(:data_ttl) { 1 }
|
||||||
let(:redis) { MockRedis.new }
|
|
||||||
let(:finish) { '0.00' }
|
let(:finish) { '0.00' }
|
||||||
let(:now) { Time.now }
|
let(:now) { Time.now }
|
||||||
|
|
||||||
|
|
@ -2572,6 +2572,7 @@ EOT
|
||||||
subject.connection_pool.with_metrics do |pool_object|
|
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(:ensured_vsphere_connection).with(pool_object).and_return(connection)
|
||||||
expect(subject).to receive(:get_vm_details).and_return(vm_details)
|
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(:run_select_hosts).with(poolname, {})
|
||||||
expect(subject).to receive(:vm_in_target?).and_return false
|
expect(subject).to receive(:vm_in_target?).and_return false
|
||||||
expect(subject).to receive(:migration_enabled?).and_return true
|
expect(subject).to receive(:migration_enabled?).and_return true
|
||||||
|
|
@ -2601,6 +2602,7 @@ EOT
|
||||||
subject.connection_pool.with_metrics do |pool_object|
|
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(:ensured_vsphere_connection).with(pool_object).and_return(connection)
|
||||||
expect(subject).to receive(:get_vm_details).and_return(vm_details)
|
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(:run_select_hosts).with(poolname, {})
|
||||||
expect(subject).to receive(:vm_in_target?).and_return true
|
expect(subject).to receive(:vm_in_target?).and_return true
|
||||||
expect(subject).to receive(:migration_enabled?).and_return true
|
expect(subject).to receive(:migration_enabled?).and_return true
|
||||||
|
|
@ -2690,6 +2692,8 @@ EOT
|
||||||
it' migrates a vm' do
|
it' migrates a vm' do
|
||||||
expect($redis).to receive(:sadd).with('vmpooler__migration', vmname)
|
expect($redis).to receive(:sadd).with('vmpooler__migration', vmname)
|
||||||
expect(subject).to receive(:select_next_host).and_return(new_host)
|
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(: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(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")
|
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