Skip to content

Commit

Permalink
Implement new template-based FormatVirtualMachine
Browse files Browse the repository at this point in the history
Also moved code around to prepare other Format functions for same.
  • Loading branch information
Telyn committed Jul 1, 2016
1 parent 1c1010e commit 07e610d
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 310 deletions.
5 changes: 3 additions & 2 deletions cmd/bytemark/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/util/log"
"github.com/urfave/cli"
"os"
"strconv"
"strings"
)
Expand Down Expand Up @@ -284,7 +285,7 @@ func fn_createServer(c *Context) (err error) {
groupName := c.VirtualMachineName.GroupName()

log.Log("The following server will be created:")
log.Log(util.FormatVirtualMachineSpec(groupName, &spec))
lib.FormatVirtualMachineSpec(os.Stderr, groupName, &spec, "specfull")

// If we're not forcing, prompt. If the prompt comes back false, exit.
if !c.Bool("force") && !util.PromptYesNo("Are you certain you wish to continue?") {
Expand All @@ -303,7 +304,7 @@ func fn_createServer(c *Context) (err error) {
return c.IfNotMarshalJSON(map[string]interface{}{"spec": spec, "virtual_machine": vm}, func() error {

log.Log("cloud server created successfully", "")
log.Log(util.FormatVirtualMachine(vm))
lib.FormatVirtualMachine(os.Stderr, vm, "serverfull")
if imageInstall != nil {
log.Log()
log.Logf("Root password:") // logf so we don't get a tailing \r\n
Expand Down
3 changes: 2 additions & 1 deletion cmd/bytemark/reimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/util/log"
"github.com/urfave/cli"
"os"
)

var imageInstallFlags = []cli.Flag{
Expand Down Expand Up @@ -59,7 +60,7 @@ The root password will be the only thing output on stdout - good for scripts!
}

log.Logf("%s will be reimaged with the following. Note that this will wipe all data on the main disc:\r\n\r\n", c.VirtualMachineName.String())
log.Log(util.FormatImageInstall(imageInstall))
lib.FormatImageInstall(os.Stderr, imageInstall, "imageinstall")

if !c.Bool("force") && !util.PromptYesNo("Are you certain you wish to continue?") {
log.Error("Exiting")
Expand Down
32 changes: 23 additions & 9 deletions cmd/bytemark/show.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/util/log"
"github.com/urfave/cli"
"os"
)

func init() {
Expand All @@ -29,12 +30,21 @@ If the --json flag is specified, prints a complete overview of the account in JS
},
Action: With(AccountProvider, func(c *Context) error {
return c.IfNotMarshalJSON(c.Account, func() error {
log.Output(util.FormatAccount(c.Account))
err := lib.FormatAccount(os.Stderr, c.Account)
if err != nil {
return err
}
log.Output()
log.Output()

for _, g := range c.Account.Groups {
log.Outputf("Group %s =========================================\r\n\r\n", g.Name)
for _, v := range util.FormatVirtualMachines(g.VirtualMachines) {
log.Output(v + "\r\n")
for _, vm := range g.VirtualMachines {
err := lib.FormatVirtualMachine(os.Stderr, vm, "servertwoline")
log.Output()
log.Output()
if err != nil {
return err
}
}
}
return nil
Expand All @@ -61,9 +71,14 @@ If the --json flag is specified, prints a complete overview of the group in JSON
log.Outputf("%s - Group containing %d cloud server%s\r\n", c.Group.Name, len(c.Group.VirtualMachines), s)

log.Output()
for _, vm := range c.Group.VirtualMachines {

for _, v := range util.FormatVirtualMachines(c.Group.VirtualMachines) {
log.Output(v)
err := lib.FormatVirtualMachine(os.Stderr, vm, "servertwoline")
log.Output()
log.Output()
if err != nil {
return err
}
}

return nil
Expand All @@ -82,8 +97,7 @@ If the --json flag is specified, prints a complete overview of the group in JSON
},
Action: With(VirtualMachineProvider, func(c *Context) error {
return c.IfNotMarshalJSON(c.VirtualMachine, func() error {
log.Log(util.FormatVirtualMachine(c.VirtualMachine))
return nil
return lib.FormatVirtualMachine(os.Stderr, c.VirtualMachine, "serverfull")
})
}),
}, {
Expand Down
Loading

0 comments on commit 07e610d

Please sign in to comment.