diff --git a/cmd/workload/cmd.go b/cmd/workload/cmd.go index 9c43d8a..7777f9c 100644 --- a/cmd/workload/cmd.go +++ b/cmd/workload/cmd.go @@ -233,6 +233,12 @@ func Command() *cli.Command { Usage: "dissociate workload(s) from eru, return it resource but not remove it", ArgsUsage: workloadArgsUsage, Action: utils.ExitCoder(cmdWorkloadDissociate), + Flags: []cli.Flag{ + &cli.StringSliceFlag{ + Name: "node", + Usage: "dissociate all workload(s) on node(s)", + }, + }, }, { Name: "realloc", diff --git a/cmd/workload/dissociate.go b/cmd/workload/dissociate.go index d929311..e961ed7 100644 --- a/cmd/workload/dissociate.go +++ b/cmd/workload/dissociate.go @@ -15,10 +15,24 @@ import ( type dissociateWorkloadsOptions struct { client corepb.CoreRPCClient ids []string + nodes []string } func (o *dissociateWorkloadsOptions) run(ctx context.Context) error { - opts := &corepb.DissociateWorkloadOptions{IDs: o.ids} + ids := o.ids + for _, node := range o.nodes { + wrks, err := o.client.ListNodeWorkloads(ctx, &corepb.GetNodeOptions{Nodename: node}) + if err != nil { + return err + } + for _, wrk := range wrks.Workloads { + ids = append(ids, wrk.Id) + } + } + if len(ids) == 0 { + return fmt.Errorf("no workloads found") + } + opts := &corepb.DissociateWorkloadOptions{IDs: ids} resp, err := o.client.DissociateWorkload(ctx, opts) if err != nil { return err @@ -48,14 +62,16 @@ func cmdWorkloadDissociate(c *cli.Context) error { return err } + nodes := c.StringSlice("node") ids := c.Args().Slice() - if len(ids) == 0 { - return fmt.Errorf("Workload ID(s) should not be empty") + if len(ids) == 0 && len(nodes) == 0 { + return fmt.Errorf("Workload ID(s) and Node(s) should not be empty") } o := &dissociateWorkloadsOptions{ client: client, ids: ids, + nodes: nodes, } return o.run(c.Context) }