Represents a set of records with the same name, with the same type and in the same zone.
Наследование: ICloneable
Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Returns a deep copy of this record set
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var clone = new DnsRecordSet();

            clone.Name              = this.Name;
            clone.TargetResourceId  = this.TargetResourceId;
            clone.ProvisioningState = this.ProvisioningState;
            clone.Id                = this.Id;
            clone.ZoneName          = this.ZoneName;
            clone.ResourceGroupName = this.ResourceGroupName;
            clone.Ttl               = this.Ttl;
            clone.Etag              = this.Etag;
            clone.RecordType        = this.RecordType;

            if (this.Records != null)
            {
                clone.Records = this.Records.Select(record => record.Clone()).Cast <DnsRecordBase>().ToList();
            }

            if (this.Metadata != null)
            {
                clone.Metadata = (Hashtable)this.Metadata.Clone();
            }

            return(clone);
        }
        public override void ExecuteCmdlet()
        {
            if ((string.IsNullOrWhiteSpace(this.RecordSet.Etag) || this.RecordSet.Etag == "*") && !this.Overwrite.IsPresent)
            {
                throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(DnsRecordSet).Name));
            }

            DnsRecordSet recordSetToUpdate = (DnsRecordSet)this.RecordSet.Clone();

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

            ConfirmAction(
                ProjectResources.Progress_Modifying,
                recordSetToUpdate.Name,
                () =>
            {
                DnsRecordSet result = this.DnsClient.UpdateDnsRecordSet(recordSetToUpdate, this.Overwrite.IsPresent);

                WriteVerbose(ProjectResources.Success);

                WriteObject(result);
            });
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            RecordType recordType = default(RecordType);

            if (this.RecordType != null && !Enum.TryParse(this.RecordType, false, out recordType))
            {
                throw new PSArgumentException("RecordType must be one of A, AAAA, CNAME, MX, NS, SOA, SRV, TXT.");
            }

            string zoneName          = null;
            string resourceGroupName = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneName          = this.ZoneName;
                resourceGroupName = this.ResourceGroupName;
            }
            else if (this.ParameterSetName == "Object")
            {
                zoneName          = this.Zone.Name;
                resourceGroupName = this.Zone.ResourceGroupName;
            }

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

            if (this.Name != null && this.EndsWith != null)
            {
                throw new PSArgumentException(ProjectResources.Error_NameAndEndsWith);
            }
            else if (this.Name != null)
            {
                if (this.RecordType == null)
                {
                    throw new PSArgumentException("If you specify the Name parameter you must also specify the RecordType parameter.");
                }

                DnsRecordSet result = this.DnsClient.GetDnsRecordSet(this.Name, zoneName, resourceGroupName, recordType);
                this.WriteObject(result);
            }
            else
            {
                List <DnsRecordSet> result = null;
                if (this.RecordType == null)
                {
                    result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, this.EndsWith);
                }
                else
                {
                    result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, recordType, this.EndsWith);
                }

                this.WriteObject(result);
            }
        }
