Class: Fog::Hyperv::Compute::Real
- Includes:
- Utils::Winrm
- Defined in:
- lib/fog/hyperv/compute.rb,
lib/fog/hyperv/compute/requests/get_vm.rb,
lib/fog/hyperv/compute/requests/new_vm.rb,
lib/fog/hyperv/compute/requests/set_vm.rb,
lib/fog/hyperv/compute/requests/get_vhd.rb,
lib/fog/hyperv/compute/requests/new_vhd.rb,
lib/fog/hyperv/compute/requests/save_vm.rb,
lib/fog/hyperv/compute/requests/stop_vm.rb,
lib/fog/hyperv/compute/requests/start_vm.rb,
lib/fog/hyperv/compute/requests/remove_vm.rb,
lib/fog/hyperv/compute/requests/rename_vm.rb,
lib/fog/hyperv/compute/requests/resume_vm.rb,
lib/fog/hyperv/compute/requests/update_vm.rb,
lib/fog/hyperv/compute/requests/resize_vhd.rb,
lib/fog/hyperv/compute/requests/restart_vm.rb,
lib/fog/hyperv/compute/requests/suspend_vm.rb,
lib/fog/hyperv/compute/requests/get_cluster.rb,
lib/fog/hyperv/compute/requests/get_vm_bios.rb,
lib/fog/hyperv/compute/requests/get_vm_host.rb,
lib/fog/hyperv/compute/requests/remove_item.rb,
lib/fog/hyperv/compute/requests/set_vm_bios.rb,
lib/fog/hyperv/compute/requests/get_vm_group.rb,
lib/fog/hyperv/compute/requests/optimize_vhd.rb,
lib/fog/hyperv/compute/requests/enable_vm_tpm.rb,
lib/fog/hyperv/compute/requests/get_vm_switch.rb,
lib/fog/hyperv/compute/requests/new_vm_switch.rb,
lib/fog/hyperv/compute/requests/set_vm_switch.rb,
lib/fog/hyperv/compute/requests/disable_vm_tpm.rb,
lib/fog/hyperv/compute/requests/get_vm_com_port.rb,
lib/fog/hyperv/compute/requests/get_vm_firmware.rb,
lib/fog/hyperv/compute/requests/get_vm_host_sbt.rb,
lib/fog/hyperv/compute/requests/get_vm_security.rb,
lib/fog/hyperv/compute/requests/set_vm_com_port.rb,
lib/fog/hyperv/compute/requests/set_vm_firmware.rb,
lib/fog/hyperv/compute/requests/set_vm_security.rb,
lib/fog/hyperv/compute/requests/add_vm_dvd_drive.rb,
lib/fog/hyperv/compute/requests/get_cluster_node.rb,
lib/fog/hyperv/compute/requests/get_vm_dvd_drive.rb,
lib/fog/hyperv/compute/requests/remove_vm_switch.rb,
lib/fog/hyperv/compute/requests/rename_vm_switch.rb,
lib/fog/hyperv/compute/requests/set_vm_dvd_drive.rb,
lib/fog/hyperv/compute/requests/get_vm_host_cluster.rb,
lib/fog/hyperv/compute/requests/remove_vm_dvd_drive.rb,
lib/fog/hyperv/compute/requests/get_vm_key_protector.rb,
lib/fog/hyperv/compute/requests/set_vm_key_protector.rb,
lib/fog/hyperv/compute/requests/add_vm_hard_disk_drive.rb,
lib/fog/hyperv/compute/requests/add_vm_network_adapter.rb,
lib/fog/hyperv/compute/requests/get_vm_hard_disk_drive.rb,
lib/fog/hyperv/compute/requests/get_vm_network_adapter.rb,
lib/fog/hyperv/compute/requests/set_vm_hard_disk_drive.rb,
lib/fog/hyperv/compute/requests/set_vm_network_adapter.rb,
lib/fog/hyperv/compute/requests/get_vm_floppy_disk_drive.rb,
lib/fog/hyperv/compute/requests/set_vm_floppy_disk_drive.rb,
lib/fog/hyperv/compute/requests/remove_vm_hard_disk_drive.rb,
lib/fog/hyperv/compute/requests/remove_vm_network_adapter.rb,
lib/fog/hyperv/compute/requests/rename_vm_network_adapter.rb,
lib/fog/hyperv/compute/requests/connect_vm_network_adapter.rb,
lib/fog/hyperv/compute/requests/get_vm_network_adapter_vlan.rb,
lib/fog/hyperv/compute/requests/set_vm_network_adapter_vlan.rb,
lib/fog/hyperv/compute/requests/disconnect_vm_network_adapter.rb
Instance Attribute Summary collapse
-
#bake_json ⇒ Object
Returns the value of attribute bake_json.
-
#bake_optmap ⇒ Object
Returns the value of attribute bake_optmap.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #add_vm_dvd_drive(vm_id:, computer_name: nil, **options) ⇒ Object
- #add_vm_hard_disk_drive(vm_id:, computer_name: nil, **options) ⇒ Object
- #add_vm_network_adapter(computer_name: nil, **options) ⇒ Object
- #connect_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
- #disable_vm_tpm(vm_id:, computer_name: nil, **options) ⇒ Object
- #disconnect_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
- #enable_vm_tpm(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_cluster(**options) ⇒ Object
- #get_cluster_node(id:, **options) ⇒ Object
- #get_vhd(computer_name: nil, **options) ⇒ Object
- #get_vm(**options) ⇒ Object
- #get_vm_bios(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_com_port(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_dvd_drive(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_firmware(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_floppy_disk_drive(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_group(computer_name: nil, **options) ⇒ Object
- #get_vm_hard_disk_drive(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_host(computer_name: nil, **options) ⇒ Object
- #get_vm_host_cluster(cluster_name:, computer_name: nil, **options) ⇒ Object
-
#get_vm_host_sbt(computer_name:, **options) ⇒ Object
Retrieve SecureBoot Templates for a VM Host.
-
#get_vm_key_protector(vm_id:, computer_name: nil, **options) ⇒ Object
Retrieve SecureBoot Templates for a VM Host.
- #get_vm_network_adapter(computer_name: nil, **options) ⇒ Object
- #get_vm_network_adapter_vlan(id:, computer_name: nil, **options) ⇒ Object
- #get_vm_security(vm_id:, computer_name: nil, **options) ⇒ Object
- #get_vm_switch(computer_name: nil, **options) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
rubocop:disable Style/OptionHash, Lint/MissingSuper – No super method.
-
#local? ⇒ Boolean
Is the provider communicating with a Hyper-V install on the local machine.
- #new_vhd(path:, size_bytes:, computer_name: nil, **options) ⇒ Object
- #new_vm(computer_name: nil, **options) ⇒ Object
- #new_vm_switch(name:, computer_name: nil, **options) ⇒ Object
- #optimize_vhd(path:, computer_name: nil, **options) ⇒ Object
- #remove_item(path:, computer_name: nil, **options) ⇒ Object
- #remove_vm(id:, computer_name: nil, **options) ⇒ Object
- #remove_vm_dvd_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
- #remove_vm_hard_disk_drive(vm_id:, id:, computer_name: nil, **options) ⇒ Object
- #remove_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
- #remove_vm_switch(id:, computer_name: nil, **options) ⇒ Object
- #rename_vm(id:, new_name:, computer_name: nil, **options) ⇒ Object
- #rename_vm_network_adapter(id:, new_name:, computer_name: nil, **options) ⇒ Object
- #rename_vm_switch(id:, new_name:, computer_name: nil, **options) ⇒ Object
- #resize_vhd(path:, size_bytes:, computer_name: nil, **options) ⇒ Object
- #restart_vm(id:, computer_name: nil, **options) ⇒ Object
- #resume_vm(id:, computer_name: nil, **options) ⇒ Object
- #save_vm(id:, computer_name: nil, **options) ⇒ Object
- #set_vm(id:, computer_name: nil, **options) ⇒ Object
- #set_vm_bios(vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_com_port(id:, vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_dvd_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_firmware(vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_floppy_disk_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_hard_disk_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_key_protector(vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
- #set_vm_network_adapter_vlan(id:, computer_name: nil, **options) ⇒ Object
- #set_vm_security(vm_id:, computer_name: nil, **options) ⇒ Object
- #set_vm_switch(id:, computer_name: nil, **options) ⇒ Object
- #start_vm(id:, computer_name: nil, **options) ⇒ Object
- #stop_vm(id:, computer_name: nil, **options) ⇒ Object
-
#supports_clusters? ⇒ Boolean
Does the Hyper-V install support clusters - i.e.
- #suspend_vm(id:, computer_name: nil, **options) ⇒ Object
- #update_vm(id:, computer_name: nil, **options) ⇒ Object
-
#valid? ⇒ Boolean
Is the Hyper-V provider valid - i.e.
Methods included from Utils::Winrm
#ps_version?, #run_cmd, #run_cmdlist, #run_wql
Methods inherited from Shared
Constructor Details
#initialize(options = {}) ⇒ Real
rubocop:disable Style/OptionHash, Lint/MissingSuper – No super method
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fog/hyperv/compute.rb', line 139 def initialize( = {}) # rubocop:disable Style/OptionHash, Lint/MissingSuper -- No super method require 'fog/json' require 'logging' # Transfer cmdlet parameters as JSON object @bake_json = true @bake_optmap = true @connections = {} @hyperv_endpoint = [:hyperv_endpoint] @hyperv_endpoint ||= "http://#{[:hyperv_host]}:5985/wsman" if [:hyperv_host] @hyperv_username = [:hyperv_username] @hyperv_password = [:hyperv_password] @hyperv_realm = [:hyperv_realm] @hyperv_transport = [:hyperv_transport] || (@hyperv_realm ? :kerberos : :negotiate) # Hide NEGOTIATE logging from WinRM to reduce log spam when debugging Logging.logger['WinRM::HTTP::HttpNegotiate'].level = :error @logger = Logging.logger[Fog::Hyperv] if [:hyperv_debug] logger.level = :debug logger.add_appenders Logging.appenders.stdout end connect end |
Instance Attribute Details
#bake_json ⇒ Object
Returns the value of attribute bake_json.
137 138 139 |
# File 'lib/fog/hyperv/compute.rb', line 137 def bake_json @bake_json end |
#bake_optmap ⇒ Object
Returns the value of attribute bake_optmap.
137 138 139 |
# File 'lib/fog/hyperv/compute.rb', line 137 def bake_optmap @bake_optmap end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
135 136 137 |
# File 'lib/fog/hyperv/compute.rb', line 135 def logger @logger end |
Instance Method Details
#add_vm_dvd_drive(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/add_vm_dvd_drive.rb', line 5 def add_vm_dvd_drive(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Add-VMDvdDrive', { passthru: true, ** }] ], target_computer: computer_name ) end |
#add_vm_hard_disk_drive(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/add_vm_hard_disk_drive.rb', line 5 def add_vm_hard_disk_drive(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Add-VMHardDiskDrive', { passthru: true, ** }] ], target_computer: computer_name ) end |
#add_vm_network_adapter(computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/hyperv/compute/requests/add_vm_network_adapter.rb', line 5 def add_vm_network_adapter(computer_name: nil, **) requires_one , :vm_id, :management_os .delete :management_os if [:vm_id] vm_id = .delete :vm_id run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Add-VMNetworkAdapter', { _always_include: %i[is_legacy], passthru: true, ** }] ], target_computer: computer_name ) else .delete :vm_id run_cmd('Add-VMNetworkAdapter', _target_computer: computer_name, management_os: true, passthru: true, **) end end |
#connect_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/hyperv/compute/requests/connect_vm_network_adapter.rb', line 5 def connect_vm_network_adapter(id:, computer_name: nil, **) requires_one , :vm_id, :management_os requires_one , :switch_name, :switch_id .delete :management_os cmdlist = [] if [:vm_id] vm_id = .delete :vm_id cmdlist += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :vm_id cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }] end if [:switch_id] switch_id = .delete :switch_id .delete :switch_name cmdlist += [ ['$Switch = Get-VMSwitch', { id: switch_id }], ['$NIC | Connect-VMNetworkAdapter -VMSwitch @Switch', ] ] else switch_name = .delete :switch_name .delete :switch_id cmdlist << ['$NIC | Connect-VMNetworkAdapter', { switch_name:, ** }] end run_cmdlist(cmdlist, skip_json: true, target_computer: computer_name) end |
#disable_vm_tpm(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/disable_vm_tpm.rb', line 5 def disable_vm_tpm(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Disable-VMTPM', ] ], skip_json: true, target_computer: computer_name ) end |
#disconnect_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hyperv/compute/requests/disconnect_vm_network_adapter.rb', line 5 def disconnect_vm_network_adapter(id:, computer_name: nil, **) requires_one , :vm_id, :management_os .delete :management_os cmdlist = [] if [:vm_id] vm_id = .delete :vm_id cmdlist += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :vm_id cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }] end cmdlist << ['$NIC | Disconnect-VMNetworkAdapter', ] run_cmdlist(commands, skip_json: true, target_computer: computer_name) end |
#enable_vm_tpm(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/enable_vm_tpm.rb', line 5 def enable_vm_tpm(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Enable-VMTPM', ] ], skip_json: true, target_computer: computer_name ) end |
#get_cluster(**options) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/hyperv/compute/requests/get_cluster.rb', line 5 def get_cluster(**) _by_id = .delete(:id) run_cmd 'Get-Cluster', _by_id:, ** end |
#get_cluster_node(id:, **options) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/hyperv/compute/requests/get_cluster_node.rb', line 5 def get_cluster_node(id:, **) run_cmdlist( [ ['$Cluster = Get-Cluster', { _by_id: id }], ['$Cluster | Get-ClusterNode', ] ] ) end |
#get_vhd(computer_name: nil, **options) ⇒ Object
5 6 7 8 |
# File 'lib/fog/hyperv/compute/requests/get_vhd.rb', line 5 def get_vhd(computer_name: nil, **) requires_one , :path, :disk_number unless [:vm_id] run_cmd 'Get-VHD', _target_computer: computer_name, ** end |
#get_vm(**options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/get_vm.rb', line 5 def get_vm(**) run_cmd('Get-VM', **) end |
#get_vm_bios(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/get_vm_bios.rb', line 5 def get_vm_bios(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMBios', ] ], target_computer: computer_name ) end |
#get_vm_com_port(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/hyperv/compute/requests/get_vm_com_port.rb', line 5 def get_vm_com_port(vm_id:, computer_name: nil, **) _by_id = .delete :id run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMComPort', { _by_id:, ** }] ], target_computer: computer_name ) end |
#get_vm_dvd_drive(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/hyperv/compute/requests/get_vm_dvd_drive.rb', line 5 def get_vm_dvd_drive(vm_id:, computer_name: nil, **) _by_id = .delete :id run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMDvdDrive', { _by_id:, ** }] ], target_computer: computer_name ) end |
#get_vm_firmware(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/get_vm_firmware.rb', line 5 def get_vm_firmware(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMFirmware', ] ], target_computer: computer_name ) end |
#get_vm_floppy_disk_drive(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/get_vm_floppy_disk_drive.rb', line 5 def get_vm_floppy_disk_drive(vm_id:, computer_name: nil, **) _by_id = .delete :id run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMFloppyDiskDrive', { _by_id:, ** }] ], target_computer: computer_name ) end |
#get_vm_group(computer_name: nil, **options) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/hyperv/compute/requests/get_vm_group.rb', line 5 def get_vm_group(computer_name: nil, **) requires_version '10.0' run_cmd('Get-VMGroup', _target_computer: computer_name, **) end |
#get_vm_hard_disk_drive(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/get_vm_hard_disk_drive.rb', line 5 def get_vm_hard_disk_drive(vm_id:, computer_name: nil, **) _by_id = .delete :id run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMHardDiskDrive', { _by_id:, ** }] ], target_computer: computer_name ) end |
#get_vm_host(computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/get_vm_host.rb', line 5 def get_vm_host(computer_name: nil, **) run_cmd 'Get-VMHost', _target_computer: computer_name, ** end |
#get_vm_host_cluster(cluster_name:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/hyperv/compute/requests/get_vm_host_cluster.rb', line 5 def get_vm_host_cluster(cluster_name:, computer_name: nil, **) requires_version '10.0' run_cmd 'Get-VMHostCluster', _target_computer: computer_name, cluster_name:, ** end |
#get_vm_host_sbt(computer_name:, **options) ⇒ Object
Retrieve SecureBoot Templates for a VM Host
6 7 8 |
# File 'lib/fog/hyperv/compute/requests/get_vm_host_sbt.rb', line 6 def get_vm_host_sbt(computer_name:, **) run_cmd '(Get-VMHost @Args).SecureBootTemplates', _target_computer: computer_name, ** end |
#get_vm_key_protector(vm_id:, computer_name: nil, **options) ⇒ Object
Retrieve SecureBoot Templates for a VM Host
6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/get_vm_key_protector.rb', line 6 def get_vm_key_protector(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMKeyProtector', ] ], target_computer: computer_name ) end |
#get_vm_network_adapter(computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/hyperv/compute/requests/get_vm_network_adapter.rb', line 5 def get_vm_network_adapter(computer_name: nil, **) requires_one , :vm_id, :all, :management_os id = .delete :id if [:vm_id] vm_id = .delete :vm_id .delete :management_os .delete :all run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMNetworkAdapter', { _by_id: id, ** }] ], target_computer: computer_name ) else .delete :management_os if [:all] run_cmd 'Get-VMNetworkAdapter', _by_id: id, _target_computer: computer_name, ** end end |
#get_vm_network_adapter_vlan(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/hyperv/compute/requests/get_vm_network_adapter_vlan.rb', line 5 def get_vm_network_adapter_vlan(id:, computer_name: nil, **) requires_one , :vm_id, :management_os commands = [] if .key? :vm_id vm_id = .delete :vm_id .delete :management_os commands += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :management_os commands << ['$NIC = Get-VMNetworkAdapter', { management_os: true, _by_id: id }] end commands << ['$NIC | Get-VMNetworkAdapterVlan', ] run_cmdlist( commands, target_computer: computer_name ) end |
#get_vm_security(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/get_vm_security.rb', line 5 def get_vm_security(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Get-VMSecurity', ] ], target_computer: computer_name ) end |
#get_vm_switch(computer_name: nil, **options) ⇒ Object
5 6 7 8 |
# File 'lib/fog/hyperv/compute/requests/get_vm_switch.rb', line 5 def get_vm_switch(computer_name: nil, **) id = .delete :id run_cmd 'Get-VMSwitch', _by_id: id, _target_computer: computer_name, ** end |
#local? ⇒ Boolean
Is the provider communicating with a Hyper-V install on the local machine
168 169 170 |
# File 'lib/fog/hyperv/compute.rb', line 168 def local? false # @hyperv_endpoint.nil? end |
#new_vhd(path:, size_bytes:, computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/new_vhd.rb', line 5 def new_vhd(path:, size_bytes:, computer_name: nil, **) run_cmd 'New-VHD', _target_computer: computer_name, path:, size_bytes:, ** end |
#new_vm(computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/fog/hyperv/compute/requests/new_vm.rb', line 5 def new_vm(computer_name: nil, **) requires , :new_vhd_path, :new_vhd_size_bytes \ if [:new_whd_path] || [:new_vhd_size_bytes] run_cmd 'New-VM', _target_computer: computer_name, ** end |
#new_vm_switch(name:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/hyperv/compute/requests/new_vm_switch.rb', line 5 def new_vm_switch(name:, computer_name: nil, **) requires_one , :net_adapter_name, :net_adapter_interface_description run_cmd 'New-VMSwitch', _target_computer: computer_name, name:, ** end |
#optimize_vhd(path:, computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/optimize_vhd.rb', line 5 def optimize_vhd(path:, computer_name: nil, **) run_cmd 'Optimize-VHD', _target_computer: computer_name, _skip_json: true, path:, ** end |
#remove_item(path:, computer_name: nil, **options) ⇒ Object
5 6 7 8 |
# File 'lib/fog/hyperv/compute/requests/remove_item.rb', line 5 def remove_item(path:, computer_name: nil, **) # TODO: Really lock this method down, validation is good. run_cmd 'Remove-Item', _target_computer: computer_name, _skip_json: true, path:, force: true, ** end |
#remove_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/remove_vm.rb', line 5 def remove_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Remove-VM', { force: true, ** }] ], skip_json: true, target_computer: computer_name ) end |
#remove_vm_dvd_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/hyperv/compute/requests/remove_vm_dvd_drive.rb', line 5 def remove_vm_dvd_drive(id:, vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$DVD = $VM | Get-VMDvdDrive', { _by_id: id }], ['$DVD | Remove-VMDvdDrive', ] ], skip_json: true, target_computer: computer_name ) end |
#remove_vm_hard_disk_drive(vm_id:, id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/hyperv/compute/requests/remove_vm_hard_disk_drive.rb', line 5 def remove_vm_hard_disk_drive(vm_id:, id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$HDD = $VM | Get-VMHardDiskDrive', { _by_id: id }], ['$HDD | Remove-VMHardDiskDrive', ] ], skip_json: true, target_computer: computer_name ) end |
#remove_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/hyperv/compute/requests/remove_vm_network_adapter.rb', line 5 def remove_vm_network_adapter(id:, computer_name: nil, **) requires_one , :vm_id, :management_os .delete :management_os cmdlist = [] if [:vm_id] vm_id = .delete :vm_id cmdlist += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :vm_id cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }] end cmdlist << ['$NIC | Remove-VMNetworkAdapter', ] run_cmdlist( cmdlist, skip_json: true, target_computer: computer_name ) end |
#remove_vm_switch(id:, computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/remove_vm_switch.rb', line 5 def remove_vm_switch(id:, computer_name: nil, **) run_cmd 'Remove-VMSwitch', _target_computer: computer_name, _by_id: id, _skip_json: true, force: true, ** end |
#rename_vm(id:, new_name:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/rename_vm.rb', line 5 def rename_vm(id:, new_name:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Rename-VM', { new_name:, ** }] ], target_computer: computer_name, skip_json: true ) end |
#rename_vm_network_adapter(id:, new_name:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hyperv/compute/requests/rename_vm_network_adapter.rb', line 5 def rename_vm_network_adapter(id:, new_name:, computer_name: nil, **) requires_one , :vm_id, :management_os .delete :management_os cmdlist = [] if [:vm_id] vm_id = .delete :vm_id cmdlist += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :vm_id cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }] end cmdlist << ['$NIC | Rename-VMNetworkAdapter', { new_name:, ** }] run_cmdlist(cmdlist, target_computer: computer_name, skip_json: true) end |
#rename_vm_switch(id:, new_name:, computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/rename_vm_switch.rb', line 5 def rename_vm_switch(id:, new_name:, computer_name: nil, **) run_cmd 'Rename-VMSwitch', new_name:, _target_computer: computer_name, _by_id: id, _skip_json: true, ** end |
#resize_vhd(path:, size_bytes:, computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/resize_vhd.rb', line 5 def resize_vhd(path:, size_bytes:, computer_name: nil, **) run_cmd 'Resize-VHD', _target_computer: computer_name, _skip_json: true, path:, size_bytes:, ** end |
#restart_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/restart_vm.rb', line 5 def restart_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Restart-VM', { force: true, ** }] ], skip_json: true, target_computer: computer_name ) end |
#resume_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/resume_vm.rb', line 5 def resume_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Resume-VM', ] ], skip_json: true, target_computer: computer_name ) end |
#save_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/save_vm.rb', line 5 def save_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Save-VM', ] ], skip_json: true, target_computer: computer_name ) end |
#set_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/set_vm.rb', line 5 def set_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Set-VM', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_bios(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/set_vm_bios.rb', line 5 def set_vm_bios(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Set-VMBios', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_com_port(id:, vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/set_vm_com_port.rb', line 5 def set_vm_com_port(id:, vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$COM = $VM | Get-VMComPort', { _by_id: id }], ['$COM | Set-VMComPort', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_dvd_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/set_vm_dvd_drive.rb', line 5 def set_vm_dvd_drive(id:, vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$DVD = $VM | Get-VMDvdDrive', { _by_id: id }], ['$DVD | Set-VMDvdDrive', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_firmware(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/set_vm_firmware.rb', line 5 def set_vm_firmware(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Set-VMFirmware', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_floppy_disk_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/set_vm_floppy_disk_drive.rb', line 5 def set_vm_floppy_disk_drive(id:, vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$Floppy = $VM | Get-VMFloppyDiskDrive', { _by_id: id }], ['$Floppy | Set-VMFloppyDiskDrive', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_hard_disk_drive(id:, vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/set_vm_hard_disk_drive.rb', line 5 def set_vm_hard_disk_drive(id:, vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$HDD = $VM | Get-VMHardDiskDrive', { _by_id: id }], ['$HDD | Set-VMHardDiskDrive', { passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_key_protector(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/hyperv/compute/requests/set_vm_key_protector.rb', line 5 def set_vm_key_protector(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Set-VMKeyProtector', ] ], target_computer: computer_name ) end |
#set_vm_network_adapter(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hyperv/compute/requests/set_vm_network_adapter.rb', line 5 def set_vm_network_adapter(id:, computer_name: nil, **) requires_one , :vm_id, :management_os .delete :management_os cmdlist = [] if [:vm_id] vm_id = .delete :vm_id cmdlist += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :vm_id cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }] end cmdlist << ['$NIC | Set-VMNetworkAdapter', { passthru: true, ** }] run_cmdlist(cmdlist, target_computer: computer_name) end |
#set_vm_network_adapter_vlan(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hyperv/compute/requests/set_vm_network_adapter_vlan.rb', line 5 def set_vm_network_adapter_vlan(id:, computer_name: nil, **) requires_one , :vm_id, :management_os .delete :management_os cmdlist = [] if [:vm_id] vm_id = .delete :vm_id cmdlist += [ ['$VM = Get-VM', { id: vm_id }], ['$NIC = $VM | Get-VMNetworkAdapter', { _by_id: id }] ] else .delete :vm_id cmdlist << ['$NIC = Get-VMNetworkAdapter', { _by_id: id, management_os: true }] end cmdlist << ['$NIC | Set-VMNetworkAdapterVlan', { passthru: true, ** }] run_cmdlist(cmdlist, target_computer: computer_name) end |
#set_vm_security(vm_id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/hyperv/compute/requests/set_vm_security.rb', line 5 def set_vm_security(vm_id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: vm_id }], ['$VM | Set-VMSecurity', { _always_include: %i[encrypt_state_and_vm_migration_traffic virtualization_based_security_opt_out], passthru: true, ** }] ], target_computer: computer_name ) end |
#set_vm_switch(id:, computer_name: nil, **options) ⇒ Object
5 6 7 |
# File 'lib/fog/hyperv/compute/requests/set_vm_switch.rb', line 5 def set_vm_switch(id:, computer_name: nil, **) run_cmd 'Set-VMSwitch', _target_computer: computer_name, _by_id: id, passthru: true, ** end |
#start_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/start_vm.rb', line 5 def start_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Start-VM', ] ], skip_json: true, target_computer: computer_name ) end |
#stop_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/stop_vm.rb', line 5 def stop_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Stop-VM', { force: true, ** }] ], skip_json: true, target_computer: computer_name ) end |
#supports_clusters? ⇒ Boolean
Does the Hyper-V install support clusters - i.e. is the machine joined to a failover cluster
187 188 189 190 191 192 |
# File 'lib/fog/hyperv/compute.rb', line 187 def supports_clusters? run_wql('SELECT Name FROM MSCluster_ResourceGroup', _namespace: 'root/mscluster/*')[:xml_fragment] && true rescue StandardError => e logger.debug "Cluster support checking failed with #{e.class}: #{e.}" false end |
#suspend_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/suspend_vm.rb', line 5 def suspend_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Suspend-VM', ] ], skip_json: true, target_computer: computer_name ) end |
#update_vm(id:, computer_name: nil, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/hyperv/compute/requests/update_vm.rb', line 5 def update_vm(id:, computer_name: nil, **) run_cmdlist( [ ['$VM = Get-VM', { id: }], ['$VM | Update-VM', ] ], skip_json: true, target_computer: computer_name ) end |
#valid? ⇒ Boolean
Is the Hyper-V provider valid - i.e. can it communicate with a Hyper-V install
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/fog/hyperv/compute.rb', line 174 def valid? if local? run_cmd('Get-VMHost', _return_fields: :name) && true else run_wql('SELECT Name FROM Msvm_ComputerSystem WHERE Caption = "Hosting Computer System"')[:xml_fragment] && true end rescue StandardError => e logger.debug "Validation failed with #{e.class}; #{e.}" false end |