PowerCLI

 View Only
  • 1.  Attach a PCI Network passthrough device to VM in a VAPP

    Posted Mar 11, 2015 05:09 PM

    Hello,

    I currently have a security lab setup which requires a VM to use a PCI passthrough network card.   It takes me about an hour and a half to reset a lab for each person every week.  I've decided to try to automate this but am haveing problems figuring out what the unique ID of the PCI passthrough device in powershell.  I'm able to attach to the nic without a problem in vsphere 5.1 but have yet to be able to attach it in powershell.  Here is an example of what I'm doing.

    New-VApp -Name SPod8 -Location (VMHost 10.10.10.100) -vApp (Get-VApp GoldMasterv5) -Datastore DC2store

    In vsphere I would simply attach a pci pass-through for each server.

    Modify HQ-SRV network port

    -Add a pci passthrough

    -Select 03:00.3 pci card

    Modify Employee-PC

        -Add a pci passthrough

        -Select 0a:00.0

    Modify Guest-PC

        -Add a pci passthrough

        -Select 0a:00.1

    Some of the commands I’ve run and attempted to use are as follows:

    **This did not work complained about the device ID.**

    Add-PassThroughDevice 10.10.10.100 -VM Guest-PC –ID 0a:00.0   

    **Brings up names of PCI devices but not unique assignable port id’s none that will work with the command add-passthroughdevice id

    Get-vmhost 10.10.10.100 | get-passthroughdevice

    PowerCLI C:\> Get-PassthroughDevice -VMHost 10.10.10.100

    Key        Name                           VendorName                     Type

    ---        ----                           ----------                     ----

               I350 Gigabit Network Connec... Intel Corporation              Pci

               82580 Gigabit Network Conne... Intel Corporation              Pci

               C600/X79 series chipset USB... Intel Corporation              Pci

               C600/X79 series chipset USB... Intel Corporation              Pci

               Patsburg 4 port SATA IDE Co... Intel Corporation              Pci

               iLO4                           Hewlett-Packard Company        Pci

               Smart Array P420i              Hewlett-Packard Company        Pci

               NetXtreme II BCM57810 10 Gi... Broadcom Corporation           Pci

    So I tried it with a variable but I need to figure out how to specify only one VAPP on the specific VMHost to execute the command.   It appears to want to apply it to all the Guest-PC’s on all vmhosts and in all vapps.

    $pcicard = Get-PassthroughDevice -VMHost  10.10.10.100 -Type Pci

    PowerCLI C:\> Add-PassThroughDevice  -VM Guest-PC -PassthroughDevice $pcicard[1] -Whatif

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    PowerCLI C:\>


    At this point i'm questioning how to pipline this command to just the one vapp and on only the vmhost 10.10.10.100 or if there is some easier way to do this via powercli.



  • 2.  RE: Attach a PCI Network passthrough device to VM in a VAPP

    Posted Mar 12, 2015 02:56 PM

    I manually assigned the nics through vsphere to vms but still not finding a unique identifier when queering the nic that is actually assigned to the VM.   When you look at both the query's below they com back with identical queries even though different sub interfaces on the PCI card are assigned.

    PowerCLI C:\>  get-vapp SPOD8 | Get-VM Guest-PC | Get-PassthroughDevice

    Key        Name                           VendorName                     Type

    ---        ----                           ----------                     ----

    13000      82580 Gigabit Network Conne... Intel Corporation              Pci

    Here is the actual nic assigned to that VM

    0a:00.1| Intel Corporation 82580 gigabit network card

    PowerCLI C:\>  get-vapp SPOD8 | Get-VM Employee-PC | Get-PassthroughDevice

    Key        Name                           VendorName                     Type

    ---        ----                           ----------                     ----

    13000      82580 Gigabit Network Conne... Intel Corporation              Pci

    Here is the actual nic assigned to that VM

    0a:00.0| Intel Corporation 82580 gigabit network card


    If I use the following sequence of commands i'm able to reassign the same sub-interface but I still am unable to see anything unique in the queries.


    PowerCLI C:\>  get-vapp SISAS_ATC_POD8 | Get-VM Guest-PC | Get-PassthroughDevice | Remove-PassthroughDevice

    Perform operation?

    Remove passthrough device '82580 Gigabit Network Connection'.

    [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

    PowerCLI C:\> get-vapp SISAS_ATC_POD8 | Get-VM Guest-PC | Add-PassThroughDevice -PassthroughDevice $PCI02 -Whatif

    What if: Add passthrough device '82580 Gigabit Network Connection' to VM 'Guest-PC'.

    PowerCLI C:\> get-vapp SISAS_ATC_POD8 | Get-VM Guest-PC | Add-PassThroughDevice -PassthroughDevice $PCI02

    Key        Name                           VendorName                     Type

    ---        ----                           ----------                     ----

    13000      82580 Gigabit Network Conne... Intel Corporation              Pci

    PowerCLI C:\>

    Verified in vsphere the same sub interface is assigned.



  • 3.  RE: Attach a PCI Network passthrough device to VM in a VAPP

    Posted Mar 14, 2015 03:37 PM

    So apprently the cmdlet Add-PassthroughDevice does not give me the option to look at or add the subids on a quadport card so here is how I was able to do it.  Thanks to Greg from  VMware and Powershell | Automating VMWare Infrastructure using powershell powercli – esx esxi vsphere

    function add-uniquepcipassthroughdevice {

    [cmdletbinding()]

    param (

    [Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()][string]$vm,

    [Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()][string]$pciid,

    [Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()][string]$vmhost,

    [Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()][string]$vapp

    )

    $vmhostview= get-view -viewtype hostsystem -filter @{'name'=$vmhost}

    $vendorid = ($vmhostview.hardware.pcidevice |?{$_.id -eq $pciid}).vendorid

    $deviceid = ($vmhostview.hardware.pcidevice |?{$_.id -eq $pciid}).deviceid

    $devicename = ($vmhostview.hardware.pcidevice |?{$_.id -eq $pciid}).devicename

    $systemid = (get-esxcli -vmhost $vmhost).system.uuid.get()  # noob way to do it but vspher has this shit hidden hit vmware up on how to do this outside of esxcli

    $vmv=(get-vapp -name $vapp | get-vm -name $vm).Extensiondata

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.deviceChange  = New-Object VMware.Vim.VirtualDeviceConfigSpec

    $spec.deviceChange[0].Operation = New-Object VMware.Vim.VirtualDeviceConfigSpecOperation

    $spec.deviceChange[0].Operation = 'add'

    $spec.deviceChange[0].device = New-Object VMware.Vim.VirtualPCIPassthrough

    $spec.deviceChange[0].device.key = -100

    $spec.deviceChange[0].Device.DeviceInfo = New-Object VMware.Vim.Description

    $spec.deviceChange[0].Device.DeviceInfo.label = 'PCI device 0'

    $spec.deviceChange[0].Device.Backing = new-object vmware.vim.VirtualPCIPassthroughDeviceBackingInfo

    $spec.deviceChange[0].Device.Backing.devicename = $devicename

    $spec.deviceChange[0].Device.Backing.id = $pciid

    $spec.deviceChange[0].Device.Backing.deviceId = $deviceid  ####THISdoesn't seem to do anything

    $spec.deviceChange[0].Device.Backing.systemId = $systemid  #3553494a-2d34-4d32-3234-313330303357

    $spec.deviceChange[0].Device.Backing.vendorId = $vendorid

    $spec.deviceChange[0].Device.connectable = New-Object vmware.vim.VirtualDeviceConnectInfo

    $spec.deviceChange[0].Device.connectable.startConnected = $true

    $spec.deviceChange[0].Device.connectable.allowGuestControl = $false

    $spec.deviceChange[0].Device.connectable.connected = $true

    $spec.devicechange[0].Device.DeviceInfo.Summary = ''

    $vmv.ReconfigVM_Task($spec)

    }