GithubHelp home page GithubHelp logo

ananace / foreman_hyperv Goto Github PK

View Code? Open in Web Editor NEW
15.0 7.0 2.0 103 KB

Microsoft Hyper-V compute resource for Foreman

License: GNU General Public License v3.0

Ruby 62.67% HTML 31.99% JavaScript 5.34%
foreman hyperv hyper-v foreman-hyperv

foreman_hyperv's Introduction

Foreman Hyper-V

Gem Version

Microsoft Hyper-V compute resource for Foreman

Uses the in-development fog-hyperv gem found here.

Nota Bene

Currently the plugin only supports Hyper-V hosts where the names are well defined in DNS and in connection strings, avoid using IP addresses for now.

If you're using SELinux, you may need to enable the connect_all boolean. For Foreman 2.0 and earlier, run setsebool -P passenger_can_connect_all 1. For Foreman 2.1 and later the command would be setsebool -P foreman_rails_can_connect_all 1.

Testing/Installing

Follow the Foreman manual for advanced installation from gems for fog-hyperv and foreman_hyperv.

There are RPMs packaged for the fog-hyperv dependencies under Release v0.0.1, or they too can be installed from gems.

Do bear in mind that this is still very early in development, so plenty of issues may exist.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ananace/foreman_hyperv.

License

The gem is available as open source under the terms of the MIT License.

foreman_hyperv's People

Contributors

ananace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

foreman_hyperv's Issues

Issue with Gen2 Compute profiles

Hey,

I'm running in to an issue when creating a Gen2 compute profile. I am able to create the a gen 2 profile:

compute_profile

but then once I try to open the profile, I get the following error:

Oops, we're sorry but something went wrong Hyper-V was unable to find a virtual machine with name "foreman_1511888691".
image
image

compute_profile_2

The name 'foreman_1511888691' is static, it does not change based on the name of the profile/host/etc.

I looked for that string in the code, but was unable to find it. Stack trace is attached.

stack_trace_compute.txt

Kevin

Create host - Interfaces throws a "Error loading interfaces information: Internal Server Error"

This is running on Ubuntu 16.04 with foreman version 1.17.1

In the production log I find the following with a looong stacktrace after.

2018-06-04T14:53:23 36712af6 [app] [I] Rendered vendor/ruby/2.3.0/bundler/gems/foreman_hyperv-9eacbdc1f657/app/views/compute_resources_vms/form/hyp
erv/_network.html.erb (1101.3ms)
2018-06-04T14:53:23 36712af6 [app] [I] Rendered nic/_provider_specific_form.html.erb (1468.1ms)
2018-06-04T14:53:23 36712af6 [app] [I] Rendered nic/manageds/_managed.html.erb (1494.7ms)
2018-06-04T14:53:23 36712af6 [app] [I] Rendered hosts/_interfaces.html.erb (1495.8ms)
2018-06-04T14:53:23 36712af6 [app] [I] Rendered hosts/_interfaces_tab.html.erb (1496.2ms)
2018-06-04T14:53:23 36712af6 [app] [W] Action failed
| ActionView::Template::Error: singleton can't be dumped

After some googling I'm of the impression this is a casting error?
http://bloggershetty.blogspot.com/2007/04/ruby-typeerror-singleton-cant-be-dumped.html

If I understand the template right, it will create a list or not print anything, but I'm not sure I'm on the right track...

Extend creation UI with additional VHD support

A 2 minute mockup;
firefox_2017-11-30_23-07-45

Options should include;

  • New VHD, which acts like the current UI
  • Source VHD, copies said source to act as the base of the VM disk
  • Existing VHD, adds an already existing VHD as a disk on the new VM

This should make a workflow like the one discussed in #12 possible.

Handle volumes and network interfaces in a more sane way

This would probably require splitting up the VM creation, instead of having them created by the New-VM cmdlet.

Without this it's impossible to support MAC assignment or multiple disks/network adapters

