本文整理匯總了Golang中github.com/vmware/vic/pkg/vsphere/extraconfig.Encode函數的典型用法代碼示例。如果您正苦於以下問題:Golang Encode函數的具體用法?Golang Encode怎麽用?Golang Encode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Encode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Commit
func (h *Handle) Commit(ctx context.Context, sess *session.Session, waitTime *int32) error {
cfg := make(map[string]string)
// Set timestamps based on target state
switch h.TargetState() {
case StateRunning:
for _, sc := range h.ExecConfig.Sessions {
sc.StartTime = time.Now().UTC().Unix()
sc.Started = ""
sc.ExitStatus = 0
}
case StateStopped:
for _, sc := range h.ExecConfig.Sessions {
sc.StopTime = time.Now().UTC().Unix()
}
}
extraconfig.Encode(extraconfig.MapSink(cfg), h.ExecConfig)
s := h.Spec.Spec()
s.ExtraConfig = append(s.ExtraConfig, vmomi.OptionValueFromMap(cfg)...)
if err := Commit(ctx, sess, h, waitTime); err != nil {
return err
}
removeHandle(h.key)
return nil
}
示例2: StartAttachTether
func StartAttachTether(t *testing.T, cfg *executor.ExecutorConfig, mocker *Mocker) (tether.Tether, extraconfig.DataSource, net.Conn) {
store := extraconfig.New()
sink := store.Put
src := store.Get
extraconfig.Encode(sink, cfg)
log.Debugf("Test configuration: %#v", sink)
tthr = tether.New(src, sink, mocker)
tthr.Register("mocker", mocker)
tthr.Register("Attach", server)
// run the tether to service the attach
go func() {
erR := tthr.Start()
if erR != nil {
t.Error(erR)
}
}()
// create client on the mock pipe
conn, err := mockBackChannel(context.Background())
if err != nil && (err != io.EOF || server.(*testAttachServer).enabled) {
// we accept the case where the error is end-of-file and the attach server is disabled because that's
// expected when the tether is shut down.
t.Error(err)
}
return tthr, src, conn
}
示例3: reconfigureApplianceSpec
func (d *Dispatcher) reconfigureApplianceSpec(vm *vm.VirtualMachine, conf *metadata.VirtualContainerHostConfigSpec) (*types.VirtualMachineConfigSpec, error) {
defer trace.End(trace.Begin(""))
var devices object.VirtualDeviceList
var err error
spec := &types.VirtualMachineConfigSpec{
Name: conf.Name,
GuestId: "other3xLinux64Guest",
Files: &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", conf.ImageStores[0].Host)},
}
if devices, err = d.configIso(conf, vm); err != nil {
return nil, err
}
deviceChange, err := devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd)
if err != nil {
log.Errorf("Failed to create config spec for appliance: %s", err)
return nil, err
}
spec.DeviceChange = deviceChange
cfg := make(map[string]string)
extraconfig.Encode(extraconfig.MapSink(cfg), conf)
spec.ExtraConfig = append(spec.ExtraConfig, extraconfig.OptionValueFromMap(cfg)...)
return spec, nil
}
示例4: TestToExtraConfig
func TestToExtraConfig(t *testing.T) {
exec := metadata.ExecutorConfig{
Common: metadata.Common{
ID: "deadbeef",
Name: "configtest",
},
Sessions: map[string]metadata.SessionConfig{
"deadbeef": metadata.SessionConfig{
Cmd: metadata.Cmd{
Path: "/bin/bash",
Args: []string{"/bin/bash", "-c", "echo hello"},
Dir: "/",
Env: []string{"HOME=/", "PATH=/bin"},
},
},
"beefed": metadata.SessionConfig{
Cmd: metadata.Cmd{
Path: "/bin/bash",
Args: []string{"/bin/bash", "-c", "echo goodbye"},
Dir: "/",
Env: []string{"HOME=/", "PATH=/bin"},
},
},
},
Networks: map[string]*metadata.NetworkEndpoint{
"eth0": &metadata.NetworkEndpoint{
Static: &net.IPNet{IP: localhost, Mask: lmask.Mask},
Network: metadata.ContainerNetwork{
Common: metadata.Common{
Name: "notsure",
},
Gateway: net.IPNet{IP: gateway, Mask: gmask.Mask},
Nameservers: []net.IP{},
},
},
},
}
// encode metadata package's ExecutorConfig
encoded := map[string]string{}
extraconfig.Encode(extraconfig.MapSink(encoded), exec)
// decode into this package's ExecutorConfig
var decoded ExecutorConfig
extraconfig.Decode(extraconfig.MapSource(encoded), &decoded)
// the networks should be identical
assert.Equal(t, exec.Networks["eth0"], decoded.Networks["eth0"])
// the source and destination structs are different - we're doing a sparse comparison
expected := exec.Sessions["deadbeef"]
actual := *decoded.Sessions["deadbeef"]
assert.Equal(t, expected.Cmd.Path, actual.Cmd.Path)
assert.Equal(t, expected.Cmd.Args, actual.Cmd.Args)
assert.Equal(t, expected.Cmd.Dir, actual.Cmd.Dir)
assert.Equal(t, expected.Cmd.Env, actual.Cmd.Env)
}
示例5: Start
func (t *tether) Start() error {
defer trace.End(trace.Begin("main tether loop"))
// do the initial setup and start the extensions
t.setup()
defer t.cleanup()
// initial entry, so seed this
t.reload <- true
for range t.reload {
log.Info("Loading main configuration")
// load the config - this modifies the structure values in place
extraconfig.Decode(t.src, t.config)
t.setLogLevel()
if err := t.setHostname(); err != nil {
log.Error(err)
return err
}
// process the networks then publish any dynamic data
if err := t.setNetworks(); err != nil {
log.Error(err)
return err
}
extraconfig.Encode(t.sink, t.config)
//process the filesystem mounts - this is performed after networks to allow for network mounts
if err := t.setMounts(); err != nil {
log.Error(err)
return err
}
if err := t.initializeSessions(); err != nil {
log.Error(err)
return err
}
if err := t.reloadExtensions(); err != nil {
log.Error(err)
return err
}
if err := t.processSessions(); err != nil {
log.Error(err)
return err
}
}
log.Info("Finished processing sessions")
return nil
}
示例6: logConfig
func logConfig(config *ExecutorConfig) {
// just pretty print the json for now
log.Info("Loaded executor config")
if log.GetLevel() == log.DebugLevel && config.DebugLevel > 1 {
sink := map[string]string{}
extraconfig.Encode(extraconfig.MapSink(sink), config)
for k, v := range sink {
log.Debugf("%s: %s", k, v)
}
}
}
示例7: RunTether
func RunTether(t *testing.T, cfg *executor.ExecutorConfig) (tether.Tether, extraconfig.DataSource, error) {
store := extraconfig.New()
sink := store.Put
src := store.Get
extraconfig.Encode(sink, cfg)
log.Debugf("Test configuration: %#v", sink)
tthr = tether.New(src, sink, &Mocked)
tthr.Register("Mocker", &Mocked)
// run the tether to service the attach
erR := tthr.Start()
return tthr, src, erR
}
示例8: RunTether
func RunTether(t *testing.T, cfg *metadata.ExecutorConfig) (Tether, extraconfig.DataSource, error) {
store := map[string]string{}
sink := extraconfig.MapSink(store)
src := extraconfig.MapSource(store)
extraconfig.Encode(sink, cfg)
log.Debugf("Test configuration: %#v", sink)
tthr := New(src, sink, &Mocked)
tthr.Register("Mocker", &Mocked)
// run the tether to service the attach
erR := tthr.Start()
return tthr, src, erR
}
示例9: logConfig
func logConfig(config *ExecutorConfig) {
// just pretty print the json for now
log.Info("Loaded executor config")
// TODO: investigate whether it's the govmomi types package cause the binary size
// inflation - if so we need an alternative approach here or in extraconfig
if log.GetLevel() == log.DebugLevel {
sink := map[string]string{}
extraconfig.Encode(extraconfig.MapSink(sink), config)
for k, v := range sink {
log.Debugf("%s: %s", k, v)
}
}
}
示例10: encodeConfig
func (d *Dispatcher) encodeConfig(conf *config.VirtualContainerHostConfigSpec) (map[string]string, error) {
if d.secret == nil {
log.Debug("generating new config secret key")
s, err := extraconfig.NewSecretKey()
if err != nil {
return nil, err
}
d.secret = s
}
cfg := make(map[string]string)
extraconfig.Encode(d.secret.Sink(extraconfig.MapSink(cfg)), conf)
return cfg, nil
}
示例11: createApplianceSpec
func (d *Dispatcher) createApplianceSpec(conf *metadata.VirtualContainerHostConfigSpec, vConf *data.InstallerData) (*types.VirtualMachineConfigSpec, error) {
defer trace.End(trace.Begin(""))
var devices object.VirtualDeviceList
var err error
cfg := make(map[string]string)
extraconfig.Encode(extraconfig.MapSink(cfg), conf)
spec := &spec.VirtualMachineConfigSpec{
VirtualMachineConfigSpec: &types.VirtualMachineConfigSpec{
Name: conf.Name,
GuestId: "other3xLinux64Guest",
Files: &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", conf.ImageStores[0].Host)},
NumCPUs: int32(vConf.ApplianceSize.CPU.Limit),
MemoryMB: vConf.ApplianceSize.Memory.Limit,
// Encode the config both here and after the VMs created so that it can be identified as a VCH appliance as soon as
// creation is complete.
ExtraConfig: extraconfig.OptionValueFromMap(cfg),
},
}
if devices, err = d.addIDEController(devices); err != nil {
return nil, err
}
if devices, err = d.addParaVirtualSCSIController(devices); err != nil {
return nil, err
}
if devices, err = d.addNetworkDevices(conf, spec, devices); err != nil {
return nil, err
}
deviceChange, err := devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd)
if err != nil {
return nil, err
}
spec.DeviceChange = deviceChange
return spec.VirtualMachineConfigSpec, nil
}
示例12: Commit
func (h *Handle) Commit(ctx context.Context, sess *session.Session, waitTime *int32) error {
if h.committed {
return nil // already committed
}
// make sure there is a spec
h.SetSpec(nil)
cfg := make(map[string]string)
extraconfig.Encode(extraconfig.MapSink(cfg), h.ExecConfig)
s := h.Spec.Spec()
s.ExtraConfig = append(s.ExtraConfig, vmomi.OptionValueFromMap(cfg)...)
if err := h.Container.Commit(ctx, sess, h, waitTime); err != nil {
return err
}
h.committed = true
removeHandle(h.key)
return nil
}
示例13: StartTether
func StartTether(t *testing.T, cfg *executor.ExecutorConfig) (tether.Tether, extraconfig.DataSource) {
store := extraconfig.New()
sink := store.Put
src := store.Get
extraconfig.Encode(sink, cfg)
log.Debugf("Test configuration: %#v", sink)
tthr = tether.New(src, sink, &Mocked)
tthr.Register("mocker", &Mocked)
// run the tether to service the attach
go func() {
err := tthr.Start()
if err != nil {
t.Error(err)
}
}()
return tthr, src
}
示例14: StartTether
func StartTether(t *testing.T, cfg *executor.ExecutorConfig, mocker *Mocker) (Tether, extraconfig.DataSource) {
store := extraconfig.New()
sink := store.Put
src := store.Get
extraconfig.Encode(sink, cfg)
log.Debugf("Test configuration: %#v", sink)
Tthr = New(src, sink, mocker)
Tthr.Register("mocker", mocker)
// run the tether to service the attach
go func() {
erR := Tthr.Start()
if erR != nil {
t.Error(erR)
}
}()
return Tthr, src
}
示例15: TestToExtraConfig
func TestToExtraConfig(t *testing.T) {
exec := executor.ExecutorConfig{
Common: executor.Common{
ID: "deadbeef",
Name: "configtest",
},
Sessions: map[string]*executor.SessionConfig{
"deadbeef": &executor.SessionConfig{
Cmd: executor.Cmd{
Path: "/bin/bash",
Args: []string{"/bin/bash", "-c", "echo hello"},
Dir: "/",
Env: []string{"HOME=/", "PATH=/bin"},
},
},
"beefed": &executor.SessionConfig{
Cmd: executor.Cmd{
Path: "/bin/bash",
Args: []string{"/bin/bash", "-c", "echo goodbye"},
Dir: "/",
Env: []string{"HOME=/", "PATH=/bin"},
},
},
},
Networks: map[string]*executor.NetworkEndpoint{
"eth0": &executor.NetworkEndpoint{
Static: true,
IP: &net.IPNet{IP: localhost, Mask: lmask.Mask},
Network: executor.ContainerNetwork{
Common: executor.Common{
Name: "notsure",
},
Gateway: net.IPNet{IP: gateway, Mask: gmask.Mask},
Nameservers: []net.IP{},
Pools: []ip.Range{},
Aliases: []string{},
},
},
},
}
// encode exec package's ExecutorConfig
encoded := map[string]string{}
extraconfig.Encode(extraconfig.MapSink(encoded), exec)
// decode into this package's ExecutorConfig
var decoded ExecutorConfig
extraconfig.Decode(extraconfig.MapSource(encoded), &decoded)
// the source and destination structs are different - we're doing a sparse comparison
expectedNet := exec.Networks["eth0"]
actualNet := decoded.Networks["eth0"]
assert.Equal(t, expectedNet.Common, actualNet.Common)
assert.Equal(t, expectedNet.Static, actualNet.Static)
assert.Equal(t, expectedNet.Assigned, actualNet.Assigned)
assert.Equal(t, expectedNet.Network, actualNet.Network)
expectedSession := exec.Sessions["deadbeef"]
actualSession := decoded.Sessions["deadbeef"]
assert.Equal(t, expectedSession.Cmd.Path, actualSession.Cmd.Path)
assert.Equal(t, expectedSession.Cmd.Args, actualSession.Cmd.Args)
assert.Equal(t, expectedSession.Cmd.Dir, actualSession.Cmd.Dir)
assert.Equal(t, expectedSession.Cmd.Env, actualSession.Cmd.Env)
}