本文整理汇总了Golang中github.com/juju/errors.NotFoundf函数的典型用法代码示例。如果您正苦于以下问题:Golang NotFoundf函数的具体用法?Golang NotFoundf怎么用?Golang NotFoundf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NotFoundf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: versionInitSystem
func versionInitSystem(ser string) (string, error) {
seriesos, err := series.GetOSFromSeries(ser)
if err != nil {
notFound := errors.NotFoundf("init system for series %q", ser)
return "", errors.Wrap(err, notFound)
}
switch seriesos {
case os.Windows:
return InitSystemWindows, nil
case os.Ubuntu:
switch ser {
case "precise", "quantal", "raring", "saucy", "trusty", "utopic":
return InitSystemUpstart, nil
default:
// vivid and later
if featureflag.Enabled(feature.LegacyUpstart) {
return InitSystemUpstart, nil
}
return InitSystemSystemd, nil
}
case os.CentOS:
return InitSystemSystemd, nil
}
return "", errors.NotFoundf("unknown os %q (from series %q), init system", seriesos, ser)
}
示例2: ModelByName
// ModelByName implements ModelGetter.
func (s *store) ModelByName(controllerName, modelName string) (*ModelDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
if err := ValidateModelName(modelName); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Trace(err)
}
defer releaser.Release()
all, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return nil, errors.Trace(err)
}
controllerModels, ok := all[controllerName]
if !ok {
return nil, errors.NotFoundf(
"models for controller %s",
controllerName,
)
}
details, ok := controllerModels.Models[modelName]
if !ok {
return nil, errors.NotFoundf(
"model %s:%s",
controllerName,
modelName,
)
}
return &details, nil
}
示例3: findMatchingEnvironment
func (c *UseEnvironmentCommand) findMatchingEnvironment(ctx *cmd.Context, client UseEnvironmentAPI, creds configstore.APICredentials) (base.UserEnvironment, error) {
var empty base.UserEnvironment
envs, err := client.ListEnvironments(creds.User)
if err != nil {
return empty, errors.Annotate(err, "cannot list environments")
}
var owner string
if c.Owner != "" {
// The username always contains the provider aspect of the user.
owner = names.NewUserTag(c.Owner).Username()
}
// If we have a UUID, we warn if the owner is different, but accept it.
// We also trust that the environment UUIDs are unique
if c.EnvUUID != "" {
for _, env := range envs {
if env.UUID == c.EnvUUID {
if owner != "" && env.Owner != owner {
ctx.Infof("Specified environment owned by %s, not %s", env.Owner, owner)
}
return env, nil
}
}
return empty, errors.NotFoundf("matching environment")
}
var matches []base.UserEnvironment
for _, env := range envs {
match := env.Name == c.EnvName
if match && owner != "" {
match = env.Owner == owner
}
if match {
matches = append(matches, env)
}
}
// If there is only one match, that's the one.
switch len(matches) {
case 0:
return empty, errors.NotFoundf("matching environment")
case 1:
return matches[0], nil
}
// We are going to return an error, but tell the user what the matches
// were so they can make an informed decision. We are also going to assume
// here that the resulting environment list has only one matching name for
// each user. There are tests creating environments that enforce this.
ctx.Infof("Multiple environments matched name %q:", c.EnvName)
for _, env := range matches {
ctx.Infof(" %s, owned by %s", env.UUID, env.Owner)
}
ctx.Infof("Please specify either the environment UUID or the owner to disambiguate.")
return empty, errors.New("multiple environments matched")
}
示例4: newMetricsManager
func (st *State) newMetricsManager() (*MetricsManager, error) {
mm := &MetricsManager{
st: st,
doc: metricsManagerDoc{
DocID: st.docID(metricsManagerKey),
EnvUUID: st.EnvironUUID(),
LastSuccessfulSend: time.Time{},
ConsecutiveErrors: 0,
GracePeriod: defaultGracePeriod,
}}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
return nil, errors.NotFoundf("metrics manager")
}
return []txn.Op{{
C: metricsManagerC,
Id: st.docID(metricsManagerKey),
Assert: txn.DocMissing,
Insert: mm.doc,
}}, nil
}
err := st.run(buildTxn)
if err != nil {
return nil, onAbort(err, errors.NotFoundf("metrics manager"))
}
return mm, nil
}
示例5: CurrentModel
// CurrentModel implements ModelGetter.
func (s *store) CurrentModel(controllerName string) (string, error) {
if err := ValidateControllerName(controllerName); err != nil {
return "", errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return "", errors.Trace(err)
}
defer releaser.Release()
all, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return "", errors.Trace(err)
}
controllerModels, ok := all[controllerName]
if !ok {
return "", errors.NotFoundf(
"current model for controller %s",
controllerName,
)
}
if controllerModels.CurrentModel == "" {
return "", errors.NotFoundf(
"current model for controller %s",
controllerName,
)
}
return controllerModels.CurrentModel, nil
}
示例6: RemoveModel
// RemoveModel implements ModelRemover.
func (c *MemStore) RemoveModel(controller, account, model string) error {
if err := jujuclient.ValidateControllerName(controller); err != nil {
return err
}
if err := jujuclient.ValidateAccountName(account); err != nil {
return err
}
if err := jujuclient.ValidateModelName(model); err != nil {
return err
}
controllerAccountModels, ok := c.Models[controller]
if !ok {
return errors.NotFoundf("models for controller %s", controller)
}
accountModels, ok := controllerAccountModels.AccountModels[account]
if !ok {
return errors.NotFoundf(
"models for account %s on controller %s",
account, controller,
)
}
if _, ok := accountModels.Models[model]; !ok {
return errors.NotFoundf("model %s:%s:%s", controller, account, model)
}
delete(accountModels.Models, model)
if accountModels.CurrentModel == model {
accountModels.CurrentModel = ""
}
return nil
}
示例7: virtualMachines
// virtualMachines returns a mapping of instance IDs to VirtualMachines and
// errors, for each of the specified instance IDs.
func (v *azureVolumeSource) virtualMachines(instanceIds []instance.Id) (map[instance.Id]*maybeVirtualMachine, error) {
// Fetch all instances at once. Failure to find an instance should
// not cause the entire method to fail.
results := make(map[instance.Id]*maybeVirtualMachine)
instances, err := v.env.instances(
v.env.resourceGroup,
instanceIds,
false, /* don't refresh addresses */
)
switch err {
case nil, environs.ErrPartialInstances:
for i, inst := range instances {
vm := &maybeVirtualMachine{}
if inst != nil {
vm.vm = &inst.(*azureInstance).VirtualMachine
} else {
vm.err = errors.NotFoundf("instance %v", instanceIds[i])
}
results[instanceIds[i]] = vm
}
case environs.ErrNoInstances:
for _, instanceId := range instanceIds {
results[instanceId] = &maybeVirtualMachine{
err: errors.NotFoundf("instance %v", instanceId),
}
}
default:
return nil, errors.Annotate(err, "getting instances")
}
return results, nil
}
示例8: SetCurrentModel
// SetCurrentModel implements ModelUpdater.
func (c *MemStore) SetCurrentModel(controllerName, accountName, modelName string) error {
if err := jujuclient.ValidateControllerName(controllerName); err != nil {
return errors.Trace(err)
}
if err := jujuclient.ValidateAccountName(accountName); err != nil {
return err
}
if err := jujuclient.ValidateModelName(modelName); err != nil {
return errors.Trace(err)
}
controllerAccountModels, ok := c.Models[controllerName]
if !ok {
return errors.NotFoundf("models for controller %s", controllerName)
}
accountModels, ok := controllerAccountModels.AccountModels[accountName]
if !ok {
return errors.NotFoundf(
"models for account %s on controller %s",
accountName, controllerName,
)
}
if _, ok := accountModels.Models[modelName]; !ok {
return errors.NotFoundf("model %s:%s:%s", controllerName, accountName, modelName)
}
accountModels.CurrentModel = modelName
return nil
}
示例9: AccountByName
// AccountByName implements AccountGetter.
func (s *store) AccountByName(controllerName, accountName string) (*AccountDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
if err := ValidateAccountName(accountName); err != nil {
return nil, errors.Trace(err)
}
lock, err := s.lock("account-by-name")
if err != nil {
return nil, errors.Trace(err)
}
defer s.unlock(lock)
controllerAccounts, err := ReadAccountsFile(JujuAccountsPath())
if err != nil {
return nil, errors.Trace(err)
}
accounts, ok := controllerAccounts[controllerName]
if !ok {
return nil, errors.NotFoundf("controller %s", controllerName)
}
details, ok := accounts.Accounts[accountName]
if !ok {
return nil, errors.NotFoundf("account %s:%s", controllerName, accountName)
}
return &details, nil
}
示例10: RemoveAccount
// RemoveAccount implements AccountRemover.
func (s *store) RemoveAccount(controllerName, accountName string) error {
if err := ValidateControllerName(controllerName); err != nil {
return errors.Trace(err)
}
if err := ValidateAccountName(accountName); err != nil {
return errors.Trace(err)
}
lock, err := s.lock("remove-account")
if err != nil {
return errors.Trace(err)
}
defer s.unlock(lock)
controllerAccounts, err := ReadAccountsFile(JujuAccountsPath())
if err != nil {
return errors.Trace(err)
}
accounts, ok := controllerAccounts[controllerName]
if !ok {
return errors.NotFoundf("controller %s", controllerName)
}
if _, ok := accounts.Accounts[accountName]; !ok {
return errors.NotFoundf("account %s:%s", controllerName, accountName)
}
delete(accounts.Accounts, accountName)
if accounts.CurrentAccount == accountName {
accounts.CurrentAccount = ""
}
return errors.Trace(WriteAccountsFile(controllerAccounts))
}
示例11: CurrentModel
// CurrentModel implements ModelGetter.
func (s *store) CurrentModel(controllerName, accountName string) (string, error) {
if err := ValidateControllerName(controllerName); err != nil {
return "", errors.Trace(err)
}
if err := ValidateAccountName(accountName); err != nil {
return "", errors.Trace(err)
}
lock, err := s.lock("read-current-model")
if err != nil {
return "", errors.Trace(err)
}
defer s.unlock(lock)
all, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return "", errors.Trace(err)
}
controllerAccountModels, ok := all[controllerName]
if !ok {
return "", errors.NotFoundf(
"current model for controller %s",
controllerName,
)
}
accountModels, ok := controllerAccountModels.AccountModels[accountName]
if !ok || accountModels.CurrentModel == "" {
return "", errors.NotFoundf(
"current model for account %s on controller %s",
accountName, controllerName,
)
}
return accountModels.CurrentModel, nil
}
示例12: AllModels
// AllModels implements ModelGetter.
func (s *store) AllModels(controllerName, accountName string) (map[string]ModelDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
if err := ValidateAccountName(accountName); err != nil {
return nil, errors.Trace(err)
}
lock, err := s.lock("read-all-models")
if err != nil {
return nil, errors.Trace(err)
}
defer s.unlock(lock)
all, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return nil, errors.Trace(err)
}
controllerAccountModels, ok := all[controllerName]
if !ok {
return nil, errors.NotFoundf(
"models for controller %s",
controllerName,
)
}
accountModels, ok := controllerAccountModels.AccountModels[accountName]
if !ok {
return nil, errors.NotFoundf(
"models for account %s on controller %s",
accountName, controllerName,
)
}
return accountModels.Models, nil
}
示例13: getMirrorReference
// getMirrorReference returns the reference to the metadata file containing mirrors for the specified content and cloud.
func (mirrorRefs *MirrorRefs) getMirrorReference(datatype, contentId string, cloud CloudSpec) (*MirrorReference, error) {
candidates := mirrorRefs.extractMirrorRefs(contentId)
if len(candidates) == 0 {
return nil, errors.NotFoundf("mirror data for %q", contentId)
}
// Restrict by cloud spec and datatype.
hasRightCloud := func(mirrorRef *MirrorReference) bool {
return mirrorRef.hasCloud(cloud) && mirrorRef.DataType == datatype
}
matchingCandidates := candidates.filter(hasRightCloud)
if len(matchingCandidates) == 0 {
// No cloud specific mirrors found so look for a non cloud specific mirror.
for _, candidate := range candidates {
if len(candidate.Clouds) == 0 {
logger.Debugf("using default candidate for content id %q are %v", contentId, candidate)
return &candidate, nil
}
}
return nil, errors.NotFoundf("index file with cloud %v", cloud)
}
logger.Debugf("candidate matches for content id %q are %v", contentId, candidates)
// Pick arbitrary match.
return &matchingCandidates[0], nil
}
示例14: migrationFromQuery
func (st *State) migrationFromQuery(query mongo.Query) (ModelMigration, error) {
var doc modelMigDoc
err := query.One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("migration")
} else if err != nil {
return nil, errors.Annotate(err, "migration lookup failed")
}
statusColl, closer := st.getCollection(migrationsStatusC)
defer closer()
var statusDoc modelMigStatusDoc
err = statusColl.FindId(doc.Id).One(&statusDoc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("migration status")
} else if err != nil {
return nil, errors.Annotate(err, "migration status lookup failed")
}
return &modelMigration{
doc: doc,
statusDoc: statusDoc,
st: st,
}, nil
}
示例15: TestGetMachineProviderInterfaceInfo
func (*undertakerSuite) TestGetMachineProviderInterfaceInfo(c *gc.C) {
backend, _, api := makeApi(c, "")
backend.machines = map[string]*mockMachine{
"0": &mockMachine{
Stub: &testing.Stub{},
interfaceInfos: []network.ProviderInterfaceInfo{{
InterfaceName: "billy",
MACAddress: "hexadecimal!",
ProviderId: "a number",
}, {
InterfaceName: "lily",
MACAddress: "octal?",
ProviderId: "different number",
}}},
"2": &mockMachine{
Stub: &testing.Stub{},
interfaceInfos: []network.ProviderInterfaceInfo{{
InterfaceName: "gilly",
MACAddress: "sexagesimal?!",
ProviderId: "some number",
}},
},
}
backend.SetErrors(nil, errors.NotFoundf("no machine 100 fool!"))
args := makeEntities("machine-2", "machine-100", "machine-0", "machine-inv")
result := api.GetMachineProviderInterfaceInfo(args)
c.Assert(result, gc.DeepEquals, params.ProviderInterfaceInfoResults{
Results: []params.ProviderInterfaceInfoResult{{
MachineTag: "machine-2",
Interfaces: []params.ProviderInterfaceInfo{{
InterfaceName: "gilly",
MACAddress: "sexagesimal?!",
ProviderId: "some number",
}},
}, {
MachineTag: "machine-100",
Error: common.ServerError(
errors.NotFoundf("no machine 100 fool!"),
),
}, {
MachineTag: "machine-0",
Interfaces: []params.ProviderInterfaceInfo{{
InterfaceName: "billy",
MACAddress: "hexadecimal!",
ProviderId: "a number",
}, {
InterfaceName: "lily",
MACAddress: "octal?",
ProviderId: "different number",
}},
}, {
MachineTag: "machine-inv",
Error: common.ServerError(
errors.New(`"machine-inv" is not a valid machine tag`),
),
}},
})
}