$VM = New-VM -Name mister-virtual.example.com -BootDevice NetworkAdapter -MemoryStartup 2147483648
$VM | Set-VM -ProcessorCount 4
$VM | Add-VMNetworkAdapter -StaticMacAddress "00:1f:2a:34:53:12" -Name "Example network adapter" -SwitchName net_switch
$VM | Add-VMNetworkAdapter -StaticMacAddress "00:1f:2a:34:53:13" -Name "Example network adapter 2" -SwitchName internal_switch
New-VHD -Path C:\VMs\Disk01.vhdx -SizeBytes 68719476736 -Dynamic
New-VHD -Path C:\VMs\Disk02.vhdx -SizeBytes 68719476736 -Dynamic
$VM | Add-VMHardDiskDrive -Path C:\VMs\Disk01.vhdx ... 
$VM | Add-VMHardDiskDrive -Path C:\VMs\Disk02.vhdx ...

Problem rendering compute_resources_vms/form/hyperv/_base.html.erb

My knowledge of Ruby is severely limited, but it seems that "f.object.cluster" on line 5 of compute_resources_vms/form/hyperv/_base.html.erb returns "nil".
To test I removed "f.object.cluster", and the template renders and show the cluster, but no computers.

5c5
< computers = (f.object.cluster || compute_resource).hosts.map(&:name)

computers = compute_resource.hosts.map(&:name)

Since I know you're working on this code I don't know if you want bug reports at this time.

Erro when install

Hi dear,

In my foreman/katello when installed this error:

[root@katello ]# gem install fog-hyperv
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: fog-hyperv requires fog-core (
> 1.42)

My fg-core this version 2.10

Lock the MAC address for the main interface

This is required to allow for proper life-cycle management.

The proper way seems to be to launch the VM for a few moments so that it has time to initialize the network adapter, then change it to a static MAC address with it's current MAC as the static value.

Error when trying to view a VM

I have just done a fresh install of Katello / Foreman under Centos 7, and added foreman_hyperv to it.
The provided plugin rpms would not install so I had to install all dependancies from gem intself.

I am able to view the list of VMs on the HyperV server, but when I click an individual server I get this error:

Oops, we're sorry but something went wrong getaddrinfo: Name or service not known (HYPERV.foo.com:5985)

My guess is it's trying to resolve the port number as part of the hostname ?

"Hyper-V was unable to find a virtual machine with name"

Hello All,

After setting up my HyperV box as a compute resc. in foreman, I see that I am now getting this error at seemingly random points in the host creation process (in the WebUI).

Oops, we're sorry but something went wrong Hyper-V was unable to find a virtual machine with name "foreman_1515980741".

I have not yet provisioned anything to this hyperV Instance, nor do I have any VM with this name already on that hyperv box.

Would love some feedback on this issue!!

foreman_hyperv

Environment CentOS 8 x64
Hosted on Ovirt 4.3 CentOS 7
CPU 2
Ram 16 GB
Foreman 2.4
Katello 4.0

I have Hyperv as a compute resource in Foreman but cannot list vm's. I get the following error when trying to view vm's

There was an error listing VMs: Unable to parse authorization header. Headers: {"Content-Type"=>"text/html; charset=us-ascii", "Server"=>"Microsoft-HTTPAPI/2.0", "Date"=>"Thu, 24 Jun 2021 19:18:31 GMT", "Connection"=>"close", "Content-Length"=>"315"} Body: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Not Found</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Not Found</h2> <hr><p>HTTP Error 404. The requested resource is not found.</p> </BODY></HTML> (404).

Foreman-rake console

[root@katello ~]# foreman-rake console
Loading production environment (Rails 6.0.3.4)
irb(main):001:0> cr = Compute Resource.find_by name: 'HV01'
Traceback (most recent call last):
        2: from lib/tasks/console.rake:5:in `block in <top (required)>'
        1: from (irb):1
NameError (uninitialized constant Resource)
irb(main):002:0> cr = Compute Resource.find_by name: 'HV02'
Traceback (most recent call last):
        2: from lib/tasks/console.rake:5:in `block in <top (required)>'
        1: from (irb):2
