All checks were successful
continuous-integration/drone/push Build is passing
900 lines
25 KiB
Go
900 lines
25 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.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, PlaceholderChange, Name, RawChangeString
|
|
`
|
|
|
|
type CleanupUpdatesParams struct {
|
|
UpdateType string `db:"updateType" json:"updateType"`
|
|
UpdateTime sql.NullInt64 `db:"updateTime" json:"updateTime"`
|
|
}
|
|
|
|
func (q *Queries) CleanupUpdates(ctx context.Context, arg CleanupUpdatesParams) error {
|
|
_, err := q.db.ExecContext(ctx, cleanupUpdates, arg.UpdateType, arg.UpdateTime)
|
|
return err
|
|
}
|
|
|
|
const cleanupUpdatesNullVm = `-- name: CleanupUpdatesNullVm :exec
|
|
DELETE FROM updates
|
|
WHERE "InventoryId" IS NULL
|
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString
|
|
`
|
|
|
|
func (q *Queries) CleanupUpdatesNullVm(ctx context.Context) error {
|
|
_, err := q.db.ExecContext(ctx, cleanupUpdatesNullVm)
|
|
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 `db:"CloudId" json:"CloudId"`
|
|
Source string `db:"Source" json:"Source"`
|
|
EventTime sql.NullInt64 `db:"EventTime" json:"EventTime"`
|
|
ChainId string `db:"ChainId" json:"ChainId"`
|
|
VmId sql.NullString `db:"VmId" json:"VmId"`
|
|
VmName sql.NullString `db:"VmName" json:"VmName"`
|
|
EventType sql.NullString `db:"EventType" json:"EventType"`
|
|
EventKey sql.NullString `db:"EventKey" json:"EventKey"`
|
|
DatacenterId sql.NullString `db:"DatacenterId" json:"DatacenterId"`
|
|
DatacenterName sql.NullString `db:"DatacenterName" json:"DatacenterName"`
|
|
ComputeResourceId sql.NullString `db:"ComputeResourceId" json:"ComputeResourceId"`
|
|
ComputeResourceName sql.NullString `db:"ComputeResourceName" json:"ComputeResourceName"`
|
|
UserName sql.NullString `db:"UserName" json:"UserName"`
|
|
}
|
|
|
|
func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Event, 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 Event
|
|
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 `db:"Name" json:"Name"`
|
|
Vcenter string `db:"Vcenter" json:"Vcenter"`
|
|
VmId sql.NullString `db:"VmId" json:"VmId"`
|
|
VmUuid sql.NullString `db:"VmUuid" json:"VmUuid"`
|
|
EventKey sql.NullString `db:"EventKey" json:"EventKey"`
|
|
CloudId sql.NullString `db:"CloudId" json:"CloudId"`
|
|
CreationTime sql.NullInt64 `db:"CreationTime" json:"CreationTime"`
|
|
ResourcePool sql.NullString `db:"ResourcePool" json:"ResourcePool"`
|
|
VmType sql.NullString `db:"VmType" json:"VmType"`
|
|
IsTemplate interface{} `db:"IsTemplate" json:"IsTemplate"`
|
|
Datacenter sql.NullString `db:"Datacenter" json:"Datacenter"`
|
|
Cluster sql.NullString `db:"Cluster" json:"Cluster"`
|
|
Folder sql.NullString `db:"Folder" json:"Folder"`
|
|
ProvisionedDisk sql.NullFloat64 `db:"ProvisionedDisk" json:"ProvisionedDisk"`
|
|
InitialVcpus sql.NullInt64 `db:"InitialVcpus" json:"InitialVcpus"`
|
|
InitialRam sql.NullInt64 `db:"InitialRam" json:"InitialRam"`
|
|
SrmPlaceholder interface{} `db:"SrmPlaceholder" json:"SrmPlaceholder"`
|
|
PoweredOn interface{} `db:"PoweredOn" json:"PoweredOn"`
|
|
}
|
|
|
|
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 inventory_history (
|
|
"InventoryId", "ReportDate", "UpdateTime", "PreviousVcpus", "PreviousRam", "PreviousResourcePool", "PreviousProvisionedDisk"
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
RETURNING Hid, InventoryId, ReportDate, UpdateTime, PreviousVcpus, PreviousRam, PreviousResourcePool, PreviousProvisionedDisk
|
|
`
|
|
|
|
type CreateInventoryHistoryParams struct {
|
|
InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"`
|
|
ReportDate sql.NullInt64 `db:"ReportDate" json:"ReportDate"`
|
|
UpdateTime sql.NullInt64 `db:"UpdateTime" json:"UpdateTime"`
|
|
PreviousVcpus sql.NullInt64 `db:"PreviousVcpus" json:"PreviousVcpus"`
|
|
PreviousRam sql.NullInt64 `db:"PreviousRam" json:"PreviousRam"`
|
|
PreviousResourcePool sql.NullString `db:"PreviousResourcePool" json:"PreviousResourcePool"`
|
|
PreviousProvisionedDisk sql.NullFloat64 `db:"PreviousProvisionedDisk" json:"PreviousProvisionedDisk"`
|
|
}
|
|
|
|
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", "Name", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange", "RawChangeString"
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString
|
|
`
|
|
|
|
type CreateUpdateParams struct {
|
|
InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"`
|
|
Name sql.NullString `db:"Name" json:"Name"`
|
|
EventKey sql.NullString `db:"EventKey" json:"EventKey"`
|
|
EventId sql.NullString `db:"EventId" json:"EventId"`
|
|
UpdateTime sql.NullInt64 `db:"UpdateTime" json:"UpdateTime"`
|
|
UpdateType string `db:"UpdateType" json:"UpdateType"`
|
|
NewVcpus sql.NullInt64 `db:"NewVcpus" json:"NewVcpus"`
|
|
NewRam sql.NullInt64 `db:"NewRam" json:"NewRam"`
|
|
NewResourcePool sql.NullString `db:"NewResourcePool" json:"NewResourcePool"`
|
|
NewProvisionedDisk sql.NullFloat64 `db:"NewProvisionedDisk" json:"NewProvisionedDisk"`
|
|
UserName sql.NullString `db:"UserName" json:"UserName"`
|
|
PlaceholderChange sql.NullString `db:"PlaceholderChange" json:"PlaceholderChange"`
|
|
RawChangeString []byte `db:"RawChangeString" json:"RawChangeString"`
|
|
}
|
|
|
|
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Update, error) {
|
|
row := q.db.QueryRowContext(ctx, createUpdate,
|
|
arg.InventoryId,
|
|
arg.Name,
|
|
arg.EventKey,
|
|
arg.EventId,
|
|
arg.UpdateTime,
|
|
arg.UpdateType,
|
|
arg.NewVcpus,
|
|
arg.NewRam,
|
|
arg.NewResourcePool,
|
|
arg.NewProvisionedDisk,
|
|
arg.UserName,
|
|
arg.PlaceholderChange,
|
|
arg.RawChangeString,
|
|
)
|
|
var i Update
|
|
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,
|
|
&i.PlaceholderChange,
|
|
&i.Name,
|
|
&i.RawChangeString,
|
|
)
|
|
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 `db:"vmId" json:"vmId"`
|
|
DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"`
|
|
}
|
|
|
|
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 `db:"vmUuid" json:"vmUuid"`
|
|
DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"`
|
|
}
|
|
|
|
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, PlaceholderChange, Name, RawChangeString FROM updates
|
|
ORDER BY "UpdateTime"
|
|
`
|
|
|
|
func (q *Queries) GetReportUpdates(ctx context.Context) ([]Update, error) {
|
|
rows, err := q.db.QueryContext(ctx, getReportUpdates)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Update
|
|
for rows.Next() {
|
|
var i Update
|
|
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,
|
|
&i.PlaceholderChange,
|
|
&i.Name,
|
|
&i.RawChangeString,
|
|
); 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 getVmUpdates = `-- name: GetVmUpdates :many
|
|
SELECT Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString FROM updates
|
|
WHERE "UpdateType" = ?1 AND "InventoryId" = ?2
|
|
`
|
|
|
|
type GetVmUpdatesParams struct {
|
|
UpdateType string `db:"updateType" json:"updateType"`
|
|
InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"`
|
|
}
|
|
|
|
func (q *Queries) GetVmUpdates(ctx context.Context, arg GetVmUpdatesParams) ([]Update, error) {
|
|
rows, err := q.db.QueryContext(ctx, getVmUpdates, arg.UpdateType, arg.InventoryId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Update
|
|
for rows.Next() {
|
|
var i Update
|
|
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,
|
|
&i.PlaceholderChange,
|
|
&i.Name,
|
|
&i.RawChangeString,
|
|
); 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 `db:"vmId" json:"vmId"`
|
|
DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"`
|
|
}
|
|
|
|
func (q *Queries) InventoryCleanup(ctx context.Context, arg InventoryCleanupParams) error {
|
|
_, err := q.db.ExecContext(ctx, inventoryCleanup, arg.VmId, arg.DatacenterName)
|
|
return err
|
|
}
|
|
|
|
const inventoryCleanupTemplates = `-- name: InventoryCleanupTemplates :exec
|
|
DELETE FROM inventory
|
|
WHERE "IsTemplate" = 'TRUE'
|
|
RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, IsTemplate, PoweredOn, SrmPlaceholder, VmUuid
|
|
`
|
|
|
|
func (q *Queries) InventoryCleanupTemplates(ctx context.Context) error {
|
|
_, err := q.db.ExecContext(ctx, inventoryCleanupTemplates)
|
|
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 `db:"deletionTime" json:"deletionTime"`
|
|
VmId sql.NullString `db:"vmId" json:"vmId"`
|
|
DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"`
|
|
}
|
|
|
|
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 `db:"uuid" json:"uuid"`
|
|
SrmPlaceholder interface{} `db:"srmPlaceholder" json:"srmPlaceholder"`
|
|
Iid int64 `db:"iid" json:"iid"`
|
|
}
|
|
|
|
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) ([]Event, error) {
|
|
rows, err := q.db.QueryContext(ctx, listEvents)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Event
|
|
for rows.Next() {
|
|
var i Event
|
|
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) ([]Event, error) {
|
|
rows, err := q.db.QueryContext(ctx, listUnprocessedEvents, eventtime)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Event
|
|
for rows.Next() {
|
|
var i Event
|
|
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
|
|
}
|