예제 #1
0
// LTMVirtualServerNameList show local traffic manager specific virtual server
func LTMVirtualServerNameList(c *gin.Context) {
	lbpair := c.Params.ByName("lbpair")
	vservername := c.Params.ByName("virtual")
	f5url, err := ltm.Loadbalancer(lbpair, conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, vservername, nil, err.Message, conf.Documentation["ltmvirtualdocumentationuri"], c)
		return
	}
	res, virtualservernamelist, err := ltm.ShowLTMVirtualServerName(f5url, vservername)
	if err != nil {
		respondWithStatus(err.Status, vservername, nil, err.Message, conf.Documentation["ltmvirtualdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	u1 := new(url.URL)
	u1.Scheme = common.Protocol
	u1.Path = path.Join(c.Request.Host, c.Request.RequestURI, common.ProfilesURI)
	u2 := new(url.URL)
	u2.Scheme = common.Protocol
	u2.Path = path.Join(c.Request.Host, c.Request.RequestURI, common.FwURI)
	virtualservernamelist.ProfilesReference = u1.String()
	virtualservernamelist.FwRulesReference = u2.String()
	if len(virtualservernamelist.Pool) > 0 {
		u := new(url.URL)
		u.Scheme = common.Protocol
		u.Path = path.Join(c.Request.Host, "/api/ltms/", lbpair, common.PoolsURI, util.ReplaceCommon(virtualservernamelist.Pool))
		virtualservernamelist.PoolsReference = u.String()
	}
	respondWithStatus(res.Status, "", virtualservernamelist, returnerror.ErrorMessage(), conf.Documentation["ltmvirtualdocumentationuri"], c)
}
예제 #2
0
// LTMBlockIPPatch add ips which will be blocked
func LTMBlockIPPatch(c *gin.Context) {
	var blockips ltm.CreateAddresses

	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	f5url = util.ReplaceLTMUritoAddressListURI(f5url)
	if err := c.BindJSON(&blockips); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Block IPs",
			fmt.Sprintf("%s", err), conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	res, err := ltm.PatchLTMBlockAddresses(f5url, &blockips)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	if res.Status == http.StatusOK {
		res.Status = http.StatusCreated
	}
	respondWithStatus(res.Status, "IP(s) blocked successfully", blockips,
		returnerror.ErrorMessage(), conf.Documentation["ltmaddresslistdocumentationuri"], c)
}
예제 #3
0
// LTMDataGroupItemPatch add an item to a datagroup (ip or string) on a local traffic manager
func LTMDataGroupItemPatch(c *gin.Context) {
	var datagroupitemcreate ltm.CreateDataGroupItem
	direction := common.InternalDataGroup
	datagroupname := c.Params.ByName("datagroupname")

	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, datagroupname, nil, err.Message, conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}

	if err := c.BindJSON(&datagroupitemcreate); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Create datagroup item",
			fmt.Sprintf("%s", err), conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	res, err := ltm.PatchLTMDataGroupItem(f5url, direction, datagroupname, &datagroupitemcreate)
	if err != nil {
		respondWithStatus(err.Status, datagroupname, nil, err.Message, conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	if res.Status == http.StatusOK {
		res.Status = http.StatusCreated
	}
	respondWithStatus(res.Status, "Datagroup item added in", datagroupname,
		returnerror.ErrorMessage(), conf.Documentation["ltmdatagroupdocumentationuri"], c)
}
예제 #4
0
// LTMPoolMemberPost add new members to a specific pool on a local traffic manager
func LTMPoolMemberPost(c *gin.Context) {
	var poolmembercreate ltm.CreatePoolMember

	pool := c.Params.ByName("pool")
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmpoolmemberdocumentationuri"], c)
		return
	}

	if err := c.BindJSON(&poolmembercreate); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Create pool member",
			fmt.Sprintf("%s", err), conf.Documentation["ltmpoolmemberdocumentationuri"], c)
		return
	}
	res, err := ltm.PostLTMPoolMember(f5url, pool, &poolmembercreate)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmpoolmemberdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)

	if res.Status == http.StatusOK {
		res.Status = http.StatusCreated
	}
	respondWithStatus(res.Status, "Poolmember added", poolmembercreate.Name,
		returnerror.ErrorMessage(), conf.Documentation["ltmpoolmemberdocumentationuri"], c)
}
예제 #5
0
// LTMDeviceList show local traffic manager devices
func LTMDeviceList(c *gin.Context) {
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmdevicedocumentationuri"], c)
		return
	}
	res, devicelist, err := ltm.ShowLTMDevice(f5url)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmdevicedocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "", devicelist, returnerror.ErrorMessage(), conf.Documentation["ltmdevicedocumentationuri"], c)
}
예제 #6
0
// LTMDataGroupList show local traffic manager internal data groups
func LTMDataGroupList(c *gin.Context) {
	direction := common.InternalDataGroup
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	res, datagrouplist, err := ltm.ShowLTMDataGroup(f5url, direction)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "", datagrouplist, returnerror.ErrorMessage(), conf.Documentation["ltmdatagroupdocumentationuri"], c)
}
예제 #7
0
// LTMFWRuleList show local traffic manager iRules of a specific virtual server
func LTMFWRuleList(c *gin.Context) {
	vservername := c.Params.ByName("virtual")
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, vservername, nil, err.Message, conf.Documentation["ltmvirtualdocumentationuri"], c)
		return
	}
	res, rulelist, err := ltm.ShowLTMFWRules(f5url, vservername)
	if err != nil {
		respondWithStatus(err.Status, vservername, nil, err.Message, conf.Documentation["ltmvirtualdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "", rulelist, returnerror.ErrorMessage(), conf.Documentation["ltmvirtualdocumentationuri"], c)
}
예제 #8
0
// LTMWhiteAddressList show local traffic whitelisted ip addresses
func LTMWhiteAddressList(c *gin.Context) {
	lbpair := c.Params.ByName("lbpair")
	f5url, err := ltm.Loadbalancer(lbpair, conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	f5url = util.ReplaceLTMUritoAddressListURI(f5url)
	res, addresslist, err := ltm.ShowLTMAddressList(f5url, common.WhiteList)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "", addresslist, returnerror.ErrorMessage(), conf.Documentation["ltmaddresslistdocumentationuri"], c)
}
예제 #9
0
// LTMPoolDelete delete a pool on a local traffic manager
func LTMPoolDelete(c *gin.Context) {
	pool := c.Params.ByName("pool")
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmpooldocumentationuri"], c)
		return
	}
	res, err := ltm.DeleteLTMPool(f5url, pool)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmpooldocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "Pool deleted", pool,
		returnerror.ErrorMessage(), conf.Documentation["ltmpooldocumentationuri"], c)
}
예제 #10
0
// LTMPoolNameList show specific local traffic manager pool
func LTMPoolNameList(c *gin.Context) {
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmpooldocumentationuri"], c)
		return
	}
	pool := c.Params.ByName("pool")
	res, poollist, err := ltm.ShowLTMPool(f5url, pool)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmpooldocumentationuri"], 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)
	poollist.MembersReference = u.String()
	respondWithStatus(res.Status, "", poollist, returnerror.ErrorMessage(), conf.Documentation["ltmpooldocumentationuri"], c)
}
예제 #11
0
// LTMDataGroupDelete delete a internal datagroup on a local traffic manager
func LTMDataGroupDelete(c *gin.Context) {
	var datagroupdelete ltm.RemoveDataGroup
	direction := common.InternalDataGroup
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	if err := c.BindJSON(&datagroupdelete); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Delete datagroup item",
			fmt.Sprintf("%s", err), conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	res, err := ltm.DeleteLTMDataGroup(f5url, direction, datagroupdelete.Name)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmdatagroupdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "Datagroup deleted", datagroupdelete.Name,
		returnerror.ErrorMessage(), conf.Documentation["ltmdatagroupdocumentationuri"], c)
}
예제 #12
0
// LTMPoolMemberPut modify pool members on a local traffic manager (enabled, disabled, force-offline)
func LTMPoolMemberPut(c *gin.Context) {
	var poolmembermodify ltm.ModifyPoolMember
	pool := c.Params.ByName("pool")
	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["ltmpoolmemberdocumentationuri"], c)
		return
	}
	if err := c.BindJSON(&poolmembermodify); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Modify pool member",
			fmt.Sprintf("%s", err), conf.Documentation["ltmpoolmemberdocumentationuri"], c)
		return
	}
	res, err := ltm.PutLTMPoolMember(f5url, pool, poolmembermodify.Name, poolmembermodify.Status)
	if err != nil {
		respondWithStatus(err.Status, pool, nil, err.Message, conf.Documentation["ltmpoolmemberdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "Poolmember modified", poolmembermodify.Name,
		returnerror.ErrorMessage(), conf.Documentation["ltmpoolmemberdocumentationuri"], c)
}
예제 #13
0
// LTMRemoveWhiteIPPatch remove ips which are currently whitelisted
func LTMRemoveWhiteIPPatch(c *gin.Context) {
	var removewhiteips ltm.DeleteAddresses

	f5url, err := ltm.Loadbalancer(c.Params.ByName("lbpair"), conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	f5url = util.ReplaceLTMUritoAddressListURI(f5url)
	if err := c.BindJSON(&removewhiteips); err != nil {
		respondWithStatus(http.StatusBadRequest, "Invalid JSON data", "Unblock IPs",
			fmt.Sprintf("%s", err), conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	res, err := ltm.DeleteLTMBlockAddresses(f5url, &removewhiteips, common.WhiteList)
	if err != nil {
		respondWithStatus(err.Status, "", nil, err.Message, conf.Documentation["ltmaddresslistdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	respondWithStatus(res.Status, "IP(s) removed successfully from whitelist", fmt.Sprintf("%+v", removewhiteips),
		returnerror.ErrorMessage(), conf.Documentation["ltmaddresslistdocumentationuri"], c)
}