NameError (uninitialized constant Resource)
irb(main):003:0> cr = Compute Resource.find_by name: 'HV02.digitaldatatechs.com'
Traceback (most recent call last):
        2: from lib/tasks/console.rake:5:in `block in <top (required)>'
        1: from (irb):3
NameError (uninitialized constant Resource)
irb(main):004:0> cr = Compute Resource.find_by name: '192.168.254.230'          Traceback (most recent call last):
        2: from lib/tasks/console.rake:5:in `block in <top (required)>'
        1: from (irb):4
NameError (uninitialized constant Resource)
irb(main):005:0>

Hyper-V config:

winrm winrm/config/listener

Listener [Source="GPO"]
    Address = *
    Transport = HTTP
    Port = 5985
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 192.168.254.230

Listener
    Address = *
    Transport = HTTPS
    Port = 5986
    Hostname = HV02
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint = D442460344F2154D02546EFCA3E5788ACDCD327B
    ListeningOn = 192.168.254.230

Listener [Source="Compatibility"]
    Address = *
    Transport = HTTP
    Port = 80
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 192.168.254.230

PS C:\Users\Administrator.DIGITALDATATECH>  winrm get winrm/config
Config
    MaxEnvelopeSizekb = 500
    MaxTimeoutms = 60000
    MaxBatchItems = 32000
    MaxProviderRequests = 4294967295
    Client
        NetworkDelayms = 5000
        URLPrefix = wsman
        AllowUnencrypted = false
        Auth
            Basic = true
            Digest = true
            Kerberos = true
            Negotiate = true
            Certificate = true
            CredSSP = true
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        TrustedHosts = *
    Service
        RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
        MaxConcurrentOperations = 4294967295
        MaxConcurrentOperationsPerUser = 1500
        EnumerationTimeoutms = 240000
        MaxConnections = 300
        MaxPacketRetrievalTimeSeconds = 120
        AllowUnencrypted = true [Source="GPO"]
        Auth
            Basic = true [Source="GPO"]
            Kerberos = true [Source="GPO"]
            Negotiate = true [Source="GPO"]
            Certificate = false
            CredSSP = true [Source="GPO"]
            CbtHardeningLevel = Relaxed [Source="GPO"]
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        IPv4Filter = 192.168.254.1-192.168.254.254 [Source="GPO"]
        IPv6Filter [Source="GPO"]
        EnableCompatibilityHttpListener = true [Source="GPO"]
        EnableCompatibilityHttpsListener = false
        CertificateThumbprint
        AllowRemoteAccess = true [Source="GPO"]
    Winrs
        AllowRemoteShellAccess = true [Source="GPO"]
        IdleTimeout = 900000 [Source="GPO"]
        MaxConcurrentUsers = 5 [Source="GPO"]
        MaxShellRunTime = 2147483647
        MaxProcessesPerShell = 2147483647
        MaxMemoryPerShellMB = 2147483647
        MaxShellsPerUser = 2147483647

I can remote manage with powershell and connect-wsman gives a login prompt but does not login. I'm honestly not sure if it's supposed to.,

You seem to be the only one with a grasp of Foreman and hyperv.
I just need some direction.
Thanks.

Cluster support is too agressive in activating

As reported on ace13/fog-hyperv@e835496;

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

Get-Cluster only exists if failover clustering support is installed, so it should definitely query for that support before ever depending on the result of cluster queries for anything.

Support VLANs on interfaces

This will depend on ananace/fog-hyperv#16 for the actual backend code, but the UI would need to be extended to allow setting the VLAN information in a reasonable manner.

https://docs.microsoft.com/en-us/powershell/module/hyper-v/set-vmnetworkadaptervlan?view=win10-ps

Would require options for VLAN type, as well as information required for each VLAN mode.
The most likely one would probably be Access, Trunk, or Untagged. Though Isolated and Promiscuous might be good to support as well.

Trouble creating vm when hyper-v host is part of a cluster

This is probably a known problem since the cluster support in fog-hyperv isn't complete.
Trying to create a vm will generate a error "Failure: undefined method `clusters' for #ForemanHyperv::Hyperv:0x007f96da783bb0" Foreman version is 1.15.4

