本文整理汇总了Golang中github.com/juju/cmd.Run函数的典型用法代码示例。如果您正苦于以下问题:Golang Run函数的具体用法?Golang Run怎么用?Golang Run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Run函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Run
// Run resolves c.Target to a machine, to the address of a i
// machine or unit forks ssh passing any arguments provided.
func (c *SSHCommand) Run(ctx *cmd.Context) error {
if c.apiClient == nil {
// If the apClient is not already opened and it is opened
// by ensureAPIClient, then close it when we're done.
defer func() {
if c.apiClient != nil {
c.apiClient.Close()
c.apiClient = nil
}
}()
}
options, err := c.getSSHOptions(c.pty)
if err != nil {
return err
}
host, err := c.hostFromTarget(c.Target)
if err != nil {
return err
}
cmd := ssh.Command("[email protected]"+host, c.Args, options)
cmd.Stdin = ctx.Stdin
cmd.Stdout = ctx.Stdout
cmd.Stderr = ctx.Stderr
return cmd.Run()
}
开发者ID:kapilt,项目名称:juju,代码行数:28,代码来源:ssh.go
示例2: TestSetConstraints
func (s *BootstrapSuite) TestSetConstraints(c *gc.C) {
tcons := constraints.Value{Mem: uint64p(2048), CpuCores: uint64p(2)}
_, cmd, err := s.initBootstrapCommand(c, nil,
"--env-config", s.b64yamlEnvcfg,
"--instance-id", string(s.instanceId),
"--constraints", tcons.String(),
)
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
st, err := state.Open(testing.EnvironmentTag, &mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, jc.ErrorIsNil)
defer st.Close()
cons, err := st.EnvironConstraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cons, gc.DeepEquals, tcons)
machines, err := st.AllMachines()
c.Assert(err, jc.ErrorIsNil)
c.Assert(machines, gc.HasLen, 1)
cons, err = machines[0].Constraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cons, gc.DeepEquals, tcons)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:31,代码来源:bootstrap_test.go
示例3: run
func (s *LoginCommandSuite) run(c *gc.C, stdin string, args ...string) (*cmd.Context, juju.NewAPIConnectionParams, error) {
var argsOut juju.NewAPIConnectionParams
cmd, _ := user.NewLoginCommandForTest(func(args juju.NewAPIConnectionParams) (user.LoginAPI, user.ConnectionAPI, error) {
argsOut = args
// The account details are modified in place, so take a copy.
accountDetails := *argsOut.AccountDetails
argsOut.AccountDetails = &accountDetails
if s.loginErr != nil {
err := s.loginErr
s.loginErr = nil
return nil, nil, err
}
return s.mockAPI, s.mockAPI, nil
}, s.store)
ctx := coretesting.Context(c)
if stdin == "" {
stdin = "sekrit\n"
}
ctx.Stdin = strings.NewReader(stdin)
err := coretesting.InitCommand(cmd, args)
if err != nil {
return nil, argsOut, err
}
err = cmd.Run(ctx)
return ctx, argsOut, err
}
开发者ID:kat-co,项目名称:juju,代码行数:26,代码来源:login_test.go
示例4: testEnsureControllerName
func testEnsureControllerName(c *gc.C, store jujuclient.ClientStore, expect string, args ...string) {
cmd, controllerCmd, err := initTestControllerCommand(c, store, args...)
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerCmd.ControllerName(), gc.Equals, expect)
}
开发者ID:kat-co,项目名称:juju,代码行数:7,代码来源:controller_test.go
示例5: runRestore
func (c *restoreCommand) runRestore(ctx *cmd.Context) error {
cmdArgs := []string{"backups"}
if c.Log.Path != "" {
cmdArgs = append(cmdArgs, "--log-file", c.Log.Path)
}
if c.Log.Verbose {
cmdArgs = append(cmdArgs, "--verbose")
}
if c.Log.Quiet {
cmdArgs = append(cmdArgs, "--quiet")
}
if c.Log.Debug {
cmdArgs = append(cmdArgs, "--debug")
}
if c.Log.Config != c.Log.DefaultConfig {
cmdArgs = append(cmdArgs, "--logging-config", c.Log.Config)
}
if c.Log.ShowLog {
cmdArgs = append(cmdArgs, "--show-log")
}
cmdArgs = append(cmdArgs, "restore", "-b", "--file", c.backupFile)
cmd := exec.Command("juju", cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
开发者ID:pmatulis,项目名称:juju,代码行数:27,代码来源:restore.go
示例6: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
oldMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
newMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
if !exploded {
c.Assert(newMetadata, gc.HasLen, len(oldMetadata))
} else {
// new metadata should have more tools.
c.Assert(len(newMetadata), jc.GreaterThan, len(oldMetadata))
var expectedSeries set.Strings
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Ubuntu {
expectedSeries.Add(series)
}
}
c.Assert(newMetadata, gc.HasLen, expectedSeries.Size())
for _, m := range newMetadata {
c.Assert(expectedSeries.Contains(m.Release), jc.IsTrue)
}
}
}
开发者ID:kapilt,项目名称:juju,代码行数:34,代码来源:bootstrap_test.go
示例7: TestInitializeEnvironmentInvalidOplogSize
func (s *BootstrapSuite) TestInitializeEnvironmentInvalidOplogSize(c *gc.C) {
s.mongoOplogSize = "NaN"
hw := instance.MustParseHardware("arch=amd64 mem=8G")
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String())
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, gc.ErrorMatches, `invalid oplog size: "NaN"`)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:8,代码来源:bootstrap_test.go
示例8: TestInitializeEnvironment
func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) {
hw := instance.MustParseHardware("arch=amd64 mem=8G")
machConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String())
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
c.Assert(s.fakeEnsureMongo.dataDir, gc.Equals, s.dataDir)
c.Assert(s.fakeEnsureMongo.initiateCount, gc.Equals, 1)
c.Assert(s.fakeEnsureMongo.ensureCount, gc.Equals, 1)
c.Assert(s.fakeEnsureMongo.dataDir, gc.Equals, s.dataDir)
c.Assert(s.fakeEnsureMongo.oplogSize, gc.Equals, 1234)
expectInfo, exists := machConf.StateServingInfo()
c.Assert(exists, jc.IsTrue)
c.Assert(expectInfo.SharedSecret, gc.Equals, "")
servingInfo := s.fakeEnsureMongo.info
c.Assert(len(servingInfo.SharedSecret), gc.Not(gc.Equals), 0)
servingInfo.SharedSecret = ""
c.Assert(servingInfo, jc.DeepEquals, expectInfo)
expectDialAddrs := []string{fmt.Sprintf("127.0.0.1:%d", expectInfo.StatePort)}
gotDialAddrs := s.fakeEnsureMongo.initiateParams.DialInfo.Addrs
c.Assert(gotDialAddrs, gc.DeepEquals, expectDialAddrs)
memberHost := fmt.Sprintf("%s:%d", s.bootstrapName, expectInfo.StatePort)
c.Assert(s.fakeEnsureMongo.initiateParams.MemberHostPort, gc.Equals, memberHost)
c.Assert(s.fakeEnsureMongo.initiateParams.User, gc.Equals, "")
c.Assert(s.fakeEnsureMongo.initiateParams.Password, gc.Equals, "")
st, err := state.Open(&authentication.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
machines, err := st.AllMachines()
c.Assert(err, gc.IsNil)
c.Assert(machines, gc.HasLen, 1)
instid, err := machines[0].InstanceId()
c.Assert(err, gc.IsNil)
c.Assert(instid, gc.Equals, instance.Id(string(s.instanceId)))
stateHw, err := machines[0].HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Assert(stateHw, gc.NotNil)
c.Assert(*stateHw, gc.DeepEquals, hw)
cons, err := st.EnvironConstraints()
c.Assert(err, gc.IsNil)
c.Assert(&cons, jc.Satisfies, constraints.IsEmpty)
}
开发者ID:jiasir,项目名称:juju,代码行数:56,代码来源:bootstrap_test.go
示例9: runViaJujuSSH
// runViaJujuSSH will run arbitrary code in the remote machine.
func runViaJujuSSH(machine, script string, stdout, stderr *bytes.Buffer) error {
cmd := exec.Command("ssh", []string{"-o StrictHostKeyChecking=no", fmt.Sprintf("[email protected]%s", machine), "sudo -n bash -c " + utils.ShQuote(script)}...)
cmd.Stderr = stderr
cmd.Stdout = stdout
err := cmd.Run()
if err != nil {
return errors.Annotatef(err, "ssh command failed: (%q)", stderr.String())
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:upgrade.go
示例10: testToolsMetadata
func (s *BootstrapSuite) testToolsMetadata(c *gc.C, exploded bool) {
provider, err := environs.Provider(s.envcfg.Type())
c.Assert(err, gc.IsNil)
env, err := provider.Open(s.envcfg)
c.Assert(err, gc.IsNil)
envtesting.RemoveFakeToolsMetadata(c, env.Storage())
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
// We don't write metadata at bootstrap anymore.
simplestreamsMetadata, err := envtools.ReadMetadata(env.Storage())
c.Assert(err, gc.IsNil)
c.Assert(simplestreamsMetadata, gc.HasLen, 0)
// The tools should have been added to state, and
// exploded into each of the supported series of
// the same operating system if the tools were uploaded.
st, err := state.Open(&mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
var expectedSeries set.Strings
if exploded {
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
c.Assert(err, gc.IsNil)
if os == version.Current.OS {
expectedSeries.Add(series)
}
}
} else {
expectedSeries.Add(version.Current.Series)
}
storage, err := st.ToolsStorage()
c.Assert(err, gc.IsNil)
defer storage.Close()
metadata, err := storage.AllMetadata()
c.Assert(err, gc.IsNil)
c.Assert(metadata, gc.HasLen, expectedSeries.Size())
for _, m := range metadata {
c.Assert(expectedSeries.Contains(m.Version.Series), jc.IsTrue)
}
}
开发者ID:zhouqt,项目名称:juju,代码行数:53,代码来源:bootstrap_test.go
示例11: TestSystemIdentityWritten
func (s *BootstrapSuite) TestSystemIdentityWritten(c *gc.C) {
_, err := os.Stat(filepath.Join(s.dataDir, agent.SystemIdentity))
c.Assert(err, jc.Satisfies, os.IsNotExist)
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
data, err := ioutil.ReadFile(filepath.Join(s.dataDir, agent.SystemIdentity))
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(data), gc.Equals, "private-key")
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:13,代码来源:bootstrap_test.go
示例12: TestStructuredImageMetadataStored
func (s *BootstrapSuite) TestStructuredImageMetadataStored(c *gc.C) {
dir, m := createImageMetadata(c)
_, cmd, err := s.initBootstrapCommand(
c, nil,
"--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId),
"--image-metadata", dir,
)
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
// This metadata should have also been written to state...
assertWrittenToState(c, m)
}
开发者ID:snailwalker,项目名称:juju,代码行数:14,代码来源:bootstrap_test.go
示例13: runViaSsh
func runViaSsh(addr string, script string) error {
// This is taken from cmd/juju/ssh.go there is no other clear way to set user
userAddr := "[email protected]" + addr
cmd := ssh.Command(userAddr, []string{"sudo", "-n", "bash", "-c " + utils.ShQuote(script)}, nil)
var stderrBuf bytes.Buffer
var stdoutBuf bytes.Buffer
cmd.Stderr = &stderrBuf
cmd.Stdout = &stdoutBuf
err := cmd.Run()
if err != nil {
return fmt.Errorf("ssh command failed: %v (%q)", err, stderrBuf.String())
}
progress("ssh command succedded: %q", stdoutBuf.String())
return nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:15,代码来源:restore.go
示例14: TestInitialPassword
func (s *BootstrapSuite) TestInitialPassword(c *gc.C) {
machineConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instanceId))
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
// Check that we cannot now connect to the state without a
// password.
info := &authentication.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
}
testOpenState(c, info, errors.Unauthorizedf(""))
// Check we can log in to mongo as admin.
// TODO(dfc) does passing nil for the admin user name make your skin crawl ? mine too.
info.Tag, info.Password = nil, testPasswordHash()
st, err := state.Open(info, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
// Reset password so the tests can continue to use the same server.
defer st.Close()
defer st.SetAdminMongoPassword("")
// Check that the admin user has been given an appropriate
// password
u, err := st.User("admin")
c.Assert(err, gc.IsNil)
c.Assert(u.PasswordValid(testPassword), gc.Equals, true)
// Check that the machine configuration has been given a new
// password and that we can connect to mongo as that machine
// and that the in-mongo password also verifies correctly.
machineConf1, err := agent.ReadConfig(agent.ConfigPath(machineConf.DataDir(), names.NewMachineTag("0")))
c.Assert(err, gc.IsNil)
stateinfo, ok := machineConf1.MongoInfo()
c.Assert(ok, jc.IsTrue)
st, err = state.Open(stateinfo, mongo.DialOpts{}, environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
m, err := st.Machine("0")
c.Assert(err, gc.IsNil)
c.Assert(m.HasVote(), jc.IsTrue)
}
开发者ID:jiasir,项目名称:juju,代码行数:48,代码来源:bootstrap_test.go
示例15: TestInitializeStateArgs
func (s *BootstrapSuite) TestInitializeStateArgs(c *gc.C) {
var called int
initializeState := func(_ names.UserTag, _ agent.ConfigSetter, envCfg *config.Config, machineCfg agent.BootstrapMachineConfig, dialOpts mongo.DialOpts, policy state.Policy) (_ *state.State, _ *state.Machine, resultErr error) {
called++
c.Assert(dialOpts.Direct, jc.IsTrue)
c.Assert(dialOpts.Timeout, gc.Equals, 30*time.Second)
c.Assert(dialOpts.SocketTimeout, gc.Equals, 123*time.Second)
return nil, nil, errors.New("failed to initialize state")
}
s.PatchValue(&agentInitializeState, initializeState)
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, gc.ErrorMatches, "failed to initialize state")
c.Assert(called, gc.Equals, 1)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:16,代码来源:bootstrap_test.go
示例16: TestImageMetadata
func (s *BootstrapSuite) TestImageMetadata(c *gc.C) {
metadataDir := c.MkDir()
expected := []struct{ path, content string }{{
path: "images/streams/v1/index.json",
content: "abc",
}, {
path: "images/streams/v1/products.json",
content: "def",
}, {
path: "wayward/file.txt",
content: "ghi",
}}
for _, pair := range expected {
path := filepath.Join(metadataDir, pair.path)
err := os.MkdirAll(filepath.Dir(path), 0755)
c.Assert(err, jc.ErrorIsNil)
err = ioutil.WriteFile(path, []byte(pair.content), 0644)
c.Assert(err, jc.ErrorIsNil)
}
var stor statetesting.MapStorage
s.PatchValue(&newStateStorage, func(string, *mgo.Session) statestorage.Storage {
return &stor
})
_, cmd, err := s.initBootstrapCommand(
c, nil,
"--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId),
"--image-metadata", metadataDir,
)
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
// The contents of the directory should have been added to
// environment storage.
for _, pair := range expected {
r, length, err := stor.Get(pair.path)
c.Assert(err, jc.ErrorIsNil)
data, err := ioutil.ReadAll(r)
r.Close()
c.Assert(err, jc.ErrorIsNil)
c.Assert(length, gc.Equals, int64(len(pair.content)))
c.Assert(data, gc.HasLen, int(length))
c.Assert(string(data), gc.Equals, pair.content)
}
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:47,代码来源:bootstrap_test.go
示例17: TestStructuredImageMetadataInvalidSeries
func (s *BootstrapSuite) TestStructuredImageMetadataInvalidSeries(c *gc.C) {
dir, _, _ := createImageMetadata(c)
msg := "my test error"
s.PatchValue(&seriesFromVersion, func(string) (string, error) {
return "", errors.New(msg)
})
_, cmd, err := s.initBootstrapCommand(
c, nil,
"--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId),
"--image-metadata", dir,
)
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, gc.ErrorMatches, fmt.Sprintf(".*%v.*", msg))
}
开发者ID:imoapps,项目名称:juju,代码行数:17,代码来源:bootstrap_test.go
示例18: TestConfiguredMachineJobs
func (s *BootstrapSuite) TestConfiguredMachineJobs(c *gc.C) {
jobs := []multiwatcher.MachineJob{multiwatcher.JobManageEnviron}
_, cmd, err := s.initBootstrapCommand(c, jobs, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId))
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
st, err := state.Open(testing.EnvironmentTag, &mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, jc.ErrorIsNil)
defer st.Close()
m, err := st.Machine("0")
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.Jobs(), gc.DeepEquals, []state.MachineJob{state.JobManageEnviron})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:20,代码来源:bootstrap_test.go
注:本文中的github.com/juju/cmd.Run函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论