예제 #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
}
예제 #2
0
func (e *GetRouterExecutor) Execute(t *Task) error {
	zkRouter, err := datamodel.GetRouter(e.arg.Internal, e.arg.Zone, e.arg.Host)
	castedRouter := Router(*zkRouter)
	e.reply.Router = &castedRouter
	if err != nil {
		e.reply.Status = StatusError
	}
	e.reply.Status = StatusOk
	return err
}
예제 #3
0
func Unregister(internal bool, zone, value string) error {
	zkRouter, err := datamodel.GetRouter(internal, zone, value)
	if err != nil {
		return err
	}
	if dns.Provider == nil || len(zkRouter.RecordIDs) == 0 {
		// if we have no dns provider or there aren't any record IDs then just save here
		return zkRouter.Delete()
	}
	err, errChan := dns.Provider.DeleteRecords(Region, "DELETE_ROUTER "+value+" in "+zone, zkRouter.RecordIDs...)
	if err != nil {
		return err
	}
	err = <-errChan // wait for it to propagate
	if err != nil {
		return err
	}
	return zkRouter.Delete()
}