Skip to content

Commit

Permalink
Return VM Type instead of bool
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel committed Sep 17, 2024
1 parent f690f34 commit 246e547
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions v3/services/vmsvc/internal/vmservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"

hfv1 "github.com/hobbyfarm/gargantua/v3/pkg/apis/hobbyfarm.io/v1"
hferrors "github.com/hobbyfarm/gargantua/v3/pkg/errors"
hflabels "github.com/hobbyfarm/gargantua/v3/pkg/labels"
"github.com/hobbyfarm/gargantua/v3/pkg/rbac"
Expand All @@ -24,25 +25,25 @@ const (
)

type PreparedVirtualMachine struct {
Id string `json:"id"`
VirtualMachineTemplateId string `json:"vm_template_id"`
SshUsername string `json:"ssh_username"`
Protocol string `json:"protocol"`
SecretName string `json:"secret_name"` // this refers to the secret name for the keypair
VirtualMachineClaimId string `json:"vm_claim_id"`
UserId string `json:"user"`
Provision bool `json:"provision"`
VirtualMachineSetId string `json:"vm_set_id"`
Status string `json:"status"` // default is nothing, but could be one of the following: readyforprovisioning, provisioning, running, terminating
Allocated bool `json:"allocated"`
Tainted bool `json:"tainted"`
PublicIP string `json:"public_ip"`
PrivateIP string `json:"private_ip"`
EnvironmentId string `json:"environment_id"`
Hostname string `json:"hostname"` // ideally <hostname>.<enviroment dnssuffix> should be the FQDN to this machine
TFState string `json:"tfstate,omitempty"` // Terraform state name
WsEndpoint string `json:"ws_endpoint"`
IsShared bool `json:"is_shared"`
Id string `json:"id"`
VirtualMachineTemplateId string `json:"vm_template_id"`
SshUsername string `json:"ssh_username"`
Protocol string `json:"protocol"`
SecretName string `json:"secret_name"` // this refers to the secret name for the keypair
VirtualMachineClaimId string `json:"vm_claim_id"`
UserId string `json:"user"`
Provision bool `json:"provision"`
VirtualMachineSetId string `json:"vm_set_id"`
Status string `json:"status"` // default is nothing, but could be one of the following: readyforprovisioning, provisioning, running, terminating
Allocated bool `json:"allocated"`
Tainted bool `json:"tainted"`
PublicIP string `json:"public_ip"`
PrivateIP string `json:"private_ip"`
EnvironmentId string `json:"environment_id"`
Hostname string `json:"hostname"` // ideally <hostname>.<enviroment dnssuffix> should be the FQDN to this machine
TFState string `json:"tfstate,omitempty"` // Terraform state name
WsEndpoint string `json:"ws_endpoint"`
VirtualMachineType hfv1.VirtualMachineType `json:"vm_type"`
}

/*
Expand Down Expand Up @@ -258,7 +259,7 @@ func (vms VMServer) GetAllVMListFunc(w http.ResponseWriter, r *http.Request) {
}

func (vms VMServer) GetSharedVirtualMachinesFunc(w http.ResponseWriter, r *http.Request) {
// Check if User has access to VMs
// TODO Check if User has access to VMs
_, err := rbac.AuthenticateRequest(r, vms.authnClient)
if err != nil {
util.ReturnHTTPMessage(w, r, 403, "forbidden", "no access to get shared vms")
Expand Down Expand Up @@ -334,6 +335,6 @@ func getPreparedVM(vm *vmpb.VM) PreparedVirtualMachine {
Hostname: vm.GetStatus().GetHostname(),
TFState: vm.GetStatus().GetTfstate(),
WsEndpoint: vm.GetStatus().GetWsEndpoint(),
IsShared: vm.GetVmType() == vmpb.VirtualMachineType_SHARED,
VirtualMachineType: util.ConvertToStringEnum(vm.GetVmType(), vmpb.VirtualMachineType_name, hfv1.VirtualMachineTypeUser),
}
}

0 comments on commit 246e547

Please sign in to comment.