Beispiel #1
0
        /// <summary>
        /// This method adds name server delegation in the parent zone for the created child zone.
        /// The NS records are added in the parent zone that corresponds to the child zone
        /// </summary>
        /// <param name="zone">the created child zone</param>
        /// <param name="parent">the parent zone</param>
        private DnsRecordSet AddDnsNameserverDelegation(DnsZone zone, DnsZone parent)
        {
            DnsRecordSet recordSet = null;

            if (zone != null && parent != null && zone.NameServers != null && zone.NameServers.Count > 0)
            {
                List <NsRecord> nameServersList = new List <NsRecord>();
                foreach (string nameserver in zone.NameServers)
                {
                    NsRecord record = new NsRecord();
                    record.Nsdname = nameserver;
                    nameServersList.Add(record);
                }

                DnsRecordBase[] resourceRecords = nameServersList.ToArray();
                string          recordName      = this.Name.Replace('.' + parent.Name, "");
                recordSet = this.DnsClient.CreateDnsRecordSet(
                    parent.Name,
                    this.ResourceGroupName,
                    recordName,
                    3600,
                    RecordType.NS,
                    null,
                    true,
                    resourceRecords,
                    null);
            }
            return(recordSet);
        }
Beispiel #2
0
        /// <summary>
        /// This method parses the parent zone from the command arguments, depending
        /// on the format of the parent zone details passed.
        /// Supports resource id, parent zone name and the zone object.
        /// </summary>
        private DnsZone ParseParentZoneFromArguments()
        {
            DnsZone parent                  = null;
            string  parentZoneName          = this.ParentZoneName;
            string  parentResourceGroupName = this.ResourceGroupName;

            if (this.ParameterSetName == ObjectsParameterSetName && this.ParentZone != null)
            {
                parentZoneName          = this.ParentZone.Name;
                parentResourceGroupName = this.ParentZone.ResourceGroupName;
            }
            else if (this.ParameterSetName == IdsParameterSetName && !string.IsNullOrEmpty(this.ParentZoneId))
            {
                ResourceIdentifier resource = new ResourceIdentifier(ParentZoneId);
                string             subscriptionIdInContext = this.DefaultContext.Subscription.Id;
                parentZoneName          = resource.ResourceName;
                parentResourceGroupName = resource.ResourceGroupName;
                if (subscriptionIdInContext != resource.Subscription)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_NSDelegationSubscriptionMisMatch, this.Name, parentZoneName));
                }
            }
            if (parentZoneName != null)
            {
                parent      = new DnsZone();
                parent.Name = parentZoneName;
                parent.ResourceGroupName = parentResourceGroupName;
            }
            return(parent);
        }
Beispiel #3
0
        public override void ExecuteCmdlet()
        {
            if (this.Name.EndsWith("."))
            {
                this.Name = this.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", this.Name));
            }

            base.ConfirmAction(
                ProjectResources.Progress_CreatingNewZone,
                this.Name,
                () =>
            {
                ZoneType zoneType = this.ZoneType != null ? this.ZoneType.Value : Management.Dns.Models.ZoneType.Public;

                List <string> registrationVirtualNetworkIds = this.RegistrationVirtualNetworkId;
                List <string> resolutionVirtualNetworkIds   = this.ResolutionVirtualNetworkId;
                if (this.ParameterSetName == ObjectsParameterSetName)
                {
                    registrationVirtualNetworkIds = this.RegistrationVirtualNetwork?.Select(virtualNetwork => virtualNetwork.Id).ToList();
                    resolutionVirtualNetworkIds   = this.ResolutionVirtualNetwork?.Select(virtualNetwork => virtualNetwork.Id).ToList();
                }

                DnsZone result = this.DnsClient.CreateDnsZone(
                    this.Name,
                    this.ResourceGroupName,
                    this.Tag,
                    zoneType,
                    registrationVirtualNetworkIds,
                    resolutionVirtualNetworkIds);
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(zoneType == Management.Dns.Models.ZoneType.Private
                        ? string.Format(ProjectResources.Success_NewPrivateZone, this.Name, this.ResourceGroupName)
                        : string.Format(ProjectResources.Success_NewZone, this.Name, this.ResourceGroupName));

                this.WriteObject(result);

                try
                {
                    DnsZone parent = this.ParseParentZoneFromArguments();
                    if (parent != null && this.Name.EndsWith(parent.Name))
                    {
                        AddDnsNameserverDelegation(result, parent);
                        this.WriteVerbose(ProjectResources.Success);
                        this.WriteVerbose(string.Format(ProjectResources.Success_NSDelegation, this.Name, parent.Name));
                    }
                }
                catch (System.Exception ex)
                {
                    this.WriteWarning(string.Format(ProjectResources.Error_NSDelegation, this.Name));
                    this.WriteWarning(ex.Message);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            bool    deleted      = false;
            DnsZone zoneToDelete = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToDelete = new DnsZone
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = null,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToDelete = this.Zone;
            }

            if (zoneToDelete.Name != null && zoneToDelete.Name.EndsWith("."))
            {
                zoneToDelete.Name = zoneToDelete.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToDelete.Name));
            }

            bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";

            ConfirmAction(
                Force.IsPresent,
                string.Format(ProjectResources.Confirm_RemoveZone, zoneToDelete.Name),
                ProjectResources.Progress_RemovingZone,
                this.Name,
                () => { deleted = DnsClient.DeleteDnsZone(zoneToDelete, overwrite); });

            if (deleted)
            {
                WriteVerbose(ProjectResources.Success);
                WriteVerbose(string.Format(ProjectResources.Success_RemoveZone, zoneToDelete.Name, zoneToDelete.ResourceGroupName));
            }

            if (this.PassThru)
            {
                WriteObject(deleted);
            }
        }
        protected override void ProcessRecord()
        {
            bool deleted = false;
            DnsZone zoneToDelete = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToDelete = new DnsZone 
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = null,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToDelete = this.Zone;
            }

            if (zoneToDelete.Name != null && zoneToDelete.Name.EndsWith("."))
            {
                zoneToDelete.Name = zoneToDelete.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToDelete.Name));
            }

            bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";

            ConfirmAction(
                Force.IsPresent,
                string.Format(ProjectResources.Confirm_RemoveZone, zoneToDelete.Name),
                ProjectResources.Progress_RemovingZone,
                this.Name,
                () => { deleted = DnsClient.DeleteDnsZone(zoneToDelete, overwrite); });

            if (deleted)
            {
                WriteVerbose(ProjectResources.Success);
                WriteVerbose(string.Format(ProjectResources.Success_RemoveZone, zoneToDelete.Name, zoneToDelete.ResourceGroupName));
            }

            if (this.PassThru)
            {
                WriteObject(deleted);
            }
        }
