intergrated cli functionality

This commit is contained in:
2021-08-13 21:40:00 +04:00
parent 1fe5db06c0
commit a920ff749b
3 changed files with 160 additions and 23 deletions

View File

@@ -1,12 +1,46 @@
{ {
"Groups": [ "Groups": [
{ {
"ID": "grp72f16ae0-4f68-4245-b570-93fb31de887e", "ID": "grp8c59a8bd-56c2-4234-b7b7-3ef4727da927",
"TrackContainer": null "TrackContainer": [
}, {
{ "ID": "9c407a796018eba3db51eda61d6e6f75adea2da66bca2e7a2b1c1cdb08f282aa",
"ID": "grpf184d181-68ac-4829-a801-a7a585421f68", "Container": {
"TrackContainer": null "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"
}
]
} }
] ]
} }

View File

@@ -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 return nil
} }

View File

@@ -6,23 +6,28 @@ import (
// Variables declared for CLI // Variables declared for CLI
var ( var (
AddServer string AddServer string
ViewImages string ViewImages string
CreateVM string CreateVM string
ContainerName string ContainerName string
Ports string Ports string
Server bool Server bool
RemoveVM string RemoveVM string
ID string ID string
Specs string Specs string
GPU bool GPU bool
UpdateServerList bool UpdateServerList bool
ServerList bool ServerList bool
SetDefaultConfig bool SetDefaultConfig bool
NetworkInterface bool NetworkInterface bool
ViewPlugin bool ViewPlugin bool
TrackedContainers bool TrackedContainers bool
ExecutePlugin string ExecutePlugin string
CreateGroup bool
Group string
Groups bool
RemoveContainerGroup bool
RemoveGroup string
) )
var AppConfigFlags = []cli.Flag{ var AppConfigFlags = []cli.Flag{
@@ -147,4 +152,39 @@ var AppConfigFlags = []cli.Flag{
EnvVars: []string{"EXECUTE_PLUGIN"}, EnvVars: []string{"EXECUTE_PLUGIN"},
Destination: &ExecutePlugin, 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,
},
} }