Exemple #1
0
        public static bool AddNetwork(
            dynamic json, string networkUuid, string networkName)
        {
            if (NtnxUtil.PassThroughNonNull(networkUuid))
            {
                json.spec.resources.nic_list[0].subnet_reference.uuid = networkUuid;
            }
            else if (NtnxUtil.PassThroughNonNull(networkName))
            {
                // TODO: grab images by name.
                var networks = GetSubnetCmdlet.GetSubnetsByName(networkName);
                if (networks.Length > 1)
                {
                    for (int i = 0; i < networks.Length; ++i)
                    {
                        Console.WriteLine("Network " + i.ToString(CultureInfo.InvariantCulture) + ": " + networks[i].Uuid);
                    }

                    return(false);
                }
                else
                {
                    json.spec.resources.nic_list[0].subnet_reference.uuid =
                        networks[0].Uuid;
                }
            }

            return(true);
        }
Exemple #2
0
        public static bool AddImage(
            dynamic json, string imageUuid, string imageName)
        {
            if (NtnxUtil.PassThroughNonNull(imageUuid))
            {
                json.spec.resources.disk_list[0].data_source_reference.uuid = imageUuid;
            }
            else if (NtnxUtil.PassThroughNonNull(imageName))
            {
                // TODO: grab images by name.
                var images = GetImageCmdlet.GetImagesByName(imageName);
                if (images.Length > 1)
                {
                    // Ambiguous: found more than 1 image with the same name
                    for (int i = 0; i < images.Length; ++i)
                    {
                        Console.WriteLine("Image " + i.ToString(CultureInfo.InvariantCulture) + ": " + images[i].Uuid);
                    }

                    return(false);
                }
                else
                {
                    json.spec.resources.disk_list[0].data_source_reference.uuid =
                        images[0].Uuid;
                }
            }

            return(true);
        }
Exemple #3
0
 protected override void ProcessRecord()
 {
     if (NtnxUtil.PassThroughNonNull(Uuid))
     {
         // TODO: WriteObject Task
         DeleteImageByUuid(Uuid);
     }
 }
Exemple #4
0
        protected override void ProcessRecord()
        {
            if (NtnxUtil.PassThroughNonNull(Uuid))
            {
                WriteObject(GetImageByUuid(Uuid));
                return;
            }

            var images = GetAllImages(BuildRequestBody());

            WriteObject(images);
        }
Exemple #5
0
        protected override void ProcessRecord()
        {
            if (NtnxUtil.PassThroughNonNull(Uuid))
            {
                WriteObject(GetSubnetByUuid(Uuid));
                return;
            }

            var subnets = GetAllSubnets(BuildRequestBody());

            WriteObject(subnets);
        }
Exemple #6
0
        // Given the parameters, build request body for '/images/list'.
        public dynamic BuildRequestBody()
        {
            dynamic json = JsonConvert.DeserializeObject("{}");

            if (Max != null)
            {
                json.length = Max;
            }

            if (NtnxUtil.PassThroughNonNull(Name))
            {
                json.filter = "name==" + Name;
            }

            return(json);
        }
Exemple #7
0
        protected override void ProcessRecord()
        {
            if (NtnxUtil.PassThroughNonNull(Uuid))
            {
                WriteObject(GetTaskByUuid(Uuid));
                return;
            }

            if (Task != null)
            {
                WriteObject(GetTaskByUuid(Task.Uuid));
                return;
            }

            var message = string.Format(CultureInfo.InvariantCulture, "Expected either -Uuid or -Task. We were given Uuid {0} and/or Task {1}", Uuid, Task);

            throw new NtnxException(message);
        }
Exemple #8
0
        protected override void ProcessRecord()
        {
            if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Uuid))
            {
                // If no params specified, then get all VMs.
                WriteObject(GetAllVms());
                return;
            }

            if (NtnxUtil.PassThroughNonNull(Uuid))
            {
                WriteObject(GetVmByUuid(Uuid));
                return;
            }

            if (NtnxUtil.PassThroughNonNull(Name))
            {
                WriteObject(GetVmByName(Name));
            }
        }
Exemple #9
0
        protected override void ProcessRecord()
        {
            if (this.VM != null)
            {
                this.Uuid = this.VM.Uuid;
            }

            if (string.IsNullOrEmpty(this.Name) && string.IsNullOrEmpty(this.Uuid))
            {
                var message = string.Format(CultureInfo.InvariantCulture, "Need -Name or -Uuid. We were given Name {0} and/or UUID {1}", this.Name, this.Uuid);
                throw new NtnxException(message);
            }

            if (NtnxUtil.PassThroughNonNull(Uuid))
            {
                WriteObject(DeleteVmByUuid(Uuid));
                return;
            }

            if (NtnxUtil.PassThroughNonNull(Name))
            {
                WriteObject(DeleteVmByName(Name));
            }
        }