-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||
``` |
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.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
{ | ||||||
Name: "creationDate", | ||||||
Type: proto.ColumnType_TIMESTAMP, | ||||||
Description: "Volume creation date.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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)", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
{ | ||||||
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 | ||||||
} |
There was a problem hiding this comment.
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?