本文整理汇总了Golang中github.com/juju/names.NewModelTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewModelTag函数的具体用法?Golang NewModelTag怎么用?Golang NewModelTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewModelTag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: InitiateModelMigration
// InitiateModelMigration attempts to start a migration for the
// specified model, returning the migration's ID.
//
// The API server supports starting multiple migrations in one request
// but we don't need that at the client side yet (and may never) so
// this call just supports starting one migration at a time.
func (c *Client) InitiateModelMigration(spec ModelMigrationSpec) (string, error) {
if err := spec.Validate(); err != nil {
return "", errors.Trace(err)
}
args := params.InitiateModelMigrationArgs{
Specs: []params.ModelMigrationSpec{{
ModelTag: names.NewModelTag(spec.ModelUUID).String(),
TargetInfo: params.ModelMigrationTargetInfo{
ControllerTag: names.NewModelTag(spec.TargetControllerUUID).String(),
Addrs: spec.TargetAddrs,
CACert: spec.TargetCACert,
AuthTag: names.NewUserTag(spec.TargetUser).String(),
Password: spec.TargetPassword,
},
}},
}
response := params.InitiateModelMigrationResults{}
if err := c.facade.FacadeCall("InitiateModelMigration", args, &response); err != nil {
return "", errors.Trace(err)
}
if len(response.Results) != 1 {
return "", errors.New("unexpected number of results returned")
}
result := response.Results[0]
if result.Error != nil {
return "", errors.Trace(result.Error)
}
return result.Id, nil
}
开发者ID:makyo,项目名称:juju,代码行数:35,代码来源:controller.go
示例2: TestOpenHonorsModelTag
func (s *apiclientSuite) TestOpenHonorsModelTag(c *gc.C) {
info := s.APIInfo(c)
// TODO(jam): 2014-06-05 http://pad.lv/1326802
// we want to test this eventually, but for now s.APIInfo uses
// conn.StateInfo() which doesn't know about ModelTag.
// c.Check(info.ModelTag, gc.Equals, env.Tag())
// c.Assert(info.ModelTag, gc.Not(gc.Equals), "")
// We start by ensuring we have an invalid tag, and Open should fail.
info.ModelTag = names.NewModelTag("bad-tag")
_, err := api.Open(info, api.DialOpts{})
c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
Message: `unknown model: "bad-tag"`,
Code: "not found",
})
c.Check(params.ErrCode(err), gc.Equals, params.CodeNotFound)
// Now set it to the right tag, and we should succeed.
info.ModelTag = s.State.ModelTag()
st, err := api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
st.Close()
// Backwards compatibility, we should succeed if we do not set an
// model tag
info.ModelTag = names.NewModelTag("")
st, err = api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
st.Close()
}
开发者ID:OSBI,项目名称:juju,代码行数:31,代码来源:apiclient_test.go
示例3: TestOpenUsesEnvironUUIDPaths
func (s *clientSuite) TestOpenUsesEnvironUUIDPaths(c *gc.C) {
info := s.APIInfo(c)
// Backwards compatibility, passing ModelTag = "" should just work
info.ModelTag = names.NewModelTag("")
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
apistate.Close()
// Passing in the correct model UUID should also work
environ, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
info.ModelTag = environ.ModelTag()
apistate, err = api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
apistate.Close()
// Passing in a bad model UUID should fail with a known error
info.ModelTag = names.NewModelTag("dead-beef-123456")
apistate, err = api.Open(info, api.DialOpts{})
c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
Message: `unknown model: "dead-beef-123456"`,
Code: "not found",
})
c.Check(err, jc.Satisfies, params.IsCodeNotFound)
c.Assert(apistate, gc.IsNil)
}
开发者ID:OSBI,项目名称:juju,代码行数:26,代码来源:client_test.go
示例4: TestResourceTagsUUID
func (*tagsSuite) TestResourceTagsUUID(c *gc.C) {
testResourceTags(c, testing.ModelTag, names.NewModelTag(""), nil, map[string]string{
"juju-model-uuid": testing.ModelTag.Id(),
"juju-controller-uuid": "",
})
testResourceTags(c, names.NewModelTag(""), testing.ModelTag, nil, map[string]string{
"juju-model-uuid": "",
"juju-controller-uuid": testing.ModelTag.Id(),
})
}
开发者ID:makyo,项目名称:juju,代码行数:10,代码来源:tags_test.go
示例5: InstanceTags
// InstanceTags returns the minimum set of tags that should be set on a
// machine instance, if the provider supports them.
func InstanceTags(cfg *config.Config, jobs []multiwatcher.MachineJob) map[string]string {
instanceTags := tags.ResourceTags(
names.NewModelTag(cfg.UUID()),
names.NewModelTag(cfg.ControllerUUID()),
cfg,
)
if multiwatcher.AnyJobNeedsState(jobs...) {
instanceTags[tags.JujuIsController] = "true"
}
return instanceTags
}
开发者ID:makyo,项目名称:juju,代码行数:13,代码来源:instancecfg.go
示例6: setup
func (s *PresenceSuite) setup(c *gc.C, key string) (*presence.Watcher, *presence.Pinger, <-chan presence.Change) {
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
modelUUID := uuid.String()
w := presence.NewWatcher(s.presence, names.NewModelTag(modelUUID))
p := presence.NewPinger(s.presence, names.NewModelTag(modelUUID), key)
ch := make(chan presence.Change)
w.Watch(key, ch)
assertChange(c, ch, presence.Change{key, false})
return w, p, ch
}
开发者ID:exekias,项目名称:juju,代码行数:13,代码来源:presence_test.go
示例7: initResourceGroup
// initResourceGroup creates and initialises a resource group for this
// environment. The resource group will have a storage account and a
// subnet associated with it (but not necessarily contained within:
// see subnet creation).
func (env *azureEnviron) initResourceGroup() (*config.Config, error) {
location := env.config.location
tags := tags.ResourceTags(
names.NewModelTag(env.config.Config.UUID()),
names.NewModelTag(env.config.Config.ControllerUUID()),
env.config,
)
resourceGroupsClient := resources.GroupsClient{env.resources}
logger.Debugf("creating resource group %q", env.resourceGroup)
_, err := resourceGroupsClient.CreateOrUpdate(env.resourceGroup, resources.Group{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
})
if err != nil {
return nil, errors.Annotate(err, "creating resource group")
}
// Create an internal network for all VMs in the
// resource group to connect to.
vnetPtr, err := createInternalVirtualNetwork(
env.network, env.resourceGroup, location, tags,
)
if err != nil {
return nil, errors.Annotate(err, "creating virtual network")
}
_, err = createInternalSubnet(
env.network, env.resourceGroup, vnetPtr, location, tags,
)
if err != nil {
return nil, errors.Annotate(err, "creating subnet")
}
// Create a storage account for the resource group.
storageAccountsClient := storage.AccountsClient{env.storage}
storageAccountName, storageAccountKey, err := createStorageAccount(
storageAccountsClient, env.config.storageAccountType,
env.resourceGroup, location, tags,
env.provider.config.StorageAccountNameGenerator,
)
if err != nil {
return nil, errors.Annotate(err, "creating storage account")
}
return env.config.Config.Apply(map[string]interface{}{
configAttrStorageAccount: storageAccountName,
configAttrStorageAccountKey: storageAccountKey,
})
}
开发者ID:xushiwei,项目名称:juju,代码行数:53,代码来源:environ.go
示例8: storageTags
// storageTags returns the tags that should be set on a volume or filesystem,
// if the provider supports them.
func storageTags(
storageInstance state.StorageInstance,
cfg *config.Config,
) (map[string]string, error) {
storageTags := tags.ResourceTags(
names.NewModelTag(cfg.UUID()),
names.NewModelTag(cfg.ControllerUUID()),
cfg,
)
if storageInstance != nil {
storageTags[tags.JujuStorageInstance] = storageInstance.Tag().Id()
storageTags[tags.JujuStorageOwner] = storageInstance.Owner().Id()
}
return storageTags, nil
}
开发者ID:makyo,项目名称:juju,代码行数:17,代码来源:storage.go
示例9: SetUpTest
func (s *ModelMigrationSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
s.clock = coretesting.NewClock(time.Now().Truncate(time.Second))
s.PatchValue(&state.GetClock, func() clock.Clock {
return s.clock
})
// Create a hosted model to migrate.
s.State2 = s.Factory.MakeModel(c, nil)
s.AddCleanup(func(*gc.C) { s.State2.Close() })
targetControllerTag := names.NewModelTag(utils.MustNewUUID().String())
// Plausible migration arguments to test with.
s.stdSpec = state.ModelMigrationSpec{
InitiatedBy: names.NewUserTag("admin"),
TargetInfo: migration.TargetInfo{
ControllerTag: targetControllerTag,
Addrs: []string{"1.2.3.4:5555", "4.3.2.1:6666"},
CACert: "cert",
AuthTag: names.NewUserTag("user"),
Password: "password",
},
}
}
开发者ID:makyo,项目名称:juju,代码行数:25,代码来源:modelmigration_test.go
示例10: TestActivate
func (s *ClientSuite) TestActivate(c *gc.C) {
client, stub := s.getClientAndStub(c)
uuid := "fake"
err := client.Activate(uuid)
s.AssertModelCall(c, stub, names.NewModelTag(uuid), "Activate", err)
}
开发者ID:makyo,项目名称:juju,代码行数:7,代码来源:client_test.go
示例11: newState
// newState returns a new State that uses the given environment.
// The environment must have already been bootstrapped.
func newState(environ environs.Environ, mongoInfo *mongo.MongoInfo) (*state.State, error) {
config := environ.Config()
password := config.AdminSecret()
if password == "" {
return nil, fmt.Errorf("cannot connect without admin-secret")
}
modelTag := names.NewModelTag(config.UUID())
mongoInfo.Password = password
opts := mongo.DefaultDialOpts()
st, err := state.Open(modelTag, mongoInfo, opts, environs.NewStatePolicy())
if errors.IsUnauthorized(errors.Cause(err)) {
// We try for a while because we might succeed in
// connecting to mongo before the state has been
// initialized and the initial password set.
for a := redialStrategy.Start(); a.Next(); {
st, err = state.Open(modelTag, mongoInfo, opts, environs.NewStatePolicy())
if !errors.IsUnauthorized(errors.Cause(err)) {
break
}
}
if err != nil {
return nil, err
}
} else if err != nil {
return nil, err
}
if err := updateSecrets(environ, st); err != nil {
st.Close()
return nil, fmt.Errorf("unable to push secrets: %v", err)
}
return st, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:35,代码来源:conn.go
示例12: APIInfo
// APIInfo returns an api.Info for the environment. The result is populated
// with addresses and CA certificate, but no tag or password.
func APIInfo(env Environ) (*api.Info, error) {
instanceIds, err := env.ControllerInstances()
if err != nil {
return nil, err
}
logger.Debugf("ControllerInstances returned: %v", instanceIds)
addrs, err := waitAnyInstanceAddresses(env, instanceIds)
if err != nil {
return nil, err
}
defaultSpaceAddr, ok := network.SelectAddressBySpace(addrs, network.DefaultSpace)
if ok {
addrs = []network.Address{defaultSpaceAddr}
logger.Debugf("selected %q as API address in space %q", defaultSpaceAddr.Value, network.DefaultSpace)
} else {
logger.Warningf("using all API addresses (cannot pick by space %q): %+v", network.DefaultSpace, addrs)
}
config := env.Config()
cert, hasCert := config.CACert()
if !hasCert {
return nil, errors.New("config has no CACert")
}
apiPort := config.APIPort()
apiAddrs := network.HostPortsToStrings(
network.AddressesWithPort(addrs, apiPort),
)
uuid, uuidSet := config.UUID()
if !uuidSet {
return nil, errors.New("config has no UUID")
}
modelTag := names.NewModelTag(uuid)
apiInfo := &api.Info{Addrs: apiAddrs, CACert: cert, ModelTag: modelTag}
return apiInfo, nil
}
开发者ID:OSBI,项目名称:juju,代码行数:36,代码来源:utils.go
示例13: TestMigration
func (s *Suite) TestMigration(c *gc.C) {
masterClient := newStubMasterClient(s.stub)
w := migrationmaster.New(masterClient)
// Trigger migration.
masterClient.watcher.changes <- migration.TargetInfo{
ControllerTag: names.NewModelTag("uuid"),
Addrs: []string{"1.2.3.4:5"},
CACert: "cert",
AuthTag: names.NewUserTag("admin"),
Password: "secret",
}
// This error is temporary while migrationmaster is a WIP.
runWorkerAndWait(c, w, "migration seen and aborted")
// Observe that the migration was seen, the model exported, an API
// connection to the target controller was made, the model was
// imported and then the migration aborted.
s.stub.CheckCalls(c, []jujutesting.StubCall{
{"masterClient.Watch", nil},
{"masterClient.Export", nil},
{"apiOpen", []interface{}{&api.Info{
Addrs: []string{"1.2.3.4:5"},
CACert: "cert",
Tag: names.NewUserTag("admin"),
Password: "secret",
}, api.DefaultDialOpts()}},
{"APICall:MigrationTarget.Import",
[]interface{}{params.SerializedModel{Bytes: fakeSerializedModel}}},
{"masterClient.SetPhase", []interface{}{migration.ABORT}},
{"Connection.Close", nil},
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:34,代码来源:worker_test.go
示例14: ModelsForUser
// ModelsForUser returns a list of models that the user
// is able to access.
func (st *State) ModelsForUser(user names.UserTag) ([]*UserModel, error) {
// Since there are no groups at this stage, the simplest way to get all
// the models that a particular user can see is to look through the
// model user collection. A raw collection is required to support
// queries across multiple models.
modelUsers, userCloser := st.getRawCollection(modelUsersC)
defer userCloser()
// TODO: consider adding an index to the modelUsers collection on the username.
var userSlice []modelUserDoc
err := modelUsers.Find(bson.D{{"user", user.Canonical()}}).Select(bson.D{{"model-uuid", 1}, {"_id", 1}}).All(&userSlice)
if err != nil {
return nil, err
}
var result []*UserModel
for _, doc := range userSlice {
modelTag := names.NewModelTag(doc.ModelUUID)
env, err := st.GetModel(modelTag)
if err != nil {
return nil, errors.Trace(err)
}
result = append(result, &UserModel{Model: env, User: user})
}
return result, nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:30,代码来源:modeluser.go
示例15: Run
// Run implements Command.Run.
func (c *showModelCommand) Run(ctx *cmd.Context) (err error) {
api, err := c.getAPI()
if err != nil {
return err
}
defer api.Close()
store := c.ClientStore()
modelDetails, err := store.ModelByName(
c.ControllerName(),
c.AccountName(),
c.ModelName(),
)
if err != nil {
return errors.Annotate(err, "getting model details")
}
modelTag := names.NewModelTag(modelDetails.ModelUUID)
results, err := api.ModelInfo([]names.ModelTag{modelTag})
if err != nil {
return err
}
if results[0].Error != nil {
return results[0].Error
}
infoMap, err := c.apiModelInfoToModelInfoMap([]params.ModelInfo{*results[0].Result})
if err != nil {
return errors.Trace(err)
}
return c.out.Write(ctx, infoMap)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:32,代码来源:show.go
示例16: TestAllModels
func (s *controllerSuite) TestAllModels(c *gc.C) {
admin := s.Factory.MakeUser(c, &factory.UserParams{Name: "foobar"})
s.Factory.MakeModel(c, &factory.ModelParams{
Name: "owned", Owner: admin.UserTag()}).Close()
remoteUserTag := names.NewUserTag("[email protected]")
st := s.Factory.MakeModel(c, &factory.ModelParams{
Name: "user", Owner: remoteUserTag})
defer st.Close()
st.AddModelUser(state.ModelUserSpec{
User: admin.UserTag(),
CreatedBy: remoteUserTag,
DisplayName: "Foo Bar"})
s.Factory.MakeModel(c, &factory.ModelParams{
Name: "no-access", Owner: remoteUserTag}).Close()
response, err := s.controller.AllModels()
c.Assert(err, jc.ErrorIsNil)
// The results are sorted.
expected := []string{"dummymodel", "no-access", "owned", "user"}
var obtained []string
for _, env := range response.UserModels {
obtained = append(obtained, env.Name)
stateEnv, err := s.State.GetModel(names.NewModelTag(env.UUID))
c.Assert(err, jc.ErrorIsNil)
s.checkEnvironmentMatches(c, env.Model, stateEnv)
}
c.Assert(obtained, jc.DeepEquals, expected)
}
开发者ID:pmatulis,项目名称:juju,代码行数:30,代码来源:controller_test.go
示例17: apiInfoConnect
// apiInfoConnect looks for endpoint on the given environment and
// tries to connect to it, sending the result on the returned channel.
func apiInfoConnect(info configstore.EnvironInfo, apiOpen api.OpenFunc, stop <-chan struct{}, bClient *httpbakery.Client) (api.Connection, error) {
endpoint := info.APIEndpoint()
if info == nil || len(endpoint.Addresses) == 0 {
return nil, &infoConnectError{fmt.Errorf("no cached addresses")}
}
logger.Infof("connecting to API addresses: %v", endpoint.Addresses)
var modelTag names.ModelTag
if names.IsValidModel(endpoint.ModelUUID) {
modelTag = names.NewModelTag(endpoint.ModelUUID)
}
apiInfo := &api.Info{
Addrs: endpoint.Addresses,
CACert: endpoint.CACert,
Tag: environInfoUserTag(info),
Password: info.APICredentials().Password,
ModelTag: modelTag,
}
if apiInfo.Tag == nil {
apiInfo.UseMacaroons = true
}
dialOpts := api.DefaultDialOpts()
dialOpts.BakeryClient = bClient
st, err := apiOpen(apiInfo, dialOpts)
if err != nil {
return nil, &infoConnectError{err}
}
return st, nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:33,代码来源:api.go
示例18: exportModel
func (c *MigrateCommand) exportModel(ctx *cmd.Context, st *state.State) error {
ctx.Infof("\nexport %s", c.modelUUID)
// first make sure the uuid is good enough
tag := names.NewModelTag(c.modelUUID)
_, err := st.GetModel(tag)
if err != nil {
return errors.Trace(err)
}
modelState, err := st.ForModel(tag)
if err != nil {
return errors.Trace(err)
}
defer modelState.Close()
model, err := modelState.Export()
if err != nil {
return errors.Trace(err)
}
bytes, err := yaml.Marshal(model)
if err != nil {
return errors.Trace(err)
}
ctx.Stdout.Write(bytes)
return nil
}
开发者ID:howbazaar,项目名称:migration-test,代码行数:29,代码来源:main.go
示例19: APIInfo
// APIInfo returns an api.Info for the environment. The result is populated
// with addresses and CA certificate, but no tag or password.
func APIInfo(env Environ) (*api.Info, error) {
instanceIds, err := env.ControllerInstances()
if err != nil {
return nil, err
}
logger.Debugf("ControllerInstances returned: %v", instanceIds)
addrs, err := waitAnyInstanceAddresses(env, instanceIds)
if err != nil {
return nil, err
}
config := env.Config()
cert, hasCert := config.CACert()
if !hasCert {
return nil, errors.New("config has no CACert")
}
apiPort := config.APIPort()
apiAddrs := network.HostPortsToStrings(
network.AddressesWithPort(addrs, apiPort),
)
uuid, uuidSet := config.UUID()
if !uuidSet {
return nil, errors.New("config has no UUID")
}
modelTag := names.NewModelTag(uuid)
apiInfo := &api.Info{Addrs: apiAddrs, CACert: cert, ModelTag: modelTag}
return apiInfo, nil
}
开发者ID:exekias,项目名称:juju,代码行数:29,代码来源:utils.go
示例20: SetUpSuite
func (s *PresenceSuite) SetUpSuite(c *gc.C) {
s.BaseSuite.SetUpSuite(c)
s.MgoSuite.SetUpSuite(c)
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
s.modelTag = names.NewModelTag(uuid.String())
}
开发者ID:exekias,项目名称:juju,代码行数:7,代码来源:presence_test.go
注:本文中的github.com/juju/names.NewModelTag函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论