• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang modelcmd.Wrap函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/juju/cmd/modelcmd.Wrap函数的典型用法代码示例。如果您正苦于以下问题:Golang Wrap函数的具体用法?Golang Wrap怎么用?Golang Wrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Wrap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestDebugHooksCommand

func (s *DebugHooksSuite) TestDebugHooksCommand(c *gc.C) {
	//TODO(bogdanteleaga): Fix once debughooks are supported on windows
	if runtime.GOOS == "windows" {
		c.Skip("bug 1403084: Skipping on windows for now")
	}
	machines := s.makeMachines(3, c, true)
	dummy := s.AddTestingCharm(c, "dummy")
	srv := s.AddTestingService(c, "mysql", dummy)
	s.addUnit(srv, machines[0], c)

	srv = s.AddTestingService(c, "mongodb", dummy)
	s.addUnit(srv, machines[1], c)
	s.addUnit(srv, machines[2], c)

	for i, t := range debugHooksTests {
		c.Logf("test %d: %s\n\t%s\n", i, t.info, t.args)
		ctx := coretesting.Context(c)

		debugHooksCmd := &debugHooksCommand{}
		debugHooksCmd.proxy = true
		err := modelcmd.Wrap(debugHooksCmd).Init(t.args)
		if err == nil {
			err = modelcmd.Wrap(debugHooksCmd).Run(ctx)
		}
		if t.error != "" {
			c.Assert(err, gc.ErrorMatches, t.error)
		} else {
			c.Assert(err, jc.ErrorIsNil)
		}
	}
}
开发者ID:pmatulis,项目名称:juju,代码行数:31,代码来源:debughooks_test.go


示例2: TestResetPreviousUpgrade

func (s *UpgradeJujuSuite) TestResetPreviousUpgrade(c *gc.C) {
	fakeAPI := NewFakeUpgradeJujuAPI(c, s.State)
	fakeAPI.patch(s)

	ctx := coretesting.Context(c)
	var stdin bytes.Buffer
	ctx.Stdin = &stdin

	run := func(answer string, expect bool, args ...string) {
		stdin.Reset()
		if answer != "" {
			stdin.WriteString(answer)
		}

		fakeAPI.reset()

		cmd := &upgradeJujuCommand{}
		err := coretesting.InitCommand(modelcmd.Wrap(cmd),
			append([]string{"--reset-previous-upgrade"}, args...))
		c.Assert(err, jc.ErrorIsNil)
		err = modelcmd.Wrap(cmd).Run(ctx)
		if expect {
			c.Assert(err, jc.ErrorIsNil)
		} else {
			c.Assert(err, gc.ErrorMatches, "previous upgrade not reset and no new upgrade triggered")
		}

		c.Assert(fakeAPI.abortCurrentUpgradeCalled, gc.Equals, expect)
		expectedVersion := version.Number{}
		if expect {
			expectedVersion = fakeAPI.nextVersion.Number
		}
		c.Assert(fakeAPI.setVersionCalledWith, gc.Equals, expectedVersion)
	}

	const expectUpgrade = true
	const expectNoUpgrade = false

	// EOF on stdin - equivalent to answering no.
	run("", expectNoUpgrade)

	// -y on command line - no confirmation required
	run("", expectUpgrade, "-y")

	// --yes on command line - no confirmation required
	run("", expectUpgrade, "--yes")

	// various ways of saying "yes" to the prompt
	for _, answer := range []string{"y", "Y", "yes", "YES"} {
		run(answer, expectUpgrade)
	}

	// various ways of saying "no" to the prompt
	for _, answer := range []string{"n", "N", "no", "foo"} {
		run(answer, expectNoUpgrade)
	}
}
开发者ID:bac,项目名称:juju,代码行数:57,代码来源:upgradejuju_test.go


示例3: TestSCPCommand

