-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ppc64le-cloud/events
get events command
- Loading branch information
Showing
6 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package events | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ppc64le-cloud/pvsadm/pkg" | ||
"github.com/ppc64le-cloud/pvsadm/pkg/client" | ||
"github.com/ppc64le-cloud/pvsadm/pkg/utils" | ||
"github.com/spf13/cobra" | ||
"time" | ||
) | ||
|
||
var ( | ||
since time.Duration | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "events", | ||
Short: "Get Powervs events", | ||
Long: `Get the PowerVS events`, | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" { | ||
return fmt.Errorf("--instance-name or --instance-name required") | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opt := pkg.Options | ||
|
||
c, err := client.NewClient(opt.APIKey) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
pvmclient, err := client.NewPVMClient(c, opt.InstanceID, opt.InstanceName) | ||
if err != nil { | ||
return err | ||
} | ||
events, err := pvmclient.EventsClient.GetPcloudEventsGetsince(since) | ||
if err != nil { | ||
return err | ||
} | ||
table := utils.NewTable() | ||
table.Render(events.Payload.Events, []string{"user", "timestamp"}) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
Cmd.PersistentFlags().DurationVar(&since, "since", 24*time.Hour, "Show events since") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package get | ||
|
||
import ( | ||
"github.com/ppc64le-cloud/pvsadm/cmd/get/events" | ||
"github.com/ppc64le-cloud/pvsadm/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get the resources", | ||
Long: `Get the resources`, | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(events.Cmd) | ||
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") | ||
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "instance-name", "n", "", "Instance name of the PowerVS") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/IBM-Cloud/power-go-client/ibmpisession" | ||
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_events" | ||
"github.com/ppc64le-cloud/pvsadm/pkg" | ||
"time" | ||
) | ||
|
||
type Client struct { | ||
instanceID string | ||
client *p_cloud_events.Client | ||
session *ibmpisession.IBMPISession | ||
} | ||
|
||
func NewClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *Client { | ||
c := &Client{ | ||
session: sess, | ||
instanceID: powerinstanceid, | ||
client: sess.Power.PCloudEvents, | ||
} | ||
return c | ||
} | ||
|
||
func (c *Client) GetPcloudEventsGetsince(since time.Duration) (*p_cloud_events.PcloudEventsGetsinceOK, error) { | ||
params := p_cloud_events.NewPcloudEventsGetsinceParamsWithTimeout(pkg.TIMEOUT).WithCloudInstanceID(c.instanceID).WithTime(time.Now().UTC().Add(-since).Format(time.RFC3339)) | ||
return c.client.PcloudEventsGetsince(params, ibmpisession.NewAuth(c.session, c.instanceID)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters