818 lines
20 KiB
Go
818 lines
20 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: query.sql
|
|
|
|
package queries
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const cleanupUpdates = `-- name: CleanupUpdates :exec
|
|
DELETE FROM "Updates"
|
|
WHERE "UpdateType" = ?1 AND "UpdateTime" <= ?2
|
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName
|
|
`
|
|
|
|
type CleanupUpdatesParams struct {
|
|
UpdateType string
|
|
UpdateTime sql.NullInt64
|
|
}
|
|
|
|
func (q *Queries) CleanupUpdates(ctx context.Context, arg CleanupUpdatesParams) error {
|
|
_, err := q.db.ExecContext(ctx, cleanupUpdates, arg.UpdateType, arg.UpdateTime)
|
|
return err
|
|
}
|
|
|
|
const createEvent = `-- name: CreateEvent :one
|
|
INSERT INTO "Events" (
|
|
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
RETURNING Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType
|
|
`
|
|
|
|
type CreateEventParams struct {
|
|
CloudId string
|
|
Source string
|
|
EventTime sql.NullInt64
|
|
ChainId string
|
|
VmId sql.NullString
|
|
VmName sql.NullString
|
|
EventType sql.NullString
|
|
EventKey sql.NullString
|
|
DatacenterId sql.NullString
|
|
DatacenterName sql.NullString
|
|
ComputeResourceId sql.NullString
|
|
ComputeResourceName sql.NullString
|
|
UserName sql.NullString
|
|
}
|
|
|
|
func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Events, error) {
|
|
row := q.db.QueryRowContext(ctx, createEvent,
|
|
arg.CloudId,
|
|
arg.Source,
|
|
arg.EventTime,
|
|
arg.ChainId,
|
|
arg.VmId,
|
|
arg.VmName,
|
|
arg.EventType,
|
|
arg.EventKey,
|
|
arg.DatacenterId,
|
|
arg.DatacenterName,
|
|
arg.ComputeResourceId,
|
|
arg.ComputeResourceName,
|
|
arg.UserName,
|
|
)
|
|
var i Events
|
|
err := row.Scan(
|
|
&i.Eid,
|
|
&i.CloudId,
|
|
&i.Source,
|
|
&i.EventTime,
|
|
&i.ChainId,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.DatacenterName,
|
|
&i.ComputeResourceName,
|
|
&i.UserName,
|
|
&i.Processed,
|
|
&i.DatacenterId,
|
|
&i.ComputeResourceId,
|
|
&i.VmName,
|
|
&i.EventType,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createInventory = `-- name: CreateInventory :one
|
|
INSERT INTO "Inventory" (
|
|
"Name", "Vcenter", "VmId", "VmUuid", "EventKey", "CloudId", "CreationTime", "ResourcePool", "VmType", "IsTemplate", "Datacenter", "Cluster", "Folder", "ProvisionedDisk", "InitialVcpus", "InitialRam", "SrmPlaceholder", "PoweredOn"
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid
|
|
`
|
|
|
|
type CreateInventoryParams struct {
|
|
Name string
|
|
Vcenter string
|
|
VmId sql.NullString
|
|
VmUuid sql.NullString
|
|
EventKey sql.NullString
|
|
CloudId sql.NullString
|
|
CreationTime sql.NullInt64
|
|
ResourcePool sql.NullString
|
|
VmType sql.NullString
|
|
IsTemplate interface{}
|
|
Datacenter sql.NullString
|
|
Cluster sql.NullString
|
|
Folder sql.NullString
|
|
ProvisionedDisk sql.NullFloat64
|
|
InitialVcpus sql.NullInt64
|
|
InitialRam sql.NullInt64
|
|
SrmPlaceholder interface{}
|
|
PoweredOn interface{}
|
|
}
|
|
|
|
func (q *Queries) CreateInventory(ctx context.Context, arg CreateInventoryParams) (Inventory, error) {
|
|
row := q.db.QueryRowContext(ctx, createInventory,
|
|
arg.Name,
|
|
arg.Vcenter,
|
|
arg.VmId,
|
|
arg.VmUuid,
|
|
arg.EventKey,
|
|
arg.CloudId,
|
|
arg.CreationTime,
|
|
arg.ResourcePool,
|
|
arg.VmType,
|
|
arg.IsTemplate,
|
|
arg.Datacenter,
|
|
arg.Cluster,
|
|
arg.Folder,
|
|
arg.ProvisionedDisk,
|
|
arg.InitialVcpus,
|
|
arg.InitialRam,
|
|
arg.SrmPlaceholder,
|
|
arg.PoweredOn,
|
|
)
|
|
var i Inventory
|
|
err := row.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createInventoryHistory = `-- name: CreateInventoryHistory :one
|
|
INSERT INTO "InventoryHistory" (
|
|
"InventoryId", "ReportDate", "UpdateTime", "PreviousVcpus", "PreviousRam", "PreviousResourcePool", "PreviousProvisionedDisk"
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
RETURNING Hid, InventoryId, ReportDate, UpdateTime, PreviousVcpus, PreviousRam, PreviousResourcePool, PreviousProvisionedDisk
|
|
`
|
|
|
|
type CreateInventoryHistoryParams struct {
|
|
InventoryId sql.NullInt64
|
|
ReportDate sql.NullInt64
|
|
UpdateTime sql.NullInt64
|
|
PreviousVcpus sql.NullInt64
|
|
PreviousRam sql.NullInt64
|
|
PreviousResourcePool sql.NullString
|
|
PreviousProvisionedDisk sql.NullFloat64
|
|
}
|
|
|
|
func (q *Queries) CreateInventoryHistory(ctx context.Context, arg CreateInventoryHistoryParams) (InventoryHistory, error) {
|
|
row := q.db.QueryRowContext(ctx, createInventoryHistory,
|
|
arg.InventoryId,
|
|
arg.ReportDate,
|
|
arg.UpdateTime,
|
|
arg.PreviousVcpus,
|
|
arg.PreviousRam,
|
|
arg.PreviousResourcePool,
|
|
arg.PreviousProvisionedDisk,
|
|
)
|
|
var i InventoryHistory
|
|
err := row.Scan(
|
|
&i.Hid,
|
|
&i.InventoryId,
|
|
&i.ReportDate,
|
|
&i.UpdateTime,
|
|
&i.PreviousVcpus,
|
|
&i.PreviousRam,
|
|
&i.PreviousResourcePool,
|
|
&i.PreviousProvisionedDisk,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createUpdate = `-- name: CreateUpdate :one
|
|
INSERT INTO "Updates" (
|
|
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName"
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName
|
|
`
|
|
|
|
type CreateUpdateParams struct {
|
|
InventoryId sql.NullInt64
|
|
EventKey sql.NullString
|
|
EventId sql.NullString
|
|
UpdateTime sql.NullInt64
|
|
UpdateType string
|
|
NewVcpus sql.NullInt64
|
|
NewRam sql.NullInt64
|
|
NewResourcePool sql.NullString
|
|
NewProvisionedDisk sql.NullFloat64
|
|
UserName sql.NullString
|
|
}
|
|
|
|
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
|
|
row := q.db.QueryRowContext(ctx, createUpdate,
|
|
arg.InventoryId,
|
|
arg.EventKey,
|
|
arg.EventId,
|
|
arg.UpdateTime,
|
|
arg.UpdateType,
|
|
arg.NewVcpus,
|
|
arg.NewRam,
|
|
arg.NewResourcePool,
|
|
arg.NewProvisionedDisk,
|
|
arg.UserName,
|
|
)
|
|
var i Updates
|
|
err := row.Scan(
|
|
&i.Uid,
|
|
&i.InventoryId,
|
|
&i.UpdateTime,
|
|
&i.UpdateType,
|
|
&i.NewVcpus,
|
|
&i.NewRam,
|
|
&i.NewResourcePool,
|
|
&i.EventKey,
|
|
&i.EventId,
|
|
&i.NewProvisionedDisk,
|
|
&i.UserName,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getInventoryByName = `-- name: GetInventoryByName :many
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
WHERE "Name" = ?
|
|
`
|
|
|
|
func (q *Queries) GetInventoryByName(ctx context.Context, name string) ([]Inventory, error) {
|
|
rows, err := q.db.QueryContext(ctx, getInventoryByName, name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Inventory
|
|
for rows.Next() {
|
|
var i Inventory
|
|
if err := rows.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInventoryByVcenter = `-- name: GetInventoryByVcenter :many
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
WHERE "Vcenter" = ?
|
|
`
|
|
|
|
func (q *Queries) GetInventoryByVcenter(ctx context.Context, vcenter string) ([]Inventory, error) {
|
|
rows, err := q.db.QueryContext(ctx, getInventoryByVcenter, vcenter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Inventory
|
|
for rows.Next() {
|
|
var i Inventory
|
|
if err := rows.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInventoryEventId = `-- name: GetInventoryEventId :one
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
WHERE "CloudId" = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetInventoryEventId(ctx context.Context, cloudid sql.NullString) (Inventory, error) {
|
|
row := q.db.QueryRowContext(ctx, getInventoryEventId, cloudid)
|
|
var i Inventory
|
|
err := row.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getInventoryVcUrl = `-- name: GetInventoryVcUrl :many
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
WHERE "Vcenter" = ?1
|
|
`
|
|
|
|
func (q *Queries) GetInventoryVcUrl(ctx context.Context, vc string) ([]Inventory, error) {
|
|
rows, err := q.db.QueryContext(ctx, getInventoryVcUrl, vc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Inventory
|
|
for rows.Next() {
|
|
var i Inventory
|
|
if err := rows.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInventoryVmId = `-- name: GetInventoryVmId :one
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
WHERE "VmId" = ?1 AND "Datacenter" = ?2
|
|
`
|
|
|
|
type GetInventoryVmIdParams struct {
|
|
VmId sql.NullString
|
|
DatacenterName sql.NullString
|
|
}
|
|
|
|
func (q *Queries) GetInventoryVmId(ctx context.Context, arg GetInventoryVmIdParams) (Inventory, error) {
|
|
row := q.db.QueryRowContext(ctx, getInventoryVmId, arg.VmId, arg.DatacenterName)
|
|
var i Inventory
|
|
err := row.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getInventoryVmUuid = `-- name: GetInventoryVmUuid :one
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
WHERE "VmUuid" = ?1 AND "Datacenter" = ?2
|
|
`
|
|
|
|
type GetInventoryVmUuidParams struct {
|
|
VmUuid sql.NullString
|
|
DatacenterName sql.NullString
|
|
}
|
|
|
|
func (q *Queries) GetInventoryVmUuid(ctx context.Context, arg GetInventoryVmUuidParams) (Inventory, error) {
|
|
row := q.db.QueryRowContext(ctx, getInventoryVmUuid, arg.VmUuid, arg.DatacenterName)
|
|
var i Inventory
|
|
err := row.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getReportInventory = `-- name: GetReportInventory :many
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
ORDER BY "CreationTime"
|
|
`
|
|
|
|
func (q *Queries) GetReportInventory(ctx context.Context) ([]Inventory, error) {
|
|
rows, err := q.db.QueryContext(ctx, getReportInventory)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Inventory
|
|
for rows.Next() {
|
|
var i Inventory
|
|
if err := rows.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getReportUpdates = `-- name: GetReportUpdates :many
|
|
SELECT Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName FROM "Updates"
|
|
ORDER BY "UpdateTime"
|
|
`
|
|
|
|
func (q *Queries) GetReportUpdates(ctx context.Context) ([]Updates, error) {
|
|
rows, err := q.db.QueryContext(ctx, getReportUpdates)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Updates
|
|
for rows.Next() {
|
|
var i Updates
|
|
if err := rows.Scan(
|
|
&i.Uid,
|
|
&i.InventoryId,
|
|
&i.UpdateTime,
|
|
&i.UpdateType,
|
|
&i.NewVcpus,
|
|
&i.NewRam,
|
|
&i.NewResourcePool,
|
|
&i.EventKey,
|
|
&i.EventId,
|
|
&i.NewProvisionedDisk,
|
|
&i.UserName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const inventoryCleanup = `-- name: InventoryCleanup :exec
|
|
DELETE FROM "Inventory"
|
|
WHERE "VmId" = ?1 AND "Datacenter" = ?2
|
|
RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid
|
|
`
|
|
|
|
type InventoryCleanupParams struct {
|
|
VmId sql.NullString
|
|
DatacenterName sql.NullString
|
|
}
|
|
|
|
func (q *Queries) InventoryCleanup(ctx context.Context, arg InventoryCleanupParams) error {
|
|
_, err := q.db.ExecContext(ctx, inventoryCleanup, arg.VmId, arg.DatacenterName)
|
|
return err
|
|
}
|
|
|
|
const inventoryCleanupVcenter = `-- name: InventoryCleanupVcenter :exec
|
|
DELETE FROM "Inventory"
|
|
WHERE "Vcenter" = ?1
|
|
RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid
|
|
`
|
|
|
|
func (q *Queries) InventoryCleanupVcenter(ctx context.Context, vc string) error {
|
|
_, err := q.db.ExecContext(ctx, inventoryCleanupVcenter, vc)
|
|
return err
|
|
}
|
|
|
|
const inventoryMarkDeleted = `-- name: InventoryMarkDeleted :exec
|
|
UPDATE "Inventory"
|
|
SET "DeletionTime" = ?1
|
|
WHERE "VmId" = ?2 AND "Datacenter" = ?3
|
|
`
|
|
|
|
type InventoryMarkDeletedParams struct {
|
|
DeletionTime sql.NullInt64
|
|
VmId sql.NullString
|
|
DatacenterName sql.NullString
|
|
}
|
|
|
|
func (q *Queries) InventoryMarkDeleted(ctx context.Context, arg InventoryMarkDeletedParams) error {
|
|
_, err := q.db.ExecContext(ctx, inventoryMarkDeleted, arg.DeletionTime, arg.VmId, arg.DatacenterName)
|
|
return err
|
|
}
|
|
|
|
const inventoryUpdate = `-- name: InventoryUpdate :exec
|
|
UPDATE "Inventory"
|
|
SET "VmUuid" = ?1, "SrmPlaceholder" = ?2
|
|
WHERE "Iid" = ?3
|
|
`
|
|
|
|
type InventoryUpdateParams struct {
|
|
Uuid sql.NullString
|
|
SrmPlaceholder interface{}
|
|
Iid int64
|
|
}
|
|
|
|
func (q *Queries) InventoryUpdate(ctx context.Context, arg InventoryUpdateParams) error {
|
|
_, err := q.db.ExecContext(ctx, inventoryUpdate, arg.Uuid, arg.SrmPlaceholder, arg.Iid)
|
|
return err
|
|
}
|
|
|
|
const listEvents = `-- name: ListEvents :many
|
|
SELECT Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType FROM "Events"
|
|
ORDER BY "EventTime"
|
|
`
|
|
|
|
func (q *Queries) ListEvents(ctx context.Context) ([]Events, error) {
|
|
rows, err := q.db.QueryContext(ctx, listEvents)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Events
|
|
for rows.Next() {
|
|
var i Events
|
|
if err := rows.Scan(
|
|
&i.Eid,
|
|
&i.CloudId,
|
|
&i.Source,
|
|
&i.EventTime,
|
|
&i.ChainId,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.DatacenterName,
|
|
&i.ComputeResourceName,
|
|
&i.UserName,
|
|
&i.Processed,
|
|
&i.DatacenterId,
|
|
&i.ComputeResourceId,
|
|
&i.VmName,
|
|
&i.EventType,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listInventory = `-- name: ListInventory :many
|
|
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid FROM "Inventory"
|
|
ORDER BY "Name"
|
|
`
|
|
|
|
func (q *Queries) ListInventory(ctx context.Context) ([]Inventory, error) {
|
|
rows, err := q.db.QueryContext(ctx, listInventory)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Inventory
|
|
for rows.Next() {
|
|
var i Inventory
|
|
if err := rows.Scan(
|
|
&i.Iid,
|
|
&i.Name,
|
|
&i.Vcenter,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.CloudId,
|
|
&i.CreationTime,
|
|
&i.DeletionTime,
|
|
&i.ResourcePool,
|
|
&i.VmType,
|
|
&i.Datacenter,
|
|
&i.Cluster,
|
|
&i.Folder,
|
|
&i.ProvisionedDisk,
|
|
&i.InitialVcpus,
|
|
&i.InitialRam,
|
|
&i.IsTemplate,
|
|
&i.PoweredOn,
|
|
&i.SrmPlaceholder,
|
|
&i.VmUuid,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listUnprocessedEvents = `-- name: ListUnprocessedEvents :many
|
|
SELECT Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType FROM "Events"
|
|
WHERE "Processed" = 0
|
|
AND "EventTime" > ?1
|
|
ORDER BY "EventTime"
|
|
`
|
|
|
|
func (q *Queries) ListUnprocessedEvents(ctx context.Context, eventtime sql.NullInt64) ([]Events, error) {
|
|
rows, err := q.db.QueryContext(ctx, listUnprocessedEvents, eventtime)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Events
|
|
for rows.Next() {
|
|
var i Events
|
|
if err := rows.Scan(
|
|
&i.Eid,
|
|
&i.CloudId,
|
|
&i.Source,
|
|
&i.EventTime,
|
|
&i.ChainId,
|
|
&i.VmId,
|
|
&i.EventKey,
|
|
&i.DatacenterName,
|
|
&i.ComputeResourceName,
|
|
&i.UserName,
|
|
&i.Processed,
|
|
&i.DatacenterId,
|
|
&i.ComputeResourceId,
|
|
&i.VmName,
|
|
&i.EventType,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateEventsProcessed = `-- name: UpdateEventsProcessed :exec
|
|
UPDATE "Events"
|
|
SET "Processed" = 1
|
|
WHERE "Eid" = ?1
|
|
`
|
|
|
|
func (q *Queries) UpdateEventsProcessed(ctx context.Context, eid int64) error {
|
|
_, err := q.db.ExecContext(ctx, updateEventsProcessed, eid)
|
|
return err
|
|
}
|