f5-rest-client icon indicating copy to clipboard operation
f5-rest-client copied to clipboard

How to remove virtualserver configuration from other partitions?

Open lefeck opened this issue 2 years ago • 0 comments

Hi, I want to delete all the configurations in the virtualserver under partition, it doesn't seem to work, I don't know how to do it? My code is as follows:

package main

import (
	"fmt"
	"github.com/e-XpertSolutions/f5-rest-client/f5"
	"github.com/e-XpertSolutions/f5-rest-client/f5/ltm"
	"log"
	"sort"
	"time"
)

const Partition = "test"

//initiable f5 client
func NewF5Client() (*f5.Client, error) {
	//hosts := fmt.Sprintf("https://" + Host)
	//client, err := f5.NewBasicClient(hosts, Username, Password)
	client, err := f5.NewBasicClient("https://192.168.10.83", "admin", "admin")
	client.DisableCertCheck()

	client.SetTimeout(60 * time.Second)
	if err != nil {
		fmt.Println(err)
	}
	return client, nil
}

func DeleteVS(client *f5.Client) (err error) {
	tx, err := client.Begin()
	if err != nil {
		log.Fatalf("client open transaction: %s", err)
	}
	part := fmt.Sprintf("cd /%s", Partition)

	output, _ := tx.ExecTMSH(part)
	fmt.Println(output)
	cmd := fmt.Sprintf("delete ltm virtual all")

	outputs, _ := tx.ExecTMSH(cmd)
	fmt.Println(outputs)
	if err = tx.Commit(); err != nil {
		log.Fatalf("client commits transaction: %s", err)
	}
	return nil
}

func main() {
	client, _ := NewF5Client()
	DeleteVS(client)
}

As a result, only the virtualserver whose partition is common can be deleted, and the virtualserver configuration of other partitions cannot be deleted.

lefeck avatar Nov 15 '22 08:11 lefeck