-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate hcapi.ISOClient usage to hcapi2 (#444)
- Loading branch information
Showing
5 changed files
with
49 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hetznercloud/cli/internal/cmd/base" | ||
"github.com/hetznercloud/cli/internal/cmd/cmpl" | ||
"github.com/hetznercloud/cli/internal/hcapi2" | ||
"github.com/hetznercloud/cli/internal/state" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newAttachISOCommand(cli *state.State) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "attach-iso [FLAGS] SERVER ISO", | ||
Short: "Attach an ISO to a server", | ||
Args: cobra.ExactArgs(2), | ||
TraverseChildren: true, | ||
ValidArgsFunction: cmpl.SuggestArgs( | ||
cmpl.SuggestCandidatesF(cli.ServerNames), | ||
cmpl.SuggestCandidatesF(cli.ISONames), | ||
), | ||
DisableFlagsInUseLine: true, | ||
PreRunE: cli.EnsureToken, | ||
RunE: cli.Wrap(runAttachISO), | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runAttachISO(cli *state.State, cmd *cobra.Command, args []string) error { | ||
idOrName := args[0] | ||
server, _, err := cli.Client().Server.Get(cli.Context, idOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if server == nil { | ||
return fmt.Errorf("server not found: %s", idOrName) | ||
} | ||
|
||
isoIDOrName := args[1] | ||
iso, _, err := cli.Client().ISO.Get(cli.Context, isoIDOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if iso == nil { | ||
return fmt.Errorf("ISO not found: %s", isoIDOrName) | ||
} | ||
|
||
action, _, err := cli.Client().Server.AttachISO(cli.Context, server, iso) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := cli.ActionProgress(cli.Context, action); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("ISO %s attached to server %d\n", iso.Name, server.ID) | ||
return nil | ||
var AttachISOCommand = base.Cmd{ | ||
BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "attach-iso [FLAGS] SERVER ISO", | ||
Short: "Attach an ISO to a server", | ||
Args: cobra.ExactArgs(2), | ||
TraverseChildren: true, | ||
ValidArgsFunction: cmpl.SuggestArgs( | ||
cmpl.SuggestCandidatesF(client.Server().Names), | ||
cmpl.SuggestCandidatesF(client.ISO().Names), | ||
), | ||
DisableFlagsInUseLine: true, | ||
} | ||
}, | ||
Run: func(ctx context.Context, client hcapi2.Client, waiter state.ActionWaiter, command *cobra.Command, args []string) error { | ||
idOrName := args[0] | ||
server, _, err := client.Server().Get(ctx, idOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if server == nil { | ||
return fmt.Errorf("server not found: %s", idOrName) | ||
} | ||
|
||
isoIDOrName := args[1] | ||
iso, _, err := client.ISO().Get(ctx, isoIDOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if iso == nil { | ||
return fmt.Errorf("ISO not found: %s", isoIDOrName) | ||
} | ||
|
||
action, _, err := client.Server().AttachISO(ctx, server, iso) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := waiter.ActionProgress(ctx, action); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("ISO %s attached to server %d\n", iso.Name, server.ID) | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters