Skip to content

Commit

Permalink
Temporary solution for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ananace committed Nov 30, 2017
1 parent f6fbdd0 commit e835496
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/fog/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def self.requires_computer
attr_accessor :cluster
attr_accessor :computer

def new(attributes = {})
object = super
object.computer_name ||= computer.name if computer && object.respond_to?(:computer_name)
object
end

protected

def creation_attributes
Expand Down Expand Up @@ -103,6 +109,7 @@ def self.requires_vm

def new(attributes = {})
object = super
object.computer_name ||= vm.computer_name if vm && object.respond_to?(:computer_name)
# Ensure both ID and Name are populated, regardless of `match_on`
object.vm_id ||= vm.id if vm && object.respond_to?(:vm_id)
object.vm_name ||= vm.name if vm && object.respond_to?(:vm_name)
Expand Down

2 comments on commit e835496

@ksagle77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

I get the following now after selecting a hyperv server as the compute resource:

image

Log:

2017-11-30T10:29:23 40a10d10 [app] [I] Started POST "/hosts/compute_resource_selected" for 192.168.1.100 at 2017-11-30 10:29:23 -0500
2017-11-30T10:29:23 40a10d10 [app] [I] Processing by HostsController#compute_resource_selected as */*
2017-11-30T10:29:23 40a10d10 [app] [I]   Parameters: {"utf8"=>"✓", "authenticity_token"=>"QA1maAVozlN5Fj+Fm17nnaqBj0asMW0YLG0DX46y8aKRYf12K9tMOPdKbpymAH+i58uUT8GPEP7FwKcWoFuIVw==", "host"=>{"name"=>"kate-sangster", "hostgroup_id"=>"", "compute_resource_id"=>"2", "compute_profile_id"=>"", "environment_id"=>"", "puppet_proxy_id"=>"", "puppet_ca_proxy_id"=>"", "managed"=>"true", "progress_report_id"=>"[FILTERED]", "type"=>"Host::Managed", "interfaces_attributes"=>{"0"=>{"_destroy"=>"0", "type"=>"Nic::Managed", "mac"=>"", "identifier"=>"", "name"=>"kate-sangster", "domain_id"=>"", "subnet_id"=>"", "ip"=>"", "ip6"=>"", "managed"=>"1", "primary"=>"1", "provision"=>"1", "virtual"=>"0", "tag"=>"", "attached_to"=>""}}, "architecture_id"=>"", "provision_method"=>"build", "build"=>"1", "disk"=>"", "root_pass"=>"[FILTERED]", "is_owned_by"=>"3-Users", "enabled"=>"1", "model_id"=>"", "comment"=>"", "overwrite"=>"false"}, "fakepassword"=>"[FILTERED]", "bare_metal_capabilities"=>"build"}
2017-11-30T10:29:23 40a10d10 [app] [I] Current user: admin (administrator)
2017-11-30T10:29:23 40a10d10 [app] [D] Setting current user thread-local variable to admin
2017-11-30T10:29:23 40a10d10 [app] [D] Setting current organization thread-local variable to none
2017-11-30T10:29:23 40a10d10 [app] [D] Setting current location thread-local variable to none
2017-11-30T10:29:23 40a10d10 [hyper-v] [D] Creating WinRM connection with {:endpoint=>"http://j2p2hv59:5985/wsman", :transport=>:negotiate, :user=>".\\administrator", :password=>"<REDACTED>", :realm=>nil}
2017-11-30T10:29:23 40a10d10 [hyper-v] [D] WQL; root/virtualization/v2/* >>> SELECT Name FROM Msvm_ComputerSystem WHERE Caption = "Hosting Computer System"
2017-11-30T10:29:23 40a10d10 [hyper-v] [D] WQL; <<< {:xml_fragment=>[{:name=>"J2P2HV59", :"@xmlns:m"=>"http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd", :"@xmlns:w"=>"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", :"@xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"}]}
2017-11-30T10:29:23 40a10d10 [hyper-v] [D] PS; >>> Get-Cluster   | select Id,Description,Domain,Name | ConvertTo-Json -Compress -Depth 1
2017-11-30T10:29:24 40a10d10 [app] [I]   Rendered .gem/ruby/gems/foreman_hyperv-0.0.2/app/views/compute_resources_vms/form/hyperv/_base.html.erb (389.2ms)
2017-11-30T10:29:24 40a10d10 [app] [I]   Rendered hosts/_compute_detail.html.erb (394.0ms)
2017-11-30T10:29:24 40a10d10 [app] [I]   Rendered hosts/_compute.html.erb (803.6ms)
2017-11-30T10:29:24 40a10d10 [app] [D] Setting current location thread-local variable to none
2017-11-30T10:29:24 40a10d10 [app] [D] Setting current organization thread-local variable to none
2017-11-30T10:29:24 40a10d10 [app] [W] Failed to render compute resource template
 | ActionView::Template::Error: The term 'Get-Cluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
 | /usr/share/foreman/.gem/ruby/gems/fog-hyperv-0.0.5/lib/fog/hyperv/compute.rb:288:in `run_shell'
 | /usr/share/foreman/.gem/ruby/gems/fog-hyperv-0.0.5/lib/fog/hyperv/requests/compute/get_cluster.rb:6:in `get_cluster'
 | /usr/share/foreman/.gem/ruby/gems/fog-hyperv-0.0.5/lib/fog/collection.rb:20:in `all'
 | /usr/share/foreman/.gem/ruby/gems/fog-core-1.45.0/lib/fog/core/collection.rb:112:in `lazy_load'
 | /usr/share/foreman/.gem/ruby/gems/fog-core-1.45.0/lib/fog/core/collection.rb:16:in `map'

Regards,

Kevin

@ananace
Copy link
Owner Author

@ananace ananace commented on e835496 Nov 30, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.