tested real proxmox connection
--> passed
This commit is contained in:
@@ -27,6 +27,8 @@ type ProvisionClientFactory func(cluster.Cluster) (ProvisionProxmoxClient, error
|
||||
|
||||
type ProvisionProxmoxClient interface {
|
||||
CloneVM(ctx context.Context, node string, templateVMID int, newVMID int, name string) (string, error)
|
||||
ConfigureHardware(ctx context.Context, node string, vmid int, cfg proxmox.HardwareConfig) (string, error)
|
||||
ResizeDisk(ctx context.Context, node string, vmid int, disk string, sizeGB int) (string, error)
|
||||
ConfigureCloudInit(ctx context.Context, node string, vmid int, cfg proxmox.CloudInitConfig) (string, error)
|
||||
StartVM(ctx context.Context, node string, vmid int) (string, error)
|
||||
StopVM(ctx context.Context, node string, vmid int) (string, error)
|
||||
@@ -174,15 +176,15 @@ func (h Handler) CreateVM(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
vm, err := h.repository.InsertVM(r.Context(), InsertVMRecord{
|
||||
ProjectID: projectID,
|
||||
ClusterID: template.ClusterID,
|
||||
ProxmoxVMID: vmid,
|
||||
Node: req.Node,
|
||||
Name: req.Name,
|
||||
Status: "provisioning",
|
||||
VCPU: req.VCPU,
|
||||
RAMMB: req.RAMMB,
|
||||
DiskGB: req.DiskGB,
|
||||
ProjectID: projectID,
|
||||
ClusterID: template.ClusterID,
|
||||
ProxmoxVMID: vmid,
|
||||
Node: req.Node,
|
||||
Name: req.Name,
|
||||
Status: "provisioning",
|
||||
VCPU: req.VCPU,
|
||||
RAMMB: req.RAMMB,
|
||||
DiskGB: req.DiskGB,
|
||||
})
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "vm_insert_failed")
|
||||
@@ -211,6 +213,19 @@ func (h Handler) CreateVM(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := proxmoxClient.ConfigureHardware(r.Context(), req.Node, vmid, proxmox.HardwareConfig{
|
||||
Cores: req.VCPU,
|
||||
Memory: req.RAMMB,
|
||||
}); err != nil {
|
||||
writeError(w, http.StatusBadGateway, "proxmox_hardware_failed")
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := proxmoxClient.ResizeDisk(r.Context(), req.Node, vmid, "scsi0", req.DiskGB); err != nil {
|
||||
writeError(w, http.StatusBadGateway, "proxmox_resize_failed")
|
||||
return
|
||||
}
|
||||
|
||||
ciCfg := proxmox.CloudInitConfig{
|
||||
CIUser: req.CIUser,
|
||||
IPConfig0: req.IPConfig0,
|
||||
@@ -273,23 +288,23 @@ func (h Handler) CreateVM(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusAccepted, map[string]any{
|
||||
"vm": vm,
|
||||
"upid": startUPID,
|
||||
"clone_upid": cloneUPID,
|
||||
"status": "provisioning",
|
||||
"vm": vm,
|
||||
"upid": startUPID,
|
||||
"clone_upid": cloneUPID,
|
||||
"status": "provisioning",
|
||||
})
|
||||
}
|
||||
|
||||
type createVMRequest struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"`
|
||||
TemplateID string `json:"template_id"`
|
||||
Node string `json:"node"`
|
||||
VCPU int `json:"vcpu"`
|
||||
RAMMB int `json:"ram_mb"`
|
||||
DiskGB int `json:"disk_gb"`
|
||||
SSHKeyID string `json:"ssh_key_id"`
|
||||
CIUser string `json:"ci_user"`
|
||||
IPConfig0 string `json:"ip_config0"`
|
||||
Node string `json:"node"`
|
||||
VCPU int `json:"vcpu"`
|
||||
RAMMB int `json:"ram_mb"`
|
||||
DiskGB int `json:"disk_gb"`
|
||||
SSHKeyID string `json:"ssh_key_id"`
|
||||
CIUser string `json:"ci_user"`
|
||||
IPConfig0 string `json:"ip_config0"`
|
||||
}
|
||||
|
||||
func DefaultProvisionClientFactory(cluster cluster.Cluster) (ProvisionProxmoxClient, error) {
|
||||
@@ -306,11 +321,11 @@ func NewSQLProvisionAuditWriter(db *sql.DB) SQLProvisionAuditWriter {
|
||||
|
||||
func (w SQLProvisionAuditWriter) WriteVMProvisionAudit(ctx context.Context, event VMProvisionAuditEvent) error {
|
||||
metadata, err := json.Marshal(map[string]any{
|
||||
"cluster_id": event.ClusterID,
|
||||
"template_id": event.TemplateID,
|
||||
"node": event.Node,
|
||||
"upid": event.UPID,
|
||||
"proxmox_vmid": event.ProxmoxVMID,
|
||||
"cluster_id": event.ClusterID,
|
||||
"template_id": event.TemplateID,
|
||||
"node": event.Node,
|
||||
"upid": event.UPID,
|
||||
"proxmox_vmid": event.ProxmoxVMID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -428,4 +443,4 @@ func (h Handler) DeleteVM(w http.ResponseWriter, r *http.Request) {
|
||||
"upid": deleteUPID,
|
||||
"status": "deleting",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user