id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,600 | juju/juju | worker/uniter/relation/state.go | Exists | func (d *StateDir) Exists() bool {
_, err := os.Stat(d.path)
return err == nil
} | go | func (d *StateDir) Exists() bool {
_, err := os.Stat(d.path)
return err == nil
} | [
"func",
"(",
"d",
"*",
"StateDir",
")",
"Exists",
"(",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"d",
".",
"path",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // Exists returns true if the directory for this state exists. | [
"Exists",
"returns",
"true",
"if",
"the",
"directory",
"for",
"this",
"state",
"exists",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/relation/state.go#L188-L191 |
4,601 | juju/juju | worker/uniter/relation/state.go | Write | func (d *StateDir) Write(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.RemoteUnit)
if hi.Kind == hooks.RelationBroken {
return d.Remove()
}
name := strings.Replace(hi.RemoteUnit, "/", "-", 1)
path := filepath.Join(d.path, name)
if hi.Kind == hooks.RelationDeparted {
if err = os.Remove(path); err != nil && !os.IsNotExist(err) {
return err
}
// If atomic delete succeeded, update own state.
delete(d.state.Members, hi.RemoteUnit)
return nil
}
di := diskInfo{&hi.ChangeVersion, hi.Kind == hooks.RelationJoined}
if err := utils.WriteYaml(path, &di); err != nil {
return err
}
// If write was successful, update own state.
d.state.Members[hi.RemoteUnit] = hi.ChangeVersion
if hi.Kind == hooks.RelationJoined {
d.state.ChangedPending = hi.RemoteUnit
} else {
d.state.ChangedPending = ""
}
return nil
} | go | func (d *StateDir) Write(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.RemoteUnit)
if hi.Kind == hooks.RelationBroken {
return d.Remove()
}
name := strings.Replace(hi.RemoteUnit, "/", "-", 1)
path := filepath.Join(d.path, name)
if hi.Kind == hooks.RelationDeparted {
if err = os.Remove(path); err != nil && !os.IsNotExist(err) {
return err
}
// If atomic delete succeeded, update own state.
delete(d.state.Members, hi.RemoteUnit)
return nil
}
di := diskInfo{&hi.ChangeVersion, hi.Kind == hooks.RelationJoined}
if err := utils.WriteYaml(path, &di); err != nil {
return err
}
// If write was successful, update own state.
d.state.Members[hi.RemoteUnit] = hi.ChangeVersion
if hi.Kind == hooks.RelationJoined {
d.state.ChangedPending = hi.RemoteUnit
} else {
d.state.ChangedPending = ""
}
return nil
} | [
"func",
"(",
"d",
"*",
"StateDir",
")",
"Write",
"(",
"hi",
"hook",
".",
"Info",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"hi",
".",
"Kind",
",",
"hi",
".",
"RemoteUnit",
")",
"\n",
"if",
"hi",
".",
"Kind",
"==",
"hooks",
".",
"RelationBroken",
"{",
"return",
"d",
".",
"Remove",
"(",
")",
"\n",
"}",
"\n",
"name",
":=",
"strings",
".",
"Replace",
"(",
"hi",
".",
"RemoteUnit",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"path",
":=",
"filepath",
".",
"Join",
"(",
"d",
".",
"path",
",",
"name",
")",
"\n",
"if",
"hi",
".",
"Kind",
"==",
"hooks",
".",
"RelationDeparted",
"{",
"if",
"err",
"=",
"os",
".",
"Remove",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// If atomic delete succeeded, update own state.",
"delete",
"(",
"d",
".",
"state",
".",
"Members",
",",
"hi",
".",
"RemoteUnit",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"di",
":=",
"diskInfo",
"{",
"&",
"hi",
".",
"ChangeVersion",
",",
"hi",
".",
"Kind",
"==",
"hooks",
".",
"RelationJoined",
"}",
"\n",
"if",
"err",
":=",
"utils",
".",
"WriteYaml",
"(",
"path",
",",
"&",
"di",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// If write was successful, update own state.",
"d",
".",
"state",
".",
"Members",
"[",
"hi",
".",
"RemoteUnit",
"]",
"=",
"hi",
".",
"ChangeVersion",
"\n",
"if",
"hi",
".",
"Kind",
"==",
"hooks",
".",
"RelationJoined",
"{",
"d",
".",
"state",
".",
"ChangedPending",
"=",
"hi",
".",
"RemoteUnit",
"\n",
"}",
"else",
"{",
"d",
".",
"state",
".",
"ChangedPending",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Write atomically writes to disk the relation state change in hi.
// It must be called after the respective hook was executed successfully.
// Write doesn't validate hi but guarantees that successive writes of
// the same hi are idempotent. | [
"Write",
"atomically",
"writes",
"to",
"disk",
"the",
"relation",
"state",
"change",
"in",
"hi",
".",
"It",
"must",
"be",
"called",
"after",
"the",
"respective",
"hook",
"was",
"executed",
"successfully",
".",
"Write",
"doesn",
"t",
"validate",
"hi",
"but",
"guarantees",
"that",
"successive",
"writes",
"of",
"the",
"same",
"hi",
"are",
"idempotent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/relation/state.go#L197-L224 |
4,602 | juju/juju | worker/applicationscaler/manifold.go | start | func (config ManifoldConfig) start(apiCaller base.APICaller) (worker.Worker, error) {
facade, err := config.NewFacade(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
return config.NewWorker(Config{
Facade: facade,
})
} | go | func (config ManifoldConfig) start(apiCaller base.APICaller) (worker.Worker, error) {
facade, err := config.NewFacade(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
return config.NewWorker(Config{
Facade: facade,
})
} | [
"func",
"(",
"config",
"ManifoldConfig",
")",
"start",
"(",
"apiCaller",
"base",
".",
"APICaller",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"facade",
",",
"err",
":=",
"config",
".",
"NewFacade",
"(",
"apiCaller",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"config",
".",
"NewWorker",
"(",
"Config",
"{",
"Facade",
":",
"facade",
",",
"}",
")",
"\n",
"}"
] | // start is a method on ManifoldConfig because that feels a bit cleaner
// than closing over config in Manifold. | [
"start",
"is",
"a",
"method",
"on",
"ManifoldConfig",
"because",
"that",
"feels",
"a",
"bit",
"cleaner",
"than",
"closing",
"over",
"config",
"in",
"Manifold",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/applicationscaler/manifold.go#L25-L33 |
4,603 | juju/juju | worker/applicationscaler/manifold.go | Manifold | func Manifold(config ManifoldConfig) dependency.Manifold {
return engine.APIManifold(
engine.APIManifoldConfig{config.APICallerName},
config.start,
)
} | go | func Manifold(config ManifoldConfig) dependency.Manifold {
return engine.APIManifold(
engine.APIManifoldConfig{config.APICallerName},
config.start,
)
} | [
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"return",
"engine",
".",
"APIManifold",
"(",
"engine",
".",
"APIManifoldConfig",
"{",
"config",
".",
"APICallerName",
"}",
",",
"config",
".",
"start",
",",
")",
"\n",
"}"
] | // Manifold returns a dependency.Manifold that runs an applicationscaler worker. | [
"Manifold",
"returns",
"a",
"dependency",
".",
"Manifold",
"that",
"runs",
"an",
"applicationscaler",
"worker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/applicationscaler/manifold.go#L36-L41 |
4,604 | juju/juju | environs/tags/tags.go | ResourceTags | func ResourceTags(modelTag names.ModelTag, controllerTag names.ControllerTag, taggers ...ResourceTagger) map[string]string {
allTags := make(map[string]string)
for _, tagger := range taggers {
tags, ok := tagger.ResourceTags()
if !ok {
continue
}
for k, v := range tags {
allTags[k] = v
}
}
allTags[JujuModel] = modelTag.Id()
allTags[JujuController] = controllerTag.Id()
return allTags
} | go | func ResourceTags(modelTag names.ModelTag, controllerTag names.ControllerTag, taggers ...ResourceTagger) map[string]string {
allTags := make(map[string]string)
for _, tagger := range taggers {
tags, ok := tagger.ResourceTags()
if !ok {
continue
}
for k, v := range tags {
allTags[k] = v
}
}
allTags[JujuModel] = modelTag.Id()
allTags[JujuController] = controllerTag.Id()
return allTags
} | [
"func",
"ResourceTags",
"(",
"modelTag",
"names",
".",
"ModelTag",
",",
"controllerTag",
"names",
".",
"ControllerTag",
",",
"taggers",
"...",
"ResourceTagger",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"allTags",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"tagger",
":=",
"range",
"taggers",
"{",
"tags",
",",
"ok",
":=",
"tagger",
".",
"ResourceTags",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"tags",
"{",
"allTags",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"allTags",
"[",
"JujuModel",
"]",
"=",
"modelTag",
".",
"Id",
"(",
")",
"\n",
"allTags",
"[",
"JujuController",
"]",
"=",
"controllerTag",
".",
"Id",
"(",
")",
"\n",
"return",
"allTags",
"\n",
"}"
] | // ResourceTags returns tags to set on an infrastructure resource
// for the specified Juju environment. | [
"ResourceTags",
"returns",
"tags",
"to",
"set",
"on",
"an",
"infrastructure",
"resource",
"for",
"the",
"specified",
"Juju",
"environment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/tags/tags.go#L55-L69 |
4,605 | juju/juju | logfwd/origin.go | Validate | func (ot OriginType) Validate() error {
// As noted above, typedef'ing int means that the use of int
// literals or explicit type conversion could result in unsupported
// "enum" values. Otherwise OriginType would not need this method.
if _, ok := originTypes[ot]; !ok {
return errors.NewNotValid(nil, "unsupported origin type")
}
return nil
} | go | func (ot OriginType) Validate() error {
// As noted above, typedef'ing int means that the use of int
// literals or explicit type conversion could result in unsupported
// "enum" values. Otherwise OriginType would not need this method.
if _, ok := originTypes[ot]; !ok {
return errors.NewNotValid(nil, "unsupported origin type")
}
return nil
} | [
"func",
"(",
"ot",
"OriginType",
")",
"Validate",
"(",
")",
"error",
"{",
"// As noted above, typedef'ing int means that the use of int",
"// literals or explicit type conversion could result in unsupported",
"// \"enum\" values. Otherwise OriginType would not need this method.",
"if",
"_",
",",
"ok",
":=",
"originTypes",
"[",
"ot",
"]",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate ensures that the origin type is correct. | [
"Validate",
"ensures",
"that",
"the",
"origin",
"type",
"is",
"correct",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L58-L66 |
4,606 | juju/juju | logfwd/origin.go | ValidateName | func (ot OriginType) ValidateName(name string) error {
switch ot {
case OriginTypeUnknown:
if name != "" {
return errors.NewNotValid(nil, "origin name must not be set if type is unknown")
}
case OriginTypeUser:
if !names.IsValidUser(name) {
return errors.NewNotValid(nil, "bad user name")
}
case OriginTypeMachine:
if !names.IsValidMachine(name) {
return errors.NewNotValid(nil, "bad machine name")
}
case OriginTypeUnit:
if !names.IsValidUnit(name) {
return errors.NewNotValid(nil, "bad unit name")
}
}
return nil
} | go | func (ot OriginType) ValidateName(name string) error {
switch ot {
case OriginTypeUnknown:
if name != "" {
return errors.NewNotValid(nil, "origin name must not be set if type is unknown")
}
case OriginTypeUser:
if !names.IsValidUser(name) {
return errors.NewNotValid(nil, "bad user name")
}
case OriginTypeMachine:
if !names.IsValidMachine(name) {
return errors.NewNotValid(nil, "bad machine name")
}
case OriginTypeUnit:
if !names.IsValidUnit(name) {
return errors.NewNotValid(nil, "bad unit name")
}
}
return nil
} | [
"func",
"(",
"ot",
"OriginType",
")",
"ValidateName",
"(",
"name",
"string",
")",
"error",
"{",
"switch",
"ot",
"{",
"case",
"OriginTypeUnknown",
":",
"if",
"name",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"OriginTypeUser",
":",
"if",
"!",
"names",
".",
"IsValidUser",
"(",
"name",
")",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"OriginTypeMachine",
":",
"if",
"!",
"names",
".",
"IsValidMachine",
"(",
"name",
")",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"OriginTypeUnit",
":",
"if",
"!",
"names",
".",
"IsValidUnit",
"(",
"name",
")",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidateName ensures that the given origin name is valid within the
// context of the origin type. | [
"ValidateName",
"ensures",
"that",
"the",
"given",
"origin",
"name",
"is",
"valid",
"within",
"the",
"context",
"of",
"the",
"origin",
"type",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L70-L90 |
4,607 | juju/juju | logfwd/origin.go | OriginForMachineAgent | func OriginForMachineAgent(tag names.MachineTag, controller, model string, ver version.Number) Origin {
return originForAgent(OriginTypeMachine, tag, controller, model, ver)
} | go | func OriginForMachineAgent(tag names.MachineTag, controller, model string, ver version.Number) Origin {
return originForAgent(OriginTypeMachine, tag, controller, model, ver)
} | [
"func",
"OriginForMachineAgent",
"(",
"tag",
"names",
".",
"MachineTag",
",",
"controller",
",",
"model",
"string",
",",
"ver",
"version",
".",
"Number",
")",
"Origin",
"{",
"return",
"originForAgent",
"(",
"OriginTypeMachine",
",",
"tag",
",",
"controller",
",",
"model",
",",
"ver",
")",
"\n",
"}"
] | // OriginForMachineAgent populates a new origin for the agent. | [
"OriginForMachineAgent",
"populates",
"a",
"new",
"origin",
"for",
"the",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L116-L118 |
4,608 | juju/juju | logfwd/origin.go | OriginForUnitAgent | func OriginForUnitAgent(tag names.UnitTag, controller, model string, ver version.Number) Origin {
return originForAgent(OriginTypeUnit, tag, controller, model, ver)
} | go | func OriginForUnitAgent(tag names.UnitTag, controller, model string, ver version.Number) Origin {
return originForAgent(OriginTypeUnit, tag, controller, model, ver)
} | [
"func",
"OriginForUnitAgent",
"(",
"tag",
"names",
".",
"UnitTag",
",",
"controller",
",",
"model",
"string",
",",
"ver",
"version",
".",
"Number",
")",
"Origin",
"{",
"return",
"originForAgent",
"(",
"OriginTypeUnit",
",",
"tag",
",",
"controller",
",",
"model",
",",
"ver",
")",
"\n",
"}"
] | // OriginForUnitAgent populates a new origin for the agent. | [
"OriginForUnitAgent",
"populates",
"a",
"new",
"origin",
"for",
"the",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L121-L123 |
4,609 | juju/juju | logfwd/origin.go | OriginForJuju | func OriginForJuju(tag names.Tag, controller, model string, ver version.Number) (Origin, error) {
oType, err := ParseOriginType(tag.Kind())
if err != nil {
return Origin{}, errors.Annotate(err, "invalid tag")
}
return originForJuju(oType, tag.Id(), controller, model, ver), nil
} | go | func OriginForJuju(tag names.Tag, controller, model string, ver version.Number) (Origin, error) {
oType, err := ParseOriginType(tag.Kind())
if err != nil {
return Origin{}, errors.Annotate(err, "invalid tag")
}
return originForJuju(oType, tag.Id(), controller, model, ver), nil
} | [
"func",
"OriginForJuju",
"(",
"tag",
"names",
".",
"Tag",
",",
"controller",
",",
"model",
"string",
",",
"ver",
"version",
".",
"Number",
")",
"(",
"Origin",
",",
"error",
")",
"{",
"oType",
",",
"err",
":=",
"ParseOriginType",
"(",
"tag",
".",
"Kind",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Origin",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"originForJuju",
"(",
"oType",
",",
"tag",
".",
"Id",
"(",
")",
",",
"controller",
",",
"model",
",",
"ver",
")",
",",
"nil",
"\n",
"}"
] | // OriginForJuju populates a new origin for the juju client. | [
"OriginForJuju",
"populates",
"a",
"new",
"origin",
"for",
"the",
"juju",
"client",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L133-L139 |
4,610 | juju/juju | logfwd/origin.go | Validate | func (o Origin) Validate() error {
if o.ControllerUUID == "" {
return errors.NewNotValid(nil, "empty ControllerUUID")
}
if !names.IsValidModel(o.ControllerUUID) {
return errors.NewNotValid(nil, fmt.Sprintf("ControllerUUID %q not a valid UUID", o.ControllerUUID))
}
if o.ModelUUID == "" {
return errors.NewNotValid(nil, "empty ModelUUID")
}
if !names.IsValidModel(o.ModelUUID) {
return errors.NewNotValid(nil, fmt.Sprintf("ModelUUID %q not a valid UUID", o.ModelUUID))
}
if err := o.Type.Validate(); err != nil {
return errors.Annotate(err, "invalid Type")
}
if o.Name == "" && o.Type != OriginTypeUnknown {
return errors.NewNotValid(nil, "empty Name")
}
if err := o.Type.ValidateName(o.Name); err != nil {
return errors.Annotatef(err, "invalid Name %q", o.Name)
}
if !o.Software.isZero() {
if err := o.Software.Validate(); err != nil {
return errors.Annotate(err, "invalid Software")
}
}
return nil
} | go | func (o Origin) Validate() error {
if o.ControllerUUID == "" {
return errors.NewNotValid(nil, "empty ControllerUUID")
}
if !names.IsValidModel(o.ControllerUUID) {
return errors.NewNotValid(nil, fmt.Sprintf("ControllerUUID %q not a valid UUID", o.ControllerUUID))
}
if o.ModelUUID == "" {
return errors.NewNotValid(nil, "empty ModelUUID")
}
if !names.IsValidModel(o.ModelUUID) {
return errors.NewNotValid(nil, fmt.Sprintf("ModelUUID %q not a valid UUID", o.ModelUUID))
}
if err := o.Type.Validate(); err != nil {
return errors.Annotate(err, "invalid Type")
}
if o.Name == "" && o.Type != OriginTypeUnknown {
return errors.NewNotValid(nil, "empty Name")
}
if err := o.Type.ValidateName(o.Name); err != nil {
return errors.Annotatef(err, "invalid Name %q", o.Name)
}
if !o.Software.isZero() {
if err := o.Software.Validate(); err != nil {
return errors.Annotate(err, "invalid Software")
}
}
return nil
} | [
"func",
"(",
"o",
"Origin",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"o",
".",
"ControllerUUID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"names",
".",
"IsValidModel",
"(",
"o",
".",
"ControllerUUID",
")",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"o",
".",
"ControllerUUID",
")",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"ModelUUID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"names",
".",
"IsValidModel",
"(",
"o",
".",
"ModelUUID",
")",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"o",
".",
"ModelUUID",
")",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"o",
".",
"Type",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"Name",
"==",
"\"",
"\"",
"&&",
"o",
".",
"Type",
"!=",
"OriginTypeUnknown",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"o",
".",
"Type",
".",
"ValidateName",
"(",
"o",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"o",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"o",
".",
"Software",
".",
"isZero",
"(",
")",
"{",
"if",
"err",
":=",
"o",
".",
"Software",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate ensures that the origin is correct. | [
"Validate",
"ensures",
"that",
"the",
"origin",
"is",
"correct",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L156-L189 |
4,611 | juju/juju | logfwd/origin.go | Validate | func (sw Software) Validate() error {
if sw.PrivateEnterpriseNumber <= 0 {
return errors.NewNotValid(nil, "missing PrivateEnterpriseNumber")
}
if sw.Name == "" {
return errors.NewNotValid(nil, "empty Name")
}
if sw.Version == version.Zero {
return errors.NewNotValid(nil, "empty Version")
}
return nil
} | go | func (sw Software) Validate() error {
if sw.PrivateEnterpriseNumber <= 0 {
return errors.NewNotValid(nil, "missing PrivateEnterpriseNumber")
}
if sw.Name == "" {
return errors.NewNotValid(nil, "empty Name")
}
if sw.Version == version.Zero {
return errors.NewNotValid(nil, "empty Version")
}
return nil
} | [
"func",
"(",
"sw",
"Software",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"sw",
".",
"PrivateEnterpriseNumber",
"<=",
"0",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"sw",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"sw",
".",
"Version",
"==",
"version",
".",
"Zero",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate ensures that the software info is correct. | [
"Validate",
"ensures",
"that",
"the",
"software",
"info",
"is",
"correct",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/origin.go#L220-L231 |
4,612 | juju/juju | worker/apiaddressupdater/apiaddressupdater.go | Handle | func (c *APIAddressUpdater) Handle(_ <-chan struct{}) error {
hpsToSet, err := c.getAddresses()
if err != nil {
return err
}
logger.Debugf("updating API hostPorts to %+v", hpsToSet)
c.mu.Lock()
c.current = hpsToSet
c.mu.Unlock()
if err := c.setter.SetAPIHostPorts(hpsToSet); err != nil {
return fmt.Errorf("error setting addresses: %v", err)
}
return nil
} | go | func (c *APIAddressUpdater) Handle(_ <-chan struct{}) error {
hpsToSet, err := c.getAddresses()
if err != nil {
return err
}
logger.Debugf("updating API hostPorts to %+v", hpsToSet)
c.mu.Lock()
c.current = hpsToSet
c.mu.Unlock()
if err := c.setter.SetAPIHostPorts(hpsToSet); err != nil {
return fmt.Errorf("error setting addresses: %v", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"APIAddressUpdater",
")",
"Handle",
"(",
"_",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"hpsToSet",
",",
"err",
":=",
"c",
".",
"getAddresses",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"hpsToSet",
")",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"current",
"=",
"hpsToSet",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"setter",
".",
"SetAPIHostPorts",
"(",
"hpsToSet",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Handle is part of the watcher.NotifyHandler interface. | [
"Handle",
"is",
"part",
"of",
"the",
"watcher",
".",
"NotifyHandler",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/apiaddressupdater/apiaddressupdater.go#L68-L81 |
4,613 | juju/juju | container/broker/lxd-broker.go | AllInstances | func (broker *lxdBroker) AllInstances(ctx context.ProviderCallContext) (result []instances.Instance, err error) {
return broker.manager.ListContainers()
} | go | func (broker *lxdBroker) AllInstances(ctx context.ProviderCallContext) (result []instances.Instance, err error) {
return broker.manager.ListContainers()
} | [
"func",
"(",
"broker",
"*",
"lxdBroker",
")",
"AllInstances",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"result",
"[",
"]",
"instances",
".",
"Instance",
",",
"err",
"error",
")",
"{",
"return",
"broker",
".",
"manager",
".",
"ListContainers",
"(",
")",
"\n",
"}"
] | // AllInstances only returns running containers. | [
"AllInstances",
"only",
"returns",
"running",
"containers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/broker/lxd-broker.go#L173-L175 |
4,614 | juju/juju | container/broker/lxd-broker.go | MaintainInstance | func (broker *lxdBroker) MaintainInstance(ctx context.ProviderCallContext, args environs.StartInstanceParams) error {
machineID := args.InstanceConfig.MachineId
// There's no InterfaceInfo we expect to get below.
_, err := prepareOrGetContainerInterfaceInfo(
broker.api,
machineID,
false, // maintain, do not allocate.
lxdLogger,
)
return err
} | go | func (broker *lxdBroker) MaintainInstance(ctx context.ProviderCallContext, args environs.StartInstanceParams) error {
machineID := args.InstanceConfig.MachineId
// There's no InterfaceInfo we expect to get below.
_, err := prepareOrGetContainerInterfaceInfo(
broker.api,
machineID,
false, // maintain, do not allocate.
lxdLogger,
)
return err
} | [
"func",
"(",
"broker",
"*",
"lxdBroker",
")",
"MaintainInstance",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"StartInstanceParams",
")",
"error",
"{",
"machineID",
":=",
"args",
".",
"InstanceConfig",
".",
"MachineId",
"\n\n",
"// There's no InterfaceInfo we expect to get below.",
"_",
",",
"err",
":=",
"prepareOrGetContainerInterfaceInfo",
"(",
"broker",
".",
"api",
",",
"machineID",
",",
"false",
",",
"// maintain, do not allocate.",
"lxdLogger",
",",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // MaintainInstance ensures the container's host has the required iptables and
// routing rules to make the container visible to both the host and other
// machines on the same subnet. | [
"MaintainInstance",
"ensures",
"the",
"container",
"s",
"host",
"has",
"the",
"required",
"iptables",
"and",
"routing",
"rules",
"to",
"make",
"the",
"container",
"visible",
"to",
"both",
"the",
"host",
"and",
"other",
"machines",
"on",
"the",
"same",
"subnet",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/broker/lxd-broker.go#L180-L191 |
4,615 | juju/juju | container/broker/lxd-broker.go | LXDProfileNames | func (broker *lxdBroker) LXDProfileNames(containerName string) ([]string, error) {
nameRetriever, ok := broker.manager.(container.LXDProfileNameRetriever)
if !ok {
return make([]string, 0), nil
}
return nameRetriever.LXDProfileNames(containerName)
} | go | func (broker *lxdBroker) LXDProfileNames(containerName string) ([]string, error) {
nameRetriever, ok := broker.manager.(container.LXDProfileNameRetriever)
if !ok {
return make([]string, 0), nil
}
return nameRetriever.LXDProfileNames(containerName)
} | [
"func",
"(",
"broker",
"*",
"lxdBroker",
")",
"LXDProfileNames",
"(",
"containerName",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"nameRetriever",
",",
"ok",
":=",
"broker",
".",
"manager",
".",
"(",
"container",
".",
"LXDProfileNameRetriever",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nameRetriever",
".",
"LXDProfileNames",
"(",
"containerName",
")",
"\n",
"}"
] | // LXDProfileNames returns all the profiles for a container that the broker
// currently is aware of.
// LXDProfileNames implements environs.LXDProfiler. | [
"LXDProfileNames",
"returns",
"all",
"the",
"profiles",
"for",
"a",
"container",
"that",
"the",
"broker",
"currently",
"is",
"aware",
"of",
".",
"LXDProfileNames",
"implements",
"environs",
".",
"LXDProfiler",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/broker/lxd-broker.go#L196-L202 |
4,616 | juju/juju | state/modelgeneration.go | coreChange | func (c *itemChange) coreChange() settings.ItemChange {
return settings.ItemChange{
Type: c.Type,
Key: utils.UnescapeKey(c.Key),
OldValue: c.OldValue,
NewValue: c.NewValue,
}
} | go | func (c *itemChange) coreChange() settings.ItemChange {
return settings.ItemChange{
Type: c.Type,
Key: utils.UnescapeKey(c.Key),
OldValue: c.OldValue,
NewValue: c.NewValue,
}
} | [
"func",
"(",
"c",
"*",
"itemChange",
")",
"coreChange",
"(",
")",
"settings",
".",
"ItemChange",
"{",
"return",
"settings",
".",
"ItemChange",
"{",
"Type",
":",
"c",
".",
"Type",
",",
"Key",
":",
"utils",
".",
"UnescapeKey",
"(",
"c",
".",
"Key",
")",
",",
"OldValue",
":",
"c",
".",
"OldValue",
",",
"NewValue",
":",
"c",
".",
"NewValue",
",",
"}",
"\n",
"}"
] | // coreChange returns the core package representation of this change.
// Stored keys are unescaped. | [
"coreChange",
"returns",
"the",
"core",
"package",
"representation",
"of",
"this",
"change",
".",
"Stored",
"keys",
"are",
"unescaped",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L35-L42 |
4,617 | juju/juju | state/modelgeneration.go | Config | func (g *Generation) Config() map[string]settings.ItemChanges {
changes := make(map[string]settings.ItemChanges, len(g.doc.Config))
for appName, appCfg := range g.doc.Config {
appChanges := make(settings.ItemChanges, len(appCfg))
for i, ch := range appCfg {
appChanges[i] = ch.coreChange()
}
sort.Sort(appChanges)
changes[appName] = appChanges
}
return changes
} | go | func (g *Generation) Config() map[string]settings.ItemChanges {
changes := make(map[string]settings.ItemChanges, len(g.doc.Config))
for appName, appCfg := range g.doc.Config {
appChanges := make(settings.ItemChanges, len(appCfg))
for i, ch := range appCfg {
appChanges[i] = ch.coreChange()
}
sort.Sort(appChanges)
changes[appName] = appChanges
}
return changes
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"Config",
"(",
")",
"map",
"[",
"string",
"]",
"settings",
".",
"ItemChanges",
"{",
"changes",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"settings",
".",
"ItemChanges",
",",
"len",
"(",
"g",
".",
"doc",
".",
"Config",
")",
")",
"\n",
"for",
"appName",
",",
"appCfg",
":=",
"range",
"g",
".",
"doc",
".",
"Config",
"{",
"appChanges",
":=",
"make",
"(",
"settings",
".",
"ItemChanges",
",",
"len",
"(",
"appCfg",
")",
")",
"\n",
"for",
"i",
",",
"ch",
":=",
"range",
"appCfg",
"{",
"appChanges",
"[",
"i",
"]",
"=",
"ch",
".",
"coreChange",
"(",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"appChanges",
")",
"\n",
"changes",
"[",
"appName",
"]",
"=",
"appChanges",
"\n",
"}",
"\n",
"return",
"changes",
"\n",
"}"
] | // Config returns all changed charm configuration for the generation.
// The persisted objects are converted to core changes. | [
"Config",
"returns",
"all",
"changed",
"charm",
"configuration",
"for",
"the",
"generation",
".",
"The",
"persisted",
"objects",
"are",
"converted",
"to",
"core",
"changes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L118-L129 |
4,618 | juju/juju | state/modelgeneration.go | AssignApplication | func (g *Generation) AssignApplication(appName string) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if _, ok := g.doc.AssignedUnits[appName]; ok {
return nil, jujutxn.ErrNoOperations
}
if err := g.CheckNotComplete(); err != nil {
return nil, err
}
return assignGenerationAppTxnOps(g.doc.DocId, appName), nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | go | func (g *Generation) AssignApplication(appName string) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if _, ok := g.doc.AssignedUnits[appName]; ok {
return nil, jujutxn.ErrNoOperations
}
if err := g.CheckNotComplete(); err != nil {
return nil, err
}
return assignGenerationAppTxnOps(g.doc.DocId, appName), nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"AssignApplication",
"(",
"appName",
"string",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"g",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"g",
".",
"doc",
".",
"AssignedUnits",
"[",
"appName",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"CheckNotComplete",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"assignGenerationAppTxnOps",
"(",
"g",
".",
"doc",
".",
"DocId",
",",
"appName",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"errors",
".",
"Trace",
"(",
"g",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
")",
"\n",
"}"
] | // AssignApplication indicates that the application with the input name has had
// changes in this generation. | [
"AssignApplication",
"indicates",
"that",
"the",
"application",
"with",
"the",
"input",
"name",
"has",
"had",
"changes",
"in",
"this",
"generation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L154-L171 |
4,619 | juju/juju | state/modelgeneration.go | AssignAllUnits | func (g *Generation) AssignAllUnits(appName string) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if err := g.CheckNotComplete(); err != nil {
return nil, errors.Trace(err)
}
unitNames, err := appUnitNames(g.st, appName)
if err != nil {
return nil, errors.Trace(err)
}
app, err := g.st.Application(appName)
if err != nil {
return nil, errors.Trace(err)
}
ops := []txn.Op{
{
C: applicationsC,
Id: app.doc.DocID,
Assert: bson.D{
{"life", Alive},
{"unitcount", app.doc.UnitCount},
},
},
}
assignedUnits := set.NewStrings(g.doc.AssignedUnits[appName]...)
for _, name := range unitNames {
if !assignedUnits.Contains(name) {
unit, err := g.st.Unit(name)
if err != nil {
return nil, errors.Trace(err)
}
ops = append(ops, assignGenerationUnitTxnOps(g.doc.DocId, appName, unit)...)
}
}
// If there are no units to add to the generation, quit here.
if len(ops) < 2 {
return nil, jujutxn.ErrNoOperations
}
return ops, nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | go | func (g *Generation) AssignAllUnits(appName string) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if err := g.CheckNotComplete(); err != nil {
return nil, errors.Trace(err)
}
unitNames, err := appUnitNames(g.st, appName)
if err != nil {
return nil, errors.Trace(err)
}
app, err := g.st.Application(appName)
if err != nil {
return nil, errors.Trace(err)
}
ops := []txn.Op{
{
C: applicationsC,
Id: app.doc.DocID,
Assert: bson.D{
{"life", Alive},
{"unitcount", app.doc.UnitCount},
},
},
}
assignedUnits := set.NewStrings(g.doc.AssignedUnits[appName]...)
for _, name := range unitNames {
if !assignedUnits.Contains(name) {
unit, err := g.st.Unit(name)
if err != nil {
return nil, errors.Trace(err)
}
ops = append(ops, assignGenerationUnitTxnOps(g.doc.DocId, appName, unit)...)
}
}
// If there are no units to add to the generation, quit here.
if len(ops) < 2 {
return nil, jujutxn.ErrNoOperations
}
return ops, nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"AssignAllUnits",
"(",
"appName",
"string",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"g",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"CheckNotComplete",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"unitNames",
",",
"err",
":=",
"appUnitNames",
"(",
"g",
".",
"st",
",",
"appName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"g",
".",
"st",
".",
"Application",
"(",
"appName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"applicationsC",
",",
"Id",
":",
"app",
".",
"doc",
".",
"DocID",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Alive",
"}",
",",
"{",
"\"",
"\"",
",",
"app",
".",
"doc",
".",
"UnitCount",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"assignedUnits",
":=",
"set",
".",
"NewStrings",
"(",
"g",
".",
"doc",
".",
"AssignedUnits",
"[",
"appName",
"]",
"...",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"unitNames",
"{",
"if",
"!",
"assignedUnits",
".",
"Contains",
"(",
"name",
")",
"{",
"unit",
",",
"err",
":=",
"g",
".",
"st",
".",
"Unit",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"assignGenerationUnitTxnOps",
"(",
"g",
".",
"doc",
".",
"DocId",
",",
"appName",
",",
"unit",
")",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// If there are no units to add to the generation, quit here.",
"if",
"len",
"(",
"ops",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"g",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
")",
"\n",
"}"
] | // AssignAllUnits ensures that all units of the input application are
// designated as tracking the branch, by adding the unit names
// to the generation. | [
"AssignAllUnits",
"ensures",
"that",
"all",
"units",
"of",
"the",
"input",
"application",
"are",
"designated",
"as",
"tracking",
"the",
"branch",
"by",
"adding",
"the",
"unit",
"names",
"to",
"the",
"generation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L196-L241 |
4,620 | juju/juju | state/modelgeneration.go | AssignUnit | func (g *Generation) AssignUnit(unitName string) error {
appName, err := names.UnitApplication(unitName)
if err != nil {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if err := g.CheckNotComplete(); err != nil {
return nil, errors.Trace(err)
}
if set.NewStrings(g.doc.AssignedUnits[appName]...).Contains(unitName) {
return nil, jujutxn.ErrNoOperations
}
unit, err := g.st.Unit(unitName)
if err != nil {
return nil, errors.Trace(err)
}
return assignGenerationUnitTxnOps(g.doc.DocId, appName, unit), nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | go | func (g *Generation) AssignUnit(unitName string) error {
appName, err := names.UnitApplication(unitName)
if err != nil {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if err := g.CheckNotComplete(); err != nil {
return nil, errors.Trace(err)
}
if set.NewStrings(g.doc.AssignedUnits[appName]...).Contains(unitName) {
return nil, jujutxn.ErrNoOperations
}
unit, err := g.st.Unit(unitName)
if err != nil {
return nil, errors.Trace(err)
}
return assignGenerationUnitTxnOps(g.doc.DocId, appName, unit), nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"AssignUnit",
"(",
"unitName",
"string",
")",
"error",
"{",
"appName",
",",
"err",
":=",
"names",
".",
"UnitApplication",
"(",
"unitName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"g",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"CheckNotComplete",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"set",
".",
"NewStrings",
"(",
"g",
".",
"doc",
".",
"AssignedUnits",
"[",
"appName",
"]",
"...",
")",
".",
"Contains",
"(",
"unitName",
")",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"unit",
",",
"err",
":=",
"g",
".",
"st",
".",
"Unit",
"(",
"unitName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"assignGenerationUnitTxnOps",
"(",
"g",
".",
"doc",
".",
"DocId",
",",
"appName",
",",
"unit",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"errors",
".",
"Trace",
"(",
"g",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
")",
"\n",
"}"
] | // AssignUnit indicates that the unit with the input name is tracking this
// branch, by adding the name to the generation. | [
"AssignUnit",
"indicates",
"that",
"the",
"unit",
"with",
"the",
"input",
"name",
"is",
"tracking",
"this",
"branch",
"by",
"adding",
"the",
"name",
"to",
"the",
"generation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L245-L271 |
4,621 | juju/juju | state/modelgeneration.go | UpdateCharmConfig | func (g *Generation) UpdateCharmConfig(appName string, master *Settings, validChanges charm.Settings) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if err := g.CheckNotComplete(); err != nil {
return nil, errors.Trace(err)
}
// Apply the current branch deltas to the master settings.
branchChanges := g.Config()
branchDelta, branchHasDelta := branchChanges[appName]
if branchHasDelta {
master.applyChanges(branchDelta)
}
// Now apply the incoming changes on top and generate a new delta.
for k, v := range validChanges {
if v == nil {
master.Delete(k)
} else {
master.Set(k, v)
}
}
newDelta := master.changes()
// Ensure that the delta represents a change from master settings
// as they were when each setting was first modified under the branch.
if branchHasDelta {
var err error
if newDelta, err = newDelta.ApplyDeltaSource(branchDelta); err != nil {
return nil, errors.Trace(err)
}
}
return []txn.Op{
{
C: generationsC,
Id: g.doc.DocId,
Assert: bson.D{{"$and", []bson.D{
{{"completed", 0}},
{{"txn-revno", g.doc.TxnRevno}},
}}},
Update: bson.D{
{"$set", bson.D{{"charm-config." + appName, makeItemChanges(newDelta)}}},
},
},
}, nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | go | func (g *Generation) UpdateCharmConfig(appName string, master *Settings, validChanges charm.Settings) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if err := g.CheckNotComplete(); err != nil {
return nil, errors.Trace(err)
}
// Apply the current branch deltas to the master settings.
branchChanges := g.Config()
branchDelta, branchHasDelta := branchChanges[appName]
if branchHasDelta {
master.applyChanges(branchDelta)
}
// Now apply the incoming changes on top and generate a new delta.
for k, v := range validChanges {
if v == nil {
master.Delete(k)
} else {
master.Set(k, v)
}
}
newDelta := master.changes()
// Ensure that the delta represents a change from master settings
// as they were when each setting was first modified under the branch.
if branchHasDelta {
var err error
if newDelta, err = newDelta.ApplyDeltaSource(branchDelta); err != nil {
return nil, errors.Trace(err)
}
}
return []txn.Op{
{
C: generationsC,
Id: g.doc.DocId,
Assert: bson.D{{"$and", []bson.D{
{{"completed", 0}},
{{"txn-revno", g.doc.TxnRevno}},
}}},
Update: bson.D{
{"$set", bson.D{{"charm-config." + appName, makeItemChanges(newDelta)}}},
},
},
}, nil
}
return errors.Trace(g.st.db().Run(buildTxn))
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"UpdateCharmConfig",
"(",
"appName",
"string",
",",
"master",
"*",
"Settings",
",",
"validChanges",
"charm",
".",
"Settings",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"g",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"g",
".",
"CheckNotComplete",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Apply the current branch deltas to the master settings.",
"branchChanges",
":=",
"g",
".",
"Config",
"(",
")",
"\n",
"branchDelta",
",",
"branchHasDelta",
":=",
"branchChanges",
"[",
"appName",
"]",
"\n",
"if",
"branchHasDelta",
"{",
"master",
".",
"applyChanges",
"(",
"branchDelta",
")",
"\n",
"}",
"\n\n",
"// Now apply the incoming changes on top and generate a new delta.",
"for",
"k",
",",
"v",
":=",
"range",
"validChanges",
"{",
"if",
"v",
"==",
"nil",
"{",
"master",
".",
"Delete",
"(",
"k",
")",
"\n",
"}",
"else",
"{",
"master",
".",
"Set",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"newDelta",
":=",
"master",
".",
"changes",
"(",
")",
"\n\n",
"// Ensure that the delta represents a change from master settings",
"// as they were when each setting was first modified under the branch.",
"if",
"branchHasDelta",
"{",
"var",
"err",
"error",
"\n",
"if",
"newDelta",
",",
"err",
"=",
"newDelta",
".",
"ApplyDeltaSource",
"(",
"branchDelta",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"generationsC",
",",
"Id",
":",
"g",
".",
"doc",
".",
"DocId",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"[",
"]",
"bson",
".",
"D",
"{",
"{",
"{",
"\"",
"\"",
",",
"0",
"}",
"}",
",",
"{",
"{",
"\"",
"\"",
",",
"g",
".",
"doc",
".",
"TxnRevno",
"}",
"}",
",",
"}",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
"+",
"appName",
",",
"makeItemChanges",
"(",
"newDelta",
")",
"}",
"}",
"}",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"errors",
".",
"Trace",
"(",
"g",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
")",
"\n",
"}"
] | // UpdateCharmConfig applies the input changes to the input application's
// charm configuration under this branch.
// the incoming charm settings are assumed to have been validated. | [
"UpdateCharmConfig",
"applies",
"the",
"input",
"changes",
"to",
"the",
"input",
"application",
"s",
"charm",
"configuration",
"under",
"this",
"branch",
".",
"the",
"incoming",
"charm",
"settings",
"are",
"assumed",
"to",
"have",
"been",
"validated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L301-L354 |
4,622 | juju/juju | state/modelgeneration.go | Commit | func (g *Generation) Commit(userName string) (int, error) {
var newGenId int
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if g.IsCompleted() {
if g.GenerationId() == 0 {
return nil, errors.New("branch was already aborted")
}
return nil, jujutxn.ErrNoOperations
}
now, err := g.st.ControllerTimestamp()
if err != nil {
return nil, errors.Trace(err)
}
// Add all units who's applications have changed.
assigned := g.AssignedUnits()
for app := range assigned {
units, err := appUnitNames(g.st, app)
if err != nil {
return nil, errors.Trace(err)
}
assigned[app] = units
}
// Get the new sequence as late as we can.
// If assigned is empty, indicating no changes under this branch,
// then the generation ID in not incremented.
// This effectively means the generation is aborted, not committed.
if len(assigned) > 0 {
id, err := sequenceWithMin(g.st, "generation", 1)
if err != nil {
return nil, errors.Trace(err)
}
newGenId = id
}
// As a proxy for checking that the generation has not changed,
// Assert that the txn rev-no has not changed since we materialised
// this generation object.
ops := []txn.Op{
{
C: generationsC,
Id: g.doc.DocId,
Assert: bson.D{{"txn-revno", g.doc.TxnRevno}},
Update: bson.D{
{"$set", bson.D{
{"assigned-units", assigned},
{"completed", now.Unix()},
{"completed-by", userName},
{"generation-id", newGenId},
}},
},
},
}
return ops, nil
}
if err := g.st.db().Run(buildTxn); err != nil {
return 0, errors.Trace(err)
}
return newGenId, nil
} | go | func (g *Generation) Commit(userName string) (int, error) {
var newGenId int
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := g.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if g.IsCompleted() {
if g.GenerationId() == 0 {
return nil, errors.New("branch was already aborted")
}
return nil, jujutxn.ErrNoOperations
}
now, err := g.st.ControllerTimestamp()
if err != nil {
return nil, errors.Trace(err)
}
// Add all units who's applications have changed.
assigned := g.AssignedUnits()
for app := range assigned {
units, err := appUnitNames(g.st, app)
if err != nil {
return nil, errors.Trace(err)
}
assigned[app] = units
}
// Get the new sequence as late as we can.
// If assigned is empty, indicating no changes under this branch,
// then the generation ID in not incremented.
// This effectively means the generation is aborted, not committed.
if len(assigned) > 0 {
id, err := sequenceWithMin(g.st, "generation", 1)
if err != nil {
return nil, errors.Trace(err)
}
newGenId = id
}
// As a proxy for checking that the generation has not changed,
// Assert that the txn rev-no has not changed since we materialised
// this generation object.
ops := []txn.Op{
{
C: generationsC,
Id: g.doc.DocId,
Assert: bson.D{{"txn-revno", g.doc.TxnRevno}},
Update: bson.D{
{"$set", bson.D{
{"assigned-units", assigned},
{"completed", now.Unix()},
{"completed-by", userName},
{"generation-id", newGenId},
}},
},
},
}
return ops, nil
}
if err := g.st.db().Run(buildTxn); err != nil {
return 0, errors.Trace(err)
}
return newGenId, nil
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"Commit",
"(",
"userName",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"newGenId",
"int",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"g",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"g",
".",
"IsCompleted",
"(",
")",
"{",
"if",
"g",
".",
"GenerationId",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"now",
",",
"err",
":=",
"g",
".",
"st",
".",
"ControllerTimestamp",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Add all units who's applications have changed.",
"assigned",
":=",
"g",
".",
"AssignedUnits",
"(",
")",
"\n",
"for",
"app",
":=",
"range",
"assigned",
"{",
"units",
",",
"err",
":=",
"appUnitNames",
"(",
"g",
".",
"st",
",",
"app",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"assigned",
"[",
"app",
"]",
"=",
"units",
"\n",
"}",
"\n\n",
"// Get the new sequence as late as we can.",
"// If assigned is empty, indicating no changes under this branch,",
"// then the generation ID in not incremented.",
"// This effectively means the generation is aborted, not committed.",
"if",
"len",
"(",
"assigned",
")",
">",
"0",
"{",
"id",
",",
"err",
":=",
"sequenceWithMin",
"(",
"g",
".",
"st",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"newGenId",
"=",
"id",
"\n",
"}",
"\n\n",
"// As a proxy for checking that the generation has not changed,",
"// Assert that the txn rev-no has not changed since we materialised",
"// this generation object.",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"generationsC",
",",
"Id",
":",
"g",
".",
"doc",
".",
"DocId",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"g",
".",
"doc",
".",
"TxnRevno",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"assigned",
"}",
",",
"{",
"\"",
"\"",
",",
"now",
".",
"Unix",
"(",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"userName",
"}",
",",
"{",
"\"",
"\"",
",",
"newGenId",
"}",
",",
"}",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"g",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"newGenId",
",",
"nil",
"\n",
"}"
] | // Commit marks the generation as completed and assigns it the next value from
// the generation sequence. The new generation ID is returned. | [
"Commit",
"marks",
"the",
"generation",
"as",
"completed",
"and",
"assigns",
"it",
"the",
"next",
"value",
"from",
"the",
"generation",
"sequence",
".",
"The",
"new",
"generation",
"ID",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L358-L425 |
4,623 | juju/juju | state/modelgeneration.go | Refresh | func (g *Generation) Refresh() error {
col, closer := g.st.db().GetCollection(generationsC)
defer closer()
var doc generationDoc
if err := col.FindId(g.doc.DocId).One(&doc); err != nil {
return errors.Trace(err)
}
g.doc = doc
return nil
} | go | func (g *Generation) Refresh() error {
col, closer := g.st.db().GetCollection(generationsC)
defer closer()
var doc generationDoc
if err := col.FindId(g.doc.DocId).One(&doc); err != nil {
return errors.Trace(err)
}
g.doc = doc
return nil
} | [
"func",
"(",
"g",
"*",
"Generation",
")",
"Refresh",
"(",
")",
"error",
"{",
"col",
",",
"closer",
":=",
"g",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"generationsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"doc",
"generationDoc",
"\n",
"if",
"err",
":=",
"col",
".",
"FindId",
"(",
"g",
".",
"doc",
".",
"DocId",
")",
".",
"One",
"(",
"&",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"g",
".",
"doc",
"=",
"doc",
"\n",
"return",
"nil",
"\n",
"}"
] | // Refresh refreshes the contents of the generation from the underlying state. | [
"Refresh",
"refreshes",
"the",
"contents",
"of",
"the",
"generation",
"from",
"the",
"underlying",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L444-L454 |
4,624 | juju/juju | state/modelgeneration.go | AddBranch | func (m *Model) AddBranch(branchName, userName string) error {
return errors.Trace(m.st.AddBranch(branchName, userName))
} | go | func (m *Model) AddBranch(branchName, userName string) error {
return errors.Trace(m.st.AddBranch(branchName, userName))
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"AddBranch",
"(",
"branchName",
",",
"userName",
"string",
")",
"error",
"{",
"return",
"errors",
".",
"Trace",
"(",
"m",
".",
"st",
".",
"AddBranch",
"(",
"branchName",
",",
"userName",
")",
")",
"\n",
"}"
] | // AddBranch creates a new branch in the current model. | [
"AddBranch",
"creates",
"a",
"new",
"branch",
"in",
"the",
"current",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L457-L459 |
4,625 | juju/juju | state/modelgeneration.go | AddBranch | func (st *State) AddBranch(branchName, userName string) error {
id, err := sequence(st, "branch")
if err != nil {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if _, err := st.Branch(branchName); err != nil {
if !errors.IsNotFound(err) {
return nil, errors.Annotatef(err, "checking for existing branch")
}
} else {
return nil, errors.Errorf("model already has branch %q", branchName)
}
now, err := st.ControllerTimestamp()
if err != nil {
return nil, errors.Trace(err)
}
return insertGenerationTxnOps(strconv.Itoa(id), branchName, userName, now), nil
}
err = st.db().Run(buildTxn)
if err != nil {
err = onAbort(err, ErrDead)
logger.Errorf("cannot add branch to the model: %v", err)
}
return err
} | go | func (st *State) AddBranch(branchName, userName string) error {
id, err := sequence(st, "branch")
if err != nil {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if _, err := st.Branch(branchName); err != nil {
if !errors.IsNotFound(err) {
return nil, errors.Annotatef(err, "checking for existing branch")
}
} else {
return nil, errors.Errorf("model already has branch %q", branchName)
}
now, err := st.ControllerTimestamp()
if err != nil {
return nil, errors.Trace(err)
}
return insertGenerationTxnOps(strconv.Itoa(id), branchName, userName, now), nil
}
err = st.db().Run(buildTxn)
if err != nil {
err = onAbort(err, ErrDead)
logger.Errorf("cannot add branch to the model: %v", err)
}
return err
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AddBranch",
"(",
"branchName",
",",
"userName",
"string",
")",
"error",
"{",
"id",
",",
"err",
":=",
"sequence",
"(",
"st",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"st",
".",
"Branch",
"(",
"branchName",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"branchName",
")",
"\n",
"}",
"\n\n",
"now",
",",
"err",
":=",
"st",
".",
"ControllerTimestamp",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"insertGenerationTxnOps",
"(",
"strconv",
".",
"Itoa",
"(",
"id",
")",
",",
"branchName",
",",
"userName",
",",
"now",
")",
",",
"nil",
"\n",
"}",
"\n",
"err",
"=",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"onAbort",
"(",
"err",
",",
"ErrDead",
")",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // AddBranch creates a new branch in the current model.
// A branch cannot be created with the same name as another "in-flight" branch.
// The input user indicates the operator who invoked the creation. | [
"AddBranch",
"creates",
"a",
"new",
"branch",
"in",
"the",
"current",
"model",
".",
"A",
"branch",
"cannot",
"be",
"created",
"with",
"the",
"same",
"name",
"as",
"another",
"in",
"-",
"flight",
"branch",
".",
"The",
"input",
"user",
"indicates",
"the",
"operator",
"who",
"invoked",
"the",
"creation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L464-L491 |
4,626 | juju/juju | state/modelgeneration.go | Branches | func (m *Model) Branches() ([]*Generation, error) {
b, err := m.st.Branches()
return b, errors.Trace(err)
} | go | func (m *Model) Branches() ([]*Generation, error) {
b, err := m.st.Branches()
return b, errors.Trace(err)
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Branches",
"(",
")",
"(",
"[",
"]",
"*",
"Generation",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"m",
".",
"st",
".",
"Branches",
"(",
")",
"\n",
"return",
"b",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Branches returns all "in-flight" branches for the model. | [
"Branches",
"returns",
"all",
"in",
"-",
"flight",
"branches",
"for",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L511-L514 |
4,627 | juju/juju | state/modelgeneration.go | Branches | func (st *State) Branches() ([]*Generation, error) {
col, closer := st.db().GetCollection(generationsC)
defer closer()
var docs []generationDoc
if err := col.Find(bson.M{"completed": 0}).All(&docs); err != nil {
return nil, errors.Trace(err)
}
branches := make([]*Generation, len(docs))
for i, d := range docs {
branches[i] = newGeneration(st, &d)
}
return branches, nil
} | go | func (st *State) Branches() ([]*Generation, error) {
col, closer := st.db().GetCollection(generationsC)
defer closer()
var docs []generationDoc
if err := col.Find(bson.M{"completed": 0}).All(&docs); err != nil {
return nil, errors.Trace(err)
}
branches := make([]*Generation, len(docs))
for i, d := range docs {
branches[i] = newGeneration(st, &d)
}
return branches, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Branches",
"(",
")",
"(",
"[",
"]",
"*",
"Generation",
",",
"error",
")",
"{",
"col",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"generationsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"docs",
"[",
"]",
"generationDoc",
"\n",
"if",
"err",
":=",
"col",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"0",
"}",
")",
".",
"All",
"(",
"&",
"docs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"branches",
":=",
"make",
"(",
"[",
"]",
"*",
"Generation",
",",
"len",
"(",
"docs",
")",
")",
"\n",
"for",
"i",
",",
"d",
":=",
"range",
"docs",
"{",
"branches",
"[",
"i",
"]",
"=",
"newGeneration",
"(",
"st",
",",
"&",
"d",
")",
"\n",
"}",
"\n",
"return",
"branches",
",",
"nil",
"\n",
"}"
] | // Branches returns all "in-flight" branches. | [
"Branches",
"returns",
"all",
"in",
"-",
"flight",
"branches",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L517-L531 |
4,628 | juju/juju | state/modelgeneration.go | makeItemChanges | func makeItemChanges(coreChanges settings.ItemChanges) []itemChange {
changes := make([]itemChange, len(coreChanges))
for i, c := range coreChanges {
changes[i] = itemChange{
Type: c.Type,
Key: utils.EscapeKey(c.Key),
OldValue: c.OldValue,
NewValue: c.NewValue,
}
}
return changes
} | go | func makeItemChanges(coreChanges settings.ItemChanges) []itemChange {
changes := make([]itemChange, len(coreChanges))
for i, c := range coreChanges {
changes[i] = itemChange{
Type: c.Type,
Key: utils.EscapeKey(c.Key),
OldValue: c.OldValue,
NewValue: c.NewValue,
}
}
return changes
} | [
"func",
"makeItemChanges",
"(",
"coreChanges",
"settings",
".",
"ItemChanges",
")",
"[",
"]",
"itemChange",
"{",
"changes",
":=",
"make",
"(",
"[",
"]",
"itemChange",
",",
"len",
"(",
"coreChanges",
")",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"coreChanges",
"{",
"changes",
"[",
"i",
"]",
"=",
"itemChange",
"{",
"Type",
":",
"c",
".",
"Type",
",",
"Key",
":",
"utils",
".",
"EscapeKey",
"(",
"c",
".",
"Key",
")",
",",
"OldValue",
":",
"c",
".",
"OldValue",
",",
"NewValue",
":",
"c",
".",
"NewValue",
",",
"}",
"\n",
"}",
"\n",
"return",
"changes",
"\n",
"}"
] | // makeItemChanges generates a persistable collection of changes from a core
// settings representation, with keys escaped for Mongo. | [
"makeItemChanges",
"generates",
"a",
"persistable",
"collection",
"of",
"changes",
"from",
"a",
"core",
"settings",
"representation",
"with",
"keys",
"escaped",
"for",
"Mongo",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modelgeneration.go#L581-L592 |
4,629 | juju/juju | worker/uniter/runner/jujuc/pod-spec-set.go | NewPodSpecSetCommand | func NewPodSpecSetCommand(ctx Context) (cmd.Command, error) {
return &PodSpecSetCommand{ctx: ctx}, nil
} | go | func NewPodSpecSetCommand(ctx Context) (cmd.Command, error) {
return &PodSpecSetCommand{ctx: ctx}, nil
} | [
"func",
"NewPodSpecSetCommand",
"(",
"ctx",
"Context",
")",
"(",
"cmd",
".",
"Command",
",",
"error",
")",
"{",
"return",
"&",
"PodSpecSetCommand",
"{",
"ctx",
":",
"ctx",
"}",
",",
"nil",
"\n",
"}"
] | // NewPodSpecSetCommand makes a pod-spec-set command. | [
"NewPodSpecSetCommand",
"makes",
"a",
"pod",
"-",
"spec",
"-",
"set",
"command",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/jujuc/pod-spec-set.go#L23-L25 |
4,630 | juju/juju | worker/peergrouper/machinetracker.go | Id | func (m *machineTracker) Id() string {
m.mu.Lock()
defer m.mu.Unlock()
return m.id
} | go | func (m *machineTracker) Id() string {
m.mu.Lock()
defer m.mu.Unlock()
return m.id
} | [
"func",
"(",
"m",
"*",
"machineTracker",
")",
"Id",
"(",
")",
"string",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"id",
"\n",
"}"
] | // Id returns the id of the machine being tracked. | [
"Id",
"returns",
"the",
"id",
"of",
"the",
"machine",
"being",
"tracked",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/machinetracker.go#L63-L67 |
4,631 | juju/juju | worker/peergrouper/machinetracker.go | Addresses | func (m *machineTracker) Addresses() []network.Address {
m.mu.Lock()
defer m.mu.Unlock()
out := make([]network.Address, len(m.addresses))
copy(out, m.addresses)
return out
} | go | func (m *machineTracker) Addresses() []network.Address {
m.mu.Lock()
defer m.mu.Unlock()
out := make([]network.Address, len(m.addresses))
copy(out, m.addresses)
return out
} | [
"func",
"(",
"m",
"*",
"machineTracker",
")",
"Addresses",
"(",
")",
"[",
"]",
"network",
".",
"Address",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"len",
"(",
"m",
".",
"addresses",
")",
")",
"\n",
"copy",
"(",
"out",
",",
"m",
".",
"addresses",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // Addresses returns the machine addresses from state. | [
"Addresses",
"returns",
"the",
"machine",
"addresses",
"from",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/machinetracker.go#L78-L84 |
4,632 | juju/juju | worker/peergrouper/machinetracker.go | SelectMongoAddressFromSpace | func (m *machineTracker) SelectMongoAddressFromSpace(port int, space network.SpaceName) (string, error) {
if space == "" {
return "", fmt.Errorf("empty space supplied as an argument for selecting Mongo address for machine %q", m.id)
}
m.mu.Lock()
hostPorts := network.AddressesWithPort(m.addresses, port)
m.mu.Unlock()
addrs, ok := network.SelectHostPortsBySpaceNames(hostPorts, space)
if ok {
addr := addrs[0].NetAddr()
logger.Debugf("machine %q selected address %q by space %q from %v", m.id, addr, space, hostPorts)
return addr, nil
}
// If we end up here, then there are no addresses available in the
// specified space. This should not happen, because the configured
// space is used as a constraint when first enabling HA.
return "", errors.NotFoundf("addresses for machine %q in space %q", m.id, space)
} | go | func (m *machineTracker) SelectMongoAddressFromSpace(port int, space network.SpaceName) (string, error) {
if space == "" {
return "", fmt.Errorf("empty space supplied as an argument for selecting Mongo address for machine %q", m.id)
}
m.mu.Lock()
hostPorts := network.AddressesWithPort(m.addresses, port)
m.mu.Unlock()
addrs, ok := network.SelectHostPortsBySpaceNames(hostPorts, space)
if ok {
addr := addrs[0].NetAddr()
logger.Debugf("machine %q selected address %q by space %q from %v", m.id, addr, space, hostPorts)
return addr, nil
}
// If we end up here, then there are no addresses available in the
// specified space. This should not happen, because the configured
// space is used as a constraint when first enabling HA.
return "", errors.NotFoundf("addresses for machine %q in space %q", m.id, space)
} | [
"func",
"(",
"m",
"*",
"machineTracker",
")",
"SelectMongoAddressFromSpace",
"(",
"port",
"int",
",",
"space",
"network",
".",
"SpaceName",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"space",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"id",
")",
"\n",
"}",
"\n\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"hostPorts",
":=",
"network",
".",
"AddressesWithPort",
"(",
"m",
".",
"addresses",
",",
"port",
")",
"\n",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"addrs",
",",
"ok",
":=",
"network",
".",
"SelectHostPortsBySpaceNames",
"(",
"hostPorts",
",",
"space",
")",
"\n",
"if",
"ok",
"{",
"addr",
":=",
"addrs",
"[",
"0",
"]",
".",
"NetAddr",
"(",
")",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"m",
".",
"id",
",",
"addr",
",",
"space",
",",
"hostPorts",
")",
"\n",
"return",
"addr",
",",
"nil",
"\n",
"}",
"\n\n",
"// If we end up here, then there are no addresses available in the",
"// specified space. This should not happen, because the configured",
"// space is used as a constraint when first enabling HA.",
"return",
"\"",
"\"",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"m",
".",
"id",
",",
"space",
")",
"\n",
"}"
] | // SelectMongoAddress returns the best address on the machine for MongoDB peer
// use, using the input space.
// An error is returned if the empty space is supplied. | [
"SelectMongoAddress",
"returns",
"the",
"best",
"address",
"on",
"the",
"machine",
"for",
"MongoDB",
"peer",
"use",
"using",
"the",
"input",
"space",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"empty",
"space",
"is",
"supplied",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/machinetracker.go#L89-L109 |
4,633 | juju/juju | worker/peergrouper/machinetracker.go | GetPotentialMongoHostPorts | func (m *machineTracker) GetPotentialMongoHostPorts(port int) []network.HostPort {
m.mu.Lock()
defer m.mu.Unlock()
return network.AddressesWithPort(m.addresses, port)
} | go | func (m *machineTracker) GetPotentialMongoHostPorts(port int) []network.HostPort {
m.mu.Lock()
defer m.mu.Unlock()
return network.AddressesWithPort(m.addresses, port)
} | [
"func",
"(",
"m",
"*",
"machineTracker",
")",
"GetPotentialMongoHostPorts",
"(",
"port",
"int",
")",
"[",
"]",
"network",
".",
"HostPort",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"network",
".",
"AddressesWithPort",
"(",
"m",
".",
"addresses",
",",
"port",
")",
"\n",
"}"
] | // GetPotentialMongoHostPorts simply returns all the available addresses
// with the Mongo port appended. | [
"GetPotentialMongoHostPorts",
"simply",
"returns",
"all",
"the",
"available",
"addresses",
"with",
"the",
"Mongo",
"port",
"appended",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/machinetracker.go#L113-L117 |
4,634 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | AllLinkLayerDevices | func (m *MockMachine) AllLinkLayerDevices() ([]containerizer.LinkLayerDevice, error) {
ret := m.ctrl.Call(m, "AllLinkLayerDevices")
ret0, _ := ret[0].([]containerizer.LinkLayerDevice)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachine) AllLinkLayerDevices() ([]containerizer.LinkLayerDevice, error) {
ret := m.ctrl.Call(m, "AllLinkLayerDevices")
ret0, _ := ret[0].([]containerizer.LinkLayerDevice)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"AllLinkLayerDevices",
"(",
")",
"(",
"[",
"]",
"containerizer",
".",
"LinkLayerDevice",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"containerizer",
".",
"LinkLayerDevice",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // AllLinkLayerDevices mocks base method | [
"AllLinkLayerDevices",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L43-L48 |
4,635 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | AllSpaces | func (m *MockMachine) AllSpaces() (set.Strings, error) {
ret := m.ctrl.Call(m, "AllSpaces")
ret0, _ := ret[0].(set.Strings)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachine) AllSpaces() (set.Strings, error) {
ret := m.ctrl.Call(m, "AllSpaces")
ret0, _ := ret[0].(set.Strings)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"AllSpaces",
"(",
")",
"(",
"set",
".",
"Strings",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"set",
".",
"Strings",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // AllSpaces mocks base method | [
"AllSpaces",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L56-L61 |
4,636 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | ContainerType | func (m *MockMachine) ContainerType() instance.ContainerType {
ret := m.ctrl.Call(m, "ContainerType")
ret0, _ := ret[0].(instance.ContainerType)
return ret0
} | go | func (m *MockMachine) ContainerType() instance.ContainerType {
ret := m.ctrl.Call(m, "ContainerType")
ret0, _ := ret[0].(instance.ContainerType)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"ContainerType",
"(",
")",
"instance",
".",
"ContainerType",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"instance",
".",
"ContainerType",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ContainerType mocks base method | [
"ContainerType",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L69-L73 |
4,637 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | IsManual | func (m *MockMachine) IsManual() (bool, error) {
ret := m.ctrl.Call(m, "IsManual")
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachine) IsManual() (bool, error) {
ret := m.ctrl.Call(m, "IsManual")
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"IsManual",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // IsManual mocks base method | [
"IsManual",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L119-L124 |
4,638 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | LinkLayerDevicesForSpaces | func (m *MockMachine) LinkLayerDevicesForSpaces(arg0 []string) (map[string][]containerizer.LinkLayerDevice, error) {
ret := m.ctrl.Call(m, "LinkLayerDevicesForSpaces", arg0)
ret0, _ := ret[0].(map[string][]containerizer.LinkLayerDevice)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachine) LinkLayerDevicesForSpaces(arg0 []string) (map[string][]containerizer.LinkLayerDevice, error) {
ret := m.ctrl.Call(m, "LinkLayerDevicesForSpaces", arg0)
ret0, _ := ret[0].(map[string][]containerizer.LinkLayerDevice)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"LinkLayerDevicesForSpaces",
"(",
"arg0",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"containerizer",
".",
"LinkLayerDevice",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"containerizer",
".",
"LinkLayerDevice",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // LinkLayerDevicesForSpaces mocks base method | [
"LinkLayerDevicesForSpaces",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L132-L137 |
4,639 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | Raw | func (m *MockMachine) Raw() *state.Machine {
ret := m.ctrl.Call(m, "Raw")
ret0, _ := ret[0].(*state.Machine)
return ret0
} | go | func (m *MockMachine) Raw() *state.Machine {
ret := m.ctrl.Call(m, "Raw")
ret0, _ := ret[0].(*state.Machine)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"Raw",
"(",
")",
"*",
"state",
".",
"Machine",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"state",
".",
"Machine",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Raw mocks base method | [
"Raw",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L157-L161 |
4,640 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | Raw | func (mr *MockMachineMockRecorder) Raw() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Raw", reflect.TypeOf((*MockMachine)(nil).Raw))
} | go | func (mr *MockMachineMockRecorder) Raw() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Raw", reflect.TypeOf((*MockMachine)(nil).Raw))
} | [
"func",
"(",
"mr",
"*",
"MockMachineMockRecorder",
")",
"Raw",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMachine",
")",
"(",
"nil",
")",
".",
"Raw",
")",
")",
"\n",
"}"
] | // Raw indicates an expected call of Raw | [
"Raw",
"indicates",
"an",
"expected",
"call",
"of",
"Raw"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L164-L166 |
4,641 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | RemoveAllAddresses | func (m *MockMachine) RemoveAllAddresses() error {
ret := m.ctrl.Call(m, "RemoveAllAddresses")
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachine) RemoveAllAddresses() error {
ret := m.ctrl.Call(m, "RemoveAllAddresses")
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"RemoveAllAddresses",
"(",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // RemoveAllAddresses mocks base method | [
"RemoveAllAddresses",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L169-L173 |
4,642 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | SetConstraints | func (m *MockMachine) SetConstraints(arg0 constraints.Value) error {
ret := m.ctrl.Call(m, "SetConstraints", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachine) SetConstraints(arg0 constraints.Value) error {
ret := m.ctrl.Call(m, "SetConstraints", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"SetConstraints",
"(",
"arg0",
"constraints",
".",
"Value",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetConstraints mocks base method | [
"SetConstraints",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L181-L185 |
4,643 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | SetConstraints | func (mr *MockMachineMockRecorder) SetConstraints(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetConstraints", reflect.TypeOf((*MockMachine)(nil).SetConstraints), arg0)
} | go | func (mr *MockMachineMockRecorder) SetConstraints(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetConstraints", reflect.TypeOf((*MockMachine)(nil).SetConstraints), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockMachineMockRecorder",
")",
"SetConstraints",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMachine",
")",
"(",
"nil",
")",
".",
"SetConstraints",
")",
",",
"arg0",
")",
"\n",
"}"
] | // SetConstraints indicates an expected call of SetConstraints | [
"SetConstraints",
"indicates",
"an",
"expected",
"call",
"of",
"SetConstraints"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L188-L190 |
4,644 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | SetDevicesAddresses | func (m *MockMachine) SetDevicesAddresses(arg0 ...state.LinkLayerDeviceAddress) error {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetDevicesAddresses", varargs...)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachine) SetDevicesAddresses(arg0 ...state.LinkLayerDeviceAddress) error {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetDevicesAddresses", varargs...)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"SetDevicesAddresses",
"(",
"arg0",
"...",
"state",
".",
"LinkLayerDeviceAddress",
")",
"error",
"{",
"varargs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"arg0",
"{",
"varargs",
"=",
"append",
"(",
"varargs",
",",
"a",
")",
"\n",
"}",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"varargs",
"...",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetDevicesAddresses mocks base method | [
"SetDevicesAddresses",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L193-L201 |
4,645 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | SetLinkLayerDevices | func (m *MockMachine) SetLinkLayerDevices(arg0 ...state.LinkLayerDeviceArgs) error {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetLinkLayerDevices", varargs...)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachine) SetLinkLayerDevices(arg0 ...state.LinkLayerDeviceArgs) error {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetLinkLayerDevices", varargs...)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"SetLinkLayerDevices",
"(",
"arg0",
"...",
"state",
".",
"LinkLayerDeviceArgs",
")",
"error",
"{",
"varargs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"arg0",
"{",
"varargs",
"=",
"append",
"(",
"varargs",
",",
"a",
")",
"\n",
"}",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"varargs",
"...",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetLinkLayerDevices mocks base method | [
"SetLinkLayerDevices",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L209-L217 |
4,646 | juju/juju | apiserver/facades/agent/provisioner/mocks/machine_mock.go | SetParentLinkLayerDevicesBeforeTheirChildren | func (m *MockMachine) SetParentLinkLayerDevicesBeforeTheirChildren(arg0 []state.LinkLayerDeviceArgs) error {
ret := m.ctrl.Call(m, "SetParentLinkLayerDevicesBeforeTheirChildren", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachine) SetParentLinkLayerDevicesBeforeTheirChildren(arg0 []state.LinkLayerDeviceArgs) error {
ret := m.ctrl.Call(m, "SetParentLinkLayerDevicesBeforeTheirChildren", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachine",
")",
"SetParentLinkLayerDevicesBeforeTheirChildren",
"(",
"arg0",
"[",
"]",
"state",
".",
"LinkLayerDeviceArgs",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetParentLinkLayerDevicesBeforeTheirChildren mocks base method | [
"SetParentLinkLayerDevicesBeforeTheirChildren",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/machine_mock.go#L225-L229 |
4,647 | juju/juju | worker/uniter/operation/executor.go | NewExecutor | func NewExecutor(stateFilePath string, initialState State, acquireLock func(string) (func(), error)) (Executor, error) {
file := NewStateFile(stateFilePath)
state, err := file.Read()
if err == ErrNoStateFile {
state = &initialState
} else if err != nil {
return nil, err
}
return &executor{
file: file,
state: state,
acquireMachineLock: acquireLock,
}, nil
} | go | func NewExecutor(stateFilePath string, initialState State, acquireLock func(string) (func(), error)) (Executor, error) {
file := NewStateFile(stateFilePath)
state, err := file.Read()
if err == ErrNoStateFile {
state = &initialState
} else if err != nil {
return nil, err
}
return &executor{
file: file,
state: state,
acquireMachineLock: acquireLock,
}, nil
} | [
"func",
"NewExecutor",
"(",
"stateFilePath",
"string",
",",
"initialState",
"State",
",",
"acquireLock",
"func",
"(",
"string",
")",
"(",
"func",
"(",
")",
",",
"error",
")",
")",
"(",
"Executor",
",",
"error",
")",
"{",
"file",
":=",
"NewStateFile",
"(",
"stateFilePath",
")",
"\n",
"state",
",",
"err",
":=",
"file",
".",
"Read",
"(",
")",
"\n",
"if",
"err",
"==",
"ErrNoStateFile",
"{",
"state",
"=",
"&",
"initialState",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"executor",
"{",
"file",
":",
"file",
",",
"state",
":",
"state",
",",
"acquireMachineLock",
":",
"acquireLock",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewExecutor returns an Executor which takes its starting state from the
// supplied path, and records state changes there. If no state file exists,
// the executor's starting state will include a queued Install hook, for
// the charm identified by the supplied func. | [
"NewExecutor",
"returns",
"an",
"Executor",
"which",
"takes",
"its",
"starting",
"state",
"from",
"the",
"supplied",
"path",
"and",
"records",
"state",
"changes",
"there",
".",
"If",
"no",
"state",
"file",
"exists",
"the",
"executor",
"s",
"starting",
"state",
"will",
"include",
"a",
"queued",
"Install",
"hook",
"for",
"the",
"charm",
"identified",
"by",
"the",
"supplied",
"func",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/executor.go#L37-L50 |
4,648 | juju/juju | worker/uniter/operation/executor.go | Run | func (x *executor) Run(op Operation) error {
logger.Debugf("running operation %v", op)
if op.NeedsGlobalMachineLock() {
releaser, err := x.acquireMachineLock(op.String())
if err != nil {
return errors.Annotate(err, "could not acquire lock")
}
defer logger.Debugf("lock released")
defer releaser()
}
switch err := x.do(op, stepPrepare); errors.Cause(err) {
case ErrSkipExecute:
case nil:
if err := x.do(op, stepExecute); err != nil {
return err
}
default:
return err
}
return x.do(op, stepCommit)
} | go | func (x *executor) Run(op Operation) error {
logger.Debugf("running operation %v", op)
if op.NeedsGlobalMachineLock() {
releaser, err := x.acquireMachineLock(op.String())
if err != nil {
return errors.Annotate(err, "could not acquire lock")
}
defer logger.Debugf("lock released")
defer releaser()
}
switch err := x.do(op, stepPrepare); errors.Cause(err) {
case ErrSkipExecute:
case nil:
if err := x.do(op, stepExecute); err != nil {
return err
}
default:
return err
}
return x.do(op, stepCommit)
} | [
"func",
"(",
"x",
"*",
"executor",
")",
"Run",
"(",
"op",
"Operation",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"op",
")",
"\n\n",
"if",
"op",
".",
"NeedsGlobalMachineLock",
"(",
")",
"{",
"releaser",
",",
"err",
":=",
"x",
".",
"acquireMachineLock",
"(",
"op",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"releaser",
"(",
")",
"\n",
"}",
"\n\n",
"switch",
"err",
":=",
"x",
".",
"do",
"(",
"op",
",",
"stepPrepare",
")",
";",
"errors",
".",
"Cause",
"(",
"err",
")",
"{",
"case",
"ErrSkipExecute",
":",
"case",
"nil",
":",
"if",
"err",
":=",
"x",
".",
"do",
"(",
"op",
",",
"stepExecute",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"default",
":",
"return",
"err",
"\n",
"}",
"\n",
"return",
"x",
".",
"do",
"(",
"op",
",",
"stepCommit",
")",
"\n",
"}"
] | // Run is part of the Executor interface. | [
"Run",
"is",
"part",
"of",
"the",
"Executor",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/executor.go#L58-L80 |
4,649 | juju/juju | worker/uniter/operation/executor.go | Skip | func (x *executor) Skip(op Operation) error {
logger.Debugf("skipping operation %v", op)
return x.do(op, stepCommit)
} | go | func (x *executor) Skip(op Operation) error {
logger.Debugf("skipping operation %v", op)
return x.do(op, stepCommit)
} | [
"func",
"(",
"x",
"*",
"executor",
")",
"Skip",
"(",
"op",
"Operation",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"op",
")",
"\n",
"return",
"x",
".",
"do",
"(",
"op",
",",
"stepCommit",
")",
"\n",
"}"
] | // Skip is part of the Executor interface. | [
"Skip",
"is",
"part",
"of",
"the",
"Executor",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/executor.go#L83-L86 |
4,650 | juju/juju | state/multienv.go | ensureModelUUID | func ensureModelUUID(modelUUID, id string) string {
prefix := modelUUID + ":"
if strings.HasPrefix(id, prefix) {
return id
}
return prefix + id
} | go | func ensureModelUUID(modelUUID, id string) string {
prefix := modelUUID + ":"
if strings.HasPrefix(id, prefix) {
return id
}
return prefix + id
} | [
"func",
"ensureModelUUID",
"(",
"modelUUID",
",",
"id",
"string",
")",
"string",
"{",
"prefix",
":=",
"modelUUID",
"+",
"\"",
"\"",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"id",
",",
"prefix",
")",
"{",
"return",
"id",
"\n",
"}",
"\n",
"return",
"prefix",
"+",
"id",
"\n",
"}"
] | // This file contains utility functions related to documents and
// collections that contain data for multiple models.
// ensureModelUUID returns an model UUID prefixed document ID. The
// prefix is only added if it isn't already there. | [
"This",
"file",
"contains",
"utility",
"functions",
"related",
"to",
"documents",
"and",
"collections",
"that",
"contain",
"data",
"for",
"multiple",
"models",
".",
"ensureModelUUID",
"returns",
"an",
"model",
"UUID",
"prefixed",
"document",
"ID",
".",
"The",
"prefix",
"is",
"only",
"added",
"if",
"it",
"isn",
"t",
"already",
"there",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multienv.go#L18-L24 |
4,651 | juju/juju | state/multienv.go | ensureModelUUIDIfString | func ensureModelUUIDIfString(modelUUID string, id interface{}) interface{} {
if id, ok := id.(string); ok {
return ensureModelUUID(modelUUID, id)
}
return id
} | go | func ensureModelUUIDIfString(modelUUID string, id interface{}) interface{} {
if id, ok := id.(string); ok {
return ensureModelUUID(modelUUID, id)
}
return id
} | [
"func",
"ensureModelUUIDIfString",
"(",
"modelUUID",
"string",
",",
"id",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"id",
",",
"ok",
":=",
"id",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"ensureModelUUID",
"(",
"modelUUID",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"id",
"\n",
"}"
] | // ensureModelUUIDIfString will call ensureModelUUID, but only if the id
// is a string. The id will be left untouched otherwise. | [
"ensureModelUUIDIfString",
"will",
"call",
"ensureModelUUID",
"but",
"only",
"if",
"the",
"id",
"is",
"a",
"string",
".",
"The",
"id",
"will",
"be",
"left",
"untouched",
"otherwise",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multienv.go#L28-L33 |
4,652 | juju/juju | state/multienv.go | splitDocID | func splitDocID(id string) (string, string, bool) {
parts := strings.SplitN(id, ":", 2)
if len(parts) != 2 {
return "", "", false
}
return parts[0], parts[1], true
} | go | func splitDocID(id string) (string, string, bool) {
parts := strings.SplitN(id, ":", 2)
if len(parts) != 2 {
return "", "", false
}
return parts[0], parts[1], true
} | [
"func",
"splitDocID",
"(",
"id",
"string",
")",
"(",
"string",
",",
"string",
",",
"bool",
")",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"id",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"return",
"parts",
"[",
"0",
"]",
",",
"parts",
"[",
"1",
"]",
",",
"true",
"\n",
"}"
] | // splitDocID returns the 2 parts of model UUID prefixed
// document ID. If the id is not in the expected format the final
// return value will be false. | [
"splitDocID",
"returns",
"the",
"2",
"parts",
"of",
"model",
"UUID",
"prefixed",
"document",
"ID",
".",
"If",
"the",
"id",
"is",
"not",
"in",
"the",
"expected",
"format",
"the",
"final",
"return",
"value",
"will",
"be",
"false",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multienv.go#L38-L44 |
4,653 | juju/juju | state/multienv.go | toBsonD | func toBsonD(doc interface{}) (bson.D, error) {
bytes, err := bson.Marshal(doc)
if err != nil {
return nil, errors.Annotate(err, "bson marshaling failed")
}
var out bson.D
err = bson.Unmarshal(bytes, &out)
if err != nil {
return nil, errors.Annotate(err, "bson unmarshaling failed")
}
return out, nil
} | go | func toBsonD(doc interface{}) (bson.D, error) {
bytes, err := bson.Marshal(doc)
if err != nil {
return nil, errors.Annotate(err, "bson marshaling failed")
}
var out bson.D
err = bson.Unmarshal(bytes, &out)
if err != nil {
return nil, errors.Annotate(err, "bson unmarshaling failed")
}
return out, nil
} | [
"func",
"toBsonD",
"(",
"doc",
"interface",
"{",
"}",
")",
"(",
"bson",
".",
"D",
",",
"error",
")",
"{",
"bytes",
",",
"err",
":=",
"bson",
".",
"Marshal",
"(",
"doc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"out",
"bson",
".",
"D",
"\n",
"err",
"=",
"bson",
".",
"Unmarshal",
"(",
"bytes",
",",
"&",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // toBsonD converts an arbitrary value to a bson.D via marshaling
// through BSON. This is still done even if the input is already a
// bson.D so that we end up with a copy of the input. | [
"toBsonD",
"converts",
"an",
"arbitrary",
"value",
"to",
"a",
"bson",
".",
"D",
"via",
"marshaling",
"through",
"BSON",
".",
"This",
"is",
"still",
"done",
"even",
"if",
"the",
"input",
"is",
"already",
"a",
"bson",
".",
"D",
"so",
"that",
"we",
"end",
"up",
"with",
"a",
"copy",
"of",
"the",
"input",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multienv.go#L140-L151 |
4,654 | juju/juju | api/state.go | addAddress | func addAddress(servers [][]network.HostPort, addr string) ([][]network.HostPort, error) {
for i, server := range servers {
for j, hostPort := range server {
if hostPort.NetAddr() == addr {
slideAddressToFront(servers, i, j)
return servers, nil
}
}
}
host, portString, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
port, err := strconv.Atoi(portString)
if err != nil {
return nil, err
}
result := make([][]network.HostPort, 0, len(servers)+1)
result = append(result, network.NewHostPorts(port, host))
result = append(result, servers...)
return result, nil
} | go | func addAddress(servers [][]network.HostPort, addr string) ([][]network.HostPort, error) {
for i, server := range servers {
for j, hostPort := range server {
if hostPort.NetAddr() == addr {
slideAddressToFront(servers, i, j)
return servers, nil
}
}
}
host, portString, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
port, err := strconv.Atoi(portString)
if err != nil {
return nil, err
}
result := make([][]network.HostPort, 0, len(servers)+1)
result = append(result, network.NewHostPorts(port, host))
result = append(result, servers...)
return result, nil
} | [
"func",
"addAddress",
"(",
"servers",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"addr",
"string",
")",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"error",
")",
"{",
"for",
"i",
",",
"server",
":=",
"range",
"servers",
"{",
"for",
"j",
",",
"hostPort",
":=",
"range",
"server",
"{",
"if",
"hostPort",
".",
"NetAddr",
"(",
")",
"==",
"addr",
"{",
"slideAddressToFront",
"(",
"servers",
",",
"i",
",",
"j",
")",
"\n",
"return",
"servers",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"host",
",",
"portString",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"port",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"portString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"0",
",",
"len",
"(",
"servers",
")",
"+",
"1",
")",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"network",
".",
"NewHostPorts",
"(",
"port",
",",
"host",
")",
")",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"servers",
"...",
")",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // addAddress appends a new server derived from the given
// address to servers if the address is not already found
// there. | [
"addAddress",
"appends",
"a",
"new",
"server",
"derived",
"from",
"the",
"given",
"address",
"to",
"servers",
"if",
"the",
"address",
"is",
"not",
"already",
"found",
"there",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/state.go#L255-L276 |
4,655 | juju/juju | api/state.go | Client | func (st *state) Client() *Client {
frontend, backend := base.NewClientFacade(st, "Client")
return &Client{ClientFacade: frontend, facade: backend, st: st}
} | go | func (st *state) Client() *Client {
frontend, backend := base.NewClientFacade(st, "Client")
return &Client{ClientFacade: frontend, facade: backend, st: st}
} | [
"func",
"(",
"st",
"*",
"state",
")",
"Client",
"(",
")",
"*",
"Client",
"{",
"frontend",
",",
"backend",
":=",
"base",
".",
"NewClientFacade",
"(",
"st",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"Client",
"{",
"ClientFacade",
":",
"frontend",
",",
"facade",
":",
"backend",
",",
"st",
":",
"st",
"}",
"\n",
"}"
] | // Client returns an object that can be used
// to access client-specific functionality. | [
"Client",
"returns",
"an",
"object",
"that",
"can",
"be",
"used",
"to",
"access",
"client",
"-",
"specific",
"functionality",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/state.go#L280-L283 |
4,656 | juju/juju | api/state.go | Uniter | func (st *state) Uniter() (*uniter.State, error) {
unitTag, ok := st.authTag.(names.UnitTag)
if !ok {
return nil, errors.Errorf("expected UnitTag, got %T %v", st.authTag, st.authTag)
}
return uniter.NewState(st, unitTag), nil
} | go | func (st *state) Uniter() (*uniter.State, error) {
unitTag, ok := st.authTag.(names.UnitTag)
if !ok {
return nil, errors.Errorf("expected UnitTag, got %T %v", st.authTag, st.authTag)
}
return uniter.NewState(st, unitTag), nil
} | [
"func",
"(",
"st",
"*",
"state",
")",
"Uniter",
"(",
")",
"(",
"*",
"uniter",
".",
"State",
",",
"error",
")",
"{",
"unitTag",
",",
"ok",
":=",
"st",
".",
"authTag",
".",
"(",
"names",
".",
"UnitTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"st",
".",
"authTag",
",",
"st",
".",
"authTag",
")",
"\n",
"}",
"\n",
"return",
"uniter",
".",
"NewState",
"(",
"st",
",",
"unitTag",
")",
",",
"nil",
"\n",
"}"
] | // Uniter returns a version of the state that provides functionality
// required by the uniter worker. | [
"Uniter",
"returns",
"a",
"version",
"of",
"the",
"state",
"that",
"provides",
"functionality",
"required",
"by",
"the",
"uniter",
"worker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/state.go#L293-L299 |
4,657 | juju/juju | api/state.go | Reboot | func (st *state) Reboot() (reboot.State, error) {
switch tag := st.authTag.(type) {
case names.MachineTag:
return reboot.NewState(st, tag), nil
default:
return nil, errors.Errorf("expected names.MachineTag, got %T", tag)
}
} | go | func (st *state) Reboot() (reboot.State, error) {
switch tag := st.authTag.(type) {
case names.MachineTag:
return reboot.NewState(st, tag), nil
default:
return nil, errors.Errorf("expected names.MachineTag, got %T", tag)
}
} | [
"func",
"(",
"st",
"*",
"state",
")",
"Reboot",
"(",
")",
"(",
"reboot",
".",
"State",
",",
"error",
")",
"{",
"switch",
"tag",
":=",
"st",
".",
"authTag",
".",
"(",
"type",
")",
"{",
"case",
"names",
".",
"MachineTag",
":",
"return",
"reboot",
".",
"NewState",
"(",
"st",
",",
"tag",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"}"
] | // Reboot returns access to the Reboot API | [
"Reboot",
"returns",
"access",
"to",
"the",
"Reboot",
"API"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/state.go#L307-L314 |
4,658 | juju/juju | api/state.go | ServerVersion | func (st *state) ServerVersion() (version.Number, bool) {
return st.serverVersion, st.serverVersion != version.Zero
} | go | func (st *state) ServerVersion() (version.Number, bool) {
return st.serverVersion, st.serverVersion != version.Zero
} | [
"func",
"(",
"st",
"*",
"state",
")",
"ServerVersion",
"(",
")",
"(",
"version",
".",
"Number",
",",
"bool",
")",
"{",
"return",
"st",
".",
"serverVersion",
",",
"st",
".",
"serverVersion",
"!=",
"version",
".",
"Zero",
"\n",
"}"
] | // ServerVersion holds the version of the API server that we are connected to.
// It is possible that this version is Zero if the server does not report this
// during login. The second result argument indicates if the version number is
// set. | [
"ServerVersion",
"holds",
"the",
"version",
"of",
"the",
"API",
"server",
"that",
"we",
"are",
"connected",
"to",
".",
"It",
"is",
"possible",
"that",
"this",
"version",
"is",
"Zero",
"if",
"the",
"server",
"does",
"not",
"report",
"this",
"during",
"login",
".",
"The",
"second",
"result",
"argument",
"indicates",
"if",
"the",
"version",
"number",
"is",
"set",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/state.go#L340-L342 |
4,659 | juju/juju | provider/oci/common/client.go | Config | func (j JujuConfigProvider) Config() (ociCommon.ConfigurationProvider, error) {
if err := j.Validate(); err != nil {
return nil, err
}
return &j, nil
} | go | func (j JujuConfigProvider) Config() (ociCommon.ConfigurationProvider, error) {
if err := j.Validate(); err != nil {
return nil, err
}
return &j, nil
} | [
"func",
"(",
"j",
"JujuConfigProvider",
")",
"Config",
"(",
")",
"(",
"ociCommon",
".",
"ConfigurationProvider",
",",
"error",
")",
"{",
"if",
"err",
":=",
"j",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"j",
",",
"nil",
"\n",
"}"
] | // Config returns a new ociCommon.ConfigurationProvider instance | [
"Config",
"returns",
"a",
"new",
"ociCommon",
".",
"ConfigurationProvider",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/common/client.go#L98-L103 |
4,660 | juju/juju | core/constraints/validation.go | NewValidator | func NewValidator() Validator {
return &validator{
conflicts: make(map[string]set.Strings),
vocab: make(map[string][]interface{}),
}
} | go | func NewValidator() Validator {
return &validator{
conflicts: make(map[string]set.Strings),
vocab: make(map[string][]interface{}),
}
} | [
"func",
"NewValidator",
"(",
")",
"Validator",
"{",
"return",
"&",
"validator",
"{",
"conflicts",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"set",
".",
"Strings",
")",
",",
"vocab",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"interface",
"{",
"}",
")",
",",
"}",
"\n",
"}"
] | // NewValidator returns a new constraints Validator instance. | [
"NewValidator",
"returns",
"a",
"new",
"constraints",
"Validator",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L52-L57 |
4,661 | juju/juju | core/constraints/validation.go | RegisterConflicts | func (v *validator) RegisterConflicts(reds, blues []string) {
for _, red := range reds {
v.conflicts[red] = set.NewStrings(blues...)
}
for _, blue := range blues {
v.conflicts[blue] = set.NewStrings(reds...)
}
} | go | func (v *validator) RegisterConflicts(reds, blues []string) {
for _, red := range reds {
v.conflicts[red] = set.NewStrings(blues...)
}
for _, blue := range blues {
v.conflicts[blue] = set.NewStrings(reds...)
}
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"RegisterConflicts",
"(",
"reds",
",",
"blues",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"red",
":=",
"range",
"reds",
"{",
"v",
".",
"conflicts",
"[",
"red",
"]",
"=",
"set",
".",
"NewStrings",
"(",
"blues",
"...",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"blue",
":=",
"range",
"blues",
"{",
"v",
".",
"conflicts",
"[",
"blue",
"]",
"=",
"set",
".",
"NewStrings",
"(",
"reds",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // RegisterConflicts is defined on Validator. | [
"RegisterConflicts",
"is",
"defined",
"on",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L66-L73 |
4,662 | juju/juju | core/constraints/validation.go | RegisterUnsupported | func (v *validator) RegisterUnsupported(unsupported []string) {
v.unsupported = set.NewStrings(unsupported...)
} | go | func (v *validator) RegisterUnsupported(unsupported []string) {
v.unsupported = set.NewStrings(unsupported...)
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"RegisterUnsupported",
"(",
"unsupported",
"[",
"]",
"string",
")",
"{",
"v",
".",
"unsupported",
"=",
"set",
".",
"NewStrings",
"(",
"unsupported",
"...",
")",
"\n",
"}"
] | // RegisterUnsupported is defined on Validator. | [
"RegisterUnsupported",
"is",
"defined",
"on",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L76-L78 |
4,663 | juju/juju | core/constraints/validation.go | RegisterVocabulary | func (v *validator) RegisterVocabulary(attributeName string, allowedValues interface{}) {
v.vocab[resolveAlias(attributeName)] = convertToSlice(allowedValues)
} | go | func (v *validator) RegisterVocabulary(attributeName string, allowedValues interface{}) {
v.vocab[resolveAlias(attributeName)] = convertToSlice(allowedValues)
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"RegisterVocabulary",
"(",
"attributeName",
"string",
",",
"allowedValues",
"interface",
"{",
"}",
")",
"{",
"v",
".",
"vocab",
"[",
"resolveAlias",
"(",
"attributeName",
")",
"]",
"=",
"convertToSlice",
"(",
"allowedValues",
")",
"\n",
"}"
] | // RegisterVocabulary is defined on Validator. | [
"RegisterVocabulary",
"is",
"defined",
"on",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L81-L83 |
4,664 | juju/juju | core/constraints/validation.go | UpdateVocabulary | func (v *validator) UpdateVocabulary(attributeName string, allowedValues interface{}) {
attributeName = resolveAlias(attributeName)
// If this attribute is not registered, delegate to RegisterVocabulary()
currentValues, ok := v.vocab[attributeName]
if !ok {
v.RegisterVocabulary(attributeName, allowedValues)
}
unique := map[interface{}]bool{}
writeUnique := func(all []interface{}) {
for _, one := range all {
unique[one] = true
}
}
// merge existing values with new, ensuring uniqueness
writeUnique(currentValues)
newValues := convertToSlice(allowedValues)
writeUnique(newValues)
v.updateVocabularyFromMap(attributeName, unique)
} | go | func (v *validator) UpdateVocabulary(attributeName string, allowedValues interface{}) {
attributeName = resolveAlias(attributeName)
// If this attribute is not registered, delegate to RegisterVocabulary()
currentValues, ok := v.vocab[attributeName]
if !ok {
v.RegisterVocabulary(attributeName, allowedValues)
}
unique := map[interface{}]bool{}
writeUnique := func(all []interface{}) {
for _, one := range all {
unique[one] = true
}
}
// merge existing values with new, ensuring uniqueness
writeUnique(currentValues)
newValues := convertToSlice(allowedValues)
writeUnique(newValues)
v.updateVocabularyFromMap(attributeName, unique)
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"UpdateVocabulary",
"(",
"attributeName",
"string",
",",
"allowedValues",
"interface",
"{",
"}",
")",
"{",
"attributeName",
"=",
"resolveAlias",
"(",
"attributeName",
")",
"\n",
"// If this attribute is not registered, delegate to RegisterVocabulary()",
"currentValues",
",",
"ok",
":=",
"v",
".",
"vocab",
"[",
"attributeName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"v",
".",
"RegisterVocabulary",
"(",
"attributeName",
",",
"allowedValues",
")",
"\n",
"}",
"\n\n",
"unique",
":=",
"map",
"[",
"interface",
"{",
"}",
"]",
"bool",
"{",
"}",
"\n",
"writeUnique",
":=",
"func",
"(",
"all",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"one",
":=",
"range",
"all",
"{",
"unique",
"[",
"one",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"// merge existing values with new, ensuring uniqueness",
"writeUnique",
"(",
"currentValues",
")",
"\n",
"newValues",
":=",
"convertToSlice",
"(",
"allowedValues",
")",
"\n",
"writeUnique",
"(",
"newValues",
")",
"\n\n",
"v",
".",
"updateVocabularyFromMap",
"(",
"attributeName",
",",
"unique",
")",
"\n",
"}"
] | // UpdateVocabulary is defined on Validator. | [
"UpdateVocabulary",
"is",
"defined",
"on",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L103-L124 |
4,665 | juju/juju | core/constraints/validation.go | checkConflicts | func (v *validator) checkConflicts(cons Value) error {
attrValues := cons.attributesWithValues()
attrSet := make(set.Strings)
for attrTag := range attrValues {
attrSet.Add(attrTag)
}
for _, attrTag := range attrSet.SortedValues() {
conflicts, ok := v.conflicts[attrTag]
if !ok {
continue
}
for _, conflict := range conflicts.SortedValues() {
if attrSet.Contains(conflict) {
return fmt.Errorf("ambiguous constraints: %q overlaps with %q", attrTag, conflict)
}
}
}
return nil
} | go | func (v *validator) checkConflicts(cons Value) error {
attrValues := cons.attributesWithValues()
attrSet := make(set.Strings)
for attrTag := range attrValues {
attrSet.Add(attrTag)
}
for _, attrTag := range attrSet.SortedValues() {
conflicts, ok := v.conflicts[attrTag]
if !ok {
continue
}
for _, conflict := range conflicts.SortedValues() {
if attrSet.Contains(conflict) {
return fmt.Errorf("ambiguous constraints: %q overlaps with %q", attrTag, conflict)
}
}
}
return nil
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"checkConflicts",
"(",
"cons",
"Value",
")",
"error",
"{",
"attrValues",
":=",
"cons",
".",
"attributesWithValues",
"(",
")",
"\n",
"attrSet",
":=",
"make",
"(",
"set",
".",
"Strings",
")",
"\n",
"for",
"attrTag",
":=",
"range",
"attrValues",
"{",
"attrSet",
".",
"Add",
"(",
"attrTag",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"attrTag",
":=",
"range",
"attrSet",
".",
"SortedValues",
"(",
")",
"{",
"conflicts",
",",
"ok",
":=",
"v",
".",
"conflicts",
"[",
"attrTag",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"conflict",
":=",
"range",
"conflicts",
".",
"SortedValues",
"(",
")",
"{",
"if",
"attrSet",
".",
"Contains",
"(",
"conflict",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"attrTag",
",",
"conflict",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkConflicts returns an error if the constraints Value contains conflicting attributes. | [
"checkConflicts",
"returns",
"an",
"error",
"if",
"the",
"constraints",
"Value",
"contains",
"conflicting",
"attributes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L139-L157 |
4,666 | juju/juju | core/constraints/validation.go | checkUnsupported | func (v *validator) checkUnsupported(cons Value) []string {
return cons.hasAny(v.unsupported.Values()...)
} | go | func (v *validator) checkUnsupported(cons Value) []string {
return cons.hasAny(v.unsupported.Values()...)
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"checkUnsupported",
"(",
"cons",
"Value",
")",
"[",
"]",
"string",
"{",
"return",
"cons",
".",
"hasAny",
"(",
"v",
".",
"unsupported",
".",
"Values",
"(",
")",
"...",
")",
"\n",
"}"
] | // checkUnsupported returns any unsupported attributes. | [
"checkUnsupported",
"returns",
"any",
"unsupported",
"attributes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L160-L162 |
4,667 | juju/juju | core/constraints/validation.go | checkValidValues | func (v *validator) checkValidValues(cons Value) error {
for attrTag, attrValue := range cons.attributesWithValues() {
k := reflect.TypeOf(attrValue).Kind()
if k == reflect.Slice || k == reflect.Array {
// For slices we check that all values are valid.
val := reflect.ValueOf(attrValue)
for i := 0; i < val.Len(); i++ {
if err := v.checkInVocab(attrTag, val.Index(i).Interface()); err != nil {
return err
}
}
} else {
if err := v.checkInVocab(attrTag, attrValue); err != nil {
return err
}
}
}
return nil
} | go | func (v *validator) checkValidValues(cons Value) error {
for attrTag, attrValue := range cons.attributesWithValues() {
k := reflect.TypeOf(attrValue).Kind()
if k == reflect.Slice || k == reflect.Array {
// For slices we check that all values are valid.
val := reflect.ValueOf(attrValue)
for i := 0; i < val.Len(); i++ {
if err := v.checkInVocab(attrTag, val.Index(i).Interface()); err != nil {
return err
}
}
} else {
if err := v.checkInVocab(attrTag, attrValue); err != nil {
return err
}
}
}
return nil
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"checkValidValues",
"(",
"cons",
"Value",
")",
"error",
"{",
"for",
"attrTag",
",",
"attrValue",
":=",
"range",
"cons",
".",
"attributesWithValues",
"(",
")",
"{",
"k",
":=",
"reflect",
".",
"TypeOf",
"(",
"attrValue",
")",
".",
"Kind",
"(",
")",
"\n",
"if",
"k",
"==",
"reflect",
".",
"Slice",
"||",
"k",
"==",
"reflect",
".",
"Array",
"{",
"// For slices we check that all values are valid.",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"attrValue",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"val",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"if",
"err",
":=",
"v",
".",
"checkInVocab",
"(",
"attrTag",
",",
"val",
".",
"Index",
"(",
"i",
")",
".",
"Interface",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"v",
".",
"checkInVocab",
"(",
"attrTag",
",",
"attrValue",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkValidValues returns an error if the constraints value contains an
// attribute value which is not allowed by the vocab which may have been
// registered for it. | [
"checkValidValues",
"returns",
"an",
"error",
"if",
"the",
"constraints",
"value",
"contains",
"an",
"attribute",
"value",
"which",
"is",
"not",
"allowed",
"by",
"the",
"vocab",
"which",
"may",
"have",
"been",
"registered",
"for",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L167-L185 |
4,668 | juju/juju | core/constraints/validation.go | checkInVocab | func (v *validator) checkInVocab(attributeName string, attributeValue interface{}) error {
validValues, ok := v.vocab[resolveAlias(attributeName)]
if !ok {
return nil
}
for _, validValue := range validValues {
if coerce(validValue) == coerce(attributeValue) {
return nil
}
}
return fmt.Errorf(
"invalid constraint value: %v=%v\nvalid values are: %v", attributeName, attributeValue, validValues)
} | go | func (v *validator) checkInVocab(attributeName string, attributeValue interface{}) error {
validValues, ok := v.vocab[resolveAlias(attributeName)]
if !ok {
return nil
}
for _, validValue := range validValues {
if coerce(validValue) == coerce(attributeValue) {
return nil
}
}
return fmt.Errorf(
"invalid constraint value: %v=%v\nvalid values are: %v", attributeName, attributeValue, validValues)
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"checkInVocab",
"(",
"attributeName",
"string",
",",
"attributeValue",
"interface",
"{",
"}",
")",
"error",
"{",
"validValues",
",",
"ok",
":=",
"v",
".",
"vocab",
"[",
"resolveAlias",
"(",
"attributeName",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"validValue",
":=",
"range",
"validValues",
"{",
"if",
"coerce",
"(",
"validValue",
")",
"==",
"coerce",
"(",
"attributeValue",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"attributeName",
",",
"attributeValue",
",",
"validValues",
")",
"\n",
"}"
] | // checkInVocab returns an error if the attribute value is not allowed by the
// vocab which may have been registered for it. | [
"checkInVocab",
"returns",
"an",
"error",
"if",
"the",
"attribute",
"value",
"is",
"not",
"allowed",
"by",
"the",
"vocab",
"which",
"may",
"have",
"been",
"registered",
"for",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L189-L201 |
4,669 | juju/juju | core/constraints/validation.go | withFallbacks | func withFallbacks(v Value, vFallback Value) Value {
vAttr := v.attributesWithValues()
fbAttr := vFallback.attributesWithValues()
for k, v := range fbAttr {
if _, ok := vAttr[k]; !ok {
vAttr[k] = v
}
}
return fromAttributes(vAttr)
} | go | func withFallbacks(v Value, vFallback Value) Value {
vAttr := v.attributesWithValues()
fbAttr := vFallback.attributesWithValues()
for k, v := range fbAttr {
if _, ok := vAttr[k]; !ok {
vAttr[k] = v
}
}
return fromAttributes(vAttr)
} | [
"func",
"withFallbacks",
"(",
"v",
"Value",
",",
"vFallback",
"Value",
")",
"Value",
"{",
"vAttr",
":=",
"v",
".",
"attributesWithValues",
"(",
")",
"\n",
"fbAttr",
":=",
"vFallback",
".",
"attributesWithValues",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"fbAttr",
"{",
"if",
"_",
",",
"ok",
":=",
"vAttr",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"vAttr",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fromAttributes",
"(",
"vAttr",
")",
"\n",
"}"
] | // withFallbacks returns a copy of v with nil values taken from vFallback. | [
"withFallbacks",
"returns",
"a",
"copy",
"of",
"v",
"with",
"nil",
"values",
"taken",
"from",
"vFallback",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L242-L251 |
4,670 | juju/juju | core/constraints/validation.go | Validate | func (v *validator) Validate(cons Value) ([]string, error) {
unsupported := v.checkUnsupported(cons)
if err := v.checkConflicts(cons); err != nil {
return unsupported, err
}
if err := v.checkValidValues(cons); err != nil {
return unsupported, err
}
return unsupported, nil
} | go | func (v *validator) Validate(cons Value) ([]string, error) {
unsupported := v.checkUnsupported(cons)
if err := v.checkConflicts(cons); err != nil {
return unsupported, err
}
if err := v.checkValidValues(cons); err != nil {
return unsupported, err
}
return unsupported, nil
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"Validate",
"(",
"cons",
"Value",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"unsupported",
":=",
"v",
".",
"checkUnsupported",
"(",
"cons",
")",
"\n",
"if",
"err",
":=",
"v",
".",
"checkConflicts",
"(",
"cons",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"unsupported",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"checkValidValues",
"(",
"cons",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"unsupported",
",",
"err",
"\n",
"}",
"\n",
"return",
"unsupported",
",",
"nil",
"\n",
"}"
] | // Validate is defined on Validator. | [
"Validate",
"is",
"defined",
"on",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L254-L263 |
4,671 | juju/juju | core/constraints/validation.go | Merge | func (v *validator) Merge(consFallback, cons Value) (Value, error) {
// First ensure both constraints are valid. We don't care if there
// are constraint attributes that are unsupported.
if _, err := v.Validate(consFallback); err != nil {
return Value{}, err
}
if _, err := v.Validate(cons); err != nil {
return Value{}, err
}
// Gather any attributes from consFallback which conflict with those on cons.
attrValues := cons.attributesWithValues()
var fallbackConflicts []string
for attrTag := range attrValues {
fallbackConflicts = append(fallbackConflicts, v.conflicts[attrTag].Values()...)
}
// Null out the conflicting consFallback attribute values because
// cons takes priority. We can't error here because we
// know that aConflicts contains valid attr names.
consFallbackMinusConflicts := consFallback.without(fallbackConflicts...)
// The result is cons with fallbacks coming from any
// non conflicting consFallback attributes.
return withFallbacks(cons, consFallbackMinusConflicts), nil
} | go | func (v *validator) Merge(consFallback, cons Value) (Value, error) {
// First ensure both constraints are valid. We don't care if there
// are constraint attributes that are unsupported.
if _, err := v.Validate(consFallback); err != nil {
return Value{}, err
}
if _, err := v.Validate(cons); err != nil {
return Value{}, err
}
// Gather any attributes from consFallback which conflict with those on cons.
attrValues := cons.attributesWithValues()
var fallbackConflicts []string
for attrTag := range attrValues {
fallbackConflicts = append(fallbackConflicts, v.conflicts[attrTag].Values()...)
}
// Null out the conflicting consFallback attribute values because
// cons takes priority. We can't error here because we
// know that aConflicts contains valid attr names.
consFallbackMinusConflicts := consFallback.without(fallbackConflicts...)
// The result is cons with fallbacks coming from any
// non conflicting consFallback attributes.
return withFallbacks(cons, consFallbackMinusConflicts), nil
} | [
"func",
"(",
"v",
"*",
"validator",
")",
"Merge",
"(",
"consFallback",
",",
"cons",
"Value",
")",
"(",
"Value",
",",
"error",
")",
"{",
"// First ensure both constraints are valid. We don't care if there",
"// are constraint attributes that are unsupported.",
"if",
"_",
",",
"err",
":=",
"v",
".",
"Validate",
"(",
"consFallback",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"Value",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"v",
".",
"Validate",
"(",
"cons",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"Value",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"// Gather any attributes from consFallback which conflict with those on cons.",
"attrValues",
":=",
"cons",
".",
"attributesWithValues",
"(",
")",
"\n",
"var",
"fallbackConflicts",
"[",
"]",
"string",
"\n",
"for",
"attrTag",
":=",
"range",
"attrValues",
"{",
"fallbackConflicts",
"=",
"append",
"(",
"fallbackConflicts",
",",
"v",
".",
"conflicts",
"[",
"attrTag",
"]",
".",
"Values",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"// Null out the conflicting consFallback attribute values because",
"// cons takes priority. We can't error here because we",
"// know that aConflicts contains valid attr names.",
"consFallbackMinusConflicts",
":=",
"consFallback",
".",
"without",
"(",
"fallbackConflicts",
"...",
")",
"\n",
"// The result is cons with fallbacks coming from any",
"// non conflicting consFallback attributes.",
"return",
"withFallbacks",
"(",
"cons",
",",
"consFallbackMinusConflicts",
")",
",",
"nil",
"\n",
"}"
] | // Merge is defined on Validator. | [
"Merge",
"is",
"defined",
"on",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/constraints/validation.go#L266-L288 |
4,672 | juju/juju | apiserver/facades/client/imagemetadatamanager/metadata.go | createAPI | func createAPI(
st metadataAccess,
newEnviron func() (environs.Environ, error),
resources facade.Resources,
authorizer facade.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
admin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag())
if err != nil {
return nil, common.ErrPerm
}
if !admin {
return nil, common.ErrPerm
}
return &API{
metadata: st,
newEnviron: newEnviron,
}, nil
} | go | func createAPI(
st metadataAccess,
newEnviron func() (environs.Environ, error),
resources facade.Resources,
authorizer facade.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
admin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag())
if err != nil {
return nil, common.ErrPerm
}
if !admin {
return nil, common.ErrPerm
}
return &API{
metadata: st,
newEnviron: newEnviron,
}, nil
} | [
"func",
"createAPI",
"(",
"st",
"metadataAccess",
",",
"newEnviron",
"func",
"(",
")",
"(",
"environs",
".",
"Environ",
",",
"error",
")",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
")",
"(",
"*",
"API",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthClient",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"admin",
",",
"err",
":=",
"authorizer",
".",
"HasPermission",
"(",
"permission",
".",
"SuperuserAccess",
",",
"st",
".",
"ControllerTag",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"if",
"!",
"admin",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n\n",
"return",
"&",
"API",
"{",
"metadata",
":",
"st",
",",
"newEnviron",
":",
"newEnviron",
",",
"}",
",",
"nil",
"\n",
"}"
] | // createAPI returns a new image metadata API facade. | [
"createAPI",
"returns",
"a",
"new",
"image",
"metadata",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/imagemetadatamanager/metadata.go#L33-L54 |
4,673 | juju/juju | apiserver/facades/client/imagemetadatamanager/metadata.go | List | func (api *API) List(filter params.ImageMetadataFilter) (params.ListCloudImageMetadataResult, error) {
found, err := api.metadata.FindMetadata(cloudimagemetadata.MetadataFilter{
Region: filter.Region,
Series: filter.Series,
Arches: filter.Arches,
Stream: filter.Stream,
VirtType: filter.VirtType,
RootStorageType: filter.RootStorageType,
})
if err != nil {
return params.ListCloudImageMetadataResult{}, common.ServerError(err)
}
var all []params.CloudImageMetadata
addAll := func(ms []cloudimagemetadata.Metadata) {
for _, m := range ms {
all = append(all, parseMetadataToParams(m))
}
}
for _, ms := range found {
addAll(ms)
}
sort.Sort(metadataList(all))
return params.ListCloudImageMetadataResult{Result: all}, nil
} | go | func (api *API) List(filter params.ImageMetadataFilter) (params.ListCloudImageMetadataResult, error) {
found, err := api.metadata.FindMetadata(cloudimagemetadata.MetadataFilter{
Region: filter.Region,
Series: filter.Series,
Arches: filter.Arches,
Stream: filter.Stream,
VirtType: filter.VirtType,
RootStorageType: filter.RootStorageType,
})
if err != nil {
return params.ListCloudImageMetadataResult{}, common.ServerError(err)
}
var all []params.CloudImageMetadata
addAll := func(ms []cloudimagemetadata.Metadata) {
for _, m := range ms {
all = append(all, parseMetadataToParams(m))
}
}
for _, ms := range found {
addAll(ms)
}
sort.Sort(metadataList(all))
return params.ListCloudImageMetadataResult{Result: all}, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"List",
"(",
"filter",
"params",
".",
"ImageMetadataFilter",
")",
"(",
"params",
".",
"ListCloudImageMetadataResult",
",",
"error",
")",
"{",
"found",
",",
"err",
":=",
"api",
".",
"metadata",
".",
"FindMetadata",
"(",
"cloudimagemetadata",
".",
"MetadataFilter",
"{",
"Region",
":",
"filter",
".",
"Region",
",",
"Series",
":",
"filter",
".",
"Series",
",",
"Arches",
":",
"filter",
".",
"Arches",
",",
"Stream",
":",
"filter",
".",
"Stream",
",",
"VirtType",
":",
"filter",
".",
"VirtType",
",",
"RootStorageType",
":",
"filter",
".",
"RootStorageType",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ListCloudImageMetadataResult",
"{",
"}",
",",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"all",
"[",
"]",
"params",
".",
"CloudImageMetadata",
"\n",
"addAll",
":=",
"func",
"(",
"ms",
"[",
"]",
"cloudimagemetadata",
".",
"Metadata",
")",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"ms",
"{",
"all",
"=",
"append",
"(",
"all",
",",
"parseMetadataToParams",
"(",
"m",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ms",
":=",
"range",
"found",
"{",
"addAll",
"(",
"ms",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"metadataList",
"(",
"all",
")",
")",
"\n\n",
"return",
"params",
".",
"ListCloudImageMetadataResult",
"{",
"Result",
":",
"all",
"}",
",",
"nil",
"\n",
"}"
] | // List returns all found cloud image metadata that satisfy
// given filter.
// Returned list contains metadata ordered by priority. | [
"List",
"returns",
"all",
"found",
"cloud",
"image",
"metadata",
"that",
"satisfy",
"given",
"filter",
".",
"Returned",
"list",
"contains",
"metadata",
"ordered",
"by",
"priority",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/imagemetadatamanager/metadata.go#L71-L97 |
4,674 | juju/juju | apiserver/facades/client/imagemetadatamanager/metadata.go | Save | func (api *API) Save(metadata params.MetadataSaveParams) (params.ErrorResults, error) {
all, err := imagecommon.Save(api.metadata, metadata)
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
return params.ErrorResults{Results: all}, nil
} | go | func (api *API) Save(metadata params.MetadataSaveParams) (params.ErrorResults, error) {
all, err := imagecommon.Save(api.metadata, metadata)
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
return params.ErrorResults{Results: all}, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"Save",
"(",
"metadata",
"params",
".",
"MetadataSaveParams",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"all",
",",
"err",
":=",
"imagecommon",
".",
"Save",
"(",
"api",
".",
"metadata",
",",
"metadata",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"all",
"}",
",",
"nil",
"\n",
"}"
] | // Save stores given cloud image metadata.
// It supports bulk calls. | [
"Save",
"stores",
"given",
"cloud",
"image",
"metadata",
".",
"It",
"supports",
"bulk",
"calls",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/imagemetadatamanager/metadata.go#L101-L107 |
4,675 | juju/juju | apiserver/facades/client/imagemetadatamanager/metadata.go | Delete | func (api *API) Delete(images params.MetadataImageIds) (params.ErrorResults, error) {
all := make([]params.ErrorResult, len(images.Ids))
for i, imageId := range images.Ids {
err := api.metadata.DeleteMetadata(imageId)
all[i] = params.ErrorResult{common.ServerError(err)}
}
return params.ErrorResults{Results: all}, nil
} | go | func (api *API) Delete(images params.MetadataImageIds) (params.ErrorResults, error) {
all := make([]params.ErrorResult, len(images.Ids))
for i, imageId := range images.Ids {
err := api.metadata.DeleteMetadata(imageId)
all[i] = params.ErrorResult{common.ServerError(err)}
}
return params.ErrorResults{Results: all}, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"Delete",
"(",
"images",
"params",
".",
"MetadataImageIds",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"all",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"images",
".",
"Ids",
")",
")",
"\n",
"for",
"i",
",",
"imageId",
":=",
"range",
"images",
".",
"Ids",
"{",
"err",
":=",
"api",
".",
"metadata",
".",
"DeleteMetadata",
"(",
"imageId",
")",
"\n",
"all",
"[",
"i",
"]",
"=",
"params",
".",
"ErrorResult",
"{",
"common",
".",
"ServerError",
"(",
"err",
")",
"}",
"\n",
"}",
"\n",
"return",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"all",
"}",
",",
"nil",
"\n",
"}"
] | // Delete deletes cloud image metadata for given image ids.
// It supports bulk calls. | [
"Delete",
"deletes",
"cloud",
"image",
"metadata",
"for",
"given",
"image",
"ids",
".",
"It",
"supports",
"bulk",
"calls",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/imagemetadatamanager/metadata.go#L111-L118 |
4,676 | juju/juju | provider/lxd/storage.go | CreateFilesystems | func (s *lxdFilesystemSource) CreateFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemParams) (_ []storage.CreateFilesystemsResult, err error) {
results := make([]storage.CreateFilesystemsResult, len(args))
for i, arg := range args {
if err := s.ValidateFilesystemParams(arg); err != nil {
results[i].Error = err
continue
}
filesystem, err := s.createFilesystem(arg)
if err != nil {
results[i].Error = err
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
continue
}
results[i].Filesystem = filesystem
}
return results, nil
} | go | func (s *lxdFilesystemSource) CreateFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemParams) (_ []storage.CreateFilesystemsResult, err error) {
results := make([]storage.CreateFilesystemsResult, len(args))
for i, arg := range args {
if err := s.ValidateFilesystemParams(arg); err != nil {
results[i].Error = err
continue
}
filesystem, err := s.createFilesystem(arg)
if err != nil {
results[i].Error = err
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
continue
}
results[i].Filesystem = filesystem
}
return results, nil
} | [
"func",
"(",
"s",
"*",
"lxdFilesystemSource",
")",
"CreateFilesystems",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"[",
"]",
"storage",
".",
"FilesystemParams",
")",
"(",
"_",
"[",
"]",
"storage",
".",
"CreateFilesystemsResult",
",",
"err",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"storage",
".",
"CreateFilesystemsResult",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"err",
":=",
"s",
".",
"ValidateFilesystemParams",
"(",
"arg",
")",
";",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"filesystem",
",",
"err",
":=",
"s",
".",
"createFilesystem",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"err",
"\n",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
".",
"Filesystem",
"=",
"filesystem",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // CreateFilesystems is specified on the storage.FilesystemSource interface. | [
"CreateFilesystems",
"is",
"specified",
"on",
"the",
"storage",
".",
"FilesystemSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/storage.go#L235-L251 |
4,677 | juju/juju | provider/lxd/storage.go | parseFilesystemId | func parseFilesystemId(id string) (lxdPool, volumeName string, _ error) {
fields := strings.SplitN(id, ":", 2)
if len(fields) < 2 {
return "", "", errors.Errorf(
"invalid filesystem ID %q; expected ID in format <lxd-pool>:<volume-name>", id,
)
}
return fields[0], fields[1], nil
} | go | func parseFilesystemId(id string) (lxdPool, volumeName string, _ error) {
fields := strings.SplitN(id, ":", 2)
if len(fields) < 2 {
return "", "", errors.Errorf(
"invalid filesystem ID %q; expected ID in format <lxd-pool>:<volume-name>", id,
)
}
return fields[0], fields[1], nil
} | [
"func",
"parseFilesystemId",
"(",
"id",
"string",
")",
"(",
"lxdPool",
",",
"volumeName",
"string",
",",
"_",
"error",
")",
"{",
"fields",
":=",
"strings",
".",
"SplitN",
"(",
"id",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
",",
")",
"\n",
"}",
"\n",
"return",
"fields",
"[",
"0",
"]",
",",
"fields",
"[",
"1",
"]",
",",
"nil",
"\n",
"}"
] | // parseFilesystemId parses the given filesystem ID, returning the underlying
// LXD storage pool name and volume name. | [
"parseFilesystemId",
"parses",
"the",
"given",
"filesystem",
"ID",
"returning",
"the",
"underlying",
"LXD",
"storage",
"pool",
"name",
"and",
"volume",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/storage.go#L306-L314 |
4,678 | juju/juju | provider/lxd/storage.go | ReleaseFilesystems | func (s *lxdFilesystemSource) ReleaseFilesystems(ctx context.ProviderCallContext, filesystemIds []string) ([]error, error) {
results := make([]error, len(filesystemIds))
for i, filesystemId := range filesystemIds {
results[i] = s.releaseFilesystem(filesystemId)
common.HandleCredentialError(IsAuthorisationFailure, results[i], ctx)
}
return results, nil
} | go | func (s *lxdFilesystemSource) ReleaseFilesystems(ctx context.ProviderCallContext, filesystemIds []string) ([]error, error) {
results := make([]error, len(filesystemIds))
for i, filesystemId := range filesystemIds {
results[i] = s.releaseFilesystem(filesystemId)
common.HandleCredentialError(IsAuthorisationFailure, results[i], ctx)
}
return results, nil
} | [
"func",
"(",
"s",
"*",
"lxdFilesystemSource",
")",
"ReleaseFilesystems",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"filesystemIds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"filesystemIds",
")",
")",
"\n",
"for",
"i",
",",
"filesystemId",
":=",
"range",
"filesystemIds",
"{",
"results",
"[",
"i",
"]",
"=",
"s",
".",
"releaseFilesystem",
"(",
"filesystemId",
")",
"\n",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"results",
"[",
"i",
"]",
",",
"ctx",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // ReleaseFilesystems is specified on the storage.FilesystemSource interface. | [
"ReleaseFilesystems",
"is",
"specified",
"on",
"the",
"storage",
".",
"FilesystemSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/storage.go#L376-L383 |
4,679 | juju/juju | provider/lxd/storage.go | AttachFilesystems | func (s *lxdFilesystemSource) AttachFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemAttachmentParams) ([]storage.AttachFilesystemsResult, error) {
var instanceIds []instance.Id
instanceIdsSeen := make(set.Strings)
for _, arg := range args {
if instanceIdsSeen.Contains(string(arg.InstanceId)) {
continue
}
instanceIdsSeen.Add(string(arg.InstanceId))
instanceIds = append(instanceIds, arg.InstanceId)
}
instances, err := s.env.Instances(ctx, instanceIds)
switch err {
case nil, environs.ErrPartialInstances, environs.ErrNoInstances:
default:
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
return nil, errors.Trace(err)
}
results := make([]storage.AttachFilesystemsResult, len(args))
for i, arg := range args {
var inst *environInstance
for i, instanceId := range instanceIds {
if instanceId != arg.InstanceId {
continue
}
if instances[i] != nil {
inst = instances[i].(*environInstance)
}
break
}
attachment, err := s.attachFilesystem(arg, inst)
if err != nil {
results[i].Error = errors.Annotatef(
err, "attaching %s to %s",
names.ReadableString(arg.Filesystem),
names.ReadableString(arg.Machine),
)
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
continue
}
results[i].FilesystemAttachment = attachment
}
return results, nil
} | go | func (s *lxdFilesystemSource) AttachFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemAttachmentParams) ([]storage.AttachFilesystemsResult, error) {
var instanceIds []instance.Id
instanceIdsSeen := make(set.Strings)
for _, arg := range args {
if instanceIdsSeen.Contains(string(arg.InstanceId)) {
continue
}
instanceIdsSeen.Add(string(arg.InstanceId))
instanceIds = append(instanceIds, arg.InstanceId)
}
instances, err := s.env.Instances(ctx, instanceIds)
switch err {
case nil, environs.ErrPartialInstances, environs.ErrNoInstances:
default:
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
return nil, errors.Trace(err)
}
results := make([]storage.AttachFilesystemsResult, len(args))
for i, arg := range args {
var inst *environInstance
for i, instanceId := range instanceIds {
if instanceId != arg.InstanceId {
continue
}
if instances[i] != nil {
inst = instances[i].(*environInstance)
}
break
}
attachment, err := s.attachFilesystem(arg, inst)
if err != nil {
results[i].Error = errors.Annotatef(
err, "attaching %s to %s",
names.ReadableString(arg.Filesystem),
names.ReadableString(arg.Machine),
)
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
continue
}
results[i].FilesystemAttachment = attachment
}
return results, nil
} | [
"func",
"(",
"s",
"*",
"lxdFilesystemSource",
")",
"AttachFilesystems",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"[",
"]",
"storage",
".",
"FilesystemAttachmentParams",
")",
"(",
"[",
"]",
"storage",
".",
"AttachFilesystemsResult",
",",
"error",
")",
"{",
"var",
"instanceIds",
"[",
"]",
"instance",
".",
"Id",
"\n",
"instanceIdsSeen",
":=",
"make",
"(",
"set",
".",
"Strings",
")",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"instanceIdsSeen",
".",
"Contains",
"(",
"string",
"(",
"arg",
".",
"InstanceId",
")",
")",
"{",
"continue",
"\n",
"}",
"\n",
"instanceIdsSeen",
".",
"Add",
"(",
"string",
"(",
"arg",
".",
"InstanceId",
")",
")",
"\n",
"instanceIds",
"=",
"append",
"(",
"instanceIds",
",",
"arg",
".",
"InstanceId",
")",
"\n",
"}",
"\n",
"instances",
",",
"err",
":=",
"s",
".",
"env",
".",
"Instances",
"(",
"ctx",
",",
"instanceIds",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
",",
"environs",
".",
"ErrPartialInstances",
",",
"environs",
".",
"ErrNoInstances",
":",
"default",
":",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"results",
":=",
"make",
"(",
"[",
"]",
"storage",
".",
"AttachFilesystemsResult",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"var",
"inst",
"*",
"environInstance",
"\n",
"for",
"i",
",",
"instanceId",
":=",
"range",
"instanceIds",
"{",
"if",
"instanceId",
"!=",
"arg",
".",
"InstanceId",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"instances",
"[",
"i",
"]",
"!=",
"nil",
"{",
"inst",
"=",
"instances",
"[",
"i",
"]",
".",
"(",
"*",
"environInstance",
")",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"attachment",
",",
"err",
":=",
"s",
".",
"attachFilesystem",
"(",
"arg",
",",
"inst",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"names",
".",
"ReadableString",
"(",
"arg",
".",
"Filesystem",
")",
",",
"names",
".",
"ReadableString",
"(",
"arg",
".",
"Machine",
")",
",",
")",
"\n",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
".",
"FilesystemAttachment",
"=",
"attachment",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // AttachFilesystems is specified on the storage.FilesystemSource interface. | [
"AttachFilesystems",
"is",
"specified",
"on",
"the",
"storage",
".",
"FilesystemSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/storage.go#L416-L459 |
4,680 | juju/juju | provider/lxd/storage.go | ImportFilesystem | func (s *lxdFilesystemSource) ImportFilesystem(
callCtx context.ProviderCallContext,
filesystemId string,
tags map[string]string,
) (storage.FilesystemInfo, error) {
lxdPool, volumeName, err := parseFilesystemId(filesystemId)
if err != nil {
return storage.FilesystemInfo{}, errors.Trace(err)
}
volume, eTag, err := s.env.server().GetStoragePoolVolume(lxdPool, storagePoolVolumeType, volumeName)
if err != nil {
common.HandleCredentialError(IsAuthorisationFailure, err, callCtx)
return storage.FilesystemInfo{}, errors.Trace(err)
}
if len(volume.UsedBy) > 0 {
return storage.FilesystemInfo{}, errors.Errorf(
"filesystem %q is in use by %d containers, cannot import",
filesystemId, len(volume.UsedBy),
)
}
// NOTE(axw) not all drivers support specifying a volume size.
// If we can't find a size config attribute, we have to make
// up a number since the model will not allow a size of zero.
// We use the magic number 999GiB to indicate that it's unknown.
size := uint64(999 * 1024) // 999GiB
if sizeString := volume.Config["size"]; sizeString != "" {
n, err := shared.ParseByteSizeString(sizeString)
if err != nil {
return storage.FilesystemInfo{}, errors.Annotate(err, "parsing size")
}
// ParseByteSizeString returns bytes, we want MiB.
size = uint64(n / (1024 * 1024))
}
if len(tags) > 0 {
// Update the volume's user-data with the given tags. This will
// include updating the model and controller UUIDs, so that the
// storage is associated with this controller and model.
if volume.Config == nil {
volume.Config = make(map[string]string)
}
for k, v := range tags {
volume.Config["user."+k] = v
}
if err := s.env.server().UpdateStoragePoolVolume(
lxdPool, storagePoolVolumeType, volumeName, volume.Writable(), eTag); err != nil {
common.HandleCredentialError(IsAuthorisationFailure, err, callCtx)
return storage.FilesystemInfo{}, errors.Annotate(err, "tagging volume")
}
}
return storage.FilesystemInfo{
FilesystemId: filesystemId,
Size: size,
}, nil
} | go | func (s *lxdFilesystemSource) ImportFilesystem(
callCtx context.ProviderCallContext,
filesystemId string,
tags map[string]string,
) (storage.FilesystemInfo, error) {
lxdPool, volumeName, err := parseFilesystemId(filesystemId)
if err != nil {
return storage.FilesystemInfo{}, errors.Trace(err)
}
volume, eTag, err := s.env.server().GetStoragePoolVolume(lxdPool, storagePoolVolumeType, volumeName)
if err != nil {
common.HandleCredentialError(IsAuthorisationFailure, err, callCtx)
return storage.FilesystemInfo{}, errors.Trace(err)
}
if len(volume.UsedBy) > 0 {
return storage.FilesystemInfo{}, errors.Errorf(
"filesystem %q is in use by %d containers, cannot import",
filesystemId, len(volume.UsedBy),
)
}
// NOTE(axw) not all drivers support specifying a volume size.
// If we can't find a size config attribute, we have to make
// up a number since the model will not allow a size of zero.
// We use the magic number 999GiB to indicate that it's unknown.
size := uint64(999 * 1024) // 999GiB
if sizeString := volume.Config["size"]; sizeString != "" {
n, err := shared.ParseByteSizeString(sizeString)
if err != nil {
return storage.FilesystemInfo{}, errors.Annotate(err, "parsing size")
}
// ParseByteSizeString returns bytes, we want MiB.
size = uint64(n / (1024 * 1024))
}
if len(tags) > 0 {
// Update the volume's user-data with the given tags. This will
// include updating the model and controller UUIDs, so that the
// storage is associated with this controller and model.
if volume.Config == nil {
volume.Config = make(map[string]string)
}
for k, v := range tags {
volume.Config["user."+k] = v
}
if err := s.env.server().UpdateStoragePoolVolume(
lxdPool, storagePoolVolumeType, volumeName, volume.Writable(), eTag); err != nil {
common.HandleCredentialError(IsAuthorisationFailure, err, callCtx)
return storage.FilesystemInfo{}, errors.Annotate(err, "tagging volume")
}
}
return storage.FilesystemInfo{
FilesystemId: filesystemId,
Size: size,
}, nil
} | [
"func",
"(",
"s",
"*",
"lxdFilesystemSource",
")",
"ImportFilesystem",
"(",
"callCtx",
"context",
".",
"ProviderCallContext",
",",
"filesystemId",
"string",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
",",
")",
"(",
"storage",
".",
"FilesystemInfo",
",",
"error",
")",
"{",
"lxdPool",
",",
"volumeName",
",",
"err",
":=",
"parseFilesystemId",
"(",
"filesystemId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"storage",
".",
"FilesystemInfo",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"volume",
",",
"eTag",
",",
"err",
":=",
"s",
".",
"env",
".",
"server",
"(",
")",
".",
"GetStoragePoolVolume",
"(",
"lxdPool",
",",
"storagePoolVolumeType",
",",
"volumeName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"callCtx",
")",
"\n",
"return",
"storage",
".",
"FilesystemInfo",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"volume",
".",
"UsedBy",
")",
">",
"0",
"{",
"return",
"storage",
".",
"FilesystemInfo",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filesystemId",
",",
"len",
"(",
"volume",
".",
"UsedBy",
")",
",",
")",
"\n",
"}",
"\n\n",
"// NOTE(axw) not all drivers support specifying a volume size.",
"// If we can't find a size config attribute, we have to make",
"// up a number since the model will not allow a size of zero.",
"// We use the magic number 999GiB to indicate that it's unknown.",
"size",
":=",
"uint64",
"(",
"999",
"*",
"1024",
")",
"// 999GiB",
"\n",
"if",
"sizeString",
":=",
"volume",
".",
"Config",
"[",
"\"",
"\"",
"]",
";",
"sizeString",
"!=",
"\"",
"\"",
"{",
"n",
",",
"err",
":=",
"shared",
".",
"ParseByteSizeString",
"(",
"sizeString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"storage",
".",
"FilesystemInfo",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// ParseByteSizeString returns bytes, we want MiB.",
"size",
"=",
"uint64",
"(",
"n",
"/",
"(",
"1024",
"*",
"1024",
")",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"tags",
")",
">",
"0",
"{",
"// Update the volume's user-data with the given tags. This will",
"// include updating the model and controller UUIDs, so that the",
"// storage is associated with this controller and model.",
"if",
"volume",
".",
"Config",
"==",
"nil",
"{",
"volume",
".",
"Config",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"tags",
"{",
"volume",
".",
"Config",
"[",
"\"",
"\"",
"+",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"env",
".",
"server",
"(",
")",
".",
"UpdateStoragePoolVolume",
"(",
"lxdPool",
",",
"storagePoolVolumeType",
",",
"volumeName",
",",
"volume",
".",
"Writable",
"(",
")",
",",
"eTag",
")",
";",
"err",
"!=",
"nil",
"{",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"callCtx",
")",
"\n",
"return",
"storage",
".",
"FilesystemInfo",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"storage",
".",
"FilesystemInfo",
"{",
"FilesystemId",
":",
"filesystemId",
",",
"Size",
":",
"size",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ImportFilesystem is part of the storage.FilesystemImporter interface. | [
"ImportFilesystem",
"is",
"part",
"of",
"the",
"storage",
".",
"FilesystemImporter",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/storage.go#L547-L603 |
4,681 | juju/juju | provider/cloudsigma/constraints.go | newConstraints | func newConstraints(bootstrap bool, jc constraints.Value, img *imagemetadata.ImageMetadata) *sigmaConstraints {
var sc = sigmaConstraints{
driveTemplate: img.Id,
}
if size := jc.RootDisk; bootstrap && size == nil {
sc.driveSize = defaultDriveGB * gosigma.Gigabyte
} else if size != nil {
sc.driveSize = *size * gosigma.Megabyte
}
if c := jc.CpuCores; c != nil {
sc.cores = *c
} else {
sc.cores = 1
}
if p := jc.CpuPower; p != nil {
sc.power = *p
} else {
if sc.cores == 1 {
// The default of cpu power is 2000 Mhz
sc.power = defaultCPUPower
} else {
// The maximum amount of cpu per smp is 2300
sc.power = sc.cores * defaultCPUPower
}
}
if m := jc.Mem; m != nil {
sc.mem = *m * gosigma.Megabyte
} else {
sc.mem = defaultMemoryGB * gosigma.Gigabyte
}
return &sc
} | go | func newConstraints(bootstrap bool, jc constraints.Value, img *imagemetadata.ImageMetadata) *sigmaConstraints {
var sc = sigmaConstraints{
driveTemplate: img.Id,
}
if size := jc.RootDisk; bootstrap && size == nil {
sc.driveSize = defaultDriveGB * gosigma.Gigabyte
} else if size != nil {
sc.driveSize = *size * gosigma.Megabyte
}
if c := jc.CpuCores; c != nil {
sc.cores = *c
} else {
sc.cores = 1
}
if p := jc.CpuPower; p != nil {
sc.power = *p
} else {
if sc.cores == 1 {
// The default of cpu power is 2000 Mhz
sc.power = defaultCPUPower
} else {
// The maximum amount of cpu per smp is 2300
sc.power = sc.cores * defaultCPUPower
}
}
if m := jc.Mem; m != nil {
sc.mem = *m * gosigma.Megabyte
} else {
sc.mem = defaultMemoryGB * gosigma.Gigabyte
}
return &sc
} | [
"func",
"newConstraints",
"(",
"bootstrap",
"bool",
",",
"jc",
"constraints",
".",
"Value",
",",
"img",
"*",
"imagemetadata",
".",
"ImageMetadata",
")",
"*",
"sigmaConstraints",
"{",
"var",
"sc",
"=",
"sigmaConstraints",
"{",
"driveTemplate",
":",
"img",
".",
"Id",
",",
"}",
"\n\n",
"if",
"size",
":=",
"jc",
".",
"RootDisk",
";",
"bootstrap",
"&&",
"size",
"==",
"nil",
"{",
"sc",
".",
"driveSize",
"=",
"defaultDriveGB",
"*",
"gosigma",
".",
"Gigabyte",
"\n",
"}",
"else",
"if",
"size",
"!=",
"nil",
"{",
"sc",
".",
"driveSize",
"=",
"*",
"size",
"*",
"gosigma",
".",
"Megabyte",
"\n",
"}",
"\n\n",
"if",
"c",
":=",
"jc",
".",
"CpuCores",
";",
"c",
"!=",
"nil",
"{",
"sc",
".",
"cores",
"=",
"*",
"c",
"\n",
"}",
"else",
"{",
"sc",
".",
"cores",
"=",
"1",
"\n",
"}",
"\n\n",
"if",
"p",
":=",
"jc",
".",
"CpuPower",
";",
"p",
"!=",
"nil",
"{",
"sc",
".",
"power",
"=",
"*",
"p",
"\n",
"}",
"else",
"{",
"if",
"sc",
".",
"cores",
"==",
"1",
"{",
"// The default of cpu power is 2000 Mhz",
"sc",
".",
"power",
"=",
"defaultCPUPower",
"\n",
"}",
"else",
"{",
"// The maximum amount of cpu per smp is 2300",
"sc",
".",
"power",
"=",
"sc",
".",
"cores",
"*",
"defaultCPUPower",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"m",
":=",
"jc",
".",
"Mem",
";",
"m",
"!=",
"nil",
"{",
"sc",
".",
"mem",
"=",
"*",
"m",
"*",
"gosigma",
".",
"Megabyte",
"\n",
"}",
"else",
"{",
"sc",
".",
"mem",
"=",
"defaultMemoryGB",
"*",
"gosigma",
".",
"Gigabyte",
"\n",
"}",
"\n\n",
"return",
"&",
"sc",
"\n",
"}"
] | // newConstraints creates new CloudSigma constraints from juju common constraints | [
"newConstraints",
"creates",
"new",
"CloudSigma",
"constraints",
"from",
"juju",
"common",
"constraints"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/constraints.go#L30-L66 |
4,682 | juju/juju | resource/content.go | GenerateContent | func GenerateContent(reader io.ReadSeeker) (Content, error) {
var sizer utils.SizeTracker
sizingReader := io.TeeReader(reader, &sizer)
fp, err := charmresource.GenerateFingerprint(sizingReader)
if err != nil {
return Content{}, errors.Trace(err)
}
if _, err := reader.Seek(0, os.SEEK_SET); err != nil {
return Content{}, errors.Trace(err)
}
size := sizer.Size()
content := Content{
Data: reader,
Size: size,
Fingerprint: fp,
}
return content, nil
} | go | func GenerateContent(reader io.ReadSeeker) (Content, error) {
var sizer utils.SizeTracker
sizingReader := io.TeeReader(reader, &sizer)
fp, err := charmresource.GenerateFingerprint(sizingReader)
if err != nil {
return Content{}, errors.Trace(err)
}
if _, err := reader.Seek(0, os.SEEK_SET); err != nil {
return Content{}, errors.Trace(err)
}
size := sizer.Size()
content := Content{
Data: reader,
Size: size,
Fingerprint: fp,
}
return content, nil
} | [
"func",
"GenerateContent",
"(",
"reader",
"io",
".",
"ReadSeeker",
")",
"(",
"Content",
",",
"error",
")",
"{",
"var",
"sizer",
"utils",
".",
"SizeTracker",
"\n",
"sizingReader",
":=",
"io",
".",
"TeeReader",
"(",
"reader",
",",
"&",
"sizer",
")",
"\n",
"fp",
",",
"err",
":=",
"charmresource",
".",
"GenerateFingerprint",
"(",
"sizingReader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Content",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"reader",
".",
"Seek",
"(",
"0",
",",
"os",
".",
"SEEK_SET",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"Content",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"size",
":=",
"sizer",
".",
"Size",
"(",
")",
"\n\n",
"content",
":=",
"Content",
"{",
"Data",
":",
"reader",
",",
"Size",
":",
"size",
",",
"Fingerprint",
":",
"fp",
",",
"}",
"\n",
"return",
"content",
",",
"nil",
"\n",
"}"
] | // GenerateContent returns a new Content for the given data stream. | [
"GenerateContent",
"returns",
"a",
"new",
"Content",
"for",
"the",
"given",
"data",
"stream",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/content.go#L31-L49 |
4,683 | juju/juju | provider/gce/google/conn_disks.go | CreateDisks | func (gce *Connection) CreateDisks(zone string, disks []DiskSpec) ([]*Disk, error) {
results := make([]*Disk, len(disks))
for i, disk := range disks {
d, err := disk.newDetached()
if err != nil {
return []*Disk{}, errors.Annotate(err, "cannot create disk spec")
}
if err := gce.createDisk(zone, d); err != nil {
return []*Disk{}, errors.Annotatef(err, "cannot create disk %q", disk.Name)
}
results[i] = NewDisk(d)
}
return results, nil
} | go | func (gce *Connection) CreateDisks(zone string, disks []DiskSpec) ([]*Disk, error) {
results := make([]*Disk, len(disks))
for i, disk := range disks {
d, err := disk.newDetached()
if err != nil {
return []*Disk{}, errors.Annotate(err, "cannot create disk spec")
}
if err := gce.createDisk(zone, d); err != nil {
return []*Disk{}, errors.Annotatef(err, "cannot create disk %q", disk.Name)
}
results[i] = NewDisk(d)
}
return results, nil
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"CreateDisks",
"(",
"zone",
"string",
",",
"disks",
"[",
"]",
"DiskSpec",
")",
"(",
"[",
"]",
"*",
"Disk",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"*",
"Disk",
",",
"len",
"(",
"disks",
")",
")",
"\n",
"for",
"i",
",",
"disk",
":=",
"range",
"disks",
"{",
"d",
",",
"err",
":=",
"disk",
".",
"newDetached",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"*",
"Disk",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"gce",
".",
"createDisk",
"(",
"zone",
",",
"d",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"*",
"Disk",
"{",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"disk",
".",
"Name",
")",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
"=",
"NewDisk",
"(",
"d",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // CreateDisks implements storage section of gceConnection. | [
"CreateDisks",
"implements",
"storage",
"section",
"of",
"gceConnection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L15-L28 |
4,684 | juju/juju | provider/gce/google/conn_disks.go | Disks | func (gce *Connection) Disks() ([]*Disk, error) {
computeDisks, err := gce.raw.ListDisks(gce.projectID)
if err != nil {
return nil, errors.Annotate(err, "cannot list disks")
}
disks := make([]*Disk, len(computeDisks))
for i, disk := range computeDisks {
disks[i] = NewDisk(disk)
}
return disks, nil
} | go | func (gce *Connection) Disks() ([]*Disk, error) {
computeDisks, err := gce.raw.ListDisks(gce.projectID)
if err != nil {
return nil, errors.Annotate(err, "cannot list disks")
}
disks := make([]*Disk, len(computeDisks))
for i, disk := range computeDisks {
disks[i] = NewDisk(disk)
}
return disks, nil
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"Disks",
"(",
")",
"(",
"[",
"]",
"*",
"Disk",
",",
"error",
")",
"{",
"computeDisks",
",",
"err",
":=",
"gce",
".",
"raw",
".",
"ListDisks",
"(",
"gce",
".",
"projectID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"disks",
":=",
"make",
"(",
"[",
"]",
"*",
"Disk",
",",
"len",
"(",
"computeDisks",
")",
")",
"\n",
"for",
"i",
",",
"disk",
":=",
"range",
"computeDisks",
"{",
"disks",
"[",
"i",
"]",
"=",
"NewDisk",
"(",
"disk",
")",
"\n",
"}",
"\n",
"return",
"disks",
",",
"nil",
"\n",
"}"
] | // Disks implements storage section of gceConnection. | [
"Disks",
"implements",
"storage",
"section",
"of",
"gceConnection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L35-L45 |
4,685 | juju/juju | provider/gce/google/conn_disks.go | Disk | func (gce *Connection) Disk(zone, name string) (*Disk, error) {
d, err := gce.raw.GetDisk(gce.projectID, zone, name)
if err != nil {
return nil, errors.Annotatef(err, "cannot get disk %q in zone %q", name, zone)
}
return NewDisk(d), nil
} | go | func (gce *Connection) Disk(zone, name string) (*Disk, error) {
d, err := gce.raw.GetDisk(gce.projectID, zone, name)
if err != nil {
return nil, errors.Annotatef(err, "cannot get disk %q in zone %q", name, zone)
}
return NewDisk(d), nil
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"Disk",
"(",
"zone",
",",
"name",
"string",
")",
"(",
"*",
"Disk",
",",
"error",
")",
"{",
"d",
",",
"err",
":=",
"gce",
".",
"raw",
".",
"GetDisk",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
",",
"zone",
")",
"\n",
"}",
"\n",
"return",
"NewDisk",
"(",
"d",
")",
",",
"nil",
"\n",
"}"
] | // Disk implements storage section of gceConnection. | [
"Disk",
"implements",
"storage",
"section",
"of",
"gceConnection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L54-L60 |
4,686 | juju/juju | provider/gce/google/conn_disks.go | SetDiskLabels | func (gce *Connection) SetDiskLabels(zone, name, labelFingerprint string, labels map[string]string) error {
err := gce.raw.SetDiskLabels(gce.projectID, zone, name, labelFingerprint, labels)
return errors.Annotatef(err, "cannot update labels for disk %q in zone %q", name, zone)
} | go | func (gce *Connection) SetDiskLabels(zone, name, labelFingerprint string, labels map[string]string) error {
err := gce.raw.SetDiskLabels(gce.projectID, zone, name, labelFingerprint, labels)
return errors.Annotatef(err, "cannot update labels for disk %q in zone %q", name, zone)
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"SetDiskLabels",
"(",
"zone",
",",
"name",
",",
"labelFingerprint",
"string",
",",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"err",
":=",
"gce",
".",
"raw",
".",
"SetDiskLabels",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"name",
",",
"labelFingerprint",
",",
"labels",
")",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
",",
"zone",
")",
"\n",
"}"
] | // SetDiskLabels implements storage section of gceConnection. | [
"SetDiskLabels",
"implements",
"storage",
"section",
"of",
"gceConnection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L63-L66 |
4,687 | juju/juju | provider/gce/google/conn_disks.go | AttachDisk | func (gce *Connection) AttachDisk(zone, volumeName, instanceId string, mode DiskMode) (*AttachedDisk, error) {
disk, err := gce.raw.GetDisk(gce.projectID, zone, volumeName)
if err != nil {
return nil, errors.Annotatef(err, "cannot obtain disk %q to attach it", volumeName)
}
attachedDisk := &compute.AttachedDisk{
// Specifies a unique device name of your choice that
// is reflected into the /dev/disk/by-id/google-*
DeviceName: deviceName(zone, disk.Id),
Source: disk.SelfLink,
Mode: string(mode),
}
err = gce.raw.AttachDisk(gce.projectID, zone, instanceId, attachedDisk)
if err != nil {
return nil, errors.Annotate(err, "cannot attach disk")
}
return &AttachedDisk{
VolumeName: volumeName,
DeviceName: attachedDisk.DeviceName,
Mode: mode,
}, nil
} | go | func (gce *Connection) AttachDisk(zone, volumeName, instanceId string, mode DiskMode) (*AttachedDisk, error) {
disk, err := gce.raw.GetDisk(gce.projectID, zone, volumeName)
if err != nil {
return nil, errors.Annotatef(err, "cannot obtain disk %q to attach it", volumeName)
}
attachedDisk := &compute.AttachedDisk{
// Specifies a unique device name of your choice that
// is reflected into the /dev/disk/by-id/google-*
DeviceName: deviceName(zone, disk.Id),
Source: disk.SelfLink,
Mode: string(mode),
}
err = gce.raw.AttachDisk(gce.projectID, zone, instanceId, attachedDisk)
if err != nil {
return nil, errors.Annotate(err, "cannot attach disk")
}
return &AttachedDisk{
VolumeName: volumeName,
DeviceName: attachedDisk.DeviceName,
Mode: mode,
}, nil
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"AttachDisk",
"(",
"zone",
",",
"volumeName",
",",
"instanceId",
"string",
",",
"mode",
"DiskMode",
")",
"(",
"*",
"AttachedDisk",
",",
"error",
")",
"{",
"disk",
",",
"err",
":=",
"gce",
".",
"raw",
".",
"GetDisk",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"volumeName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volumeName",
")",
"\n",
"}",
"\n",
"attachedDisk",
":=",
"&",
"compute",
".",
"AttachedDisk",
"{",
"// Specifies a unique device name of your choice that",
"// is reflected into the /dev/disk/by-id/google-*",
"DeviceName",
":",
"deviceName",
"(",
"zone",
",",
"disk",
".",
"Id",
")",
",",
"Source",
":",
"disk",
".",
"SelfLink",
",",
"Mode",
":",
"string",
"(",
"mode",
")",
",",
"}",
"\n",
"err",
"=",
"gce",
".",
"raw",
".",
"AttachDisk",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"instanceId",
",",
"attachedDisk",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"AttachedDisk",
"{",
"VolumeName",
":",
"volumeName",
",",
"DeviceName",
":",
"attachedDisk",
".",
"DeviceName",
",",
"Mode",
":",
"mode",
",",
"}",
",",
"nil",
"\n",
"}"
] | // AttachDisk implements storage section of gceConnection. | [
"AttachDisk",
"implements",
"storage",
"section",
"of",
"gceConnection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L77-L98 |
4,688 | juju/juju | provider/gce/google/conn_disks.go | DetachDisk | func (gce *Connection) DetachDisk(zone, instanceId, volumeName string) error {
disk, err := gce.raw.GetDisk(gce.projectID, zone, volumeName)
if err != nil {
return errors.Annotatef(err, "cannot obtain disk %q to detach it", volumeName)
}
dn := deviceName(zone, disk.Id)
err = gce.raw.DetachDisk(gce.projectID, zone, instanceId, dn)
if err != nil {
return errors.Annotatef(err, "cannot detach %q from %q", dn, instanceId)
}
return nil
} | go | func (gce *Connection) DetachDisk(zone, instanceId, volumeName string) error {
disk, err := gce.raw.GetDisk(gce.projectID, zone, volumeName)
if err != nil {
return errors.Annotatef(err, "cannot obtain disk %q to detach it", volumeName)
}
dn := deviceName(zone, disk.Id)
err = gce.raw.DetachDisk(gce.projectID, zone, instanceId, dn)
if err != nil {
return errors.Annotatef(err, "cannot detach %q from %q", dn, instanceId)
}
return nil
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"DetachDisk",
"(",
"zone",
",",
"instanceId",
",",
"volumeName",
"string",
")",
"error",
"{",
"disk",
",",
"err",
":=",
"gce",
".",
"raw",
".",
"GetDisk",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"volumeName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volumeName",
")",
"\n",
"}",
"\n",
"dn",
":=",
"deviceName",
"(",
"zone",
",",
"disk",
".",
"Id",
")",
"\n",
"err",
"=",
"gce",
".",
"raw",
".",
"DetachDisk",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"instanceId",
",",
"dn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"dn",
",",
"instanceId",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DetachDisk implements storage section of gceConnection.
// disk existence is checked but not instance nor is attachment. | [
"DetachDisk",
"implements",
"storage",
"section",
"of",
"gceConnection",
".",
"disk",
"existence",
"is",
"checked",
"but",
"not",
"instance",
"nor",
"is",
"attachment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L102-L113 |
4,689 | juju/juju | provider/gce/google/conn_disks.go | InstanceDisks | func (gce *Connection) InstanceDisks(zone, instanceId string) ([]*AttachedDisk, error) {
disks, err := gce.raw.InstanceDisks(gce.projectID, zone, instanceId)
if err != nil {
return nil, errors.Annotatef(err, "cannot get disks from instance")
}
att := make([]*AttachedDisk, len(disks))
for i, disk := range disks {
att[i] = &AttachedDisk{
VolumeName: sourceToVolumeName(disk.Source),
DeviceName: disk.DeviceName,
Mode: DiskMode(disk.Mode),
}
}
return att, nil
} | go | func (gce *Connection) InstanceDisks(zone, instanceId string) ([]*AttachedDisk, error) {
disks, err := gce.raw.InstanceDisks(gce.projectID, zone, instanceId)
if err != nil {
return nil, errors.Annotatef(err, "cannot get disks from instance")
}
att := make([]*AttachedDisk, len(disks))
for i, disk := range disks {
att[i] = &AttachedDisk{
VolumeName: sourceToVolumeName(disk.Source),
DeviceName: disk.DeviceName,
Mode: DiskMode(disk.Mode),
}
}
return att, nil
} | [
"func",
"(",
"gce",
"*",
"Connection",
")",
"InstanceDisks",
"(",
"zone",
",",
"instanceId",
"string",
")",
"(",
"[",
"]",
"*",
"AttachedDisk",
",",
"error",
")",
"{",
"disks",
",",
"err",
":=",
"gce",
".",
"raw",
".",
"InstanceDisks",
"(",
"gce",
".",
"projectID",
",",
"zone",
",",
"instanceId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"att",
":=",
"make",
"(",
"[",
"]",
"*",
"AttachedDisk",
",",
"len",
"(",
"disks",
")",
")",
"\n",
"for",
"i",
",",
"disk",
":=",
"range",
"disks",
"{",
"att",
"[",
"i",
"]",
"=",
"&",
"AttachedDisk",
"{",
"VolumeName",
":",
"sourceToVolumeName",
"(",
"disk",
".",
"Source",
")",
",",
"DeviceName",
":",
"disk",
".",
"DeviceName",
",",
"Mode",
":",
"DiskMode",
"(",
"disk",
".",
"Mode",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"att",
",",
"nil",
"\n",
"}"
] | // InstanceDisks implements storage section of gceConnection. | [
"InstanceDisks",
"implements",
"storage",
"section",
"of",
"gceConnection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_disks.go#L136-L150 |
4,690 | juju/juju | worker/uniter/runner/jujuc/restricted.go | NetworkInfo | func (*RestrictedContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error) {
return map[string]params.NetworkInfoResult{}, ErrRestrictedContext
} | go | func (*RestrictedContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error) {
return map[string]params.NetworkInfoResult{}, ErrRestrictedContext
} | [
"func",
"(",
"*",
"RestrictedContext",
")",
"NetworkInfo",
"(",
"bindingNames",
"[",
"]",
"string",
",",
"relationId",
"int",
")",
"(",
"map",
"[",
"string",
"]",
"params",
".",
"NetworkInfoResult",
",",
"error",
")",
"{",
"return",
"map",
"[",
"string",
"]",
"params",
".",
"NetworkInfoResult",
"{",
"}",
",",
"ErrRestrictedContext",
"\n",
"}"
] | // NetworkInfo implements hooks.Context. | [
"NetworkInfo",
"implements",
"hooks",
".",
"Context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/jujuc/restricted.go#L89-L91 |
4,691 | juju/juju | worker/uniter/runner/jujuc/restricted.go | AddMetricLabels | func (*RestrictedContext) AddMetricLabels(string, string, time.Time, map[string]string) error {
return ErrRestrictedContext
} | go | func (*RestrictedContext) AddMetricLabels(string, string, time.Time, map[string]string) error {
return ErrRestrictedContext
} | [
"func",
"(",
"*",
"RestrictedContext",
")",
"AddMetricLabels",
"(",
"string",
",",
"string",
",",
"time",
".",
"Time",
",",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"return",
"ErrRestrictedContext",
"\n",
"}"
] | // AddMetricLabels implements hooks.Context. | [
"AddMetricLabels",
"implements",
"hooks",
".",
"Context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/jujuc/restricted.go#L108-L110 |
4,692 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | ControllerTag | func (m *MockState) ControllerTag() names_v2.ControllerTag {
ret := m.ctrl.Call(m, "ControllerTag")
ret0, _ := ret[0].(names_v2.ControllerTag)
return ret0
} | go | func (m *MockState) ControllerTag() names_v2.ControllerTag {
ret := m.ctrl.Call(m, "ControllerTag")
ret0, _ := ret[0].(names_v2.ControllerTag)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockState",
")",
"ControllerTag",
"(",
")",
"names_v2",
".",
"ControllerTag",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"names_v2",
".",
"ControllerTag",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ControllerTag mocks base method | [
"ControllerTag",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L53-L57 |
4,693 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | NewMockModel | func NewMockModel(ctrl *gomock.Controller) *MockModel {
mock := &MockModel{ctrl: ctrl}
mock.recorder = &MockModelMockRecorder{mock}
return mock
} | go | func NewMockModel(ctrl *gomock.Controller) *MockModel {
mock := &MockModel{ctrl: ctrl}
mock.recorder = &MockModelMockRecorder{mock}
return mock
} | [
"func",
"NewMockModel",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockModel",
"{",
"mock",
":=",
"&",
"MockModel",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockModelMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockModel creates a new mock instance | [
"NewMockModel",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L89-L93 |
4,694 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | Branch | func (m *MockModel) Branch(arg0 string) (modelgeneration.Generation, error) {
ret := m.ctrl.Call(m, "Branch", arg0)
ret0, _ := ret[0].(modelgeneration.Generation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockModel) Branch(arg0 string) (modelgeneration.Generation, error) {
ret := m.ctrl.Call(m, "Branch", arg0)
ret0, _ := ret[0].(modelgeneration.Generation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockModel",
")",
"Branch",
"(",
"arg0",
"string",
")",
"(",
"modelgeneration",
".",
"Generation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"modelgeneration",
".",
"Generation",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // Branch mocks base method | [
"Branch",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L113-L118 |
4,695 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | Branches | func (m *MockModel) Branches() ([]modelgeneration.Generation, error) {
ret := m.ctrl.Call(m, "Branches")
ret0, _ := ret[0].([]modelgeneration.Generation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockModel) Branches() ([]modelgeneration.Generation, error) {
ret := m.ctrl.Call(m, "Branches")
ret0, _ := ret[0].([]modelgeneration.Generation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockModel",
")",
"Branches",
"(",
")",
"(",
"[",
"]",
"modelgeneration",
".",
"Generation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"modelgeneration",
".",
"Generation",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // Branches mocks base method | [
"Branches",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L126-L131 |
4,696 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | ModelTag | func (mr *MockModelMockRecorder) ModelTag() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelTag", reflect.TypeOf((*MockModel)(nil).ModelTag))
} | go | func (mr *MockModelMockRecorder) ModelTag() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelTag", reflect.TypeOf((*MockModel)(nil).ModelTag))
} | [
"func",
"(",
"mr",
"*",
"MockModelMockRecorder",
")",
"ModelTag",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockModel",
")",
"(",
"nil",
")",
".",
"ModelTag",
")",
")",
"\n",
"}"
] | // ModelTag indicates an expected call of ModelTag | [
"ModelTag",
"indicates",
"an",
"expected",
"call",
"of",
"ModelTag"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L146-L148 |
4,697 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | NewMockGeneration | func NewMockGeneration(ctrl *gomock.Controller) *MockGeneration {
mock := &MockGeneration{ctrl: ctrl}
mock.recorder = &MockGenerationMockRecorder{mock}
return mock
} | go | func NewMockGeneration(ctrl *gomock.Controller) *MockGeneration {
mock := &MockGeneration{ctrl: ctrl}
mock.recorder = &MockGenerationMockRecorder{mock}
return mock
} | [
"func",
"NewMockGeneration",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockGeneration",
"{",
"mock",
":=",
"&",
"MockGeneration",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockGenerationMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockGeneration creates a new mock instance | [
"NewMockGeneration",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L162-L166 |
4,698 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | AssignAllUnits | func (m *MockGeneration) AssignAllUnits(arg0 string) error {
ret := m.ctrl.Call(m, "AssignAllUnits", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockGeneration) AssignAllUnits(arg0 string) error {
ret := m.ctrl.Call(m, "AssignAllUnits", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockGeneration",
")",
"AssignAllUnits",
"(",
"arg0",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // AssignAllUnits mocks base method | [
"AssignAllUnits",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L174-L178 |
4,699 | juju/juju | apiserver/facades/client/modelgeneration/mocks/package_mock.go | AssignUnit | func (mr *MockGenerationMockRecorder) AssignUnit(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignUnit", reflect.TypeOf((*MockGeneration)(nil).AssignUnit), arg0)
} | go | func (mr *MockGenerationMockRecorder) AssignUnit(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignUnit", reflect.TypeOf((*MockGeneration)(nil).AssignUnit), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockGenerationMockRecorder",
")",
"AssignUnit",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockGeneration",
")",
"(",
"nil",
")",
".",
"AssignUnit",
")",
",",
"arg0",
")",
"\n",
"}"
] | // AssignUnit indicates an expected call of AssignUnit | [
"AssignUnit",
"indicates",
"an",
"expected",
"call",
"of",
"AssignUnit"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelgeneration/mocks/package_mock.go#L193-L195 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.