OVH Virtual Mac (vmac) API

Asphyxia

Owner
Administrator
Apr 25, 2015
1,844
2
2,197
327
Code:
Promise.promisifyAll(ovh);

function requestVirtualMac(ip_address) {
return ovh.requestAsync('POST', '/dedicated/server/' + config.SERVICE_NAME + '/virtualMac', {
  ipAddress: ip_address,
  type: 'ovh',
  virtualMachineName: uuid.v4()
}).then(function(result) {
  arclog.log("OVH is now working on a MAC for " + ip_address + "...", "info");
  return checkRequestStatus(result, ip_address);
}).catch(function(err) {
  arclog.error("Got problem requesting virtualMac for IP " + ip_address, err);
});
}

From the above, I sourced this. One could just pre-build all the different distros/flavors in your hypervisor VM export of choice. Then just import all your bare exported VM instances on-the-fly, have the VMAC generated, assigned, queue (pool) the IP assignment or DHCP and listen for IP.

Just like that, you have a 1-2-3 fresh VM up and running. The developer of the above script claims Virtkick is a solution but in my opinion I would just script everything in PHP.

I hate paying $50+ monthly just for something that is basic cron scheduling, database calls, payment processing via gateways in PayPal/Stripe, and.. at the end of the day, all this is entirely scriptable in a way to have automated with minimal effort really. Let a user register/login, select a VM to deploy with customizable RAM/CPU, make sure the hypervisor has the resources. Deploy!

This could be a really fun project ;) also keep in mind there may be more to the above request URL for the API. For example, you may have to enable dev mode (unsure), configure app access, and possibly have a token.

You at least know it is possible though, I've done some basic groundwork. I'll do the rest later as I get to it
 

Asphyxia

Owner
Administrator
Apr 25, 2015
1,844
2
2,197
327
Just an additional note, if you want to combine this vmac stuff with automatic provisioning of Linux on Hyper-V, this place covers that quite damn well:

Bash:
#function New-LinuxVM {
    #requires -Modules Hyper-V
    [CmdletBinding(SupportsShouldProcess=$true)]
    param
    (
        [Parameter(Mandatory=$true, Position=1)][String]$VMName,
        [Parameter()][String]$VHDXName = '',
        [Parameter()][String]$VMStoragePath = '',
        [Parameter()][String]$VHDStoragePath = '',
        [Parameter()][String]$InstallISOPath = '',
        [Parameter()][Switch]$Cluster,
        [Parameter()][String]$VMSwitchName = '',
        [Parameter()][Uint32]$StartupMemory = 512MB,
        [Parameter()][Uint32]$MinimumMemory = 256MB,
        [Parameter()][Uint32]$MaximumMemory = 1GB,
        [Parameter()][Uint64]$VHDXSizeBytes = 40GB
    )

    if([String]::IsNullOrEmpty($VHDXName))
    {
        $VHDXName = '{0}.vhdx' -f $VMName
    }
    if($VHDXName -notmatch '\.vhdx$')
    {
        $VHDXName += '.vhdx'
    }
    if([String]::IsNullOrEmpty($VMStoragePath))
    {
        $VMStoragePath = (Get-VMHost).VirtualMachinePath
    }
    if(-not (Test-Path -Path $VMStoragePath))
    {
        Write-Error -Message ('VM path {0} does not exist.' -f $VMStoragePath)
        return
    }
    if([String]::IsNullOrEmpty($VHDStoragePath))
    {
        $VHDStoragePath = (Get-VMHost).VirtualHardDiskPath
    }
    if(-not (Test-Path -Path $VHDStoragePath))
    {
        Write-Error -Message ('Storage path {0} does not exist.' -f $VHDStoragePath)
        return
    }
    $VHDStoragePath = Join-Path -Path $VHDStoragePath -ChildPath $VHDXName
    if([String]::IsNullOrEmpty($InstallISOPath) -or -not (Test-Path -Path $InstallISOPath -PathType Leaf))
    {
        Write-Error -Message ('ISO {0} does not exist' -f $InstallISOPath)
        return
    }
    if([String]::IsNullOrEmpty($VMSwitchName))
    {
        $VMSwitchName = (Get-VMSwitch | ? SwitchType -eq 'External')[0].Name
    }
    if([String]::IsNullOrEmpty($VMSwitchName))
    {
        Write-Error -Message ('No virtual switch specified')
        return
    }

    $VM = New-VM -Name $VMName -MemoryStartupBytes $StartupMemory -SwitchName $VMSwitchName -Path $VMStoragePath -Generation 2 -NoVHD
    Set-VMMemory -VM $VM -DynamicMemoryEnabled $true -MinimumBytes $MinimumMemory -MaximumBytes $MaximumMemory
    Set-VMProcessor -VM $VM -Count 2
    Start-VM -VM $VM
    Stop-VM -VM $VM -Force
    New-VHD -Path $VHDStoragePath -SizeBytes $VHDXSizeBytes -Dynamic -BlockSizeBytes 1MB
    $VMVHD = Add-VMHardDiskDrive -VM $VM -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path $VHDStoragePath -Passthru
    $VMDVDDrive = Add-VMDvdDrive -VM $VM -ControllerNumber 0 -ControllerLocation 1 -Passthru
    $VMNetAdapter = Get-VMNetworkAdapter -VM $VM
    Set-VMNetworkAdapter -VMNetworkAdapter $VMNetAdapter -StaticMacAddress ($VMNetAdapter.MacAddress)
    Set-VMFirmware -VM $VM -BootOrder $VMDVDDrive, $VMVHD, $VMNetAdapter -EnableSecureBoot On -SecureBootTemplate 'MicrosoftUEFICertificateAuthority'
    Set-VMDvdDrive -VMDvdDrive $VMDVDDrive -Path $InstallISOPath
    if($Cluster)
    {
        Add-ClusterVirtualMachineRole -VMName $VMName
    }
#}
 
Top