Beispiel #6
0
        protected override void ProcessRecord()
        {
            if (this.Name.EndsWith("."))
            {
                this.Name = this.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", this.Name));
            }

            DnsZone result = this.DnsClient.CreateDnsZone(this.Name, this.ResourceGroupName, this.Tag);

            this.WriteVerbose(ProjectResources.Success);
            this.WriteVerbose(string.Format(ProjectResources.Success_NewZone, this.Name, this.ResourceGroupName));
            this.WriteObject(result);
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release.");

            if (this.Name.EndsWith("."))
            {
                this.Name = this.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", this.Name));
            }

            DnsZone result = this.DnsClient.CreateDnsZone(this.Name, this.ResourceGroupName, this.Tag);

            this.WriteVerbose(ProjectResources.Success);
            this.WriteVerbose(string.Format(ProjectResources.Success_NewZone, this.Name, this.ResourceGroupName));
            this.WriteObject(result);
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release. Also, the usability of Tag parameter in this cmdlet will be modified in a future release. This will impact creating, updating and appending tags for Azure resources. For more details about the change, please visit https://github.com/Azure/azure-powershell/issues/726#issuecomment-213545494");

            if (this.Name.EndsWith("."))
            {
                this.Name = this.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", this.Name));
            }

            DnsZone result = this.DnsClient.CreateDnsZone(this.Name, this.ResourceGroupName, this.Tag);

            this.WriteVerbose(ProjectResources.Success);
            this.WriteVerbose(string.Format(ProjectResources.Success_NewZone, this.Name, this.ResourceGroupName));
            this.WriteObject(result);
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release.");

            DnsZone result = null;
            DnsZone zoneToUpdate = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToUpdate = new DnsZone
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = "*",
                    Tags = this.Tag,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToUpdate = this.Zone;
            }

            if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith("."))
            {
                zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToUpdate.Name));
            }
            ConfirmAction(
                ProjectResources.Progress_Modifying,
                zoneToUpdate.Name,
                () =>
                {
                    bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";
                    result = this.DnsClient.UpdateDnsZone(zoneToUpdate, overwrite);

                    WriteVerbose(ProjectResources.Success);
                    WriteObject(result);
                });
        }
Beispiel #10
0
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release.");

            DnsZone result       = null;
            DnsZone zoneToUpdate = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToUpdate = new DnsZone
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = "*",
                    Tags = this.Tag,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToUpdate = this.Zone;
            }

            if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith("."))
            {
                zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToUpdate.Name));
            }
            ConfirmAction(
                ProjectResources.Progress_Modifying,
                zoneToUpdate.Name,
                () =>
            {
                bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";
                result         = this.DnsClient.UpdateDnsZone(zoneToUpdate, overwrite);

                WriteVerbose(ProjectResources.Success);
                WriteObject(result);
            });
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release. Also, the usability of Tag parameter in this cmdlet will be modified in a future release. This will impact creating, updating and appending tags for Azure resources. For more details about the change, please visit https://github.com/Azure/azure-powershell/issues/726#issuecomment-213545494");

            DnsZone result       = null;
            DnsZone zoneToUpdate = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToUpdate = new DnsZone
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = "*",
                    Tags = this.Tag,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToUpdate = this.Zone;
            }

            if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith("."))
            {
                zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToUpdate.Name));
            }

            bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";

            result = this.DnsClient.UpdateDnsZone(zoneToUpdate, overwrite);

            WriteVerbose(ProjectResources.Success);
            WriteObject(result);
        }
