-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rest: Isolate Code-Hex/vz code from the rest code
Code-Hex/vz requires cgo/native builds, so it's preferrable to separate it from the client rest code. This PR achieves this by introducing interfaces to help move the mac-specific code to a separate package
- Loading branch information
Showing
5 changed files
with
74 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package rest | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/Code-Hex/vz/v3" | ||
"github.com/crc-org/vfkit/pkg/rest/define" | ||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type VzVirtualMachine struct { | ||
VzVM *vz.VirtualMachine | ||
config *vz.VirtualMachineConfiguration | ||
} | ||
|
||
func NewVzVirtualMachine(vm *vz.VirtualMachine, config *vz.VirtualMachineConfiguration) *VzVirtualMachine { | ||
return &VzVirtualMachine{config: config, VzVM: vm} | ||
} | ||
|
||
// inspect returns information about the virtual machine like hw resources | ||
// and devices | ||
func (vm *VzVirtualMachine) Inspect(c *gin.Context) { | ||
ii := define.InspectResponse{ | ||
// TODO complete me | ||
CPUs: 1, | ||
Memory: 2048, | ||
//Devices: vm.Devices, | ||
} | ||
c.JSON(http.StatusOK, ii) | ||
} | ||
|
||
// getVMState retrieves the current vm state | ||
func (vm *VzVirtualMachine) GetVMState(c *gin.Context) { | ||
current := vm.GetState() | ||
c.JSON(http.StatusOK, gin.H{"state": current.String()}) | ||
} | ||
|
||
// setVMState requests a state change on a virtual machine. At this time only | ||
// the following states are valid: | ||
// Pause - pause a running machine | ||
// Resume - resume a paused machine | ||
// Stop - stops a running machine | ||
// HardStop - forceably stops a running machine | ||
func (vm *VzVirtualMachine) SetVMState(c *gin.Context) { | ||
var ( | ||
s define.VMState | ||
) | ||
|
||
if err := c.ShouldBindJSON(&s); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
response := vm.ChangeState(define.StateChange(s.State)) | ||
if response != nil { | ||
logrus.Errorf("failed action %s: %q", s.State, response) | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": response.Error()}) | ||
return | ||
} | ||
c.Status(http.StatusAccepted) | ||
} |
This file was deleted.
Oops, something went wrong.