{"action":"created","issue":{"url":"https://api.github.com/repos/vmware/pyvmomi-community-samples/issues/240","repository_url":"https://api.github.com/repos/vmware/pyvmomi-community-samples","labels_url":"https://api.github.com/repos/vmware/pyvmomi-community-samples/issues/240/labels{/name}","comments_url":"https://api.github.com/repos/vmware/pyvmomi-community-samples/issues/240/comments","events_url":"https://api.github.com/repos/vmware/pyvmomi-community-samples/issues/240/events","html_url":"https://github.com/vmware/pyvmomi-community-samples/issues/240","id":137356345,"number":240,"title":"Trouble getting virtual disk config to work","user":{"login":"draxeis","id":13227829,"avatar_url":"https://avatars.githubusercontent.com/u/13227829?v=3","gravatar_id":"","url":"https://api.github.com/users/draxeis","html_url":"https://github.com/draxeis","followers_url":"https://api.github.com/users/draxeis/followers","following_url":"https://api.github.com/users/draxeis/following{/other_user}","gists_url":"https://api.github.com/users/draxeis/gists{/gist_id}","starred_url":"https://api.github.com/users/draxeis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/draxeis/subscriptions","organizations_url":"https://api.github.com/users/draxeis/orgs","repos_url":"https://api.github.com/users/draxeis/repos","events_url":"https://api.github.com/users/draxeis/events{/privacy}","received_events_url":"https://api.github.com/users/draxeis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-29T20:03:06Z","updated_at":"2016-06-02T23:00:15Z","closed_at":null,"body":"Hi,\r\nI'm having trouble getting the disk spec to work, i've tried different variants on the disk config (there are a lot of configuration added to try to work out what it wants) but always get the error message on vcenter saying \"Invalid configuration for device '1'.\"  If i comment out the disk block it creates the VM fine.\r\n\r\nI've worked from the sample of adding_disk_to_vm.py, create_random_marvel_vms.py, and a few other samples i've found googling around. Any help would be appreciated.\r\n\r\nThanks,\r\nMark\r\n```\r\ndef create_vm(vm_name, si, vm_folder, resource_pool, host, datastore, network):\r\n    \"\"\"\r\n    :param name: String Name for the VirtualMachine\r\n    :param service_instance: ServiceInstance connection\r\n    :param vm_folder: Folder to place the VirtualMachine in\r\n    :param resource_pool: ResourcePool to place the VirtualMachine in\r\n    :param datastore: DataStrore to place the VirtualMachine on\r\n    \"\"\"\r\n    global cpucount\r\n    global memorysize\r\n    global disksizes\r\n    unit_number = 0\r\n    disk_type = 'thin'\r\n\r\n    datastore_path = '[' + str(datastore.name) + '] ' + vm_name \r\n    dbg('%s %s %s' % (datastore, datastore.name, datastore_path))\r\n    devices = []\r\n\r\n    scsi_spec = vim.vm.device.VirtualDeviceSpec()\r\n    scsi_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add\r\n    scsi_spec.device = vim.vm.device.ParaVirtualSCSIController()\r\n    scsi_spec.device.busNumber = 0\r\n    scsi_spec.device.controllerKey = 100\r\n    scsi_spec.device.sharedBus = 'noSharing'\r\n    devices.append(scsi_spec)\r\n\r\n    disk = 40\r\n    new_disk_kb = int(disk) * 1024 * 1024\r\n    disk_spec = vim.vm.device.VirtualDeviceSpec()\r\n    disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add\r\n    disk_spec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create\r\n    disk_spec.device = vim.vm.device.VirtualDisk()\r\n    disk_spec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()\r\n    if disk_type == 'thin':\r\n        disk_spec.device.backing.thinProvisioned = True\r\n    disk_spec.device.backing.diskMode = 'persistent'\r\n    disk_spec.device.backing.fileName = datastore_path + '/' + vm_name + '.vmdk'\r\n    disk_spec.device.backing.datastore = datastore\r\n    disk_spec.device.key = 2001\r\n    disk_spec.device.unitNumber = 1\r\n    disk_spec.device.capacityInKB = new_disk_kb\r\n    disk_spec.device.controllerKey = 100\r\n    devices.append(disk_spec)\r\n    dbg(\"Creating new disk with %sGBs\" % disk)\r\n\r\n    dbg(\"Creating new NIC for network '%s'\" % (network.name))\r\n    #add a NIC. the network Name must be set as the device name to create the NIC.\r\n    nic_spec = vim.vm.device.VirtualDeviceSpec()\r\n    nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add\r\n    nic_spec.device = vim.vm.device.VirtualE1000()\r\n    nic_spec.device.deviceInfo = vim.Description()\r\n#    nic_spec.device.deviceInfo.label = 'Network adapter 1'\r\n    nic_spec.device.deviceInfo.summary = network.name\r\n    nic_spec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()\r\n    nic_spec.device.backing.network = network \r\n    nic_spec.device.backing.deviceName = network.name\r\n    nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()\r\n    nic_spec.device.connectable.startConnected = True\r\n    nic_spec.device.connectable.connected = True\r\n    nic_spec.device.connectable.allowGuestControl = True \r\n    devices.append(nic_spec)\r\n\r\n    vmx_file = vim.vm.FileInfo(vmPathName=datastore_path)\r\n\r\n#    vmx_file = vim.vm.FileInfo(logDirectory=datastore_path,\r\n#                               snapshotDirectory=datastore_path,\r\n#                               suspendDirectory=datastore_path,\r\n#                               vmPathName=datastore_path)\r\n\r\n \r\n    config = vim.vm.ConfigSpec(name=vm_name, memoryMB=long(memorysize), numCPUs=cpucount,\r\n                               deviceChange=devices, files=vmx_file, guestId=guestosid,\r\n                               version='vmx-08', annotation=annotation)\r\n\r\n    print \"Creating VM {}...\".format(vm_name)\r\n    dbg(devices)\r\n    task = vm_folder.CreateVM_Task(config=config, pool=resource_pool, host=host)\r\n#    tasks.wait_for_tasks(si, [task])\r\n```"},"comment":{"url":"https://api.github.com/repos/vmware/pyvmomi-community-samples/issues/comments/223447621","html_url":"https://github.com/vmware/pyvmomi-community-samples/issues/240#issuecomment-223447621","issue_url":"https://api.github.com/repos/vmware/pyvmomi-community-samples/issues/240","id":223447621,"user":{"login":"prziborowski","id":13127297,"avatar_url":"https://avatars.githubusercontent.com/u/13127297?v=3","gravatar_id":"","url":"https://api.github.com/users/prziborowski","html_url":"https://github.com/prziborowski","followers_url":"https://api.github.com/users/prziborowski/followers","following_url":"https://api.github.com/users/prziborowski/following{/other_user}","gists_url":"https://api.github.com/users/prziborowski/gists{/gist_id}","starred_url":"https://api.github.com/users/prziborowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prziborowski/subscriptions","organizations_url":"https://api.github.com/users/prziborowski/orgs","repos_url":"https://api.github.com/users/prziborowski/repos","events_url":"https://api.github.com/users/prziborowski/events{/privacy}","received_events_url":"https://api.github.com/users/prziborowski/received_events","type":"User","site_admin":false},"created_at":"2016-06-02T23:00:15Z","updated_at":"2016-06-02T23:00:15Z","body":"I haven't tried your sample yet, but a couple things caught my attention.\r\n\r\nFirst is you have controllerKey = 100.\r\nThis is the pointer to the controller. You also specify this for the controller.\r\n`scsi_spec = vim.vm.device.VirtualDeviceSpec()\r\n    scsi_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add\r\n    scsi_spec.device = vim.vm.device.ParaVirtualSCSIController()\r\n    scsi_spec.device.busNumber = 0\r\n    scsi_spec.device.controllerKey = 100\r\n    scsi_spec.device.sharedBus = 'noSharing'\r\n    devices.append(scsi_spec)`\r\nYou should specify scsi_spec.device.key = 100.\r\nThen the disk will point to the controller. Currently the disk and controller pointer to some device with key=100.\r\n\r\nNext thing is you should key your devices with negative numbers to make sure they don't conflict with any existing devices (more of a thing for reconfigure than create, but a good pattern to have)."}}
{"actor":{"display_login":"prziborowski"}}