This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'solo' of https://github.com/vmware/dispatch into solo
- Loading branch information
Showing
187 changed files
with
103,817 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ bin/ | |
*.tar | ||
*.zip | ||
*.ovf | ||
!**/config/*.ovf | ||
*.ova | ||
*.vmdk | ||
*.tgz | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,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 | ||
} |
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,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) | ||
} | ||
} | ||
} |
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,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() | ||
} |
Oops, something went wrong.