Feature Discussion - use existing VHD

Hey Ace,

Currently, I have a puppet workflow that works like this:

  1. Ensure d:\data\images exists on every hyperv server. Ensure base images (.vhdx) exist within it.

  2. I specify the required VMs in hiera data as follows:

hyperv::hvhost_vms:
  'test-01':
    vm_name: 'test-01'
    vm_vhdpath: 'd:/vms/test-01/test-01.vhdx'
    vm_configfolder: 'd:/vms/test-01'
    vm_os: '2016GUI'
    vm_desiredstate: 'Running'
    hvhost_datadir: 'd:/data'
  1. Based on the OS, the required image is copied from the data folder to the new directory for the VM. It is renamed to match the parent folder (the VM name).

  2. Prepare_Vhd.ps1 is copied to the same directory, and executed. Prepare_VHD updates an unattend.xml file, copies the latest puppet agent msi, and sets puppet install to run on first boot:

$vmname = ($PSScriptRoot -split "\\")[($PSScriptRoot -split "\\").Count-1]
$vmConfigFolder = $PSScriptRoot
$vmVhdPath = "$($PSScriptRoot)\$($vmName).vhdx"
$dataDir = 'd:/data'

$error.clear()
if ((!(get-vm $vmName -erroraction SilentlyContinue)))
{
  Mount-DiskImage $vmVhdPath

  $VMMountedDisk = get-disk | where {$_.FriendlyName -match "msft"}

  $driveLetter = ($VMMountedDisk | Get-Partition | where {$_.type -eq "Basic"}).driveletter

  (get-content $dataDir\unattend.xml).replace("PlaceHolderName",$vmName) | set-content -Path "$($driveLetter):\windows\system32\sysprep\unattend.xml"

  mkdir "$($driveLetter):\temp" -ErrorAction SilentlyContinue

  Copy-Item "$($dataDir)\puppet_agent_latest.msi"  "$($driveLetter):\temp\puppet_agent_latest.msi"

  mkdir "$($driveLetter):\Windows\Setup\Scripts\" -ErrorAction SilentlyContinue

  Copy-Item -path "$($dataDir)\SetupComplete.cmd"  "$($driveLetter):\Windows\Setup\Scripts\"

  dismount-diskimage $vmVhdPath
}

if ($error.count -eq 0)
{
  return 0
}
else
{
  return 1
}

I'm investigating options for porting this to the foreman. I'm currently thinking of something roughly like this.

Fog-hyperv:

New Methods:

  1. requests/get_childitems.rb (generic) OR requests/get_vhds.rb:
    Return array of VHDs found in path.

    image

  2. requests/copy_item.rb

    image

  3. requests/invoke_expression.rb
    image

New Models:

If using get_childitem,

	Item:
  		Identity: Name
		Attribute: fullname
		Attribute: lastwritetime
		Attribute: creationtime
		Attribute: lastaccesstime
		Attribute: length
		Attribute: mode

Foreman_hyperv:

  1. Add text field to virtual machine tab called “Path”. Set this as path to be used during vm creation.

  2. Add an button to the virtual machine tab storage area called “Use local VHD”

  3. If selected, display a select field (similar to the one used in app/views/compute_resources_vms/form/hyperv/_network.html.erb to show the switches).

  4. Populate the options either using names for each item in an array of items returned by either get_childitem with *.vhdx as filter, or get_vhds.

  5. Set a flag called useExistingVHD to true.

  6. In /app/models/foreman_hyperv/hyperv.rb, if flag is true, set bootdevice to VHD. Add “path” option to vm creation.

  7. If flag is set, do the following instead of create_volume.

    a.	copy_item(vhd, path)

    b.	copy_item(unattend.xml, path)

    c.	copy_item(prepare_vhd.ps1, path)

    d.	invoke_expression(prepare_vhd.ps1)

    e.	update_volumes

It may be better to split it in to two parts, one part in foreman_hyperv that copies the required VHD and set's it as the boot device on the VM, and a second provisioning template that prepares the VHD before turning it on, but I'm not sure.

