// CreateDNSRecord creates a new DNS record
436573
func (c *Client) CreateDNSRecord(domain, name, rtype, data string, priority, ttl int) error {
	values := url.Values{
		"domain":   {domain},
		"name":     {name},
		"type":     {rtype},
		"data":     {data},
		"priority": {fmt.Sprintf("%v", priority)},
		"ttl":      {fmt.Sprintf("%v", ttl)},
	}

	if err := c.post(`dns/create_record`, values, nil); err != nil {
		return err
	}
	return nil
}
727768
func NewRecorder(w Interface) *Recorder {
	r := &Recorder{}
	r.Interface = Filter(w, r.record)
	return r
}
835326
func (d *DNSRecordSets) DeleteDNSRecordSet(name string, ip string) {
	res := []DNSRecordSet{}
	for i := range d.ResourceRecordSets {
		if d.ResourceRecordSets[i].Name != name || d.ResourceRecordSets[i].Type != "A" || d.ResourceRecordSets[i].RData != ip {
			res = append(res, d.ResourceRecordSets[i])
		}
	}

	d.ResourceRecordSets = res
}
652800
func (m *MDNSService) instanceRecords(q dns.Question) []dns.RR {
	switch q.Qtype {
	case dns.TypeANY:
		// Get the SRV, which includes A and AAAA
		recs := m.instanceRecords(dns.Question{
			Name:  m.instanceAddr,
			Qtype: dns.TypeSRV,
		})

		// Add the TXT record
		recs = append(recs, m.instanceRecords(dns.Question{
			Name:  m.instanceAddr,
			Qtype: dns.TypeTXT,
		})...)
		return recs

	case dns.TypeA:
		var rr []dns.RR
		for _, ip := range m.IPs {
			if ip4 := ip.To4(); ip4 != nil {
				rr = append(rr, &dns.A{
					Hdr: dns.RR_Header{
						Name:   m.HostName,
						Rrtype: dns.TypeA,
						Class:  dns.ClassINET,
						Ttl:    defaultTTL,
					},
					A: ip4,
				})
			}
		}
		return rr

	case dns.TypeAAAA:
		var rr []dns.RR
		for _, ip := range m.IPs {
			if ip.To4() != nil {
				// TODO(reddaly): IPv4 addresses could be encoded in IPv6 format and
				// putinto AAAA records, but the current logic puts ipv4-encodable
				// addresses into the A records exclusively.  Perhaps this should be
				// configurable?
				continue
			}

			if ip16 := ip.To16(); ip16 != nil {
				rr = append(rr, &dns.AAAA{
					Hdr: dns.RR_Header{
						Name:   m.HostName,
						Rrtype: dns.TypeAAAA,
						Class:  dns.ClassINET,
						Ttl:    defaultTTL,
					},
					AAAA: ip16,
				})
			}
		}
		return rr

	case dns.TypeSRV:
		// Create the SRV Record
		srv := &dns.SRV{
			Hdr: dns.RR_Header{
				Name:   q.Name,
				Rrtype: dns.TypeSRV,
				Class:  dns.ClassINET,
				Ttl:    defaultTTL,
			},
			Priority: 10,
			Weight:   1,
			Port:     uint16(m.Port),
			Target:   m.HostName,
		}
		recs := []dns.RR{srv}

		// Add the A record
		recs = append(recs, m.instanceRecords(dns.Question{
			Name:  m.instanceAddr,
			Qtype: dns.TypeA,
		})...)

		// Add the AAAA record
		recs = append(recs, m.instanceRecords(dns.Question{
			Name:  m.instanceAddr,
			Qtype: dns.TypeAAAA,
		})...)
		return recs

	case dns.TypeTXT:
		txt := &dns.TXT{
			Hdr: dns.RR_Header{
				Name:   q.Name,
				Rrtype: dns.TypeTXT,
				Class:  dns.ClassINET,
				Ttl:    defaultTTL,
			},
			Txt: m.TXT,
		}
		return []dns.RR{txt}
	}
	return nil
}
1335446
func NewServiceRecord(instance, service, domain string) *ServiceRecord {
	return &ServiceRecord{instance, service, domain, "", "", ""}
}
883964
func (s *DNSViewSnapshot) RecordsForZone(zoneInfo DNSZoneInfo) []DNSRecord {
	var records []DNSRecord

	zone := s.zoneMap[zoneInfo.Name]
	if zone != nil {
		for k := range zone.Records {
			records = append(records, zone.Records[k])
		}
	}

	return records
}
476666
func (c *Client) CreateReservedIP(regionID int, ipType string, label string) (string, error) {
	values := url.Values{
		"DCID":    {fmt.Sprintf("%v", regionID)},
		"ip_type": {ipType},
	}
	if len(label) > 0 {
		values.Add("label", label)
	}

	result := IP{}
	err := c.post(`reservedip/create`, values, &result)
	if err != nil {
		return "", err
	}
	return result.ID, nil
}
1052355
func (o *NSGateway) CreateNSPort(child *NSPort) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
601025
func (c *Client) CreateRecord(domain string, opts *CreateRecord) (*Record, error) {
	// Make the request parameters
	params := make(map[string]string)
	params["z"] = domain

	params["type"] = opts.Type

	if opts.Name != "" {
		params["name"] = opts.Name
	}

	if opts.Content != "" {
		params["content"] = opts.Content
	}

	if opts.Priority != "" {
		params["prio"] = opts.Priority
	}

	if opts.Ttl != "" {
		params["ttl"] = opts.Ttl
	} else {
		params["ttl"] = "1"
	}

	req, err := c.NewRequest(params, "POST", "rec_new")
	if err != nil {
		return nil, err
	}

	resp, err := checkResp(c.Http.Do(req))

	if err != nil {
		return nil, fmt.Errorf("Error creating record: %s", err)
	}

	recordResp := new(RecordResponse)

	err = decodeBody(resp, &recordResp)

	if err != nil {
		return nil, fmt.Errorf("Error parsing record response: %s", err)
	}
	record, err := recordResp.GetRecord()
	if err != nil {
		return nil, err
	}

	// The request was successful
	return record, nil
}
882703
func (c *Client) CreateDNSDomain(domain, serverIP string) error {
	values := url.Values{
		"domain":   {domain},
		"serverip": {serverIP},
	}

	if err := c.post(`dns/create_domain`, values, nil); err != nil {
		return err
	}
	return nil
}
476927
func removeDNSRecords(nameList string, dnsProvider protokube.DNSProvider) {
	for {
		var removeRecords []dns.Record
		for _, s := range strings.Split(nameList, ",") {
			s = strings.TrimSpace(s)
			if s == "" {
				continue
			}

			removeRecords = append(removeRecords, dns.Record{
				FQDN:       s,
				RecordType: dns.RecordTypeA,
			})
		}

		if len(removeRecords) == 0 {
			return
		}

		if err := dnsProvider.RemoveRecordsImmediate(removeRecords); err != nil {
			glog.Warningf("error removing records %q, will retry: %v", nameList, err)
		} else {
			glog.Infof("removed DNS records %q", nameList)
			return
		}
		time.Sleep(5 * time.Second)
	}
}
280298
func createDNSRedirect(r *Redirect, conf dnsConfiguration, endpointInfoRegistry logger.EndpointInfoRegistry) (RedirectImplementation, error) {
	dr := &dnsRedirect{
		redirect:             r,
		conf:                 conf,
		endpointInfoRegistry: endpointInfoRegistry,
	}

	log.WithFields(logrus.Fields{
		"dnsRedirect": dr,
		"conf":        conf,
	}).Debug("Creating DNS Proxy redirect")

	return dr, dr.setRules(nil, r.rules)
}
100894
func newRecord(key string, rls *rspb.Release) *record {
	var lbs labels

	lbs.init()
	lbs.set("NAME", rls.Name)
	lbs.set("OWNER", "TILLER")
	lbs.set("STATUS", rspb.Status_Code_name[int32(rls.Info.Status.Code)])
	lbs.set("VERSION", strconv.Itoa(int(rls.Version)))

	return &record{key: key, lbs: lbs, rls: proto.Clone(rls).(*rspb.Release)}
}
828298
func (client *Client) GetRecord(ctx context.Context, domain string, recordID int64) (*DNSRecord, error) {
	id := strconv.FormatInt(recordID, 10)
	resp, err := client.dnsRequest(ctx, "/v1/domains/"+domain+"/records/"+id, nil, "", "GET")
	if err != nil {
		return nil, err
	}

	var r DNSRecordResponse
	if err = json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &(r.Record), nil
}
469836
func (c *ServiceController) updateServiceRecords(service *v1.Service) string {
	var records []dns.Record

	specExternal := service.Annotations[AnnotationNameDNSExternal]
	specInternal := service.Annotations[AnnotationNameDNSInternal]
	if len(specExternal) != 0 || len(specInternal) != 0 {
		var ingresses []dns.Record

		if service.Spec.Type == v1.ServiceTypeLoadBalancer {
			for i := range service.Status.LoadBalancer.Ingress {
				ingress := &service.Status.LoadBalancer.Ingress[i]
				if ingress.Hostname != "" {
					// TODO: Support ELB aliases
					ingresses = append(ingresses, dns.Record{
						RecordType: dns.RecordTypeCNAME,
						Value:      ingress.Hostname,
					})
					glog.V(4).Infof("Found CNAME record for service %s/%s: %q", service.Namespace, service.Name, ingress.Hostname)
				}
				if ingress.IP != "" {
					ingresses = append(ingresses, dns.Record{
						RecordType: dns.RecordTypeA,
						Value:      ingress.IP,
					})
					glog.V(4).Infof("Found A record for service %s/%s: %q", service.Namespace, service.Name, ingress.IP)
				}
			}
		} else if service.Spec.Type == v1.ServiceTypeNodePort {
			var roleType string
			if len(specExternal) != 0 && len(specInternal) != 0 {
				glog.Warningln("DNS Records not possible for both Internal and Externals IPs.")
				return ""
			} else if len(specInternal) != 0 {
				roleType = dns.RoleTypeInternal
			} else {
				roleType = dns.RoleTypeExternal
			}
			ingresses = append(ingresses, dns.Record{
				RecordType: dns.RecordTypeAlias,
				Value:      dns.AliasForNodesInRole("node", roleType),
			})
			glog.V(4).Infof("Setting internal alias for NodePort service %s/%s", service.Namespace, service.Name)
		} else {
			// TODO: Emit event so that users are informed of this
			glog.V(2).Infof("Cannot expose service %s/%s of type %q", service.Namespace, service.Name, service.Spec.Type)
		}

		var tokens []string

		if len(specExternal) != 0 {
			tokens = append(tokens, strings.Split(specExternal, ",")...)
		}

		if len(specInternal) != 0 {
			tokens = append(tokens, strings.Split(specInternal, ",")...)
		}

		for _, token := range tokens {
			token = strings.TrimSpace(token)

			fqdn := dns.EnsureDotSuffix(token)
			for _, ingress := range ingresses {
				var r dns.Record
				r = ingress
				r.FQDN = fqdn
				records = append(records, r)
			}
		}
	} else {
		glog.V(8).Infof("Service %s/%s did not have %s annotation", service.Namespace, service.Name, AnnotationNameDNSExternal)
	}

	key := service.Namespace + "/" + service.Name
	c.scope.Replace(key, records)
	return key
}
87316
func (client *Client) GetRecords(ctx context.Context, domain string) ([]DNSRecord, error) {
	resp, err := client.dnsRequest(ctx, "/v1/domains/"+domain+"/records", nil, "", "GET")
	if err != nil {
		return nil, err
	}

	var r []DNSRecordResponse
	if err = json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	records := make([]DNSRecord, 0, len(r))
	for _, rec := range r {
		records = append(records, rec.Record)
	}

	return records, nil
}
83727
func (api *API) DNSRecords(zoneID string, rr DNSRecord) ([]DNSRecord, error) {
	// Construct a query string
	v := url.Values{}
	// Request as many records as possible per page - API max is 50
	v.Set("per_page", "50")
	if rr.Name != "" {
		v.Set("name", rr.Name)
	}
	if rr.Type != "" {
		v.Set("type", rr.Type)
	}
	if rr.Content != "" {
		v.Set("content", rr.Content)
	}

	var query string
	var records []DNSRecord
	page := 1

	// Loop over makeRequest until what we've fetched all records
	for {
		v.Set("page", strconv.Itoa(page))
		query = "?" + v.Encode()
		uri := "/zones/" + zoneID + "/dns_records" + query
		res, err := api.makeRequest("GET", uri, nil)
		if err != nil {
			return []DNSRecord{}, errors.Wrap(err, errMakeRequestError)
		}
		var r DNSListResponse
		err = json.Unmarshal(res, &r)
		if err != nil {
			return []DNSRecord{}, errors.Wrap(err, errUnmarshalError)
		}
		records = append(records, r.Result...)
		if r.ResultInfo.Page >= r.ResultInfo.TotalPages {
			break
		}
		// Loop around and fetch the next page
		page++
	}
	return records, nil
}