本文整理汇总了Golang中github.com/juju/juju/core/description.Model.Constraints方法的典型用法代码示例。如果您正苦于以下问题:Golang Model.Constraints方法的具体用法?Golang Model.Constraints怎么用?Golang Model.Constraints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/core/description.Model
的用法示例。
在下文中一共展示了Model.Constraints方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Import
// Import the database agnostic model representation into the database.
func (st *State) Import(model description.Model) (_ *Model, _ *State, err error) {
logger := loggo.GetLogger("juju.state.import-model")
logger.Debugf("import starting for model %s", model.Tag().Id())
// At this stage, attempting to import a model with the same
// UUID as an existing model will error.
tag := model.Tag()
_, err = st.GetModel(tag)
if err == nil {
// We have an existing matching model.
return nil, nil, errors.AlreadyExistsf("model with UUID %s", tag.Id())
} else if !errors.IsNotFound(err) {
return nil, nil, errors.Trace(err)
}
// Create the model.
cfg, err := config.New(config.NoDefaults, model.Config())
if err != nil {
return nil, nil, errors.Trace(err)
}
dbModel, newSt, err := st.NewModel(cfg, model.Owner())
if err != nil {
return nil, nil, errors.Trace(err)
}
logger.Debugf("model created %s/%s", dbModel.Owner().Canonical(), dbModel.Name())
defer func() {
if err != nil {
newSt.Close()
}
}()
// I would have loved to use import, but that is a reserved word.
restore := importer{
st: newSt,
dbModel: dbModel,
model: model,
logger: logger,
}
if err := restore.sequences(); err != nil {
return nil, nil, errors.Annotate(err, "sequences")
}
// We need to import the sequences first as we may add blocks
// in the modelExtras which will touch the block sequence.
if err := restore.modelExtras(); err != nil {
return nil, nil, errors.Annotate(err, "base model aspects")
}
if err := newSt.SetModelConstraints(restore.constraints(model.Constraints())); err != nil {
return nil, nil, errors.Annotate(err, "model constraints")
}
if err := restore.modelUsers(); err != nil {
return nil, nil, errors.Annotate(err, "modelUsers")
}
if err := restore.machines(); err != nil {
return nil, nil, errors.Annotate(err, "machines")
}
if err := restore.services(); err != nil {
return nil, nil, errors.Annotate(err, "services")
}
if err := restore.relations(); err != nil {
return nil, nil, errors.Annotate(err, "relations")
}
// NOTE: at the end of the import make sure that the mode of the model
// is set to "imported" not "active" (or whatever we call it). This way
// we don't start model workers for it before the migration process
// is complete.
// Update the sequences to match that the source.
logger.Debugf("import success")
return dbModel, newSt, nil
}
示例2: Import
// Import the database agnostic model representation into the database.
func (st *State) Import(model description.Model) (_ *Model, _ *State, err error) {
logger := loggo.GetLogger("juju.state.import-model")
logger.Debugf("import starting for model %s", model.Tag().Id())
// At this stage, attempting to import a model with the same
// UUID as an existing model will error.
tag := model.Tag()
_, err = st.GetModel(tag)
if err == nil {
// We have an existing matching model.
return nil, nil, errors.AlreadyExistsf("model with UUID %s", tag.Id())
} else if !errors.IsNotFound(err) {
return nil, nil, errors.Trace(err)
}
// Create the model.
cfg, err := config.New(config.NoDefaults, model.Config())
if err != nil {
return nil, nil, errors.Trace(err)
}
dbModel, newSt, err := st.NewModel(ModelArgs{
CloudName: model.Cloud(),
CloudRegion: model.CloudRegion(),
Config: cfg,
Owner: model.Owner(),
MigrationMode: MigrationModeImporting,
// NOTE(axw) we create the model without any storage
// pools. We'll need to import the storage pools from
// the model description before adding any volumes,
// filesystems or storage instances.
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
if err != nil {
return nil, nil, errors.Trace(err)
}
logger.Debugf("model created %s/%s", dbModel.Owner().Canonical(), dbModel.Name())
defer func() {
if err != nil {
newSt.Close()
}
}()
// I would have loved to use import, but that is a reserved word.
restore := importer{
st: newSt,
dbModel: dbModel,
model: model,
logger: logger,
}
if err := restore.sequences(); err != nil {
return nil, nil, errors.Annotate(err, "sequences")
}
// We need to import the sequences first as we may add blocks
// in the modelExtras which will touch the block sequence.
if err := restore.modelExtras(); err != nil {
return nil, nil, errors.Annotate(err, "base model aspects")
}
if err := newSt.SetModelConstraints(restore.constraints(model.Constraints())); err != nil {
return nil, nil, errors.Annotate(err, "model constraints")
}
if err := restore.sshHostKeys(); err != nil {
return nil, nil, errors.Annotate(err, "sshHostKeys")
}
if err := restore.cloudimagemetadata(); err != nil {
return nil, nil, errors.Annotate(err, "cloudimagemetadata")
}
if err := restore.actions(); err != nil {
return nil, nil, errors.Annotate(err, "actions")
}
if err := restore.modelUsers(); err != nil {
return nil, nil, errors.Annotate(err, "modelUsers")
}
if err := restore.machines(); err != nil {
return nil, nil, errors.Annotate(err, "machines")
}
if err := restore.applications(); err != nil {
return nil, nil, errors.Annotate(err, "applications")
}
if err := restore.relations(); err != nil {
return nil, nil, errors.Annotate(err, "relations")
}
if err := restore.spaces(); err != nil {
return nil, nil, errors.Annotate(err, "spaces")
}
if err := restore.linklayerdevices(); err != nil {
return nil, nil, errors.Annotate(err, "linklayerdevices")
}
if err := restore.subnets(); err != nil {
return nil, nil, errors.Annotate(err, "subnets")
}
if err := restore.ipaddresses(); err != nil {
return nil, nil, errors.Annotate(err, "ipaddresses")
}
if err := restore.storage(); err != nil {
return nil, nil, errors.Annotate(err, "storage")
}
//.........这里部分代码省略.........