-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config status publishing for config items #1364
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,27 +26,28 @@ import ( | |
"github.com/ligato/cn-infra/agent" | ||
"github.com/ligato/cn-infra/infra" | ||
"github.com/ligato/cn-infra/logging/logrus" | ||
"github.com/ligato/vpp-agent/api/configurator" | ||
"github.com/ligato/vpp-agent/api/genericmanager" | ||
"github.com/ligato/vpp-agent/client" | ||
"github.com/ligato/vpp-agent/client/remoteclient" | ||
"github.com/ligato/vpp-agent/cmd/vpp-agent/app" | ||
"github.com/ligato/vpp-agent/examples/custom_model/pb" | ||
mymodel "github.com/ligato/vpp-agent/examples/custom_model/pb" | ||
"github.com/ligato/vpp-agent/plugins/orchestrator" | ||
"github.com/namsral/flag" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/ligato/vpp-agent/api/models/linux" | ||
"github.com/ligato/vpp-agent/api/models/linux/interfaces" | ||
"github.com/ligato/vpp-agent/api/models/linux/l3" | ||
linux_interfaces "github.com/ligato/vpp-agent/api/models/linux/interfaces" | ||
linux_l3 "github.com/ligato/vpp-agent/api/models/linux/l3" | ||
"github.com/ligato/vpp-agent/api/models/vpp" | ||
interfaces "github.com/ligato/vpp-agent/api/models/vpp/interfaces" | ||
"github.com/ligato/vpp-agent/api/models/vpp/l2" | ||
vpp_l2 "github.com/ligato/vpp-agent/api/models/vpp/l2" | ||
) | ||
|
||
var ( | ||
address = flag.String("address", "172.17.0.2:9111", "address of GRPC server") | ||
address = flag.String("address", "127.0.0.1:9111", "address of GRPC server") | ||
socketType = flag.String("socket-type", "tcp", "socket type [tcp, tcp4, tcp6, unix, unixpacket]") | ||
|
||
dialTimeout = time.Second * 2 | ||
dialTimeout = time.Second * 3 | ||
) | ||
|
||
var exampleFinished = make(chan struct{}) | ||
|
@@ -66,7 +67,7 @@ func main() { | |
agent.QuitOnClose(exampleFinished), | ||
) | ||
if err := a.Run(); err != nil { | ||
log.Fatal() | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
|
@@ -109,12 +110,14 @@ func (p *ExamplePlugin) AfterInit() (err error) { | |
go func() { | ||
time.Sleep(time.Second) | ||
|
||
//c := remoteclient.NewClientGRPC(api.NewGenericManagerClient(conn)) | ||
c := client.LocalClient | ||
|
||
// remoteclient | ||
c := remoteclient.NewClientGRPC(genericmanager.NewGenericManagerClient(p.conn)) | ||
demonstrateClient(c) | ||
|
||
time.Sleep(time.Second * 3) | ||
//time.Sleep(time.Second * 3) | ||
|
||
// localclient | ||
//demonstrateClient(client.LocalClient) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could remove all this clutter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a clutter. This is actually how the example will work after some upcoming changes. This example will most likely ask user to pick client implementation used for configuring agent. This should demonstrate that the client API can be kept exactly same for all client implementations (local, remote grpc, remote kvdb...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I would comment it with a little explanation so it does not look like forgotten commented code, for example:
plus There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The localclient is not fully supported. I will un-comment this and ask for user input to pick implementation when all are ready and fully implemented. |
||
|
||
logrus.DefaultLogger().Info("Closing example") | ||
close(exampleFinished) | ||
|
@@ -137,40 +140,50 @@ func (p *ExamplePlugin) Close() error { | |
} | ||
|
||
func demonstrateClient(c client.ConfigClient) { | ||
// ========================================== | ||
tm := proto.TextMarshaler{ | ||
Compact: true, | ||
ExpandAny: true, | ||
} | ||
log.SetFlags(log.Lshortfile | log.Lmicroseconds) | ||
|
||
// List known models | ||
// ========================================== | ||
fmt.Println("# ==========================================") | ||
fmt.Println("# List known models..") | ||
fmt.Println("# ==========================================") | ||
knownModels, err := c.KnownModels() | ||
if err != nil { | ||
log.Fatalln(err) | ||
log.Println("KnownModels failed:", err) | ||
} | ||
fmt.Printf("Listing %d known models..\n", len(knownModels)) | ||
fmt.Printf("listing %d models\n", len(knownModels)) | ||
for _, model := range knownModels { | ||
fmt.Printf(" - %v\n", model.String()) | ||
} | ||
time.Sleep(time.Second * 3) | ||
time.Sleep(time.Second * 1) | ||
|
||
// ========================================== | ||
// Resync config | ||
// ========================================== | ||
fmt.Printf("Requesting config resync..\n") | ||
fmt.Println("# ==========================================") | ||
fmt.Println("# Requesting config resync..") | ||
fmt.Println("# ==========================================") | ||
customModel := &mymodel.MyModel{ | ||
Name: "TheModel", | ||
} | ||
err = c.ResyncConfig( | ||
memif1, memif2, | ||
veth1, veth2, | ||
routeX, | ||
routeX, routeCache, | ||
customModel, | ||
) | ||
if err != nil { | ||
log.Fatalln(err) | ||
log.Println("ResyncConfig failed:", err) | ||
} | ||
time.Sleep(time.Second * 5) | ||
time.Sleep(time.Second * 2) | ||
|
||
// ========================================== | ||
// Change config | ||
// ========================================== | ||
fmt.Printf("Requesting config change..\n") | ||
fmt.Println("# ==========================================") | ||
fmt.Println("# Requesting config change..") | ||
fmt.Println("# ==========================================") | ||
memif1.Enabled = false | ||
memif1.Mtu = 666 | ||
|
||
custom := &mymodel.MyModel{ | ||
Name: "my1", | ||
Mynum: 33, | ||
|
@@ -182,20 +195,35 @@ func demonstrateClient(c client.ConfigClient) { | |
if err := req.Send(context.Background()); err != nil { | ||
log.Fatalln(err) | ||
} | ||
time.Sleep(time.Second * 5) | ||
time.Sleep(time.Second * 2) | ||
|
||
// ========================================== | ||
// Get config | ||
// ========================================== | ||
fmt.Printf("Retrieving config..\n") | ||
data := &configurator.Config{ | ||
VppConfig: &vpp.ConfigData{}, | ||
LinuxConfig: &linux.ConfigData{}, | ||
fmt.Println("# ==========================================") | ||
fmt.Println("# Retrieving config..") | ||
fmt.Println("# ==========================================") | ||
type config struct { | ||
VPP vpp.ConfigData | ||
Linux linux.ConfigData | ||
MyModels []*mymodel.MyModel | ||
} | ||
if err := c.GetConfig(data.VppConfig, data.LinuxConfig); err != nil { | ||
log.Fatalln(err) | ||
var cfg config | ||
if err := c.GetConfig(&cfg.VPP, &cfg.Linux, &cfg); err != nil { | ||
log.Println("GetConfig failed:", err) | ||
} | ||
fmt.Printf("Retrieved config:\n%+v\n", cfg) | ||
|
||
// Dump state | ||
fmt.Println("# ==========================================") | ||
fmt.Println("# Dumping state..") | ||
fmt.Println("# ==========================================") | ||
states, err := c.DumpState() | ||
if err != nil { | ||
log.Println("DumpState failed:", err) | ||
} | ||
fmt.Printf("Dumping %d states\n", len(states)) | ||
for _, state := range states { | ||
fmt.Printf(" - %v\n", tm.Text(state)) | ||
} | ||
fmt.Printf("Retrieved config:\n%+v\n", proto.MarshalTextString(data)) | ||
} | ||
|
||
// Dialer for unix domain socket | ||
|
@@ -286,4 +314,16 @@ var ( | |
GwAddr: "10.10.3.254", | ||
Scope: linux_l3.Route_GLOBAL, | ||
} | ||
routeCache = &linux.Route{ | ||
DstNetwork: "10.10.5.0/24", | ||
OutgoingInterface: "if10", | ||
GwAddr: "10.10.5.254", | ||
Scope: linux_l3.Route_GLOBAL, | ||
} | ||
routeBad = &linux.Route{ | ||
DstNetwork: "192.168.6.0/24", | ||
OutgoingInterface: "myVETH1", | ||
GwAddr: "10.10.3.2545", | ||
Scope: linux_l3.Route_GLOBAL, | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it redundant creating aliases with the same name as original types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will be defined as new types later and the API won't have to change for the rest of the code.