protected override void ProcessRecord()
        {
            var attachedDisk = new AttachedDisk
            {
                AutoDelete  = AutoDelete,
                Boot        = Boot,
                DeviceName  = DeviceName,
                Interface__ = Nvme ? "NVME" : "SCSI",
                Mode        = ReadOnly ? "READ_ONLY" : "READ_WRITE",
                Source      = Source?.SelfLink
            };

            if (DiskType != null && GetUriPart("disktypes", DiskType.ToLower()) == "local-ssd")
            {
                attachedDisk.Type = "SCRATCH";
            }
            else
            {
                attachedDisk.Type = "PERSISTENT";
            }

            if (ParameterSetName == ParameterSetNames.New)
            {
                attachedDisk.InitializeParams = new AttachedDiskInitializeParams
                {
                    DiskName    = Name,
                    DiskSizeGb  = Size,
                    DiskType    = DiskType,
                    SourceImage = SourceImage?.SelfLink
                };
            }
            WriteObject(attachedDisk);
        }
Exemplo n.º 2
0
        public void InsertInstance(String zone, String name, String imgProject, String imgFamily, String interface__ = "SCSI")
        {
            GetInstanceShh("api-project-545812698446", zone, name);
            var image = service.Images.GetFromFamily(imgProject, imgFamily).Execute();

            IList <AttachedDisk>         attachedDisks = new List <AttachedDisk>();
            AttachedDisk                 attachedDisk  = new AttachedDisk();
            AttachedDiskInitializeParams attachedDiskInitializeParams = new AttachedDiskInitializeParams();

            attachedDiskInitializeParams.DiskSizeGb  = image.DiskSizeGb;
            attachedDiskInitializeParams.SourceImage = image.SelfLink;


            attachedDisk.AutoDelete       = true;
            attachedDisk.Boot             = true;
            attachedDisk.Interface__      = interface__;
            attachedDisk.InitializeParams = attachedDiskInitializeParams;
            attachedDisks.Add(attachedDisk);

            var accessConfig = new AccessConfig();

            accessConfig.Name = "External NAT";
            accessConfig.Type = "ONE_TO_ONE_NAT";

            IList <NetworkInterface> networkInterfaces = new List <NetworkInterface>();
            NetworkInterface         networkInterface  = new NetworkInterface();

            networkInterface.Network       = "/global/networks/default";
            networkInterface.AccessConfigs = new List <AccessConfig>()
            {
                accessConfig
            };
            networkInterfaces.Add(networkInterface);

            Tags           tags       = new Tags();
            IList <string> stringList = new List <string>();

            tags.Items = new List <string>();
            tags.Items.Add("http-server");
            tags.Items.Add("https-server");


            Instance instance = new Instance()
            {
                MachineType = "zones/" + zone + "/machineTypes/n1-standard-1",
                // Metadata = metaData,
                Name = name,
                Tags = tags,
                NetworkInterfaces = networkInterfaces,
                Disks             = attachedDisks
            };

            service.Instances.Insert(instance, "api-project-545812698446", zone).Execute();
        }
Exemplo n.º 3
0
        protected override void ProcessRecord()
        {
            var attachedDisk = new AttachedDisk
            {
                AutoDelete  = AutoDelete,
                Boot        = Boot,
                DeviceName  = DeviceName,
                Interface__ = Nvme ? "NVME" : "SCSI",
                Mode        = ReadOnly ? "READ_ONLY" : "READ_WRITE",
                Source      = Source?.SelfLink
            };

            if (ParameterSetName == ParameterSetNames.New)
            {
                attachedDisk.InitializeParams = new AttachedDiskInitializeParams
                {
                    DiskName    = Name,
                    DiskSizeGb  = Size,
                    DiskType    = DiskType,
                    SourceImage = SourceImage.SelfLink
                };
            }
            WriteObject(attachedDisk);
        }
        /// <summary>
        /// ProcessRecord for Disk parameter set.
        /// </summary>
        private void ProcessDisk()
        {
            foreach (string diskName in RemoveDisk)
            {
                InstancesResource.DetachDiskRequest request = Service.Instances.DetachDisk(
                    _project, _zone, _name, diskName);
                Operation operation = request.Execute();
                AddZoneOperation(_project, _zone, operation, () =>
                {
                    WriteObject(Service.Instances.Get(_project, _zone, _name));
                });
            }

            foreach (object diskParam in AddDisk)
            {
                // Allow for taking Disk, AttachedDisk, and string objects.
                var newDisk = diskParam as AttachedDisk ?? (diskParam as PSObject)?.BaseObject as AttachedDisk;
                if (newDisk == null)
                {
                    var disk = diskParam as Disk ?? (diskParam as PSObject)?.BaseObject as Disk;
                    if (disk == null)
                    {
                        disk = Service.Disks.Get(_project, _zone, diskParam.ToString()).Execute();
                    }
                    newDisk = new AttachedDisk { Source = disk.SelfLink, DeviceName = disk.Name };
                }
                InstancesResource.AttachDiskRequest request =
                    Service.Instances.AttachDisk(newDisk, _project, _zone, _name);
                Operation operation = request.Execute();
                AddZoneOperation(_project, _zone, operation, () =>
                {
                    WriteObject(Service.Instances.Get(_project, _zone, _name));
                });
            }
        }
        protected override void ProcessRecord()
        {
            var attachedDisk = new AttachedDisk
            {
                AutoDelete = AutoDelete,
                Boot = Boot,
                DeviceName = DeviceName,
                Interface__ = Nvme ? "NVME" : "SCSI",
                Mode = ReadOnly ? "READ_ONLY" : "READ_WRITE",
                Source = Source?.SelfLink
            };

            if (ParameterSetName == ParameterSetNames.New)
            {
                attachedDisk.InitializeParams = new AttachedDiskInitializeParams
                {
                    DiskName = Name,
                    DiskSizeGb = Size,
                    DiskType = DiskType,
                    SourceImage = SourceImage.SelfLink
                };
            }
            WriteObject(attachedDisk);
        }