Пример #5
0
        public override void ExecuteCmdlet()
        {
            string       zoneName          = null;
            string       resourceGroupname = null;
            DnsRecordSet result            = null;

            if (RecordType == RecordType.SOA)
            {
                throw new System.ArgumentException(ProjectResources.Error_AddRecordSOA);
            }

            if (ParameterSetName == "Fields")
            {
                zoneName          = this.ZoneName;
                resourceGroupname = this.ResourceGroupName;
            }
            else if (ParameterSetName == "Object")
            {
                zoneName          = this.Zone.Name;
                resourceGroupname = this.Zone.ResourceGroupName;
            }
            if (this.Name.EndsWith(zoneName.ToString()))
            {
                this.WriteWarning(string.Format(ProjectResources.Error_RecordSetNameEndsWithZoneName, this.Name, zoneName.ToString()));
            }

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

            if (this.DnsRecords == null)
            {
                this.WriteWarning(ProjectResources.Warning_DnsRecordsParamNeedsToBeSpecified);
            }

            ConfirmAction(
                ProjectResources.Progress_CreatingRecordSet,
                this.Name,
                () =>
            {
                result = this.DnsClient.CreateDnsRecordSet(zoneName, resourceGroupname, this.Name, this.Ttl, this.RecordType, this.Metadata, this.Overwrite, this.DnsRecords);

                if (result != null)
                {
                    WriteVerbose(ProjectResources.Success);
                    WriteVerbose(string.Format(ProjectResources.Success_NewRecordSet, this.Name, zoneName, this.RecordType));
                    WriteVerbose(string.Format(ProjectResources.Success_RecordSetFqdn, this.Name, zoneName, this.RecordType));
                }

                WriteObject(result);
            });
        }
        public override void ExecuteCmdlet()
        {
            string zoneName          = null;
            string resourceGroupName = null;

            if (this.ParameterSetName == "Fields")
            {
                zoneName          = this.ZoneName;
                resourceGroupName = this.ResourceGroupName;
            }
            else
            {
                zoneName          = this.Zone.Name;
                resourceGroupName = this.Zone.ResourceGroupName;
            }

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

            if (this.Name != null)
            {
                if (this.RecordType == null)
                {
                    throw new PSArgumentException("If you specify the Name parameter you must also specify the RecordType parameter.");
                }

                DnsRecordSet result = this.DnsClient.GetDnsRecordSet(this.Name, zoneName, resourceGroupName, this.RecordType.Value);
                this.WriteObject(result);
            }
            else
            {
                List <DnsRecordSet> result = null;
                if (this.RecordType == null)
                {
                    result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName);
                }
                else
                {
                    result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, this.RecordType.Value);
                }

                foreach (var r in result)
                {
                    this.WriteObject(r);
                }
            }
        }
Пример #7
0
        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");

            string       zoneName          = null;
            string       resourceGroupname = null;
            DnsRecordSet result            = null;

            if (ParameterSetName == "Fields")
            {
                zoneName          = this.ZoneName;
                resourceGroupname = this.ResourceGroupName;
            }
            else if (ParameterSetName == "Object")
            {
                zoneName          = this.Zone.Name;
                resourceGroupname = this.Zone.ResourceGroupName;
            }

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

            ConfirmAction(
                !Overwrite.IsPresent || Force.IsPresent,
                string.Format(ProjectResources.Confirm_OverwriteRecord, this.Name, this.RecordType, zoneName),
                ProjectResources.Progress_CreatingEmptyRecordSet,
                this.Name,
                () => { result = this.DnsClient.CreateDnsRecordSet(zoneName, resourceGroupname, this.Name, this.Ttl, this.RecordType, this.Tag, this.Overwrite); });

            if (result != null)
            {
                WriteVerbose(ProjectResources.Success);
                WriteVerbose(string.Format(ProjectResources.Success_NewRecordSet, this.Name, zoneName, this.RecordType));
                WriteVerbose(string.Format(ProjectResources.Success_RecordSetFqdn, this.Name, zoneName, this.RecordType));
            }

            WriteObject(result);
        }
Пример #8
0
        public override void ExecuteCmdlet()
        {
            string       zoneName          = null;
            string       resourceGroupname = null;
            DnsRecordSet result            = null;

            if (ParameterSetName == "Fields")
            {
                zoneName          = this.ZoneName;
                resourceGroupname = this.ResourceGroupName;
            }
            else if (ParameterSetName == "Object")
            {
                zoneName          = this.Zone.Name;
                resourceGroupname = this.Zone.ResourceGroupName;
            }

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

            ConfirmAction(
                !Overwrite.IsPresent || Force.IsPresent,
                string.Format(ProjectResources.Confirm_OverwriteRecord, this.Name, this.RecordType, zoneName),
                ProjectResources.Progress_CreatingEmptyRecordSet,
                this.Name,
                () => { result = this.DnsClient.CreateDnsRecordSet(zoneName, resourceGroupname, this.Name, this.Ttl, this.RecordType, this.Tag, this.Overwrite); });

            if (result != null)
            {
                WriteVerbose(ProjectResources.Success);
                WriteVerbose(string.Format(ProjectResources.Success_NewRecordSet, this.Name, zoneName, this.RecordType));
                WriteVerbose(string.Format(ProjectResources.Success_RecordSetFqdn, this.Name, zoneName, this.RecordType));
            }

            WriteObject(result);
        }
