Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local hyper_v = {}
- -- Определение интерфейса для диска, который можно подключить к SCSI-контроллеру
- hyper_v.IScsiDrive = {}
- -- Defines the current state of a virtual machine.
- hyper_v.VirtualMachineState = {
- -- <summary>The state of the virtual machine could not be determined.</summary>
- Unknown = 0,
- -- <summary>The virtual machine is in an other state.</summary>
- Other = 1,
- -- <summary>The virtual machine is running.</summary>
- Running = 2,
- -- <summary>The virtual machine is turned off.</summary>
- Off = 3,
- -- <summary>The virtual machine is in the process of turning off.</summary>
- ShuttingDown = 4,
- -- <summary>The virtual machine does not support being started or turned off.</summary>
- NotApplicable = 5,
- -- <summary>The virtual machine might be completing commands, and it will drop any new requests.</summary>
- EnabledButOffline = 6,
- -- <summary>The virtual machine is in a test state.</summary>
- InTest = 7,
- -- <summary>The virtual machine might be completing commands, but it will queue any new requests.</summary>
- Deferred = 8,
- -- <summary>The virtual machine is running but in a restricted mode. The behavior of the virtual machine is similar to the Running state, but it processes only a restricted set of commands. All other requests are queued.</summary>
- Quiesce = 9,
- -- <summary>The virtual machine is in the process of starting. New requests are queued.</summary>
- Starting = 10
- }
- hyper_v.VirtualHardDrive = {}
- hyper_v.VirtualHardDrive.__index = hyper_v.VirtualHardDrive
- -- The file format of the virtual hard disk.
- hyper_v.VirtualHardDiskFormat = {
- -- <summary>Generation 1 virtual hard disk format.</summary>
- Vhd = 2,
- -- <summary>Generation 2 virtual hard disk format.</summary>
- Vhdx = 3
- }
- -- Defines the type of virtual hard disk.
- hyper_v.VirtualHardType = {
- -- <summary>Space for fixed virtual hard disks is first allocated when the file is created.</summary>
- FixedSize = 2,
- -- <summary>Space for dynamically expanding virtual hard disks is allocated on demand.</summary>
- DynamicallyExpanding = 3
- -- Differencing disks are not supported by this library.
- -- Differencing = 4
- }
- hyper_v.VirtualHardDisk = {}
- hyper_v.VirtualHardDisk.__index = hyper_v.VirtualHardDisk
- -- Define the ScsiController class
- hyper_v.ScsiController = {}
- hyper_v.ScsiController.__index = hyper_v.ScsiController
- hyper_v.ScsiController.Drives = {}
- -- Defines virtual DVD media
- hyper_v.VirtualDvdDisk = {}
- hyper_v.VirtualDvdDisk.__index = hyper_v.VirtualDvdDisk
- -- Defines a virtual DVD drive
- hyper_v.VirtualDvdDrive = {}
- hyper_v.VirtualDvdDrive.__index = hyper_v.VirtualDvdDrive
- hyper_v.WmiHelpers = {}
- hyper_v.SecureBootTemplate = {}
- hyper_v.SecureBootTemplate.RsOpenServer = "{1734C6E8-3154-4DDA-BA5F-A874CC483422}"
- hyper_v.SecureBootTemplate.RsUEFICertificateAuthority = "{272E7447-90A4-4563-A4B9-8E4AB00526CE}"
- hyper_v.SecureBootTemplate.OpenSourceShieldedVM = "{4292AE2B-EE2C-42B5-A969-DD8F8689F6F3}"
- -- Define the MacAddress class
- hyper_v.MacAddress = {}
- hyper_v.MacAddress.__index = hyper_v.MacAddress
- -- Define the NetworkAdapter class
- hyper_v.NetworkAdapter = {}
- hyper_v.NetworkAdapter.__index = hyper_v.NetworkAdapter
- -- Defines the automatic start action.
- hyper_v.AutomaticStartAction = {
- -- Do not start automatically.
- Nothing = 2,
- -- Automatically start if the virtual machine was running when the service stopped.
- StartIfRunning = 3,
- -- Always start the virtual machine automatically.
- AlwaysStart = 4
- }
- -- Defines the automatic stop action.
- hyper_v.AutomaticStopAction = {
- -- Save the virtual machine state.
- Save = 3,
- -- Turn off the virtual machine.
- TurnOff = 2,
- -- Shutdown the guest operating system.
- Shutdown = 4
- }
- -- Defines the port mirroring mode for a network adapter.
- hyper_v.PortMirroringMode = {
- -- The network adapter will not participate in mirroring.
- None = nil,
- -- The network adapter will accept mirrored data from source ports.
- Destination = nil,
- -- The network adapter will send mirrored data to detination ports.
- Source = nil
- }
- -- Defines the priority when balancing memory availability compared to other virtual machines.
- hyper_v.MemoryWeight = {
- -- The lowest priority possible.
- Lowest = 0,
- -- The priority is lower than low.
- Lower = 1250,
- -- The priority is lower than balanced.
- Low = 2500,
- -- The priority is lower than balanced.
- BalancedLow = 3750,
- -- The priority is balanced.
- Balanced = 5000,
- -- The priority is higher than balanced.
- BalancedHigh = 6250,
- -- The priority is high.
- High = 7500,
- -- The priority is higher than high.
- Higher = 8750,
- -- The highest priority possible.
- Higest = 10000
- }
- function hyper_v.IScsiDrive.new()
- local obj = {}
- setmetatable(obj, hyper_v.IScsiDrive)
- hyper_v.IScsiDrive.__index = hyper_v.IScsiDrive
- return obj
- end
- -- Constructor function for MacAddress class
- function hyper_v.MacAddress.new(mac)
- local self = setmetatable({}, hyper_v.MacAddress)
- self.mac = mac
- return self
- end
- -- Method to validate the MAC address format and check if it is a unicast MAC address
- function hyper_v.MacAddress:validate()
- local pattern = "^([0-9A-Fa-f][0-9A-Fa-f](-|%|:)){5}[0-9A-Fa-f][0-9A-Fa-f]$"
- if string.match(self.mac, pattern) then
- return true
- else
- return false
- end
- end
- -- Method to convert the MacAddress object to its string representation
- function hyper_v.MacAddress:toString(lowercase)
- if lowercase then
- return string.lower(self.mac)
- else
- return self.mac
- end
- end
- -- Method to convert the MacAddress object to its string representation using a separator
- function hyper_v.MacAddress:toStringWithSeparator(separator, lowercase)
- local formattedMac = string.gsub(self.mac, "[-%:]", separator)
- if lowercase then
- return string.lower(formattedMac)
- else
- return formattedMac
- end
- end
- -- Constructor function for NetworkAdapter class
- function hyper_v.NetworkAdapter.new(virtualSwitch)
- local self = setmetatable({}, hyper_v.NetworkAdapter)
- self.IpsecOffloading = true
- self.IpsecSecurityAssociations = 512
- self.PortMirroringMode = "None"
- self.ProtectedNetwork = true
- self.Vmq = true
- self.VirtualSwitch = virtualSwitch
- return self
- end
- -- Method to set VLAN ID for NetworkAdapter
- function hyper_v.NetworkAdapter:setVlanId(value)
- if value < 1 or value > 4094 then
- error("VlanId must be between 1 and 4094.")
- end
- self.Vlan = true
- self.vlanId = value
- end
- -- Method to set Maximum Bandwidth for NetworkAdapter
- function hyper_v.NetworkAdapter:setMaximumBandwidth(value)
- if value > 999999999 then
- error("MaximumBandwidth must be between 0 and 999999999.")
- end
- self.maximumBandwidth = value
- end
- -- Method to set Minimum Bandwidth for NetworkAdapter
- function hyper_v.NetworkAdapter:setMinimumBandwidth(value)
- if value > 999999999 then
- error("MinimumBandwidth must be between 0 and 999999999.")
- end
- self.minimumBandwidth = value
- end
- function hyper_v.ScsiController.new()
- local self = setmetatable({}, hyper_v.ScsiController)
- self.Drives = {}
- return self
- end
- function hyper_v.ScsiController:init()
- for i = 1, 64 do
- table.insert(self.Drives, i)
- end
- end
- function hyper_v.WmiHelpers.Dispose(array)
- for _, managementObject in ipairs(array) do
- managementObject:Dispose()
- end
- end
- function hyper_v.WmiHelpers.First(collection)
- for _, managementObject in ipairs(collection) do
- return managementObject
- end
- return nil
- end
- function hyper_v.WmiHelpers.ToObjectArray(managementStrings)
- local managementObjects = {}
- for index = 1, #managementStrings do
- managementObjects[index] = managementStrings[index]
- end
- return managementObjects
- end
- function hyper_v.VirtualDvdDrive:new()
- local self = setmetatable({}, hyper_v.VirtualDvdDrive)
- self.VirtualDvdDisk = nil
- return self
- end
- function hyper_v.VirtualDvdDrive:newWithDisk(virtualDvdDisk)
- local self = setmetatable({}, hyper_v.VirtualDvdDrive)
- self.VirtualDvdDisk = virtualDvdDisk
- return self
- end
- function hyper_v.VirtualDvdDisk:new(path)
- local self = setmetatable({}, hyper_v.VirtualDvdDisk)
- self.Path = path
- return self
- end
- function hyper_v.VirtualHardDisk:new()
- local vhd = {}
- setmetatable(vhd, hyper_v.VirtualHardDisk)
- vhd.Format = nil
- vhd.Path = nil
- vhd.size = 0
- return vhd
- end
- function hyper_v.VirtualHardDisk:SetSize(value)
- if self.Format == "Vhd" then
- if value < 1 or value > 2040 then
- error("Size must be between 1 and 2040.")
- end
- elseif self.Format == "Vhdx" then
- if value < 1 or value > 65536 then
- error("Size must be between 1 and 65536.")
- end
- end
- self.size = value
- end
- function hyper_v.VirtualHardDrive:new()
- local vhd = {}
- setmetatable(vhd, hyper_v.VirtualHardDrive)
- vhd.MaximumIOPS = 0
- vhd.MinimumIOPS = 0
- vhd.VirtualHardDisk = nil
- return vhd
- end
- function hyper_v.VirtualHardDrive:SetMaximumIOPS(value)
- if value < 0 or value > 1000000000 then
- error("MaximumIOPS must be between 0 and 1000000000.")
- end
- self.MaximumIOPS = value
- end
- function hyper_v.VirtualHardDrive:SetMinimumIOPS(value)
- if value < 0 or value > 1000000000 then
- error("MinimumIOPS must be between 0 and 1000000000.")
- end
- self.MinimumIOPS = value
- end
- function hyper_v.VirtualHardDrive:AttachVirtualHardDisk(virtualHardDisk)
- self.VirtualHardDisk = virtualHardDisk
- end
- function hyper_v.VirtualHardDrive:__call(virtualHardDisk, minimumIOPS, maximumIOPS)
- local vhd = {}
- setmetatable(vhd, hyper_v.VirtualHardDrive)
- vhd.VirtualHardDisk = virtualHardDisk
- vhd.MinimumIOPS = minimumIOPS
- vhd.MaximumIOPS = maximumIOPS
- return vhd
- end
- return hyper_v
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement