Esempio n. 1
0
func preCreateRecordSets(internal bool, zone, host string, zkRouter *datamodel.ZkRouter) (string, error) {
	// we're only creating records for this region
	suffix, err := dns.Provider.Suffix(Region)
	if err != nil {
		return "", err
	}
	// first delete all entries we may already have for this Value in DNS
	err = dns.DeleteRecordsForValue(Region, host)
	if err != nil {
		return "", err
	}
	// choose cname
	routers, err := datamodel.ListRoutersInZone(internal, zone)
	if err != nil {
		return "", err
	}
	routerMap := map[string]bool{}
	for _, router := range routers {
		tmpRouter, err := datamodel.GetRouter(internal, zone, router)
		if err != nil {
			return "", err
		}
		routerMap[tmpRouter.CName] = true
	}
	routerNum := 1
	myCName := helper.GetRouterCName(internal, routerNum, zone, suffix)
	for ; routerMap[myCName]; routerNum++ {
		myCName = helper.GetRouterCName(internal, routerNum, zone, suffix)
	}
	zkRouter.CName = myCName
	return suffix, nil
}
Esempio n. 2
0
func (c *DNSDeleteRecordsForValueCommand) Execute(args []string) error {
	if err := InitDNSProvider(c.Provider, c.ZoneID, c.TTL); err != nil {
		return Output(nil, nil, err)
	}
	err := dns.DeleteRecordsForValue("cli", c.Value)
	if err == nil {
		Log("-> deleted")
	}
	return Output(nil, nil, err)
}
Esempio n. 3
0
func Register(region, value, registryCName, managerCName string) (*datamodel.ZkManager, error) {
	if tmpManager, err := datamodel.GetManager(region, value); err == nil {
		return tmpManager, errors.New("Already registered.")
	}

	// NOTE[jigish]: health check removed because we can't actually do it security-group wise.

	// set up datamodel
	zkManager := datamodel.Manager(region, value)
	err := zkManager.Save()
	if err != nil {
		return zkManager, err
	}

	// pass through specified cnames
	if managerCName != "" {
		zkManager.ManagerCName = managerCName
	}
	if registryCName != "" {
		zkManager.RegistryCName = registryCName
	}
	err = zkManager.Save()
	if err != nil {
		return zkManager, err
	}

	if dns.Provider == nil || (zkManager.ManagerCName != "" && zkManager.RegistryCName != "") {
		return zkManager, nil
	}

	suffix, err := dns.Provider.Suffix(region)
	if err != nil {
		return nil, err
	}

	// set up unspecified cnames
	// first delete all entries we may already have for this Value in DNS
	err = dns.DeleteRecordsForValue(region, value)
	if err != nil {
		return zkManager, err
	}
	// choose cnames
	managers, err := datamodel.ListManagersInRegion(region)
	if err != nil {
		return zkManager, err
	}
	managerMap := map[string]bool{}
	registryMap := map[string]bool{}
	for _, manager := range managers {
		tmpManager, err := datamodel.GetManager(region, manager)
		if err != nil {
			return zkManager, err
		}
		managerMap[tmpManager.ManagerCName] = true
		registryMap[tmpManager.RegistryCName] = true
	}

	cnames := []dns.Record{}
	if zkManager.ManagerCName == "" {
		managerNum := 1
		zkManager.ManagerCName = helper.GetManagerCName(managerNum, suffix)
		for ; managerMap[zkManager.ManagerCName]; managerNum++ {
			zkManager.ManagerCName = helper.GetManagerCName(managerNum, suffix)
		}
		// managerX.<region>.<suffix>
		cname := dns.NewRecord(zkManager.ManagerCName, zkManager.Host, 0)
		zkManager.ManagerRecordID = cname.ID()
		cnames = append(cnames, cname)
	}
	if zkManager.RegistryCName == "" {
		registryNum := 1
		zkManager.RegistryCName = helper.GetRegistryCName(registryNum, suffix)
		for ; registryMap[zkManager.RegistryCName]; registryNum++ {
			zkManager.RegistryCName = helper.GetRegistryCName(registryNum, suffix)
		}
		// registryX.<region>.<suffix>
		cname := dns.NewRecord(zkManager.RegistryCName, zkManager.Host, 0)
		zkManager.RegistryRecordID = cname.ID()
		cnames = append(cnames, cname)
	}

	if len(cnames) == 0 {
		return zkManager, nil
	}
	err = dns.Provider.CreateRecords(region, "CREATE_MANAGER "+zkManager.Host+" in "+region, cnames)
	if err != nil {
		return zkManager, err
	}
	return zkManager, zkManager.Save()
}