Do you think that's a reasonable plan?

Thanks,

Kevin

Assign vlan to VM

Would it be hard to be able to set witch vlan a interface should be connected to?

Expose more advanced options to VMs

Shouldn't be much work to add support for setting things like;

  • Option for Secure boot if generation is 2
  • Minimum and maximum memory limits for dynamic memory
  • Fixed or Dynamic VHD types for storage
  • IDE / SCSI controller choice for storage

Problem creating vm

I'm trying to get this to work in our environment, but at the moment I get a bit strange error.

"Oops, we're sorry but something went wrong getaddrinfo: Name or service not known (CH1BLADE1SLOT0.255.30.111:5985)"

Ok, the fact that foreman can't find the address is quite understandable, but as to how that address gets created I don't understand. The hostname is CH1BLADE1SLOT0 , and the ip is 10.255.30.111, so it seems that the first octet of the ip address somehow gets truncated.

I can attach the stack trace, but I'm uncertain how much help it would be as I suspect the problem is not where it's triggered.

The version of foreman is 1.15.6 and foreman_hyperv was pulled from git on friday. Is there anything else I can provide to find out what's going on?

Computer_name required by fog network adapters, but not passed.

When creating a VM from the web UI, foreman_hyperv fails when trying to build the network adapters. The following parameters are passed when VM creation is started.

2017-11-28 12:03:21 5e39cbfe [app] [I] Parameters: {"utf8"=>"✓", "authenticity_token"=>"TsTwloaxIZUUpAfVAf1MldD/nXfJxMF7WT0eC4pB/LspRGTJRpM32xm9dcXICH+FjWjcIgQgVQiO5rDy6sxJiA==", "host"=>{"name"=>"test-vm", "hostgroup_id"=>"1", "compute_resource_id"=>"2", "environment_id"=>"1", "puppetclass_ids"=>[""], "managed"=>"true", "progress_report_id"=>"[FILTERED]", "type"=>"Host::Managed", "interfaces_attributes"=>{"0"=>{"_destroy"=>"0", "type"=>"Nic::Managed", "mac"=>"", "identifier"=>"", "name"=>"test-vm", "domain_id"=>"1", "subnet_id"=>"2", "ip"=>"192.168.1.243", "ip6"=>"", "managed"=>"1", "primary"=>"1", "provision"=>"1", "virtual"=>"0", "tag"=>"", "attached_to"=>"", "compute_attributes"=>__{"name"=>"test", "network"=>"PFSense_LAN", "id"=>""}__}}, "compute_attributes"=>{"generation"=>"1", "processor_count"=>"1", "memory_startup"=>"536870912", "memory_maximum"=>"17179869184", "memory_minimum"=>"536870912", "dynamic_memory_enabled"=>"false", "start"=>"1", "notes"=>"", "id"=>""}, "architecture_id"=>"3", "operatingsystem_id"=>"2", "provision_method"=>"build", "build"=>"1", "medium_id"=>"9", "ptable_id"=>"104", "pxe_loader"=>"PXELinux BIOS", "disk"=>"", "root_pass"=>"[FILTERED]", "is_owned_by"=>"3-Users", "enabled"=>"1", "comment"=>"", "overwrite"=>"false"}, "capabilities"=>"build", "provider"=>"Hyperv", "bare_metal_capabilities"=>"build"}

Foreman continues to work correctly until attempting to create the interfaces:

create_interfaces(vm, args[:interfaces_attributes])

def create_interfaces(vm, attrs)
  vm.network_adapters.each(&:destroy)

  interfaces = nested_attributes_for :interfaces, attrs
  client.logger.debug "Building interfaces with: #{interfaces}"
  interfaces.each do |iface|
    nic = vm.network_adapters.new name: iface[:name], switch_name: iface[:network]
    if iface[:mac]
      nic.mac = iface[:mac]
      nic.dynamic_mac_address_enabled = false
    end
    nic.save
  end

  # Populate the MAC addresses
  vm.start
  vm.stop turn_off: true

  vm.network_adapters.reload
  vm.network_adapters.each do |nic|
    nic.dynamic_mac_address_enabled = false
    nic.save if nic.dirty?
  end
