id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c4200
} setupAgentLogging(a.CurrentConfig()) a.runner.StartWorker("api", a.APIWorkers) err = cmdutil.AgentDone(logger, a.runner.Wait()) return err }
c4201
if err != nil { return nil, err } if err := dependency.Install(engine, manifolds); err != nil { if err := worker.Stop(engine); err != nil { logger.Errorf("while stopping engine with bad manifolds: %v", err) } return nil, err } if err := startIntrospection(introspectionConfig{ Agent: a, Engine: engine, NewSocketName: DefaultIntrospectionSocketName, PrometheusGatherer: a.prometheusRegistry, MachineLock: machineLock, WorkerFunc: introspection.NewWorker, }); err != nil { // If the introspection worker failed to start, we just log error // but continue. It is very unlikely to happen in the real world // as the only issue is connecting to the abstract domain socket // and the agent is controlled by by the OS to only have one. logger.Errorf("failed to start introspection worker: %v", err) } return engine, nil }
c4202
error) { return common.StateControllerInfo(st) }, st.WatchAPIHostPortsForClients, ) }
c4203
resources, localControllerInfo: localControllerInfo, watchLocalControllerInfo: watchLocalControllerInfo, }, nil }
c4204
= common.ServerError(watcher.EnsureErr(w)) return results, nil } results.Results[0].NotifyWatcherId = api.resources.Register(w) return results, nil }
c4205
= common.ServerError(err) return results, nil } results.Results[0].Addresses = addrs results.Results[0].CACert = caCert return results, nil }
c4206
*Context { return &Context{ apiClient: apiClient, dataDir: dataDir, } }
c4207
err := internal.ContextDownload(deps) if err != nil { return "", errors.Trace(err) } return path, nil }
c4208
%s", ids[i].AttachmentTag, ids[i].MachineTag, ) } life = params.Dead } switch life { case params.Alive: alive = append(alive, ids[i]) case params.Dying: dying = append(dying, ids[i]) case params.Dead: dead = append(dead, ids[i]) } } return alive, dying, dead, nil }
c4209
result := range errorResults { if result.Error != nil { return errors.Annotatef(result.Error, "removing %s from state", names.ReadableString(tags[i])) } } return nil }
c4210
&& !params.IsCodeNotFound(result.Error) { // ignore not found error. return errors.Annotatef( result.Error, "removing attachment of %s to %s from state", ids[i].AttachmentTag, ids[i].MachineTag, ) } } return nil }
c4211
!= nil { logger.Errorf("failed to set status: %v", err) } } }
c4212
DBDumpDir: filepath.Join(rootDir, contentDir, dbDumpDir), MetadataFile: filepath.Join(rootDir, contentDir, metadataFile), } }
c4213
if err != nil { return nil, errors.Trace(err) } err = unpackCompressedReader(ws.RootDir, archive) return ws, errors.Trace(err) }
c4214
os.RemoveAll(ws.RootDir) return errors.Trace(err) }
c4215
errors.Trace(err) } defer tarFile.Close() err = tar.UntarFiles(tarFile, targetRoot) return errors.Trace(err) }
c4216
return nil, errors.Trace(err) } _, file, err := tar.FindFile(tarFile, filename) if err != nil { tarFile.Close() return nil, errors.Trace(err) } return file, nil }
c4217
err != nil { return nil, errors.Trace(err) } defer metaFile.Close() meta, err := NewMetadataJSONReader(metaFile) return meta, errors.Trace(err) }
c4218
data, err := ioutil.ReadAll(gzr) if err != nil { return nil, errors.Trace(err) } return NewArchiveData(data), nil }
c4219
if err != nil { return nil, errors.Trace(err) } meta, err := NewMetadataJSONReader(metaFile) return meta, errors.Trace(err) }
c4220
if err != nil { return nil, errors.Trace(err) } return &meta.Origin.Version, nil }
c4221
for _, suffix := range windowsSuffixOrder { file := fmt.Sprintf("%s%s", hookFile, suffix) foundHook, err := lookPath(file) if err != nil { if charmrunner.IsMissingHookError(err) { // look for next suffix continue } return "", err } return foundHook, nil } return "", charmrunner.NewMissingHookError(hook) }
c4222
!= nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } machine, err := p.getMachine(canAccess, tag) if err == nil { result.Results[i].Result, err = p.getProvisioningInfo(machine, env) } result.Results[i].Error = common.ServerError(err) } return result, nil }
c4223
if !unit.IsPrincipal() { continue } unitNames = append(unitNames, unit.Name()) } sort.Strings(unitNames) cfg, err := p.m.ModelConfig() if err != nil { return nil, errors.Trace(err) } controllerCfg, err := p.st.ControllerConfig() if err != nil { return nil, errors.Trace(err) } machineTags := instancecfg.InstanceTags(cfg.UUID(), controllerCfg.ControllerUUID(), cfg, jobs) if len(unitNames) > 0 { machineTags[tags.JujuUnitsDeployed] = strings.Join(unitNames, " ") } machineId := fmt.Sprintf("%s-%s", cfg.Name(), m.Tag().String()) machineTags[tags.JujuMachine] = machineId return machineTags, nil }
c4224
:= range subnets { warningPrefix := fmt.Sprintf( "not using subnet %q in space %q for machine %q provisioning: ", subnet.CIDR(), spaceName, m.Id(), ) providerId := subnet.ProviderId() if providerId == "" { logger.Warningf(warningPrefix + "no ProviderId set") continue } // TODO(dimitern): Once state.Subnet supports multiple zones, // use all of them below. // // LKK Card: https://canonical.leankit.com/Boards/View/101652562/119979611 zone := subnet.AvailabilityZone() if zone == "" { logger.Warningf(warningPrefix + "no availability zone(s) set") continue } subnetsToZones[string(providerId)] = []string{zone} } return subnetsToZones, nil }
c4225
!= nil { return nil, errors.Trace(err) } ch, _, err := app.Charm() if err != nil { return nil, errors.Trace(err) } profile := ch.LXDProfile() if profile == nil || (profile != nil && profile.Empty()) { continue } pName := lxdprofile.Name(p.m.Name(), app.Name(), ch.Revision()) // Lock here, we get a new env for every call to ProvisioningInfo(). p.mu.Lock() if err := profileEnv.MaybeWriteLXDProfile(pName, profile); err != nil { p.mu.Unlock() return nil, errors.Trace(err) } p.mu.Unlock() names = append(names, pName) } return names, nil }
c4226
err := p.findImageMetadata(imageConstraint, env) if err != nil { return nil, errors.Trace(err) } sort.Sort(metadataList(data)) logger.Debugf("available image metadata for provisioning: %v", data) return data, nil }
c4227
// metadata specific to this region. spec, err := hasRegion.Region() if err != nil { // can't really find images if we cannot determine cloud region // TODO (anastasiamac 2015-12-03) or can we? return nil, errors.Annotate(err, "getting provider region information (cloud spec)") } lookup.CloudSpec = spec } return imagemetadata.NewImageConstraint(lookup), nil }
c4228
%d metadata", len(stateMetadata)) // No need to look in data sources if found in state. if len(stateMetadata) != 0 { return stateMetadata, nil } // If no metadata is found in state, fall back to original simple stream search. // Currently, an image metadata worker picks up this metadata periodically (daily), // and stores it in state. So potentially, this collection could be different // to what is in state. dsMetadata, err := p.imageMetadataFromDataSources(env, imageConstraint) if err != nil { if !errors.IsNotFound(err) { return nil, errors.Trace(err) } } logger.Debugf("got from data sources %d metadata", len(dsMetadata)) return dsMetadata, nil }
c4229
m.Series, Arch: m.Arch, VirtType: m.VirtType, RootStorageType: m.RootStorageType, RootStorageSize: m.RootStorageSize, Source: m.Source, Priority: m.Priority, } } var all []params.CloudImageMetadata for _, ms := range stored { for _, m := range ms { all = append(all, toParams(m)) } } return all, nil }
c4230
info.Source, source.Priority())) } } if len(metadataState) > 0 { if err := p.st.CloudImageMetadataStorage.SaveMetadata(metadataState); err != nil { // No need to react here, just take note logger.Warningf("failed to save published image metadata: %v", err) } } // Since we've fallen through to data sources search and have saved all needed images into controller, // let's try to get them from controller to avoid duplication of conversion logic here. all, err := p.imageMetadataFromState(constraint) if err != nil { return nil, errors.Annotate(err, "could not read metadata from controller after saving it there from data sources") } if len(all) == 0 { return nil, errors.NotFoundf("image metadata for series %v, arch %v", constraint.Series, constraint.Arches) } return all, nil }
c4231
m[i].Priority < m[j].Priority }
c4232
resp, err := client.Get(url.String()) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { // resp.Body is always non-nil. (see https://golang.org/pkg/net/http/#Response) resp.Body.Close() return nil, errors.Errorf("bad http response: %v", resp.Status) } return resp.Body, nil } }
c4233
actual != expected { err := errors.Errorf("expected sha256 %q, got %q", expected, actual) return errors.NewNotValid(err, "") } return nil } }
c4234
return err } s.life = life return nil }
c4235
len(results.Results) != 1 { return -1, fmt.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return -1, result.Error } return result.Result, nil }
c4236
data, }, }, } err := s.st.facade.FacadeCall("SetApplicationStatus", args, &result) if err != nil { return errors.Trace(err) } return result.OneError() }
c4237
{ Tag: tag.String(), }, }, } err := s.st.facade.FacadeCall("ApplicationStatus", args, &results) if err != nil { return params.ApplicationStatusResult{}, errors.Trace(err) } result := results.Results[0] if result.Error != nil { return params.ApplicationStatusResult{}, result.Error } return result, nil }
c4238
s.st.LeadershipSettings.WatchLeadershipSettings(s.tag.Id()) }
c4239
} rules = append(rules, rule) } if err := scanner.Err(); err != nil { return nil, errors.Annotate(err, "reading iptables output") } return rules, nil }
c4240
field, remainder = s[:i], strings.TrimLeft(s[i+1:], " ") return field, remainder, true }
c4241
nil { return nil, "", errors.Annotate(err, "getting tenant ID") } authURI.Path = "" adEndpoint := authURI.String() oauthConfig, err := adal.NewOAuthConfig(adEndpoint, tenantId) if err != nil { return nil, "", errors.Annotate(err, "getting OAuth configuration") } return oauthConfig, tenantId, nil }
c4242
nil, err } var err error env.compute, err = newCompute(cloud) if err != nil { return nil, err } return env, nil }
c4243
= LastSentResult{ LastSentInfo: LastSentInfo{ LastSentID: ids[i], RecordID: apiRes.RecordID, }, Error: common.RestoreError(apiRes.Error), } if apiRes.RecordTimestamp > 0 { results[i].RecordTimestamp = time.Unix(0, apiRes.RecordTimestamp) } } return results, nil }
c4244
var apiResults params.ErrorResults err := c.caller.FacadeCall("SetLastSent", args, &apiResults) if err != nil { return nil, errors.Trace(err) } results := make([]LastSentResult, len(reqs)) for i, apiRes := range apiResults.Results { results[i] = LastSentResult{ LastSentInfo: reqs[i], Error: common.RestoreError(apiRes.Error), } } return results, nil }
c4245
err != nil { return nil, errors.Trace(err) } r := &Reader{config: config} return r, nil }
c4246
for the first time, it'll be globalEpoch. t = globalEpoch } else if err != nil { return time.Time{}, errors.Trace(err) } return t, nil }
c4247
Entities: models, } if err := c.facade.FacadeCall("ModelStatus", req, &result); err != nil { return nil, err } return c.processModelStatusResults(result.Results) }
c4248
:= connectFallback(apiOpen, info, agentConfig.OldPassword()) if err != nil { return nil, errors.Trace(err) } return conn, nil }
c4249
2 * time.Second, RetryDelay: 500 * time.Millisecond, }) }
c4250
Version: archive.CharmVersion, } // Now update the charm data in state and mark it as no longer pending. _, err = st.UpdateUploadedCharm(info) if err != nil { alreadyUploaded := err == state.ErrCharmRevisionAlreadyModified || errors.Cause(err) == state.ErrCharmRevisionAlreadyModified || state.IsCharmAlreadyUploadedError(err) if err := storage.Remove(storagePath); err != nil { if alreadyUploaded { logger.Errorf("cannot remove duplicated charm archive from storage: %v", err) } else { logger.Errorf("cannot remove unsuccessfully recorded charm archive from storage: %v", err) } } if alreadyUploaded { // Somebody else managed to upload and update the charm in // state before us. This is not an error. return nil } return errors.Trace(err) } return nil }
c4251
if err != nil { return "", err } return fmt.Sprintf("charms/%s-%s", curl.String(), uuid), nil }
c4252
return &API{ ClientFacade: clientFacade, facade: facadeCaller, } }
c4253
space.String(), Zones: zones, }}, } err := api.facade.FacadeCall("AddSubnets", params, &response) if err != nil { return errors.Trace(err) } return response.OneError() }
c4254
zones, IsPublic: isPublic, }}, } err := api.facade.FacadeCall("CreateSubnets", params, &response) if err != nil { return errors.Trace(err) } return response.OneError() }
c4255
Zone: zone, } err := api.facade.FacadeCall("ListSubnets", args, &response) if err != nil { return nil, errors.Trace(err) } return response.Results, nil }
c4256
ExpireAfter: expiryTime, Sparse: true, }} }
c4257
return s.saveMetadata(metadata, false) }
c4258
s.saveMetadata(metadata, true) }
c4259
noOp() } allTxn := make([]txn.Op, len(imageMetadata)) for i, doc := range imageMetadata { allTxn[i] = deleteOperation(doc.Id) } return allTxn, nil } err := s.store.RunTransaction(buildTxn) if err != nil { return errors.Annotatef(err, "cannot delete metadata for cloud image %v", imageId) } return nil }
c4260
get all image metadata") } for _, doc := range docs { results = append(results, doc.metadata()) } return results, nil }
c4261
if len(docs) == 0 { return nil, errors.NotFoundf("matching cloud image metadata") } metadata := make(map[string][]Metadata) for _, doc := range docs { one := doc.metadata() metadata[one.Source] = append(metadata[one.Source], one) } return metadata, nil }
c4262
if err := coll.Find(buildSearchClauses(criteria)).Distinct("arch", &arches); err != nil { return nil, errors.Trace(err) } return arches, nil }
c4263
stor.Put(StateFile, bytes.NewBuffer(data), int64(len(data))) }
c4264
"", fmt.Errorf("cannot create initial state file: %v", err) } return stor.URL(StateFile) }
c4265
!= nil { return err } return putState(storage, data) }
c4266
if err != nil { if errors.IsNotFound(err) { return nil, environs.ErrNotBootstrapped } return nil, err } return loadState(r) }
c4267
record state instance-id") } state.StateInstances = append(state.StateInstances, id) return SaveState(stor, state) }
c4268
head := state.StateInstances[:i] tail := state.StateInstances[i+1:] state.StateInstances = append(head, tail...) anyFound = true i-- break } } } if !anyFound { return nil } return SaveState(stor, state) }
c4269
err != nil { return nil, err } return st.StateInstances, nil }
c4270
common.AuthFuncForTagKind(names.UnitTagKind), ), ), AgentEntityWatcher: common.NewAgentEntityWatcher( st, resources, accessApplication, ), resources: resources, state: st, }, nil }
c4271
if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Result = exposed } return results, nil }
c4272
if err != nil { return block.ProcessBlockedError(err, block.BlockChange) } for i, result := range results { if result.Error != nil { fmt.Fprintf(context.Stderr, "cannot import key id %q: %v\n", c.sshKeyIds[i], result.Error) } } return nil }
c4273
[]string{params.Series}, Arches: params.Architectures, }) } matchingTools, resolveInfo, err := Fetch(params.Sources, toolsConstraint) if err != nil { return nil, resolveInfo, err } if len(matchingTools) == 0 { return nil, resolveInfo, fmt.Errorf("no matching agent binaries found for constraint %+v", toolsConstraint) } versions := make([]string, len(matchingTools)) for i, tm := range matchingTools { vers := version.Binary{ Number: version.MustParse(tm.Version), Series: tm.Release, Arch: tm.Arch, } versions[i] = vers.String() } return versions, resolveInfo, nil }
c4274
C: firewallRulesC, Id: serviceStr, Assert: txn.DocExists, Update: bson.D{ {"$set", bson.D{{"whitelist-cidrs", rule.WhitelistCIDRs}}}, }, }, model.assertActiveOp()} } else { doc.WhitelistCIDRS = rule.WhitelistCIDRs ops = []txn.Op{{ C: firewallRulesC, Id: doc.Id, Assert: txn.DocMissing, Insert: doc, }, model.assertActiveOp()} } return ops, nil } if err := fw.st.db().Run(buildTxn); err != nil { return errors.Annotate(err, "failed to create firewall rules") } return nil }
c4275
firewallRulesDoc err := coll.FindId(string(service)).One(&doc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("firewall rules for service %v", service) } if err != nil { return nil, errors.Trace(err) } return doc.toRule(), nil }
c4276
result := make([]*FirewallRule, len(docs)) for i, doc := range docs { result[i] = doc.toRule() } return result, nil }
c4277
err := w.machineLock.Acquire(spec) if err != nil { return nil, errors.Trace(err) } return releaser, nil }
c4278
:= createPermissionOp(cloudGlobalKey(cloud), userGlobalKey(userAccessID(user)), access) err := st.db().RunTransaction([]txn.Op{op}) if err == txn.ErrAborted { err = errors.AlreadyExistsf("permission for user %q for cloud %q", user.Id(), cloud) } return errors.Trace(err) }
c4279
:= st.userPermission(cloudGlobalKey(cloud), userGlobalKey(userAccessID(user))) if err != nil { return "", errors.Trace(err) } return perm.access(), nil }
c4280
_, p := range perms { result[userIDFromGlobalKey(p.doc.SubjectGlobalKey)] = p.access() } return result, nil }
c4281
error) { _, err := st.GetCloudAccess(cloud, user) if err != nil { return nil, errors.Trace(err) } ops := []txn.Op{updatePermissionOp(cloudGlobalKey(cloud), userGlobalKey(userAccessID(user)), access)} return ops, nil } err := st.db().Run(buildTxn) return errors.Trace(err) }
c4282
ops := []txn.Op{removePermissionOp(cloudGlobalKey(cloud), userGlobalKey(userAccessID(user)))} return ops, nil } err := st.db().Run(buildTxn) return errors.Trace(err) }
c4283
get all the clouds. cloudQuery = clouds.Find(nil) } else { cloudNames, err := st.cloudNamesForUser(user) if err != nil { return nil, errors.Trace(err) } cloudQuery = clouds.Find(bson.M{ "_id": bson.M{"$in": cloudNames}, }) } cloudQuery = cloudQuery.Sort("name") var cloudDocs []cloudDoc if err := cloudQuery.All(&cloudDocs); err != nil { return nil, errors.Trace(err) } result := make([]CloudInfo, len(cloudDocs)) for i, c := range cloudDocs { result[i] = CloudInfo{ Cloud: c.toCloud(), } } if err := st.fillInCloudUserAccess(user, result); err != nil { return nil, errors.Trace(err) } return result, nil }
c4284
permissionDoc iter := query.Iter() var cloudNames []string for iter.Next(&doc) { cloudName := strings.TrimPrefix(doc.ObjectGlobalKey, "cloud#") cloudNames = append(cloudNames, cloudName) } if err := iter.Close(); err != nil { return nil, errors.Trace(err) } return cloudNames, nil }
c4285
series, CloudInitConfigDir: cloudInitConfigDir, CloudInitInstanceConfigDir: cloudInitInstanceConfigDir, CurtinInstallConfigFile: curtinInstallConfigFile, } return NewMachineInitReaderFromConfig(cfg), nil }
c4286
return nil, errors.Trace(err) } file := filepath.Join(r.config.CloudInitInstanceConfigDir, "vendor-data.txt") vendorData, err := r.unmarshallConfigFile(file) if err != nil { return nil, errors.Trace(err) } for k, v := range vendorData { machineCloudInitData[k] = v } _, curtinData, err := fileAsConfigMap(r.config.CurtinInstallConfigFile) if err != nil { return nil, errors.Trace(err) } for k, v := range curtinData { machineCloudInitData[k] = v } return machineCloudInitData, nil }
c4287
sort.Sort(sortedFiles) cloudInit := make(map[string]interface{}) for _, file := range files { name := file.Name() if !strings.HasSuffix(name, ".cfg") { continue } _, cloudCfgData, err := fileAsConfigMap(filepath.Join(dir, name)) if err != nil { return nil, errors.Trace(err) } for k, v := range cloudCfgData { cloudInit[k] = v } } return cloudInit, nil }
c4288
During testing, it was found that the trusty vendor-data.txt.i file // can contain only the text "NONE", which doesn't unmarshall or decompress // we don't want to fail in that case. if r.config.Series == "trusty" { logger.Debugf("failed to unmarshall or decompress %q: %s", file, err) return nil, nil } return nil, errors.Annotatef(err, "cannot unmarshall or decompress %q", file) } cfg, err := bytesAsConfigMap(decodedZippedBuf) return cfg, errors.Trace(err) }
c4289
nil } cfg, err := bytesAsConfigMap(raw) if err != nil { return raw, cfg, errors.NotValidf("converting %q contents to map: %s", file, err.Error()) } return raw, cfg, nil }
c4290
} } } } else { log.Debugf("%s not found in machine init data", key) } case "ca-certs": // No translation needed, ca-certs the same in both versions of Cloud-Init. if val, ok := cfg[key]; ok { foundDataMap[key] = val } else { log.Debugf("%s not found in machine init data", key) } } } return foundDataMap }
c4291
assumption // that provisioning trusty machines on much newer MAAS // versions is highly unlikely. log.Debugf("%q ignored for this machine series", key) case "apt-security": // Translation for apt-security unknown at this time. log.Debugf("%q ignored for this machine series", key) case "ca-certs": // No translation needed, ca-certs the same in both versions of Cloud-Init. if val, ok := cfg[key]; ok { foundDataMap[key] = val } else { log.Debugf("%s not found in machine init data", key) } } } return foundDataMap }
c4292
:= csClient.Get(endpoint, &m); err != nil { return nil, errors.Trace(err) } return m, nil }
c4293
return nil, errors.Trace(err) } return common.Watch(c.facade, "Watch", appTag) }
c4294
:= len(results.Results); n != 1 { return "", errors.Errorf("expected 1 result, got %d", n) } if err := results.Results[0].Error; err != nil { return "", maybeNotFound(err) } return life.Value(results.Results[0].Life), nil }
c4295
:= len(results.Results); n != 1 { return false, errors.Errorf("expected 1 result, got %d", n) } if err := results.Results[0].Error; err != nil { return false, maybeNotFound(err) } return results.Results[0].Result, nil }
c4296
p.arch } return arch.HostArch() }
c4297
} if d.Driver() == "raw" { ds = true } } if !ds { return errors.Trace(errors.Errorf("missing data source disk")) } if !fs { return errors.Trace(errors.Errorf("missing system disk")) } return nil }
c4298
err != nil { return errors.Annotatef(err, "failed to write domain xml for %q", params.Host()) } out, err := params.runCmdAsRoot("", virsh, "define", domainPath) if err != nil { return errors.Annotatef(err, "failed to defined the domain for %q from %s", params.Host(), domainPath) } logger.Debugf("created domain: %s", out) out, err = params.runCmdAsRoot("", virsh, "start", params.Host()) if err != nil { return errors.Annotatef(err, "failed to start domain %q", params.Host()) } logger.Debugf("started domain: %s", out) return err }
c4299
p.runCmd = runAsLibvirt } if p.runCmdAsRoot == nil { p.runCmdAsRoot = run } }