Skip to content

Commit

Permalink
Merge pull request #334 from mattkirby/pooler_142
Browse files Browse the repository at this point in the history
(POOLER-142) Add running host to vm API data
  • Loading branch information
mchllweeks authored Aug 21, 2019
2 parents 9d48bc1 + 9c5a0d1 commit edfcb66
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ git logs & PR history.
# [Unreleased](https://github.com/puppetlabs/vmpooler/compare/0.6.3...master)

### 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)

Expand Down
4 changes: 3 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ $ curl --url vmpooler.example.com/api/v1/vm/pxpmtoonx7fiqg6
"user": "jdoe"
},
"ip": "192.168.0.1",
"domain": "example.com"
"domain": "example.com",
"host": "host1.example.com",
"migrated": "true"
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions lib/vmpooler/api/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,10 @@ def invalid_pool(payload)
if config['domain']
result[params[:hostname]]['domain'] = config['domain']
end

result[params[:hostname]]['host'] = rdata['host'] if rdata['host']
result[params[:hostname]]['migrated'] = rdata['migrated'] if rdata['migrated']

end

JSON.pretty_generate(result)
Expand Down
4 changes: 3 additions & 1 deletion lib/vmpooler/providers/vsphere.rb
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ def migrate_vm(pool_name, vm_name)
begin
connection = ensured_vsphere_connection(pool_object)
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_count = $redis.scard('vmpooler__migration')
if migration_enabled? @config
Expand All @@ -965,9 +966,10 @@ def migrate_vm(pool_name, vm_name)
def migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
$redis.sadd('vmpooler__migration', vm_name)
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)
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")
ensure
$redis.srem('vmpooler__migration', vm_name)
Expand Down
1 change: 1 addition & 0 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/integration/api/v1/vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def app()
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

Expand Down
6 changes: 5 additions & 1 deletion spec/unit/providers/vsphere_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
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) }

Expand Down Expand Up @@ -138,7 +139,6 @@
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 }

Expand Down Expand Up @@ -2572,6 +2572,7 @@
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
Expand Down Expand Up @@ -2601,6 +2602,7 @@
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
Expand Down Expand Up @@ -2690,6 +2692,8 @@
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")
Expand Down

0 comments on commit edfcb66

Please sign in to comment.