Exemplo n.º 1
0
// PutGTMPoolStatus modify status of wideip pool
func PutGTMPoolStatus(host string, poolmodify *ModifyPoolStatus) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmpoolsuri)
	u.Path = path.Join(u.Path, fmt.Sprintf("/~%s~%s", gtmPartition, poolmodify.Name))
	var poolstatus interface{}
	switch poolmodify.Status {
	case true:
		{
			poolstatus = EnablePoolStatus{Enabled: true}
		}
	case false:
		{
			poolstatus = DisablePoolStatus{Disabled: true}
		}
	}

	r, err := backend.Request(common.PUT, u.String(), &poolstatus)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 2
0
// PutLTMPoolMember modify status of pool member
func PutLTMPoolMember(host, poolname, member, status string) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("pool/~%s~%s/members/~%s~%s", ltmPartition, poolname, ltmPartition, member))
	memberstatus := ModifyPoolMemberStatus{}
	switch status {
	case "enabled":
		{
			memberstatus = ModifyPoolMemberStatus{State: "user-up", Session: "user-enabled"}
		}
	case "disabled":
		{
			memberstatus = ModifyPoolMemberStatus{State: "user-up", Session: "user-disabled"}
		}
	case "offline":
		{
			memberstatus = ModifyPoolMemberStatus{State: "user-down", Session: "user-disabled"}
		}
	}

	r, err := backend.Request(common.PUT, u.String(), &memberstatus)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 3
0
// ShowLTMDevice returns information
// of loadbalancer devices
func ShowLTMDevice(inputURL string) (*backend.Response, *Devices, *errors.Error) {
	// Declaration LTM Device
	ltmdevice := new(Devices)
	deviceURL := util.ReplaceLTMUritoDeviceURI(inputURL)
	fmt.Println(deviceURL)
	res, err := backend.Request(common.GET, deviceURL, &ltmdevice)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmdevice, nil
}
Exemplo n.º 4
0
// PostLTMDataGroup creates a new datagroup
func PostLTMDataGroup(host, direction string, json *CreateDataGroup) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, common.Dg, direction)
	r, err := backend.Request(common.POST, u.String(), &json)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 5
0
// PostLTMSSLCert create a new ssl certificate
func PostLTMSSLCert(host string, json interface{}) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, "cert")
	r, err := backend.Request(common.POST, u.String(), &json)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 6
0
// DeleteLTMDataGroup deletes a specific datagroup
func DeleteLTMDataGroup(host, direction, datagroupname string) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, common.Dg, direction, "/", datagroupname)
	r, err := backend.Request(common.DELETE, u.String(), nil)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 7
0
// PostLTMPoolMember add member to a pool
func PostLTMPoolMember(host, poolname string, json *CreatePoolMember) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("pool/~%s~%s/members", ltmPartition, poolname))
	r, err := backend.Request(common.POST, u.String(), &json)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 8
0
// PostLTMPool create a new pool
func PostLTMPool(host string, json *CreatePool) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, "pool")
	r, err := backend.Request(common.POST, u.String(), &json)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 9
0
// DeleteLTMPoolMember delete pool member
func DeleteLTMPoolMember(host, poolname, poolmember string) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("pool/~%s~%s/members/~%s~%s", ltmPartition, poolname, ltmPartition, poolmember))
	r, err := backend.Request(common.DELETE, u.String(), nil)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 10
