Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/docs/devops/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ The root object of the configuration file is the environment object, which conta
| CATALOG_COMPRESS_VM_RATIO | The ratio that will be used to determine whether the virtual machine should be compressed best_speed/balanced/best_compression/no_compression | best_compression |
| CATALOG_ENABLE_PROVIDER_CREDENTIALS_OBFUSCATION | Specifies whether the provider credentials in the catalog should be obfuscated | true |
| VIRTUAL_MACHINES_FOLDER | The folder where the virtual machines will be stored | users/`<username>`/Parallels |
| PARALLELS_DESKTOP_REFRESH_INTERVAL | The interval in seconds that the service will refresh the Parallels Desktop virtual machines in seconds | 15 seconds |
| SYSTEM_RESERVED_CPU | The number of cpu cores that will be reserved for the system and not used for Orchestrator | 1 |
| SYSTEM_RESERVED_MEMORY | The amount of memory that will be reserved for the system and not used for Orchestrator in Mb's | 2048 |
| SYSTEM_RESERVED_DISK | The amount of disk space that will be reserved for the system and not used for Orchestrator in Mb's | 20000 |
Expand Down
3 changes: 1 addition & 2 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ github.com/cjlapao/common-go-identity v0.0.3/go.mod h1:xuNepNCHVI/51Q6DQgNPYvx3H
github.com/cjlapao/common-go-logger v0.0.9 h1:ZFUs0tVOn7KydxOnDSPtz3TvksaOPiNxlRT2VcMQTLs=
github.com/cjlapao/common-go-logger v0.0.9/go.mod h1:Ao96R8kuUfeTFY4lAhRFfTpnlb8F5eO7aThI5nzCTzA=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/go-jose/go-jose/v4 v4.0.1/go.mod h1:WVf9LFMHh/QVrmqrOfqun0C45tMe3RoiKJMPvgWwLfY=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
Expand All @@ -17,8 +18,6 @@ github.com/pascaldekloe/jwt v1.12.0/go.mod h1:LiIl7EwaglmH1hWThd/AmydNCnHf/mmflu
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
4 changes: 2 additions & 2 deletions src/catalog/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (s *CatalogManifestService) renameMachineWithParallelsDesktop(r *models.Pul
if !response.HasErrors() {
s.ns.NotifyInfof("Renaming machine %v to %v", r.MachineName, r.MachineName)
filter := fmt.Sprintf("name=%s", r.MachineName)
vms, err := parallelsDesktopSvc.GetVmsSync(s.ctx, filter)
vms, err := parallelsDesktopSvc.GetCachedVms(s.ctx, filter)
if err != nil {
s.ns.NotifyErrorf("Error getting machine %v: %v", r.MachineName, err)
response.AddError(err)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (s *CatalogManifestService) startMachineWithParallelsDesktop(r *models.Pull

if !response.HasErrors() {
filter := fmt.Sprintf("name=%s", r.MachineName)
vms, err := parallelsDesktopSvc.GetVmsSync(s.ctx, filter)
vms, err := parallelsDesktopSvc.GetCachedVms(s.ctx, filter)
if err != nil {
s.ns.NotifyErrorf("Error getting machine %v: %v", r.MachineName, err)
response.AddError(err)
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ func processApi(ctx basecontext.ApiContext, cmd string) {
os.Exit(0)
}

cfg := config.Get()
_ = os.Setenv(constants.SOURCE_ENV_VAR, "api")
if cfg.Mode() == "" {
_ = os.Setenv(constants.MODE_ENV_VAR, "api")
}

versionSvc.PrintAnsiHeader()
processTelemetry(cmd)
startup.Init(ctx)

startup.Start(ctx)
cfg := config.Get()

if cfg.EncryptionPrivateKey() == "" {
common.Logger.Warn("No security key found, database will be unencrypted")
Expand Down
9 changes: 0 additions & 9 deletions src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,6 @@ func (c *Config) DbSaveInterval() time.Duration {
return time.Duration(interval) * time.Minute
}

func (c *Config) ParallelsRefreshInterval() time.Duration {
interval := c.GetIntKey(constants.PARALLELS_DESKTOP_REFRESH_INTERVAL_ENV_VAR)
if interval == 0 {
return 20 * time.Second
}

return time.Duration(interval) * time.Second
}

func (c *Config) RootFolder() (string, error) {
ctx := basecontext.NewRootBaseContext()
srv := system.Get()
Expand Down
1 change: 0 additions & 1 deletion src/constants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const (
ENABLE_VAGRANT_PLUGIN_ENV_VAR = "ENABLE_VAGRANT_PLUGIN"
ENABLE_CORS_ENV_VAR = "ENABLE_CORS"
VIRTUAL_MACHINES_FOLDER_ENV_VAR = "VIRTUAL_MACHINES_FOLDER"
PARALLELS_DESKTOP_REFRESH_INTERVAL_ENV_VAR = "PARALLELS_DESKTOP_REFRESH_INTERVAL"
SYSTEM_RESERVED_CPU_ENV_VAR = "SYSTEM_RESERVED_CPU"
SYSTEM_RESERVED_MEMORY_ENV_VAR = "SYSTEM_RESERVED_MEMORY"
SYSTEM_RESERVED_DISK_ENV_VAR = "SYSTEM_RESERVED_DISK"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ func RegisterVirtualMachineHandler() restapi.ControllerHandler {
}

filter := fmt.Sprintf("Home=%s/,i", request.Path)
vms, err := svc.GetVmsSync(ctx, filter)
vms, err := svc.GetCachedVms(ctx, filter)
if err != nil {
ReturnApiError(ctx, w, models.NewFromError(err))
return
Expand Down
1 change: 1 addition & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/creack/pty v1.1.24 // indirect
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ github.com/cjlapao/common-go-logger v0.0.10/go.mod h1:HTmIKmw8K7eLY5WsoI4fLLNiFG
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/cyphar/filepath-securejoin v0.3.6 h1:4d9N5ykBnSp5Xn2JkhocYDkOpURL/18CYMpo6xB9uWM=
github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
12 changes: 12 additions & 0 deletions src/models/parallels_service_events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package models

type AdditionalInfo struct {
VmStateName string `json:"Vm state name"`
}

type ParallelsServiceEvent struct {
Timestamp string `json:"Timestamp"`
VMID string `json:"VM ID"`
EventName string `json:"Event name"`
AdditionalInfo *AdditionalInfo `json:"Additional info,omitempty"`
}
33 changes: 33 additions & 0 deletions src/processlauncher/processlauncher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package processlauncher

import (
"os"
"os/exec"

"github.com/creack/pty"
)

type ProcessLauncher interface {
Start(cmd *exec.Cmd) (*os.File, error)
}

// RealProcessLauncher implements ProcessLauncher using pty.Start.
type RealProcessLauncher struct{}

func (r *RealProcessLauncher) Start(cmd *exec.Cmd) (*os.File, error) {
return pty.Start(cmd)
}

// MockProcessLauncher is a mock implementation of ProcessLauncher for testing purposes.
// It allows injecting custom behavior via the LaunchFunc field to simulate different scenarios without actual PTY dependencies.
type MockProcessLauncher struct {
LaunchFunc func(cmd *exec.Cmd) (*os.File, error)
}

func (m *MockProcessLauncher) Start(cmd *exec.Cmd) (*os.File, error) {
if m.LaunchFunc != nil {
return m.LaunchFunc(cmd)
}
// Default behavior: return nil if no function is set (can be customized for tests).
return nil, nil
}
63 changes: 63 additions & 0 deletions src/processlauncher/processlauncher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package processlauncher

import (
"bufio"
"io"
"os"
"os/exec"
"strings"
"testing"
)

func TestMockProcessLauncher(t *testing.T) {
// Create a temporary pipe to simulate stdout
r, w, _ := os.Pipe()
w.WriteString("test output")
w.Close()

mock := &MockProcessLauncher{
LaunchFunc: func(cmd *exec.Cmd) (*os.File, error) {
// Simulate successful launch by returning a file with some test data.
return r, nil
},
}

cmd := exec.Command("echo", "hello")
file, err := mock.Start(cmd)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
defer file.Close()

// Read from the returned file to verify content
reader := bufio.NewReader(file)
output, err := reader.ReadString('\n')
if err != nil && err != io.EOF {
t.Fatalf("Expected no error reading from file, got %v", err)
}

if strings.TrimSpace(output) != "test output" {
t.Fatalf("Expected 'test output', got '%s'", output)
}
}

func TestRealProcessLauncher(t *testing.T) {
real := &RealProcessLauncher{}
cmd := exec.Command("echo", "hello")
file, err := real.Start(cmd)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
defer file.Close()

// Read from the returned file to verify content
reader := bufio.NewReader(file)
output, err := reader.ReadString('\n')
if err != nil && err != io.EOF {
t.Fatalf("Expected no error reading from file, got %v", err)
}

if strings.TrimSpace(output) != "hello" {
t.Fatalf("Expected 'hello', got '%s'", output)
}
}
2 changes: 1 addition & 1 deletion src/serviceprovider/parallelsdesktop/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *ParallelsService) findVm(ctx basecontext.ApiContext, idOrName string) (
}

func (s *ParallelsService) findVmSync(ctx basecontext.ApiContext, idOrName string) (*models.ParallelsVM, error) {
vms, err := s.GetVmsSync(ctx, "")
vms, err := s.GetCachedVms(ctx, "")
if err != nil {
return nil, err
}
Expand Down
Loading
Loading