intergrated cli functionality
This commit is contained in:
@@ -1,12 +1,46 @@
|
||||
{
|
||||
"Groups": [
|
||||
{
|
||||
"ID": "grp72f16ae0-4f68-4245-b570-93fb31de887e",
|
||||
"TrackContainer": null
|
||||
},
|
||||
{
|
||||
"ID": "grpf184d181-68ac-4829-a801-a7a585421f68",
|
||||
"TrackContainer": null
|
||||
"ID": "grp8c59a8bd-56c2-4234-b7b7-3ef4727da927",
|
||||
"TrackContainer": [
|
||||
{
|
||||
"ID": "9c407a796018eba3db51eda61d6e6f75adea2da66bca2e7a2b1c1cdb08f282aa",
|
||||
"Container": {
|
||||
"SSHUsername": "master",
|
||||
"SSHPassword": "password",
|
||||
"ID": "9c407a796018eba3db51eda61d6e6f75adea2da66bca2e7a2b1c1cdb08f282aa",
|
||||
"TagName": "p2p-ubuntu",
|
||||
"ImagePath": "/home/akilan/Documents/p2p-rendering-computation/server/docker/containers/docker-ubuntu-sshd/",
|
||||
"Ports": {
|
||||
"Port": [
|
||||
{
|
||||
"PortName": "SSH",
|
||||
"InternalPort": 22,
|
||||
"Type": "tcp",
|
||||
"ExternalPort": 43835,
|
||||
"Description": "SSH Port"
|
||||
},
|
||||
{
|
||||
"PortName": "NoVNC",
|
||||
"InternalPort": 5901,
|
||||
"Type": "tcp",
|
||||
"ExternalPort": 34383,
|
||||
"Description": "NoVNC port"
|
||||
},
|
||||
{
|
||||
"PortName": "NoVNC",
|
||||
"InternalPort": 6081,
|
||||
"Type": "tcp",
|
||||
"ExternalPort": 34501,
|
||||
"Description": "NoVNC port"
|
||||
}
|
||||
]
|
||||
},
|
||||
"GPU": "false"
|
||||
},
|
||||
"IpAddress": "0.0.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -181,6 +181,69 @@ var CliAction = func(ctx *cli.Context) error {
|
||||
|
||||
}
|
||||
|
||||
// Executing function to create new group
|
||||
// Creates new group and outputs JSON file
|
||||
if CreateGroup {
|
||||
group, err := client.CreateGroup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client.PrettyPrint(group)
|
||||
}
|
||||
|
||||
// Actions to be performed when the
|
||||
// group flag is called
|
||||
// --group <Group ID>
|
||||
if Group != "" {
|
||||
// Remove container from group based on group ID provided
|
||||
// --rmcgroup --id <contianer id>
|
||||
if RemoveContainerGroup && ID != "" {
|
||||
group, err := client.RemoveContainerGroup(ID, Group)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
client.PrettyPrint(group)
|
||||
}
|
||||
} else if ID != "" { // Add container to group based on group ID provided
|
||||
// --id <Container ID>
|
||||
group, err := client.AddContainerToGroup(ID,Group)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
client.PrettyPrint(group)
|
||||
}
|
||||
} else { // View all information about current group
|
||||
group, err := client.GetGroup(Group)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
client.PrettyPrint(group)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute function to remove entire group
|
||||
// when remove group flag is called
|
||||
// --rmgroup
|
||||
if RemoveGroup != "" {
|
||||
err := client.RemoveGroup(RemoveGroup)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println("Group Removed")
|
||||
}
|
||||
}
|
||||
|
||||
// Execute Function to view all groups
|
||||
if Groups {
|
||||
groups, err := client.ReadGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
client.PrettyPrint(groups)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
74
cmd/flags.go
74
cmd/flags.go
@@ -6,23 +6,28 @@ import (
|
||||
|
||||
// Variables declared for CLI
|
||||
var (
|
||||
AddServer string
|
||||
ViewImages string
|
||||
CreateVM string
|
||||
ContainerName string
|
||||
Ports string
|
||||
Server bool
|
||||
RemoveVM string
|
||||
ID string
|
||||
Specs string
|
||||
GPU bool
|
||||
UpdateServerList bool
|
||||
ServerList bool
|
||||
SetDefaultConfig bool
|
||||
NetworkInterface bool
|
||||
ViewPlugin bool
|
||||
TrackedContainers bool
|
||||
ExecutePlugin string
|
||||
AddServer string
|
||||
ViewImages string
|
||||
CreateVM string
|
||||
ContainerName string
|
||||
Ports string
|
||||
Server bool
|
||||
RemoveVM string
|
||||
ID string
|
||||
Specs string
|
||||
GPU bool
|
||||
UpdateServerList bool
|
||||
ServerList bool
|
||||
SetDefaultConfig bool
|
||||
NetworkInterface bool
|
||||
ViewPlugin bool
|
||||
TrackedContainers bool
|
||||
ExecutePlugin string
|
||||
CreateGroup bool
|
||||
Group string
|
||||
Groups bool
|
||||
RemoveContainerGroup bool
|
||||
RemoveGroup string
|
||||
)
|
||||
|
||||
var AppConfigFlags = []cli.Flag{
|
||||
@@ -147,4 +152,39 @@ var AppConfigFlags = []cli.Flag{
|
||||
EnvVars: []string{"EXECUTE_PLUGIN"},
|
||||
Destination: &ExecutePlugin,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "CreateGroup",
|
||||
Aliases: []string{"cgroup"},
|
||||
Usage: "Creates a new group",
|
||||
EnvVars: []string{"CREATE_GROUP"},
|
||||
Destination: &CreateGroup,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "Group",
|
||||
Aliases: []string{"group"},
|
||||
Usage: "group flag with argument group ID",
|
||||
EnvVars: []string{"GROUP"},
|
||||
Destination: &Group,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "Groups",
|
||||
Aliases: []string{"groups"},
|
||||
Usage: "View all groups",
|
||||
EnvVars: []string{"GROUPS"},
|
||||
Destination: &Groups,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "RemoveContainerGroup",
|
||||
Aliases: []string{"rmcgroup"},
|
||||
Usage: "Remove specific container in the group",
|
||||
EnvVars: []string{"REMOVE_CONTAINER_GROUP"},
|
||||
Destination: &RemoveContainerGroup,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "RemoveGroup",
|
||||
Aliases: []string{"rmgroup"},
|
||||
Usage: "Removes the entire group",
|
||||
EnvVars: []string{"REMOVE_GROUP"},
|
||||
Destination: &RemoveGroup,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user