0
// ShowLTMFWRules shows firewall profile
func ShowLTMFWRules(host, vserver string) (*backend.Response, *FirewallRules, *errors.Error) {
	fwrules := new(FirewallRules)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("virtual/~%s~%s/fw-rules", ltmPartition, vserver))
	res, err := backend.Request(common.GET, u.String(), &fwrules)
	if err != nil {
		return nil, nil, err
	}
	return res, fwrules, nil
}
Exemplo n.º 11
0
// ShowLTMAddressListName returns a specific address list on LB
func ShowLTMAddressListName(host, address string) (*backend.Response, *AddressList, *errors.Error) {
	addresslist := new(AddressList)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, address)
	res, err := backend.Request(common.GET, u.String(), addresslist)
	if err != nil {
		return nil, nil, err
	}
	return res, addresslist, nil
}
Exemplo n.º 12
0
// ShowLTMIRules shows iRules
func ShowLTMIRules(host string) (*backend.Response, *IRules, *errors.Error) {
	iRs := new(IRules)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, "rule")
	res, err := backend.Request(common.GET, u.String(), &iRs)
	if err != nil {
		return nil, nil, err
	}
	return res, iRs, nil
}
Exemplo n.º 13
0
// ShowLTMIRule shows a specific iRule
func ShowLTMIRule(host, iRuleName string) (*backend.Response, *IRule, *errors.Error) {
	iR := new(IRule)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("rule/~%s~%s", ltmPartition, iRuleName))
	res, err := backend.Request(common.GET, u.String(), &iR)
	if err != nil {
		return nil, nil, err
	}
	return res, iR, nil
}
Exemplo n.º 14
0
// ShowLTMPools show all declared pools
func ShowLTMPools(host string) (*backend.Response, *Pools, *errors.Error) {
	// Declaration LTM Pools
	ltmpools := new(Pools)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, "pool")
	res, err := backend.Request(common.GET, u.String(), &ltmpools)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmpools, nil
}
Exemplo n.º 15
0
// ShowLTMPool show specific pool
func ShowLTMPool(host, pool string) (*backend.Response, *Pool, *errors.Error) {
	// Declaration LTM Pool
	ltmpool := new(Pool)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("pool/~%s~%s", ltmPartition, pool))
	res, err := backend.Request(common.GET, u.String(), &ltmpool)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmpool, nil
}
Exemplo n.º 16
0
// ShowLTMDataGroup lists all datagroups on a loadbalancer
func ShowLTMDataGroup(host, source string) (*backend.Response, *DataGroups, *errors.Error) {
	// Declaration LTM DataGroup
	ltmdatagroup := new(DataGroups)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, common.Dg, source)
	res, err := backend.Request(common.GET, u.String(), ltmdatagroup)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmdatagroup, nil
}
Exemplo n.º 17
0
// ShowLTMVirtualServer show all virtual server
func ShowLTMVirtualServer(host string) (*backend.Response, *VirtualServers, *errors.Error) {
	// Declaration LTM virtual server
	ltmvirtualserver := new(VirtualServers)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, "virtual")
	res, err := backend.Request(common.GET, u.String(), ltmvirtualserver)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmvirtualserver, nil
}
Exemplo n.º 18
0
// ShowGTMIRule shows a specific iRule
func ShowGTMIRule(host, iRuleName string) (*backend.Response, *IRule, *errors.Error) {
	iR := new(IRule)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmirulesuri, fmt.Sprintf("/%s", iRuleName))
	res, err := backend.Request(common.GET, u.String(), &iR)
	if err != nil {
		return nil, nil, err
	}
	return res, iR, nil
}
Exemplo n.º 19
0
// ShowLTMProfile show profiles from a virtual server
func ShowLTMProfile(host, vserver string) (*backend.Response, *Profiles, *errors.Error) {
	// Declaration LTM Profile
	ltmprofile := new(Profiles)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, fmt.Sprintf("virtual/~%s~%s/profiles", ltmPartition, vserver))
	res, err := backend.Request(common.GET, u.String(), &ltmprofile)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmprofile, nil
}
Exemplo n.º 20
0
// DeleteGTMWip deletes a pool on a trafficmanager
func DeleteGTMWip(host, wideip string) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmwipsuri)
	u.Path = path.Join(u.Path, fmt.Sprintf("/~%s~%s", gtmPartition, wideip))
	r, err := backend.Request(common.DELETE, u.String(), nil)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 21
0
// ShowGTMWip list a specific wide ip on a trafficmanager
func ShowGTMWip(host, wideip string) (*backend.Response, *Wip, *errors.Error) {
	gtmwip := new(Wip)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmwipsuri, "/", wideip)
	res, err := backend.Request(common.GET, u.String(), &gtmwip)
	if err != nil {
		return nil, nil, err
	}
	return res, gtmwip, nil
}
Exemplo n.º 22
0
// ShowLTMDeviceName returns information
// of a specific loadbalancer device
func ShowLTMDeviceName(host, inputURL string, ltmDeviceNames map[string]string) (*backend.Response, *Device, *errors.Error) {
	// Declaration LTM Device Name
	value := ltmDeviceNames[host]
	ltmdevicename := new(Device)
	u := new(url.URL)
	u.Scheme = common.Protocol
	u.Path = path.Join(host, common.DeviceURI, value)
	devicenameURL := u.String()
	res, err := backend.Request(common.GET, devicenameURL, &ltmdevicename)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmdevicename, nil
}
Exemplo n.º 23
0
// ShowGTMPools shows all declared pools on gtm
func ShowGTMPools(host string) (*backend.Response, *Pools, *errors.Error) {
	gtmpools := new(Pools)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmpoolsuri)
	res, err := backend.Request(common.GET, u.String(), &gtmpools)
	if err != nil {
		return nil, nil, err
	}
	return res, gtmpools, nil
}
Exemplo n.º 24
0
// ShowLTMDataGroupName lists a specific datagroup on a loadbalancer
func ShowLTMDataGroupName(host, direction, datagroupname string) (*backend.Response, *DataGroup, *errors.Error) {
	// Declaration LTM DataGroup by Name
	ltmdatagroupname := new(DataGroup)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, common.Dg, direction, "/", datagroupname)
	res, err := backend.Request(common.GET, u.String(), ltmdatagroupname)
	if err != nil {
		return nil, nil, err
	}
	return res, ltmdatagroupname, nil
}
Exemplo n.º 25
0
// DeleteGTMPoolMember delete pool member on a trafficmanager
func DeleteGTMPoolMember(host, pool string, poolmember *RemovePoolMember) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmpoolsuri)
	u.Path = path.Join(u.Path, fmt.Sprintf("/%s/members/~%s~%s:~%s~%s", pool, gtmPartition,
		poolmember.Loadbalancer, ltmPartition, poolmember.Name))
	r, err := backend.Request(common.DELETE, u.String(), nil)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 26
