@@ -20,14 +20,17 @@ import (
2020
2121 "github.com/spf13/cobra"
2222
23+ "github.com/liquidweb/liquidweb-cli/instance"
2324 "github.com/liquidweb/liquidweb-cli/types/api"
2425 "github.com/liquidweb/liquidweb-cli/validate"
2526)
2627
28+ var cloudNetworkPrivateDetailsCmdUniqIdFlag []string
29+
2730var cloudNetworkPrivateDetailsCmd = & cobra.Command {
2831 Use : "details" ,
29- Short : "Get Private Network details for a Cloud Server" ,
30- Long : `Get Private Network details for a Cloud Server
32+ Short : "Get Private Network details for a single or all Cloud Server(s) " ,
33+ Long : `Get Private Network details for a single or all Cloud Server(s)
3134
3235Private networking provides the option for several Cloud Servers to contact each other
3336via a network interface that is:
@@ -39,37 +42,50 @@ Applications that communicate internally will frequently use this for both secur
3942and cost-savings.
4043` ,
4144 Run : func (cmd * cobra.Command , args []string ) {
42- uniqIdFlag , _ := cmd . Flags (). GetString ( "uniq-id" )
45+ var uniqIds [] string
4346
44- validateFields := map [interface {}]interface {}{
45- uniqIdFlag : "UniqId" ,
46- }
47- if err := validate .Validate (validateFields ); err != nil {
48- lwCliInst .Die (err )
47+ if len (cloudNetworkPrivateDetailsCmdUniqIdFlag ) == 0 {
48+ methodArgs := instance.AllPaginatedResultsArgs {
49+ Method : "bleed/storm/server/list" ,
50+ ResultsPerPage : 100 ,
51+ }
52+ results , err := lwCliInst .AllPaginatedResults (& methodArgs )
53+ if err != nil {
54+ lwCliInst .Die (err )
55+ }
56+ for _ , item := range results .Items {
57+ var cs apiTypes.CloudServerDetails
58+ if err := instance .CastFieldTypes (item , & cs ); err != nil {
59+ lwCliInst .Die (err )
60+ }
61+ uniqIds = append (uniqIds , cs .UniqId )
62+ }
63+ } else {
64+ uniqIds = cloudNetworkPrivateDetailsCmdUniqIdFlag
4965 }
5066
51- apiArgs := map [string ]interface {}{"uniq_id" : uniqIdFlag }
67+ for _ , uniqId := range uniqIds {
68+ validateFields := map [interface {}]interface {}{
69+ uniqId : "UniqId" ,
70+ }
71+ if err := validate .Validate (validateFields ); err != nil {
72+ lwCliInst .Die (err )
73+ }
5274
53- var details apiTypes.CloudNetworkPrivateGetIpResponse
54- err := lwCliInst .CallLwApiInto ("bleed/network/private/getip" , apiArgs , & details )
55- if err != nil {
56- lwCliInst .Die (err )
57- }
75+ apiArgs := map [string ]interface {}{"uniq_id" : uniqId }
5876
59- if details . Ip == "" {
60- fmt . Printf ( "Cloud Server is not attached to a Private Network \n " )
61- } else {
62- fmt . Printf ( "Cloud Server is attached to a Private Network \n " )
63- fmt . Printf ( " \t IP: %s \n " , details . Ip )
64- fmt .Printf ( " \t Legacy: %t \n " , details . Legacy )
77+ var details apiTypes. CloudNetworkPrivateGetIpResponse
78+ if err := lwCliInst . CallLwApiInto ( "bleed/network/private/getip" , apiArgs , & details ); err != nil {
79+ lwCliInst . Die ( err )
80+ }
81+
82+ fmt .Print ( details )
6583 }
6684 },
6785}
6886
6987func init () {
7088 cloudNetworkPrivateCmd .AddCommand (cloudNetworkPrivateDetailsCmd )
71- cloudNetworkPrivateDetailsCmd .Flags ().String ("uniq-id" , "" , "uniq-id of the Cloud Server" )
72- if err := cloudNetworkPrivateDetailsCmd .MarkFlagRequired ("uniq-id" ); err != nil {
73- lwCliInst .Die (err )
74- }
89+ cloudNetworkPrivateDetailsCmd .Flags ().StringSliceVar (& cloudNetworkPrivateDetailsCmdUniqIdFlag , "uniq-id" ,
90+ []string {}, "uniq-ids separated by ',' of Cloud Servers to fetch private networking details for" )
7591}
0 commit comments