Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "vms", Short: "Purge the PowerVS vms", Long: `Purge the PowerVS vms! pvsadm purge --help for information `, RunE: func(cmd *cobra.Command, args []string) error { opt := pkg.Options c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug) if err != nil { return err } pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment) if err != nil { return err } instances, err := pvmclient.InstanceClient.GetAllPurgeable(pkg.Options.Before, pkg.Options.Since, pkg.Options.Expr) if err != nil { return err } t := utils.NewTable() t.SetHeader([]string{"Name", "IP Addresses", "Image", "CPUS", "RAM", "STATUS", "Creation Date"}) for _, instance := range instances { ins, err := pvmclient.InstanceClient.Get(*instance.PvmInstanceID) if err != nil { klog.Errorf("error occurred while getting the vm %s", err) continue } var ipAddrsPrivate, ipAddrsPublic []string for _, ip := range ins.Networks { if ip.ExternalIP != "" { ipAddrsPublic = append(ipAddrsPublic, ip.ExternalIP) } ipAddrsPrivate = append(ipAddrsPrivate, ip.IPAddress) } ipString := fmt.Sprintf("External: %s\nPrivate: %s", strings.Join(ipAddrsPublic, ", "), strings.Join(ipAddrsPrivate, ", ")) status := fmt.Sprintf("Status: %s\nHealth: %s", *instance.Status, instance.Health.Status) row := []string{*instance.ServerName, ipString, *instance.ImageID, utils.FormatProcessor(instance.Processors), utils.FormatMemory(instance.Memory), status, instance.CreationDate.String()} t.Append(row) } t.Table.Render() if !opt.DryRun && len(instances) != 0 { if opt.NoPrompt || utils.AskConfirmation(fmt.Sprintf(utils.DeletePromptMessage, "instances")) { for _, instance := range instances { klog.Infof("Deleting instance: %s with ID: %s", *instance.ServerName, *instance.PvmInstanceID) err = pvmclient.InstanceClient.Delete(*instance.PvmInstanceID) if err != nil { if opt.IgnoreErrors { klog.Errorf("error occurred while deleting the vm: %v", err) } else { return err } } audit.Log("vms", "delete", pvmclient.InstanceName+":"+*instance.ServerName) } } } return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.