end

It then explicitly uses the parameters passed by foreman_hyperv-0.0.2/app/views/compute_resources_vms/form/hyperv/_network.html.erb to try and build the interfaces.

Log:

2017-11-29T14:21:26 0f1e160f [hyper-v] [D] PS; <<< OUT=[""] ERR=[""] EXIT=[0]
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] Building interfaces with: [{:network=>"PFSense_LAN", :name=>"test123", :ip=>"192.168.1.22", :ip6=>""}]
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] Executing multi-query for [""]
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] PS; >>> Stop-VM -TurnOff -Name adele-dulatre.cloudapp.net
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] PS; <<< OUT=["Warning: The virtual machine is already in the specified state.\r\n"] ERR=[""] EXIT=[0]
2017-11-29T14:21:26 0f1e160f [app] [W] Failed to create a compute ****** (Hyper-V) instance adele-dulatre.
***: computer_name is required for this operation

|
| ArgumentError: computer_name is required for this operation
| /usr/share/foreman/.gem/ruby/gems/fog-core-1.45.0/lib/fog/core/attributes.rb:155:in requires' | /usr/share/foreman/.gem/ruby/gems/fog-hyperv-0.0.5/lib/fog/hyperv/models/compute/network_adapter.rb:61:in save'
| /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:195:in block in create_interfaces' | /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:189:in each'
| /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:189:in create_interfaces' | /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:89:in create_vm'
| /usr/share/foreman/app/models/concerns/orchestration/compute.rb:77:in `setCompute'

Computer_name is required by fog-hyperv-0.0.5/lib/fog/hyperv/models/compute/network_adapter.rb

  def connect(switch, options = {})
      requires :name, :vm_name
	  
  def disconnect(options = {})
      requires :name, :computer_name, :vm_name

  def save
      requires :name, :computer_name, :vm_name

I think the best solution would be to remove the :computer_name requirement from the methods in fog-hyperv-0.0.5/lib/fog/hyperv/models/compute/network_adapter.rb. I think using -computername with the *-vmnetadapter cmdlets is pretty rare, and having it as required doesn't provide any tangible benefit.

Otherwise, computer_name could be passed as a compute_parameter from _network.html.erb, or added to object before create_interfaces is called.

Let me know if I'm off base.

Kevin

Foreman and Hyperv permissions issue

I was able to add my hyper-v servers but when I try to view the vms, it error out. I can connect to hyperv but it's complaining about NTLM authentication. These are Hyperv 2019 servers.
The error is:
There was an error listing VMs: Permission denied - Permission denied - connect(2) for with the correct port.

The production.log:
2020-08-05T15:03:31 [I|app|ecef5ea3] Processing by ComputeResourcesVmsController#index as HTML
2020-08-05T15:03:31 [I|app|ecef5ea3] Parameters: {"compute_resource_id"=>"2-HV01"}
2020-08-05T15:03:31 [I|app|d5a5bbc7] Started GET "/notification_recipients" for 192.168.254.251 at 2020-08-05 15:03:31 -0400
2020-08-05T15:03:31 [I|app|d5a5bbc7] Processing by NotificationRecipientsController#index as JSON
2020-08-05T15:03:31 [I|app|d5a5bbc7] Completed 200 OK in 49ms (Views: 0.7ms | ActiveRecord: 4.3ms)
2020-08-05T15:03:51 [W|app|ecef5ea3] Error has occurred while listing VMs on HV01 (Hyper-V)
2020-08-05T15:03:51 [I|app|ecef5ea3] Rendered compute_resources_vms/_error.html.erb (2.2ms)
2020-08-05T15:03:51 [I|app|ecef5ea3] Completed 200 OK in 20112ms (Views: 5.1ms | ActiveRecord: 9.4ms)

Do I need to change local group policy to allow NTLM authentication? I've had to do that with Samba in the past.
Any help would be very much appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.