func (s *SCPSuite) TestSCPCommand(c *gc.C) {
	m := s.makeMachines(4, c, true)
	ch := testcharms.Repo.CharmDir("dummy")
	curl := charm.MustParseURL(
		fmt.Sprintf("local:quantal/%s-%d", ch.Meta().Name, ch.Revision()),
	)
	info := state.CharmInfo{
		Charm:       ch,
		ID:          curl,
		StoragePath: "dummy-path",
		SHA256:      "dummy-1-sha256",
	}
	dummyCharm, err := s.State.AddCharm(info)
	c.Assert(err, jc.ErrorIsNil)
	srv := s.AddTestingService(c, "mysql", dummyCharm)
	s.addUnit(srv, m[0], c)

	srv = s.AddTestingService(c, "mongodb", dummyCharm)
	s.addUnit(srv, m[1], c)
	s.addUnit(srv, m[2], c)
	srv = s.AddTestingService(c, "ipv6-svc", dummyCharm)
	s.addUnit(srv, m[3], c)
	// Simulate machine 3 has a public IPv6 address.
	ipv6Addr := network.NewScopedAddress("2001:db8::1", network.ScopePublic)
	err = m[3].SetProviderAddresses(ipv6Addr)
	c.Assert(err, jc.ErrorIsNil)

	for i, t := range scpTests {
		c.Logf("test %d: %s -> %s\n", i, t.about, t.args)
		ctx := coretesting.Context(c)
		scpcmd := &scpCommand{}
		scpcmd.proxy = t.proxy

		err := modelcmd.Wrap(scpcmd).Init(t.args)
		c.Check(err, jc.ErrorIsNil)
		err = modelcmd.Wrap(scpcmd).Run(ctx)
		if t.error != "" {
			c.Check(err, gc.ErrorMatches, t.error)
			c.Check(t.result, gc.Equals, "")
		} else {
			c.Check(err, jc.ErrorIsNil)
			// we suppress stdout from scp
			c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
			c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, "")
			data, err := ioutil.ReadFile(filepath.Join(s.bin, "scp.args"))
			c.Check(err, jc.ErrorIsNil)
			actual := string(data)
			if t.proxy {
				actual = strings.Replace(actual, ".dns", ".internal", 2)
			}
			c.Check(actual, gc.Equals, t.result)
		}
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:54,代码来源:scp_unix_test.go


示例4: TestBlockUpgradeInProgress

func (s *UpgradeJujuSuite) TestBlockUpgradeInProgress(c *gc.C) {
	fakeAPI := NewFakeUpgradeJujuAPI(c, s.State)
	fakeAPI.setVersionErr = common.OperationBlockedError("the operation has been blocked")
	fakeAPI.patch(s)
	cmd := &upgradeJujuCommand{}
	err := coretesting.InitCommand(modelcmd.Wrap(cmd), []string{})
	c.Assert(err, jc.ErrorIsNil)

	// Block operation
	s.BlockAllChanges(c, "TestBlockUpgradeInProgress")
	err = modelcmd.Wrap(cmd).Run(coretesting.Context(c))
	s.AssertBlocked(c, err, ".*To enable changes.*")
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:upgradejuju_test.go


示例5: NewRestoreCommandForTest

func NewRestoreCommandForTest(
	store jujuclient.ClientStore,
	api RestoreAPI,
	getArchive func(string) (ArchiveReader, *params.BackupsMetadataResult, error),
	newEnviron func(environs.OpenParams) (environs.Environ, error),
	getRebootstrapParams func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error),
) cmd.Command {
	c := &restoreCommand{
		getArchiveFunc:           getArchive,
		newEnvironFunc:           newEnviron,
		getRebootstrapParamsFunc: getRebootstrapParams,
		newAPIClientFunc: func() (RestoreAPI, error) {
			return api, nil
		},
		waitForAgentFunc: func(ctx *cmd.Context, c *modelcmd.ModelCommandBase, controllerName, hostedModelName string) error {
			return nil
		},
	}
	if getRebootstrapParams == nil {
		c.getRebootstrapParamsFunc = c.getRebootstrapParams
	}
	if newEnviron == nil {
		c.newEnvironFunc = environs.New
	}
	c.Log = &cmd.Log{}
	c.SetClientStore(store)
	return modelcmd.Wrap(c)
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:export_test.go


示例6: newVolumeListCommand

func newVolumeListCommand() cmd.Command {
	cmd := &volumeListCommand{}
	cmd.newAPIFunc = func() (VolumeListAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
开发者ID:pmatulis,项目名称:juju,代码行数:7,代码来源:volumelist.go


示例7: newFilesystemListCommand

func newFilesystemListCommand() cmd.Command {
	cmd := &filesystemListCommand{}
	cmd.newAPIFunc = func() (FilesystemListAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
开发者ID:exekias,项目名称:juju,代码行数:7,代码来源:filesystemlist.go


示例8: NewDestroyCommand

// NewDestroyCommand returns a command used to destroy a model.
func NewDestroyCommand() cmd.Command {
	return modelcmd.Wrap(
		&destroyCommand{},
		modelcmd.WrapSkipDefaultModel,
		modelcmd.WrapSkipModelFlags,
	)
}
开发者ID:kat-co,项目名称:juju,代码行数:8,代码来源:destroy.go


示例9: NewDeployCommandWithDefaultAPI

func NewDeployCommandWithDefaultAPI(steps []DeployStep) cmd.Command {
	deployCmd := &DeployCommand{Steps: steps}
	cmd := modelcmd.Wrap(deployCmd)
	deployCmd.NewAPIRoot = func() (DeployAPI, error) {
		apiRoot, err := deployCmd.ModelCommandBase.NewAPIRoot()
		if err != nil {
			return nil, errors.Trace(err)
		}
		bakeryClient, err := deployCmd.BakeryClient()
		if err != nil {
			return nil, errors.Trace(err)
		}
		cstoreClient := newCharmStoreClient(bakeryClient).WithChannel(deployCmd.Channel)

		adapter := &deployAPIAdapter{
			Connection:        apiRoot,
			apiClient:         &apiClient{Client: apiRoot.Client()},
			charmsClient:      &charmsClient{Client: apicharms.NewClient(apiRoot)},
			applicationClient: &applicationClient{Client: application.NewClient(apiRoot)},
			modelConfigClient: &modelConfigClient{Client: modelconfig.NewClient(apiRoot)},
			charmstoreClient:  &charmstoreClient{Client: cstoreClient},
			annotationsClient: &annotationsClient{Client: annotations.NewClient(apiRoot)},
			charmRepoClient:   &charmRepoClient{CharmStore: charmrepo.NewCharmStoreFromClient(cstoreClient)},
		}

		return adapter, nil
	}
	return cmd
}
开发者ID:kat-co,项目名称:juju,代码行数:29,代码来源:deploy.go


示例10: newAddCommand

func newAddCommand() cmd.Command {
	cmd := &addCommand{}
	cmd.newAPIFunc = func() (StorageAddAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
开发者ID:pmatulis,项目名称:juju,代码行数:7,代码来源:add.go


示例11: NewDestroyCommand

// NewDestroyCommand returns a command used to destroy a model.
func NewDestroyCommand() cmd.Command {
	return modelcmd.Wrap(
		&destroyCommand{},
		modelcmd.ModelSkipDefault,
		modelcmd.ModelSkipFlags,
	)
}
开发者ID:exekias,项目名称:juju,代码行数:8,代码来源:destroy.go


示例12: NewAddCommandForTest

func NewAddCommandForTest(api StorageAddAPI, store jujuclient.ClientStore) cmd.Command {
	cmd := &addCommand{newAPIFunc: func() (StorageAddAPI, error) {
		return api, nil
	}}
	cmd.SetClientStore(store)
	return modelcmd.Wrap(cmd)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:export_test.go


示例13: NewPoolCreateCommandForTest

func NewPoolCreateCommandForTest(api PoolCreateAPI, store jujuclient.ClientStore) cmd.Command {
	cmd := &poolCreateCommand{newAPIFunc: func() (PoolCreateAPI, error) {
		return api, nil
	}}
	cmd.SetClientStore(store)
	return modelcmd.Wrap(cmd)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:export_test.go


示例14: NewShowCommand

// NewShowCommand returns a command that shows storage details
// on the specified machine
func NewShowCommand() cmd.Command {
	cmd := &showCommand{}
	cmd.newAPIFunc = func() (StorageShowAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:show.go


示例15: NewListCommand

// NewListCommand returns a command for listing storage instances.
func NewListCommand() cmd.Command {
	cmd := &listCommand{}
	cmd.newAPIFunc = func() (StorageListAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:list.go


示例16: newDeleteImageMetadataCommand

func newDeleteImageMetadataCommand() cmd.Command {
	deleteCmd := &deleteImageMetadataCommand{}
	deleteCmd.newAPIFunc = func() (MetadataDeleteAPI, error) {
		return deleteCmd.NewImageMetadataAPI()
	}
	return modelcmd.Wrap(deleteCmd)
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:deleteimage.go


示例17: newPoolCreateCommand

func newPoolCreateCommand() cmd.Command {
	cmd := &poolCreateCommand{}
	cmd.newAPIFunc = func() (PoolCreateAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
开发者ID:exekias,项目名称:juju,代码行数:7,代码来源:poolcreate.go


示例18: NewEnableCommand

// NewEnableCommand returns a new command that eanbles previously disabled
// command sets.
func NewEnableCommand() cmd.Command {
	return modelcmd.Wrap(&enableCommand{
		apiFunc: func(c newAPIRoot) (unblockClientAPI, error) {
			return getBlockAPI(c)
		},
	})
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:enablecommand.go


示例19: RunPlugin

func RunPlugin(ctx *cmd.Context, subcommand string, args []string) error {
	cmdName := JujuPluginPrefix + subcommand
	plugin := modelcmd.Wrap(&PluginCommand{name: cmdName})

	// We process common flags supported by Juju commands.
	// To do this, we extract only those supported flags from the
	// argument list to avoid confusing flags.Parse().
	flags := gnuflag.NewFlagSet(cmdName, gnuflag.ContinueOnError)
	flags.SetOutput(ioutil.Discard)
	plugin.SetFlags(flags)
	jujuArgs := extractJujuArgs(args)
	if err := flags.Parse(false, jujuArgs); err != nil {
		return err
	}
	if err := plugin.Init(args); err != nil {
		return err
	}
	err := plugin.Run(ctx)
	_, execError := err.(*exec.Error)
	// exec.Error results are for when the executable isn't found, in
	// those cases, drop through.
	if !execError {
		return err
	}
	return &cmd.UnrecognizedCommand{Name: subcommand}
}
开发者ID:exekias,项目名称:juju,代码行数:26,代码来源:plugin.go


示例20: TestUpgradeUnknownSeriesInStreams

func (s *UpgradeJujuSuite) TestUpgradeUnknownSeriesInStreams(c *gc.C) {
	fakeAPI := NewFakeUpgradeJujuAPI(c, s.State)
	fakeAPI.addTools("2.1.0-weird-amd64")
	fakeAPI.patch(s)

	cmd := &upgradeJujuCommand{}
	err := coretesting.InitCommand(modelcmd.Wrap(cmd), []string{})
	c.Assert(err, jc.ErrorIsNil)

	err = modelcmd.Wrap(cmd).Run(coretesting.Context(c))
	c.Assert(err, gc.IsNil)

	// ensure find tools was called
	c.Assert(fakeAPI.findToolsCalled, jc.IsTrue)
	c.Assert(fakeAPI.tools, gc.DeepEquals, []string{"2.1.0-weird-amd64", fakeAPI.nextVersion.String()})
}
开发者ID:bac,项目名称:juju,代码行数:16,代码来源:upgradejuju_test.go



注:本文中的github.com/juju/juju/cmd/modelcmd.Wrap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang modelcmd.WrapController函数代码示例发布时间:2022-05-23
下一篇:
Golang modelcmd.NewModelCommandBase函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap