MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runStorageContentList

Function runStorageContentList

internal/cli/storage.go:294–353  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

292}
293
294func runStorageContentList(cmd *cobra.Command, args []string) error {
295 ctx := context.Background()
296 nodeName := args[0]
297 storageName := args[1]
298
299 contentType, _ := cmd.Flags().GetString("type")
300
301 session, err := initCLISession(cmd)
302 if err != nil {
303 return printError(err)
304 }
305
306 if session == nil {
307 return nil
308 }
309
310 client, err := session.clientForNode(ctx, nodeName)
311 if err != nil {
312 return printError(err)
313 }
314
315 items, err := client.GetStorageContent(nodeName, storageName, contentType)
316 if err != nil {
317 return printError(fmt.Errorf("failed to list content: %w", err))
318 }
319
320 rows := make([]storageContentRow, 0, len(items))
321 for _, item := range items {
322 name := item.VolID
323 if idx := strings.LastIndex(name, "/"); idx >= 0 {
324 name = name[idx+1:]
325 }
326
327 rows = append(rows, storageContentRow{
328 VolID: item.VolID,
329 Name: name,
330 Type: item.Content,
331 Size: item.Size,
332 CTime: item.CreatedAt.Unix(),
333 VMID: item.VMID,
334 })
335 }
336
337 format := getOutputFormat(cmd)
338 if format == outputTable {
339 headers := []string{"VOLID", "TYPE", "SIZE", "DATE"}
340 tableRows := make([][]string, 0, len(rows))
341 for _, r := range rows {
342 date := ""
343 if r.CTime > 0 {
344 date = time.Unix(r.CTime, 0).Format("2006-01-02")
345 }
346 tableRows = append(tableRows, []string{r.VolID, r.Type, formatBytes(r.Size), date})
347 }
348 printTable(headers, tableRows)
349 return nil
350 }
351

Callers

nothing calls this directly

Calls 8

initCLISessionFunction · 0.85
printErrorFunction · 0.85
getOutputFormatFunction · 0.85
formatBytesFunction · 0.85
printTableFunction · 0.85
printJSONFunction · 0.85
clientForNodeMethod · 0.80
GetStorageContentMethod · 0.80

Tested by

no test coverage detected