diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2017-05-06 05:47:54 -0400 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2017-05-06 09:30:10 -0400 |
commit | 86d9587f757fe728996d36c4acfbf7417fda4fb2 (patch) | |
tree | 80bab06a054dcfb76a376ae53537bc5afc86f326 /client | |
parent | 897adf530cfe0247f3b5d8e60d846cdbdc7c1b88 (diff) |
cli: speed up showing a specific defined-set
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'client')
-rw-r--r-- | client/client.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/client/client.go b/client/client.go index c571facd..4a94ac4a 100644 --- a/client/client.go +++ b/client/client.go @@ -535,8 +535,11 @@ func (cli *Client) DeleteVRF(name string) error { return err } -func (cli *Client) GetDefinedSet(typ table.DefinedType) ([]table.DefinedSet, error) { - ret, err := cli.cli.GetDefinedSet(context.Background(), &api.GetDefinedSetRequest{Type: api.DefinedType(typ)}) +func (cli *Client) getDefinedSet(typ table.DefinedType, name string) ([]table.DefinedSet, error) { + ret, err := cli.cli.GetDefinedSet(context.Background(), &api.GetDefinedSetRequest{ + Type: api.DefinedType(typ), + Name: name, + }) if err != nil { return nil, err } @@ -551,6 +554,23 @@ func (cli *Client) GetDefinedSet(typ table.DefinedType) ([]table.DefinedSet, err return ds, nil } +func (cli *Client) GetDefinedSet(typ table.DefinedType) ([]table.DefinedSet, error) { + return cli.getDefinedSet(typ, "") +} + +func (cli *Client) GetDefinedSetByName(typ table.DefinedType, name string) (table.DefinedSet, error) { + sets, err := cli.getDefinedSet(typ, name) + if err != nil { + return nil, err + } + if len(sets) == 0 { + return nil, fmt.Errorf("not found defined set: %s", name) + } else if len(sets) > 1 { + return nil, fmt.Errorf("invalid response for GetDefinedSetByName") + } + return sets[0], nil +} + func (cli *Client) AddDefinedSet(d table.DefinedSet) error { a, err := api.NewAPIDefinedSetFromTableStruct(d) if err != nil { |