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 listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
155,700 | juju/juju | provider/azure/internal/azurestorage/interface.go | Blobs | func (c container) Blobs() ([]Blob, error) {
//TODO(axw) handle pagination.
resp, err := c.Container.ListBlobs(storage.ListBlobsParameters{})
if err != nil {
return nil, errors.Trace(err)
}
blobs := make([]Blob, len(resp.Blobs))
for i := range blobs {
blobs[i] = blob{&resp.Blobs[i]}
}
return blobs, nil
} | go | func (c container) Blobs() ([]Blob, error) {
//TODO(axw) handle pagination.
resp, err := c.Container.ListBlobs(storage.ListBlobsParameters{})
if err != nil {
return nil, errors.Trace(err)
}
blobs := make([]Blob, len(resp.Blobs))
for i := range blobs {
blobs[i] = blob{&resp.Blobs[i]}
}
return blobs, nil
} | [
"func",
"(",
"c",
"container",
")",
"Blobs",
"(",
")",
"(",
"[",
"]",
"Blob",
",",
"error",
")",
"{",
"//TODO(axw) handle pagination.",
"resp",
",",
"err",
":=",
"c",
".",
"Container",
".",
"ListBlobs",
"(",
"storage",
".",
"ListBlobsParameters",
"{",
"}... | // Blobs is part of the Container interface. | [
"Blobs",
"is",
"part",
"of",
"the",
"Container",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurestorage/interface.go#L93-L104 |
155,701 | juju/juju | provider/azure/internal/azurestorage/interface.go | Blob | func (c container) Blob(name string) Blob {
return blob{c.Container.GetBlobReference(name)}
} | go | func (c container) Blob(name string) Blob {
return blob{c.Container.GetBlobReference(name)}
} | [
"func",
"(",
"c",
"container",
")",
"Blob",
"(",
"name",
"string",
")",
"Blob",
"{",
"return",
"blob",
"{",
"c",
".",
"Container",
".",
"GetBlobReference",
"(",
"name",
")",
"}",
"\n",
"}"
] | // Blob is part of the Container interface. | [
"Blob",
"is",
"part",
"of",
"the",
"Container",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurestorage/interface.go#L107-L109 |
155,702 | juju/juju | worker/terminationworker/manifold.go | Manifold | func Manifold() dependency.Manifold {
return dependency.Manifold{
Start: func(_ dependency.Context) (worker.Worker, error) {
return NewWorker(), nil
},
}
} | go | func Manifold() dependency.Manifold {
return dependency.Manifold{
Start: func(_ dependency.Context) (worker.Worker, error) {
return NewWorker(), nil
},
}
} | [
"func",
"Manifold",
"(",
")",
"dependency",
".",
"Manifold",
"{",
"return",
"dependency",
".",
"Manifold",
"{",
"Start",
":",
"func",
"(",
"_",
"dependency",
".",
"Context",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"return",
"NewWorker"... | // Manifold returns a manifold whose worker returns ErrTerminateAgent
// if a termination signal is received by the process it's running in. | [
"Manifold",
"returns",
"a",
"manifold",
"whose",
"worker",
"returns",
"ErrTerminateAgent",
"if",
"a",
"termination",
"signal",
"is",
"received",
"by",
"the",
"process",
"it",
"s",
"running",
"in",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/terminationworker/manifold.go#L13-L19 |
155,703 | juju/juju | state/ports.go | NewPortRange | func NewPortRange(unitName string, fromPort, toPort int, protocol string) (PortRange, error) {
p := PortRange{
UnitName: unitName,
FromPort: fromPort,
ToPort: toPort,
Protocol: strings.ToLower(protocol),
}
if err := p.Validate(); err != nil {
return PortRange{}, err
}
return p, nil
} | go | func NewPortRange(unitName string, fromPort, toPort int, protocol string) (PortRange, error) {
p := PortRange{
UnitName: unitName,
FromPort: fromPort,
ToPort: toPort,
Protocol: strings.ToLower(protocol),
}
if err := p.Validate(); err != nil {
return PortRange{}, err
}
return p, nil
} | [
"func",
"NewPortRange",
"(",
"unitName",
"string",
",",
"fromPort",
",",
"toPort",
"int",
",",
"protocol",
"string",
")",
"(",
"PortRange",
",",
"error",
")",
"{",
"p",
":=",
"PortRange",
"{",
"UnitName",
":",
"unitName",
",",
"FromPort",
":",
"fromPort",
... | // NewPortRange create a new port range and validate it. | [
"NewPortRange",
"create",
"a",
"new",
"port",
"range",
"and",
"validate",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L43-L54 |
155,704 | juju/juju | state/ports.go | Validate | func (p PortRange) Validate() error {
proto := strings.ToLower(p.Protocol)
if proto != "tcp" && proto != "udp" && proto != "icmp" {
return errors.Errorf("invalid protocol %q", proto)
}
if !names.IsValidUnit(p.UnitName) {
return errors.Errorf("invalid unit %q", p.UnitName)
}
if proto == "icmp" {
if p.FromPort == p.ToPort && p.FromPort == -1 {
return nil
}
return errors.Errorf(`protocol "icmp" doesn't support any ports; got "%v"`, p.FromPort)
}
if p.FromPort > p.ToPort {
return errors.Errorf("invalid port range %d-%d", p.FromPort, p.ToPort)
}
if p.FromPort <= 0 || p.FromPort > 65535 ||
p.ToPort <= 0 || p.ToPort > 65535 {
return errors.Errorf("port range bounds must be between 1 and 65535, got %d-%d", p.FromPort, p.ToPort)
}
return nil
} | go | func (p PortRange) Validate() error {
proto := strings.ToLower(p.Protocol)
if proto != "tcp" && proto != "udp" && proto != "icmp" {
return errors.Errorf("invalid protocol %q", proto)
}
if !names.IsValidUnit(p.UnitName) {
return errors.Errorf("invalid unit %q", p.UnitName)
}
if proto == "icmp" {
if p.FromPort == p.ToPort && p.FromPort == -1 {
return nil
}
return errors.Errorf(`protocol "icmp" doesn't support any ports; got "%v"`, p.FromPort)
}
if p.FromPort > p.ToPort {
return errors.Errorf("invalid port range %d-%d", p.FromPort, p.ToPort)
}
if p.FromPort <= 0 || p.FromPort > 65535 ||
p.ToPort <= 0 || p.ToPort > 65535 {
return errors.Errorf("port range bounds must be between 1 and 65535, got %d-%d", p.FromPort, p.ToPort)
}
return nil
} | [
"func",
"(",
"p",
"PortRange",
")",
"Validate",
"(",
")",
"error",
"{",
"proto",
":=",
"strings",
".",
"ToLower",
"(",
"p",
".",
"Protocol",
")",
"\n",
"if",
"proto",
"!=",
"\"",
"\"",
"&&",
"proto",
"!=",
"\"",
"\"",
"&&",
"proto",
"!=",
"\"",
"... | // Validate checks if the port range is valid. | [
"Validate",
"checks",
"if",
"the",
"port",
"range",
"is",
"valid",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L57-L79 |
155,705 | juju/juju | state/ports.go | Length | func (a PortRange) Length() int {
if err := a.Validate(); err != nil {
// Invalid range (from > to or something equally bad)
return 0
}
return (a.ToPort - a.FromPort) + 1
} | go | func (a PortRange) Length() int {
if err := a.Validate(); err != nil {
// Invalid range (from > to or something equally bad)
return 0
}
return (a.ToPort - a.FromPort) + 1
} | [
"func",
"(",
"a",
"PortRange",
")",
"Length",
"(",
")",
"int",
"{",
"if",
"err",
":=",
"a",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"// Invalid range (from > to or something equally bad)",
"return",
"0",
"\n",
"}",
"\n",
"return",
"(",
"... | // Length returns the number of ports in the range.
// If the range is not valid, it returns 0. | [
"Length",
"returns",
"the",
"number",
"of",
"ports",
"in",
"the",
"range",
".",
"If",
"the",
"range",
"is",
"not",
"valid",
"it",
"returns",
"0",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L83-L89 |
155,706 | juju/juju | state/ports.go | SanitizeBounds | func (a PortRange) SanitizeBounds() PortRange {
b := a
if a.Protocol == "icmp" {
return b
}
if b.FromPort > b.ToPort {
b.FromPort, b.ToPort = b.ToPort, b.FromPort
}
for _, bound := range []*int{&b.FromPort, &b.ToPort} {
switch {
case *bound <= 0:
*bound = 1
case *bound > 65535:
*bound = 65535
}
}
return b
} | go | func (a PortRange) SanitizeBounds() PortRange {
b := a
if a.Protocol == "icmp" {
return b
}
if b.FromPort > b.ToPort {
b.FromPort, b.ToPort = b.ToPort, b.FromPort
}
for _, bound := range []*int{&b.FromPort, &b.ToPort} {
switch {
case *bound <= 0:
*bound = 1
case *bound > 65535:
*bound = 65535
}
}
return b
} | [
"func",
"(",
"a",
"PortRange",
")",
"SanitizeBounds",
"(",
")",
"PortRange",
"{",
"b",
":=",
"a",
"\n",
"if",
"a",
".",
"Protocol",
"==",
"\"",
"\"",
"{",
"return",
"b",
"\n",
"}",
"\n",
"if",
"b",
".",
"FromPort",
">",
"b",
".",
"ToPort",
"{",
... | // Sanitize returns a copy of the port range, which is guaranteed to
// have FromPort >= ToPort and both FromPort and ToPort fit into the
// valid range from 1 to 65535, inclusive. | [
"Sanitize",
"returns",
"a",
"copy",
"of",
"the",
"port",
"range",
"which",
"is",
"guaranteed",
"to",
"have",
"FromPort",
">",
"=",
"ToPort",
"and",
"both",
"FromPort",
"and",
"ToPort",
"fit",
"into",
"the",
"valid",
"range",
"from",
"1",
"to",
"65535",
"... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L94-L111 |
155,707 | juju/juju | state/ports.go | CheckConflicts | func (prA PortRange) CheckConflicts(prB PortRange) error {
if err := prA.Validate(); err != nil {
return err
}
if err := prB.Validate(); err != nil {
return err
}
// An exact port range match (including the associated unit name) is not
// considered a conflict due to the fact that many charms issue commands
// to open the same port multiple times.
if prA == prB {
return nil
}
if prA.Protocol != prB.Protocol {
return nil
}
if prA.ToPort >= prB.FromPort && prB.ToPort >= prA.FromPort {
return errors.Errorf("port ranges %v and %v conflict", prA, prB)
}
return nil
} | go | func (prA PortRange) CheckConflicts(prB PortRange) error {
if err := prA.Validate(); err != nil {
return err
}
if err := prB.Validate(); err != nil {
return err
}
// An exact port range match (including the associated unit name) is not
// considered a conflict due to the fact that many charms issue commands
// to open the same port multiple times.
if prA == prB {
return nil
}
if prA.Protocol != prB.Protocol {
return nil
}
if prA.ToPort >= prB.FromPort && prB.ToPort >= prA.FromPort {
return errors.Errorf("port ranges %v and %v conflict", prA, prB)
}
return nil
} | [
"func",
"(",
"prA",
"PortRange",
")",
"CheckConflicts",
"(",
"prB",
"PortRange",
")",
"error",
"{",
"if",
"err",
":=",
"prA",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"prB",
".",
... | // CheckConflicts determines if the two port ranges conflict. | [
"CheckConflicts",
"determines",
"if",
"the",
"two",
"port",
"ranges",
"conflict",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L114-L135 |
155,708 | juju/juju | state/ports.go | String | func (p PortRange) String() string {
proto := strings.ToLower(p.Protocol)
if proto == "icmp" {
return fmt.Sprintf("%s (%q)", proto, p.UnitName)
}
return fmt.Sprintf("%d-%d/%s (%q)", p.FromPort, p.ToPort, proto, p.UnitName)
} | go | func (p PortRange) String() string {
proto := strings.ToLower(p.Protocol)
if proto == "icmp" {
return fmt.Sprintf("%s (%q)", proto, p.UnitName)
}
return fmt.Sprintf("%d-%d/%s (%q)", p.FromPort, p.ToPort, proto, p.UnitName)
} | [
"func",
"(",
"p",
"PortRange",
")",
"String",
"(",
")",
"string",
"{",
"proto",
":=",
"strings",
".",
"ToLower",
"(",
"p",
".",
"Protocol",
")",
"\n",
"if",
"proto",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p... | // Strings returns the port range as a string. | [
"Strings",
"returns",
"the",
"port",
"range",
"as",
"a",
"string",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L138-L144 |
155,709 | juju/juju | state/ports.go | String | func (p *Ports) String() string {
return fmt.Sprintf("ports for machine %q, subnet %q", p.doc.MachineID, p.doc.SubnetID)
} | go | func (p *Ports) String() string {
return fmt.Sprintf("ports for machine %q, subnet %q", p.doc.MachineID, p.doc.SubnetID)
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"doc",
".",
"MachineID",
",",
"p",
".",
"doc",
".",
"SubnetID",
")",
"\n",
"}"
] | // String returns p as a user-readable string. | [
"String",
"returns",
"p",
"as",
"a",
"user",
"-",
"readable",
"string",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L165-L167 |
155,710 | juju/juju | state/ports.go | extractPortsIDParts | func extractPortsIDParts(globalKey string) ([]string, error) {
if parts := portsIDRe.FindStringSubmatch(globalKey); len(parts) == 3 {
return parts, nil
}
return nil, errors.NotValidf("ports document key %q", globalKey)
} | go | func extractPortsIDParts(globalKey string) ([]string, error) {
if parts := portsIDRe.FindStringSubmatch(globalKey); len(parts) == 3 {
return parts, nil
}
return nil, errors.NotValidf("ports document key %q", globalKey)
} | [
"func",
"extractPortsIDParts",
"(",
"globalKey",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"parts",
":=",
"portsIDRe",
".",
"FindStringSubmatch",
"(",
"globalKey",
")",
";",
"len",
"(",
"parts",
")",
"==",
"3",
"{",
"return",
... | // extractPortsIDParts parses the given ports global key and extracts
// its parts. | [
"extractPortsIDParts",
"parses",
"the",
"given",
"ports",
"global",
"key",
"and",
"extracts",
"its",
"parts",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L177-L182 |
155,711 | juju/juju | state/ports.go | OpenPorts | func (p *Ports) OpenPorts(portRange PortRange) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot open ports %s", portRange)
if err = portRange.Validate(); err != nil {
return errors.Trace(err)
}
ports := Ports{st: p.st, doc: p.doc, areNew: p.areNew}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := checkModelActive(p.st); err != nil {
return nil, errors.Trace(err)
}
if err := p.verifySubnetAliveWhenSet(); err != nil {
return nil, errors.Trace(err)
}
if err = ports.Refresh(); errors.IsNotFound(err) {
// No longer exists, we'll create it.
if !ports.areNew {
ports.areNew = true
}
} else if err != nil {
return nil, errors.Trace(err)
} else if ports.areNew {
// Already created, we'll update it.
ports.areNew = false
}
}
// Check for conflicts with existing ports.
for _, existingPorts := range p.doc.Ports {
if err := existingPorts.CheckConflicts(portRange); err != nil {
return nil, errors.Trace(err)
} else if existingPorts == portRange {
// Trying to open the same range for the same unit is
// ignored, as we don't need to change the document
// and hence its txn-revno and trigger unnecessary
// watcher notifications.
return nil, statetxn.ErrNoOperations
}
}
ops := []txn.Op{
assertModelActiveOp(p.st.ModelUUID()),
}
if ports.areNew {
// Create a new document.
assert := txn.DocMissing
ops = append(ops, addPortsDocOps(p.st, &ports.doc, assert, portRange)...)
} else {
// Update an existing document.
assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
ops = append(ops, updatePortsDocOps(p.st, ports.doc, assert, portRange)...)
}
return ops, nil
}
// Run the transaction using the state transaction runner.
if err = p.st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
// Mark object as created.
p.areNew = false
p.doc.Ports = append(p.doc.Ports, portRange)
return nil
} | go | func (p *Ports) OpenPorts(portRange PortRange) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot open ports %s", portRange)
if err = portRange.Validate(); err != nil {
return errors.Trace(err)
}
ports := Ports{st: p.st, doc: p.doc, areNew: p.areNew}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := checkModelActive(p.st); err != nil {
return nil, errors.Trace(err)
}
if err := p.verifySubnetAliveWhenSet(); err != nil {
return nil, errors.Trace(err)
}
if err = ports.Refresh(); errors.IsNotFound(err) {
// No longer exists, we'll create it.
if !ports.areNew {
ports.areNew = true
}
} else if err != nil {
return nil, errors.Trace(err)
} else if ports.areNew {
// Already created, we'll update it.
ports.areNew = false
}
}
// Check for conflicts with existing ports.
for _, existingPorts := range p.doc.Ports {
if err := existingPorts.CheckConflicts(portRange); err != nil {
return nil, errors.Trace(err)
} else if existingPorts == portRange {
// Trying to open the same range for the same unit is
// ignored, as we don't need to change the document
// and hence its txn-revno and trigger unnecessary
// watcher notifications.
return nil, statetxn.ErrNoOperations
}
}
ops := []txn.Op{
assertModelActiveOp(p.st.ModelUUID()),
}
if ports.areNew {
// Create a new document.
assert := txn.DocMissing
ops = append(ops, addPortsDocOps(p.st, &ports.doc, assert, portRange)...)
} else {
// Update an existing document.
assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
ops = append(ops, updatePortsDocOps(p.st, ports.doc, assert, portRange)...)
}
return ops, nil
}
// Run the transaction using the state transaction runner.
if err = p.st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
// Mark object as created.
p.areNew = false
p.doc.Ports = append(p.doc.Ports, portRange)
return nil
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"OpenPorts",
"(",
"portRange",
"PortRange",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"portRange",
")",
"\n\n",
"if",
"err",
"=",
"port... | // OpenPorts adds the specified port range to the list of ports
// maintained by this document. | [
"OpenPorts",
"adds",
"the",
"specified",
"port",
"range",
"to",
"the",
"list",
"of",
"ports",
"maintained",
"by",
"this",
"document",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L191-L255 |
155,712 | juju/juju | state/ports.go | ClosePorts | func (p *Ports) ClosePorts(portRange PortRange) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot close ports %s", portRange)
if err = portRange.Validate(); err != nil {
return errors.Trace(err)
}
var newPorts []PortRange
ports := Ports{st: p.st, doc: p.doc, areNew: p.areNew}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := p.verifySubnetAliveWhenSet(); err != nil {
return nil, errors.Trace(err)
}
if err = ports.Refresh(); errors.IsNotFound(err) {
// No longer exists, nothing to do.
return nil, statetxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
}
newPorts = newPorts[0:0]
found := false
for _, existingPortsDef := range ports.doc.Ports {
if existingPortsDef == portRange {
found = true
continue
}
err = existingPortsDef.CheckConflicts(portRange)
if existingPortsDef.UnitName == portRange.UnitName && err != nil {
return nil, errors.Trace(err)
}
newPorts = append(newPorts, existingPortsDef)
}
if !found {
return nil, statetxn.ErrNoOperations
}
if len(newPorts) == 0 {
// All ports closed, so remove the ports doc instead.
return p.removeOps(), nil
} else {
assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
return setPortsDocOps(p.st, ports.doc, assert, newPorts...), nil
}
}
if err = p.st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
p.doc.Ports = newPorts
return nil
} | go | func (p *Ports) ClosePorts(portRange PortRange) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot close ports %s", portRange)
if err = portRange.Validate(); err != nil {
return errors.Trace(err)
}
var newPorts []PortRange
ports := Ports{st: p.st, doc: p.doc, areNew: p.areNew}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := p.verifySubnetAliveWhenSet(); err != nil {
return nil, errors.Trace(err)
}
if err = ports.Refresh(); errors.IsNotFound(err) {
// No longer exists, nothing to do.
return nil, statetxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
}
newPorts = newPorts[0:0]
found := false
for _, existingPortsDef := range ports.doc.Ports {
if existingPortsDef == portRange {
found = true
continue
}
err = existingPortsDef.CheckConflicts(portRange)
if existingPortsDef.UnitName == portRange.UnitName && err != nil {
return nil, errors.Trace(err)
}
newPorts = append(newPorts, existingPortsDef)
}
if !found {
return nil, statetxn.ErrNoOperations
}
if len(newPorts) == 0 {
// All ports closed, so remove the ports doc instead.
return p.removeOps(), nil
} else {
assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
return setPortsDocOps(p.st, ports.doc, assert, newPorts...), nil
}
}
if err = p.st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
p.doc.Ports = newPorts
return nil
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"ClosePorts",
"(",
"portRange",
"PortRange",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"portRange",
")",
"\n\n",
"if",
"err",
"=",
"por... | // ClosePorts removes the specified port range from the list of ports
// maintained by this document. | [
"ClosePorts",
"removes",
"the",
"specified",
"port",
"range",
"from",
"the",
"list",
"of",
"ports",
"maintained",
"by",
"this",
"document",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L273-L324 |
155,713 | juju/juju | state/ports.go | Refresh | func (p *Ports) Refresh() error {
openedPorts, closer := p.st.db().GetCollection(openedPortsC)
defer closer()
err := openedPorts.FindId(p.doc.DocID).One(&p.doc)
if err == mgo.ErrNotFound {
return errors.NotFoundf(p.String())
} else if err != nil {
return errors.Annotatef(err, "cannot refresh %s", p)
}
return nil
} | go | func (p *Ports) Refresh() error {
openedPorts, closer := p.st.db().GetCollection(openedPortsC)
defer closer()
err := openedPorts.FindId(p.doc.DocID).One(&p.doc)
if err == mgo.ErrNotFound {
return errors.NotFoundf(p.String())
} else if err != nil {
return errors.Annotatef(err, "cannot refresh %s", p)
}
return nil
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"Refresh",
"(",
")",
"error",
"{",
"openedPorts",
",",
"closer",
":=",
"p",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"openedPortsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"err",
":=",... | // Refresh refreshes the port document from state. | [
"Refresh",
"refreshes",
"the",
"port",
"document",
"from",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L339-L350 |
155,714 | juju/juju | state/ports.go | AllPortRanges | func (p *Ports) AllPortRanges() map[network.PortRange]string {
result := make(map[network.PortRange]string)
for _, portRange := range p.doc.Ports {
rawRange := network.PortRange{
FromPort: portRange.FromPort,
ToPort: portRange.ToPort,
Protocol: portRange.Protocol,
}
result[rawRange] = portRange.UnitName
}
return result
} | go | func (p *Ports) AllPortRanges() map[network.PortRange]string {
result := make(map[network.PortRange]string)
for _, portRange := range p.doc.Ports {
rawRange := network.PortRange{
FromPort: portRange.FromPort,
ToPort: portRange.ToPort,
Protocol: portRange.Protocol,
}
result[rawRange] = portRange.UnitName
}
return result
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"AllPortRanges",
"(",
")",
"map",
"[",
"network",
".",
"PortRange",
"]",
"string",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"network",
".",
"PortRange",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"portRange",... | // AllPortRanges returns a map with network.PortRange as keys and unit
// names as values. | [
"AllPortRanges",
"returns",
"a",
"map",
"with",
"network",
".",
"PortRange",
"as",
"keys",
"and",
"unit",
"names",
"as",
"values",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L354-L365 |
155,715 | juju/juju | state/ports.go | Remove | func (p *Ports) Remove() error {
ports := &Ports{st: p.st, doc: p.doc}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
err := ports.Refresh()
if errors.IsNotFound(err) {
return nil, statetxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
}
return ports.removeOps(), nil
}
return p.st.db().Run(buildTxn)
} | go | func (p *Ports) Remove() error {
ports := &Ports{st: p.st, doc: p.doc}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
err := ports.Refresh()
if errors.IsNotFound(err) {
return nil, statetxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
}
return ports.removeOps(), nil
}
return p.st.db().Run(buildTxn)
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"Remove",
"(",
")",
"error",
"{",
"ports",
":=",
"&",
"Ports",
"{",
"st",
":",
"p",
".",
"st",
",",
"doc",
":",
"p",
".",
"doc",
"}",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
... | // Remove removes the ports document from state. | [
"Remove",
"removes",
"the",
"ports",
"document",
"from",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L368-L382 |
155,716 | juju/juju | state/ports.go | OpenedPorts | func (m *Machine) OpenedPorts(subnetID string) (*Ports, error) {
ports, err := getPorts(m.st, m.Id(), subnetID)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
return ports, nil
} | go | func (m *Machine) OpenedPorts(subnetID string) (*Ports, error) {
ports, err := getPorts(m.st, m.Id(), subnetID)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
return ports, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"OpenedPorts",
"(",
"subnetID",
"string",
")",
"(",
"*",
"Ports",
",",
"error",
")",
"{",
"ports",
",",
"err",
":=",
"getPorts",
"(",
"m",
".",
"st",
",",
"m",
".",
"Id",
"(",
")",
",",
"subnetID",
")",
"\... | // OpenedPorts returns this machine ports document for the given subnetID. | [
"OpenedPorts",
"returns",
"this",
"machine",
"ports",
"document",
"for",
"the",
"given",
"subnetID",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L385-L391 |
155,717 | juju/juju | state/ports.go | removeOps | func (p *Ports) removeOps() []txn.Op {
return []txn.Op{{
C: openedPortsC,
Id: p.doc.DocID,
Assert: txn.DocExists,
Remove: true,
}}
} | go | func (p *Ports) removeOps() []txn.Op {
return []txn.Op{{
C: openedPortsC,
Id: p.doc.DocID,
Assert: txn.DocExists,
Remove: true,
}}
} | [
"func",
"(",
"p",
"*",
"Ports",
")",
"removeOps",
"(",
")",
"[",
"]",
"txn",
".",
"Op",
"{",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"openedPortsC",
",",
"Id",
":",
"p",
".",
"doc",
".",
"DocID",
",",
"Assert",
":",
"txn",
... | // removeOps returns the ops for removing the ports document from
// state. | [
"removeOps",
"returns",
"the",
"ops",
"for",
"removing",
"the",
"ports",
"document",
"from",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L481-L488 |
155,718 | juju/juju | state/ports.go | removePortsForUnitOps | func removePortsForUnitOps(st *State, unit *Unit) ([]txn.Op, error) {
machineId, err := unit.AssignedMachineId()
if err != nil {
// No assigned machine, so there won't be any ports.
return nil, nil
}
machine, err := st.Machine(machineId)
if errors.IsNotFound(err) {
// Machine is removed, so there won't be a ports doc for it.
return nil, nil
} else if err != nil {
return nil, errors.Trace(err)
}
allPorts, err := machine.AllPorts()
if err != nil {
return nil, errors.Trace(err)
}
var ops []txn.Op
for _, ports := range allPorts {
allRanges := ports.AllPortRanges()
var keepPorts []PortRange
for portRange, unitName := range allRanges {
if unitName != unit.Name() {
unitRange := PortRange{
UnitName: unitName,
FromPort: portRange.FromPort,
ToPort: portRange.ToPort,
Protocol: portRange.Protocol,
}
keepPorts = append(keepPorts, unitRange)
}
}
if len(keepPorts) > 0 {
assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
ops = append(ops, setPortsDocOps(st, ports.doc, assert, keepPorts...)...)
} else {
// No other ports left, remove the doc.
ops = append(ops, ports.removeOps()...)
}
}
return ops, nil
} | go | func removePortsForUnitOps(st *State, unit *Unit) ([]txn.Op, error) {
machineId, err := unit.AssignedMachineId()
if err != nil {
// No assigned machine, so there won't be any ports.
return nil, nil
}
machine, err := st.Machine(machineId)
if errors.IsNotFound(err) {
// Machine is removed, so there won't be a ports doc for it.
return nil, nil
} else if err != nil {
return nil, errors.Trace(err)
}
allPorts, err := machine.AllPorts()
if err != nil {
return nil, errors.Trace(err)
}
var ops []txn.Op
for _, ports := range allPorts {
allRanges := ports.AllPortRanges()
var keepPorts []PortRange
for portRange, unitName := range allRanges {
if unitName != unit.Name() {
unitRange := PortRange{
UnitName: unitName,
FromPort: portRange.FromPort,
ToPort: portRange.ToPort,
Protocol: portRange.Protocol,
}
keepPorts = append(keepPorts, unitRange)
}
}
if len(keepPorts) > 0 {
assert := bson.D{{"txn-revno", ports.doc.TxnRevno}}
ops = append(ops, setPortsDocOps(st, ports.doc, assert, keepPorts...)...)
} else {
// No other ports left, remove the doc.
ops = append(ops, ports.removeOps()...)
}
}
return ops, nil
} | [
"func",
"removePortsForUnitOps",
"(",
"st",
"*",
"State",
",",
"unit",
"*",
"Unit",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"machineId",
",",
"err",
":=",
"unit",
".",
"AssignedMachineId",
"(",
")",
"\n",
"if",
"err",
"!=",
"n... | // removePortsForUnitOps returns the ops needed to remove all opened
// ports for the given unit on its assigned machine. | [
"removePortsForUnitOps",
"returns",
"the",
"ops",
"needed",
"to",
"remove",
"all",
"opened",
"ports",
"for",
"the",
"given",
"unit",
"on",
"its",
"assigned",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L492-L533 |
155,719 | juju/juju | state/ports.go | getPorts | func getPorts(st *State, machineID, subnetID string) (*Ports, error) {
openedPorts, closer := st.db().GetCollection(openedPortsC)
defer closer()
var doc portsDoc
key := portsGlobalKey(machineID, subnetID)
err := openedPorts.FindId(key).One(&doc)
if err != nil {
doc.MachineID = machineID
doc.SubnetID = subnetID
p := Ports{st, doc, false}
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf(p.String())
}
return nil, errors.Annotatef(err, "cannot get %s", p.String())
}
return &Ports{st, doc, false}, nil
} | go | func getPorts(st *State, machineID, subnetID string) (*Ports, error) {
openedPorts, closer := st.db().GetCollection(openedPortsC)
defer closer()
var doc portsDoc
key := portsGlobalKey(machineID, subnetID)
err := openedPorts.FindId(key).One(&doc)
if err != nil {
doc.MachineID = machineID
doc.SubnetID = subnetID
p := Ports{st, doc, false}
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf(p.String())
}
return nil, errors.Annotatef(err, "cannot get %s", p.String())
}
return &Ports{st, doc, false}, nil
} | [
"func",
"getPorts",
"(",
"st",
"*",
"State",
",",
"machineID",
",",
"subnetID",
"string",
")",
"(",
"*",
"Ports",
",",
"error",
")",
"{",
"openedPorts",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"openedPortsC",
")",
"... | // getPorts returns the ports document for the specified machine and subnet. | [
"getPorts",
"returns",
"the",
"ports",
"document",
"for",
"the",
"specified",
"machine",
"and",
"subnet",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L536-L554 |
155,720 | juju/juju | state/ports.go | getOrCreatePorts | func getOrCreatePorts(st *State, machineID, subnetID string) (*Ports, error) {
ports, err := getPorts(st, machineID, subnetID)
if errors.IsNotFound(err) {
key := portsGlobalKey(machineID, subnetID)
doc := portsDoc{
DocID: st.docID(key),
MachineID: machineID,
SubnetID: subnetID,
ModelUUID: st.ModelUUID(),
}
ports = &Ports{st, doc, true}
} else if err != nil {
return nil, errors.Trace(err)
}
return ports, nil
} | go | func getOrCreatePorts(st *State, machineID, subnetID string) (*Ports, error) {
ports, err := getPorts(st, machineID, subnetID)
if errors.IsNotFound(err) {
key := portsGlobalKey(machineID, subnetID)
doc := portsDoc{
DocID: st.docID(key),
MachineID: machineID,
SubnetID: subnetID,
ModelUUID: st.ModelUUID(),
}
ports = &Ports{st, doc, true}
} else if err != nil {
return nil, errors.Trace(err)
}
return ports, nil
} | [
"func",
"getOrCreatePorts",
"(",
"st",
"*",
"State",
",",
"machineID",
",",
"subnetID",
"string",
")",
"(",
"*",
"Ports",
",",
"error",
")",
"{",
"ports",
",",
"err",
":=",
"getPorts",
"(",
"st",
",",
"machineID",
",",
"subnetID",
")",
"\n",
"if",
"e... | // getOrCreatePorts attempts to retrieve a ports document and returns a newly
// created one if it does not exist. | [
"getOrCreatePorts",
"attempts",
"to",
"retrieve",
"a",
"ports",
"document",
"and",
"returns",
"a",
"newly",
"created",
"one",
"if",
"it",
"does",
"not",
"exist",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/ports.go#L558-L573 |
155,721 | juju/juju | cmd/juju/space/list.go | printTabular | func (c *ListCommand) printTabular(writer io.Writer, value interface{}) error {
tw := output.TabWriter(writer)
if c.Short {
list, ok := value.(formattedShortList)
if !ok {
return errors.New("unexpected value")
}
fmt.Fprintln(tw, "Space")
spaces := list.Spaces
sort.Strings(spaces)
for _, space := range spaces {
fmt.Fprintf(tw, "%v\n", space)
}
} else {
list, ok := value.(formattedList)
if !ok {
return errors.New("unexpected value")
}
fmt.Fprintf(tw, "%s\t%s\n", "Space", "Subnets")
spaces := []string{}
for name := range list.Spaces {
spaces = append(spaces, name)
}
sort.Strings(spaces)
for _, name := range spaces {
subnets := list.Spaces[name]
fmt.Fprintf(tw, "%s", name)
if len(subnets) == 0 {
fmt.Fprintf(tw, "\n")
continue
}
cidrs := []string{}
for subnet := range subnets {
cidrs = append(cidrs, subnet)
}
sort.Strings(cidrs)
for _, cidr := range cidrs {
fmt.Fprintf(tw, "\t%v\n", cidr)
}
}
}
tw.Flush()
return nil
} | go | func (c *ListCommand) printTabular(writer io.Writer, value interface{}) error {
tw := output.TabWriter(writer)
if c.Short {
list, ok := value.(formattedShortList)
if !ok {
return errors.New("unexpected value")
}
fmt.Fprintln(tw, "Space")
spaces := list.Spaces
sort.Strings(spaces)
for _, space := range spaces {
fmt.Fprintf(tw, "%v\n", space)
}
} else {
list, ok := value.(formattedList)
if !ok {
return errors.New("unexpected value")
}
fmt.Fprintf(tw, "%s\t%s\n", "Space", "Subnets")
spaces := []string{}
for name := range list.Spaces {
spaces = append(spaces, name)
}
sort.Strings(spaces)
for _, name := range spaces {
subnets := list.Spaces[name]
fmt.Fprintf(tw, "%s", name)
if len(subnets) == 0 {
fmt.Fprintf(tw, "\n")
continue
}
cidrs := []string{}
for subnet := range subnets {
cidrs = append(cidrs, subnet)
}
sort.Strings(cidrs)
for _, cidr := range cidrs {
fmt.Fprintf(tw, "\t%v\n", cidr)
}
}
}
tw.Flush()
return nil
} | [
"func",
"(",
"c",
"*",
"ListCommand",
")",
"printTabular",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"tw",
":=",
"output",
".",
"TabWriter",
"(",
"writer",
")",
"\n",
"if",
"c",
".",
"Short",
"{",
"... | // printTabular prints the list of spaces in tabular format | [
"printTabular",
"prints",
"the",
"list",
"of",
"spaces",
"in",
"tabular",
"format"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/space/list.go#L145-L189 |
155,722 | juju/juju | worker/raft/rafttransport/handler.go | NewHandler | func NewHandler(
connections chan<- net.Conn,
abort <-chan struct{},
) *Handler {
return &Handler{
connections: connections,
abort: abort,
}
} | go | func NewHandler(
connections chan<- net.Conn,
abort <-chan struct{},
) *Handler {
return &Handler{
connections: connections,
abort: abort,
}
} | [
"func",
"NewHandler",
"(",
"connections",
"chan",
"<-",
"net",
".",
"Conn",
",",
"abort",
"<-",
"chan",
"struct",
"{",
"}",
",",
")",
"*",
"Handler",
"{",
"return",
"&",
"Handler",
"{",
"connections",
":",
"connections",
",",
"abort",
":",
"abort",
","... | // NewHandler returns a new Handler that sends connections to the
// given connections channel, and stops accepting connections after
// the abort channel is closed. | [
"NewHandler",
"returns",
"a",
"new",
"Handler",
"that",
"sends",
"connections",
"to",
"the",
"given",
"connections",
"channel",
"and",
"stops",
"accepting",
"connections",
"after",
"the",
"abort",
"channel",
"is",
"closed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/rafttransport/handler.go#L22-L30 |
155,723 | juju/juju | juju/osenv/vars.go | FeatureFlags | func FeatureFlags() map[string]string {
result := make(map[string]string)
if envVar := featureflag.AsEnvironmentValue(); envVar != "" {
result[JujuFeatureFlagEnvKey] = envVar
}
return result
} | go | func FeatureFlags() map[string]string {
result := make(map[string]string)
if envVar := featureflag.AsEnvironmentValue(); envVar != "" {
result[JujuFeatureFlagEnvKey] = envVar
}
return result
} | [
"func",
"FeatureFlags",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"if",
"envVar",
":=",
"featureflag",
".",
"AsEnvironmentValue",
"(",
")",
";",
"envVar",
"!=",
"\""... | // FeatureFlags returns a map that can be merged with os.Environ. | [
"FeatureFlags",
"returns",
"a",
"map",
"that",
"can",
"be",
"merged",
"with",
"os",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/juju/osenv/vars.go#L53-L59 |
155,724 | juju/juju | juju/osenv/vars.go | MergeEnvironment | func MergeEnvironment(current, newValues map[string]string) map[string]string {
if current == nil {
current = make(map[string]string)
}
if runtime.GOOS == "windows" {
return mergeEnvWin(current, newValues)
}
return mergeEnvUnix(current, newValues)
} | go | func MergeEnvironment(current, newValues map[string]string) map[string]string {
if current == nil {
current = make(map[string]string)
}
if runtime.GOOS == "windows" {
return mergeEnvWin(current, newValues)
}
return mergeEnvUnix(current, newValues)
} | [
"func",
"MergeEnvironment",
"(",
"current",
",",
"newValues",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"current",
"==",
"nil",
"{",
"current",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
... | // MergeEnvironment will return the current environment updated with
// all the values from newValues. If current is nil, a new map is
// created. If current is not nil, it is mutated. | [
"MergeEnvironment",
"will",
"return",
"the",
"current",
"environment",
"updated",
"with",
"all",
"the",
"values",
"from",
"newValues",
".",
"If",
"current",
"is",
"nil",
"a",
"new",
"map",
"is",
"created",
".",
"If",
"current",
"is",
"not",
"nil",
"it",
"i... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/juju/osenv/vars.go#L64-L72 |
155,725 | juju/juju | juju/osenv/vars.go | mergeEnvUnix | func mergeEnvUnix(current, newValues map[string]string) map[string]string {
for key, value := range newValues {
current[key] = value
}
return current
} | go | func mergeEnvUnix(current, newValues map[string]string) map[string]string {
for key, value := range newValues {
current[key] = value
}
return current
} | [
"func",
"mergeEnvUnix",
"(",
"current",
",",
"newValues",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"newValues",
"{",
"current",
"[",
"key",
"]",
"=",
"value",
"\n",
... | // mergeEnvUnix merges the two evironment variable lists in a case sensitive way. | [
"mergeEnvUnix",
"merges",
"the",
"two",
"evironment",
"variable",
"lists",
"in",
"a",
"case",
"sensitive",
"way",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/juju/osenv/vars.go#L75-L80 |
155,726 | juju/juju | juju/osenv/vars.go | mergeEnvWin | func mergeEnvWin(current, newValues map[string]string) map[string]string {
uppers := make(map[string]string, len(current))
news := map[string]string{}
for k, v := range current {
uppers[strings.ToUpper(k)] = v
}
for k, v := range newValues {
up := strings.ToUpper(k)
if _, ok := uppers[up]; ok {
uppers[up] = v
} else {
news[k] = v
}
}
for k := range current {
current[k] = uppers[strings.ToUpper(k)]
}
for k, v := range news {
current[k] = v
}
return current
} | go | func mergeEnvWin(current, newValues map[string]string) map[string]string {
uppers := make(map[string]string, len(current))
news := map[string]string{}
for k, v := range current {
uppers[strings.ToUpper(k)] = v
}
for k, v := range newValues {
up := strings.ToUpper(k)
if _, ok := uppers[up]; ok {
uppers[up] = v
} else {
news[k] = v
}
}
for k := range current {
current[k] = uppers[strings.ToUpper(k)]
}
for k, v := range news {
current[k] = v
}
return current
} | [
"func",
"mergeEnvWin",
"(",
"current",
",",
"newValues",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"uppers",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"current",
")",
")",
"\n",... | // mergeEnvWin merges the two environment variable lists in a case insensitive,
// but case preserving way. Thus, if FOO=bar is set, and newValues has foo=baz,
// then the resultant map will contain FOO=baz. | [
"mergeEnvWin",
"merges",
"the",
"two",
"environment",
"variable",
"lists",
"in",
"a",
"case",
"insensitive",
"but",
"case",
"preserving",
"way",
".",
"Thus",
"if",
"FOO",
"=",
"bar",
"is",
"set",
"and",
"newValues",
"has",
"foo",
"=",
"baz",
"then",
"the",... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/juju/osenv/vars.go#L85-L108 |
155,727 | juju/juju | apiserver/common/storagecommon/blockdevices.go | BlockDeviceFromState | func BlockDeviceFromState(in state.BlockDeviceInfo) storage.BlockDevice {
return storage.BlockDevice{
in.DeviceName,
in.DeviceLinks,
in.Label,
in.UUID,
in.HardwareId,
in.WWN,
in.BusAddress,
in.Size,
in.FilesystemType,
in.InUse,
in.MountPoint,
}
} | go | func BlockDeviceFromState(in state.BlockDeviceInfo) storage.BlockDevice {
return storage.BlockDevice{
in.DeviceName,
in.DeviceLinks,
in.Label,
in.UUID,
in.HardwareId,
in.WWN,
in.BusAddress,
in.Size,
in.FilesystemType,
in.InUse,
in.MountPoint,
}
} | [
"func",
"BlockDeviceFromState",
"(",
"in",
"state",
".",
"BlockDeviceInfo",
")",
"storage",
".",
"BlockDevice",
"{",
"return",
"storage",
".",
"BlockDevice",
"{",
"in",
".",
"DeviceName",
",",
"in",
".",
"DeviceLinks",
",",
"in",
".",
"Label",
",",
"in",
"... | // BlockDeviceFromState translates a state.BlockDeviceInfo to a
// storage.BlockDevice. | [
"BlockDeviceFromState",
"translates",
"a",
"state",
".",
"BlockDeviceInfo",
"to",
"a",
"storage",
".",
"BlockDevice",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/blockdevices.go#L17-L31 |
155,728 | juju/juju | apiserver/common/storagecommon/blockdevices.go | MatchingBlockDevice | func MatchingBlockDevice(
blockDevices []state.BlockDeviceInfo,
volumeInfo state.VolumeInfo,
attachmentInfo state.VolumeAttachmentInfo,
planBlockInfo state.BlockDeviceInfo,
) (*state.BlockDeviceInfo, bool) {
logger.Tracef("looking for block device for volume %#v", volumeInfo)
for _, dev := range blockDevices {
if planBlockInfo.HardwareId != "" {
if planBlockInfo.HardwareId == dev.HardwareId {
logger.Tracef("plan hwid match on %v", volumeInfo.HardwareId)
return &dev, true
}
}
if planBlockInfo.WWN != "" {
if planBlockInfo.WWN == dev.WWN {
logger.Tracef("plan wwn match on %v", volumeInfo.WWN)
return &dev, true
}
continue
}
if planBlockInfo.DeviceName != "" {
if planBlockInfo.DeviceName == dev.DeviceName {
logger.Tracef("plan device name match on %v", attachmentInfo.DeviceName)
return &dev, true
}
continue
}
if volumeInfo.WWN != "" {
if volumeInfo.WWN == dev.WWN {
logger.Tracef("wwn match on %v", volumeInfo.WWN)
return &dev, true
}
logger.Tracef("no match for block device WWN: %v", dev.WWN)
continue
}
if volumeInfo.HardwareId != "" {
if volumeInfo.HardwareId == dev.HardwareId {
logger.Tracef("hwid match on %v", volumeInfo.HardwareId)
return &dev, true
}
logger.Tracef("no match for block device hardware id: %v", dev.HardwareId)
continue
}
if attachmentInfo.BusAddress != "" {
if attachmentInfo.BusAddress == dev.BusAddress {
logger.Tracef("bus address match on %v", attachmentInfo.BusAddress)
return &dev, true
}
logger.Tracef("no match for block device bus address: %v", dev.BusAddress)
continue
}
// Only match on block device link if the block device is published
// with device link information.
if attachmentInfo.DeviceLink != "" && len(dev.DeviceLinks) > 0 {
for _, link := range dev.DeviceLinks {
if attachmentInfo.DeviceLink == link {
logger.Tracef("device link match on %v", attachmentInfo.DeviceLink)
return &dev, true
}
}
logger.Tracef("no match for block device dev links: %v", dev.DeviceLinks)
continue
}
if attachmentInfo.DeviceName == dev.DeviceName {
logger.Tracef("device name match on %v", attachmentInfo.DeviceName)
return &dev, true
}
logger.Tracef("no match for block device name: %v", dev.DeviceName)
}
return nil, false
} | go | func MatchingBlockDevice(
blockDevices []state.BlockDeviceInfo,
volumeInfo state.VolumeInfo,
attachmentInfo state.VolumeAttachmentInfo,
planBlockInfo state.BlockDeviceInfo,
) (*state.BlockDeviceInfo, bool) {
logger.Tracef("looking for block device for volume %#v", volumeInfo)
for _, dev := range blockDevices {
if planBlockInfo.HardwareId != "" {
if planBlockInfo.HardwareId == dev.HardwareId {
logger.Tracef("plan hwid match on %v", volumeInfo.HardwareId)
return &dev, true
}
}
if planBlockInfo.WWN != "" {
if planBlockInfo.WWN == dev.WWN {
logger.Tracef("plan wwn match on %v", volumeInfo.WWN)
return &dev, true
}
continue
}
if planBlockInfo.DeviceName != "" {
if planBlockInfo.DeviceName == dev.DeviceName {
logger.Tracef("plan device name match on %v", attachmentInfo.DeviceName)
return &dev, true
}
continue
}
if volumeInfo.WWN != "" {
if volumeInfo.WWN == dev.WWN {
logger.Tracef("wwn match on %v", volumeInfo.WWN)
return &dev, true
}
logger.Tracef("no match for block device WWN: %v", dev.WWN)
continue
}
if volumeInfo.HardwareId != "" {
if volumeInfo.HardwareId == dev.HardwareId {
logger.Tracef("hwid match on %v", volumeInfo.HardwareId)
return &dev, true
}
logger.Tracef("no match for block device hardware id: %v", dev.HardwareId)
continue
}
if attachmentInfo.BusAddress != "" {
if attachmentInfo.BusAddress == dev.BusAddress {
logger.Tracef("bus address match on %v", attachmentInfo.BusAddress)
return &dev, true
}
logger.Tracef("no match for block device bus address: %v", dev.BusAddress)
continue
}
// Only match on block device link if the block device is published
// with device link information.
if attachmentInfo.DeviceLink != "" && len(dev.DeviceLinks) > 0 {
for _, link := range dev.DeviceLinks {
if attachmentInfo.DeviceLink == link {
logger.Tracef("device link match on %v", attachmentInfo.DeviceLink)
return &dev, true
}
}
logger.Tracef("no match for block device dev links: %v", dev.DeviceLinks)
continue
}
if attachmentInfo.DeviceName == dev.DeviceName {
logger.Tracef("device name match on %v", attachmentInfo.DeviceName)
return &dev, true
}
logger.Tracef("no match for block device name: %v", dev.DeviceName)
}
return nil, false
} | [
"func",
"MatchingBlockDevice",
"(",
"blockDevices",
"[",
"]",
"state",
".",
"BlockDeviceInfo",
",",
"volumeInfo",
"state",
".",
"VolumeInfo",
",",
"attachmentInfo",
"state",
".",
"VolumeAttachmentInfo",
",",
"planBlockInfo",
"state",
".",
"BlockDeviceInfo",
",",
")"... | // MatchingBlockDevice finds the block device that matches the
// provided volume info and volume attachment info. | [
"MatchingBlockDevice",
"finds",
"the",
"block",
"device",
"that",
"matches",
"the",
"provided",
"volume",
"info",
"and",
"volume",
"attachment",
"info",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/blockdevices.go#L35-L106 |
155,729 | juju/juju | worker/featureflag/flag.go | NewWorker | func NewWorker(config Config) (worker.Worker, error) {
value, err := config.Value()
if err != nil {
return nil, errors.Trace(err)
}
flag := &Worker{
config: config,
value: value,
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &flag.catacomb,
Work: flag.loop,
}); err != nil {
return nil, errors.Trace(err)
}
return flag, nil
} | go | func NewWorker(config Config) (worker.Worker, error) {
value, err := config.Value()
if err != nil {
return nil, errors.Trace(err)
}
flag := &Worker{
config: config,
value: value,
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &flag.catacomb,
Work: flag.loop,
}); err != nil {
return nil, errors.Trace(err)
}
return flag, nil
} | [
"func",
"NewWorker",
"(",
"config",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"value",
",",
"err",
":=",
"config",
".",
"Value",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",... | // NewWorker creates a feature flag worker with the specified config. | [
"NewWorker",
"creates",
"a",
"feature",
"flag",
"worker",
"with",
"the",
"specified",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/featureflag/flag.go#L63-L79 |
155,730 | juju/juju | jujuclient/file.go | generateStoreLockName | func generateStoreLockName() string {
h := sha256.New()
h.Write([]byte(JujuControllersPath()))
fullHash := fmt.Sprintf("%x", h.Sum(nil))
return fmt.Sprintf("store-lock-%x", fullHash[:8])
} | go | func generateStoreLockName() string {
h := sha256.New()
h.Write([]byte(JujuControllersPath()))
fullHash := fmt.Sprintf("%x", h.Sum(nil))
return fmt.Sprintf("store-lock-%x", fullHash[:8])
} | [
"func",
"generateStoreLockName",
"(",
")",
"string",
"{",
"h",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"JujuControllersPath",
"(",
")",
")",
")",
"\n",
"fullHash",
":=",
"fmt",
".",
"Sprintf",
"(",
... | // generateStoreLockName uses part of the hash of the controller path as the
// name of the lock. This is to avoid contention between multiple users on a
// single machine with different controller files, but also helps with
// contention in tests. | [
"generateStoreLockName",
"uses",
"part",
"of",
"the",
"hash",
"of",
"the",
"controller",
"path",
"as",
"the",
"name",
"of",
"the",
"lock",
".",
"This",
"is",
"to",
"avoid",
"contention",
"between",
"multiple",
"users",
"on",
"a",
"single",
"machine",
"with",... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L63-L68 |
155,731 | juju/juju | jujuclient/file.go | AllControllers | func (s *store) AllControllers() (map[string]ControllerDetails, error) {
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotate(err,
"cannot acquire lock file to read all the controllers",
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return nil, errors.Trace(err)
}
return controllers.Controllers, nil
} | go | func (s *store) AllControllers() (map[string]ControllerDetails, error) {
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotate(err,
"cannot acquire lock file to read all the controllers",
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return nil, errors.Trace(err)
}
return controllers.Controllers, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"AllControllers",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"ControllerDetails",
",",
"error",
")",
"{",
"releaser",
",",
"err",
":=",
"s",
".",
"acquireLock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ret... | // AllControllers implements ControllersGetter. | [
"AllControllers",
"implements",
"ControllersGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L85-L98 |
155,732 | juju/juju | jujuclient/file.go | CurrentController | func (s *store) CurrentController() (string, error) {
releaser, err := s.acquireLock()
if err != nil {
return "", errors.Annotate(err,
"cannot acquire lock file to get the current controller name",
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return "", errors.Trace(err)
}
if controllers.CurrentController == "" {
return "", errors.NotFoundf("current controller")
}
return controllers.CurrentController, nil
} | go | func (s *store) CurrentController() (string, error) {
releaser, err := s.acquireLock()
if err != nil {
return "", errors.Annotate(err,
"cannot acquire lock file to get the current controller name",
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return "", errors.Trace(err)
}
if controllers.CurrentController == "" {
return "", errors.NotFoundf("current controller")
}
return controllers.CurrentController, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"CurrentController",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"releaser",
",",
"err",
":=",
"s",
".",
"acquireLock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
... | // CurrentController implements ControllersGetter. | [
"CurrentController",
"implements",
"ControllersGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L101-L117 |
155,733 | juju/juju | jujuclient/file.go | ControllerByName | func (s *store) ControllerByName(name string) (*ControllerDetails, error) {
if err := ValidateControllerName(name); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotatef(err,
"cannot acquire lock file to read controller %s", name,
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return nil, errors.Trace(err)
}
if result, ok := controllers.Controllers[name]; ok {
return &result, nil
}
return nil, errors.NotFoundf("controller %s", name)
} | go | func (s *store) ControllerByName(name string) (*ControllerDetails, error) {
if err := ValidateControllerName(name); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotatef(err,
"cannot acquire lock file to read controller %s", name,
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return nil, errors.Trace(err)
}
if result, ok := controllers.Controllers[name]; ok {
return &result, nil
}
return nil, errors.NotFoundf("controller %s", name)
} | [
"func",
"(",
"s",
"*",
"store",
")",
"ControllerByName",
"(",
"name",
"string",
")",
"(",
"*",
"ControllerDetails",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",... | // ControllerByName implements ControllersGetter. | [
"ControllerByName",
"implements",
"ControllersGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L120-L141 |
155,734 | juju/juju | jujuclient/file.go | ControllerByAPIEndpoints | func (s *store) ControllerByAPIEndpoints(endpoints ...string) (*ControllerDetails, string, error) {
releaser, err := s.acquireLock()
if err != nil {
return nil, "", errors.Annotatef(err, "cannot acquire lock file to read controllers")
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return nil, "", errors.Trace(err)
}
matchEps := set.NewStrings(endpoints...)
for name, ctrl := range controllers.Controllers {
if matchEps.Intersection(set.NewStrings(ctrl.APIEndpoints...)).IsEmpty() {
continue
}
return &ctrl, name, nil
}
return nil, "", errors.NotFoundf("controller with API endpoints %v", endpoints)
} | go | func (s *store) ControllerByAPIEndpoints(endpoints ...string) (*ControllerDetails, string, error) {
releaser, err := s.acquireLock()
if err != nil {
return nil, "", errors.Annotatef(err, "cannot acquire lock file to read controllers")
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return nil, "", errors.Trace(err)
}
matchEps := set.NewStrings(endpoints...)
for name, ctrl := range controllers.Controllers {
if matchEps.Intersection(set.NewStrings(ctrl.APIEndpoints...)).IsEmpty() {
continue
}
return &ctrl, name, nil
}
return nil, "", errors.NotFoundf("controller with API endpoints %v", endpoints)
} | [
"func",
"(",
"s",
"*",
"store",
")",
"ControllerByAPIEndpoints",
"(",
"endpoints",
"...",
"string",
")",
"(",
"*",
"ControllerDetails",
",",
"string",
",",
"error",
")",
"{",
"releaser",
",",
"err",
":=",
"s",
".",
"acquireLock",
"(",
")",
"\n",
"if",
... | // ControllerByEndpoints implements ControllersGetter. | [
"ControllerByEndpoints",
"implements",
"ControllersGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L144-L165 |
155,735 | juju/juju | jujuclient/file.go | UpdateController | func (s *store) UpdateController(name string, details ControllerDetails) error {
if err := ValidateControllerName(name); err != nil {
return errors.Trace(err)
}
if err := ValidateControllerDetails(details); err != nil {
return errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotatef(err,
"cannot acquire lock file to update controller %s", name,
)
}
defer releaser.Release()
all, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return errors.Annotate(err, "cannot get controllers")
}
if len(all.Controllers) == 0 {
return errors.NotFoundf("controllers")
}
for k, v := range all.Controllers {
if v.ControllerUUID == details.ControllerUUID && k != name {
return errors.AlreadyExistsf("controller %s with UUID %s",
k, v.ControllerUUID)
}
}
if _, ok := all.Controllers[name]; !ok {
return errors.NotFoundf("controller %s", name)
}
all.Controllers[name] = details
return WriteControllersFile(all)
} | go | func (s *store) UpdateController(name string, details ControllerDetails) error {
if err := ValidateControllerName(name); err != nil {
return errors.Trace(err)
}
if err := ValidateControllerDetails(details); err != nil {
return errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotatef(err,
"cannot acquire lock file to update controller %s", name,
)
}
defer releaser.Release()
all, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return errors.Annotate(err, "cannot get controllers")
}
if len(all.Controllers) == 0 {
return errors.NotFoundf("controllers")
}
for k, v := range all.Controllers {
if v.ControllerUUID == details.ControllerUUID && k != name {
return errors.AlreadyExistsf("controller %s with UUID %s",
k, v.ControllerUUID)
}
}
if _, ok := all.Controllers[name]; !ok {
return errors.NotFoundf("controller %s", name)
}
all.Controllers[name] = details
return WriteControllersFile(all)
} | [
"func",
"(",
"s",
"*",
"store",
")",
"UpdateController",
"(",
"name",
"string",
",",
"details",
"ControllerDetails",
")",
"error",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
... | // UpdateController implements ControllerUpdater. | [
"UpdateController",
"implements",
"ControllerUpdater",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L209-L247 |
155,736 | juju/juju | jujuclient/file.go | SetCurrentController | func (s *store) SetCurrentController(name string) error {
if err := ValidateControllerName(name); err != nil {
return errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotate(err,
"cannot acquire lock file to set the current controller name",
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return errors.Trace(err)
}
if _, ok := controllers.Controllers[name]; !ok {
return errors.NotFoundf("controller %v", name)
}
if controllers.CurrentController == name {
return nil
}
controllers.CurrentController = name
return WriteControllersFile(controllers)
} | go | func (s *store) SetCurrentController(name string) error {
if err := ValidateControllerName(name); err != nil {
return errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotate(err,
"cannot acquire lock file to set the current controller name",
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return errors.Trace(err)
}
if _, ok := controllers.Controllers[name]; !ok {
return errors.NotFoundf("controller %v", name)
}
if controllers.CurrentController == name {
return nil
}
controllers.CurrentController = name
return WriteControllersFile(controllers)
} | [
"func",
"(",
"s",
"*",
"store",
")",
"SetCurrentController",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",... | // SetCurrentController implements ControllerUpdater. | [
"SetCurrentController",
"implements",
"ControllerUpdater",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L250-L275 |
155,737 | juju/juju | jujuclient/file.go | RemoveController | func (s *store) RemoveController(name string) error {
if err := ValidateControllerName(name); err != nil {
return errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotatef(err,
"cannot acquire lock file to remove controller %s", name,
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return errors.Annotate(err, "cannot get controllers")
}
// We remove all controllers with the same UUID as the named one.
namedControllerDetails, ok := controllers.Controllers[name]
if !ok {
return nil
}
var names []string
for name, details := range controllers.Controllers {
if details.ControllerUUID == namedControllerDetails.ControllerUUID {
names = append(names, name)
delete(controllers.Controllers, name)
if controllers.CurrentController == name {
controllers.CurrentController = ""
}
}
}
// Remove models for the controller.
controllerModels, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return errors.Trace(err)
}
for _, name := range names {
if _, ok := controllerModels[name]; ok {
delete(controllerModels, name)
if err := WriteModelsFile(controllerModels); err != nil {
return errors.Trace(err)
}
}
}
// Remove accounts for the controller.
controllerAccounts, err := ReadAccountsFile(JujuAccountsPath())
if err != nil {
return errors.Trace(err)
}
for _, name := range names {
if _, ok := controllerAccounts[name]; ok {
delete(controllerAccounts, name)
if err := WriteAccountsFile(controllerAccounts); err != nil {
return errors.Trace(err)
}
}
}
// Remove bootstrap config for the controller.
bootstrapConfigurations, err := ReadBootstrapConfigFile(JujuBootstrapConfigPath())
if err != nil {
return errors.Trace(err)
}
for _, name := range names {
if _, ok := bootstrapConfigurations[name]; ok {
delete(bootstrapConfigurations, name)
if err := WriteBootstrapConfigFile(bootstrapConfigurations); err != nil {
return errors.Trace(err)
}
}
}
// Remove the controller cookie jars.
for _, name := range names {
err := os.Remove(JujuCookiePath(name))
if err != nil && !os.IsNotExist(err) {
return errors.Trace(err)
}
}
// Finally, remove the controllers. This must be done last
// so we don't end up with dangling entries in other files.
return WriteControllersFile(controllers)
} | go | func (s *store) RemoveController(name string) error {
if err := ValidateControllerName(name); err != nil {
return errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotatef(err,
"cannot acquire lock file to remove controller %s", name,
)
}
defer releaser.Release()
controllers, err := ReadControllersFile(JujuControllersPath())
if err != nil {
return errors.Annotate(err, "cannot get controllers")
}
// We remove all controllers with the same UUID as the named one.
namedControllerDetails, ok := controllers.Controllers[name]
if !ok {
return nil
}
var names []string
for name, details := range controllers.Controllers {
if details.ControllerUUID == namedControllerDetails.ControllerUUID {
names = append(names, name)
delete(controllers.Controllers, name)
if controllers.CurrentController == name {
controllers.CurrentController = ""
}
}
}
// Remove models for the controller.
controllerModels, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return errors.Trace(err)
}
for _, name := range names {
if _, ok := controllerModels[name]; ok {
delete(controllerModels, name)
if err := WriteModelsFile(controllerModels); err != nil {
return errors.Trace(err)
}
}
}
// Remove accounts for the controller.
controllerAccounts, err := ReadAccountsFile(JujuAccountsPath())
if err != nil {
return errors.Trace(err)
}
for _, name := range names {
if _, ok := controllerAccounts[name]; ok {
delete(controllerAccounts, name)
if err := WriteAccountsFile(controllerAccounts); err != nil {
return errors.Trace(err)
}
}
}
// Remove bootstrap config for the controller.
bootstrapConfigurations, err := ReadBootstrapConfigFile(JujuBootstrapConfigPath())
if err != nil {
return errors.Trace(err)
}
for _, name := range names {
if _, ok := bootstrapConfigurations[name]; ok {
delete(bootstrapConfigurations, name)
if err := WriteBootstrapConfigFile(bootstrapConfigurations); err != nil {
return errors.Trace(err)
}
}
}
// Remove the controller cookie jars.
for _, name := range names {
err := os.Remove(JujuCookiePath(name))
if err != nil && !os.IsNotExist(err) {
return errors.Trace(err)
}
}
// Finally, remove the controllers. This must be done last
// so we don't end up with dangling entries in other files.
return WriteControllersFile(controllers)
} | [
"func",
"(",
"s",
"*",
"store",
")",
"RemoveController",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"... | // RemoveController implements ControllersRemover | [
"RemoveController",
"implements",
"ControllersRemover"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L278-L365 |
155,738 | juju/juju | jujuclient/file.go | AllModels | func (s *store) AllModels(controllerName string) (map[string]ModelDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotatef(err,
"cannot acquire lock file for getting all models for controller %s", controllerName,
)
}
defer releaser.Release()
all, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return nil, errors.Trace(err)
}
controllerModels, ok := all[controllerName]
if !ok {
return nil, errors.NotFoundf(
"models for controller %s",
controllerName,
)
}
return controllerModels.Models, nil
} | go | func (s *store) AllModels(controllerName string) (map[string]ModelDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotatef(err,
"cannot acquire lock file for getting all models for controller %s", controllerName,
)
}
defer releaser.Release()
all, err := ReadModelsFile(JujuModelsPath())
if err != nil {
return nil, errors.Trace(err)
}
controllerModels, ok := all[controllerName]
if !ok {
return nil, errors.NotFoundf(
"models for controller %s",
controllerName,
)
}
return controllerModels.Models, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"AllModels",
"(",
"controllerName",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"ModelDetails",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"controllerName",
")",
";",
"err",
"!=",
"ni... | // AllModels implements ModelGetter. | [
"AllModels",
"implements",
"ModelGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L447-L472 |
155,739 | juju/juju | jujuclient/file.go | AccountDetails | func (s *store) AccountDetails(controllerName string) (*AccountDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotatef(err,
"cannot acquire lock file for getting an account details on controller %s", controllerName,
)
}
defer releaser.Release()
accounts, err := ReadAccountsFile(JujuAccountsPath())
if err != nil {
return nil, errors.Trace(err)
}
details, ok := accounts[controllerName]
if !ok {
return nil, errors.NotFoundf("account details for controller %s", controllerName)
}
return &details, nil
} | go | func (s *store) AccountDetails(controllerName string) (*AccountDetails, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
releaser, err := s.acquireLock()
if err != nil {
return nil, errors.Annotatef(err,
"cannot acquire lock file for getting an account details on controller %s", controllerName,
)
}
defer releaser.Release()
accounts, err := ReadAccountsFile(JujuAccountsPath())
if err != nil {
return nil, errors.Trace(err)
}
details, ok := accounts[controllerName]
if !ok {
return nil, errors.NotFoundf("account details for controller %s", controllerName)
}
return &details, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"AccountDetails",
"(",
"controllerName",
"string",
")",
"(",
"*",
"AccountDetails",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"controllerName",
")",
";",
"err",
"!=",
"nil",
"{",
"return"... | // AccountByName implements AccountGetter. | [
"AccountByName",
"implements",
"AccountGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L699-L721 |
155,740 | juju/juju | jujuclient/file.go | UpdateCredential | func (s *store) UpdateCredential(cloudName string, details cloud.CloudCredential) error {
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotatef(err,
"cannot acquire lock file for updating credentials for %s", cloudName,
)
}
defer releaser.Release()
all, err := ReadCredentialsFile(JujuCredentialsPath())
if err != nil {
return errors.Annotate(err, "cannot get credentials")
}
if len(all) == 0 {
all = make(map[string]cloud.CloudCredential)
}
// Clear the default credential if we are removing that one.
if existing, ok := all[cloudName]; ok && existing.DefaultCredential != "" {
stillHaveDefault := false
for name := range details.AuthCredentials {
if name == existing.DefaultCredential {
stillHaveDefault = true
break
}
}
if !stillHaveDefault {
details.DefaultCredential = ""
}
}
if len(details.AuthCredentials) > 0 {
all[cloudName] = details
} else {
delete(all, cloudName)
}
return WriteCredentialsFile(all)
} | go | func (s *store) UpdateCredential(cloudName string, details cloud.CloudCredential) error {
releaser, err := s.acquireLock()
if err != nil {
return errors.Annotatef(err,
"cannot acquire lock file for updating credentials for %s", cloudName,
)
}
defer releaser.Release()
all, err := ReadCredentialsFile(JujuCredentialsPath())
if err != nil {
return errors.Annotate(err, "cannot get credentials")
}
if len(all) == 0 {
all = make(map[string]cloud.CloudCredential)
}
// Clear the default credential if we are removing that one.
if existing, ok := all[cloudName]; ok && existing.DefaultCredential != "" {
stillHaveDefault := false
for name := range details.AuthCredentials {
if name == existing.DefaultCredential {
stillHaveDefault = true
break
}
}
if !stillHaveDefault {
details.DefaultCredential = ""
}
}
if len(details.AuthCredentials) > 0 {
all[cloudName] = details
} else {
delete(all, cloudName)
}
return WriteCredentialsFile(all)
} | [
"func",
"(",
"s",
"*",
"store",
")",
"UpdateCredential",
"(",
"cloudName",
"string",
",",
"details",
"cloud",
".",
"CloudCredential",
")",
"error",
"{",
"releaser",
",",
"err",
":=",
"s",
".",
"acquireLock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{... | // UpdateCredential implements CredentialUpdater. | [
"UpdateCredential",
"implements",
"CredentialUpdater",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L750-L788 |
155,741 | juju/juju | jujuclient/file.go | CredentialForCloud | func (s *store) CredentialForCloud(cloudName string) (*cloud.CloudCredential, error) {
cloudCredentials, err := s.AllCredentials()
if err != nil {
return nil, errors.Trace(err)
}
credentials, ok := cloudCredentials[cloudName]
if !ok {
return nil, errors.NotFoundf("credentials for cloud %s", cloudName)
}
return &credentials, nil
} | go | func (s *store) CredentialForCloud(cloudName string) (*cloud.CloudCredential, error) {
cloudCredentials, err := s.AllCredentials()
if err != nil {
return nil, errors.Trace(err)
}
credentials, ok := cloudCredentials[cloudName]
if !ok {
return nil, errors.NotFoundf("credentials for cloud %s", cloudName)
}
return &credentials, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"CredentialForCloud",
"(",
"cloudName",
"string",
")",
"(",
"*",
"cloud",
".",
"CloudCredential",
",",
"error",
")",
"{",
"cloudCredentials",
",",
"err",
":=",
"s",
".",
"AllCredentials",
"(",
")",
"\n",
"if",
"err",
... | // CredentialForCloud implements CredentialGetter. | [
"CredentialForCloud",
"implements",
"CredentialGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L791-L801 |
155,742 | juju/juju | jujuclient/file.go | AllCredentials | func (s *store) AllCredentials() (map[string]cloud.CloudCredential, error) {
cloudCredentials, err := ReadCredentialsFile(JujuCredentialsPath())
if err != nil {
return nil, errors.Trace(err)
}
return cloudCredentials, nil
} | go | func (s *store) AllCredentials() (map[string]cloud.CloudCredential, error) {
cloudCredentials, err := ReadCredentialsFile(JujuCredentialsPath())
if err != nil {
return nil, errors.Trace(err)
}
return cloudCredentials, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"AllCredentials",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"cloud",
".",
"CloudCredential",
",",
"error",
")",
"{",
"cloudCredentials",
",",
"err",
":=",
"ReadCredentialsFile",
"(",
"JujuCredentialsPath",
"(",
")",
")"... | // AllCredentials implements CredentialGetter. | [
"AllCredentials",
"implements",
"CredentialGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L804-L810 |
155,743 | juju/juju | jujuclient/file.go | CookieJar | func (s *store) CookieJar(controllerName string) (CookieJar, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
path := JujuCookiePath(controllerName)
jar, err := cookiejar.New(&cookiejar.Options{
Filename: path,
})
if err != nil {
return nil, errors.Trace(err)
}
return &cookieJar{
path: path,
Jar: jar,
}, nil
} | go | func (s *store) CookieJar(controllerName string) (CookieJar, error) {
if err := ValidateControllerName(controllerName); err != nil {
return nil, errors.Trace(err)
}
path := JujuCookiePath(controllerName)
jar, err := cookiejar.New(&cookiejar.Options{
Filename: path,
})
if err != nil {
return nil, errors.Trace(err)
}
return &cookieJar{
path: path,
Jar: jar,
}, nil
} | [
"func",
"(",
"s",
"*",
"store",
")",
"CookieJar",
"(",
"controllerName",
"string",
")",
"(",
"CookieJar",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ValidateControllerName",
"(",
"controllerName",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",... | // CookieJar returns the cookie jar associated with the given controller. | [
"CookieJar",
"returns",
"the",
"cookie",
"jar",
"associated",
"with",
"the",
"given",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/file.go#L855-L870 |
155,744 | juju/juju | cmd/juju/commands/scp.go | Run | func (c *scpCommand) Run(ctx *cmd.Context) error {
err := c.initRun()
if err != nil {
return errors.Trace(err)
}
defer c.cleanupRun()
args, targets, err := expandArgs(c.Args, c.resolveTarget)
if err != nil {
return err
}
options, err := c.getSSHOptions(false, targets...)
if err != nil {
return err
}
return ssh.Copy(args, options)
} | go | func (c *scpCommand) Run(ctx *cmd.Context) error {
err := c.initRun()
if err != nil {
return errors.Trace(err)
}
defer c.cleanupRun()
args, targets, err := expandArgs(c.Args, c.resolveTarget)
if err != nil {
return err
}
options, err := c.getSSHOptions(false, targets...)
if err != nil {
return err
}
return ssh.Copy(args, options)
} | [
"func",
"(",
"c",
"*",
"scpCommand",
")",
"Run",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"error",
"{",
"err",
":=",
"c",
".",
"initRun",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n"... | // Run resolves c.Target to a machine, or host of a unit and
// forks ssh with c.Args, if provided. | [
"Run",
"resolves",
"c",
".",
"Target",
"to",
"a",
"machine",
"or",
"host",
"of",
"a",
"unit",
"and",
"forks",
"ssh",
"with",
"c",
".",
"Args",
"if",
"provided",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/scp.go#L107-L125 |
155,745 | juju/juju | provider/lxd/environ.go | Config | func (env *environ) Config() *config.Config {
env.lock.Lock()
defer env.lock.Unlock()
cfg := env.ecfgUnlocked.Config
return cfg
} | go | func (env *environ) Config() *config.Config {
env.lock.Lock()
defer env.lock.Unlock()
cfg := env.ecfgUnlocked.Config
return cfg
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"Config",
"(",
")",
"*",
"config",
".",
"Config",
"{",
"env",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"env",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"cfg",
":=",
"env",
".",
"ecfgUnlocked"... | // Config returns the configuration data with which the env was created. | [
"Config",
"returns",
"the",
"configuration",
"data",
"with",
"which",
"the",
"env",
"was",
"created",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/environ.go#L152-L158 |
155,746 | juju/juju | provider/lxd/environ.go | LXDProfileNames | func (env *environ) LXDProfileNames(containerName string) ([]string, error) {
return env.server().GetContainerProfiles(containerName)
} | go | func (env *environ) LXDProfileNames(containerName string) ([]string, error) {
return env.server().GetContainerProfiles(containerName)
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"LXDProfileNames",
"(",
"containerName",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"return",
"env",
".",
"server",
"(",
")",
".",
"GetContainerProfiles",
"(",
"containerName",
")",
"\n",
"}"
... | // LXDProfileNames implements environs.LXDProfiler. | [
"LXDProfileNames",
"implements",
"environs",
".",
"LXDProfiler",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/environ.go#L355-L357 |
155,747 | juju/juju | apiserver/facades/client/backups/shim.go | MachineSeries | func (s *stateShim) MachineSeries(id string) (string, error) {
m, err := s.State.Machine(id)
if err != nil {
return "", errors.Trace(err)
}
return m.Series(), nil
} | go | func (s *stateShim) MachineSeries(id string) (string, error) {
m, err := s.State.Machine(id)
if err != nil {
return "", errors.Trace(err)
}
return m.Series(), nil
} | [
"func",
"(",
"s",
"*",
"stateShim",
")",
"MachineSeries",
"(",
"id",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"s",
".",
"State",
".",
"Machine",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // MachineSeries implements backups.Backend | [
"MachineSeries",
"implements",
"backups",
".",
"Backend"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/shim.go#L27-L33 |
155,748 | juju/juju | apiserver/facades/client/backups/shim.go | NewFacadeV2 | func NewFacadeV2(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*APIv2, error) {
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return NewAPIv2(&stateShim{st, model}, resources, authorizer)
} | go | func NewFacadeV2(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*APIv2, error) {
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return NewAPIv2(&stateShim{st, model}, resources, authorizer)
} | [
"func",
"NewFacadeV2",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"APIv2",
",",
"error",
")",
"{",
"model",
",",
"err",
":=",
"st",
".",
"Model",
... | // NewFacadeV2 provides the required signature for version 2 facade registration. | [
"NewFacadeV2",
"provides",
"the",
"required",
"signature",
"for",
"version",
"2",
"facade",
"registration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/shim.go#L36-L42 |
155,749 | juju/juju | state/cloudservice.go | CloudService | func (c *CloudService) CloudService() (*CloudService, error) {
doc, err := c.cloudServiceDoc()
if err != nil {
return nil, errors.Trace(err)
}
if doc == nil {
return nil, errors.NotFoundf("cloud service %v", c.Id())
}
c.doc = *doc
return c, nil
} | go | func (c *CloudService) CloudService() (*CloudService, error) {
doc, err := c.cloudServiceDoc()
if err != nil {
return nil, errors.Trace(err)
}
if doc == nil {
return nil, errors.NotFoundf("cloud service %v", c.Id())
}
c.doc = *doc
return c, nil
} | [
"func",
"(",
"c",
"*",
"CloudService",
")",
"CloudService",
"(",
")",
"(",
"*",
"CloudService",
",",
"error",
")",
"{",
"doc",
",",
"err",
":=",
"c",
".",
"cloudServiceDoc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"erro... | // CloudService return the content of cloud service from the underlying state.
// It returns an error that satisfies errors.IsNotFound if the cloud service has been removed. | [
"CloudService",
"return",
"the",
"content",
"of",
"cloud",
"service",
"from",
"the",
"underlying",
"state",
".",
"It",
"returns",
"an",
"error",
"that",
"satisfies",
"errors",
".",
"IsNotFound",
"if",
"the",
"cloud",
"service",
"has",
"been",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudservice.go#L78-L88 |
155,750 | juju/juju | state/cloudservice.go | Refresh | func (c *CloudService) Refresh() error {
_, err := c.CloudService()
return errors.Trace(err)
} | go | func (c *CloudService) Refresh() error {
_, err := c.CloudService()
return errors.Trace(err)
} | [
"func",
"(",
"c",
"*",
"CloudService",
")",
"Refresh",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"CloudService",
"(",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Refresh refreshes the content of cloud service from the underlying state.
// It returns an error that satisfies errors.IsNotFound if the cloud service has been removed. | [
"Refresh",
"refreshes",
"the",
"content",
"of",
"cloud",
"service",
"from",
"the",
"underlying",
"state",
".",
"It",
"returns",
"an",
"error",
"that",
"satisfies",
"errors",
".",
"IsNotFound",
"if",
"the",
"cloud",
"service",
"has",
"been",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudservice.go#L92-L95 |
155,751 | juju/juju | cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go | NewMockUpgradeMachineSeriesAPI | func NewMockUpgradeMachineSeriesAPI(ctrl *gomock.Controller) *MockUpgradeMachineSeriesAPI {
mock := &MockUpgradeMachineSeriesAPI{ctrl: ctrl}
mock.recorder = &MockUpgradeMachineSeriesAPIMockRecorder{mock}
return mock
} | go | func NewMockUpgradeMachineSeriesAPI(ctrl *gomock.Controller) *MockUpgradeMachineSeriesAPI {
mock := &MockUpgradeMachineSeriesAPI{ctrl: ctrl}
mock.recorder = &MockUpgradeMachineSeriesAPIMockRecorder{mock}
return mock
} | [
"func",
"NewMockUpgradeMachineSeriesAPI",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockUpgradeMachineSeriesAPI",
"{",
"mock",
":=",
"&",
"MockUpgradeMachineSeriesAPI",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"Mock... | // NewMockUpgradeMachineSeriesAPI creates a new mock instance | [
"NewMockUpgradeMachineSeriesAPI",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go#L26-L30 |
155,752 | juju/juju | cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go | BestAPIVersion | func (m *MockUpgradeMachineSeriesAPI) BestAPIVersion() int {
ret := m.ctrl.Call(m, "BestAPIVersion")
ret0, _ := ret[0].(int)
return ret0
} | go | func (m *MockUpgradeMachineSeriesAPI) BestAPIVersion() int {
ret := m.ctrl.Call(m, "BestAPIVersion")
ret0, _ := ret[0].(int)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeMachineSeriesAPI",
")",
"BestAPIVersion",
"(",
")",
"int",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"int",
... | // BestAPIVersion mocks base method | [
"BestAPIVersion",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go#L38-L42 |
155,753 | juju/juju | cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go | GetUpgradeSeriesMessages | func (mr *MockUpgradeMachineSeriesAPIMockRecorder) GetUpgradeSeriesMessages(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUpgradeSeriesMessages", reflect.TypeOf((*MockUpgradeMachineSeriesAPI)(nil).GetUpgradeSeriesMessages), arg0, arg1)
} | go | func (mr *MockUpgradeMachineSeriesAPIMockRecorder) GetUpgradeSeriesMessages(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUpgradeSeriesMessages", reflect.TypeOf((*MockUpgradeMachineSeriesAPI)(nil).GetUpgradeSeriesMessages), arg0, arg1)
} | [
"func",
"(",
"mr",
"*",
"MockUpgradeMachineSeriesAPIMockRecorder",
")",
"GetUpgradeSeriesMessages",
"(",
"arg0",
",",
"arg1",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
... | // GetUpgradeSeriesMessages indicates an expected call of GetUpgradeSeriesMessages | [
"GetUpgradeSeriesMessages",
"indicates",
"an",
"expected",
"call",
"of",
"GetUpgradeSeriesMessages"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go#L70-L72 |
155,754 | juju/juju | cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go | UpgradeSeriesComplete | func (m *MockUpgradeMachineSeriesAPI) UpgradeSeriesComplete(arg0 string) error {
ret := m.ctrl.Call(m, "UpgradeSeriesComplete", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockUpgradeMachineSeriesAPI) UpgradeSeriesComplete(arg0 string) error {
ret := m.ctrl.Call(m, "UpgradeSeriesComplete", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeMachineSeriesAPI",
")",
"UpgradeSeriesComplete",
"(",
"arg0",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret"... | // UpgradeSeriesComplete mocks base method | [
"UpgradeSeriesComplete",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go#L75-L79 |
155,755 | juju/juju | cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go | UpgradeSeriesPrepare | func (m *MockUpgradeMachineSeriesAPI) UpgradeSeriesPrepare(arg0, arg1 string, arg2 bool) error {
ret := m.ctrl.Call(m, "UpgradeSeriesPrepare", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockUpgradeMachineSeriesAPI) UpgradeSeriesPrepare(arg0, arg1 string, arg2 bool) error {
ret := m.ctrl.Call(m, "UpgradeSeriesPrepare", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeMachineSeriesAPI",
")",
"UpgradeSeriesPrepare",
"(",
"arg0",
",",
"arg1",
"string",
",",
"arg2",
"bool",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"a... | // UpgradeSeriesPrepare mocks base method | [
"UpgradeSeriesPrepare",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go#L87-L91 |
155,756 | juju/juju | cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go | UpgradeSeriesValidate | func (m *MockUpgradeMachineSeriesAPI) UpgradeSeriesValidate(arg0, arg1 string) ([]string, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesValidate", arg0, arg1)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockUpgradeMachineSeriesAPI) UpgradeSeriesValidate(arg0, arg1 string) ([]string, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesValidate", arg0, arg1)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockUpgradeMachineSeriesAPI",
")",
"UpgradeSeriesValidate",
"(",
"arg0",
",",
"arg1",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
... | // UpgradeSeriesValidate mocks base method | [
"UpgradeSeriesValidate",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/mocks/upgradeMachineSeriesAPI_mock.go#L99-L104 |
155,757 | juju/juju | resource/context/utils.go | FingerprintMatches | func (fpm FingerprintMatcher) FingerprintMatches(filename string, expected charmresource.Fingerprint) (bool, error) {
open := fpm.Open
if open == nil {
open = func(filename string) (io.ReadCloser, error) { return os.Open(filename) }
}
generateFingerprint := fpm.GenerateFingerprint
if generateFingerprint == nil {
generateFingerprint = charmresource.GenerateFingerprint
}
file, err := open(filename)
if os.IsNotExist(errors.Cause(err)) {
return false, nil
}
if err != nil {
return false, errors.Trace(err)
}
defer file.Close()
fp, err := generateFingerprint(file)
if err != nil {
return false, errors.Trace(err)
}
matches := (fp.String() == expected.String())
return matches, nil
} | go | func (fpm FingerprintMatcher) FingerprintMatches(filename string, expected charmresource.Fingerprint) (bool, error) {
open := fpm.Open
if open == nil {
open = func(filename string) (io.ReadCloser, error) { return os.Open(filename) }
}
generateFingerprint := fpm.GenerateFingerprint
if generateFingerprint == nil {
generateFingerprint = charmresource.GenerateFingerprint
}
file, err := open(filename)
if os.IsNotExist(errors.Cause(err)) {
return false, nil
}
if err != nil {
return false, errors.Trace(err)
}
defer file.Close()
fp, err := generateFingerprint(file)
if err != nil {
return false, errors.Trace(err)
}
matches := (fp.String() == expected.String())
return matches, nil
} | [
"func",
"(",
"fpm",
"FingerprintMatcher",
")",
"FingerprintMatches",
"(",
"filename",
"string",
",",
"expected",
"charmresource",
".",
"Fingerprint",
")",
"(",
"bool",
",",
"error",
")",
"{",
"open",
":=",
"fpm",
".",
"Open",
"\n",
"if",
"open",
"==",
"nil... | // FingerprintMatches determines whether or not the identified file's
// fingerprint matches the expected fingerprint. | [
"FingerprintMatches",
"determines",
"whether",
"or",
"not",
"the",
"identified",
"file",
"s",
"fingerprint",
"matches",
"the",
"expected",
"fingerprint",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/context/utils.go#L29-L54 |
155,758 | juju/juju | worker/uniter/operation/runcommands.go | Prepare | func (rc *runCommands) Prepare(state State) (*State, error) {
rnr, err := rc.runnerFactory.NewCommandRunner(context.CommandInfo{
RelationId: rc.args.RelationId,
RemoteUnitName: rc.args.RemoteUnitName,
ForceRemoteUnit: rc.args.ForceRemoteUnit,
})
if err != nil {
return nil, err
}
err = rnr.Context().Prepare()
if err != nil {
return nil, errors.Trace(err)
}
rc.runner = rnr
return nil, nil
} | go | func (rc *runCommands) Prepare(state State) (*State, error) {
rnr, err := rc.runnerFactory.NewCommandRunner(context.CommandInfo{
RelationId: rc.args.RelationId,
RemoteUnitName: rc.args.RemoteUnitName,
ForceRemoteUnit: rc.args.ForceRemoteUnit,
})
if err != nil {
return nil, err
}
err = rnr.Context().Prepare()
if err != nil {
return nil, errors.Trace(err)
}
rc.runner = rnr
return nil, nil
} | [
"func",
"(",
"rc",
"*",
"runCommands",
")",
"Prepare",
"(",
"state",
"State",
")",
"(",
"*",
"State",
",",
"error",
")",
"{",
"rnr",
",",
"err",
":=",
"rc",
".",
"runnerFactory",
".",
"NewCommandRunner",
"(",
"context",
".",
"CommandInfo",
"{",
"Relati... | // Prepare ensures the commands can be run. It never returns a state change.
// Prepare is part of the Operation interface. | [
"Prepare",
"ensures",
"the",
"commands",
"can",
"be",
"run",
".",
"It",
"never",
"returns",
"a",
"state",
"change",
".",
"Prepare",
"is",
"part",
"of",
"the",
"Operation",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/runcommands.go#L42-L58 |
155,759 | juju/juju | worker/uniter/operation/runcommands.go | Execute | func (rc *runCommands) Execute(state State) (*State, error) {
logger.Tracef("run commands: %s", rc)
if err := rc.callbacks.SetExecutingStatus("running commands"); err != nil {
return nil, errors.Trace(err)
}
response, err := rc.runner.RunCommands(rc.args.Commands)
switch err {
case context.ErrRequeueAndReboot:
logger.Warningf("cannot requeue external commands")
fallthrough
case context.ErrReboot:
rc.sendResponse(response, nil)
err = ErrNeedsReboot
default:
rc.sendResponse(response, err)
}
return nil, err
} | go | func (rc *runCommands) Execute(state State) (*State, error) {
logger.Tracef("run commands: %s", rc)
if err := rc.callbacks.SetExecutingStatus("running commands"); err != nil {
return nil, errors.Trace(err)
}
response, err := rc.runner.RunCommands(rc.args.Commands)
switch err {
case context.ErrRequeueAndReboot:
logger.Warningf("cannot requeue external commands")
fallthrough
case context.ErrReboot:
rc.sendResponse(response, nil)
err = ErrNeedsReboot
default:
rc.sendResponse(response, err)
}
return nil, err
} | [
"func",
"(",
"rc",
"*",
"runCommands",
")",
"Execute",
"(",
"state",
"State",
")",
"(",
"*",
"State",
",",
"error",
")",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"rc",
")",
"\n",
"if",
"err",
":=",
"rc",
".",
"callbacks",
".",
"SetExec... | // Execute runs the commands and dispatches their results. It never returns a
// state change.
// Execute is part of the Operation interface. | [
"Execute",
"runs",
"the",
"commands",
"and",
"dispatches",
"their",
"results",
".",
"It",
"never",
"returns",
"a",
"state",
"change",
".",
"Execute",
"is",
"part",
"of",
"the",
"Operation",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/runcommands.go#L63-L81 |
155,760 | juju/juju | jujuclient/validation.go | ValidateModelDetails | func ValidateModelDetails(details ModelDetails) error {
if details.ModelUUID == "" {
return errors.NotValidf("missing uuid, model details")
}
if details.ModelType == "" {
return errors.NotValidf("missing type, model details")
}
return nil
} | go | func ValidateModelDetails(details ModelDetails) error {
if details.ModelUUID == "" {
return errors.NotValidf("missing uuid, model details")
}
if details.ModelType == "" {
return errors.NotValidf("missing type, model details")
}
return nil
} | [
"func",
"ValidateModelDetails",
"(",
"details",
"ModelDetails",
")",
"error",
"{",
"if",
"details",
".",
"ModelUUID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"details",
".",
"ModelType",
"... | // ValidateModelDetails ensures that given model details are valid. | [
"ValidateModelDetails",
"ensures",
"that",
"given",
"model",
"details",
"are",
"valid",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/validation.go#L20-L28 |
155,761 | juju/juju | jujuclient/validation.go | ValidateAccountDetails | func ValidateAccountDetails(details AccountDetails) error {
if err := validateUser(details.User); err != nil {
return errors.Trace(err)
}
// It is valid for a password to be blank, because the client
// may use macaroons instead.
return nil
} | go | func ValidateAccountDetails(details AccountDetails) error {
if err := validateUser(details.User); err != nil {
return errors.Trace(err)
}
// It is valid for a password to be blank, because the client
// may use macaroons instead.
return nil
} | [
"func",
"ValidateAccountDetails",
"(",
"details",
"AccountDetails",
")",
"error",
"{",
"if",
"err",
":=",
"validateUser",
"(",
"details",
".",
"User",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
... | // ValidateModelDetails ensures that given account details are valid. | [
"ValidateModelDetails",
"ensures",
"that",
"given",
"account",
"details",
"are",
"valid",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/validation.go#L31-L38 |
155,762 | juju/juju | jujuclient/validation.go | ValidateModelName | func ValidateModelName(name string) error {
modelName, _, err := SplitModelName(name)
if err != nil {
return errors.Annotatef(err, "validating model name %q", name)
}
if !names.IsValidModelName(modelName) {
return errors.NotValidf("model name %q", name)
}
return nil
} | go | func ValidateModelName(name string) error {
modelName, _, err := SplitModelName(name)
if err != nil {
return errors.Annotatef(err, "validating model name %q", name)
}
if !names.IsValidModelName(modelName) {
return errors.NotValidf("model name %q", name)
}
return nil
} | [
"func",
"ValidateModelName",
"(",
"name",
"string",
")",
"error",
"{",
"modelName",
",",
"_",
",",
"err",
":=",
"SplitModelName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
... | // ValidateModelName validates the given model name. | [
"ValidateModelName",
"validates",
"the",
"given",
"model",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/validation.go#L53-L62 |
155,763 | juju/juju | jujuclient/validation.go | ValidateModel | func ValidateModel(name string, details ModelDetails) error {
if err := ValidateModelName(name); err != nil {
return err
}
if err := ValidateModelDetails(details); err != nil {
return err
}
return nil
} | go | func ValidateModel(name string, details ModelDetails) error {
if err := ValidateModelName(name); err != nil {
return err
}
if err := ValidateModelDetails(details); err != nil {
return err
}
return nil
} | [
"func",
"ValidateModel",
"(",
"name",
"string",
",",
"details",
"ModelDetails",
")",
"error",
"{",
"if",
"err",
":=",
"ValidateModelName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ValidateModel... | // ValidateModel validates the given model name and details. | [
"ValidateModel",
"validates",
"the",
"given",
"model",
"name",
"and",
"details",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/validation.go#L65-L73 |
155,764 | juju/juju | jujuclient/validation.go | ValidateBootstrapConfig | func ValidateBootstrapConfig(cfg BootstrapConfig) error {
if cfg.Cloud == "" {
return errors.NotValidf("empty cloud name")
}
if cfg.CloudType == "" {
return errors.NotValidf("empty cloud type")
}
if len(cfg.Config) == 0 {
return errors.NotValidf("empty config")
}
return nil
} | go | func ValidateBootstrapConfig(cfg BootstrapConfig) error {
if cfg.Cloud == "" {
return errors.NotValidf("empty cloud name")
}
if cfg.CloudType == "" {
return errors.NotValidf("empty cloud type")
}
if len(cfg.Config) == 0 {
return errors.NotValidf("empty config")
}
return nil
} | [
"func",
"ValidateBootstrapConfig",
"(",
"cfg",
"BootstrapConfig",
")",
"error",
"{",
"if",
"cfg",
".",
"Cloud",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"cfg",
".",
"CloudType",
"==",
"\"... | // ValidateBootstrapConfig validates the given boostrap config. | [
"ValidateBootstrapConfig",
"validates",
"the",
"given",
"boostrap",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/validation.go#L76-L87 |
155,765 | juju/juju | provider/lxd/provider.go | NewProvider | func NewProvider() environs.CloudEnvironProvider {
configReader := lxcConfigReader{}
factory := NewServerFactory()
credentials := environProviderCredentials{
certReadWriter: certificateReadWriter{},
certGenerator: certificateGenerator{},
lookup: netLookup{},
serverFactory: factory,
lxcConfigReader: configReader,
}
return &environProvider{
ProviderCredentials: credentials,
RequestFinalizeCredential: credentials,
ProviderCredentialsRegister: credentials,
serverFactory: factory,
lxcConfigReader: configReader,
}
} | go | func NewProvider() environs.CloudEnvironProvider {
configReader := lxcConfigReader{}
factory := NewServerFactory()
credentials := environProviderCredentials{
certReadWriter: certificateReadWriter{},
certGenerator: certificateGenerator{},
lookup: netLookup{},
serverFactory: factory,
lxcConfigReader: configReader,
}
return &environProvider{
ProviderCredentials: credentials,
RequestFinalizeCredential: credentials,
ProviderCredentialsRegister: credentials,
serverFactory: factory,
lxcConfigReader: configReader,
}
} | [
"func",
"NewProvider",
"(",
")",
"environs",
".",
"CloudEnvironProvider",
"{",
"configReader",
":=",
"lxcConfigReader",
"{",
"}",
"\n",
"factory",
":=",
"NewServerFactory",
"(",
")",
"\n",
"credentials",
":=",
"environProviderCredentials",
"{",
"certReadWriter",
":"... | // NewProvider returns a new LXD EnvironProvider. | [
"NewProvider",
"returns",
"a",
"new",
"LXD",
"EnvironProvider",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/provider.go#L115-L132 |
155,766 | juju/juju | worker/uniter/storage/state.go | ValidateHook | func (s *state) ValidateHook(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "inappropriate %q hook for storage %q", hi.Kind, s.storage.Id())
if hi.StorageId != s.storage.Id() {
return errors.Errorf("expected storage %q, got storage %q", s.storage.Id(), hi.StorageId)
}
switch hi.Kind {
case hooks.StorageAttached:
if s.attached {
return errors.New("storage already attached")
}
case hooks.StorageDetaching:
if !s.attached {
return errors.New("storage not attached")
}
}
return nil
} | go | func (s *state) ValidateHook(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "inappropriate %q hook for storage %q", hi.Kind, s.storage.Id())
if hi.StorageId != s.storage.Id() {
return errors.Errorf("expected storage %q, got storage %q", s.storage.Id(), hi.StorageId)
}
switch hi.Kind {
case hooks.StorageAttached:
if s.attached {
return errors.New("storage already attached")
}
case hooks.StorageDetaching:
if !s.attached {
return errors.New("storage not attached")
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"state",
")",
"ValidateHook",
"(",
"hi",
"hook",
".",
"Info",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"hi",
".",
"Kind",
",",
"s",
".",
"storag... | // ValidateHook returns an error if the supplied hook.Info does not represent
// a valid change to the storage state. Hooks must always be validated
// against the current state before they are run, to ensure that the system
// meets its guarantees about hook execution order. | [
"ValidateHook",
"returns",
"an",
"error",
"if",
"the",
"supplied",
"hook",
".",
"Info",
"does",
"not",
"represent",
"a",
"valid",
"change",
"to",
"the",
"storage",
"state",
".",
"Hooks",
"must",
"always",
"be",
"validated",
"against",
"the",
"current",
"stat... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/storage/state.go#L34-L50 |
155,767 | juju/juju | worker/uniter/storage/state.go | readStateFile | func readStateFile(dirPath string, tag names.StorageTag) (d *stateFile, err error) {
filename := strings.Replace(tag.Id(), "/", "-", -1)
d = &stateFile{
filepath.Join(dirPath, filename),
state{storage: tag},
}
defer errors.DeferredAnnotatef(&err, "cannot load storage %q state from %q", tag.Id(), d.path)
if _, err := os.Stat(d.path); os.IsNotExist(err) {
return d, nil
} else if err != nil {
return nil, err
}
var info diskInfo
if err := utils.ReadYaml(d.path, &info); err != nil {
return nil, errors.Errorf("invalid storage state file %q: %v", d.path, err)
}
if info.Attached == nil {
return nil, errors.Errorf("invalid storage state file %q: missing 'attached'", d.path)
}
d.state.attached = *info.Attached
return d, nil
} | go | func readStateFile(dirPath string, tag names.StorageTag) (d *stateFile, err error) {
filename := strings.Replace(tag.Id(), "/", "-", -1)
d = &stateFile{
filepath.Join(dirPath, filename),
state{storage: tag},
}
defer errors.DeferredAnnotatef(&err, "cannot load storage %q state from %q", tag.Id(), d.path)
if _, err := os.Stat(d.path); os.IsNotExist(err) {
return d, nil
} else if err != nil {
return nil, err
}
var info diskInfo
if err := utils.ReadYaml(d.path, &info); err != nil {
return nil, errors.Errorf("invalid storage state file %q: %v", d.path, err)
}
if info.Attached == nil {
return nil, errors.Errorf("invalid storage state file %q: missing 'attached'", d.path)
}
d.state.attached = *info.Attached
return d, nil
} | [
"func",
"readStateFile",
"(",
"dirPath",
"string",
",",
"tag",
"names",
".",
"StorageTag",
")",
"(",
"d",
"*",
"stateFile",
",",
"err",
"error",
")",
"{",
"filename",
":=",
"strings",
".",
"Replace",
"(",
"tag",
".",
"Id",
"(",
")",
",",
"\"",
"\"",
... | // readStateFile loads a stateFile from the subdirectory of dirPath named
// for the supplied storage tag. If the directory does not exist, no error
// is returned. | [
"readStateFile",
"loads",
"a",
"stateFile",
"from",
"the",
"subdirectory",
"of",
"dirPath",
"named",
"for",
"the",
"supplied",
"storage",
"tag",
".",
"If",
"the",
"directory",
"does",
"not",
"exist",
"no",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/storage/state.go#L68-L89 |
155,768 | juju/juju | worker/uniter/storage/state.go | readAllStateFiles | func readAllStateFiles(dirPath string) (files map[names.StorageTag]*stateFile, err error) {
defer errors.DeferredAnnotatef(&err, "cannot load storage state from %q", dirPath)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
return nil, nil
} else if err != nil {
return nil, err
}
fis, err := ioutil.ReadDir(dirPath)
if err != nil {
return nil, err
}
files = make(map[names.StorageTag]*stateFile)
for _, fi := range fis {
if fi.IsDir() {
continue
}
storageId := fi.Name()
if i := strings.LastIndex(storageId, "-"); i > 0 {
storageId = storageId[:i] + "/" + storageId[i+1:]
if !names.IsValidStorage(storageId) {
continue
}
} else {
// Lack of "-" means it's not a valid storage ID.
continue
}
tag := names.NewStorageTag(storageId)
f, err := readStateFile(dirPath, tag)
if err != nil {
return nil, err
}
files[tag] = f
}
return files, nil
} | go | func readAllStateFiles(dirPath string) (files map[names.StorageTag]*stateFile, err error) {
defer errors.DeferredAnnotatef(&err, "cannot load storage state from %q", dirPath)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
return nil, nil
} else if err != nil {
return nil, err
}
fis, err := ioutil.ReadDir(dirPath)
if err != nil {
return nil, err
}
files = make(map[names.StorageTag]*stateFile)
for _, fi := range fis {
if fi.IsDir() {
continue
}
storageId := fi.Name()
if i := strings.LastIndex(storageId, "-"); i > 0 {
storageId = storageId[:i] + "/" + storageId[i+1:]
if !names.IsValidStorage(storageId) {
continue
}
} else {
// Lack of "-" means it's not a valid storage ID.
continue
}
tag := names.NewStorageTag(storageId)
f, err := readStateFile(dirPath, tag)
if err != nil {
return nil, err
}
files[tag] = f
}
return files, nil
} | [
"func",
"readAllStateFiles",
"(",
"dirPath",
"string",
")",
"(",
"files",
"map",
"[",
"names",
".",
"StorageTag",
"]",
"*",
"stateFile",
",",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
... | // readAllStateFiles loads and returns every stateFile persisted inside
// the supplied dirPath. If dirPath does not exist, no error is returned. | [
"readAllStateFiles",
"loads",
"and",
"returns",
"every",
"stateFile",
"persisted",
"inside",
"the",
"supplied",
"dirPath",
".",
"If",
"dirPath",
"does",
"not",
"exist",
"no",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/storage/state.go#L93-L127 |
155,769 | juju/juju | worker/uniter/storage/state.go | CommitHook | func (d *stateFile) CommitHook(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.StorageId)
if hi.Kind == hooks.StorageDetaching {
return d.Remove()
}
attached := true
di := diskInfo{&attached}
if err := utils.WriteYaml(d.path, &di); err != nil {
return err
}
// If write was successful, update own state.
d.state.attached = true
return nil
} | go | func (d *stateFile) CommitHook(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.StorageId)
if hi.Kind == hooks.StorageDetaching {
return d.Remove()
}
attached := true
di := diskInfo{&attached}
if err := utils.WriteYaml(d.path, &di); err != nil {
return err
}
// If write was successful, update own state.
d.state.attached = true
return nil
} | [
"func",
"(",
"d",
"*",
"stateFile",
")",
"CommitHook",
"(",
"hi",
"hook",
".",
"Info",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"hi",
".",
"Kind",
",",
"hi",
".",
"Sto... | // CommitHook atomically writes to disk the storage state change in hi.
// It must be called after the respective hook was executed successfully.
// CommitHook doesn't validate hi but guarantees that successive writes
// of the same hi are idempotent. | [
"CommitHook",
"atomically",
"writes",
"to",
"disk",
"the",
"storage",
"state",
"change",
"in",
"hi",
".",
"It",
"must",
"be",
"called",
"after",
"the",
"respective",
"hook",
"was",
"executed",
"successfully",
".",
"CommitHook",
"doesn",
"t",
"validate",
"hi",
... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/storage/state.go#L133-L146 |
155,770 | juju/juju | environs/simplestreams/decode.go | DecodeCheckSignature | func DecodeCheckSignature(r io.Reader, armoredPublicKey string) ([]byte, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
b, _ := clearsign.Decode(data)
if b == nil {
return nil, &NotPGPSignedError{}
}
keyring, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(armoredPublicKey))
if err != nil {
return nil, fmt.Errorf("failed to parse public key: %v", err)
}
_, err = openpgp.CheckDetachedSignature(keyring, bytes.NewBuffer(b.Bytes), b.ArmoredSignature.Body)
if err != nil {
return nil, err
}
return b.Plaintext, nil
} | go | func DecodeCheckSignature(r io.Reader, armoredPublicKey string) ([]byte, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
b, _ := clearsign.Decode(data)
if b == nil {
return nil, &NotPGPSignedError{}
}
keyring, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(armoredPublicKey))
if err != nil {
return nil, fmt.Errorf("failed to parse public key: %v", err)
}
_, err = openpgp.CheckDetachedSignature(keyring, bytes.NewBuffer(b.Bytes), b.ArmoredSignature.Body)
if err != nil {
return nil, err
}
return b.Plaintext, nil
} | [
"func",
"DecodeCheckSignature",
"(",
"r",
"io",
".",
"Reader",
",",
"armoredPublicKey",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // DecodeCheckSignature parses the inline signed PGP text, checks the signature,
// and returns plain text if the signature matches. | [
"DecodeCheckSignature",
"parses",
"the",
"inline",
"signed",
"PGP",
"text",
"checks",
"the",
"signature",
"and",
"returns",
"plain",
"text",
"if",
"the",
"signature",
"matches",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/decode.go#L18-L37 |
155,771 | juju/juju | api/uniter/uniter.go | NewState | func NewState(
caller base.APICaller,
authTag names.UnitTag,
) *State {
facadeCaller := base.NewFacadeCaller(
caller,
uniterFacade,
)
state := &State{
ModelWatcher: common.NewModelWatcher(facadeCaller),
APIAddresser: common.NewAPIAddresser(facadeCaller),
UpgradeSeriesAPI: common.NewUpgradeSeriesAPI(facadeCaller, authTag),
StorageAccessor: NewStorageAccessor(facadeCaller),
facade: facadeCaller,
unitTag: authTag,
}
newWatcher := func(result params.NotifyWatchResult) watcher.NotifyWatcher {
return apiwatcher.NewNotifyWatcher(caller, result)
}
state.LeadershipSettings = NewLeadershipSettingsAccessor(
facadeCaller.FacadeCall,
newWatcher,
ErrIfNotVersionFn(2, state.BestAPIVersion()),
)
return state
} | go | func NewState(
caller base.APICaller,
authTag names.UnitTag,
) *State {
facadeCaller := base.NewFacadeCaller(
caller,
uniterFacade,
)
state := &State{
ModelWatcher: common.NewModelWatcher(facadeCaller),
APIAddresser: common.NewAPIAddresser(facadeCaller),
UpgradeSeriesAPI: common.NewUpgradeSeriesAPI(facadeCaller, authTag),
StorageAccessor: NewStorageAccessor(facadeCaller),
facade: facadeCaller,
unitTag: authTag,
}
newWatcher := func(result params.NotifyWatchResult) watcher.NotifyWatcher {
return apiwatcher.NewNotifyWatcher(caller, result)
}
state.LeadershipSettings = NewLeadershipSettingsAccessor(
facadeCaller.FacadeCall,
newWatcher,
ErrIfNotVersionFn(2, state.BestAPIVersion()),
)
return state
} | [
"func",
"NewState",
"(",
"caller",
"base",
".",
"APICaller",
",",
"authTag",
"names",
".",
"UnitTag",
",",
")",
"*",
"State",
"{",
"facadeCaller",
":=",
"base",
".",
"NewFacadeCaller",
"(",
"caller",
",",
"uniterFacade",
",",
")",
"\n",
"state",
":=",
"&... | // NewState creates a new client-side Uniter facade. | [
"NewState",
"creates",
"a",
"new",
"client",
"-",
"side",
"Uniter",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L40-L66 |
155,772 | juju/juju | api/uniter/uniter.go | life | func (st *State) life(tag names.Tag) (params.Life, error) {
return common.OneLife(st.facade, tag)
} | go | func (st *State) life(tag names.Tag) (params.Life, error) {
return common.OneLife(st.facade, tag)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"life",
"(",
"tag",
"names",
".",
"Tag",
")",
"(",
"params",
".",
"Life",
",",
"error",
")",
"{",
"return",
"common",
".",
"OneLife",
"(",
"st",
".",
"facade",
",",
"tag",
")",
"\n",
"}"
] | // life requests the lifecycle of the given entity from the server. | [
"life",
"requests",
"the",
"lifecycle",
"of",
"the",
"given",
"entity",
"from",
"the",
"server",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L80-L82 |
155,773 | juju/juju | api/uniter/uniter.go | relation | func (st *State) relation(relationTag, unitTag names.Tag) (params.RelationResult, error) {
nothing := params.RelationResult{}
var result params.RelationResults
args := params.RelationUnits{
RelationUnits: []params.RelationUnit{
{Relation: relationTag.String(), Unit: unitTag.String()},
},
}
err := st.facade.FacadeCall("Relation", args, &result)
if err != nil {
return nothing, err
}
if len(result.Results) != 1 {
return nothing, fmt.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return nothing, err
}
return result.Results[0], nil
} | go | func (st *State) relation(relationTag, unitTag names.Tag) (params.RelationResult, error) {
nothing := params.RelationResult{}
var result params.RelationResults
args := params.RelationUnits{
RelationUnits: []params.RelationUnit{
{Relation: relationTag.String(), Unit: unitTag.String()},
},
}
err := st.facade.FacadeCall("Relation", args, &result)
if err != nil {
return nothing, err
}
if len(result.Results) != 1 {
return nothing, fmt.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return nothing, err
}
return result.Results[0], nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"relation",
"(",
"relationTag",
",",
"unitTag",
"names",
".",
"Tag",
")",
"(",
"params",
".",
"RelationResult",
",",
"error",
")",
"{",
"nothing",
":=",
"params",
".",
"RelationResult",
"{",
"}",
"\n",
"var",
"resu... | // relation requests relation information from the server. | [
"relation",
"requests",
"relation",
"information",
"from",
"the",
"server",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L85-L104 |
155,774 | juju/juju | api/uniter/uniter.go | getOneAction | func (st *State) getOneAction(tag *names.ActionTag) (params.ActionResult, error) {
nothing := params.ActionResult{}
args := params.Entities{
Entities: []params.Entity{
{Tag: tag.String()},
},
}
var results params.ActionResults
err := st.facade.FacadeCall("Actions", args, &results)
if err != nil {
return nothing, err
}
if len(results.Results) > 1 {
return nothing, fmt.Errorf("expected only 1 action query result, got %d", len(results.Results))
}
// handle server errors
result := results.Results[0]
if err := result.Error; err != nil {
return nothing, err
}
return result, nil
} | go | func (st *State) getOneAction(tag *names.ActionTag) (params.ActionResult, error) {
nothing := params.ActionResult{}
args := params.Entities{
Entities: []params.Entity{
{Tag: tag.String()},
},
}
var results params.ActionResults
err := st.facade.FacadeCall("Actions", args, &results)
if err != nil {
return nothing, err
}
if len(results.Results) > 1 {
return nothing, fmt.Errorf("expected only 1 action query result, got %d", len(results.Results))
}
// handle server errors
result := results.Results[0]
if err := result.Error; err != nil {
return nothing, err
}
return result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"getOneAction",
"(",
"tag",
"*",
"names",
".",
"ActionTag",
")",
"(",
"params",
".",
"ActionResult",
",",
"error",
")",
"{",
"nothing",
":=",
"params",
".",
"ActionResult",
"{",
"}",
"\n\n",
"args",
":=",
"params",... | // getOneAction retrieves a single Action from the controller. | [
"getOneAction",
"retrieves",
"a",
"single",
"Action",
"from",
"the",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L122-L148 |
155,775 | juju/juju | api/uniter/uniter.go | Application | func (st *State) Application(tag names.ApplicationTag) (*Application, error) {
life, err := st.life(tag)
if err != nil {
return nil, err
}
return &Application{
tag: tag,
life: life,
st: st,
}, nil
} | go | func (st *State) Application(tag names.ApplicationTag) (*Application, error) {
life, err := st.life(tag)
if err != nil {
return nil, err
}
return &Application{
tag: tag,
life: life,
st: st,
}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Application",
"(",
"tag",
"names",
".",
"ApplicationTag",
")",
"(",
"*",
"Application",
",",
"error",
")",
"{",
"life",
",",
"err",
":=",
"st",
".",
"life",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"... | // Application returns an application state by tag. | [
"Application",
"returns",
"an",
"application",
"state",
"by",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L164-L174 |
155,776 | juju/juju | api/uniter/uniter.go | Charm | func (st *State) Charm(curl *charm.URL) (*Charm, error) {
if curl == nil {
return nil, fmt.Errorf("charm url cannot be nil")
}
return &Charm{
st: st,
curl: curl,
}, nil
} | go | func (st *State) Charm(curl *charm.URL) (*Charm, error) {
if curl == nil {
return nil, fmt.Errorf("charm url cannot be nil")
}
return &Charm{
st: st,
curl: curl,
}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Charm",
"(",
"curl",
"*",
"charm",
".",
"URL",
")",
"(",
"*",
"Charm",
",",
"error",
")",
"{",
"if",
"curl",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",... | // Charm returns the charm with the given URL. | [
"Charm",
"returns",
"the",
"charm",
"with",
"the",
"given",
"URL",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L193-L201 |
155,777 | juju/juju | api/uniter/uniter.go | Relation | func (st *State) Relation(relationTag names.RelationTag) (*Relation, error) {
result, err := st.relation(relationTag, st.unitTag)
if err != nil {
return nil, err
}
return &Relation{
id: result.Id,
tag: relationTag,
life: result.Life,
suspended: result.Suspended,
st: st,
otherApp: result.OtherApplication,
}, nil
} | go | func (st *State) Relation(relationTag names.RelationTag) (*Relation, error) {
result, err := st.relation(relationTag, st.unitTag)
if err != nil {
return nil, err
}
return &Relation{
id: result.Id,
tag: relationTag,
life: result.Life,
suspended: result.Suspended,
st: st,
otherApp: result.OtherApplication,
}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Relation",
"(",
"relationTag",
"names",
".",
"RelationTag",
")",
"(",
"*",
"Relation",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"st",
".",
"relation",
"(",
"relationTag",
",",
"st",
".",
"unitTag",
")... | // Relation returns the existing relation with the given tag. | [
"Relation",
"returns",
"the",
"existing",
"relation",
"with",
"the",
"given",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L204-L217 |
155,778 | juju/juju | api/uniter/uniter.go | RelationById | func (st *State) RelationById(id int) (*Relation, error) {
var results params.RelationResults
args := params.RelationIds{
RelationIds: []int{id},
}
err := st.facade.FacadeCall("RelationById", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if err := result.Error; err != nil {
return nil, err
}
relationTag := names.NewRelationTag(result.Key)
return &Relation{
id: result.Id,
tag: relationTag,
life: result.Life,
suspended: result.Suspended,
st: st,
otherApp: result.OtherApplication,
}, nil
} | go | func (st *State) RelationById(id int) (*Relation, error) {
var results params.RelationResults
args := params.RelationIds{
RelationIds: []int{id},
}
err := st.facade.FacadeCall("RelationById", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if err := result.Error; err != nil {
return nil, err
}
relationTag := names.NewRelationTag(result.Key)
return &Relation{
id: result.Id,
tag: relationTag,
life: result.Life,
suspended: result.Suspended,
st: st,
otherApp: result.OtherApplication,
}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"RelationById",
"(",
"id",
"int",
")",
"(",
"*",
"Relation",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"RelationResults",
"\n",
"args",
":=",
"params",
".",
"RelationIds",
"{",
"RelationIds",
":",
"[... | // RelationById returns the existing relation with the given id. | [
"RelationById",
"returns",
"the",
"existing",
"relation",
"with",
"the",
"given",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L285-L310 |
155,779 | juju/juju | api/uniter/uniter.go | AllMachinePorts | func (st *State) AllMachinePorts(machineTag names.MachineTag) (map[corenetwork.PortRange]params.RelationUnit, error) {
if st.BestAPIVersion() < 1 {
// AllMachinePorts() was introduced in UniterAPIV1.
return nil, errors.NotImplementedf("AllMachinePorts() (need V1+)")
}
var results params.MachinePortsResults
args := params.Entities{
Entities: []params.Entity{{Tag: machineTag.String()}},
}
err := st.facade.FacadeCall("AllMachinePorts", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
portsMap := make(map[corenetwork.PortRange]params.RelationUnit)
for _, ports := range result.Ports {
portRange := ports.PortRange.NetworkPortRange()
portsMap[portRange] = params.RelationUnit{
Unit: ports.UnitTag,
Relation: ports.RelationTag,
}
}
return portsMap, nil
} | go | func (st *State) AllMachinePorts(machineTag names.MachineTag) (map[corenetwork.PortRange]params.RelationUnit, error) {
if st.BestAPIVersion() < 1 {
// AllMachinePorts() was introduced in UniterAPIV1.
return nil, errors.NotImplementedf("AllMachinePorts() (need V1+)")
}
var results params.MachinePortsResults
args := params.Entities{
Entities: []params.Entity{{Tag: machineTag.String()}},
}
err := st.facade.FacadeCall("AllMachinePorts", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
portsMap := make(map[corenetwork.PortRange]params.RelationUnit)
for _, ports := range result.Ports {
portRange := ports.PortRange.NetworkPortRange()
portsMap[portRange] = params.RelationUnit{
Unit: ports.UnitTag,
Relation: ports.RelationTag,
}
}
return portsMap, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AllMachinePorts",
"(",
"machineTag",
"names",
".",
"MachineTag",
")",
"(",
"map",
"[",
"corenetwork",
".",
"PortRange",
"]",
"params",
".",
"RelationUnit",
",",
"error",
")",
"{",
"if",
"st",
".",
"BestAPIVersion",
... | // AllMachinePorts returns all port ranges currently open on the given
// machine, mapped to the tags of the unit that opened them and the
// relation that applies. | [
"AllMachinePorts",
"returns",
"all",
"port",
"ranges",
"currently",
"open",
"on",
"the",
"given",
"machine",
"mapped",
"to",
"the",
"tags",
"of",
"the",
"unit",
"that",
"opened",
"them",
"and",
"the",
"relation",
"that",
"applies",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L336-L365 |
155,780 | juju/juju | api/uniter/uniter.go | WatchRelationUnits | func (st *State) WatchRelationUnits(
relationTag names.RelationTag,
unitTag names.UnitTag,
) (watcher.RelationUnitsWatcher, error) {
var results params.RelationUnitsWatchResults
args := params.RelationUnits{
RelationUnits: []params.RelationUnit{{
Relation: relationTag.String(),
Unit: unitTag.String(),
}},
}
err := st.facade.FacadeCall("WatchRelationUnits", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewRelationUnitsWatcher(st.facade.RawAPICaller(), result)
return w, nil
} | go | func (st *State) WatchRelationUnits(
relationTag names.RelationTag,
unitTag names.UnitTag,
) (watcher.RelationUnitsWatcher, error) {
var results params.RelationUnitsWatchResults
args := params.RelationUnits{
RelationUnits: []params.RelationUnit{{
Relation: relationTag.String(),
Unit: unitTag.String(),
}},
}
err := st.facade.FacadeCall("WatchRelationUnits", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewRelationUnitsWatcher(st.facade.RawAPICaller(), result)
return w, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"WatchRelationUnits",
"(",
"relationTag",
"names",
".",
"RelationTag",
",",
"unitTag",
"names",
".",
"UnitTag",
",",
")",
"(",
"watcher",
".",
"RelationUnitsWatcher",
",",
"error",
")",
"{",
"var",
"results",
"params",
... | // WatchRelationUnits returns a watcher that notifies of changes to the
// counterpart units in the relation for the given unit. | [
"WatchRelationUnits",
"returns",
"a",
"watcher",
"that",
"notifies",
"of",
"changes",
"to",
"the",
"counterpart",
"units",
"in",
"the",
"relation",
"for",
"the",
"given",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L369-L393 |
155,781 | juju/juju | api/uniter/uniter.go | ErrIfNotVersionFn | func ErrIfNotVersionFn(minVersion int, bestAPIVersion int) func(string) error {
return func(fnName string) error {
if minVersion <= bestAPIVersion {
return nil
}
return errors.NotImplementedf("%s(...) requires v%d+", fnName, minVersion)
}
} | go | func ErrIfNotVersionFn(minVersion int, bestAPIVersion int) func(string) error {
return func(fnName string) error {
if minVersion <= bestAPIVersion {
return nil
}
return errors.NotImplementedf("%s(...) requires v%d+", fnName, minVersion)
}
} | [
"func",
"ErrIfNotVersionFn",
"(",
"minVersion",
"int",
",",
"bestAPIVersion",
"int",
")",
"func",
"(",
"string",
")",
"error",
"{",
"return",
"func",
"(",
"fnName",
"string",
")",
"error",
"{",
"if",
"minVersion",
"<=",
"bestAPIVersion",
"{",
"return",
"nil"... | // ErrIfNotVersionFn returns a function which can be used to check for
// the minimum supported version, and, if appropriate, generate an
// error. | [
"ErrIfNotVersionFn",
"returns",
"a",
"function",
"which",
"can",
"be",
"used",
"to",
"check",
"for",
"the",
"minimum",
"supported",
"version",
"and",
"if",
"appropriate",
"generate",
"an",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L398-L405 |
155,782 | juju/juju | api/uniter/uniter.go | SLALevel | func (st *State) SLALevel() (string, error) {
if st.BestAPIVersion() < 5 {
return "unsupported", nil
}
var result params.StringResult
err := st.facade.FacadeCall("SLALevel", nil, &result)
if err != nil {
return "", errors.Trace(err)
}
if err := result.Error; err != nil {
return "", errors.Trace(err)
}
return result.Result, nil
} | go | func (st *State) SLALevel() (string, error) {
if st.BestAPIVersion() < 5 {
return "unsupported", nil
}
var result params.StringResult
err := st.facade.FacadeCall("SLALevel", nil, &result)
if err != nil {
return "", errors.Trace(err)
}
if err := result.Error; err != nil {
return "", errors.Trace(err)
}
return result.Result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SLALevel",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"st",
".",
"BestAPIVersion",
"(",
")",
"<",
"5",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"var",
"result",
"params",
".",
"S... | // SLALevel returns the SLA level set on the model. | [
"SLALevel",
"returns",
"the",
"SLA",
"level",
"set",
"on",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L408-L421 |
155,783 | juju/juju | api/uniter/uniter.go | GoalState | func (st *State) GoalState() (application.GoalState, error) {
var result params.GoalStateResults
gs := application.GoalState{}
args := params.Entities{
Entities: []params.Entity{
{Tag: st.unitTag.String()},
},
}
err := st.facade.FacadeCall("GoalStates", args, &result)
if err != nil {
return gs, err
}
if len(result.Results) != 1 {
return gs, errors.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return gs, err
}
gs = goalStateFromParams(result.Results[0].Result)
return gs, nil
} | go | func (st *State) GoalState() (application.GoalState, error) {
var result params.GoalStateResults
gs := application.GoalState{}
args := params.Entities{
Entities: []params.Entity{
{Tag: st.unitTag.String()},
},
}
err := st.facade.FacadeCall("GoalStates", args, &result)
if err != nil {
return gs, err
}
if len(result.Results) != 1 {
return gs, errors.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return gs, err
}
gs = goalStateFromParams(result.Results[0].Result)
return gs, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"GoalState",
"(",
")",
"(",
"application",
".",
"GoalState",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"GoalStateResults",
"\n\n",
"gs",
":=",
"application",
".",
"GoalState",
"{",
"}",
"\n\n",
"args",
... | // GoalState returns a GoalState struct with the charm's
// peers and related units information. | [
"GoalState",
"returns",
"a",
"GoalState",
"struct",
"with",
"the",
"charm",
"s",
"peers",
"and",
"related",
"units",
"information",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L441-L464 |
155,784 | juju/juju | api/uniter/uniter.go | CloudSpec | func (st *State) CloudSpec() (*params.CloudSpec, error) {
var result params.CloudSpecResult
err := st.facade.FacadeCall("CloudSpec", nil, &result)
if err != nil {
return nil, err
}
if err := result.Error; err != nil {
return nil, err
}
return result.Result, nil
} | go | func (st *State) CloudSpec() (*params.CloudSpec, error) {
var result params.CloudSpecResult
err := st.facade.FacadeCall("CloudSpec", nil, &result)
if err != nil {
return nil, err
}
if err := result.Error; err != nil {
return nil, err
}
return result.Result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"CloudSpec",
"(",
")",
"(",
"*",
"params",
".",
"CloudSpec",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"CloudSpecResult",
"\n\n",
"err",
":=",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\""... | // CloudSpec returns the cloud spec for the model that calling unit or
// application resides in.
// If the application has not been authorised to access its cloud spec,
// then an authorisation error will be returned. | [
"CloudSpec",
"returns",
"the",
"cloud",
"spec",
"for",
"the",
"model",
"that",
"calling",
"unit",
"or",
"application",
"resides",
"in",
".",
"If",
"the",
"application",
"has",
"not",
"been",
"authorised",
"to",
"access",
"its",
"cloud",
"spec",
"then",
"an",... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/uniter.go#L515-L526 |
155,785 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | createOffersAPI | func createOffersAPI(
getApplicationOffers func(interface{}) jujucrossmodel.ApplicationOffers,
getEnviron environFromModelFunc,
getControllerInfo func() ([]string, string, error),
backend Backend,
statePool StatePool,
authorizer facade.Authorizer,
resources facade.Resources,
authContext *commoncrossmodel.AuthContext,
callCtx context.ProviderCallContext,
) (*OffersAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
dataDir := resources.Get("dataDir").(common.StringResource)
api := &OffersAPI{
dataDir: dataDir.String(),
authContext: authContext,
BaseAPI: BaseAPI{
Authorizer: authorizer,
GetApplicationOffers: getApplicationOffers,
ControllerModel: backend,
StatePool: statePool,
getEnviron: getEnviron,
getControllerInfo: getControllerInfo,
callContext: callCtx,
},
}
return api, nil
} | go | func createOffersAPI(
getApplicationOffers func(interface{}) jujucrossmodel.ApplicationOffers,
getEnviron environFromModelFunc,
getControllerInfo func() ([]string, string, error),
backend Backend,
statePool StatePool,
authorizer facade.Authorizer,
resources facade.Resources,
authContext *commoncrossmodel.AuthContext,
callCtx context.ProviderCallContext,
) (*OffersAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
dataDir := resources.Get("dataDir").(common.StringResource)
api := &OffersAPI{
dataDir: dataDir.String(),
authContext: authContext,
BaseAPI: BaseAPI{
Authorizer: authorizer,
GetApplicationOffers: getApplicationOffers,
ControllerModel: backend,
StatePool: statePool,
getEnviron: getEnviron,
getControllerInfo: getControllerInfo,
callContext: callCtx,
},
}
return api, nil
} | [
"func",
"createOffersAPI",
"(",
"getApplicationOffers",
"func",
"(",
"interface",
"{",
"}",
")",
"jujucrossmodel",
".",
"ApplicationOffers",
",",
"getEnviron",
"environFromModelFunc",
",",
"getControllerInfo",
"func",
"(",
")",
"(",
"[",
"]",
"string",
",",
"strin... | // createAPI returns a new application offers OffersAPI facade. | [
"createAPI",
"returns",
"a",
"new",
"application",
"offers",
"OffersAPI",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L44-L74 |
155,786 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | Offer | func (api *OffersAPI) Offer(all params.AddApplicationOffers) (params.ErrorResults, error) {
result := make([]params.ErrorResult, len(all.Offers))
for i, one := range all.Offers {
modelTag, err := names.ParseModelTag(one.ModelTag)
if err != nil {
result[i].Error = common.ServerError(err)
continue
}
backend, releaser, err := api.StatePool.Get(modelTag.Id())
if err != nil {
result[i].Error = common.ServerError(err)
continue
}
defer releaser()
if err := api.checkAdmin(backend); err != nil {
result[i].Error = common.ServerError(err)
continue
}
applicationOfferParams, err := api.makeAddOfferArgsFromParams(backend, one)
if err != nil {
result[i].Error = common.ServerError(err)
continue
}
_, err = api.GetApplicationOffers(backend).AddOffer(applicationOfferParams)
result[i].Error = common.ServerError(err)
}
return params.ErrorResults{Results: result}, nil
} | go | func (api *OffersAPI) Offer(all params.AddApplicationOffers) (params.ErrorResults, error) {
result := make([]params.ErrorResult, len(all.Offers))
for i, one := range all.Offers {
modelTag, err := names.ParseModelTag(one.ModelTag)
if err != nil {
result[i].Error = common.ServerError(err)
continue
}
backend, releaser, err := api.StatePool.Get(modelTag.Id())
if err != nil {
result[i].Error = common.ServerError(err)
continue
}
defer releaser()
if err := api.checkAdmin(backend); err != nil {
result[i].Error = common.ServerError(err)
continue
}
applicationOfferParams, err := api.makeAddOfferArgsFromParams(backend, one)
if err != nil {
result[i].Error = common.ServerError(err)
continue
}
_, err = api.GetApplicationOffers(backend).AddOffer(applicationOfferParams)
result[i].Error = common.ServerError(err)
}
return params.ErrorResults{Results: result}, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"Offer",
"(",
"all",
"params",
".",
"AddApplicationOffers",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"("... | // Offer makes application endpoints available for consumption at a specified URL. | [
"Offer",
"makes",
"application",
"endpoints",
"available",
"for",
"consumption",
"at",
"a",
"specified",
"URL",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L126-L156 |
155,787 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | ListApplicationOffers | func (api *OffersAPI) ListApplicationOffers(filters params.OfferFilters) (params.QueryApplicationOffersResults, error) {
var result params.QueryApplicationOffersResults
offers, err := api.getApplicationOffersDetails(filters, permission.AdminAccess)
if err != nil {
return result, common.ServerError(err)
}
result.Results = offers
return result, nil
} | go | func (api *OffersAPI) ListApplicationOffers(filters params.OfferFilters) (params.QueryApplicationOffersResults, error) {
var result params.QueryApplicationOffersResults
offers, err := api.getApplicationOffersDetails(filters, permission.AdminAccess)
if err != nil {
return result, common.ServerError(err)
}
result.Results = offers
return result, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"ListApplicationOffers",
"(",
"filters",
"params",
".",
"OfferFilters",
")",
"(",
"params",
".",
"QueryApplicationOffersResults",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"QueryApplicationOffersResults",
"\... | // ListApplicationOffers gets deployed details about application offers that match given filter.
// The results contain details about the deployed applications such as connection count. | [
"ListApplicationOffers",
"gets",
"deployed",
"details",
"about",
"application",
"offers",
"that",
"match",
"given",
"filter",
".",
"The",
"results",
"contain",
"details",
"about",
"the",
"deployed",
"applications",
"such",
"as",
"connection",
"count",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L188-L196 |
155,788 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | ModifyOfferAccess | func (api *OffersAPI) ModifyOfferAccess(args params.ModifyOfferAccessRequest) (result params.ErrorResults, _ error) {
result = params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Changes)),
}
if len(args.Changes) == 0 {
return result, nil
}
isControllerAdmin, err := api.Authorizer.HasPermission(permission.SuperuserAccess, api.ControllerModel.ControllerTag())
if err != nil {
return result, errors.Trace(err)
}
offerURLs := make([]string, len(args.Changes))
for i, arg := range args.Changes {
offerURLs[i] = arg.OfferURL
}
models, err := api.getModelsFromOffers(offerURLs...)
if err != nil {
return result, errors.Trace(err)
}
for i, arg := range args.Changes {
if models[i].err != nil {
result.Results[i].Error = common.ServerError(models[i].err)
continue
}
err = api.modifyOneOfferAccess(models[i].model.UUID(), isControllerAdmin, arg)
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (api *OffersAPI) ModifyOfferAccess(args params.ModifyOfferAccessRequest) (result params.ErrorResults, _ error) {
result = params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Changes)),
}
if len(args.Changes) == 0 {
return result, nil
}
isControllerAdmin, err := api.Authorizer.HasPermission(permission.SuperuserAccess, api.ControllerModel.ControllerTag())
if err != nil {
return result, errors.Trace(err)
}
offerURLs := make([]string, len(args.Changes))
for i, arg := range args.Changes {
offerURLs[i] = arg.OfferURL
}
models, err := api.getModelsFromOffers(offerURLs...)
if err != nil {
return result, errors.Trace(err)
}
for i, arg := range args.Changes {
if models[i].err != nil {
result.Results[i].Error = common.ServerError(models[i].err)
continue
}
err = api.modifyOneOfferAccess(models[i].model.UUID(), isControllerAdmin, arg)
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"ModifyOfferAccess",
"(",
"args",
"params",
".",
"ModifyOfferAccessRequest",
")",
"(",
"result",
"params",
".",
"ErrorResults",
",",
"_",
"error",
")",
"{",
"result",
"=",
"params",
".",
"ErrorResults",
"{",
"Result... | // ModifyOfferAccess changes the application offer access granted to users. | [
"ModifyOfferAccess",
"changes",
"the",
"application",
"offer",
"access",
"granted",
"to",
"users",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L199-L230 |
155,789 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | changeOfferAccess | func (api *OffersAPI) changeOfferAccess(
backend Backend,
offerTag names.ApplicationOfferTag,
targetUserTag names.UserTag,
action params.OfferAction,
access permission.Access,
) error {
_, err := backend.ApplicationOffer(offerTag.Name)
if err != nil {
return errors.Trace(err)
}
switch action {
case params.GrantOfferAccess:
return api.grantOfferAccess(backend, offerTag, targetUserTag, access)
case params.RevokeOfferAccess:
return api.revokeOfferAccess(backend, offerTag, targetUserTag, access)
default:
return errors.Errorf("unknown action %q", action)
}
} | go | func (api *OffersAPI) changeOfferAccess(
backend Backend,
offerTag names.ApplicationOfferTag,
targetUserTag names.UserTag,
action params.OfferAction,
access permission.Access,
) error {
_, err := backend.ApplicationOffer(offerTag.Name)
if err != nil {
return errors.Trace(err)
}
switch action {
case params.GrantOfferAccess:
return api.grantOfferAccess(backend, offerTag, targetUserTag, access)
case params.RevokeOfferAccess:
return api.revokeOfferAccess(backend, offerTag, targetUserTag, access)
default:
return errors.Errorf("unknown action %q", action)
}
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"changeOfferAccess",
"(",
"backend",
"Backend",
",",
"offerTag",
"names",
".",
"ApplicationOfferTag",
",",
"targetUserTag",
"names",
".",
"UserTag",
",",
"action",
"params",
".",
"OfferAction",
",",
"access",
"permissio... | // changeOfferAccess performs the requested access grant or revoke action for the
// specified user on the specified application offer. | [
"changeOfferAccess",
"performs",
"the",
"requested",
"access",
"grant",
"or",
"revoke",
"action",
"for",
"the",
"specified",
"user",
"on",
"the",
"specified",
"application",
"offer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L283-L302 |
155,790 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | ApplicationOffers | func (api *OffersAPI) ApplicationOffers(urls params.OfferURLs) (params.ApplicationOffersResults, error) {
var results params.ApplicationOffersResults
results.Results = make([]params.ApplicationOfferResult, len(urls.OfferURLs))
var (
filters []params.OfferFilter
// fullURLs contains the URL strings from the url args,
// with any optional parts like model owner filled in.
// It is used to process the result offers.
fullURLs []string
)
for i, urlStr := range urls.OfferURLs {
url, err := jujucrossmodel.ParseOfferURL(urlStr)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
if url.User == "" {
url.User = api.Authorizer.GetAuthTag().Id()
}
if url.HasEndpoint() {
results.Results[i].Error = common.ServerError(
errors.Errorf("remote application %q shouldn't include endpoint", url))
continue
}
if url.Source != "" {
results.Results[i].Error = common.ServerError(
errors.NotSupportedf("query for non-local application offers"))
continue
}
fullURLs = append(fullURLs, url.String())
filters = append(filters, api.filterFromURL(url))
}
if len(filters) == 0 {
return results, nil
}
offers, err := api.getApplicationOffersDetails(params.OfferFilters{filters}, permission.ReadAccess)
if err != nil {
return results, common.ServerError(err)
}
offersByURL := make(map[string]params.ApplicationOfferAdminDetails)
for _, offer := range offers {
offersByURL[offer.OfferURL] = offer
}
for i, urlStr := range fullURLs {
offer, ok := offersByURL[urlStr]
if !ok {
err = errors.NotFoundf("application offer %q", urlStr)
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].Result = &offer
}
return results, nil
} | go | func (api *OffersAPI) ApplicationOffers(urls params.OfferURLs) (params.ApplicationOffersResults, error) {
var results params.ApplicationOffersResults
results.Results = make([]params.ApplicationOfferResult, len(urls.OfferURLs))
var (
filters []params.OfferFilter
// fullURLs contains the URL strings from the url args,
// with any optional parts like model owner filled in.
// It is used to process the result offers.
fullURLs []string
)
for i, urlStr := range urls.OfferURLs {
url, err := jujucrossmodel.ParseOfferURL(urlStr)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
if url.User == "" {
url.User = api.Authorizer.GetAuthTag().Id()
}
if url.HasEndpoint() {
results.Results[i].Error = common.ServerError(
errors.Errorf("remote application %q shouldn't include endpoint", url))
continue
}
if url.Source != "" {
results.Results[i].Error = common.ServerError(
errors.NotSupportedf("query for non-local application offers"))
continue
}
fullURLs = append(fullURLs, url.String())
filters = append(filters, api.filterFromURL(url))
}
if len(filters) == 0 {
return results, nil
}
offers, err := api.getApplicationOffersDetails(params.OfferFilters{filters}, permission.ReadAccess)
if err != nil {
return results, common.ServerError(err)
}
offersByURL := make(map[string]params.ApplicationOfferAdminDetails)
for _, offer := range offers {
offersByURL[offer.OfferURL] = offer
}
for i, urlStr := range fullURLs {
offer, ok := offersByURL[urlStr]
if !ok {
err = errors.NotFoundf("application offer %q", urlStr)
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].Result = &offer
}
return results, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"ApplicationOffers",
"(",
"urls",
"params",
".",
"OfferURLs",
")",
"(",
"params",
".",
"ApplicationOffersResults",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"ApplicationOffersResults",
"\n",
"results",
... | // ApplicationOffers gets details about remote applications that match given URLs. | [
"ApplicationOffers",
"gets",
"details",
"about",
"remote",
"applications",
"that",
"match",
"given",
"URLs",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L353-L408 |
155,791 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | FindApplicationOffers | func (api *OffersAPI) FindApplicationOffers(filters params.OfferFilters) (params.QueryApplicationOffersResults, error) {
var result params.QueryApplicationOffersResults
var filtersToUse params.OfferFilters
// If there is only one filter term, and no model is specified, add in
// any models the user can see and query across those.
// If there's more than one filter term, each must specify a model.
if len(filters.Filters) == 1 && filters.Filters[0].ModelName == "" {
uuids, err := api.ControllerModel.AllModelUUIDs()
if err != nil {
return result, errors.Trace(err)
}
for _, uuid := range uuids {
m, release, err := api.StatePool.GetModel(uuid)
if err != nil {
return result, errors.Trace(err)
}
defer release()
modelFilter := filters.Filters[0]
modelFilter.ModelName = m.Name()
modelFilter.OwnerName = m.Owner().Name()
filtersToUse.Filters = append(filtersToUse.Filters, modelFilter)
}
} else {
filtersToUse = filters
}
offers, err := api.getApplicationOffersDetails(filtersToUse, permission.ReadAccess)
if err != nil {
return result, common.ServerError(err)
}
result.Results = offers
return result, nil
} | go | func (api *OffersAPI) FindApplicationOffers(filters params.OfferFilters) (params.QueryApplicationOffersResults, error) {
var result params.QueryApplicationOffersResults
var filtersToUse params.OfferFilters
// If there is only one filter term, and no model is specified, add in
// any models the user can see and query across those.
// If there's more than one filter term, each must specify a model.
if len(filters.Filters) == 1 && filters.Filters[0].ModelName == "" {
uuids, err := api.ControllerModel.AllModelUUIDs()
if err != nil {
return result, errors.Trace(err)
}
for _, uuid := range uuids {
m, release, err := api.StatePool.GetModel(uuid)
if err != nil {
return result, errors.Trace(err)
}
defer release()
modelFilter := filters.Filters[0]
modelFilter.ModelName = m.Name()
modelFilter.OwnerName = m.Owner().Name()
filtersToUse.Filters = append(filtersToUse.Filters, modelFilter)
}
} else {
filtersToUse = filters
}
offers, err := api.getApplicationOffersDetails(filtersToUse, permission.ReadAccess)
if err != nil {
return result, common.ServerError(err)
}
result.Results = offers
return result, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"FindApplicationOffers",
"(",
"filters",
"params",
".",
"OfferFilters",
")",
"(",
"params",
".",
"QueryApplicationOffersResults",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"QueryApplicationOffersResults",
"\... | // FindApplicationOffers gets details about remote applications that match given filter. | [
"FindApplicationOffers",
"gets",
"details",
"about",
"remote",
"applications",
"that",
"match",
"given",
"filter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L411-L443 |
155,792 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | GetConsumeDetails | func (api *OffersAPI) GetConsumeDetails(args params.OfferURLs) (params.ConsumeOfferDetailsResults, error) {
var consumeResults params.ConsumeOfferDetailsResults
results := make([]params.ConsumeOfferDetailsResult, len(args.OfferURLs))
offers, err := api.ApplicationOffers(args)
if err != nil {
return consumeResults, common.ServerError(err)
}
addrs, caCert, err := api.getControllerInfo()
if err != nil {
return consumeResults, common.ServerError(err)
}
controllerInfo := ¶ms.ExternalControllerInfo{
ControllerTag: api.ControllerModel.ControllerTag().String(),
Addrs: addrs,
CACert: caCert,
}
for i, result := range offers.Results {
results[i].Error = result.Error
if result.Error != nil {
continue
}
offer := result.Result
offerDetails := &offer.ApplicationOfferDetails
results[i].Offer = offerDetails
results[i].ControllerInfo = controllerInfo
offerMacaroon, err := api.authContext.CreateConsumeOfferMacaroon(offerDetails, api.Authorizer.GetAuthTag().Id())
if err != nil {
results[i].Error = common.ServerError(err)
continue
}
results[i].Macaroon = offerMacaroon
}
consumeResults.Results = results
return consumeResults, nil
} | go | func (api *OffersAPI) GetConsumeDetails(args params.OfferURLs) (params.ConsumeOfferDetailsResults, error) {
var consumeResults params.ConsumeOfferDetailsResults
results := make([]params.ConsumeOfferDetailsResult, len(args.OfferURLs))
offers, err := api.ApplicationOffers(args)
if err != nil {
return consumeResults, common.ServerError(err)
}
addrs, caCert, err := api.getControllerInfo()
if err != nil {
return consumeResults, common.ServerError(err)
}
controllerInfo := ¶ms.ExternalControllerInfo{
ControllerTag: api.ControllerModel.ControllerTag().String(),
Addrs: addrs,
CACert: caCert,
}
for i, result := range offers.Results {
results[i].Error = result.Error
if result.Error != nil {
continue
}
offer := result.Result
offerDetails := &offer.ApplicationOfferDetails
results[i].Offer = offerDetails
results[i].ControllerInfo = controllerInfo
offerMacaroon, err := api.authContext.CreateConsumeOfferMacaroon(offerDetails, api.Authorizer.GetAuthTag().Id())
if err != nil {
results[i].Error = common.ServerError(err)
continue
}
results[i].Macaroon = offerMacaroon
}
consumeResults.Results = results
return consumeResults, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"GetConsumeDetails",
"(",
"args",
"params",
".",
"OfferURLs",
")",
"(",
"params",
".",
"ConsumeOfferDetailsResults",
",",
"error",
")",
"{",
"var",
"consumeResults",
"params",
".",
"ConsumeOfferDetailsResults",
"\n",
"r... | // GetConsumeDetails returns the details necessary to pass to another model to
// consume the specified offers represented by the urls. | [
"GetConsumeDetails",
"returns",
"the",
"details",
"necessary",
"to",
"pass",
"to",
"another",
"model",
"to",
"consume",
"the",
"specified",
"offers",
"represented",
"by",
"the",
"urls",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L447-L485 |
155,793 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | RemoteApplicationInfo | func (api *OffersAPI) RemoteApplicationInfo(args params.OfferURLs) (params.RemoteApplicationInfoResults, error) {
results := make([]params.RemoteApplicationInfoResult, len(args.OfferURLs))
for i, url := range args.OfferURLs {
info, err := api.oneRemoteApplicationInfo(url)
results[i].Result = info
results[i].Error = common.ServerError(err)
}
return params.RemoteApplicationInfoResults{results}, nil
} | go | func (api *OffersAPI) RemoteApplicationInfo(args params.OfferURLs) (params.RemoteApplicationInfoResults, error) {
results := make([]params.RemoteApplicationInfoResult, len(args.OfferURLs))
for i, url := range args.OfferURLs {
info, err := api.oneRemoteApplicationInfo(url)
results[i].Result = info
results[i].Error = common.ServerError(err)
}
return params.RemoteApplicationInfoResults{results}, nil
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"RemoteApplicationInfo",
"(",
"args",
"params",
".",
"OfferURLs",
")",
"(",
"params",
".",
"RemoteApplicationInfoResults",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"RemoteApplic... | // RemoteApplicationInfo returns information about the requested remote application. | [
"RemoteApplicationInfo",
"returns",
"information",
"about",
"the",
"requested",
"remote",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L488-L496 |
155,794 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | DestroyOffers | func (api *OffersAPI) DestroyOffers(args params.DestroyApplicationOffers) (params.ErrorResults, error) {
return destroyOffers(api, args.OfferURLs, false)
} | go | func (api *OffersAPI) DestroyOffers(args params.DestroyApplicationOffers) (params.ErrorResults, error) {
return destroyOffers(api, args.OfferURLs, false)
} | [
"func",
"(",
"api",
"*",
"OffersAPI",
")",
"DestroyOffers",
"(",
"args",
"params",
".",
"DestroyApplicationOffers",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"return",
"destroyOffers",
"(",
"api",
",",
"args",
".",
"OfferURLs",
",",
... | // DestroyOffers removes the offers specified by the given URLs. | [
"DestroyOffers",
"removes",
"the",
"offers",
"specified",
"by",
"the",
"given",
"URLs",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L543-L545 |
155,795 | juju/juju | apiserver/facades/client/applicationoffers/applicationoffers.go | DestroyOffers | func (api *OffersAPIV2) DestroyOffers(args params.DestroyApplicationOffers) (params.ErrorResults, error) {
return destroyOffers(api.OffersAPI, args.OfferURLs, args.Force)
} | go | func (api *OffersAPIV2) DestroyOffers(args params.DestroyApplicationOffers) (params.ErrorResults, error) {
return destroyOffers(api.OffersAPI, args.OfferURLs, args.Force)
} | [
"func",
"(",
"api",
"*",
"OffersAPIV2",
")",
"DestroyOffers",
"(",
"args",
"params",
".",
"DestroyApplicationOffers",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"return",
"destroyOffers",
"(",
"api",
".",
"OffersAPI",
",",
"args",
".",
... | // DestroyOffers removes the offers specified by the given URLs, forcing if necessary. | [
"DestroyOffers",
"removes",
"the",
"offers",
"specified",
"by",
"the",
"given",
"URLs",
"forcing",
"if",
"necessary",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/applicationoffers.go#L548-L550 |
155,796 | juju/juju | payload/status/list.go | NewListCommand | func NewListCommand(newAPIClient func(c *ListCommand) (ListAPI, error)) *ListCommand {
cmd := &ListCommand{
newAPIClient: newAPIClient,
}
return cmd
} | go | func NewListCommand(newAPIClient func(c *ListCommand) (ListAPI, error)) *ListCommand {
cmd := &ListCommand{
newAPIClient: newAPIClient,
}
return cmd
} | [
"func",
"NewListCommand",
"(",
"newAPIClient",
"func",
"(",
"c",
"*",
"ListCommand",
")",
"(",
"ListAPI",
",",
"error",
")",
")",
"*",
"ListCommand",
"{",
"cmd",
":=",
"&",
"ListCommand",
"{",
"newAPIClient",
":",
"newAPIClient",
",",
"}",
"\n",
"return",
... | // NewListCommand returns a new command that lists charm payloads
// in the current environment. | [
"NewListCommand",
"returns",
"a",
"new",
"command",
"that",
"lists",
"charm",
"payloads",
"in",
"the",
"current",
"environment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/payload/status/list.go#L36-L41 |
155,797 | juju/juju | apiserver/common/crossmodel/crossmodel.go | WatchRelationUnits | func WatchRelationUnits(backend Backend, tag names.RelationTag) (state.RelationUnitsWatcher, error) {
relation, err := backend.KeyRelation(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
for _, ep := range relation.Endpoints() {
_, err := backend.Application(ep.ApplicationName)
if errors.IsNotFound(err) {
// Not found, so it's the remote application. Try the next endpoint.
continue
} else if err != nil {
return nil, errors.Trace(err)
}
w, err := relation.WatchUnits(ep.ApplicationName)
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
return nil, errors.NotFoundf("local application for %s", names.ReadableString(tag))
} | go | func WatchRelationUnits(backend Backend, tag names.RelationTag) (state.RelationUnitsWatcher, error) {
relation, err := backend.KeyRelation(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
for _, ep := range relation.Endpoints() {
_, err := backend.Application(ep.ApplicationName)
if errors.IsNotFound(err) {
// Not found, so it's the remote application. Try the next endpoint.
continue
} else if err != nil {
return nil, errors.Trace(err)
}
w, err := relation.WatchUnits(ep.ApplicationName)
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
return nil, errors.NotFoundf("local application for %s", names.ReadableString(tag))
} | [
"func",
"WatchRelationUnits",
"(",
"backend",
"Backend",
",",
"tag",
"names",
".",
"RelationTag",
")",
"(",
"state",
".",
"RelationUnitsWatcher",
",",
"error",
")",
"{",
"relation",
",",
"err",
":=",
"backend",
".",
"KeyRelation",
"(",
"tag",
".",
"Id",
"(... | // WatchRelationUnits returns a watcher for changes to the units on the specified relation. | [
"WatchRelationUnits",
"returns",
"a",
"watcher",
"for",
"changes",
"to",
"the",
"units",
"on",
"the",
"specified",
"relation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/crossmodel/crossmodel.go#L166-L186 |
155,798 | juju/juju | apiserver/common/crossmodel/crossmodel.go | RelationUnitSettings | func RelationUnitSettings(backend Backend, ru params.RelationUnit) (params.Settings, error) {
relationTag, err := names.ParseRelationTag(ru.Relation)
if err != nil {
return nil, errors.Trace(err)
}
rel, err := backend.KeyRelation(relationTag.Id())
if err != nil {
return nil, errors.Trace(err)
}
unitTag, err := names.ParseUnitTag(ru.Unit)
if err != nil {
return nil, errors.Trace(err)
}
unit, err := rel.Unit(unitTag.Id())
if err != nil {
return nil, errors.Trace(err)
}
settings, err := unit.Settings()
if err != nil {
return nil, errors.Trace(err)
}
paramsSettings := make(params.Settings)
for k, v := range settings {
vString, ok := v.(string)
if !ok {
return nil, errors.Errorf(
"invalid relation setting %q: expected string, got %T", k, v,
)
}
paramsSettings[k] = vString
}
return paramsSettings, nil
} | go | func RelationUnitSettings(backend Backend, ru params.RelationUnit) (params.Settings, error) {
relationTag, err := names.ParseRelationTag(ru.Relation)
if err != nil {
return nil, errors.Trace(err)
}
rel, err := backend.KeyRelation(relationTag.Id())
if err != nil {
return nil, errors.Trace(err)
}
unitTag, err := names.ParseUnitTag(ru.Unit)
if err != nil {
return nil, errors.Trace(err)
}
unit, err := rel.Unit(unitTag.Id())
if err != nil {
return nil, errors.Trace(err)
}
settings, err := unit.Settings()
if err != nil {
return nil, errors.Trace(err)
}
paramsSettings := make(params.Settings)
for k, v := range settings {
vString, ok := v.(string)
if !ok {
return nil, errors.Errorf(
"invalid relation setting %q: expected string, got %T", k, v,
)
}
paramsSettings[k] = vString
}
return paramsSettings, nil
} | [
"func",
"RelationUnitSettings",
"(",
"backend",
"Backend",
",",
"ru",
"params",
".",
"RelationUnit",
")",
"(",
"params",
".",
"Settings",
",",
"error",
")",
"{",
"relationTag",
",",
"err",
":=",
"names",
".",
"ParseRelationTag",
"(",
"ru",
".",
"Relation",
... | // RelationUnitSettings returns the unit settings for the specified relation unit. | [
"RelationUnitSettings",
"returns",
"the",
"unit",
"settings",
"for",
"the",
"specified",
"relation",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/crossmodel/crossmodel.go#L189-L221 |
155,799 | juju/juju | apiserver/common/crossmodel/crossmodel.go | PublishIngressNetworkChange | func PublishIngressNetworkChange(backend Backend, relationTag names.Tag, change params.IngressNetworksChangeEvent) error {
logger.Debugf("publish into model %v network change for %v: %+v", backend.ModelUUID(), relationTag, change)
// Ensure the relation exists.
rel, err := backend.KeyRelation(relationTag.Id())
if errors.IsNotFound(err) {
return nil
}
if err != nil {
return errors.Trace(err)
}
logger.Debugf("relation %v requires ingress networks %v", rel, change.Networks)
if err := validateIngressNetworks(backend, change.Networks); err != nil {
return errors.Trace(err)
}
_, err = backend.SaveIngressNetworks(rel.Tag().Id(), change.Networks)
return err
} | go | func PublishIngressNetworkChange(backend Backend, relationTag names.Tag, change params.IngressNetworksChangeEvent) error {
logger.Debugf("publish into model %v network change for %v: %+v", backend.ModelUUID(), relationTag, change)
// Ensure the relation exists.
rel, err := backend.KeyRelation(relationTag.Id())
if errors.IsNotFound(err) {
return nil
}
if err != nil {
return errors.Trace(err)
}
logger.Debugf("relation %v requires ingress networks %v", rel, change.Networks)
if err := validateIngressNetworks(backend, change.Networks); err != nil {
return errors.Trace(err)
}
_, err = backend.SaveIngressNetworks(rel.Tag().Id(), change.Networks)
return err
} | [
"func",
"PublishIngressNetworkChange",
"(",
"backend",
"Backend",
",",
"relationTag",
"names",
".",
"Tag",
",",
"change",
"params",
".",
"IngressNetworksChangeEvent",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"backend",
".",
"ModelUUID",
... | // PublishIngressNetworkChange saves the specified ingress networks for a relation. | [
"PublishIngressNetworkChange",
"saves",
"the",
"specified",
"ingress",
"networks",
"for",
"a",
"relation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/crossmodel/crossmodel.go#L224-L243 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.