0
//ShowGTMPoolMembers shows members on a specific pool
func ShowGTMPoolMembers(host, pool string) (*backend.Response, *PoolMembers, *errors.Error) {
	// Declaration GTM Pool Member
	gtmpoolmembers := new(PoolMembers)
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmpoolsuri, fmt.Sprintf("/~%s~%s/members", gtmPartition, pool))
	res, err := backend.Request(common.GET, u.String(), &gtmpoolmembers)
	if err != nil {
		return nil, nil, err
	}
	return res, gtmpoolmembers, nil
}
Exemplo n.º 27
0
// PatchLTMWhiteAddresses to whitelist ips
// Due not overwriting address list
// its necessary to get all entries first
func PatchLTMWhiteAddresses(host string, whiteIP *CreateAddresses) (*backend.Response, *errors.Error) {

	_, white, err := ShowLTMAddressListName(host, common.WhiteList)
	if err != nil {
		return nil, err
	}

	// first slices are compared to order loops
	// if white list has already white ips it will skip
	// append(...) is doing a delete item of the slice
	// see https://github.com/golang/go/wiki/SliceTricks

	if len(white.Addresses) < len(whiteIP.Addresses) {
		for i := range white.Addresses {
			for j := range whiteIP.Addresses {
				if whiteIP.Addresses[j] == white.Addresses[i] {
					whiteIP.Addresses = append(whiteIP.Addresses[:j], whiteIP.Addresses[j+1:]...)
					break
				}
			}
		}
	} else {
		for i := range whiteIP.Addresses {
			for j := range white.Addresses {
				if whiteIP.Addresses[i] == white.Addresses[j] {
					whiteIP.Addresses = append(whiteIP.Addresses[:i], whiteIP.Addresses[i+1:]...)
					break
				}
			}
		}
	}

	for i := range white.Addresses {
		whiteIP.Addresses = append(whiteIP.Addresses, white.Addresses[i])
	}

	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, common.WhiteList)

	r, err := backend.Request(common.PATCH, u.String(), &whiteIP)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 28
0
// PostGTMWip creates a new wide ip on a trafficmanager
func PostGTMWip(host string, json *CreateWip) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmwipsuri)
	if !(len(json.Poollbmode) > 0) {
		json.Poollbmode = "global-availability"
	}

	r, err := backend.Request(common.POST, u.String(), &json)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 29
0
//PostGTMPoolMember adds new members to an existing pool on a trafficmanager
func PostGTMPoolMember(host string, pool string, json *CreatePoolMember) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Scheme = common.Protocol
	u.Path = path.Join(u.Path, common.Gtmpoolsuri, pool, common.MembersURI)

	json.Partition = gtmPartition
	json.Subpath = fmt.Sprintf("%s:/%s", json.Loadbalancer, gtmPartition)
	json.Fullpath = fmt.Sprintf("/%s/%s:/%s/%s", gtmPartition, json.Loadbalancer, ltmPartition, json.Name)
	json.Loadbalancer = ""
	r, err := backend.Request(common.POST, u.String(), &json)
	fmt.Println(json)
	if err != nil {
		return nil, err
	}
	return r, nil
}
Exemplo n.º 30
0
// PatchLTMDataGroupItem keeps all records in a datagroup and add new records
// F5 API use PATCH and PUT in the same way. Overwriting all records, which is bad if you want to add items
// in existing list. It gets all records first an append the new records from client.
func PatchLTMDataGroupItem(host, direction, datagroup string, json *CreateDataGroupItem) (*backend.Response, *errors.Error) {
	u, errParse := url.Parse(host)
	if errParse != nil {
		return nil, &errors.ErrorCodeBadRequestParse
	}
	u.Path = path.Join(u.Path, common.Dg, direction, "/", datagroup)

	_, data, err := ShowLTMDataGroupName(host, direction, datagroup)
	if err != nil {
		return nil, err
	}
	for _, v := range data.Records {
		json.Records = append(json.Records, v)
	}
	r, err := backend.Request(common.PATCH, u.String(), &json)
	if err != nil {
		return nil, err
	}
	return r, nil
}