Ejemplo n.º 1
0
// GTMWideipPost create new wide IP on a global traffic manager
func GTMWideipPost(c *gin.Context) {
	var wideipcreate gtm.CreateWip

	f5url, err := gtm.Trafficmanager(c.Params.ByName("trafficmanager"))
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	if err := c.BindJSON(&wideipcreate); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Create wideip",
			fmt.Sprintf("%s", err), conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	res, err := gtm.PostGTMWip(f5url, &wideipcreate)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	if res.Status == http.StatusOK {
		res.Status = http.StatusCreated
	}
	respondWithStatus(res.Status, "WideIP created", wideipcreate.Name,
		returnerror.ErrorMessage(), conf.Documentation["gtmwideipdocumentationuri"], c)
}
Ejemplo n.º 2
0
// GTMPoolMemberPost adds additional LTM virtual server on a global traffic manager pool
func GTMPoolMemberPost(c *gin.Context) {
	var poolmember gtm.CreatePoolMember
	pool := c.Params.ByName("pool")
	f5url, err := gtm.Trafficmanager(c.Params.ByName("trafficmanager"))
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpoolmemberdocumentationuri"], c)
		return
	}
	if err := c.BindJSON(&poolmember); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Add pool member",
			fmt.Sprintf("%s", err), conf.Documentation["gtmpoolmemberdocumentationuri"], c)
		return
	}
	res, err := gtm.PostGTMPoolMember(f5url, pool, &poolmember)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpoolmemberdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	if res.Status == http.StatusOK {
		res.Status = http.StatusCreated
	}
	respondWithStatus(res.Status, "Poolmember added", poolmember.Name,
		returnerror.ErrorMessage(), conf.Documentation["gtmpoolmemberdocumentationuri"], c)
}
Ejemplo n.º 3
0
// GTMIRuleList show global traffic manager iRules
func GTMIRuleList(c *gin.Context) {
	tm := c.Params.ByName("trafficmanager")
	f5url, err := gtm.Trafficmanager(tm)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["gtmiruledocumentationuri"], c)
		return
	}
	res, gtmirulelist, err := gtm.ShowGTMIRules(f5url)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["gtmiruledocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "", gtmirulelist, returnerror.ErrorMessage(), conf.Documentation["gtmiruledocumentationuri"], c)
}
Ejemplo n.º 4
0
// GTMPoolDelete delete a pool on a global traffic manager
func GTMPoolDelete(c *gin.Context) {
	pool := c.Params.ByName("pool")
	f5url, err := gtm.Trafficmanager(c.Params.ByName("trafficmanager"))
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	res, err := gtm.DeleteGTMPool(f5url, pool)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "Pool deleted", pool,
		returnerror.ErrorMessage(), conf.Documentation["gtmpooldocumentationuri"], c)
}
Ejemplo n.º 5
0
// GTMWipDelete delete wide ip
func GTMWipDelete(c *gin.Context) {
	wideip := c.Params.ByName("wideip")
	f5url, err := gtm.Trafficmanager(c.Params.ByName("trafficmanager"))
	if err != nil {
		respondWithStatus(err.Status, wideip, nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	res, err := gtm.DeleteGTMWip(f5url, wideip)
	if err != nil {
		respondWithStatus(err.Status, wideip, nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "WideIP deleted", wideip,
		returnerror.ErrorMessage(), conf.Documentation["gtmwideipdocumentationuri"], c)
}
Ejemplo n.º 6
0
// GTMPoolMemberList show global traffic manager members in a specific pool
func GTMPoolMemberList(c *gin.Context) {
	tm := c.Params.ByName("trafficmanager")
	pool := c.Params.ByName("pool")
	f5url, err := gtm.Trafficmanager(tm)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpoolmemberdocumentationuri"], c)
		return
	}
	res, poolmemberlist, err := gtm.ShowGTMPoolMembers(f5url, pool)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpoolmemberdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "", poolmemberlist, returnerror.ErrorMessage(), conf.Documentation["gtmpoolmemberdocumentationuri"], c)
}
Ejemplo n.º 7
0
// GTMPoolNameList show specific global traffic manager pool
func GTMPoolNameList(c *gin.Context) {
	tm := c.Params.ByName("trafficmanager")
	pool := c.Params.ByName("pool")
	f5url, err := gtm.Trafficmanager(tm)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	res, gtmpoollist, err := gtm.ShowGTMPool(f5url, pool)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	u := new(url.URL)
	u.Scheme = common.Protocol
	u.Path = path.Join(c.Request.Host, c.Request.RequestURI, common.MembersURI)
	gtmpoollist.MembersReference = u.String()
	respondWithStatus(res.Status, "", gtmpoollist, returnerror.ErrorMessage(), conf.Documentation["gtmpooldocumentationuri"], c)
}
Ejemplo n.º 8
0
// GTMPoolStatusPut modify pool member status on a global traffic manager (enabled, disabled)
func GTMPoolStatusPut(c *gin.Context) {
	var poolstatus gtm.ModifyPoolStatus
	f5url, err := gtm.Trafficmanager(c.Params.ByName("trafficmanager"))
	if err != nil {
		respondWithStatus(err.Status, poolstatus.Name, nil, err.Message, conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	if err := c.BindJSON(&poolstatus); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Modify pool status",
			fmt.Sprintf("%s", err), conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	res, err := gtm.PutGTMPoolStatus(f5url, &poolstatus)
	if err != nil {
		respondWithStatus(err.Status, poolstatus.Name, nil, err.Message, conf.Documentation["gtmpooldocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "Pool modified", poolstatus.Name,
		returnerror.ErrorMessage(), conf.Documentation["gtmpooldocumentationuri"], c)
}
Ejemplo n.º 9
0
// GTMWipNameList show a specific wide ip
func GTMWipNameList(c *gin.Context) {
	tm := c.Params.ByName("trafficmanager")
	wideip := c.Params.ByName("wideip")
	f5url, err := gtm.Trafficmanager(tm)
	if err != nil {
		respondWithStatus(err.Status, wideip, nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	res, gtmwipnamelist, err := gtm.ShowGTMWip(f5url, wideip)
	if err != nil {
		respondWithStatus(err.Status, wideip, nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	for i, pool := range gtmwipnamelist.Pools {
		u := new(url.URL)
		u.Scheme = common.Protocol
		u.Path = path.Join(c.Request.Host, "/api/gtms", tm, "/pools/", pool.Name)
		gtmwipnamelist.Pools[i].PoolsReference = u.String()
	}
	respondWithStatus(res.Status, "", gtmwipnamelist, returnerror.ErrorMessage(), conf.Documentation["gtmwideipdocumentationuri"], c)
}
Ejemplo n.º 10
0
// GTMWipList show all wide ips
func GTMWipList(c *gin.Context) {
	tm := c.Params.ByName("trafficmanager")
	f5url, err := gtm.Trafficmanager(tm)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	res, gtmwiplist, err := gtm.ShowGTMWips(f5url)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["gtmwideipdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	poolsURI := util.ReplaceGTMWipUritoGTMPoolURI(c.Request.RequestURI)
	for _, wip := range gtmwiplist.Items {
		for i, pools := range wip.Pools {
			u := new(url.URL)
			u.Scheme = common.Protocol
			u.Path = path.Join(c.Request.Host, poolsURI, pools.Name)
			wip.Pools[i].PoolsReference = u.String()
		}
	}
	respondWithStatus(res.Status, "", gtmwiplist, returnerror.ErrorMessage(), conf.Documentation["gtmwideipdocumentationuri"], c)
}