Skip to content
This repository was archived by the owner on Nov 9, 2020. It is now read-only.

Commit f6c5176

Browse files
committed
Updated the system info command
- /system/info API returns merged object of deployment and info entities - merged object if user is admin, only info entity if user is non-admin - Updated the cli to handle this admin/non-admin scenario Change-Id: Ia1a0cae56ac8e1017130e12043e7cf570e601f70
1 parent b0fb8d7 commit f6c5176

File tree

3 files changed

+127
-89
lines changed

3 files changed

+127
-89
lines changed

photon/command/system.go

Lines changed: 106 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func GetSystemCommand() cli.Command {
7676
Usage: "Show system info",
7777
ArgsUsage: " ",
7878
Description: "Show detailed information about the system.\n" +
79-
" Requires system administrator access,",
79+
" Requires system administrator access for viewing all system information",
8080
Action: func(c *cli.Context) {
8181
err := showSystemInfo(c, os.Stdout)
8282
if err != nil {
@@ -184,115 +184,134 @@ func showSystemInfo(c *cli.Context, w io.Writer) error {
184184
return err
185185
}
186186

187-
deployment, err := client.Photonclient.System.GetSystemInfo()
187+
var data []VM_NetworkIPs
188188

189-
if err != nil {
190-
return err
191-
}
189+
systemInfo, err := client.Photonclient.System.GetSystemInfo()
192190

193-
vms, err := client.Photonclient.Deployments.GetVms("default")
194191
if err != nil {
195192
return err
196193
}
197194

198-
var data []VM_NetworkIPs
195+
if utils.NeedsFormatting(c) {
196+
utils.FormatObject(systemInfo, w, c)
197+
return nil
198+
}
199199

200-
for _, vm := range vms.Items {
201-
networks, err := getVMNetworks(vm.ID, c)
200+
if c.GlobalIsSet("non-interactive") {
201+
fmt.Printf("%s\t%s\t%s\t%s\n", systemInfo.BaseVersion,
202+
systemInfo.FullVersion, systemInfo.GitCommitHash, systemInfo.NetworkType)
203+
} else {
204+
fmt.Printf("\n Base Version: %s\n", systemInfo.BaseVersion)
205+
fmt.Printf(" Full Version: %s\n", systemInfo.FullVersion)
206+
fmt.Printf(" Git Commit Hash: %s\n", systemInfo.GitCommitHash)
207+
fmt.Printf(" Network Type: %s\n", systemInfo.NetworkType)
208+
fmt.Printf("\n")
209+
}
210+
if systemInfo.State != "" {
211+
vms, err := client.Photonclient.Deployments.GetVms("default")
202212
if err != nil {
203213
return err
204214
}
205-
ipAddr := "N/A"
206-
for _, nt := range networks {
207-
network := nt.(map[string]interface{})
208-
if len(network) != 0 && network["network"] != nil {
209-
if val, ok := network["ipAddress"]; ok && val != nil {
210-
ipAddr = val.(string)
211-
break
215+
216+
for _, vm := range vms.Items {
217+
networks, err := getVMNetworks(vm.ID, c)
218+
if err != nil {
219+
return err
220+
}
221+
ipAddr := "N/A"
222+
for _, nt := range networks {
223+
network := nt.(map[string]interface{})
224+
if len(network) != 0 && network["network"] != nil {
225+
if val, ok := network["ipAddress"]; ok && val != nil {
226+
ipAddr = val.(string)
227+
break
228+
}
212229
}
213230
}
214-
231+
data = append(data, VM_NetworkIPs{vm, ipAddr})
215232
}
216-
data = append(data, VM_NetworkIPs{vm, ipAddr})
217-
}
218-
if utils.NeedsFormatting(c) {
219-
utils.FormatObject(deployment, w, c)
220-
} else if c.GlobalIsSet("non-interactive") {
221-
imageDataStores := getCommaSeparatedStringFromStringArray(deployment.ImageDatastores)
222-
securityGroups := getCommaSeparatedStringFromStringArray(deployment.Auth.SecurityGroups)
233+
if c.GlobalIsSet("non-interactive") {
234+
imageDataStores := getCommaSeparatedStringFromStringArray(systemInfo.ImageDatastores)
235+
securityGroups := getCommaSeparatedStringFromStringArray(systemInfo.Auth.SecurityGroups)
223236

224-
fmt.Printf("%s\t%s\t%s\t%t\t%s\t%s\t%t\t%s\n", deployment.ID, deployment.State,
225-
imageDataStores, deployment.UseImageDatastoreForVms, deployment.SyslogEndpoint,
226-
deployment.NTPEndpoint, deployment.LoadBalancerEnabled,
227-
deployment.LoadBalancerAddress)
237+
fmt.Printf("%s\t%s\t%t\t%s\t%s\t%t\t%s\n", systemInfo.State,
238+
imageDataStores, systemInfo.UseImageDatastoreForVms, systemInfo.SyslogEndpoint,
239+
systemInfo.NTPEndpoint, systemInfo.LoadBalancerEnabled,
240+
systemInfo.LoadBalancerAddress)
228241

229-
fmt.Printf("%s\t%s\t%d\t%s\n", deployment.Auth.Endpoint,
230-
deployment.Auth.Domain, deployment.Auth.Port, securityGroups)
242+
fmt.Printf("%s\t%s\t%d\t%s\n", systemInfo.Auth.Endpoint,
243+
systemInfo.Auth.Domain, systemInfo.Auth.Port, securityGroups)
231244

232-
} else {
233-
syslogEndpoint := deployment.SyslogEndpoint
234-
if len(deployment.SyslogEndpoint) == 0 {
235-
syslogEndpoint = "-"
236-
}
237-
ntpEndpoint := deployment.NTPEndpoint
238-
if len(deployment.NTPEndpoint) == 0 {
239-
ntpEndpoint = "-"
240-
}
241-
242-
fmt.Printf("\n")
243-
fmt.Printf("Deployment ID: %s\n", deployment.ID)
244-
fmt.Printf(" State: %s\n", deployment.State)
245-
fmt.Printf("\n Image Datastores: %s\n", deployment.ImageDatastores)
246-
fmt.Printf(" Use image datastore for vms: %t\n", deployment.UseImageDatastoreForVms)
247-
fmt.Printf("\n Syslog Endpoint: %s\n", syslogEndpoint)
248-
fmt.Printf(" Ntp Endpoint: %s\n", ntpEndpoint)
249-
fmt.Printf("\n LoadBalancer:\n")
250-
fmt.Printf(" Enabled: %t\n", deployment.LoadBalancerEnabled)
251-
if deployment.LoadBalancerEnabled {
252-
fmt.Printf(" Address: %s\n", deployment.LoadBalancerAddress)
253-
}
245+
} else {
246+
syslogEndpoint := systemInfo.SyslogEndpoint
247+
if len(systemInfo.SyslogEndpoint) == 0 {
248+
syslogEndpoint = "-"
249+
}
250+
ntpEndpoint := systemInfo.NTPEndpoint
251+
if len(systemInfo.NTPEndpoint) == 0 {
252+
ntpEndpoint = "-"
253+
}
254254

255-
fmt.Printf("\n Auth:\n")
256-
fmt.Printf(" Endpoint: %s\n", deployment.Auth.Endpoint)
257-
fmt.Printf(" Domain: %s\n", deployment.Auth.Domain)
258-
fmt.Printf(" Port: %d\n", deployment.Auth.Port)
259-
fmt.Printf(" SecurityGroups: %v\n", deployment.Auth.SecurityGroups)
260-
}
255+
fmt.Printf(" State: %s\n", systemInfo.State)
256+
fmt.Printf("\n Image Datastores: %s\n", systemInfo.ImageDatastores)
257+
fmt.Printf(" Use image datastore for vms: %t\n", systemInfo.UseImageDatastoreForVms)
258+
fmt.Printf("\n Syslog Endpoint: %s\n", syslogEndpoint)
259+
fmt.Printf(" Ntp Endpoint: %s\n", ntpEndpoint)
260+
fmt.Printf("\n LoadBalancer:\n")
261+
fmt.Printf(" Enabled: %t\n", systemInfo.LoadBalancerEnabled)
262+
if systemInfo.LoadBalancerEnabled {
263+
fmt.Printf(" Address: %s\n", systemInfo.LoadBalancerAddress)
264+
}
261265

262-
if deployment.Stats != nil {
263-
stats := deployment.Stats
264-
if c.GlobalIsSet("non-interactive") {
265-
fmt.Printf("%t\t%s\t%d\n", stats.Enabled, stats.StoreEndpoint, stats.StorePort)
266-
} else if !utils.NeedsFormatting(c) {
266+
fmt.Printf("\n Auth:\n")
267+
fmt.Printf(" Endpoint: %s\n", systemInfo.Auth.Endpoint)
268+
fmt.Printf(" Domain: %s\n", systemInfo.Auth.Domain)
269+
fmt.Printf(" Port: %d\n", systemInfo.Auth.Port)
270+
fmt.Printf(" SecurityGroups: %v\n", systemInfo.Auth.SecurityGroups)
271+
}
267272

268-
fmt.Printf("\n Stats:\n")
269-
fmt.Printf(" Enabled: %t\n", stats.Enabled)
270-
if stats.Enabled {
271-
fmt.Printf(" Store Endpoint: %s\n", stats.StoreEndpoint)
272-
fmt.Printf(" Store Port: %d\n", stats.StorePort)
273+
if systemInfo.Stats != nil {
274+
stats := systemInfo.Stats
275+
if c.GlobalIsSet("non-interactive") {
276+
fmt.Printf("%t\t%s\t%d\n", stats.Enabled, stats.StoreEndpoint, stats.StorePort)
277+
} else if !utils.NeedsFormatting(c) {
278+
279+
fmt.Printf("\n Stats:\n")
280+
fmt.Printf(" Enabled: %t\n", stats.Enabled)
281+
if stats.Enabled {
282+
fmt.Printf(" Store Endpoint: %s\n", stats.StoreEndpoint)
283+
fmt.Printf(" Store Port: %d\n", stats.StorePort)
284+
}
285+
}
286+
} else {
287+
if c.GlobalIsSet("non-interactive") {
288+
fmt.Printf("\n")
273289
}
274290
}
275-
} else {
276-
if c.GlobalIsSet("non-interactive") {
277-
fmt.Printf("\n")
278-
}
279-
}
280291

281-
if deployment.ServiceConfigurations != nil && len(deployment.ServiceConfigurations) != 0 {
282-
if c.GlobalIsSet("non-interactive") {
283-
serviceConfigurations := []string{}
284-
for _, c := range deployment.ServiceConfigurations {
285-
serviceConfigurations = append(serviceConfigurations, fmt.Sprintf("%s\t%s", c.Type, c.ImageID))
292+
if systemInfo.ServiceConfigurations != nil && len(systemInfo.ServiceConfigurations) != 0 {
293+
if c.GlobalIsSet("non-interactive") {
294+
serviceConfigurations := []string{}
295+
for _, c := range systemInfo.ServiceConfigurations {
296+
serviceConfigurations = append(serviceConfigurations, fmt.Sprintf("%s\t%s", c.Type, c.ImageID))
297+
}
298+
scriptServiceConfigurations := strings.Join(serviceConfigurations, ",")
299+
fmt.Printf("%s\n", scriptServiceConfigurations)
300+
} else if !utils.NeedsFormatting(c) {
301+
fmt.Println("\n Service Configurations:")
302+
for i, c := range systemInfo.ServiceConfigurations {
303+
fmt.Printf(" ServiceConfiguration %d:\n", i+1)
304+
fmt.Println(" Kind: ", c.Kind)
305+
fmt.Println(" Type: ", c.Type)
306+
fmt.Println(" ImageID: ", c.ImageID)
307+
}
286308
}
287-
scriptServiceConfigurations := strings.Join(serviceConfigurations, ",")
288-
fmt.Printf("%s\n", scriptServiceConfigurations)
289-
} else if !utils.NeedsFormatting(c) {
290-
fmt.Println("\n Service Configurations:")
291-
for i, c := range deployment.ServiceConfigurations {
292-
fmt.Printf(" ServiceConfiguration %d:\n", i+1)
293-
fmt.Println(" Kind: ", c.Kind)
294-
fmt.Println(" Type: ", c.Type)
295-
fmt.Println(" ImageID: ", c.ImageID)
309+
} else {
310+
if c.GlobalIsSet("non-interactive") {
311+
fmt.Printf("\n")
312+
} else if !utils.NeedsFormatting(c) {
313+
fmt.Println("\n Service Configurations:")
314+
fmt.Printf(" No Service is supported")
296315
}
297316
}
298317
} else {

vendor/github.com/vmware/photon-controller-go-sdk/photon/apitypes.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vmware/photon-controller-go-sdk/photon/system.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)