Beispiel #12
0
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release.");

            if (this.Name.EndsWith("."))
            {
                this.Name = this.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", this.Name));
            }

            ConfirmAction(
                ProjectResources.Progress_CreatingNewZone,
                this.Name,
                () =>
            {
                ZoneType zoneType = this.ZoneType != null ? this.ZoneType.Value : Management.Dns.Models.ZoneType.Public;

                List <string> registrationVirtualNetworkIds = this.RegistrationVirtualNetworkId;
                List <string> resolutionVirtualNetworkIds   = this.ResolutionVirtualNetworkId;
                if (this.ParameterSetName == ObjectsParameterSetName)
                {
                    registrationVirtualNetworkIds = this.RegistrationVirtualNetwork?.Select(virtualNetwork => virtualNetwork.Id).ToList();
                    resolutionVirtualNetworkIds   = this.ResolutionVirtualNetwork?.Select(virtualNetwork => virtualNetwork.Id).ToList();
                }

                DnsZone result = this.DnsClient.CreateDnsZone(
                    this.Name,
                    this.ResourceGroupName,
                    this.Tag,
                    zoneType,
                    registrationVirtualNetworkIds,
                    resolutionVirtualNetworkIds);
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(zoneType == Management.Dns.Models.ZoneType.Private
                        ? string.Format(ProjectResources.Success_NewPrivateZone, this.Name, this.ResourceGroupName)
                        : string.Format(ProjectResources.Success_NewZone, this.Name, this.ResourceGroupName));
                this.WriteObject(result);
            });
        }
        protected override void ProcessRecord()
        {
            DnsZone result       = null;
            DnsZone zoneToUpdate = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToUpdate = new DnsZone
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = "*",
                    Tags = this.Tag,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToUpdate = this.Zone;
            }

            if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith("."))
            {
                zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToUpdate.Name));
            }

            bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";

            result = this.DnsClient.UpdateDnsZone(zoneToUpdate, overwrite);

            WriteVerbose(ProjectResources.Success);
            WriteObject(result);
        }
        protected override void ProcessRecord()
        {
            DnsZone result = null;
            DnsZone zoneToUpdate = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneToUpdate = new DnsZone
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Etag = "*",
                    Tags = this.Tag,
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToUpdate = this.Zone;
            }

            if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith("."))
            {
                zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToUpdate.Name));
            }

            bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != "Object";
            result = this.DnsClient.UpdateDnsZone(zoneToUpdate, overwrite);

            WriteVerbose(ProjectResources.Success);
            WriteObject(result);
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("The output object type of this cmdlet will be modified in a future release.");

            DnsZone result       = null;
            DnsZone zoneToUpdate = null;

            if (this.ParameterSetName == FieldsIdsParameterSetName || this.ParameterSetName == FieldsObjectsParameterSetName)
            {
                if (this.Name.EndsWith("."))
                {
                    this.Name = this.Name.TrimEnd('.');
                    this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", this.Name));
                }

                zoneToUpdate      = this.DnsClient.GetDnsZone(this.Name, this.ResourceGroupName);
                zoneToUpdate.Etag = "*";
                zoneToUpdate.Tags = this.Tag;

                if (this.ParameterSetName == FieldsIdsParameterSetName)
                {
                    // Change mutable fields if value is passed
                    if (this.RegistrationVirtualNetworkId != null)
                    {
                        zoneToUpdate.RegistrationVirtualNetworkIds = this.RegistrationVirtualNetworkId;
                    }

                    if (this.ResolutionVirtualNetworkId != null)
                    {
                        zoneToUpdate.ResolutionVirtualNetworkIds = this.ResolutionVirtualNetworkId;
                    }
                }
                else
                {
                    // Change mutable fields if value is passed
                    if (this.RegistrationVirtualNetwork != null)
                    {
                        zoneToUpdate.RegistrationVirtualNetworkIds = this.RegistrationVirtualNetwork.Select(virtualNetwork => virtualNetwork.Id).ToList();
                    }

                    if (this.ResolutionVirtualNetwork != null)
                    {
                        zoneToUpdate.ResolutionVirtualNetworkIds = this.ResolutionVirtualNetwork.Select(virtualNetwork => virtualNetwork.Id).ToList();
                    }
                }
            }
            else if (this.ParameterSetName == ObjectParameterSetName)
            {
                if ((string.IsNullOrWhiteSpace(this.Zone.Etag) || this.Zone.Etag == "*") && !this.Overwrite.IsPresent)
                {
                    throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsZone).Name));
                }

                zoneToUpdate = this.Zone;
            }

            if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith("."))
            {
                zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.');
                this.WriteWarning(string.Format("Modifying zone name to remove terminating '.'.  Zone name used is \"{0}\".", zoneToUpdate.Name));
            }
            ConfirmAction(
                ProjectResources.Progress_Modifying,
                zoneToUpdate.Name,
                () =>
            {
                bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != ObjectParameterSetName;
                result         = this.DnsClient.UpdateDnsZone(zoneToUpdate, overwrite);

                WriteVerbose(ProjectResources.Success);
                WriteObject(result);
            });
        }