Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Merge branch 'solo' of https://github.com/vmware/dispatch into solo
Browse files Browse the repository at this point in the history
  • Loading branch information
pzmrzy committed Oct 17, 2018
2 parents 9f2f9de + eaf36de commit a265f9b
Show file tree
Hide file tree
Showing 187 changed files with 103,817 additions and 154 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bin/
*.tar
*.zip
*.ovf
!**/config/*.ovf
*.ova
*.vmdk
*.tgz
Expand Down
46 changes: 45 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@
[[constraint]]
name = "github.com/kubeless/kubeless"
version = "1.0.0-alpha.2"

[[constraint]]
name = "github.com/vmware/govmomi"
version = "0.19.0"
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TAG ?= $(VERSION)


.PHONY: all
all: generate linux darwin
all: generate linux darwin ova

.PHONY: goversion
goversion:
Expand Down Expand Up @@ -119,6 +119,22 @@ cli-darwin:
cli-linux:
GOOS=linux go build -ldflags "$(GO_LDFLAGS) $(CLI_LDFLAGS)" -o bin/$(CLI)-linux ./cmd/$(CLI)

.PHONY: toolbox
toolbox:
GOOS=linux go build -ldflags "$(GO_LDFLAGS) $(CLI_LDFLAGS)" -o bin/toolbox ./cmd/toolbox

.PHONY: rpctool
rpctool:
GOOS=linux go build -ldflags "$(GO_LDFLAGS) $(CLI_LDFLAGS)" -o bin/rpctool ./cmd/rpctool

.PHONY: ovfenv
ovfenv:
GOOS=linux go build -ldflags "$(GO_LDFLAGS) $(CLI_LDFLAGS)" -o bin/ovfenv ./cmd/ovfenv

.PHONY: ova
ova: dispatch-server-linux toolbox rpctool ovfenv ## build an OVA which includes dispatch-server
./scripts/ova/build.sh ova-dev

.PHONY: images
images: linux ci-images

Expand Down
135 changes: 135 additions & 0 deletions cmd/ovfenv/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////

// +build linux,amd64

package main

import (
"flag"
"fmt"
"os"

"github.com/vmware/vmw-guestinfo/rpcvmx"
"github.com/vmware/vmw-guestinfo/vmcheck"

"github.com/vmware/govmomi/ovf"
"github.com/vmware/govmomi/vim25/xml"
)

var (
set string
key string
)

func init() {
flag.StringVar(&set, "set", "", "Set value for OVF property")
flag.StringVar(&key, "key", "", "Work on single OVF property")

flag.Parse()
}

func main() {
if err := run(); err != nil {
fmt.Println(err.Error())
os.Exit(-1)
}
}

func run() error {
// Check if we're running inside a VM
isVM, err := vmcheck.IsVirtualWorld()
if err != nil {
fmt.Printf("error: %s\n", err.Error())
return err
}

// No point in running if we're not inside a VM
if !isVM {
fmt.Println("not living in a virtual world... :(")
return err
}

config := rpcvmx.NewConfig()
var e ovf.Env

if err := fetchovfEnv(config, &e); err != nil {
return err
}

// If set and key are populated, let's set the key to the value passed
if set != "" && key != "" {

var props []ovf.EnvProperty

for _, p := range e.Property.Properties {
if p.Key == key {
props = append(props, ovf.EnvProperty{
Key: p.Key,
Value: set,
})
} else {
props = append(props, ovf.EnvProperty{
Key: p.Key,
Value: p.Value,
})
}
}

env := ovf.Env{
EsxID: e.EsxID,
Platform: &ovf.PlatformSection{
Kind: e.Platform.Kind,
Version: e.Platform.Version,
Vendor: e.Platform.Vendor,
Locale: e.Platform.Locale,
},
Property: &ovf.PropertySection{
Properties: props,
},
}
// Send updated ovfEnv through the rpcvmx channel
if err := config.SetString("guestinfo.ovfEnv", env.MarshalManual()); err != nil {
return err
}
// Refresh ovfEnv
if err := fetchovfEnv(config, &e); err != nil {
return err
}

}

// LET'S HAVE A MAP! SO YOU CAN DO LOOKUPS!
m := make(map[string]string)
for _, v := range e.Property.Properties {
m[v.Key] = v.Value
}

// If a key is all we want...
if key != "" {
fmt.Println(m[key])
return nil
}

// Let's print the whole property list by default
for k, v := range m {
fmt.Printf("[%s]=%s\n", k, v)
}

return nil
}

func fetchovfEnv(config *rpcvmx.Config, e *ovf.Env) error {
ovfEnv, err := config.String("guestinfo.ovfEnv", "")
if err != nil {
return fmt.Errorf("impossible to fetch ovf environment, exiting")
}

if err = xml.Unmarshal([]byte(ovfEnv), &e); err != nil {
return fmt.Errorf("error: %s", err.Error())
}

return nil
}
69 changes: 69 additions & 0 deletions cmd/rpctool/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////

// +build linux,amd64

package main

import (
"flag"
"fmt"

"github.com/sirupsen/logrus"

"github.com/vmware/vmw-guestinfo/rpcvmx"
"github.com/vmware/vmw-guestinfo/vmcheck"
)

var (
set bool
get bool
fork bool
)

func init() {
flag.BoolVar(&set, "set", false, "Sets the guestinfo.KEY with the string VALUE")
flag.BoolVar(&get, "get", false, "Returns the config string in the guestinfo.* namespace")

flag.Parse()
}

func main() {
log := logrus.New().WithField("app", "rpctool")

isVM, err := vmcheck.IsVirtualWorld()
if err != nil {
log.Fatalf("Error: %s", err)
}

if !isVM {
log.Fatalf("ERROR: not in a virtual world.")
}

if !set && !get && !fork {
flag.Usage()
}

config := rpcvmx.NewConfig()
if set {
if flag.NArg() != 2 {
log.Fatalf("ERROR: Please provide guestinfo key / value pair (eg; -set foo bar")
}
if err := config.SetString(flag.Arg(0), flag.Arg(1)); err != nil {
log.Fatalf("ERROR: SetString failed with %s", err)
}
}

if get {
if flag.NArg() != 1 {
log.Fatalf("ERROR: Please provide guestinfo key (eg; -get foo)")
}
if out, err := config.String(flag.Arg(0), ""); err != nil {
log.Fatalf("ERROR: String failed with %s", err)
} else {
fmt.Printf("%s\n", out)
}
}
}
63 changes: 63 additions & 0 deletions cmd/toolbox/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////

// +build linux,amd64

package main

import (
"errors"
"os"
"os/signal"
"syscall"

"github.com/coreos/go-systemd/daemon"
"github.com/sirupsen/logrus"

"github.com/vmware/govmomi/toolbox"
"github.com/vmware/govmomi/toolbox/vix"
)

const (
keepEnvVars = false
sdReady = "READY=1"
)

func main() {
log := logrus.New().WithField("app", "toolbox")

in := toolbox.NewBackdoorChannelIn()
out := toolbox.NewBackdoorChannelOut()

service := toolbox.NewService(in, out)

if os.Getuid() == 0 {
service.Power.Halt.Handler = toolbox.Halt
service.Power.Reboot.Handler = toolbox.Reboot
}

// Disable all guest operations
service.Command.Authenticate = func(_ vix.CommandRequestHeader, _ []byte) error {
return errors.New("not authorized")
}

err := service.Start()
if err != nil {
log.Fatal(err)
}

daemon.SdNotify(keepEnvVars, sdReady)

// handle the signals and gracefully shutdown the service
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)

go func() {
log.Printf("signal %s received", <-sig)
service.Stop()
}()

service.Wait()
}
Loading

0 comments on commit a265f9b

Please sign in to comment.