Пример #1
0
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record != null)
            {
                NameLabel       = Record.name_label;
                NameDescription = Record.name_description;
                PhysicalSize    = Record.physical_size;
                Type            = Record.type;
                ContentType     = Record.content_type;
                Shared          = Record.shared;
                SmConfig        = CommonCmdletFunctions.ConvertDictionaryToHashtable(Record.sm_config);
            }
            else if (HashTable != null)
            {
                NameLabel       = Marshalling.ParseString(HashTable, "name_label");
                NameDescription = Marshalling.ParseString(HashTable, "name_description");
                PhysicalSize    = Marshalling.ParseLong(HashTable, "physical_size");
                Type            = Marshalling.ParseString(HashTable, "type");
                ContentType     = Marshalling.ParseString(HashTable, "content_type");
                Shared          = Marshalling.ParseBool(HashTable, "shared");
                SmConfig        = (Marshalling.ParseHashTable(HashTable, "sm_config"));
            }
            if (!ShouldProcess(session.Url, "SR.create"))
            {
                return;
            }

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

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.SR.async_create(session, XenHost, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(DeviceConfig), PhysicalSize, NameLabel, NameDescription, Type, ContentType, Shared, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(SmConfig));

                    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.SR.create(session, XenHost, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(DeviceConfig), PhysicalSize, NameLabel, NameDescription, Type, ContentType, Shared, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(SmConfig));

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

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

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

            UpdateSessions();
        }