Пример #9
0
        /// <summary>
        /// Returns a deep copy of this record set
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var clone = new DnsRecordSet();

            clone.Name = this.Name;
            clone.ZoneName = this.ZoneName;
            clone.ResourceGroupName = this.ResourceGroupName;
            clone.Ttl = this.Ttl;
            clone.Etag = this.Etag;
            clone.RecordType = this.RecordType;

            if (this.Records != null)
            {
                clone.Records = this.Records.Select(record => record.Clone()).Cast<DnsRecordBase>().ToList();
            }

            if (this.Metadata != null)
            {
                clone.Metadata = (Hashtable)this.Metadata.Clone();
            }

            return clone;
        }
Пример #10
0
        /// <summary>
        /// Returns a deep copy of this record set
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var clone = new DnsRecordSet();

            clone.Name              = this.Name;
            clone.ZoneName          = this.ZoneName;
            clone.ResourceGroupName = this.ResourceGroupName;
            clone.Ttl        = this.Ttl;
            clone.Etag       = this.Etag;
            clone.RecordType = this.RecordType;

            if (this.Records != null)
            {
                clone.Records = this.Records.Select(record => record.Clone()).Cast <DnsRecordBase>().ToList();
            }

            if (this.Tags != null)
            {
                clone.Tags = this.Tags.Select(tag => tag.Clone()).Cast <Hashtable>().ToArray();
            }

            return(clone);
        }
        public override void ExecuteCmdlet()
        {
            bool         deleted           = false;
            DnsRecordSet recordSetToDelete = null;

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

                recordSetToDelete = new DnsRecordSet
                {
                    Name              = this.Name,
                    Etag              = null,
                    RecordType        = this.RecordType,
                    ResourceGroupName = this.ResourceGroupName,
                    ZoneName          = this.ZoneName,
                };
            }
            else if (this.ParameterSetName == "Mixed")
            {
                if (this.Name.EndsWith("."))
                {
                    this.Name = this.Name.TrimEnd('.');
                    this.WriteWarning(string.Format("Modifying recordset name to remove terminating '.'.  Recordset name used is \"{0}\".", this.Name));
                }

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

                recordSetToDelete = this.RecordSet;
            }

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

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

            ConfirmAction(
                ProjectResources.Progress_RemovingRecordSet,
                this.Name,
                () =>
            {
                deleted = DnsClient.DeleteDnsRecordSet(recordSetToDelete, overwrite);
                if (deleted)
                {
                    WriteVerbose(ProjectResources.Success);
                    WriteVerbose(ProjectResources.Success_RemoveRecordSet);
                }

                if (this.PassThru)
                {
                    WriteObject(deleted);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            bool deleted = false;
            DnsRecordSet recordSetToDelete = null;

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

                recordSetToDelete = new DnsRecordSet
                {
                    Name = this.Name,
                    Etag = null,
                    RecordType = this.RecordType,                   
                    ResourceGroupName = this.ResourceGroupName,
                    ZoneName = this.ZoneName,
                };
            }
            else if (this.ParameterSetName == "Mixed")
            {
                if (this.Name.EndsWith("."))
                {
                    this.Name = this.Name.TrimEnd('.');
                    this.WriteWarning(string.Format("Modifying recordset name to remove terminating '.'.  Recordset name used is \"{0}\".", this.Name));
                }

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

                recordSetToDelete = this.RecordSet;
            }

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

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

            ConfirmAction(
                Force.IsPresent,
                string.Format(ProjectResources.Confirm_RemoveRecordSet, recordSetToDelete.Name, recordSetToDelete.ZoneName),
                ProjectResources.Progress_RemovingRecordSet,
                this.Name,
                () => { deleted = DnsClient.DeleteDnsRecordSet(recordSetToDelete, overwrite); });

            if (deleted)
            {
                WriteVerbose(ProjectResources.Success);
                WriteVerbose(ProjectResources.Success_RemoveRecordSet);
            }

            if (this.PassThru)
            {
                WriteObject(deleted);
            }
        }