示例#1
0
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record != null)
            {
                VM          = Record.VM;
                USBGroup    = Record.USB_group;
                OtherConfig = CommonCmdletFunctions.ConvertDictionaryToHashtable(Record.other_config);
            }
            else if (HashTable != null)
            {
                VM          = Marshalling.ParseRef <VM>(HashTable, "VM");
                USBGroup    = Marshalling.ParseRef <USB_group>(HashTable, "USB_group");
                OtherConfig = (Marshalling.ParseHashTable(HashTable, "other_config"));
            }
            if (!ShouldProcess(session.Url, "VUSB.create"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenServerCmdletDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VUSB.async_create(session, VM, USBGroup, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig));

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VUSB.create(session, VM, USBGroup, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig));

                    if (PassThru)
                    {
                        XenAPI.VUSB obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VUSB.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });

            UpdateSessions();
        }