Skip to content

Commit

Permalink
Update hosts to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Oct 6, 2016
1 parent 2d705dd commit 55ed5ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
33 changes: 1 addition & 32 deletions cmd/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,42 +87,11 @@ func hostLs(ctx *cli.Context) error {
return err
}

opts := defaultListOpts(ctx)
delete(opts.Filters, "state_ne")
collection, err := c.Host.List(opts)
collection, err := c.Host.List(defaultListOpts(ctx))
if err != nil {
return err
}

knownMachines := map[string]bool{}
for _, host := range collection.Data {
knownMachines[host.PhysicalHostId] = true
}

machineCollection, err := c.Machine.List(nil)
if err != nil {
return err
}

for _, machine := range machineCollection.Data {
if knownMachines[machine.Id] {
continue
}
host := client.Host{
Resource: client.Resource{
Id: machine.Id,
},
Hostname: machine.Name,
State: machine.State,
TransitioningMessage: machine.TransitioningMessage,
}
if machine.State == "active" {
host.State = "waiting"
host.TransitioningMessage = "Almost there... Waiting for agent connection"
}
collection.Data = append(collection.Data, host)
}

writer := NewTableWriter([][]string{
{"ID", "Host.Id"},
{"HOSTNAME", "Host.Hostname"},
Expand Down
8 changes: 4 additions & 4 deletions cmd/host_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func hostCreate(ctx *cli.Context) error {
return err
}

machineSchema := c.GetSchemas().Schema("machine")
flags := buildFlags("", machineSchema, c.GetSchemas())
hostSchema := c.GetSchemas().Schema("host")
flags := buildFlags("", hostSchema, c.GetSchemas())
drivers := []string{}

for name := range machineSchema.ResourceFields {
for name := range hostSchema.ResourceFields {
if strings.HasSuffix(name, "Config") {
drivers = append(drivers, strings.TrimSuffix(name, "Config"))
}
Expand All @@ -137,7 +137,7 @@ func hostCreate(ctx *cli.Context) error {
EnvVar: "MACHINE_DRIVER",
})
hostCommand.Subcommands[i].Action = func(ctx *cli.Context) error {
return hostCreateRun(ctx, c, machineSchema, c.GetSchemas())
return hostCreateRun(ctx, c, hostSchema, c.GetSchemas())
}
hostCommand.Subcommands[i].SkipFlagParsing = false
}
Expand Down

0 comments on commit 55ed5ff

Please sign in to comment.