Skip to content

Commit

Permalink
Merge pull request #33 from ernoaapa/node-devices
Browse files Browse the repository at this point in the history
Add more info to 'eli describe device <name>'
  • Loading branch information
ernoaapa authored Mar 5, 2018
2 parents 5b0fcc8 + 8aa124f commit f20de61
Show file tree
Hide file tree
Showing 44 changed files with 1,192 additions and 618 deletions.
10 changes: 5 additions & 5 deletions cmd/eli/buildCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
var buildCommand = cli.Command{
Name: "build",
HelpName: "build",
Usage: `Build Device image, etc.`,
Description: "With build command, you can build device image, etc.",
Usage: `Build node image, etc.`,
Description: "With build command, you can build node image, etc.",
ArgsUsage: `eli build <RESOURCE> [options]
# build device image
eli build device`,
# build node image
eli build node`,
Subcommands: []cli.Command{
buildDeviceCommand,
buildNodeCommand,
},
}
20 changes: 10 additions & 10 deletions cmd/eli/buildDeviceCommand.go → cmd/eli/buildNodeCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import (
"github.com/urfave/cli"
)

var buildDeviceCommand = cli.Command{
Name: "device",
Aliases: []string{"dev", "devices"},
Usage: "Build device image",
UsageText: `eli build device [options] [FILE | URL]
var buildNodeCommand = cli.Command{
Name: "node",
Aliases: []string{"nodes", "device"}, // device is deprecated command
Usage: "Build node image",
UsageText: `eli build node [options] [FILE | URL]
# Build default device image
eli build device
# Build default node image
eli build node
# Create Linuxkit file but don't build it
eli build device --dry-run
eli build device --dry-run > custom-linuxkit.yml
eli build node --dry-run
eli build node --dry-run > custom-linuxkit.yml
# Build from custom config and unpack to directory
mkdir dist
eli build device custom-linuxkit.yml | tar xv -C dist
eli build node custom-linuxkit.yml | tar xv -C dist
`,
Flags: []cli.Flag{
cli.BoolFlag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/eli/configCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var configCommand = cli.Command{
HelpName: "config",
Usage: `View and edit client configuration`,
Description: `With this command you view and edit the client configurations
like device address, username, namespace, etc.`,
like ndoe address, username, namespace, etc.`,
ArgsUsage: "eli config view",
Subcommands: []cli.Command{
configViewCommand,
Expand Down
2 changes: 1 addition & 1 deletion cmd/eli/createCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var createCommand = cli.Command{
Name: "create",
HelpName: "create",
Usage: "Create pod based on yaml spec",
Description: "With create command, you can create new pod into the device based on yaml specification",
Description: "With create command, you can create new pod into the node based on yaml specification",
UsageText: `eli create [options] -f ./pod.yml
# Create pod based on pod.yml
Expand Down
2 changes: 1 addition & 1 deletion cmd/eli/createPodCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var createPodCommand = cli.Command{
Name: "pod",
HelpName: "pod",
Usage: "Create new pod",
Description: "With create pod command, you can create new pod into the device",
Description: "With create pod command, you can create new pod into the node",
UsageText: `eli create pod [options] <NAME>
# Create new pod 'my-pod' and create single container
Expand Down
2 changes: 1 addition & 1 deletion cmd/eli/describeCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ var describeCommand = cli.Command{
`,
Subcommands: []cli.Command{
describePodCommand,
describeDeviceCommand,
describeNodeCommand,
},
}
20 changes: 10 additions & 10 deletions cmd/eli/describeDeviceCommand.go → cmd/eli/describeNodeCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
"github.com/urfave/cli"
)

var describeDeviceCommand = cli.Command{
Name: "device",
Aliases: []string{"devices"},
Usage: "Return details of device",
UsageText: `eli describe device [options] [NAME | IP]
var describeNodeCommand = cli.Command{
Name: "node",
Aliases: []string{"nodes", "device"}, // device is deprecated command
Usage: "Return details of node",
UsageText: `eli describe node [options] [NAME | IP]
# Describe device
eli describe device my-device
# Describe node
eli describe node my-node
# Describe all pods
eli describe devices
eli describe nodes
`,
Action: func(clicontext *cli.Context) error {
cfg := cmd.GetConfigProvider(clicontext)
Expand All @@ -45,9 +45,9 @@ var describeDeviceCommand = cli.Command{
for _, endpoint := range endpoints {
info, err := api.NewClient(cfg.GetNamespace(), endpoint).GetInfo()
if err != nil {
return errors.Wrap(err, "Failed to fetch device info")
return errors.Wrap(err, "Failed to fetch node info")
}
if err := printer.PrintDevice(info, writer); err != nil {
if err := printer.PrintNode(info, writer); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eli/getCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ var getCommand = cli.Command{
eli get pods`,
Subcommands: []cli.Command{
getPodsCommand,
getDevicesCommand,
getNodesCommand,
},
}
22 changes: 11 additions & 11 deletions cmd/eli/getDevicesCommand.go → cmd/eli/getNodesCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import (
"github.com/urfave/cli"
)

var getDevicesCommand = cli.Command{
Name: "devices",
Aliases: []string{"device"},
Usage: "Get Device resources",
UsageText: `eli get devices [options]
var getNodesCommand = cli.Command{
Name: "nodes",
Aliases: []string{"node", "devices"}, // devices is deprecated command
Usage: "Get Node resources",
UsageText: `eli get nodes [options]
# Get table of known devices
eli get devices`,
# Get table of known nodes
eli get nodes`,
Action: func(clicontext *cli.Context) error {
uiline := ui.NewLine().Loading("Discover from network automatically...")

devices, err := discovery.Devices(5 * time.Second)
nodes, err := discovery.Nodes(5 * time.Second)
if err != nil {
uiline.Fatalf("Failed to auto-discover devices in network: %s", err)
uiline.Fatalf("Failed to auto-discover nodes in network: %s", err)
}
uiline.Donef("Discovered %d devices from network", len(devices))
uiline.Donef("Discovered %d nodes from network", len(nodes))

writer := printers.GetNewTabWriter(os.Stdout)
defer writer.Flush()

printer := cmd.GetPrinter(clicontext)
return printer.PrintDevices(devices, writer)
return printer.PrintNodes(nodes, writer)
},
}
20 changes: 10 additions & 10 deletions cmd/eli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ func main() {
app.Usage = `commandline interface for managing eliot`
app.UsageText = `eli [global options] command [command options] [arguments...]
# Detect devices
eli get devices
# Detect nodes
eli get nodes
# Get running pods
eli get pods
# Get pods in device
eli --device hostname.local. get pods
# Get pods in node
eli --node hostname.local. get pods
# See help of commands
eli run --help
`
app.Description = `The 'eli' is tool for managing agent in the device.
With this tool, you can create, view and remove containers from the device.`
app.Description = `The 'eli' is tool for managing agent in the node.
With this tool, you can create, view and remove containers from the node.`
app.Flags = append([]cli.Flag{
cli.StringFlag{
Name: "config, c",
Expand All @@ -49,13 +49,13 @@ func main() {
},
cli.StringFlag{
Name: "endpoint",
Usage: "Use specific device endpoint. E.g. '192.168.1.101:5000'",
Usage: "Use specific node endpoint. E.g. '192.168.1.101:5000'",
EnvVar: "ELIOT_ENDPOINT",
},
cli.StringFlag{
Name: "device",
Usage: "Use specific device by name. E.g. 'somehost.local'",
EnvVar: "ELIOT_DEVICE",
Name: "node",
Usage: "Use specific node by name. E.g. 'somehost.local'",
EnvVar: "ELIOT_NODE",
},
}, cmd.GlobalFlags...)
app.Version = fmt.Sprintf("Version: %s, Commit: %s, Build at: %s", version, commit, date)
Expand Down
6 changes: 3 additions & 3 deletions cmd/eli/runCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
var runCommand = cli.Command{
Name: "run",
HelpName: "run",
Usage: "Run command in new container in the device",
Description: "With run command, you can run command in a new container in the device",
Usage: "Run command in new container in the node",
Description: "With run command, you can run command in a new container in the node",
UsageText: `eli run [options] <image> -- <command> <args>
# Run shell session in 'eaapa/hello-world' container
Expand Down Expand Up @@ -93,7 +93,7 @@ var runCommand = cli.Command{
uiline := ui.NewLine().Loading("Resolve image for the project...")
info, err := client.GetInfo()
if err != nil {
uiline.Fatalf("Unable to resolve image for the project. Failed to get target device architecture: %s", err)
uiline.Fatalf("Unable to resolve image for the project. Failed to get target node architecture: %s", err)
}

var projectType string
Expand Down
12 changes: 6 additions & 6 deletions cmd/eli/upCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ import (
var upCommand = cli.Command{
Name: "up",
HelpName: "up",
Usage: "Start development session in the device",
Description: "With up command, you can start new development session in the device",
Usage: "Start development session in the node",
Description: "With up command, you can start new development session in the node",
UsageText: `eli up [options] -- <command>
# Run code in current directory in the device
# Run code in current directory in the node
eli up
# Run 'build.sh' command in device with files in current directory
# Run 'build.sh' command in node with files in current directory
eli up -- ./build.sh
# Run container image in the container
eli up --image docker.io/eaapa/hello-world:latest
# Run container with name in the device
# Run container with name in the node
eli up --image docker.io/eaapa/hello-world:latest --name my-pod
`,
Flags: []cli.Flag{
Expand Down Expand Up @@ -117,7 +117,7 @@ var upCommand = cli.Command{
log := ui.NewLine().Loading("Resolve image for the project...")
info, err := client.GetInfo()
if err != nil {
log.Fatalf("Unable to resolve image for the project. Failed to get target device architecture: %s", err)
log.Fatalf("Unable to resolve image for the project. Failed to get target node architecture: %s", err)
}

var projectType string
Expand Down
16 changes: 8 additions & 8 deletions cmd/eliotd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/ernoaapa/eliot/cmd"
"github.com/ernoaapa/eliot/pkg/api"
"github.com/ernoaapa/eliot/pkg/controller"
"github.com/ernoaapa/eliot/pkg/device"
"github.com/ernoaapa/eliot/pkg/discovery"
"github.com/ernoaapa/eliot/pkg/node"
"github.com/ernoaapa/eliot/pkg/profile"
log "github.com/sirupsen/logrus"
"github.com/thejerf/suture"
Expand All @@ -27,7 +27,7 @@ var date = time.Now().Format("2006-01-02_15:04:05")
func main() {
app := cli.NewApp()
app.Name = "eliotd"
app.Usage = "Daemon for the device to enable Eliot"
app.Usage = "Daemon for the node to enable Eliot"
app.UsageText = `eliotd [arguments...]
# By default listen port 5000
Expand Down Expand Up @@ -85,7 +85,7 @@ func main() {
},
cli.StringFlag{
Name: "labels",
Usage: "Comma separated list of device labels. E.g. --labels device=rpi3,location=home,environment=testing",
Usage: "Comma separated list of node labels. E.g. --labels node=rpi3,location=home,environment=testing",
EnvVar: "ELIOT_LABELS",
},
}, cmd.GlobalFlags...)
Expand All @@ -98,9 +98,9 @@ func main() {
grpcPort = parseGrpcPort(grpcListen)
)

resolver := device.NewResolver(cmd.GetLabels(clicontext))
device := resolver.GetInfo(grpcPort, version)
client := cmd.GetRuntimeClient(clicontext, device.Hostname)
resolver := node.NewResolver(grpcPort, version, cmd.GetLabels(clicontext))
node := resolver.GetInfo()
client := cmd.GetRuntimeClient(clicontext, node.Hostname)

supervisor := suture.NewSimple("eliotd")
serviceCount := 0
Expand All @@ -114,7 +114,7 @@ func main() {

if clicontext.Bool("grpc-api") {
log.Infoln("grpc-api enabled")
supervisor.Add(api.NewServer(grpcListen, client, device))
supervisor.Add(api.NewServer(grpcListen, client, resolver))
serviceCount++
}

Expand All @@ -126,7 +126,7 @@ func main() {

if clicontext.Bool("grpc-api") && clicontext.Bool("discovery") {
log.Infoln("grpc discovery over zeroconf enabled")
supervisor.Add(discovery.NewServer(device.Hostname, grpcPort, version))
supervisor.Add(discovery.NewServer(node.Hostname, grpcPort, version))
serviceCount++
}

Expand Down
30 changes: 15 additions & 15 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func GetClient(config *config.Provider) *api.Client {
endpoints := config.GetEndpoints()
switch len(endpoints) {
case 0:
uiline.Fatal("No devices to connect. You must give device endpoint. E.g. --endpoint=192.168.1.2")
uiline.Fatal("No node to connect. You must give node endpoint. E.g. --endpoint=192.168.1.2")
return nil
case 1:
uiline.Loadingf("Connecting to %s (%s)", endpoints[0].Name, endpoints[0].URL)
Expand All @@ -92,7 +92,7 @@ func GetClient(config *config.Provider) *api.Client {
uiline.Donef("Connected to %s (%s)", info.Hostname, endpoints[0].URL)
return client
default:
uiline.Fatalf("%d devices found. You must give target device. E.g. --endpoint=192.168.1.2", len(endpoints))
uiline.Fatalf("%d node found. You must give target node. E.g. --endpoint=192.168.1.2", len(endpoints))
return nil
}
}
Expand Down Expand Up @@ -126,34 +126,34 @@ func GetConfigProvider(clicontext *cli.Context) *config.Provider {

if len(provider.GetEndpoints()) == 0 {
uiline := ui.NewLine().Loading("Discover from network automatically...")
devices, err := discovery.Devices(2 * time.Second)
node, err := discovery.Nodes(2 * time.Second)
if err != nil {
uiline.Errorf("Failed to auto-discover devices in network: %s", err)
uiline.Errorf("Failed to auto-discover node in network: %s", err)
} else {
if len(devices) == 0 {
uiline.Warn("No devices discovered from network")
if len(node) == 0 {
uiline.Warn("No node discovered from network")
} else {
uiline.Donef("Discovered %d device(s) from network", len(devices))
uiline.Donef("Discovered %d node(s) from network", len(node))
}
}

endpoints := []config.Endpoint{}
for _, device := range devices {
if len(device.Addresses) > 0 {
for _, node := range node {
if len(node.Addresses) > 0 {
endpoints = append(endpoints, config.Endpoint{
Name: device.Hostname,
URL: fmt.Sprintf("%s:%d", utils.GetFirst(device.Addresses, ""), device.GrpcPort),
Name: node.Hostname,
URL: fmt.Sprintf("%s:%d", utils.GetFirst(node.Addresses, ""), node.GrpcPort),
})
}
}
provider.OverrideEndpoints(endpoints)
}

if clicontext.GlobalIsSet("device") && clicontext.GlobalString("device") != "" {
deviceName := clicontext.GlobalString("device")
endpoint, found := provider.GetEndpointByName(deviceName)
if clicontext.GlobalIsSet("node") && clicontext.GlobalString("node") != "" {
nodeName := clicontext.GlobalString("node")
endpoint, found := provider.GetEndpointByName(nodeName)
if !found {
ui.NewLine().Errorf("Failed to find device with name %s", deviceName)
ui.NewLine().Errorf("Failed to find node with name %s", nodeName)
}
provider.OverrideEndpoints([]config.Endpoint{endpoint})
}
Expand Down
Loading

0 comments on commit f20de61

Please sign in to comment.