From a920ff749b3ea631ea692fcfe616449b5c7209b3 Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar Date: Fri, 13 Aug 2021 21:40:00 +0400 Subject: [PATCH] intergrated cli functionality --- .../trackcontainers/grouptrackcontainers.json | 46 ++++++++++-- cmd/action.go | 63 ++++++++++++++++ cmd/flags.go | 74 ++++++++++++++----- 3 files changed, 160 insertions(+), 23 deletions(-) diff --git a/client/trackcontainers/grouptrackcontainers.json b/client/trackcontainers/grouptrackcontainers.json index 3d4b0c6..3274ffe 100644 --- a/client/trackcontainers/grouptrackcontainers.json +++ b/client/trackcontainers/grouptrackcontainers.json @@ -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" + } + ] } ] } \ No newline at end of file diff --git a/cmd/action.go b/cmd/action.go index ad43725..10fff98 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -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 + if Group != "" { + // Remove container from group based on group ID provided + // --rmcgroup --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 + 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 } diff --git a/cmd/flags.go b/cmd/flags.go index a7dc82b..0fe8fc9 100644 --- a/cmd/flags.go +++ b/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, + }, } \ No newline at end of file