|
|
@@ -32,6 +32,7 @@ func NewLeaseCommand() *cobra.Command {
|
|
|
|
|
|
lc.AddCommand(NewLeaseGrantCommand())
|
|
|
lc.AddCommand(NewLeaseRevokeCommand())
|
|
|
+ lc.AddCommand(NewLeaseTimeToLiveCommand())
|
|
|
lc.AddCommand(NewLeaseKeepAliveCommand())
|
|
|
|
|
|
return lc
|
|
|
@@ -87,13 +88,9 @@ func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) {
|
|
|
ExitWithError(ExitBadArgs, fmt.Errorf("lease revoke command needs 1 argument"))
|
|
|
}
|
|
|
|
|
|
- id, err := strconv.ParseInt(args[0], 16, 64)
|
|
|
- if err != nil {
|
|
|
- ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err))
|
|
|
- }
|
|
|
-
|
|
|
+ id := leaseFromArgs(args[0])
|
|
|
ctx, cancel := commandCtx(cmd)
|
|
|
- _, err = mustClientFromCmd(cmd).Revoke(ctx, v3.LeaseID(id))
|
|
|
+ _, err := mustClientFromCmd(cmd).Revoke(ctx, id)
|
|
|
cancel()
|
|
|
if err != nil {
|
|
|
ExitWithError(ExitError, fmt.Errorf("failed to revoke lease (%v)\n", err))
|
|
|
@@ -101,6 +98,37 @@ func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) {
|
|
|
fmt.Printf("lease %016x revoked\n", id)
|
|
|
}
|
|
|
|
|
|
+var timeToLiveKeys bool
|
|
|
+
|
|
|
+// NewLeaseTimeToLiveCommand returns the cobra command for "lease timetolive".
|
|
|
+func NewLeaseTimeToLiveCommand() *cobra.Command {
|
|
|
+ lc := &cobra.Command{
|
|
|
+ Use: "timetolive <leaseID>",
|
|
|
+ Short: "Get lease information",
|
|
|
+
|
|
|
+ Run: leaseTimeToLiveCommandFunc,
|
|
|
+ }
|
|
|
+ lc.Flags().BoolVar(&timeToLiveKeys, "keys", false, "Get keys attached to this lease")
|
|
|
+
|
|
|
+ return lc
|
|
|
+}
|
|
|
+
|
|
|
+// leaseTimeToLiveCommandFunc executes the "lease timetolive" command.
|
|
|
+func leaseTimeToLiveCommandFunc(cmd *cobra.Command, args []string) {
|
|
|
+ if len(args) != 1 {
|
|
|
+ ExitWithError(ExitBadArgs, fmt.Errorf("lease timetolive command needs lease ID as argument"))
|
|
|
+ }
|
|
|
+ var opts []v3.LeaseOption
|
|
|
+ if timeToLiveKeys {
|
|
|
+ opts = append(opts, v3.WithAttachedKeys())
|
|
|
+ }
|
|
|
+ resp, rerr := mustClientFromCmd(cmd).TimeToLive(context.TODO(), leaseFromArgs(args[0]), opts...)
|
|
|
+ if rerr != nil {
|
|
|
+ ExitWithError(ExitBadConnection, rerr)
|
|
|
+ }
|
|
|
+ display.TimeToLive(*resp, timeToLiveKeys)
|
|
|
+}
|
|
|
+
|
|
|
// NewLeaseKeepAliveCommand returns the cobra command for "lease keep-alive".
|
|
|
func NewLeaseKeepAliveCommand() *cobra.Command {
|
|
|
lc := &cobra.Command{
|
|
|
@@ -119,12 +147,8 @@ func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) {
|
|
|
ExitWithError(ExitBadArgs, fmt.Errorf("lease keep-alive command needs lease ID as argument"))
|
|
|
}
|
|
|
|
|
|
- id, err := strconv.ParseInt(args[0], 16, 64)
|
|
|
- if err != nil {
|
|
|
- ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err))
|
|
|
- }
|
|
|
-
|
|
|
- respc, kerr := mustClientFromCmd(cmd).KeepAlive(context.TODO(), v3.LeaseID(id))
|
|
|
+ id := leaseFromArgs(args[0])
|
|
|
+ respc, kerr := mustClientFromCmd(cmd).KeepAlive(context.TODO(), id)
|
|
|
if kerr != nil {
|
|
|
ExitWithError(ExitBadConnection, kerr)
|
|
|
}
|
|
|
@@ -134,3 +158,11 @@ func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) {
|
|
|
}
|
|
|
fmt.Printf("lease %016x expired or revoked.\n", id)
|
|
|
}
|
|
|
+
|
|
|
+func leaseFromArgs(arg string) v3.LeaseID {
|
|
|
+ id, err := strconv.ParseInt(arg, 16, 64)
|
|
|
+ if err != nil {
|
|
|
+ ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err))
|
|
|
+ }
|
|
|
+ return v3.LeaseID(id)
|
|
|
+}
|