Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added volume snapshot querying #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/tables/ovh_cloud_volume_snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Table: ovh_cloud_volume_snapshot

A volume is an independent additional disk.

The `ovh_cloud_volume_snapshot` table can be used to query information about volumes snapshots and **you must specify which cloud project** in the where or join clause (`where project_id=`, `join ovh_cloud_project on id=`).

## Examples

### List volumes snapshots of a cloud project

```sql
select
id,
name
from
ovh_cloud_volume_snapshot
where
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8'
```

### List available volumes snapshots of a cloud project

```sql
select
id,
name
from
ovh_cloud_volume_snapshot
where
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8'
and status = 'available'
```
31 changes: 16 additions & 15 deletions ovh/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ func Plugin(ctx context.Context) *plugin.Plugin {
Schema: ConfigSchema,
},
TableMap: map[string]*plugin.Table{
"ovh_bill": tableOvhBill(),
"ovh_bill_detail": tableOvhBillDetails(),
"ovh_cloud_ai_app": tableOvhCloudAIApp(),
"ovh_cloud_ai_job": tableOvhCloudAIJob(),
"ovh_cloud_ai_notebook": tableOvhCloudAINotebook(),
"ovh_cloud_data_job": tableOvhCloudDataJob(),
"ovh_cloud_database": tableOvhCloudDatabase(),
"ovh_cloud_flavor": tableOvhCloudFlavor(),
"ovh_cloud_image": tableOvhCloudImage(),
"ovh_cloud_instance": tableOvhCloudInstance(),
"ovh_cloud_postgres": tableOvhCloudPostgres(),
"ovh_cloud_project": tableOvhCloudProject(),
"ovh_cloud_ssh_key": tableOvhCloudSshKey(),
"ovh_cloud_storage": tableOvhCloudStorage(),
"ovh_cloud_volume": tableOvhCloudVolume(),
"ovh_bill": tableOvhBill(),
"ovh_bill_detail": tableOvhBillDetails(),
"ovh_cloud_ai_app": tableOvhCloudAIApp(),
"ovh_cloud_ai_job": tableOvhCloudAIJob(),
"ovh_cloud_ai_notebook": tableOvhCloudAINotebook(),
"ovh_cloud_data_job": tableOvhCloudDataJob(),
"ovh_cloud_database": tableOvhCloudDatabase(),
"ovh_cloud_flavor": tableOvhCloudFlavor(),
"ovh_cloud_image": tableOvhCloudImage(),
"ovh_cloud_instance": tableOvhCloudInstance(),
"ovh_cloud_postgres": tableOvhCloudPostgres(),
"ovh_cloud_project": tableOvhCloudProject(),
"ovh_cloud_ssh_key": tableOvhCloudSshKey(),
"ovh_cloud_storage": tableOvhCloudStorage(),
"ovh_cloud_volume": tableOvhCloudVolume(),
"ovh_cloud_volume_snapshot": tableOvhCloudVolumeSnapshot(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the indentation here?

},
}
return p
Expand Down
129 changes: 129 additions & 0 deletions ovh/table_ovh_cloud_volume_snapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package ovh

import (
"context"
"fmt"
"time"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableOvhCloudVolumeSnapshot() *plugin.Table {
return &plugin.Table{
Name: "ovh_cloud_volume_snapshot",
Description: "A volume is an independent additional disk.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should be updated I guess.

List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("project_id"),
Hydrate: listVolumeSnapshot,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"project_id", "id"}),
Hydrate: getVolumeSnapshot,
},
Columns: []*plugin.Column{
{
Name: "project_id",
Type: proto.ColumnType_STRING,
Transform: transform.FromQual("project_id"),
Description: "Project ID.",
},
{
Name: "id",
Type: proto.ColumnType_STRING,
Description: "ID.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: "ID.",
Description: "Snapshot ID.",

},
{
Name: "creationDate",
Type: proto.ColumnType_TIMESTAMP,
Description: "Volume creation date.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: "Volume creation date.",
Description: "Snapshot creation date.",

Transform: transform.FromField("CreationDate"),
},
{
Name: "name",
Type: proto.ColumnType_STRING,
Description: "Volume Snapshot Name.",
},
{
Name: "description",
Type: proto.ColumnType_STRING,
Description: "Volume Snapshot Description",
},
{
Name: "size",
Type: proto.ColumnType_INT,
Description: "Volume Snapshot size (in GB).",
},
{
Name: "volumeId",
Type: proto.ColumnType_STRING,
Description: "Volume Snapshot ID.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: "Volume Snapshot ID.",
Description: "Volume source ID.",

Transform: transform.FromField("VolumeId"),
},
{
Name: "region",
Type: proto.ColumnType_STRING,
Description: "Volume Snapshot Region.",
},
{
Name: "status",
Type: proto.ColumnType_STRING,
Description: "Volume Snapshot Status. (available, creating, deleting, error, error_deleting)",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: "Volume Snapshot Status. (available, creating, deleting, error, error_deleting)",
Description: "Volume Snapshot Status (available, creating, deleting, error, error_deleting).",

},
{
Name: "planCode",
Type: proto.ColumnType_STRING,
Description: "Volume Snapshot Plan Code",
},
},
}
}

type VolumeSnapShot struct {
ID string `json:"id"`
CreationDate time.Time `json:"creationDate"`
Name string `json:"name"`
Description string `json:"description"`
Size int `json:"size"`
VolumeId string `json:"volumeId"`
Region string `json:"region"`
Status string `json:"status"`
PlanCode string `json:"planCode"`
}

func listVolumeSnapshot(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_volume.listVolumeSnapshot", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
var volumes []VolumeSnapShot
err = client.Get(fmt.Sprintf("/cloud/project/%s/volume/snapshot", projectId), &volumes)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_volume.listVolumeSnapshot", err)
return nil, err
}
for _, volume := range volumes {
d.StreamListItem(ctx, volume)
}
return nil, nil
}

func getVolumeSnapshot(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_volume.getVolumeSnapshot", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
id := d.EqualsQuals["id"].GetStringValue()
var volume VolumeSnapShot
err = client.Get(fmt.Sprintf("/cloud/project/%s/volume/snapshot/%s", projectId, id), &volume)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_volume.getVolumeSnapshot", err)
return nil, err
}
return volume, nil
}