id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,500 | juju/juju | provider/ec2/environ.go | isSubnetConstrainedError | func isSubnetConstrainedError(err error) bool {
switch err := errors.Cause(err).(type) {
case *ec2.Error:
switch err.Code {
case "InsufficientFreeAddressesInSubnet", "InsufficientInstanceCapacity":
// Subnet and/or VPC general limits reached.
return true
case "InvalidSubnetID.NotFound":
// This shouldn't happen, as we validate the subnet IDs, but it can
// happen if the user manually deleted the subnet outside of Juju.
return true
}
}
return false
} | go | func isSubnetConstrainedError(err error) bool {
switch err := errors.Cause(err).(type) {
case *ec2.Error:
switch err.Code {
case "InsufficientFreeAddressesInSubnet", "InsufficientInstanceCapacity":
// Subnet and/or VPC general limits reached.
return true
case "InvalidSubnetID.NotFound":
// This shouldn't happen, as we validate the subnet IDs, but it can
// happen if the user manually deleted the subnet outside of Juju.
return true
}
}
return false
} | [
"func",
"isSubnetConstrainedError",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ec2",
".",
"Error",
":",
"switch",
"err",
".",
"Code",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"// Subnet and/or VPC general limits reached.",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"// This shouldn't happen, as we validate the subnet IDs, but it can",
"// happen if the user manually deleted the subnet outside of Juju.",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isSubnetConstrainedError reports whether or not the error indicates
// RunInstances failed due to the specified VPC subnet ID being constrained for
// the instance type being provisioned, or is otherwise unusable for the
// specific request made. | [
"isSubnetConstrainedError",
"reports",
"whether",
"or",
"not",
"the",
"error",
"indicates",
"RunInstances",
"failed",
"due",
"to",
"the",
"specified",
"VPC",
"subnet",
"ID",
"being",
"constrained",
"for",
"the",
"instance",
"type",
"being",
"provisioned",
"or",
"is",
"otherwise",
"unusable",
"for",
"the",
"specific",
"request",
"made",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/ec2/environ.go#L1968-L1982 |
4,501 | juju/juju | provider/ec2/environ.go | SuperSubnets | func (e *environ) SuperSubnets(ctx context.ProviderCallContext) ([]string, error) {
vpcId := e.ecfg().vpcID()
if !isVPCIDSet(vpcId) {
if hasDefaultVPC, err := e.hasDefaultVPC(ctx); err == nil && hasDefaultVPC {
vpcId = e.defaultVPC.Id
}
}
if !isVPCIDSet(vpcId) {
return nil, errors.NotSupportedf("Not a VPC environment")
}
cidr, err := getVPCCIDR(e.ec2, ctx, vpcId)
if err != nil {
return nil, err
}
return []string{cidr}, nil
} | go | func (e *environ) SuperSubnets(ctx context.ProviderCallContext) ([]string, error) {
vpcId := e.ecfg().vpcID()
if !isVPCIDSet(vpcId) {
if hasDefaultVPC, err := e.hasDefaultVPC(ctx); err == nil && hasDefaultVPC {
vpcId = e.defaultVPC.Id
}
}
if !isVPCIDSet(vpcId) {
return nil, errors.NotSupportedf("Not a VPC environment")
}
cidr, err := getVPCCIDR(e.ec2, ctx, vpcId)
if err != nil {
return nil, err
}
return []string{cidr}, nil
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"SuperSubnets",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"vpcId",
":=",
"e",
".",
"ecfg",
"(",
")",
".",
"vpcID",
"(",
")",
"\n",
"if",
"!",
"isVPCIDSet",
"(",
"vpcId",
")",
"{",
"if",
"hasDefaultVPC",
",",
"err",
":=",
"e",
".",
"hasDefaultVPC",
"(",
"ctx",
")",
";",
"err",
"==",
"nil",
"&&",
"hasDefaultVPC",
"{",
"vpcId",
"=",
"e",
".",
"defaultVPC",
".",
"Id",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"isVPCIDSet",
"(",
"vpcId",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cidr",
",",
"err",
":=",
"getVPCCIDR",
"(",
"e",
".",
"ec2",
",",
"ctx",
",",
"vpcId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"[",
"]",
"string",
"{",
"cidr",
"}",
",",
"nil",
"\n",
"}"
] | // SuperSubnets implements NetworkingEnviron.SuperSubnets | [
"SuperSubnets",
"implements",
"NetworkingEnviron",
".",
"SuperSubnets"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/ec2/environ.go#L2062-L2077 |
4,502 | juju/juju | api/annotations/client.go | Get | func (c *Client) Get(tags []string) ([]params.AnnotationsGetResult, error) {
annotations := params.AnnotationsGetResults{}
if err := c.facade.FacadeCall("Get", entitiesFromTags(tags), &annotations); err != nil {
return annotations.Results, errors.Trace(err)
}
return annotations.Results, nil
} | go | func (c *Client) Get(tags []string) ([]params.AnnotationsGetResult, error) {
annotations := params.AnnotationsGetResults{}
if err := c.facade.FacadeCall("Get", entitiesFromTags(tags), &annotations); err != nil {
return annotations.Results, errors.Trace(err)
}
return annotations.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Get",
"(",
"tags",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"AnnotationsGetResult",
",",
"error",
")",
"{",
"annotations",
":=",
"params",
".",
"AnnotationsGetResults",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"entitiesFromTags",
"(",
"tags",
")",
",",
"&",
"annotations",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"annotations",
".",
"Results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"annotations",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // Get returns annotations that have been set on the given entities. | [
"Get",
"returns",
"annotations",
"that",
"have",
"been",
"set",
"on",
"the",
"given",
"entities",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/annotations/client.go#L26-L32 |
4,503 | juju/juju | api/annotations/client.go | Set | func (c *Client) Set(annotations map[string]map[string]string) ([]params.ErrorResult, error) {
args := params.AnnotationsSet{entitiesAnnotations(annotations)}
results := new(params.ErrorResults)
if err := c.facade.FacadeCall("Set", args, results); err != nil {
return nil, errors.Trace(err)
}
return results.Results, nil
} | go | func (c *Client) Set(annotations map[string]map[string]string) ([]params.ErrorResult, error) {
args := params.AnnotationsSet{entitiesAnnotations(annotations)}
results := new(params.ErrorResults)
if err := c.facade.FacadeCall("Set", args, results); err != nil {
return nil, errors.Trace(err)
}
return results.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Set",
"(",
"annotations",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"error",
")",
"{",
"args",
":=",
"params",
".",
"AnnotationsSet",
"{",
"entitiesAnnotations",
"(",
"annotations",
")",
"}",
"\n",
"results",
":=",
"new",
"(",
"params",
".",
"ErrorResults",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // Set sets entity annotation pairs. | [
"Set",
"sets",
"entity",
"annotation",
"pairs",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/annotations/client.go#L35-L42 |
4,504 | juju/juju | cmd/juju/storage/filesystemlistformatters.go | formatFilesystemListTabular | func formatFilesystemListTabular(writer io.Writer, infos map[string]FilesystemInfo) error {
tw := output.TabWriter(writer)
print := func(values ...string) {
fmt.Fprintln(tw, strings.Join(values, "\t"))
}
haveMachines := false
filesystemAttachmentInfos := make(filesystemAttachmentInfos, 0, len(infos))
for filesystemId, info := range infos {
filesystemAttachmentInfo := filesystemAttachmentInfo{
FilesystemId: filesystemId,
FilesystemInfo: info,
}
if info.Attachments == nil {
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
continue
}
// Each unit attachment must have a corresponding filesystem
// attachment. Enumerate each of the filesystem attachments,
// and locate the corresponding unit attachment if any.
// Each filesystem attachment has at most one corresponding
// unit attachment.
for machineId, machineInfo := range info.Attachments.Machines {
filesystemAttachmentInfo := filesystemAttachmentInfo
filesystemAttachmentInfo.MachineId = machineId
filesystemAttachmentInfo.FilesystemAttachment = machineInfo
for unitId, unitInfo := range info.Attachments.Units {
if unitInfo.MachineId == machineId {
filesystemAttachmentInfo.UnitId = unitId
filesystemAttachmentInfo.UnitStorageAttachment = unitInfo
break
}
}
haveMachines = true
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
}
for hostId, containerInfo := range info.Attachments.Containers {
filesystemAttachmentInfo := filesystemAttachmentInfo
filesystemAttachmentInfo.FilesystemAttachment = containerInfo
for unitId, unitInfo := range info.Attachments.Units {
if hostId == unitId {
filesystemAttachmentInfo.UnitId = unitId
filesystemAttachmentInfo.UnitStorageAttachment = unitInfo
break
}
}
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
}
}
sort.Sort(filesystemAttachmentInfos)
if haveMachines {
print("Machine", "Unit", "Storage id", "Id", "Volume", "Provider id", "Mountpoint", "Size", "State", "Message")
} else {
print("Unit", "Storage id", "Id", "Provider id", "Mountpoint", "Size", "State", "Message")
}
for _, info := range filesystemAttachmentInfos {
var size string
if info.Size > 0 {
size = humanize.IBytes(info.Size * humanize.MiByte)
}
if haveMachines {
print(
info.MachineId, info.UnitId, info.Storage,
info.FilesystemId, info.Volume, info.ProviderFilesystemId,
info.MountPoint, size,
string(info.Status.Current), info.Status.Message,
)
} else {
print(
info.UnitId, info.Storage,
info.FilesystemId, info.ProviderFilesystemId,
info.MountPoint, size,
string(info.Status.Current), info.Status.Message,
)
}
}
return tw.Flush()
} | go | func formatFilesystemListTabular(writer io.Writer, infos map[string]FilesystemInfo) error {
tw := output.TabWriter(writer)
print := func(values ...string) {
fmt.Fprintln(tw, strings.Join(values, "\t"))
}
haveMachines := false
filesystemAttachmentInfos := make(filesystemAttachmentInfos, 0, len(infos))
for filesystemId, info := range infos {
filesystemAttachmentInfo := filesystemAttachmentInfo{
FilesystemId: filesystemId,
FilesystemInfo: info,
}
if info.Attachments == nil {
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
continue
}
// Each unit attachment must have a corresponding filesystem
// attachment. Enumerate each of the filesystem attachments,
// and locate the corresponding unit attachment if any.
// Each filesystem attachment has at most one corresponding
// unit attachment.
for machineId, machineInfo := range info.Attachments.Machines {
filesystemAttachmentInfo := filesystemAttachmentInfo
filesystemAttachmentInfo.MachineId = machineId
filesystemAttachmentInfo.FilesystemAttachment = machineInfo
for unitId, unitInfo := range info.Attachments.Units {
if unitInfo.MachineId == machineId {
filesystemAttachmentInfo.UnitId = unitId
filesystemAttachmentInfo.UnitStorageAttachment = unitInfo
break
}
}
haveMachines = true
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
}
for hostId, containerInfo := range info.Attachments.Containers {
filesystemAttachmentInfo := filesystemAttachmentInfo
filesystemAttachmentInfo.FilesystemAttachment = containerInfo
for unitId, unitInfo := range info.Attachments.Units {
if hostId == unitId {
filesystemAttachmentInfo.UnitId = unitId
filesystemAttachmentInfo.UnitStorageAttachment = unitInfo
break
}
}
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
}
}
sort.Sort(filesystemAttachmentInfos)
if haveMachines {
print("Machine", "Unit", "Storage id", "Id", "Volume", "Provider id", "Mountpoint", "Size", "State", "Message")
} else {
print("Unit", "Storage id", "Id", "Provider id", "Mountpoint", "Size", "State", "Message")
}
for _, info := range filesystemAttachmentInfos {
var size string
if info.Size > 0 {
size = humanize.IBytes(info.Size * humanize.MiByte)
}
if haveMachines {
print(
info.MachineId, info.UnitId, info.Storage,
info.FilesystemId, info.Volume, info.ProviderFilesystemId,
info.MountPoint, size,
string(info.Status.Current), info.Status.Message,
)
} else {
print(
info.UnitId, info.Storage,
info.FilesystemId, info.ProviderFilesystemId,
info.MountPoint, size,
string(info.Status.Current), info.Status.Message,
)
}
}
return tw.Flush()
} | [
"func",
"formatFilesystemListTabular",
"(",
"writer",
"io",
".",
"Writer",
",",
"infos",
"map",
"[",
"string",
"]",
"FilesystemInfo",
")",
"error",
"{",
"tw",
":=",
"output",
".",
"TabWriter",
"(",
"writer",
")",
"\n\n",
"print",
":=",
"func",
"(",
"values",
"...",
"string",
")",
"{",
"fmt",
".",
"Fprintln",
"(",
"tw",
",",
"strings",
".",
"Join",
"(",
"values",
",",
"\"",
"\\t",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"haveMachines",
":=",
"false",
"\n",
"filesystemAttachmentInfos",
":=",
"make",
"(",
"filesystemAttachmentInfos",
",",
"0",
",",
"len",
"(",
"infos",
")",
")",
"\n",
"for",
"filesystemId",
",",
"info",
":=",
"range",
"infos",
"{",
"filesystemAttachmentInfo",
":=",
"filesystemAttachmentInfo",
"{",
"FilesystemId",
":",
"filesystemId",
",",
"FilesystemInfo",
":",
"info",
",",
"}",
"\n",
"if",
"info",
".",
"Attachments",
"==",
"nil",
"{",
"filesystemAttachmentInfos",
"=",
"append",
"(",
"filesystemAttachmentInfos",
",",
"filesystemAttachmentInfo",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"// Each unit attachment must have a corresponding filesystem",
"// attachment. Enumerate each of the filesystem attachments,",
"// and locate the corresponding unit attachment if any.",
"// Each filesystem attachment has at most one corresponding",
"// unit attachment.",
"for",
"machineId",
",",
"machineInfo",
":=",
"range",
"info",
".",
"Attachments",
".",
"Machines",
"{",
"filesystemAttachmentInfo",
":=",
"filesystemAttachmentInfo",
"\n",
"filesystemAttachmentInfo",
".",
"MachineId",
"=",
"machineId",
"\n",
"filesystemAttachmentInfo",
".",
"FilesystemAttachment",
"=",
"machineInfo",
"\n",
"for",
"unitId",
",",
"unitInfo",
":=",
"range",
"info",
".",
"Attachments",
".",
"Units",
"{",
"if",
"unitInfo",
".",
"MachineId",
"==",
"machineId",
"{",
"filesystemAttachmentInfo",
".",
"UnitId",
"=",
"unitId",
"\n",
"filesystemAttachmentInfo",
".",
"UnitStorageAttachment",
"=",
"unitInfo",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"haveMachines",
"=",
"true",
"\n",
"filesystemAttachmentInfos",
"=",
"append",
"(",
"filesystemAttachmentInfos",
",",
"filesystemAttachmentInfo",
")",
"\n",
"}",
"\n\n",
"for",
"hostId",
",",
"containerInfo",
":=",
"range",
"info",
".",
"Attachments",
".",
"Containers",
"{",
"filesystemAttachmentInfo",
":=",
"filesystemAttachmentInfo",
"\n",
"filesystemAttachmentInfo",
".",
"FilesystemAttachment",
"=",
"containerInfo",
"\n",
"for",
"unitId",
",",
"unitInfo",
":=",
"range",
"info",
".",
"Attachments",
".",
"Units",
"{",
"if",
"hostId",
"==",
"unitId",
"{",
"filesystemAttachmentInfo",
".",
"UnitId",
"=",
"unitId",
"\n",
"filesystemAttachmentInfo",
".",
"UnitStorageAttachment",
"=",
"unitInfo",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"filesystemAttachmentInfos",
"=",
"append",
"(",
"filesystemAttachmentInfos",
",",
"filesystemAttachmentInfo",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"filesystemAttachmentInfos",
")",
"\n\n",
"if",
"haveMachines",
"{",
"print",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"print",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"info",
":=",
"range",
"filesystemAttachmentInfos",
"{",
"var",
"size",
"string",
"\n",
"if",
"info",
".",
"Size",
">",
"0",
"{",
"size",
"=",
"humanize",
".",
"IBytes",
"(",
"info",
".",
"Size",
"*",
"humanize",
".",
"MiByte",
")",
"\n",
"}",
"\n",
"if",
"haveMachines",
"{",
"print",
"(",
"info",
".",
"MachineId",
",",
"info",
".",
"UnitId",
",",
"info",
".",
"Storage",
",",
"info",
".",
"FilesystemId",
",",
"info",
".",
"Volume",
",",
"info",
".",
"ProviderFilesystemId",
",",
"info",
".",
"MountPoint",
",",
"size",
",",
"string",
"(",
"info",
".",
"Status",
".",
"Current",
")",
",",
"info",
".",
"Status",
".",
"Message",
",",
")",
"\n",
"}",
"else",
"{",
"print",
"(",
"info",
".",
"UnitId",
",",
"info",
".",
"Storage",
",",
"info",
".",
"FilesystemId",
",",
"info",
".",
"ProviderFilesystemId",
",",
"info",
".",
"MountPoint",
",",
"size",
",",
"string",
"(",
"info",
".",
"Status",
".",
"Current",
")",
",",
"info",
".",
"Status",
".",
"Message",
",",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"tw",
".",
"Flush",
"(",
")",
"\n",
"}"
] | // formatFilesystemListTabular writes a tabular summary of filesystem instances. | [
"formatFilesystemListTabular",
"writes",
"a",
"tabular",
"summary",
"of",
"filesystem",
"instances",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/filesystemlistformatters.go#L18-L100 |
4,505 | juju/juju | upgrades/upgrade.go | PerformUpgrade | func PerformUpgrade(from version.Number, targets []Target, context Context) error {
if hasStateTarget(targets) {
ops := newStateUpgradeOpsIterator(from)
if err := runUpgradeSteps(ops, targets, context.StateContext()); err != nil {
return err
}
}
ops := newUpgradeOpsIterator(from)
if err := runUpgradeSteps(ops, targets, context.APIContext()); err != nil {
return err
}
logger.Infof("All upgrade steps completed successfully")
return nil
} | go | func PerformUpgrade(from version.Number, targets []Target, context Context) error {
if hasStateTarget(targets) {
ops := newStateUpgradeOpsIterator(from)
if err := runUpgradeSteps(ops, targets, context.StateContext()); err != nil {
return err
}
}
ops := newUpgradeOpsIterator(from)
if err := runUpgradeSteps(ops, targets, context.APIContext()); err != nil {
return err
}
logger.Infof("All upgrade steps completed successfully")
return nil
} | [
"func",
"PerformUpgrade",
"(",
"from",
"version",
".",
"Number",
",",
"targets",
"[",
"]",
"Target",
",",
"context",
"Context",
")",
"error",
"{",
"if",
"hasStateTarget",
"(",
"targets",
")",
"{",
"ops",
":=",
"newStateUpgradeOpsIterator",
"(",
"from",
")",
"\n",
"if",
"err",
":=",
"runUpgradeSteps",
"(",
"ops",
",",
"targets",
",",
"context",
".",
"StateContext",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"ops",
":=",
"newUpgradeOpsIterator",
"(",
"from",
")",
"\n",
"if",
"err",
":=",
"runUpgradeSteps",
"(",
"ops",
",",
"targets",
",",
"context",
".",
"APIContext",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // PerformUpgrade runs the business logic needed to upgrade the current "from" version to this
// version of Juju on the "target" type of machine. | [
"PerformUpgrade",
"runs",
"the",
"business",
"logic",
"needed",
"to",
"upgrade",
"the",
"current",
"from",
"version",
"to",
"this",
"version",
"of",
"Juju",
"on",
"the",
"target",
"type",
"of",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/upgrade.go#L94-L107 |
4,506 | juju/juju | upgrades/upgrade.go | runUpgradeSteps | func runUpgradeSteps(ops *opsIterator, targets []Target, context Context) error {
for ops.Next() {
for _, step := range ops.Get().Steps() {
if targetsMatch(targets, step.Targets()) {
logger.Infof("running upgrade step: %v", step.Description())
if err := step.Run(context); err != nil {
logger.Errorf("upgrade step %q failed: %v", step.Description(), err)
return &upgradeError{
description: step.Description(),
err: err,
}
}
}
}
}
return nil
} | go | func runUpgradeSteps(ops *opsIterator, targets []Target, context Context) error {
for ops.Next() {
for _, step := range ops.Get().Steps() {
if targetsMatch(targets, step.Targets()) {
logger.Infof("running upgrade step: %v", step.Description())
if err := step.Run(context); err != nil {
logger.Errorf("upgrade step %q failed: %v", step.Description(), err)
return &upgradeError{
description: step.Description(),
err: err,
}
}
}
}
}
return nil
} | [
"func",
"runUpgradeSteps",
"(",
"ops",
"*",
"opsIterator",
",",
"targets",
"[",
"]",
"Target",
",",
"context",
"Context",
")",
"error",
"{",
"for",
"ops",
".",
"Next",
"(",
")",
"{",
"for",
"_",
",",
"step",
":=",
"range",
"ops",
".",
"Get",
"(",
")",
".",
"Steps",
"(",
")",
"{",
"if",
"targetsMatch",
"(",
"targets",
",",
"step",
".",
"Targets",
"(",
")",
")",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"step",
".",
"Description",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"step",
".",
"Run",
"(",
"context",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"step",
".",
"Description",
"(",
")",
",",
"err",
")",
"\n",
"return",
"&",
"upgradeError",
"{",
"description",
":",
"step",
".",
"Description",
"(",
")",
",",
"err",
":",
"err",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // runUpgradeSteps finds all the upgrade operations relevant to
// the targets given and runs the associated upgrade steps.
//
// As soon as any error is encountered, the operation is aborted since
// subsequent steps may required successful completion of earlier
// ones. The steps must be idempotent so that the entire upgrade
// operation can be retried. | [
"runUpgradeSteps",
"finds",
"all",
"the",
"upgrade",
"operations",
"relevant",
"to",
"the",
"targets",
"given",
"and",
"runs",
"the",
"associated",
"upgrade",
"steps",
".",
"As",
"soon",
"as",
"any",
"error",
"is",
"encountered",
"the",
"operation",
"is",
"aborted",
"since",
"subsequent",
"steps",
"may",
"required",
"successful",
"completion",
"of",
"earlier",
"ones",
".",
"The",
"steps",
"must",
"be",
"idempotent",
"so",
"that",
"the",
"entire",
"upgrade",
"operation",
"can",
"be",
"retried",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/upgrade.go#L134-L150 |
4,507 | juju/juju | upgrades/upgrade.go | targetsMatch | func targetsMatch(machineTargets []Target, stepTargets []Target) bool {
for _, machineTarget := range machineTargets {
for _, stepTarget := range stepTargets {
if machineTarget == stepTarget || stepTarget == AllMachines {
return true
}
}
}
return false
} | go | func targetsMatch(machineTargets []Target, stepTargets []Target) bool {
for _, machineTarget := range machineTargets {
for _, stepTarget := range stepTargets {
if machineTarget == stepTarget || stepTarget == AllMachines {
return true
}
}
}
return false
} | [
"func",
"targetsMatch",
"(",
"machineTargets",
"[",
"]",
"Target",
",",
"stepTargets",
"[",
"]",
"Target",
")",
"bool",
"{",
"for",
"_",
",",
"machineTarget",
":=",
"range",
"machineTargets",
"{",
"for",
"_",
",",
"stepTarget",
":=",
"range",
"stepTargets",
"{",
"if",
"machineTarget",
"==",
"stepTarget",
"||",
"stepTarget",
"==",
"AllMachines",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // targetsMatch returns true if any machineTargets match any of
// stepTargets. | [
"targetsMatch",
"returns",
"true",
"if",
"any",
"machineTargets",
"match",
"any",
"of",
"stepTargets",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/upgrade.go#L154-L163 |
4,508 | juju/juju | apiserver/apiserver.go | NewServer | func NewServer(cfg ServerConfig) (*Server, error) {
if cfg.LogSinkConfig == nil {
logSinkConfig := DefaultLogSinkConfig()
cfg.LogSinkConfig = &logSinkConfig
}
if err := cfg.Validate(); err != nil {
return nil, errors.Trace(err)
}
// Important note:
// Do not manipulate the state within NewServer as the API
// server needs to run before mongo upgrades have happened and
// any state manipulation may be be relying on features of the
// database added by upgrades. Here be dragons.
return newServer(cfg)
} | go | func NewServer(cfg ServerConfig) (*Server, error) {
if cfg.LogSinkConfig == nil {
logSinkConfig := DefaultLogSinkConfig()
cfg.LogSinkConfig = &logSinkConfig
}
if err := cfg.Validate(); err != nil {
return nil, errors.Trace(err)
}
// Important note:
// Do not manipulate the state within NewServer as the API
// server needs to run before mongo upgrades have happened and
// any state manipulation may be be relying on features of the
// database added by upgrades. Here be dragons.
return newServer(cfg)
} | [
"func",
"NewServer",
"(",
"cfg",
"ServerConfig",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"if",
"cfg",
".",
"LogSinkConfig",
"==",
"nil",
"{",
"logSinkConfig",
":=",
"DefaultLogSinkConfig",
"(",
")",
"\n",
"cfg",
".",
"LogSinkConfig",
"=",
"&",
"logSinkConfig",
"\n",
"}",
"\n",
"if",
"err",
":=",
"cfg",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Important note:",
"// Do not manipulate the state within NewServer as the API",
"// server needs to run before mongo upgrades have happened and",
"// any state manipulation may be be relying on features of the",
"// database added by upgrades. Here be dragons.",
"return",
"newServer",
"(",
"cfg",
")",
"\n",
"}"
] | // NewServer serves API requests using the given configuration. | [
"NewServer",
"serves",
"API",
"requests",
"using",
"the",
"given",
"configuration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/apiserver.go#L236-L250 |
4,509 | juju/juju | apiserver/apiserver.go | Stop | func (srv *Server) Stop() error {
srv.tomb.Kill(nil)
return srv.tomb.Wait()
} | go | func (srv *Server) Stop() error {
srv.tomb.Kill(nil)
return srv.tomb.Wait()
} | [
"func",
"(",
"srv",
"*",
"Server",
")",
"Stop",
"(",
")",
"error",
"{",
"srv",
".",
"tomb",
".",
"Kill",
"(",
"nil",
")",
"\n",
"return",
"srv",
".",
"tomb",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Stop stops the server and returns when all running requests
// have completed. | [
"Stop",
"stops",
"the",
"server",
"and",
"returns",
"when",
"all",
"running",
"requests",
"have",
"completed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/apiserver.go#L355-L358 |
4,510 | juju/juju | apiserver/apiserver.go | loop | func (srv *Server) loop(ready chan struct{}) error {
// for pat based handlers, they are matched in-order of being
// registered, first match wins. So more specific ones have to be
// registered first.
for _, ep := range srv.endpoints() {
srv.mux.AddHandler(ep.Method, ep.Pattern, ep.Handler)
defer srv.mux.RemoveHandler(ep.Method, ep.Pattern)
if ep.Method == "GET" {
srv.mux.AddHandler("HEAD", ep.Pattern, ep.Handler)
defer srv.mux.RemoveHandler("HEAD", ep.Pattern)
}
}
close(ready)
<-srv.tomb.Dying()
srv.wg.Wait() // wait for any outstanding requests to complete.
return tomb.ErrDying
} | go | func (srv *Server) loop(ready chan struct{}) error {
// for pat based handlers, they are matched in-order of being
// registered, first match wins. So more specific ones have to be
// registered first.
for _, ep := range srv.endpoints() {
srv.mux.AddHandler(ep.Method, ep.Pattern, ep.Handler)
defer srv.mux.RemoveHandler(ep.Method, ep.Pattern)
if ep.Method == "GET" {
srv.mux.AddHandler("HEAD", ep.Pattern, ep.Handler)
defer srv.mux.RemoveHandler("HEAD", ep.Pattern)
}
}
close(ready)
<-srv.tomb.Dying()
srv.wg.Wait() // wait for any outstanding requests to complete.
return tomb.ErrDying
} | [
"func",
"(",
"srv",
"*",
"Server",
")",
"loop",
"(",
"ready",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"// for pat based handlers, they are matched in-order of being",
"// registered, first match wins. So more specific ones have to be",
"// registered first.",
"for",
"_",
",",
"ep",
":=",
"range",
"srv",
".",
"endpoints",
"(",
")",
"{",
"srv",
".",
"mux",
".",
"AddHandler",
"(",
"ep",
".",
"Method",
",",
"ep",
".",
"Pattern",
",",
"ep",
".",
"Handler",
")",
"\n",
"defer",
"srv",
".",
"mux",
".",
"RemoveHandler",
"(",
"ep",
".",
"Method",
",",
"ep",
".",
"Pattern",
")",
"\n",
"if",
"ep",
".",
"Method",
"==",
"\"",
"\"",
"{",
"srv",
".",
"mux",
".",
"AddHandler",
"(",
"\"",
"\"",
",",
"ep",
".",
"Pattern",
",",
"ep",
".",
"Handler",
")",
"\n",
"defer",
"srv",
".",
"mux",
".",
"RemoveHandler",
"(",
"\"",
"\"",
",",
"ep",
".",
"Pattern",
")",
"\n",
"}",
"\n",
"}",
"\n",
"close",
"(",
"ready",
")",
"\n",
"<-",
"srv",
".",
"tomb",
".",
"Dying",
"(",
")",
"\n",
"srv",
".",
"wg",
".",
"Wait",
"(",
")",
"// wait for any outstanding requests to complete.",
"\n",
"return",
"tomb",
".",
"ErrDying",
"\n",
"}"
] | // loop is the main loop for the server. | [
"loop",
"is",
"the",
"main",
"loop",
"for",
"the",
"server",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/apiserver.go#L412-L428 |
4,511 | juju/juju | apiserver/apiserver.go | publicDNSName | func (srv *Server) publicDNSName() string {
srv.mu.Lock()
defer srv.mu.Unlock()
return srv.publicDNSName_
} | go | func (srv *Server) publicDNSName() string {
srv.mu.Lock()
defer srv.mu.Unlock()
return srv.publicDNSName_
} | [
"func",
"(",
"srv",
"*",
"Server",
")",
"publicDNSName",
"(",
")",
"string",
"{",
"srv",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"srv",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"srv",
".",
"publicDNSName_",
"\n",
"}"
] | // publicDNSName returns the current public hostname. | [
"publicDNSName",
"returns",
"the",
"current",
"public",
"hostname",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/apiserver.go#L889-L893 |
4,512 | juju/juju | provider/cloudsigma/environinstance.go | StartInstance | func (env *environ) StartInstance(ctx context.ProviderCallContext, args environs.StartInstanceParams) (*environs.StartInstanceResult, error) {
logger.Infof("sigmaEnviron.StartInstance...")
if args.InstanceConfig == nil {
return nil, errors.New("instance configuration is nil")
}
if len(args.Tools) == 0 {
return nil, errors.New("agent binaries not found")
}
img, err := findInstanceImage(args.ImageMetadata)
if err != nil {
return nil, err
}
tools, err := args.Tools.Match(tools.Filter{Arch: img.Arch})
if err != nil {
return nil, errors.Errorf("chosen architecture %v not present in %v", img.Arch, args.Tools.Arches())
}
if err := args.InstanceConfig.SetTools(tools); err != nil {
return nil, errors.Trace(err)
}
if err := instancecfg.FinishInstanceConfig(args.InstanceConfig, env.Config()); err != nil {
return nil, err
}
userData, err := providerinit.ComposeUserData(args.InstanceConfig, nil, CloudSigmaRenderer{})
if err != nil {
return nil, errors.Annotate(err, "cannot make user data")
}
logger.Debugf("cloudsigma user data; %d bytes", len(userData))
client := env.client
cfg := env.Config()
server, rootdrive, arch, err := client.newInstance(args, img, userData, cfg.AuthorizedKeys())
if err != nil {
return nil, errors.Errorf("failed start instance: %v", err)
}
inst := &sigmaInstance{server: server}
// prepare hardware characteristics
hwch, err := inst.hardware(arch, rootdrive.Size())
if err != nil {
return nil, err
}
logger.Debugf("hardware: %v", hwch)
return &environs.StartInstanceResult{
Instance: inst,
Hardware: hwch,
}, nil
} | go | func (env *environ) StartInstance(ctx context.ProviderCallContext, args environs.StartInstanceParams) (*environs.StartInstanceResult, error) {
logger.Infof("sigmaEnviron.StartInstance...")
if args.InstanceConfig == nil {
return nil, errors.New("instance configuration is nil")
}
if len(args.Tools) == 0 {
return nil, errors.New("agent binaries not found")
}
img, err := findInstanceImage(args.ImageMetadata)
if err != nil {
return nil, err
}
tools, err := args.Tools.Match(tools.Filter{Arch: img.Arch})
if err != nil {
return nil, errors.Errorf("chosen architecture %v not present in %v", img.Arch, args.Tools.Arches())
}
if err := args.InstanceConfig.SetTools(tools); err != nil {
return nil, errors.Trace(err)
}
if err := instancecfg.FinishInstanceConfig(args.InstanceConfig, env.Config()); err != nil {
return nil, err
}
userData, err := providerinit.ComposeUserData(args.InstanceConfig, nil, CloudSigmaRenderer{})
if err != nil {
return nil, errors.Annotate(err, "cannot make user data")
}
logger.Debugf("cloudsigma user data; %d bytes", len(userData))
client := env.client
cfg := env.Config()
server, rootdrive, arch, err := client.newInstance(args, img, userData, cfg.AuthorizedKeys())
if err != nil {
return nil, errors.Errorf("failed start instance: %v", err)
}
inst := &sigmaInstance{server: server}
// prepare hardware characteristics
hwch, err := inst.hardware(arch, rootdrive.Size())
if err != nil {
return nil, err
}
logger.Debugf("hardware: %v", hwch)
return &environs.StartInstanceResult{
Instance: inst,
Hardware: hwch,
}, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"StartInstance",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"StartInstanceParams",
")",
"(",
"*",
"environs",
".",
"StartInstanceResult",
",",
"error",
")",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"args",
".",
"InstanceConfig",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"args",
".",
"Tools",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"img",
",",
"err",
":=",
"findInstanceImage",
"(",
"args",
".",
"ImageMetadata",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tools",
",",
"err",
":=",
"args",
".",
"Tools",
".",
"Match",
"(",
"tools",
".",
"Filter",
"{",
"Arch",
":",
"img",
".",
"Arch",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"img",
".",
"Arch",
",",
"args",
".",
"Tools",
".",
"Arches",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"args",
".",
"InstanceConfig",
".",
"SetTools",
"(",
"tools",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"instancecfg",
".",
"FinishInstanceConfig",
"(",
"args",
".",
"InstanceConfig",
",",
"env",
".",
"Config",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"userData",
",",
"err",
":=",
"providerinit",
".",
"ComposeUserData",
"(",
"args",
".",
"InstanceConfig",
",",
"nil",
",",
"CloudSigmaRenderer",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"len",
"(",
"userData",
")",
")",
"\n\n",
"client",
":=",
"env",
".",
"client",
"\n",
"cfg",
":=",
"env",
".",
"Config",
"(",
")",
"\n",
"server",
",",
"rootdrive",
",",
"arch",
",",
"err",
":=",
"client",
".",
"newInstance",
"(",
"args",
",",
"img",
",",
"userData",
",",
"cfg",
".",
"AuthorizedKeys",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"inst",
":=",
"&",
"sigmaInstance",
"{",
"server",
":",
"server",
"}",
"\n\n",
"// prepare hardware characteristics",
"hwch",
",",
"err",
":=",
"inst",
".",
"hardware",
"(",
"arch",
",",
"rootdrive",
".",
"Size",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"hwch",
")",
"\n",
"return",
"&",
"environs",
".",
"StartInstanceResult",
"{",
"Instance",
":",
"inst",
",",
"Hardware",
":",
"hwch",
",",
"}",
",",
"nil",
"\n",
"}"
] | // StartInstance asks for a new instance to be created, associated with
// the provided config in machineConfig. The given config describes the juju
// state for the new instance to connect to. The config MachineNonce, which must be
// unique within an environment, is used by juju to protect against the
// consequences of multiple instances being started with the same machine id. | [
"StartInstance",
"asks",
"for",
"a",
"new",
"instance",
"to",
"be",
"created",
"associated",
"with",
"the",
"provided",
"config",
"in",
"machineConfig",
".",
"The",
"given",
"config",
"describes",
"the",
"juju",
"state",
"for",
"the",
"new",
"instance",
"to",
"connect",
"to",
".",
"The",
"config",
"MachineNonce",
"which",
"must",
"be",
"unique",
"within",
"an",
"environment",
"is",
"used",
"by",
"juju",
"to",
"protect",
"against",
"the",
"consequences",
"of",
"multiple",
"instances",
"being",
"started",
"with",
"the",
"same",
"machine",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/environinstance.go#L43-L97 |
4,513 | juju/juju | provider/cloudsigma/environinstance.go | AllInstances | func (env *environ) AllInstances(ctx context.ProviderCallContext) ([]instances.Instance, error) {
// Please note that this must *not* return instances that have not been
// allocated as part of this environment -- if it does, juju will see they
// are not tracked in state, assume they're stale/rogue, and shut them down.
logger.Tracef("environ.AllInstances...")
servers, err := env.client.instances()
if err != nil {
logger.Tracef("environ.AllInstances failed: %v", err)
return nil, err
}
instances := make([]instances.Instance, 0, len(servers))
for _, server := range servers {
instance := sigmaInstance{server: server}
instances = append(instances, instance)
}
if logger.LogLevel() <= loggo.TRACE {
logger.Tracef("All instances, len = %d:", len(instances))
for _, instance := range instances {
logger.Tracef("... id: %q, status: %q", instance.Id(), instance.Status(ctx))
}
}
return instances, nil
} | go | func (env *environ) AllInstances(ctx context.ProviderCallContext) ([]instances.Instance, error) {
// Please note that this must *not* return instances that have not been
// allocated as part of this environment -- if it does, juju will see they
// are not tracked in state, assume they're stale/rogue, and shut them down.
logger.Tracef("environ.AllInstances...")
servers, err := env.client.instances()
if err != nil {
logger.Tracef("environ.AllInstances failed: %v", err)
return nil, err
}
instances := make([]instances.Instance, 0, len(servers))
for _, server := range servers {
instance := sigmaInstance{server: server}
instances = append(instances, instance)
}
if logger.LogLevel() <= loggo.TRACE {
logger.Tracef("All instances, len = %d:", len(instances))
for _, instance := range instances {
logger.Tracef("... id: %q, status: %q", instance.Id(), instance.Status(ctx))
}
}
return instances, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"AllInstances",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"error",
")",
"{",
"// Please note that this must *not* return instances that have not been",
"// allocated as part of this environment -- if it does, juju will see they",
"// are not tracked in state, assume they're stale/rogue, and shut them down.",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
")",
"\n\n",
"servers",
",",
"err",
":=",
"env",
".",
"client",
".",
"instances",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"instances",
":=",
"make",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"0",
",",
"len",
"(",
"servers",
")",
")",
"\n",
"for",
"_",
",",
"server",
":=",
"range",
"servers",
"{",
"instance",
":=",
"sigmaInstance",
"{",
"server",
":",
"server",
"}",
"\n",
"instances",
"=",
"append",
"(",
"instances",
",",
"instance",
")",
"\n",
"}",
"\n\n",
"if",
"logger",
".",
"LogLevel",
"(",
")",
"<=",
"loggo",
".",
"TRACE",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"len",
"(",
"instances",
")",
")",
"\n",
"for",
"_",
",",
"instance",
":=",
"range",
"instances",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"instance",
".",
"Id",
"(",
")",
",",
"instance",
".",
"Status",
"(",
"ctx",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"instances",
",",
"nil",
"\n",
"}"
] | // AllInstances returns all instances currently known to the broker. | [
"AllInstances",
"returns",
"all",
"instances",
"currently",
"known",
"to",
"the",
"broker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/environinstance.go#L100-L127 |
4,514 | juju/juju | provider/cloudsigma/environinstance.go | Instances | func (env *environ) Instances(ctx context.ProviderCallContext, ids []instance.Id) ([]instances.Instance, error) {
logger.Tracef("environ.Instances %#v", ids)
// Please note that this must *not* return instances that have not been
// allocated as part of this environment -- if it does, juju will see they
// are not tracked in state, assume they're stale/rogue, and shut them down.
// This advice applies even if an instance id passed in corresponds to a
// real instance that's not part of the environment -- the Environ should
// treat that no differently to a request for one that does not exist.
m, err := env.client.instanceMap()
if err != nil {
return nil, errors.Annotate(err, "environ.Instances failed")
}
var found int
r := make([]instances.Instance, len(ids))
for i, id := range ids {
if s, ok := m[string(id)]; ok {
r[i] = sigmaInstance{server: s}
found++
}
}
if found == 0 {
err = environs.ErrNoInstances
} else if found != len(ids) {
err = environs.ErrPartialInstances
}
return r, errors.Trace(err)
} | go | func (env *environ) Instances(ctx context.ProviderCallContext, ids []instance.Id) ([]instances.Instance, error) {
logger.Tracef("environ.Instances %#v", ids)
// Please note that this must *not* return instances that have not been
// allocated as part of this environment -- if it does, juju will see they
// are not tracked in state, assume they're stale/rogue, and shut them down.
// This advice applies even if an instance id passed in corresponds to a
// real instance that's not part of the environment -- the Environ should
// treat that no differently to a request for one that does not exist.
m, err := env.client.instanceMap()
if err != nil {
return nil, errors.Annotate(err, "environ.Instances failed")
}
var found int
r := make([]instances.Instance, len(ids))
for i, id := range ids {
if s, ok := m[string(id)]; ok {
r[i] = sigmaInstance{server: s}
found++
}
}
if found == 0 {
err = environs.ErrNoInstances
} else if found != len(ids) {
err = environs.ErrPartialInstances
}
return r, errors.Trace(err)
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"Instances",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"ids",
"[",
"]",
"instance",
".",
"Id",
")",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"error",
")",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"ids",
")",
"\n",
"// Please note that this must *not* return instances that have not been",
"// allocated as part of this environment -- if it does, juju will see they",
"// are not tracked in state, assume they're stale/rogue, and shut them down.",
"// This advice applies even if an instance id passed in corresponds to a",
"// real instance that's not part of the environment -- the Environ should",
"// treat that no differently to a request for one that does not exist.",
"m",
",",
"err",
":=",
"env",
".",
"client",
".",
"instanceMap",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"found",
"int",
"\n",
"r",
":=",
"make",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"ids",
"{",
"if",
"s",
",",
"ok",
":=",
"m",
"[",
"string",
"(",
"id",
")",
"]",
";",
"ok",
"{",
"r",
"[",
"i",
"]",
"=",
"sigmaInstance",
"{",
"server",
":",
"s",
"}",
"\n",
"found",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"found",
"==",
"0",
"{",
"err",
"=",
"environs",
".",
"ErrNoInstances",
"\n",
"}",
"else",
"if",
"found",
"!=",
"len",
"(",
"ids",
")",
"{",
"err",
"=",
"environs",
".",
"ErrPartialInstances",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Instances returns a slice of instances corresponding to the
// given instance ids. If no instances were found, but there
// was no other error, it will return ErrNoInstances. If
// some but not all the instances were found, the returned slice
// will have some nil slots, and an ErrPartialInstances error
// will be returned. | [
"Instances",
"returns",
"a",
"slice",
"of",
"instances",
"corresponding",
"to",
"the",
"given",
"instance",
"ids",
".",
"If",
"no",
"instances",
"were",
"found",
"but",
"there",
"was",
"no",
"other",
"error",
"it",
"will",
"return",
"ErrNoInstances",
".",
"If",
"some",
"but",
"not",
"all",
"the",
"instances",
"were",
"found",
"the",
"returned",
"slice",
"will",
"have",
"some",
"nil",
"slots",
"and",
"an",
"ErrPartialInstances",
"error",
"will",
"be",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/environinstance.go#L135-L165 |
4,515 | juju/juju | environs/utils.go | getAddresses | func getAddresses(ctx context.ProviderCallContext, instances []instances.Instance) []network.Address {
var allAddrs []network.Address
for _, inst := range instances {
if inst == nil {
continue
}
addrs, err := inst.Addresses(ctx)
if err != nil {
logger.Debugf(
"failed to get addresses for %v: %v (ignoring)",
inst.Id(), err,
)
continue
}
allAddrs = append(allAddrs, addrs...)
}
return allAddrs
} | go | func getAddresses(ctx context.ProviderCallContext, instances []instances.Instance) []network.Address {
var allAddrs []network.Address
for _, inst := range instances {
if inst == nil {
continue
}
addrs, err := inst.Addresses(ctx)
if err != nil {
logger.Debugf(
"failed to get addresses for %v: %v (ignoring)",
inst.Id(), err,
)
continue
}
allAddrs = append(allAddrs, addrs...)
}
return allAddrs
} | [
"func",
"getAddresses",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"instances",
"[",
"]",
"instances",
".",
"Instance",
")",
"[",
"]",
"network",
".",
"Address",
"{",
"var",
"allAddrs",
"[",
"]",
"network",
".",
"Address",
"\n",
"for",
"_",
",",
"inst",
":=",
"range",
"instances",
"{",
"if",
"inst",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"addrs",
",",
"err",
":=",
"inst",
".",
"Addresses",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"inst",
".",
"Id",
"(",
")",
",",
"err",
",",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"allAddrs",
"=",
"append",
"(",
"allAddrs",
",",
"addrs",
"...",
")",
"\n",
"}",
"\n",
"return",
"allAddrs",
"\n",
"}"
] | // getAddresses queries and returns the Addresses for the given instances,
// ignoring nil instances or ones without addresses. | [
"getAddresses",
"queries",
"and",
"returns",
"the",
"Addresses",
"for",
"the",
"given",
"instances",
"ignoring",
"nil",
"instances",
"or",
"ones",
"without",
"addresses",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/utils.go#L29-L46 |
4,516 | juju/juju | environs/utils.go | waitAnyInstanceAddresses | func waitAnyInstanceAddresses(
env Environ,
ctx context.ProviderCallContext,
instanceIds []instance.Id,
) ([]network.Address, error) {
var addrs []network.Address
for a := AddressesRefreshAttempt.Start(); len(addrs) == 0 && a.Next(); {
instances, err := env.Instances(ctx, instanceIds)
if err != nil && err != ErrPartialInstances {
logger.Debugf("error getting state instances: %v", err)
return nil, err
}
addrs = getAddresses(ctx, instances)
}
if len(addrs) == 0 {
return nil, errors.NotFoundf("addresses for %v", instanceIds)
}
return addrs, nil
} | go | func waitAnyInstanceAddresses(
env Environ,
ctx context.ProviderCallContext,
instanceIds []instance.Id,
) ([]network.Address, error) {
var addrs []network.Address
for a := AddressesRefreshAttempt.Start(); len(addrs) == 0 && a.Next(); {
instances, err := env.Instances(ctx, instanceIds)
if err != nil && err != ErrPartialInstances {
logger.Debugf("error getting state instances: %v", err)
return nil, err
}
addrs = getAddresses(ctx, instances)
}
if len(addrs) == 0 {
return nil, errors.NotFoundf("addresses for %v", instanceIds)
}
return addrs, nil
} | [
"func",
"waitAnyInstanceAddresses",
"(",
"env",
"Environ",
",",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"instanceIds",
"[",
"]",
"instance",
".",
"Id",
",",
")",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"error",
")",
"{",
"var",
"addrs",
"[",
"]",
"network",
".",
"Address",
"\n",
"for",
"a",
":=",
"AddressesRefreshAttempt",
".",
"Start",
"(",
")",
";",
"len",
"(",
"addrs",
")",
"==",
"0",
"&&",
"a",
".",
"Next",
"(",
")",
";",
"{",
"instances",
",",
"err",
":=",
"env",
".",
"Instances",
"(",
"ctx",
",",
"instanceIds",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"ErrPartialInstances",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"addrs",
"=",
"getAddresses",
"(",
"ctx",
",",
"instances",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"addrs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"instanceIds",
")",
"\n",
"}",
"\n",
"return",
"addrs",
",",
"nil",
"\n",
"}"
] | // waitAnyInstanceAddresses waits for at least one of the instances
// to have addresses, and returns them. | [
"waitAnyInstanceAddresses",
"waits",
"for",
"at",
"least",
"one",
"of",
"the",
"instances",
"to",
"have",
"addresses",
"and",
"returns",
"them",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/utils.go#L50-L68 |
4,517 | juju/juju | environs/utils.go | APIInfo | func APIInfo(ctx context.ProviderCallContext, controllerUUID, modelUUID, caCert string, apiPort int, env Environ) (*api.Info, error) {
instanceIds, err := env.ControllerInstances(ctx, controllerUUID)
if err != nil {
return nil, err
}
logger.Debugf("ControllerInstances returned: %v", instanceIds)
addrs, err := waitAnyInstanceAddresses(env, ctx, instanceIds)
if err != nil {
return nil, err
}
apiAddrs := network.HostPortsToStrings(
network.AddressesWithPort(addrs, apiPort),
)
modelTag := names.NewModelTag(modelUUID)
apiInfo := &api.Info{Addrs: apiAddrs, CACert: caCert, ModelTag: modelTag}
return apiInfo, nil
} | go | func APIInfo(ctx context.ProviderCallContext, controllerUUID, modelUUID, caCert string, apiPort int, env Environ) (*api.Info, error) {
instanceIds, err := env.ControllerInstances(ctx, controllerUUID)
if err != nil {
return nil, err
}
logger.Debugf("ControllerInstances returned: %v", instanceIds)
addrs, err := waitAnyInstanceAddresses(env, ctx, instanceIds)
if err != nil {
return nil, err
}
apiAddrs := network.HostPortsToStrings(
network.AddressesWithPort(addrs, apiPort),
)
modelTag := names.NewModelTag(modelUUID)
apiInfo := &api.Info{Addrs: apiAddrs, CACert: caCert, ModelTag: modelTag}
return apiInfo, nil
} | [
"func",
"APIInfo",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"controllerUUID",
",",
"modelUUID",
",",
"caCert",
"string",
",",
"apiPort",
"int",
",",
"env",
"Environ",
")",
"(",
"*",
"api",
".",
"Info",
",",
"error",
")",
"{",
"instanceIds",
",",
"err",
":=",
"env",
".",
"ControllerInstances",
"(",
"ctx",
",",
"controllerUUID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"instanceIds",
")",
"\n",
"addrs",
",",
"err",
":=",
"waitAnyInstanceAddresses",
"(",
"env",
",",
"ctx",
",",
"instanceIds",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"apiAddrs",
":=",
"network",
".",
"HostPortsToStrings",
"(",
"network",
".",
"AddressesWithPort",
"(",
"addrs",
",",
"apiPort",
")",
",",
")",
"\n",
"modelTag",
":=",
"names",
".",
"NewModelTag",
"(",
"modelUUID",
")",
"\n",
"apiInfo",
":=",
"&",
"api",
".",
"Info",
"{",
"Addrs",
":",
"apiAddrs",
",",
"CACert",
":",
"caCert",
",",
"ModelTag",
":",
"modelTag",
"}",
"\n",
"return",
"apiInfo",
",",
"nil",
"\n",
"}"
] | // APIInfo returns an api.Info for the environment. The result is populated
// with addresses and CA certificate, but no tag or password. | [
"APIInfo",
"returns",
"an",
"api",
".",
"Info",
"for",
"the",
"environment",
".",
"The",
"result",
"is",
"populated",
"with",
"addresses",
"and",
"CA",
"certificate",
"but",
"no",
"tag",
"or",
"password",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/utils.go#L72-L88 |
4,518 | juju/juju | environs/utils.go | CheckProviderAPI | func CheckProviderAPI(env InstanceBroker, ctx context.ProviderCallContext) error {
// We will make a simple API call to the provider
// to ensure the underlying substrate is ok.
_, err := env.AllInstances(ctx)
switch err {
case nil, ErrPartialInstances, ErrNoInstances:
return nil
}
return errors.Annotate(err, "cannot make API call to provider")
} | go | func CheckProviderAPI(env InstanceBroker, ctx context.ProviderCallContext) error {
// We will make a simple API call to the provider
// to ensure the underlying substrate is ok.
_, err := env.AllInstances(ctx)
switch err {
case nil, ErrPartialInstances, ErrNoInstances:
return nil
}
return errors.Annotate(err, "cannot make API call to provider")
} | [
"func",
"CheckProviderAPI",
"(",
"env",
"InstanceBroker",
",",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"error",
"{",
"// We will make a simple API call to the provider",
"// to ensure the underlying substrate is ok.",
"_",
",",
"err",
":=",
"env",
".",
"AllInstances",
"(",
"ctx",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
",",
"ErrPartialInstances",
",",
"ErrNoInstances",
":",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // CheckProviderAPI returns an error if a simple API call
// to check a basic response from the specified environ fails. | [
"CheckProviderAPI",
"returns",
"an",
"error",
"if",
"a",
"simple",
"API",
"call",
"to",
"check",
"a",
"basic",
"response",
"from",
"the",
"specified",
"environ",
"fails",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/utils.go#L92-L101 |
4,519 | juju/juju | apiserver/facades/agent/caasoperator/operator.go | NewFacade | func NewFacade(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASOperatorState,
) (*Facade, error) {
if !authorizer.AuthApplicationAgent() {
return nil, common.ErrPerm
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
canRead := common.AuthAny(
common.AuthFuncForTagKind(names.ApplicationTagKind),
common.AuthFuncForTagKind(names.UnitTagKind),
)
accessUnit := func() (common.AuthFunc, error) {
switch tag := authorizer.GetAuthTag().(type) {
case names.ApplicationTag:
// Any of the units belonging to
// the application can be accessed.
app, err := st.Application(tag.Name)
if err != nil {
return nil, errors.Trace(err)
}
allUnits, err := app.AllUnits()
if err != nil {
return nil, errors.Trace(err)
}
return func(tag names.Tag) bool {
for _, u := range allUnits {
if u.Tag() == tag {
return true
}
}
return false
}, nil
default:
return nil, errors.Errorf("expected names.ApplicationTag, got %T", tag)
}
}
return &Facade{
LifeGetter: common.NewLifeGetter(st, canRead),
APIAddresser: common.NewAPIAddresser(st, resources),
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, canRead),
Remover: common.NewRemover(st, true, accessUnit),
ToolsSetter: common.NewToolsSetter(st, common.AuthFuncForTag(authorizer.GetAuthTag())),
auth: authorizer,
resources: resources,
state: st,
model: model,
}, nil
} | go | func NewFacade(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASOperatorState,
) (*Facade, error) {
if !authorizer.AuthApplicationAgent() {
return nil, common.ErrPerm
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
canRead := common.AuthAny(
common.AuthFuncForTagKind(names.ApplicationTagKind),
common.AuthFuncForTagKind(names.UnitTagKind),
)
accessUnit := func() (common.AuthFunc, error) {
switch tag := authorizer.GetAuthTag().(type) {
case names.ApplicationTag:
// Any of the units belonging to
// the application can be accessed.
app, err := st.Application(tag.Name)
if err != nil {
return nil, errors.Trace(err)
}
allUnits, err := app.AllUnits()
if err != nil {
return nil, errors.Trace(err)
}
return func(tag names.Tag) bool {
for _, u := range allUnits {
if u.Tag() == tag {
return true
}
}
return false
}, nil
default:
return nil, errors.Errorf("expected names.ApplicationTag, got %T", tag)
}
}
return &Facade{
LifeGetter: common.NewLifeGetter(st, canRead),
APIAddresser: common.NewAPIAddresser(st, resources),
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, canRead),
Remover: common.NewRemover(st, true, accessUnit),
ToolsSetter: common.NewToolsSetter(st, common.AuthFuncForTag(authorizer.GetAuthTag())),
auth: authorizer,
resources: resources,
state: st,
model: model,
}, nil
} | [
"func",
"NewFacade",
"(",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
"st",
"CAASOperatorState",
",",
")",
"(",
"*",
"Facade",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthApplicationAgent",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"canRead",
":=",
"common",
".",
"AuthAny",
"(",
"common",
".",
"AuthFuncForTagKind",
"(",
"names",
".",
"ApplicationTagKind",
")",
",",
"common",
".",
"AuthFuncForTagKind",
"(",
"names",
".",
"UnitTagKind",
")",
",",
")",
"\n",
"accessUnit",
":=",
"func",
"(",
")",
"(",
"common",
".",
"AuthFunc",
",",
"error",
")",
"{",
"switch",
"tag",
":=",
"authorizer",
".",
"GetAuthTag",
"(",
")",
".",
"(",
"type",
")",
"{",
"case",
"names",
".",
"ApplicationTag",
":",
"// Any of the units belonging to",
"// the application can be accessed.",
"app",
",",
"err",
":=",
"st",
".",
"Application",
"(",
"tag",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"allUnits",
",",
"err",
":=",
"app",
".",
"AllUnits",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"func",
"(",
"tag",
"names",
".",
"Tag",
")",
"bool",
"{",
"for",
"_",
",",
"u",
":=",
"range",
"allUnits",
"{",
"if",
"u",
".",
"Tag",
"(",
")",
"==",
"tag",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Facade",
"{",
"LifeGetter",
":",
"common",
".",
"NewLifeGetter",
"(",
"st",
",",
"canRead",
")",
",",
"APIAddresser",
":",
"common",
".",
"NewAPIAddresser",
"(",
"st",
",",
"resources",
")",
",",
"AgentEntityWatcher",
":",
"common",
".",
"NewAgentEntityWatcher",
"(",
"st",
",",
"resources",
",",
"canRead",
")",
",",
"Remover",
":",
"common",
".",
"NewRemover",
"(",
"st",
",",
"true",
",",
"accessUnit",
")",
",",
"ToolsSetter",
":",
"common",
".",
"NewToolsSetter",
"(",
"st",
",",
"common",
".",
"AuthFuncForTag",
"(",
"authorizer",
".",
"GetAuthTag",
"(",
")",
")",
")",
",",
"auth",
":",
"authorizer",
",",
"resources",
":",
"resources",
",",
"state",
":",
"st",
",",
"model",
":",
"model",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacade returns a new CAASOperator facade. | [
"NewFacade",
"returns",
"a",
"new",
"CAASOperator",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/caasoperator/operator.go#L40-L92 |
4,520 | juju/juju | apiserver/facades/agent/caasoperator/operator.go | Charm | func (f *Facade) Charm(args params.Entities) (params.ApplicationCharmResults, error) {
results := params.ApplicationCharmResults{
Results: make([]params.ApplicationCharmResult, len(args.Entities)),
}
authTag := f.auth.GetAuthTag()
for i, entity := range args.Entities {
tag, err := names.ParseApplicationTag(entity.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
if tag != authTag {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
application, err := f.state.Application(tag.Id())
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
charm, force, err := application.Charm()
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].Result = ¶ms.ApplicationCharm{
URL: charm.URL().String(),
ForceUpgrade: force,
SHA256: charm.BundleSha256(),
CharmModifiedVersion: application.CharmModifiedVersion(),
}
}
return results, nil
} | go | func (f *Facade) Charm(args params.Entities) (params.ApplicationCharmResults, error) {
results := params.ApplicationCharmResults{
Results: make([]params.ApplicationCharmResult, len(args.Entities)),
}
authTag := f.auth.GetAuthTag()
for i, entity := range args.Entities {
tag, err := names.ParseApplicationTag(entity.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
if tag != authTag {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
application, err := f.state.Application(tag.Id())
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
charm, force, err := application.Charm()
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].Result = ¶ms.ApplicationCharm{
URL: charm.URL().String(),
ForceUpgrade: force,
SHA256: charm.BundleSha256(),
CharmModifiedVersion: application.CharmModifiedVersion(),
}
}
return results, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"Charm",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"ApplicationCharmResults",
",",
"error",
")",
"{",
"results",
":=",
"params",
".",
"ApplicationCharmResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ApplicationCharmResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"authTag",
":=",
"f",
".",
"auth",
".",
"GetAuthTag",
"(",
")",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseApplicationTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"tag",
"!=",
"authTag",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"application",
",",
"err",
":=",
"f",
".",
"state",
".",
"Application",
"(",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"charm",
",",
"force",
",",
"err",
":=",
"application",
".",
"Charm",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
"=",
"&",
"params",
".",
"ApplicationCharm",
"{",
"URL",
":",
"charm",
".",
"URL",
"(",
")",
".",
"String",
"(",
")",
",",
"ForceUpgrade",
":",
"force",
",",
"SHA256",
":",
"charm",
".",
"BundleSha256",
"(",
")",
",",
"CharmModifiedVersion",
":",
"application",
".",
"CharmModifiedVersion",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // Charm returns the charm info for all given applications. | [
"Charm",
"returns",
"the",
"charm",
"info",
"for",
"all",
"given",
"applications",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/caasoperator/operator.go#L138-L171 |
4,521 | juju/juju | apiserver/facades/agent/caasoperator/operator.go | SetPodSpec | func (f *Facade) SetPodSpec(args params.SetPodSpecParams) (params.ErrorResults, error) {
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Specs)),
}
cfg, err := f.model.ModelConfig()
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
provider, err := environs.Provider(cfg.Type())
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
caasProvider, ok := provider.(caas.ContainerEnvironProvider)
if !ok {
return params.ErrorResults{}, errors.NotValidf("container environ provider %T", provider)
}
for i, arg := range args.Specs {
tag, err := names.ParseApplicationTag(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
if !f.auth.AuthOwner(tag) {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
if _, err := caasProvider.ParsePodSpec(arg.Value); err != nil {
results.Results[i].Error = common.ServerError(errors.New("invalid pod spec"))
continue
}
results.Results[i].Error = common.ServerError(
f.model.SetPodSpec(tag, arg.Value),
)
}
return results, nil
} | go | func (f *Facade) SetPodSpec(args params.SetPodSpecParams) (params.ErrorResults, error) {
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Specs)),
}
cfg, err := f.model.ModelConfig()
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
provider, err := environs.Provider(cfg.Type())
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
caasProvider, ok := provider.(caas.ContainerEnvironProvider)
if !ok {
return params.ErrorResults{}, errors.NotValidf("container environ provider %T", provider)
}
for i, arg := range args.Specs {
tag, err := names.ParseApplicationTag(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
if !f.auth.AuthOwner(tag) {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
if _, err := caasProvider.ParsePodSpec(arg.Value); err != nil {
results.Results[i].Error = common.ServerError(errors.New("invalid pod spec"))
continue
}
results.Results[i].Error = common.ServerError(
f.model.SetPodSpec(tag, arg.Value),
)
}
return results, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"SetPodSpec",
"(",
"args",
"params",
".",
"SetPodSpecParams",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"results",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Specs",
")",
")",
",",
"}",
"\n\n",
"cfg",
",",
"err",
":=",
"f",
".",
"model",
".",
"ModelConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"provider",
",",
"err",
":=",
"environs",
".",
"Provider",
"(",
"cfg",
".",
"Type",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"caasProvider",
",",
"ok",
":=",
"provider",
".",
"(",
"caas",
".",
"ContainerEnvironProvider",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"provider",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Specs",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseApplicationTag",
"(",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"f",
".",
"auth",
".",
"AuthOwner",
"(",
"tag",
")",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"caasProvider",
".",
"ParsePodSpec",
"(",
"arg",
".",
"Value",
")",
";",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"f",
".",
"model",
".",
"SetPodSpec",
"(",
"tag",
",",
"arg",
".",
"Value",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // SetPodSpec sets the container specs for a set of applications. | [
"SetPodSpec",
"sets",
"the",
"container",
"specs",
"for",
"a",
"set",
"of",
"applications",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/caasoperator/operator.go#L174-L211 |
4,522 | juju/juju | apiserver/facades/agent/caasoperator/operator.go | WatchUnits | func (f *Facade) WatchUnits(args params.Entities) (params.StringsWatchResults, error) {
results := params.StringsWatchResults{
Results: make([]params.StringsWatchResult, len(args.Entities)),
}
for i, arg := range args.Entities {
id, changes, err := f.watchUnits(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].StringsWatcherId = id
results.Results[i].Changes = changes
}
return results, nil
} | go | func (f *Facade) WatchUnits(args params.Entities) (params.StringsWatchResults, error) {
results := params.StringsWatchResults{
Results: make([]params.StringsWatchResult, len(args.Entities)),
}
for i, arg := range args.Entities {
id, changes, err := f.watchUnits(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].StringsWatcherId = id
results.Results[i].Changes = changes
}
return results, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"WatchUnits",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"StringsWatchResults",
",",
"error",
")",
"{",
"results",
":=",
"params",
".",
"StringsWatchResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"StringsWatchResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"id",
",",
"changes",
",",
"err",
":=",
"f",
".",
"watchUnits",
"(",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"StringsWatcherId",
"=",
"id",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Changes",
"=",
"changes",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // WatchUnits starts a StringsWatcher to watch changes to the
// lifecycle states of units for the specified applications in
// this model. | [
"WatchUnits",
"starts",
"a",
"StringsWatcher",
"to",
"watch",
"changes",
"to",
"the",
"lifecycle",
"states",
"of",
"units",
"for",
"the",
"specified",
"applications",
"in",
"this",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/caasoperator/operator.go#L216-L230 |
4,523 | juju/juju | api/agent/facade.go | NewConnFacade | func NewConnFacade(caller base.APICaller) (ConnFacade, error) {
facadeCaller := base.NewFacadeCaller(caller, "Agent")
return &connFacade{
caller: facadeCaller,
}, nil
} | go | func NewConnFacade(caller base.APICaller) (ConnFacade, error) {
facadeCaller := base.NewFacadeCaller(caller, "Agent")
return &connFacade{
caller: facadeCaller,
}, nil
} | [
"func",
"NewConnFacade",
"(",
"caller",
"base",
".",
"APICaller",
")",
"(",
"ConnFacade",
",",
"error",
")",
"{",
"facadeCaller",
":=",
"base",
".",
"NewFacadeCaller",
"(",
"caller",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"connFacade",
"{",
"caller",
":",
"facadeCaller",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewConnFacade returns a ConnFacade backed by the supplied APICaller. | [
"NewConnFacade",
"returns",
"a",
"ConnFacade",
"backed",
"by",
"the",
"supplied",
"APICaller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/agent/facade.go#L50-L55 |
4,524 | juju/juju | api/agent/facade.go | Life | func (facade *connFacade) Life(entity names.Tag) (Life, error) {
var results params.AgentGetEntitiesResults
args := params.Entities{
Entities: []params.Entity{{Tag: entity.String()}},
}
err := facade.caller.FacadeCall("GetEntities", args, &results)
if err != nil {
return "", errors.Trace(err)
}
if len(results.Entities) != 1 {
return "", errors.Errorf("expected 1 result, got %d", len(results.Entities))
}
if err := results.Entities[0].Error; err != nil {
if params.IsCodeNotFoundOrCodeUnauthorized(err) {
return "", ErrDenied
}
return "", errors.Trace(err)
}
life := Life(results.Entities[0].Life)
switch life {
case Alive, Dying, Dead:
return life, nil
}
return "", errors.Errorf("unknown life value %q", life)
} | go | func (facade *connFacade) Life(entity names.Tag) (Life, error) {
var results params.AgentGetEntitiesResults
args := params.Entities{
Entities: []params.Entity{{Tag: entity.String()}},
}
err := facade.caller.FacadeCall("GetEntities", args, &results)
if err != nil {
return "", errors.Trace(err)
}
if len(results.Entities) != 1 {
return "", errors.Errorf("expected 1 result, got %d", len(results.Entities))
}
if err := results.Entities[0].Error; err != nil {
if params.IsCodeNotFoundOrCodeUnauthorized(err) {
return "", ErrDenied
}
return "", errors.Trace(err)
}
life := Life(results.Entities[0].Life)
switch life {
case Alive, Dying, Dead:
return life, nil
}
return "", errors.Errorf("unknown life value %q", life)
} | [
"func",
"(",
"facade",
"*",
"connFacade",
")",
"Life",
"(",
"entity",
"names",
".",
"Tag",
")",
"(",
"Life",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"AgentGetEntitiesResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"entity",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"facade",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Entities",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Entities",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"results",
".",
"Entities",
"[",
"0",
"]",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"if",
"params",
".",
"IsCodeNotFoundOrCodeUnauthorized",
"(",
"err",
")",
"{",
"return",
"\"",
"\"",
",",
"ErrDenied",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"life",
":=",
"Life",
"(",
"results",
".",
"Entities",
"[",
"0",
"]",
".",
"Life",
")",
"\n",
"switch",
"life",
"{",
"case",
"Alive",
",",
"Dying",
",",
"Dead",
":",
"return",
"life",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"life",
")",
"\n",
"}"
] | // Life is part of the ConnFacade interface. | [
"Life",
"is",
"part",
"of",
"the",
"ConnFacade",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/agent/facade.go#L63-L87 |
4,525 | juju/juju | api/agent/facade.go | SetPassword | func (facade *connFacade) SetPassword(entity names.Tag, password string) error {
var results params.ErrorResults
args := params.EntityPasswords{
Changes: []params.EntityPassword{{
Tag: entity.String(),
Password: password,
}},
}
err := facade.caller.FacadeCall("SetPasswords", args, &results)
if err != nil {
return errors.Trace(err)
}
if len(results.Results) != 1 {
return errors.Errorf("expected 1 result, got %d", len(results.Results))
}
if err := results.Results[0].Error; err != nil {
if params.IsCodeDead(err) {
return ErrDenied
} else if params.IsCodeNotFoundOrCodeUnauthorized(err) {
return ErrDenied
}
return errors.Trace(err)
}
return nil
} | go | func (facade *connFacade) SetPassword(entity names.Tag, password string) error {
var results params.ErrorResults
args := params.EntityPasswords{
Changes: []params.EntityPassword{{
Tag: entity.String(),
Password: password,
}},
}
err := facade.caller.FacadeCall("SetPasswords", args, &results)
if err != nil {
return errors.Trace(err)
}
if len(results.Results) != 1 {
return errors.Errorf("expected 1 result, got %d", len(results.Results))
}
if err := results.Results[0].Error; err != nil {
if params.IsCodeDead(err) {
return ErrDenied
} else if params.IsCodeNotFoundOrCodeUnauthorized(err) {
return ErrDenied
}
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"facade",
"*",
"connFacade",
")",
"SetPassword",
"(",
"entity",
"names",
".",
"Tag",
",",
"password",
"string",
")",
"error",
"{",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"EntityPasswords",
"{",
"Changes",
":",
"[",
"]",
"params",
".",
"EntityPassword",
"{",
"{",
"Tag",
":",
"entity",
".",
"String",
"(",
")",
",",
"Password",
":",
"password",
",",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"facade",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"if",
"params",
".",
"IsCodeDead",
"(",
"err",
")",
"{",
"return",
"ErrDenied",
"\n",
"}",
"else",
"if",
"params",
".",
"IsCodeNotFoundOrCodeUnauthorized",
"(",
"err",
")",
"{",
"return",
"ErrDenied",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetPassword is part of the ConnFacade interface. | [
"SetPassword",
"is",
"part",
"of",
"the",
"ConnFacade",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/agent/facade.go#L90-L114 |
4,526 | juju/juju | state/mocks/mongo_mock.go | NewMockCollection | func NewMockCollection(ctrl *gomock.Controller) *MockCollection {
mock := &MockCollection{ctrl: ctrl}
mock.recorder = &MockCollectionMockRecorder{mock}
return mock
} | go | func NewMockCollection(ctrl *gomock.Controller) *MockCollection {
mock := &MockCollection{ctrl: ctrl}
mock.recorder = &MockCollectionMockRecorder{mock}
return mock
} | [
"func",
"NewMockCollection",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockCollection",
"{",
"mock",
":=",
"&",
"MockCollection",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockCollectionMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockCollection creates a new mock instance | [
"NewMockCollection",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L27-L31 |
4,527 | juju/juju | state/mocks/mongo_mock.go | Count | func (m *MockCollection) Count() (int, error) {
ret := m.ctrl.Call(m, "Count")
ret0, _ := ret[0].(int)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockCollection) Count() (int, error) {
ret := m.ctrl.Call(m, "Count")
ret0, _ := ret[0].(int)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockCollection",
")",
"Count",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"int",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // Count mocks base method | [
"Count",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L39-L44 |
4,528 | juju/juju | state/mocks/mongo_mock.go | Pipe | func (m *MockCollection) Pipe(arg0 interface{}) *mgo_v2.Pipe {
ret := m.ctrl.Call(m, "Pipe", arg0)
ret0, _ := ret[0].(*mgo_v2.Pipe)
return ret0
} | go | func (m *MockCollection) Pipe(arg0 interface{}) *mgo_v2.Pipe {
ret := m.ctrl.Call(m, "Pipe", arg0)
ret0, _ := ret[0].(*mgo_v2.Pipe)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockCollection",
")",
"Pipe",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"mgo_v2",
".",
"Pipe",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"mgo_v2",
".",
"Pipe",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Pipe mocks base method | [
"Pipe",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L88-L92 |
4,529 | juju/juju | state/mocks/mongo_mock.go | Pipe | func (mr *MockCollectionMockRecorder) Pipe(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Pipe", reflect.TypeOf((*MockCollection)(nil).Pipe), arg0)
} | go | func (mr *MockCollectionMockRecorder) Pipe(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Pipe", reflect.TypeOf((*MockCollection)(nil).Pipe), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockCollectionMockRecorder",
")",
"Pipe",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockCollection",
")",
"(",
"nil",
")",
".",
"Pipe",
")",
",",
"arg0",
")",
"\n",
"}"
] | // Pipe indicates an expected call of Pipe | [
"Pipe",
"indicates",
"an",
"expected",
"call",
"of",
"Pipe"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L95-L97 |
4,530 | juju/juju | state/mocks/mongo_mock.go | Writeable | func (m *MockCollection) Writeable() mongo.WriteCollection {
ret := m.ctrl.Call(m, "Writeable")
ret0, _ := ret[0].(mongo.WriteCollection)
return ret0
} | go | func (m *MockCollection) Writeable() mongo.WriteCollection {
ret := m.ctrl.Call(m, "Writeable")
ret0, _ := ret[0].(mongo.WriteCollection)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockCollection",
")",
"Writeable",
"(",
")",
"mongo",
".",
"WriteCollection",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"WriteCollection",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Writeable mocks base method | [
"Writeable",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L100-L104 |
4,531 | juju/juju | state/mocks/mongo_mock.go | NewMockQuery | func NewMockQuery(ctrl *gomock.Controller) *MockQuery {
mock := &MockQuery{ctrl: ctrl}
mock.recorder = &MockQueryMockRecorder{mock}
return mock
} | go | func NewMockQuery(ctrl *gomock.Controller) *MockQuery {
mock := &MockQuery{ctrl: ctrl}
mock.recorder = &MockQueryMockRecorder{mock}
return mock
} | [
"func",
"NewMockQuery",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockQuery",
"{",
"mock",
":=",
"&",
"MockQuery",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockQueryMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockQuery creates a new mock instance | [
"NewMockQuery",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L123-L127 |
4,532 | juju/juju | state/mocks/mongo_mock.go | Comment | func (m *MockQuery) Comment(arg0 string) mongo.Query {
ret := m.ctrl.Call(m, "Comment", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) Comment(arg0 string) mongo.Query {
ret := m.ctrl.Call(m, "Comment", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Comment",
"(",
"arg0",
"string",
")",
"mongo",
".",
"Query",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Comment mocks base method | [
"Comment",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L172-L176 |
4,533 | juju/juju | state/mocks/mongo_mock.go | Distinct | func (m *MockQuery) Distinct(arg0 string, arg1 interface{}) error {
ret := m.ctrl.Call(m, "Distinct", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockQuery) Distinct(arg0 string, arg1 interface{}) error {
ret := m.ctrl.Call(m, "Distinct", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Distinct",
"(",
"arg0",
"string",
",",
"arg1",
"interface",
"{",
"}",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Distinct mocks base method | [
"Distinct",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L197-L201 |
4,534 | juju/juju | state/mocks/mongo_mock.go | Iter | func (m *MockQuery) Iter() mongo.Iterator {
ret := m.ctrl.Call(m, "Iter")
ret0, _ := ret[0].(mongo.Iterator)
return ret0
} | go | func (m *MockQuery) Iter() mongo.Iterator {
ret := m.ctrl.Call(m, "Iter")
ret0, _ := ret[0].(mongo.Iterator)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Iter",
"(",
")",
"mongo",
".",
"Iterator",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Iterator",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Iter mocks base method | [
"Iter",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L249-L253 |
4,535 | juju/juju | state/mocks/mongo_mock.go | Iter | func (mr *MockQueryMockRecorder) Iter() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Iter", reflect.TypeOf((*MockQuery)(nil).Iter))
} | go | func (mr *MockQueryMockRecorder) Iter() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Iter", reflect.TypeOf((*MockQuery)(nil).Iter))
} | [
"func",
"(",
"mr",
"*",
"MockQueryMockRecorder",
")",
"Iter",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockQuery",
")",
"(",
"nil",
")",
".",
"Iter",
")",
")",
"\n",
"}"
] | // Iter indicates an expected call of Iter | [
"Iter",
"indicates",
"an",
"expected",
"call",
"of",
"Iter"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L256-L258 |
4,536 | juju/juju | state/mocks/mongo_mock.go | Limit | func (m *MockQuery) Limit(arg0 int) mongo.Query {
ret := m.ctrl.Call(m, "Limit", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) Limit(arg0 int) mongo.Query {
ret := m.ctrl.Call(m, "Limit", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Limit",
"(",
"arg0",
"int",
")",
"mongo",
".",
"Query",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Limit mocks base method | [
"Limit",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L261-L265 |
4,537 | juju/juju | state/mocks/mongo_mock.go | LogReplay | func (m *MockQuery) LogReplay() mongo.Query {
ret := m.ctrl.Call(m, "LogReplay")
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) LogReplay() mongo.Query {
ret := m.ctrl.Call(m, "LogReplay")
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"LogReplay",
"(",
")",
"mongo",
".",
"Query",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // LogReplay mocks base method | [
"LogReplay",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L273-L277 |
4,538 | juju/juju | state/mocks/mongo_mock.go | MapReduce | func (m *MockQuery) MapReduce(arg0 *mgo_v2.MapReduce, arg1 interface{}) (*mgo_v2.MapReduceInfo, error) {
ret := m.ctrl.Call(m, "MapReduce", arg0, arg1)
ret0, _ := ret[0].(*mgo_v2.MapReduceInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockQuery) MapReduce(arg0 *mgo_v2.MapReduce, arg1 interface{}) (*mgo_v2.MapReduceInfo, error) {
ret := m.ctrl.Call(m, "MapReduce", arg0, arg1)
ret0, _ := ret[0].(*mgo_v2.MapReduceInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"MapReduce",
"(",
"arg0",
"*",
"mgo_v2",
".",
"MapReduce",
",",
"arg1",
"interface",
"{",
"}",
")",
"(",
"*",
"mgo_v2",
".",
"MapReduceInfo",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"mgo_v2",
".",
"MapReduceInfo",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // MapReduce mocks base method | [
"MapReduce",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L285-L290 |
4,539 | juju/juju | state/mocks/mongo_mock.go | One | func (m *MockQuery) One(arg0 interface{}) error {
ret := m.ctrl.Call(m, "One", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockQuery) One(arg0 interface{}) error {
ret := m.ctrl.Call(m, "One", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"One",
"(",
"arg0",
"interface",
"{",
"}",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // One mocks base method | [
"One",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L298-L302 |
4,540 | juju/juju | state/mocks/mongo_mock.go | Prefetch | func (m *MockQuery) Prefetch(arg0 float64) mongo.Query {
ret := m.ctrl.Call(m, "Prefetch", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) Prefetch(arg0 float64) mongo.Query {
ret := m.ctrl.Call(m, "Prefetch", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Prefetch",
"(",
"arg0",
"float64",
")",
"mongo",
".",
"Query",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Prefetch mocks base method | [
"Prefetch",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L310-L314 |
4,541 | juju/juju | state/mocks/mongo_mock.go | Select | func (m *MockQuery) Select(arg0 interface{}) mongo.Query {
ret := m.ctrl.Call(m, "Select", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) Select(arg0 interface{}) mongo.Query {
ret := m.ctrl.Call(m, "Select", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Select",
"(",
"arg0",
"interface",
"{",
"}",
")",
"mongo",
".",
"Query",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Select mocks base method | [
"Select",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L322-L326 |
4,542 | juju/juju | state/mocks/mongo_mock.go | SetMaxTime | func (m *MockQuery) SetMaxTime(arg0 time.Duration) mongo.Query {
ret := m.ctrl.Call(m, "SetMaxTime", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) SetMaxTime(arg0 time.Duration) mongo.Query {
ret := m.ctrl.Call(m, "SetMaxTime", arg0)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"SetMaxTime",
"(",
"arg0",
"time",
".",
"Duration",
")",
"mongo",
".",
"Query",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetMaxTime mocks base method | [
"SetMaxTime",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L346-L350 |
4,543 | juju/juju | state/mocks/mongo_mock.go | SetMaxTime | func (mr *MockQueryMockRecorder) SetMaxTime(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMaxTime", reflect.TypeOf((*MockQuery)(nil).SetMaxTime), arg0)
} | go | func (mr *MockQueryMockRecorder) SetMaxTime(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMaxTime", reflect.TypeOf((*MockQuery)(nil).SetMaxTime), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockQueryMockRecorder",
")",
"SetMaxTime",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockQuery",
")",
"(",
"nil",
")",
".",
"SetMaxTime",
")",
",",
"arg0",
")",
"\n",
"}"
] | // SetMaxTime indicates an expected call of SetMaxTime | [
"SetMaxTime",
"indicates",
"an",
"expected",
"call",
"of",
"SetMaxTime"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L353-L355 |
4,544 | juju/juju | state/mocks/mongo_mock.go | Sort | func (m *MockQuery) Sort(arg0 ...string) mongo.Query {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Sort", varargs...)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | go | func (m *MockQuery) Sort(arg0 ...string) mongo.Query {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Sort", varargs...)
ret0, _ := ret[0].(mongo.Query)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Sort",
"(",
"arg0",
"...",
"string",
")",
"mongo",
".",
"Query",
"{",
"varargs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"arg0",
"{",
"varargs",
"=",
"append",
"(",
"varargs",
",",
"a",
")",
"\n",
"}",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"varargs",
"...",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"mongo",
".",
"Query",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Sort mocks base method | [
"Sort",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L382-L390 |
4,545 | juju/juju | state/mocks/mongo_mock.go | Tail | func (m *MockQuery) Tail(arg0 time.Duration) *mgo_v2.Iter {
ret := m.ctrl.Call(m, "Tail", arg0)
ret0, _ := ret[0].(*mgo_v2.Iter)
return ret0
} | go | func (m *MockQuery) Tail(arg0 time.Duration) *mgo_v2.Iter {
ret := m.ctrl.Call(m, "Tail", arg0)
ret0, _ := ret[0].(*mgo_v2.Iter)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockQuery",
")",
"Tail",
"(",
"arg0",
"time",
".",
"Duration",
")",
"*",
"mgo_v2",
".",
"Iter",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"mgo_v2",
".",
"Iter",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Tail mocks base method | [
"Tail",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/mongo_mock.go#L398-L402 |
4,546 | juju/juju | apiserver/facades/agent/proxyupdater/proxyupdater.go | NewAPIBase | func NewAPIBase(backend Backend, resources facade.Resources, authorizer facade.Authorizer) (*APIBase, error) {
if !(authorizer.AuthMachineAgent() || authorizer.AuthUnitAgent()) {
return nil, common.ErrPerm
}
return &APIBase{
backend: backend,
resources: resources,
authorizer: authorizer,
}, nil
} | go | func NewAPIBase(backend Backend, resources facade.Resources, authorizer facade.Authorizer) (*APIBase, error) {
if !(authorizer.AuthMachineAgent() || authorizer.AuthUnitAgent()) {
return nil, common.ErrPerm
}
return &APIBase{
backend: backend,
resources: resources,
authorizer: authorizer,
}, nil
} | [
"func",
"NewAPIBase",
"(",
"backend",
"Backend",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"APIBase",
",",
"error",
")",
"{",
"if",
"!",
"(",
"authorizer",
".",
"AuthMachineAgent",
"(",
")",
"||",
"authorizer",
".",
"AuthUnitAgent",
"(",
")",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"APIBase",
"{",
"backend",
":",
"backend",
",",
"resources",
":",
"resources",
",",
"authorizer",
":",
"authorizer",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewAPIBase creates a new server-side API facade with the given Backing. | [
"NewAPIBase",
"creates",
"a",
"new",
"server",
"-",
"side",
"API",
"facade",
"with",
"the",
"given",
"Backing",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/proxyupdater/proxyupdater.go#L95-L104 |
4,547 | juju/juju | apiserver/facades/agent/proxyupdater/proxyupdater.go | WatchForProxyConfigAndAPIHostPortChanges | func (api *APIBase) WatchForProxyConfigAndAPIHostPortChanges(args params.Entities) params.NotifyWatchResults {
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
errors, _ := api.authEntities(args)
for i := range args.Entities {
if errors.Results[i].Error == nil {
results.Results[i] = api.oneWatch()
} else {
results.Results[i].Error = errors.Results[i].Error
}
}
return results
} | go | func (api *APIBase) WatchForProxyConfigAndAPIHostPortChanges(args params.Entities) params.NotifyWatchResults {
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
errors, _ := api.authEntities(args)
for i := range args.Entities {
if errors.Results[i].Error == nil {
results.Results[i] = api.oneWatch()
} else {
results.Results[i].Error = errors.Results[i].Error
}
}
return results
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"WatchForProxyConfigAndAPIHostPortChanges",
"(",
"args",
"params",
".",
"Entities",
")",
"params",
".",
"NotifyWatchResults",
"{",
"results",
":=",
"params",
".",
"NotifyWatchResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"NotifyWatchResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"errors",
",",
"_",
":=",
"api",
".",
"authEntities",
"(",
"args",
")",
"\n\n",
"for",
"i",
":=",
"range",
"args",
".",
"Entities",
"{",
"if",
"errors",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"==",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
"=",
"api",
".",
"oneWatch",
"(",
")",
"\n",
"}",
"else",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"errors",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"results",
"\n",
"}"
] | // WatchForProxyConfigAndAPIHostPortChanges watches for cleanups to be perfomed in state | [
"WatchForProxyConfigAndAPIHostPortChanges",
"watches",
"for",
"cleanups",
"to",
"be",
"perfomed",
"in",
"state"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/proxyupdater/proxyupdater.go#L124-L139 |
4,548 | juju/juju | storage/provider/loop.go | CreateVolumes | func (lvs *loopVolumeSource) CreateVolumes(ctx context.ProviderCallContext, args []storage.VolumeParams) ([]storage.CreateVolumesResult, error) {
results := make([]storage.CreateVolumesResult, len(args))
for i, arg := range args {
volume, err := lvs.createVolume(arg)
if err != nil {
results[i].Error = errors.Annotate(err, "creating volume")
}
results[i].Volume = &volume
}
return results, nil
} | go | func (lvs *loopVolumeSource) CreateVolumes(ctx context.ProviderCallContext, args []storage.VolumeParams) ([]storage.CreateVolumesResult, error) {
results := make([]storage.CreateVolumesResult, len(args))
for i, arg := range args {
volume, err := lvs.createVolume(arg)
if err != nil {
results[i].Error = errors.Annotate(err, "creating volume")
}
results[i].Volume = &volume
}
return results, nil
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"CreateVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"[",
"]",
"storage",
".",
"VolumeParams",
")",
"(",
"[",
"]",
"storage",
".",
"CreateVolumesResult",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"storage",
".",
"CreateVolumesResult",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"volume",
",",
"err",
":=",
"lvs",
".",
"createVolume",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
".",
"Volume",
"=",
"&",
"volume",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // CreateVolumes is defined on the VolumeSource interface. | [
"CreateVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L109-L119 |
4,549 | juju/juju | storage/provider/loop.go | ListVolumes | func (lvs *loopVolumeSource) ListVolumes(ctx context.ProviderCallContext) ([]string, error) {
// TODO(axw) implement this when we need it.
return nil, errors.NotImplementedf("ListVolumes")
} | go | func (lvs *loopVolumeSource) ListVolumes(ctx context.ProviderCallContext) ([]string, error) {
// TODO(axw) implement this when we need it.
return nil, errors.NotImplementedf("ListVolumes")
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"ListVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"// TODO(axw) implement this when we need it.",
"return",
"nil",
",",
"errors",
".",
"NotImplementedf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ListVolumes is defined on the VolumeSource interface. | [
"ListVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L144-L147 |
4,550 | juju/juju | storage/provider/loop.go | DescribeVolumes | func (lvs *loopVolumeSource) DescribeVolumes(ctx context.ProviderCallContext, volumeIds []string) ([]storage.DescribeVolumesResult, error) {
// TODO(axw) implement this when we need it.
return nil, errors.NotImplementedf("DescribeVolumes")
} | go | func (lvs *loopVolumeSource) DescribeVolumes(ctx context.ProviderCallContext, volumeIds []string) ([]storage.DescribeVolumesResult, error) {
// TODO(axw) implement this when we need it.
return nil, errors.NotImplementedf("DescribeVolumes")
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"DescribeVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"volumeIds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"storage",
".",
"DescribeVolumesResult",
",",
"error",
")",
"{",
"// TODO(axw) implement this when we need it.",
"return",
"nil",
",",
"errors",
".",
"NotImplementedf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // DescribeVolumes is defined on the VolumeSource interface. | [
"DescribeVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L150-L153 |
4,551 | juju/juju | storage/provider/loop.go | DestroyVolumes | func (lvs *loopVolumeSource) DestroyVolumes(ctx context.ProviderCallContext, volumeIds []string) ([]error, error) {
results := make([]error, len(volumeIds))
for i, volumeId := range volumeIds {
if err := lvs.destroyVolume(volumeId); err != nil {
results[i] = errors.Annotatef(err, "destroying %q", volumeId)
}
}
return results, nil
} | go | func (lvs *loopVolumeSource) DestroyVolumes(ctx context.ProviderCallContext, volumeIds []string) ([]error, error) {
results := make([]error, len(volumeIds))
for i, volumeId := range volumeIds {
if err := lvs.destroyVolume(volumeId); err != nil {
results[i] = errors.Annotatef(err, "destroying %q", volumeId)
}
}
return results, nil
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"DestroyVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"volumeIds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"volumeIds",
")",
")",
"\n",
"for",
"i",
",",
"volumeId",
":=",
"range",
"volumeIds",
"{",
"if",
"err",
":=",
"lvs",
".",
"destroyVolume",
"(",
"volumeId",
")",
";",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
"=",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volumeId",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // DestroyVolumes is defined on the VolumeSource interface. | [
"DestroyVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L156-L164 |
4,552 | juju/juju | storage/provider/loop.go | ReleaseVolumes | func (lvs *loopVolumeSource) ReleaseVolumes(ctx context.ProviderCallContext, volumeIds []string) ([]error, error) {
return make([]error, len(volumeIds)), nil
} | go | func (lvs *loopVolumeSource) ReleaseVolumes(ctx context.ProviderCallContext, volumeIds []string) ([]error, error) {
return make([]error, len(volumeIds)), nil
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"ReleaseVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"volumeIds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"return",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"volumeIds",
")",
")",
",",
"nil",
"\n",
"}"
] | // ReleaseVolumes is defined on the VolumeSource interface. | [
"ReleaseVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L167-L169 |
4,553 | juju/juju | storage/provider/loop.go | AttachVolumes | func (lvs *loopVolumeSource) AttachVolumes(ctx context.ProviderCallContext, args []storage.VolumeAttachmentParams) ([]storage.AttachVolumesResult, error) {
results := make([]storage.AttachVolumesResult, len(args))
for i, arg := range args {
attachment, err := lvs.attachVolume(arg)
if err != nil {
results[i].Error = errors.Annotatef(err, "attaching volume %v", arg.Volume.Id())
continue
}
results[i].VolumeAttachment = attachment
}
return results, nil
} | go | func (lvs *loopVolumeSource) AttachVolumes(ctx context.ProviderCallContext, args []storage.VolumeAttachmentParams) ([]storage.AttachVolumesResult, error) {
results := make([]storage.AttachVolumesResult, len(args))
for i, arg := range args {
attachment, err := lvs.attachVolume(arg)
if err != nil {
results[i].Error = errors.Annotatef(err, "attaching volume %v", arg.Volume.Id())
continue
}
results[i].VolumeAttachment = attachment
}
return results, nil
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"AttachVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"[",
"]",
"storage",
".",
"VolumeAttachmentParams",
")",
"(",
"[",
"]",
"storage",
".",
"AttachVolumesResult",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"storage",
".",
"AttachVolumesResult",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"attachment",
",",
"err",
":=",
"lvs",
".",
"attachVolume",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"arg",
".",
"Volume",
".",
"Id",
"(",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
".",
"VolumeAttachment",
"=",
"attachment",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // AttachVolumes is defined on the VolumeSource interface. | [
"AttachVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L193-L204 |
4,554 | juju/juju | storage/provider/loop.go | DetachVolumes | func (lvs *loopVolumeSource) DetachVolumes(ctx context.ProviderCallContext, args []storage.VolumeAttachmentParams) ([]error, error) {
results := make([]error, len(args))
for i, arg := range args {
if err := lvs.detachVolume(arg.Volume); err != nil {
results[i] = errors.Annotatef(err, "detaching volume %s", arg.Volume.Id())
}
}
return results, nil
} | go | func (lvs *loopVolumeSource) DetachVolumes(ctx context.ProviderCallContext, args []storage.VolumeAttachmentParams) ([]error, error) {
results := make([]error, len(args))
for i, arg := range args {
if err := lvs.detachVolume(arg.Volume); err != nil {
results[i] = errors.Annotatef(err, "detaching volume %s", arg.Volume.Id())
}
}
return results, nil
} | [
"func",
"(",
"lvs",
"*",
"loopVolumeSource",
")",
"DetachVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"[",
"]",
"storage",
".",
"VolumeAttachmentParams",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"err",
":=",
"lvs",
".",
"detachVolume",
"(",
"arg",
".",
"Volume",
")",
";",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
"=",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"arg",
".",
"Volume",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // DetachVolumes is defined on the VolumeSource interface. | [
"DetachVolumes",
"is",
"defined",
"on",
"the",
"VolumeSource",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L224-L232 |
4,555 | juju/juju | storage/provider/loop.go | createBlockFile | func createBlockFile(run runCommandFunc, filePath string, sizeInMiB uint64) error {
// fallocate will reserve the space without actually writing to it.
_, err := run("fallocate", "-l", fmt.Sprintf("%dMiB", sizeInMiB), filePath)
if err != nil {
return errors.Annotatef(err, "allocating loop backing file %q", filePath)
}
return nil
} | go | func createBlockFile(run runCommandFunc, filePath string, sizeInMiB uint64) error {
// fallocate will reserve the space without actually writing to it.
_, err := run("fallocate", "-l", fmt.Sprintf("%dMiB", sizeInMiB), filePath)
if err != nil {
return errors.Annotatef(err, "allocating loop backing file %q", filePath)
}
return nil
} | [
"func",
"createBlockFile",
"(",
"run",
"runCommandFunc",
",",
"filePath",
"string",
",",
"sizeInMiB",
"uint64",
")",
"error",
"{",
"// fallocate will reserve the space without actually writing to it.",
"_",
",",
"err",
":=",
"run",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sizeInMiB",
")",
",",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"filePath",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // createBlockFile creates a file at the specified path, with the
// given size in mebibytes. | [
"createBlockFile",
"creates",
"a",
"file",
"at",
"the",
"specified",
"path",
"with",
"the",
"given",
"size",
"in",
"mebibytes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L253-L260 |
4,556 | juju/juju | storage/provider/loop.go | detachLoopDevice | func detachLoopDevice(run runCommandFunc, deviceName string) error {
_, err := run("losetup", "-d", path.Join("/dev", deviceName))
if err != nil {
return errors.Annotatef(err, "detaching loop device %q", deviceName)
}
return err
} | go | func detachLoopDevice(run runCommandFunc, deviceName string) error {
_, err := run("losetup", "-d", path.Join("/dev", deviceName))
if err != nil {
return errors.Annotatef(err, "detaching loop device %q", deviceName)
}
return err
} | [
"func",
"detachLoopDevice",
"(",
"run",
"runCommandFunc",
",",
"deviceName",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"run",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"path",
".",
"Join",
"(",
"\"",
"\"",
",",
"deviceName",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"deviceName",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // detachLoopDevice detaches the loop device with the specified name. | [
"detachLoopDevice",
"detaches",
"the",
"loop",
"device",
"with",
"the",
"specified",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L293-L299 |
4,557 | juju/juju | storage/provider/loop.go | associatedLoopDevices | func associatedLoopDevices(run runCommandFunc, filePath string) ([]string, error) {
stdout, err := run("losetup", "-j", filePath)
if err != nil {
return nil, errors.Trace(err)
}
stdout = strings.TrimSpace(stdout)
if stdout == "" {
return nil, nil
}
// The output will be zero or more lines with the format:
// "/dev/loop0: [0021]:7504142 (/tmp/test.dat)"
lines := strings.Split(stdout, "\n")
deviceNames := make([]string, len(lines))
for i, line := range lines {
pos := strings.IndexRune(line, ':')
if pos == -1 {
return nil, errors.Errorf("unexpected output %q", line)
}
deviceName := line[:pos][len("/dev/"):]
deviceNames[i] = deviceName
}
return deviceNames, nil
} | go | func associatedLoopDevices(run runCommandFunc, filePath string) ([]string, error) {
stdout, err := run("losetup", "-j", filePath)
if err != nil {
return nil, errors.Trace(err)
}
stdout = strings.TrimSpace(stdout)
if stdout == "" {
return nil, nil
}
// The output will be zero or more lines with the format:
// "/dev/loop0: [0021]:7504142 (/tmp/test.dat)"
lines := strings.Split(stdout, "\n")
deviceNames := make([]string, len(lines))
for i, line := range lines {
pos := strings.IndexRune(line, ':')
if pos == -1 {
return nil, errors.Errorf("unexpected output %q", line)
}
deviceName := line[:pos][len("/dev/"):]
deviceNames[i] = deviceName
}
return deviceNames, nil
} | [
"func",
"associatedLoopDevices",
"(",
"run",
"runCommandFunc",
",",
"filePath",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"stdout",
",",
"err",
":=",
"run",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"stdout",
"=",
"strings",
".",
"TrimSpace",
"(",
"stdout",
")",
"\n",
"if",
"stdout",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"// The output will be zero or more lines with the format:",
"// \"/dev/loop0: [0021]:7504142 (/tmp/test.dat)\"",
"lines",
":=",
"strings",
".",
"Split",
"(",
"stdout",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"deviceNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"lines",
")",
")",
"\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"pos",
":=",
"strings",
".",
"IndexRune",
"(",
"line",
",",
"':'",
")",
"\n",
"if",
"pos",
"==",
"-",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"line",
")",
"\n",
"}",
"\n",
"deviceName",
":=",
"line",
"[",
":",
"pos",
"]",
"[",
"len",
"(",
"\"",
"\"",
")",
":",
"]",
"\n",
"deviceNames",
"[",
"i",
"]",
"=",
"deviceName",
"\n",
"}",
"\n",
"return",
"deviceNames",
",",
"nil",
"\n",
"}"
] | // associatedLoopDevices returns the device names of the loop devices
// associated with the specified file path. | [
"associatedLoopDevices",
"returns",
"the",
"device",
"names",
"of",
"the",
"loop",
"devices",
"associated",
"with",
"the",
"specified",
"file",
"path",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/loop.go#L303-L325 |
4,558 | juju/juju | cmd/juju/controller/register.go | NewRegisterCommand | func NewRegisterCommand() cmd.Command {
c := ®isterCommand{}
c.apiOpen = c.APIOpen
c.listModelsFunc = c.listModels
c.store = jujuclient.NewFileClientStore()
c.CanClearCurrentModel = true
return modelcmd.WrapBase(c)
} | go | func NewRegisterCommand() cmd.Command {
c := ®isterCommand{}
c.apiOpen = c.APIOpen
c.listModelsFunc = c.listModels
c.store = jujuclient.NewFileClientStore()
c.CanClearCurrentModel = true
return modelcmd.WrapBase(c)
} | [
"func",
"NewRegisterCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"c",
":=",
"&",
"registerCommand",
"{",
"}",
"\n",
"c",
".",
"apiOpen",
"=",
"c",
".",
"APIOpen",
"\n",
"c",
".",
"listModelsFunc",
"=",
"c",
".",
"listModels",
"\n",
"c",
".",
"store",
"=",
"jujuclient",
".",
"NewFileClientStore",
"(",
")",
"\n",
"c",
".",
"CanClearCurrentModel",
"=",
"true",
"\n",
"return",
"modelcmd",
".",
"WrapBase",
"(",
"c",
")",
"\n",
"}"
] | // NewRegisterCommand returns a command to allow the user to register a controller. | [
"NewRegisterCommand",
"returns",
"a",
"command",
"to",
"allow",
"the",
"user",
"to",
"register",
"a",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L46-L53 |
4,559 | juju/juju | cmd/juju/controller/register.go | Info | func (c *registerCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "register",
Args: "<registration string>|<controller host name>",
Purpose: usageRegisterSummary,
Doc: usageRegisterDetails,
})
} | go | func (c *registerCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "register",
Args: "<registration string>|<controller host name>",
Purpose: usageRegisterSummary,
Doc: usageRegisterDetails,
})
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"Info",
"(",
")",
"*",
"cmd",
".",
"Info",
"{",
"return",
"jujucmd",
".",
"Info",
"(",
"&",
"cmd",
".",
"Info",
"{",
"Name",
":",
"\"",
"\"",
",",
"Args",
":",
"\"",
"\"",
",",
"Purpose",
":",
"usageRegisterSummary",
",",
"Doc",
":",
"usageRegisterDetails",
",",
"}",
")",
"\n",
"}"
] | // Info implements Command.Info
// `register` may seem generic, but is seen as simple and without potential
// naming collisions in any current or planned features. | [
"Info",
"implements",
"Command",
".",
"Info",
"register",
"may",
"seem",
"generic",
"but",
"is",
"seen",
"as",
"simple",
"and",
"without",
"potential",
"naming",
"collisions",
"in",
"any",
"current",
"or",
"planned",
"features",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L105-L112 |
4,560 | juju/juju | cmd/juju/controller/register.go | Init | func (c *registerCommand) Init(args []string) error {
if len(args) < 1 {
return errors.New("registration data missing")
}
c.Arg, args = args[0], args[1:]
if err := cmd.CheckEmpty(args); err != nil {
return errors.Trace(err)
}
return nil
} | go | func (c *registerCommand) Init(args []string) error {
if len(args) < 1 {
return errors.New("registration data missing")
}
c.Arg, args = args[0], args[1:]
if err := cmd.CheckEmpty(args); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"Init",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"1",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"Arg",
",",
"args",
"=",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"\n",
"if",
"err",
":=",
"cmd",
".",
"CheckEmpty",
"(",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetFlags implements Command.Init. | [
"SetFlags",
"implements",
"Command",
".",
"Init",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L115-L124 |
4,561 | juju/juju | cmd/juju/controller/register.go | controllerDetails | func (c *registerCommand) controllerDetails(ctx *cmd.Context, p *registrationParams, controllerName string) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
if p.publicHost != "" {
return c.publicControllerDetails(p.publicHost, controllerName)
}
return c.nonPublicControllerDetails(ctx, p, controllerName)
} | go | func (c *registerCommand) controllerDetails(ctx *cmd.Context, p *registrationParams, controllerName string) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
if p.publicHost != "" {
return c.publicControllerDetails(p.publicHost, controllerName)
}
return c.nonPublicControllerDetails(ctx, p, controllerName)
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"controllerDetails",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
",",
"p",
"*",
"registrationParams",
",",
"controllerName",
"string",
")",
"(",
"jujuclient",
".",
"ControllerDetails",
",",
"jujuclient",
".",
"AccountDetails",
",",
"error",
")",
"{",
"if",
"p",
".",
"publicHost",
"!=",
"\"",
"\"",
"{",
"return",
"c",
".",
"publicControllerDetails",
"(",
"p",
".",
"publicHost",
",",
"controllerName",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"nonPublicControllerDetails",
"(",
"ctx",
",",
"p",
",",
"controllerName",
")",
"\n",
"}"
] | // controllerDetails returns controller and account details to be registered for the
// given registration parameters. | [
"controllerDetails",
"returns",
"controller",
"and",
"account",
"details",
"to",
"be",
"registered",
"for",
"the",
"given",
"registration",
"parameters",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L188-L193 |
4,562 | juju/juju | cmd/juju/controller/register.go | publicControllerDetails | func (c *registerCommand) publicControllerDetails(host, controllerName string) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
errRet := func(err error) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
return jujuclient.ControllerDetails{}, jujuclient.AccountDetails{}, err
}
apiAddr := host
if !strings.Contains(apiAddr, ":") {
apiAddr += ":443"
}
// Make a direct API connection because we don't yet know the
// controller UUID so can't store the thus-incomplete controller
// details to make a conventional connection.
//
// Unfortunately this means we'll connect twice to the controller
// but it's probably best to go through the conventional path the
// second time.
bclient, err := c.BakeryClient(c.store, controllerName)
if err != nil {
return errRet(errors.Trace(err))
}
dialOpts := api.DefaultDialOpts()
dialOpts.BakeryClient = bclient
conn, err := c.apiOpen(&api.Info{
Addrs: []string{apiAddr},
}, dialOpts)
if err != nil {
return errRet(errors.Trace(err))
}
defer conn.Close()
user, ok := conn.AuthTag().(names.UserTag)
if !ok {
return errRet(errors.Errorf("logged in as %v, not a user", conn.AuthTag()))
}
// If we get to here, then we have a cached macaroon for the registered
// user. If we encounter an error after here, we need to clear it.
c.onRunError = func() {
if err := c.ClearControllerMacaroons(c.store, controllerName); err != nil {
logger.Errorf("failed to clear macaroon: %v", err)
}
}
return jujuclient.ControllerDetails{
APIEndpoints: []string{apiAddr},
ControllerUUID: conn.ControllerTag().Id(),
}, jujuclient.AccountDetails{
User: user.Id(),
LastKnownAccess: conn.ControllerAccess(),
}, nil
} | go | func (c *registerCommand) publicControllerDetails(host, controllerName string) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
errRet := func(err error) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
return jujuclient.ControllerDetails{}, jujuclient.AccountDetails{}, err
}
apiAddr := host
if !strings.Contains(apiAddr, ":") {
apiAddr += ":443"
}
// Make a direct API connection because we don't yet know the
// controller UUID so can't store the thus-incomplete controller
// details to make a conventional connection.
//
// Unfortunately this means we'll connect twice to the controller
// but it's probably best to go through the conventional path the
// second time.
bclient, err := c.BakeryClient(c.store, controllerName)
if err != nil {
return errRet(errors.Trace(err))
}
dialOpts := api.DefaultDialOpts()
dialOpts.BakeryClient = bclient
conn, err := c.apiOpen(&api.Info{
Addrs: []string{apiAddr},
}, dialOpts)
if err != nil {
return errRet(errors.Trace(err))
}
defer conn.Close()
user, ok := conn.AuthTag().(names.UserTag)
if !ok {
return errRet(errors.Errorf("logged in as %v, not a user", conn.AuthTag()))
}
// If we get to here, then we have a cached macaroon for the registered
// user. If we encounter an error after here, we need to clear it.
c.onRunError = func() {
if err := c.ClearControllerMacaroons(c.store, controllerName); err != nil {
logger.Errorf("failed to clear macaroon: %v", err)
}
}
return jujuclient.ControllerDetails{
APIEndpoints: []string{apiAddr},
ControllerUUID: conn.ControllerTag().Id(),
}, jujuclient.AccountDetails{
User: user.Id(),
LastKnownAccess: conn.ControllerAccess(),
}, nil
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"publicControllerDetails",
"(",
"host",
",",
"controllerName",
"string",
")",
"(",
"jujuclient",
".",
"ControllerDetails",
",",
"jujuclient",
".",
"AccountDetails",
",",
"error",
")",
"{",
"errRet",
":=",
"func",
"(",
"err",
"error",
")",
"(",
"jujuclient",
".",
"ControllerDetails",
",",
"jujuclient",
".",
"AccountDetails",
",",
"error",
")",
"{",
"return",
"jujuclient",
".",
"ControllerDetails",
"{",
"}",
",",
"jujuclient",
".",
"AccountDetails",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"apiAddr",
":=",
"host",
"\n",
"if",
"!",
"strings",
".",
"Contains",
"(",
"apiAddr",
",",
"\"",
"\"",
")",
"{",
"apiAddr",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"// Make a direct API connection because we don't yet know the",
"// controller UUID so can't store the thus-incomplete controller",
"// details to make a conventional connection.",
"//",
"// Unfortunately this means we'll connect twice to the controller",
"// but it's probably best to go through the conventional path the",
"// second time.",
"bclient",
",",
"err",
":=",
"c",
".",
"BakeryClient",
"(",
"c",
".",
"store",
",",
"controllerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errRet",
"(",
"errors",
".",
"Trace",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"dialOpts",
":=",
"api",
".",
"DefaultDialOpts",
"(",
")",
"\n",
"dialOpts",
".",
"BakeryClient",
"=",
"bclient",
"\n",
"conn",
",",
"err",
":=",
"c",
".",
"apiOpen",
"(",
"&",
"api",
".",
"Info",
"{",
"Addrs",
":",
"[",
"]",
"string",
"{",
"apiAddr",
"}",
",",
"}",
",",
"dialOpts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errRet",
"(",
"errors",
".",
"Trace",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Close",
"(",
")",
"\n",
"user",
",",
"ok",
":=",
"conn",
".",
"AuthTag",
"(",
")",
".",
"(",
"names",
".",
"UserTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errRet",
"(",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"conn",
".",
"AuthTag",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"// If we get to here, then we have a cached macaroon for the registered",
"// user. If we encounter an error after here, we need to clear it.",
"c",
".",
"onRunError",
"=",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"c",
".",
"ClearControllerMacaroons",
"(",
"c",
".",
"store",
",",
"controllerName",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"jujuclient",
".",
"ControllerDetails",
"{",
"APIEndpoints",
":",
"[",
"]",
"string",
"{",
"apiAddr",
"}",
",",
"ControllerUUID",
":",
"conn",
".",
"ControllerTag",
"(",
")",
".",
"Id",
"(",
")",
",",
"}",
",",
"jujuclient",
".",
"AccountDetails",
"{",
"User",
":",
"user",
".",
"Id",
"(",
")",
",",
"LastKnownAccess",
":",
"conn",
".",
"ControllerAccess",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // publicControllerDetails returns controller and account details to be registered
// for the given public controller host name. | [
"publicControllerDetails",
"returns",
"controller",
"and",
"account",
"details",
"to",
"be",
"registered",
"for",
"the",
"given",
"public",
"controller",
"host",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L197-L243 |
4,563 | juju/juju | cmd/juju/controller/register.go | nonPublicControllerDetails | func (c *registerCommand) nonPublicControllerDetails(ctx *cmd.Context, registrationParams *registrationParams, controllerName string) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
errRet := func(err error) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
return jujuclient.ControllerDetails{}, jujuclient.AccountDetails{}, err
}
// During registration we must set a new password. This has to be done
// atomically with the clearing of the secret key.
payloadBytes, err := json.Marshal(params.SecretKeyLoginRequestPayload{
registrationParams.newPassword,
})
if err != nil {
return errRet(errors.Trace(err))
}
// Make the registration call. If this is successful, the client's
// cookie jar will be populated with a macaroon that may be used
// to log in below without the user having to type in the password
// again.
req := params.SecretKeyLoginRequest{
Nonce: registrationParams.nonce[:],
User: registrationParams.userTag.String(),
PayloadCiphertext: secretbox.Seal(
nil, payloadBytes,
®istrationParams.nonce,
®istrationParams.key,
),
}
resp, err := c.secretKeyLogin(registrationParams.controllerAddrs, req, controllerName)
if err != nil {
// If we got here and got an error, the registration token supplied
// will be expired.
// Log the error as it will be useful for debugging, but give user a
// suggestion for the way forward instead of error details.
logger.Infof("while validating secret key: %v", err)
err = errors.Errorf("Provided registration token may have been expired.\nA controller administrator must reset your user to issue a new token.\nSee %q for more information.", "juju help change-user-password")
return errRet(errors.Trace(err))
}
// Decrypt the response to authenticate the controller and
// obtain its CA certificate.
if len(resp.Nonce) != len(registrationParams.nonce) {
return errRet(errors.NotValidf("response nonce"))
}
var respNonce [24]byte
copy(respNonce[:], resp.Nonce)
payloadBytes, ok := secretbox.Open(nil, resp.PayloadCiphertext, &respNonce, ®istrationParams.key)
if !ok {
return errRet(errors.NotValidf("response payload"))
}
var responsePayload params.SecretKeyLoginResponsePayload
if err := json.Unmarshal(payloadBytes, &responsePayload); err != nil {
return errRet(errors.Annotate(err, "unmarshalling response payload"))
}
user := registrationParams.userTag.Id()
ctx.Infof("Initial password successfully set for %s.", friendlyUserName(user))
// If we get to here, then we have a cached macaroon for the registered
// user. If we encounter an error after here, we need to clear it.
c.onRunError = func() {
if err := c.ClearControllerMacaroons(c.store, controllerName); err != nil {
logger.Errorf("failed to clear macaroon: %v", err)
}
}
return jujuclient.ControllerDetails{
APIEndpoints: registrationParams.controllerAddrs,
ControllerUUID: responsePayload.ControllerUUID,
CACert: responsePayload.CACert,
}, jujuclient.AccountDetails{
User: user,
LastKnownAccess: string(permission.LoginAccess),
}, nil
} | go | func (c *registerCommand) nonPublicControllerDetails(ctx *cmd.Context, registrationParams *registrationParams, controllerName string) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
errRet := func(err error) (jujuclient.ControllerDetails, jujuclient.AccountDetails, error) {
return jujuclient.ControllerDetails{}, jujuclient.AccountDetails{}, err
}
// During registration we must set a new password. This has to be done
// atomically with the clearing of the secret key.
payloadBytes, err := json.Marshal(params.SecretKeyLoginRequestPayload{
registrationParams.newPassword,
})
if err != nil {
return errRet(errors.Trace(err))
}
// Make the registration call. If this is successful, the client's
// cookie jar will be populated with a macaroon that may be used
// to log in below without the user having to type in the password
// again.
req := params.SecretKeyLoginRequest{
Nonce: registrationParams.nonce[:],
User: registrationParams.userTag.String(),
PayloadCiphertext: secretbox.Seal(
nil, payloadBytes,
®istrationParams.nonce,
®istrationParams.key,
),
}
resp, err := c.secretKeyLogin(registrationParams.controllerAddrs, req, controllerName)
if err != nil {
// If we got here and got an error, the registration token supplied
// will be expired.
// Log the error as it will be useful for debugging, but give user a
// suggestion for the way forward instead of error details.
logger.Infof("while validating secret key: %v", err)
err = errors.Errorf("Provided registration token may have been expired.\nA controller administrator must reset your user to issue a new token.\nSee %q for more information.", "juju help change-user-password")
return errRet(errors.Trace(err))
}
// Decrypt the response to authenticate the controller and
// obtain its CA certificate.
if len(resp.Nonce) != len(registrationParams.nonce) {
return errRet(errors.NotValidf("response nonce"))
}
var respNonce [24]byte
copy(respNonce[:], resp.Nonce)
payloadBytes, ok := secretbox.Open(nil, resp.PayloadCiphertext, &respNonce, ®istrationParams.key)
if !ok {
return errRet(errors.NotValidf("response payload"))
}
var responsePayload params.SecretKeyLoginResponsePayload
if err := json.Unmarshal(payloadBytes, &responsePayload); err != nil {
return errRet(errors.Annotate(err, "unmarshalling response payload"))
}
user := registrationParams.userTag.Id()
ctx.Infof("Initial password successfully set for %s.", friendlyUserName(user))
// If we get to here, then we have a cached macaroon for the registered
// user. If we encounter an error after here, we need to clear it.
c.onRunError = func() {
if err := c.ClearControllerMacaroons(c.store, controllerName); err != nil {
logger.Errorf("failed to clear macaroon: %v", err)
}
}
return jujuclient.ControllerDetails{
APIEndpoints: registrationParams.controllerAddrs,
ControllerUUID: responsePayload.ControllerUUID,
CACert: responsePayload.CACert,
}, jujuclient.AccountDetails{
User: user,
LastKnownAccess: string(permission.LoginAccess),
}, nil
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"nonPublicControllerDetails",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
",",
"registrationParams",
"*",
"registrationParams",
",",
"controllerName",
"string",
")",
"(",
"jujuclient",
".",
"ControllerDetails",
",",
"jujuclient",
".",
"AccountDetails",
",",
"error",
")",
"{",
"errRet",
":=",
"func",
"(",
"err",
"error",
")",
"(",
"jujuclient",
".",
"ControllerDetails",
",",
"jujuclient",
".",
"AccountDetails",
",",
"error",
")",
"{",
"return",
"jujuclient",
".",
"ControllerDetails",
"{",
"}",
",",
"jujuclient",
".",
"AccountDetails",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"// During registration we must set a new password. This has to be done",
"// atomically with the clearing of the secret key.",
"payloadBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"params",
".",
"SecretKeyLoginRequestPayload",
"{",
"registrationParams",
".",
"newPassword",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errRet",
"(",
"errors",
".",
"Trace",
"(",
"err",
")",
")",
"\n",
"}",
"\n\n",
"// Make the registration call. If this is successful, the client's",
"// cookie jar will be populated with a macaroon that may be used",
"// to log in below without the user having to type in the password",
"// again.",
"req",
":=",
"params",
".",
"SecretKeyLoginRequest",
"{",
"Nonce",
":",
"registrationParams",
".",
"nonce",
"[",
":",
"]",
",",
"User",
":",
"registrationParams",
".",
"userTag",
".",
"String",
"(",
")",
",",
"PayloadCiphertext",
":",
"secretbox",
".",
"Seal",
"(",
"nil",
",",
"payloadBytes",
",",
"&",
"registrationParams",
".",
"nonce",
",",
"&",
"registrationParams",
".",
"key",
",",
")",
",",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"secretKeyLogin",
"(",
"registrationParams",
".",
"controllerAddrs",
",",
"req",
",",
"controllerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// If we got here and got an error, the registration token supplied",
"// will be expired.",
"// Log the error as it will be useful for debugging, but give user a",
"// suggestion for the way forward instead of error details.",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"err",
"=",
"errors",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"errRet",
"(",
"errors",
".",
"Trace",
"(",
"err",
")",
")",
"\n",
"}",
"\n\n",
"// Decrypt the response to authenticate the controller and",
"// obtain its CA certificate.",
"if",
"len",
"(",
"resp",
".",
"Nonce",
")",
"!=",
"len",
"(",
"registrationParams",
".",
"nonce",
")",
"{",
"return",
"errRet",
"(",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"var",
"respNonce",
"[",
"24",
"]",
"byte",
"\n",
"copy",
"(",
"respNonce",
"[",
":",
"]",
",",
"resp",
".",
"Nonce",
")",
"\n",
"payloadBytes",
",",
"ok",
":=",
"secretbox",
".",
"Open",
"(",
"nil",
",",
"resp",
".",
"PayloadCiphertext",
",",
"&",
"respNonce",
",",
"&",
"registrationParams",
".",
"key",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errRet",
"(",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"var",
"responsePayload",
"params",
".",
"SecretKeyLoginResponsePayload",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"payloadBytes",
",",
"&",
"responsePayload",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errRet",
"(",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"user",
":=",
"registrationParams",
".",
"userTag",
".",
"Id",
"(",
")",
"\n",
"ctx",
".",
"Infof",
"(",
"\"",
"\"",
",",
"friendlyUserName",
"(",
"user",
")",
")",
"\n",
"// If we get to here, then we have a cached macaroon for the registered",
"// user. If we encounter an error after here, we need to clear it.",
"c",
".",
"onRunError",
"=",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"c",
".",
"ClearControllerMacaroons",
"(",
"c",
".",
"store",
",",
"controllerName",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"jujuclient",
".",
"ControllerDetails",
"{",
"APIEndpoints",
":",
"registrationParams",
".",
"controllerAddrs",
",",
"ControllerUUID",
":",
"responsePayload",
".",
"ControllerUUID",
",",
"CACert",
":",
"responsePayload",
".",
"CACert",
",",
"}",
",",
"jujuclient",
".",
"AccountDetails",
"{",
"User",
":",
"user",
",",
"LastKnownAccess",
":",
"string",
"(",
"permission",
".",
"LoginAccess",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // nonPublicControllerDetails returns controller and account details to be registered with
// respect to the given registration parameters. | [
"nonPublicControllerDetails",
"returns",
"controller",
"and",
"account",
"details",
"to",
"be",
"registered",
"with",
"respect",
"to",
"the",
"given",
"registration",
"parameters",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L247-L316 |
4,564 | juju/juju | cmd/juju/controller/register.go | updateController | func (c *registerCommand) updateController(
ctx *cmd.Context,
store jujuclient.ClientStore,
controllerName string,
controllerDetails jujuclient.ControllerDetails,
accountDetails jujuclient.AccountDetails,
) error {
// Check that the same controller isn't already stored, so that we
// can avoid needlessly asking for a controller name in that case.
all, err := store.AllControllers()
if err != nil {
return errors.Trace(err)
}
for name, ctl := range all {
if ctl.ControllerUUID == controllerDetails.ControllerUUID {
var buf bytes.Buffer
if err := alreadyRegisteredMessageT.Execute(
&buf,
map[string]interface{}{
"ControllerName": name,
"UserName": accountDetails.User,
},
); err != nil {
return err
}
ctx.Warningf(buf.String())
return errors.Errorf("controller is already registered as %q", name)
}
}
if err := store.AddController(controllerName, controllerDetails); err != nil {
return errors.Trace(err)
}
if err := store.UpdateAccount(controllerName, accountDetails); err != nil {
return errors.Annotatef(err, "cannot update account information: %v", err)
}
return nil
} | go | func (c *registerCommand) updateController(
ctx *cmd.Context,
store jujuclient.ClientStore,
controllerName string,
controllerDetails jujuclient.ControllerDetails,
accountDetails jujuclient.AccountDetails,
) error {
// Check that the same controller isn't already stored, so that we
// can avoid needlessly asking for a controller name in that case.
all, err := store.AllControllers()
if err != nil {
return errors.Trace(err)
}
for name, ctl := range all {
if ctl.ControllerUUID == controllerDetails.ControllerUUID {
var buf bytes.Buffer
if err := alreadyRegisteredMessageT.Execute(
&buf,
map[string]interface{}{
"ControllerName": name,
"UserName": accountDetails.User,
},
); err != nil {
return err
}
ctx.Warningf(buf.String())
return errors.Errorf("controller is already registered as %q", name)
}
}
if err := store.AddController(controllerName, controllerDetails); err != nil {
return errors.Trace(err)
}
if err := store.UpdateAccount(controllerName, accountDetails); err != nil {
return errors.Annotatef(err, "cannot update account information: %v", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"updateController",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
",",
"store",
"jujuclient",
".",
"ClientStore",
",",
"controllerName",
"string",
",",
"controllerDetails",
"jujuclient",
".",
"ControllerDetails",
",",
"accountDetails",
"jujuclient",
".",
"AccountDetails",
",",
")",
"error",
"{",
"// Check that the same controller isn't already stored, so that we",
"// can avoid needlessly asking for a controller name in that case.",
"all",
",",
"err",
":=",
"store",
".",
"AllControllers",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"name",
",",
"ctl",
":=",
"range",
"all",
"{",
"if",
"ctl",
".",
"ControllerUUID",
"==",
"controllerDetails",
".",
"ControllerUUID",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"alreadyRegisteredMessageT",
".",
"Execute",
"(",
"&",
"buf",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"name",
",",
"\"",
"\"",
":",
"accountDetails",
".",
"User",
",",
"}",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ctx",
".",
"Warningf",
"(",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"store",
".",
"AddController",
"(",
"controllerName",
",",
"controllerDetails",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"store",
".",
"UpdateAccount",
"(",
"controllerName",
",",
"accountDetails",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // updateController prompts for a controller name and updates the
// controller and account details in the given client store. | [
"updateController",
"prompts",
"for",
"a",
"controller",
"name",
"and",
"updates",
"the",
"controller",
"and",
"account",
"details",
"in",
"the",
"given",
"client",
"store",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L320-L356 |
4,565 | juju/juju | cmd/juju/controller/register.go | getParameters | func (c *registerCommand) getParameters(ctx *cmd.Context) (*registrationParams, error) {
var params registrationParams
if strings.Contains(c.Arg, ".") || c.Arg == "localhost" {
// Looks like a host name - no URL-encoded base64 string should
// contain a dot and every public controller name should.
// Allow localhost for development purposes.
params.publicHost = c.Arg
// No need for password shenanigans if we're using a public controller.
return ¶ms, nil
}
// Decode key, username, controller addresses from the string supplied
// on the command line.
decodedData, err := base64.URLEncoding.DecodeString(c.Arg)
if err != nil {
return nil, errors.Trace(err)
}
var info jujuclient.RegistrationInfo
if _, err := asn1.Unmarshal(decodedData, &info); err != nil {
return nil, errors.Trace(err)
}
params.controllerAddrs = info.Addrs
params.userTag = names.NewUserTag(info.User)
if len(info.SecretKey) != len(params.key) {
return nil, errors.NotValidf("secret key")
}
copy(params.key[:], info.SecretKey)
params.defaultControllerName = info.ControllerName
// Prompt the user for the new password to set.
newPassword, err := c.promptNewPassword(ctx.Stderr, ctx.Stdin)
if err != nil {
return nil, errors.Trace(err)
}
params.newPassword = newPassword
// Generate a random nonce for encrypting the request.
if _, err := rand.Read(params.nonce[:]); err != nil {
return nil, errors.Trace(err)
}
return ¶ms, nil
} | go | func (c *registerCommand) getParameters(ctx *cmd.Context) (*registrationParams, error) {
var params registrationParams
if strings.Contains(c.Arg, ".") || c.Arg == "localhost" {
// Looks like a host name - no URL-encoded base64 string should
// contain a dot and every public controller name should.
// Allow localhost for development purposes.
params.publicHost = c.Arg
// No need for password shenanigans if we're using a public controller.
return ¶ms, nil
}
// Decode key, username, controller addresses from the string supplied
// on the command line.
decodedData, err := base64.URLEncoding.DecodeString(c.Arg)
if err != nil {
return nil, errors.Trace(err)
}
var info jujuclient.RegistrationInfo
if _, err := asn1.Unmarshal(decodedData, &info); err != nil {
return nil, errors.Trace(err)
}
params.controllerAddrs = info.Addrs
params.userTag = names.NewUserTag(info.User)
if len(info.SecretKey) != len(params.key) {
return nil, errors.NotValidf("secret key")
}
copy(params.key[:], info.SecretKey)
params.defaultControllerName = info.ControllerName
// Prompt the user for the new password to set.
newPassword, err := c.promptNewPassword(ctx.Stderr, ctx.Stdin)
if err != nil {
return nil, errors.Trace(err)
}
params.newPassword = newPassword
// Generate a random nonce for encrypting the request.
if _, err := rand.Read(params.nonce[:]); err != nil {
return nil, errors.Trace(err)
}
return ¶ms, nil
} | [
"func",
"(",
"c",
"*",
"registerCommand",
")",
"getParameters",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"(",
"*",
"registrationParams",
",",
"error",
")",
"{",
"var",
"params",
"registrationParams",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"c",
".",
"Arg",
",",
"\"",
"\"",
")",
"||",
"c",
".",
"Arg",
"==",
"\"",
"\"",
"{",
"// Looks like a host name - no URL-encoded base64 string should",
"// contain a dot and every public controller name should.",
"// Allow localhost for development purposes.",
"params",
".",
"publicHost",
"=",
"c",
".",
"Arg",
"\n",
"// No need for password shenanigans if we're using a public controller.",
"return",
"&",
"params",
",",
"nil",
"\n",
"}",
"\n",
"// Decode key, username, controller addresses from the string supplied",
"// on the command line.",
"decodedData",
",",
"err",
":=",
"base64",
".",
"URLEncoding",
".",
"DecodeString",
"(",
"c",
".",
"Arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"info",
"jujuclient",
".",
"RegistrationInfo",
"\n",
"if",
"_",
",",
"err",
":=",
"asn1",
".",
"Unmarshal",
"(",
"decodedData",
",",
"&",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"params",
".",
"controllerAddrs",
"=",
"info",
".",
"Addrs",
"\n",
"params",
".",
"userTag",
"=",
"names",
".",
"NewUserTag",
"(",
"info",
".",
"User",
")",
"\n",
"if",
"len",
"(",
"info",
".",
"SecretKey",
")",
"!=",
"len",
"(",
"params",
".",
"key",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"copy",
"(",
"params",
".",
"key",
"[",
":",
"]",
",",
"info",
".",
"SecretKey",
")",
"\n",
"params",
".",
"defaultControllerName",
"=",
"info",
".",
"ControllerName",
"\n\n",
"// Prompt the user for the new password to set.",
"newPassword",
",",
"err",
":=",
"c",
".",
"promptNewPassword",
"(",
"ctx",
".",
"Stderr",
",",
"ctx",
".",
"Stdin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"params",
".",
"newPassword",
"=",
"newPassword",
"\n\n",
"// Generate a random nonce for encrypting the request.",
"if",
"_",
",",
"err",
":=",
"rand",
".",
"Read",
"(",
"params",
".",
"nonce",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"params",
",",
"nil",
"\n",
"}"
] | // getParameters gets all of the parameters required for registering, prompting
// the user as necessary. | [
"getParameters",
"gets",
"all",
"of",
"the",
"parameters",
"required",
"for",
"registering",
"prompting",
"the",
"user",
"as",
"necessary",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/register.go#L438-L480 |
4,566 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | NewProvisionerAPIV4 | func NewProvisionerAPIV4(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV4, error) {
provisionerAPI, err := NewProvisionerAPIV5(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV4{provisionerAPI}, nil
} | go | func NewProvisionerAPIV4(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV4, error) {
provisionerAPI, err := NewProvisionerAPIV5(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV4{provisionerAPI}, nil
} | [
"func",
"NewProvisionerAPIV4",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"ProvisionerAPIV4",
",",
"error",
")",
"{",
"provisionerAPI",
",",
"err",
":=",
"NewProvisionerAPIV5",
"(",
"st",
",",
"resources",
",",
"authorizer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ProvisionerAPIV4",
"{",
"provisionerAPI",
"}",
",",
"nil",
"\n",
"}"
] | // NewProvisionerAPIV4 creates a new server-side version 4 Provisioner API facade. | [
"NewProvisionerAPIV4",
"creates",
"a",
"new",
"server",
"-",
"side",
"version",
"4",
"Provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L197-L203 |
4,567 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | NewProvisionerAPIV5 | func NewProvisionerAPIV5(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV5, error) {
provisionerAPI, err := NewProvisionerAPIV6(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV5{provisionerAPI}, nil
} | go | func NewProvisionerAPIV5(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV5, error) {
provisionerAPI, err := NewProvisionerAPIV6(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV5{provisionerAPI}, nil
} | [
"func",
"NewProvisionerAPIV5",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"ProvisionerAPIV5",
",",
"error",
")",
"{",
"provisionerAPI",
",",
"err",
":=",
"NewProvisionerAPIV6",
"(",
"st",
",",
"resources",
",",
"authorizer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ProvisionerAPIV5",
"{",
"provisionerAPI",
"}",
",",
"nil",
"\n",
"}"
] | // NewProvisionerAPIV5 creates a new server-side Provisioner API facade. | [
"NewProvisionerAPIV5",
"creates",
"a",
"new",
"server",
"-",
"side",
"Provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L206-L212 |
4,568 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | NewProvisionerAPIV6 | func NewProvisionerAPIV6(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV6, error) {
provisionerAPI, err := NewProvisionerAPIV7(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV6{provisionerAPI}, nil
} | go | func NewProvisionerAPIV6(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV6, error) {
provisionerAPI, err := NewProvisionerAPIV7(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV6{provisionerAPI}, nil
} | [
"func",
"NewProvisionerAPIV6",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"ProvisionerAPIV6",
",",
"error",
")",
"{",
"provisionerAPI",
",",
"err",
":=",
"NewProvisionerAPIV7",
"(",
"st",
",",
"resources",
",",
"authorizer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ProvisionerAPIV6",
"{",
"provisionerAPI",
"}",
",",
"nil",
"\n",
"}"
] | // NewProvisionerAPIV6 creates a new server-side Provisioner API facade. | [
"NewProvisionerAPIV6",
"creates",
"a",
"new",
"server",
"-",
"side",
"Provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L215-L221 |
4,569 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | NewProvisionerAPIV7 | func NewProvisionerAPIV7(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV7, error) {
provisionerAPI, err := NewProvisionerAPIV8(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV7{provisionerAPI}, nil
} | go | func NewProvisionerAPIV7(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV7, error) {
provisionerAPI, err := NewProvisionerAPIV8(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV7{provisionerAPI}, nil
} | [
"func",
"NewProvisionerAPIV7",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"ProvisionerAPIV7",
",",
"error",
")",
"{",
"provisionerAPI",
",",
"err",
":=",
"NewProvisionerAPIV8",
"(",
"st",
",",
"resources",
",",
"authorizer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ProvisionerAPIV7",
"{",
"provisionerAPI",
"}",
",",
"nil",
"\n",
"}"
] | // NewProvisionerAPIV7 creates a new server-side Provisioner API facade. | [
"NewProvisionerAPIV7",
"creates",
"a",
"new",
"server",
"-",
"side",
"Provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L224-L230 |
4,570 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | NewProvisionerAPIV8 | func NewProvisionerAPIV8(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV8, error) {
provisionerAPI, err := NewProvisionerAPIV9(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV8{provisionerAPI}, nil
} | go | func NewProvisionerAPIV8(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV8, error) {
provisionerAPI, err := NewProvisionerAPIV9(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV8{provisionerAPI}, nil
} | [
"func",
"NewProvisionerAPIV8",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"ProvisionerAPIV8",
",",
"error",
")",
"{",
"provisionerAPI",
",",
"err",
":=",
"NewProvisionerAPIV9",
"(",
"st",
",",
"resources",
",",
"authorizer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ProvisionerAPIV8",
"{",
"provisionerAPI",
"}",
",",
"nil",
"\n",
"}"
] | // NewProvisionerAPIV8 creates a new server-side Provisioner API facade. | [
"NewProvisionerAPIV8",
"creates",
"a",
"new",
"server",
"-",
"side",
"Provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L233-L239 |
4,571 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | NewProvisionerAPIV9 | func NewProvisionerAPIV9(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV9, error) {
provisionerAPI, err := NewProvisionerAPI(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV9{provisionerAPI}, nil
} | go | func NewProvisionerAPIV9(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ProvisionerAPIV9, error) {
provisionerAPI, err := NewProvisionerAPI(st, resources, authorizer)
if err != nil {
return nil, errors.Trace(err)
}
return &ProvisionerAPIV9{provisionerAPI}, nil
} | [
"func",
"NewProvisionerAPIV9",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"ProvisionerAPIV9",
",",
"error",
")",
"{",
"provisionerAPI",
",",
"err",
":=",
"NewProvisionerAPI",
"(",
"st",
",",
"resources",
",",
"authorizer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ProvisionerAPIV9",
"{",
"provisionerAPI",
"}",
",",
"nil",
"\n",
"}"
] | // NewProvisionerAPIV9 creates a new server-side Provisioner API facade. | [
"NewProvisionerAPIV9",
"creates",
"a",
"new",
"server",
"-",
"side",
"Provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L242-L248 |
4,572 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | WatchContainers | func (p *ProvisionerAPI) WatchContainers(args params.WatchContainers) (params.StringsWatchResults, error) {
result := params.StringsWatchResults{
Results: make([]params.StringsWatchResult, len(args.Params)),
}
for i, arg := range args.Params {
watcherResult, err := p.watchOneMachineContainers(arg)
result.Results[i] = watcherResult
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) WatchContainers(args params.WatchContainers) (params.StringsWatchResults, error) {
result := params.StringsWatchResults{
Results: make([]params.StringsWatchResult, len(args.Params)),
}
for i, arg := range args.Params {
watcherResult, err := p.watchOneMachineContainers(arg)
result.Results[i] = watcherResult
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"WatchContainers",
"(",
"args",
"params",
".",
"WatchContainers",
")",
"(",
"params",
".",
"StringsWatchResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"StringsWatchResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"StringsWatchResult",
",",
"len",
"(",
"args",
".",
"Params",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Params",
"{",
"watcherResult",
",",
"err",
":=",
"p",
".",
"watchOneMachineContainers",
"(",
"arg",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
"=",
"watcherResult",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // WatchContainers starts a StringsWatcher to watch containers deployed to
// any machine passed in args. | [
"WatchContainers",
"starts",
"a",
"StringsWatcher",
"to",
"watch",
"containers",
"deployed",
"to",
"any",
"machine",
"passed",
"in",
"args",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L298-L308 |
4,573 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | WatchAllContainers | func (p *ProvisionerAPI) WatchAllContainers(args params.WatchContainers) (params.StringsWatchResults, error) {
return p.WatchContainers(args)
} | go | func (p *ProvisionerAPI) WatchAllContainers(args params.WatchContainers) (params.StringsWatchResults, error) {
return p.WatchContainers(args)
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"WatchAllContainers",
"(",
"args",
"params",
".",
"WatchContainers",
")",
"(",
"params",
".",
"StringsWatchResults",
",",
"error",
")",
"{",
"return",
"p",
".",
"WatchContainers",
"(",
"args",
")",
"\n",
"}"
] | // WatchAllContainers starts a StringsWatcher to watch all containers deployed to
// any machine passed in args. | [
"WatchAllContainers",
"starts",
"a",
"StringsWatcher",
"to",
"watch",
"all",
"containers",
"deployed",
"to",
"any",
"machine",
"passed",
"in",
"args",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L312-L314 |
4,574 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | SetSupportedContainers | func (p *ProvisionerAPI) SetSupportedContainers(args params.MachineContainersParams) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Params)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Params {
tag, err := names.ParseMachineTag(arg.MachineTag)
if err != nil {
logger.Warningf("SetSupportedContainers called with %q which is not a valid machine tag: %v", arg.MachineTag, err)
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if len(arg.ContainerTypes) == 0 {
err = machine.SupportsNoContainers()
} else {
err = machine.SetSupportedContainers(arg.ContainerTypes)
}
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
} | go | func (p *ProvisionerAPI) SetSupportedContainers(args params.MachineContainersParams) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Params)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Params {
tag, err := names.ParseMachineTag(arg.MachineTag)
if err != nil {
logger.Warningf("SetSupportedContainers called with %q which is not a valid machine tag: %v", arg.MachineTag, err)
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if len(arg.ContainerTypes) == 0 {
err = machine.SupportsNoContainers()
} else {
err = machine.SetSupportedContainers(arg.ContainerTypes)
}
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"SetSupportedContainers",
"(",
"args",
"params",
".",
"MachineContainersParams",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Params",
")",
")",
",",
"}",
"\n\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Params",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"arg",
".",
"MachineTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"arg",
".",
"MachineTag",
",",
"err",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"arg",
".",
"ContainerTypes",
")",
"==",
"0",
"{",
"err",
"=",
"machine",
".",
"SupportsNoContainers",
"(",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"machine",
".",
"SetSupportedContainers",
"(",
"arg",
".",
"ContainerTypes",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetSupportedContainers updates the list of containers supported by the machines passed in args. | [
"SetSupportedContainers",
"updates",
"the",
"list",
"of",
"containers",
"supported",
"by",
"the",
"machines",
"passed",
"in",
"args",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L330-L361 |
4,575 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | SupportedContainers | func (p *ProvisionerAPI) SupportedContainers(args params.Entities) (params.MachineContainerResults, error) {
result := params.MachineContainerResults{
Results: make([]params.MachineContainerResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Entities {
tag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
logger.Warningf("SupportedContainers called with %q which is not a valid machine tag: %v", arg.Tag, err)
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
containerTypes, determined := machine.SupportedContainers()
result.Results[i].ContainerTypes = containerTypes
result.Results[i].Determined = determined
}
return result, nil
} | go | func (p *ProvisionerAPI) SupportedContainers(args params.Entities) (params.MachineContainerResults, error) {
result := params.MachineContainerResults{
Results: make([]params.MachineContainerResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Entities {
tag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
logger.Warningf("SupportedContainers called with %q which is not a valid machine tag: %v", arg.Tag, err)
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
containerTypes, determined := machine.SupportedContainers()
result.Results[i].ContainerTypes = containerTypes
result.Results[i].Determined = determined
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"SupportedContainers",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"MachineContainerResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"MachineContainerResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"MachineContainerResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"arg",
".",
"Tag",
",",
"err",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"containerTypes",
",",
"determined",
":=",
"machine",
".",
"SupportedContainers",
"(",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"ContainerTypes",
"=",
"containerTypes",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Determined",
"=",
"determined",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SupportedContainers returns the list of containers supported by the machines passed in args. | [
"SupportedContainers",
"returns",
"the",
"list",
"of",
"containers",
"supported",
"by",
"the",
"machines",
"passed",
"in",
"args",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L368-L394 |
4,576 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | MachinesWithTransientErrors | func (p *ProvisionerAPI) MachinesWithTransientErrors() (params.StatusResults, error) {
var results params.StatusResults
canAccessFunc, err := p.getAuthFunc()
if err != nil {
return results, err
}
// TODO (wallyworld) - add state.State API for more efficient machines query
machines, err := p.st.AllMachines()
if err != nil {
return results, err
}
for _, machine := range machines {
if !canAccessFunc(machine.Tag()) {
continue
}
if _, provisionedErr := machine.InstanceId(); provisionedErr == nil {
// Machine may have been provisioned but machiner hasn't set the
// status to Started yet.
continue
}
var result params.StatusResult
statusInfo, err := machine.InstanceStatus()
if err != nil {
continue
}
result.Status = statusInfo.Status.String()
result.Info = statusInfo.Message
result.Data = statusInfo.Data
if statusInfo.Status != status.Error && statusInfo.Status != status.ProvisioningError {
continue
}
// Transient errors are marked as such in the status data.
if transient, ok := result.Data["transient"].(bool); !ok || !transient {
continue
}
result.Id = machine.Id()
result.Life = params.Life(machine.Life().String())
results.Results = append(results.Results, result)
}
return results, nil
} | go | func (p *ProvisionerAPI) MachinesWithTransientErrors() (params.StatusResults, error) {
var results params.StatusResults
canAccessFunc, err := p.getAuthFunc()
if err != nil {
return results, err
}
// TODO (wallyworld) - add state.State API for more efficient machines query
machines, err := p.st.AllMachines()
if err != nil {
return results, err
}
for _, machine := range machines {
if !canAccessFunc(machine.Tag()) {
continue
}
if _, provisionedErr := machine.InstanceId(); provisionedErr == nil {
// Machine may have been provisioned but machiner hasn't set the
// status to Started yet.
continue
}
var result params.StatusResult
statusInfo, err := machine.InstanceStatus()
if err != nil {
continue
}
result.Status = statusInfo.Status.String()
result.Info = statusInfo.Message
result.Data = statusInfo.Data
if statusInfo.Status != status.Error && statusInfo.Status != status.ProvisioningError {
continue
}
// Transient errors are marked as such in the status data.
if transient, ok := result.Data["transient"].(bool); !ok || !transient {
continue
}
result.Id = machine.Id()
result.Life = params.Life(machine.Life().String())
results.Results = append(results.Results, result)
}
return results, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"MachinesWithTransientErrors",
"(",
")",
"(",
"params",
".",
"StatusResults",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StatusResults",
"\n",
"canAccessFunc",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"err",
"\n",
"}",
"\n",
"// TODO (wallyworld) - add state.State API for more efficient machines query",
"machines",
",",
"err",
":=",
"p",
".",
"st",
".",
"AllMachines",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"machine",
":=",
"range",
"machines",
"{",
"if",
"!",
"canAccessFunc",
"(",
"machine",
".",
"Tag",
"(",
")",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"_",
",",
"provisionedErr",
":=",
"machine",
".",
"InstanceId",
"(",
")",
";",
"provisionedErr",
"==",
"nil",
"{",
"// Machine may have been provisioned but machiner hasn't set the",
"// status to Started yet.",
"continue",
"\n",
"}",
"\n",
"var",
"result",
"params",
".",
"StatusResult",
"\n",
"statusInfo",
",",
"err",
":=",
"machine",
".",
"InstanceStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"result",
".",
"Status",
"=",
"statusInfo",
".",
"Status",
".",
"String",
"(",
")",
"\n",
"result",
".",
"Info",
"=",
"statusInfo",
".",
"Message",
"\n",
"result",
".",
"Data",
"=",
"statusInfo",
".",
"Data",
"\n",
"if",
"statusInfo",
".",
"Status",
"!=",
"status",
".",
"Error",
"&&",
"statusInfo",
".",
"Status",
"!=",
"status",
".",
"ProvisioningError",
"{",
"continue",
"\n",
"}",
"\n",
"// Transient errors are marked as such in the status data.",
"if",
"transient",
",",
"ok",
":=",
"result",
".",
"Data",
"[",
"\"",
"\"",
"]",
".",
"(",
"bool",
")",
";",
"!",
"ok",
"||",
"!",
"transient",
"{",
"continue",
"\n",
"}",
"\n",
"result",
".",
"Id",
"=",
"machine",
".",
"Id",
"(",
")",
"\n",
"result",
".",
"Life",
"=",
"params",
".",
"Life",
"(",
"machine",
".",
"Life",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"results",
".",
"Results",
"=",
"append",
"(",
"results",
".",
"Results",
",",
"result",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // MachinesWithTransientErrors returns status data for machines with provisioning
// errors which are transient. | [
"MachinesWithTransientErrors",
"returns",
"status",
"data",
"for",
"machines",
"with",
"provisioning",
"errors",
"which",
"are",
"transient",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L470-L510 |
4,577 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | Series | func (p *ProvisionerAPI) Series(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
result.Results[i].Result = machine.Series()
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) Series(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
result.Results[i].Result = machine.Series()
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"Series",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"StringResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"StringResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"StringResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
"=",
"machine",
".",
"Series",
"(",
")",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Series returns the deployed series for each given machine entity. | [
"Series",
"returns",
"the",
"deployed",
"series",
"for",
"each",
"given",
"machine",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L513-L534 |
4,578 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | KeepInstance | func (p *ProvisionerAPI) KeepInstance(args params.Entities) (params.BoolResults, error) {
result := params.BoolResults{
Results: make([]params.BoolResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
keep, err := machine.KeepInstance()
result.Results[i].Result = keep
result.Results[i].Error = common.ServerError(err)
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) KeepInstance(args params.Entities) (params.BoolResults, error) {
result := params.BoolResults{
Results: make([]params.BoolResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
keep, err := machine.KeepInstance()
result.Results[i].Result = keep
result.Results[i].Error = common.ServerError(err)
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"KeepInstance",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"BoolResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"BoolResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"BoolResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"keep",
",",
"err",
":=",
"machine",
".",
"KeepInstance",
"(",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
"=",
"keep",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // KeepInstance returns the keep-instance value for each given machine entity. | [
"KeepInstance",
"returns",
"the",
"keep",
"-",
"instance",
"value",
"for",
"each",
"given",
"machine",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L569-L593 |
4,579 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | DistributionGroup | func (p *ProvisionerAPI) DistributionGroup(args params.Entities) (params.DistributionGroupResults, error) {
result := params.DistributionGroupResults{
Results: make([]params.DistributionGroupResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
// If the machine is a controller, return
// controller instances. Otherwise, return
// instances with services in common with the machine
// being provisioned.
if machine.IsManager() {
result.Results[i].Result, err = controllerInstances(p.st)
} else {
result.Results[i].Result, err = commonServiceInstances(p.st, machine)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) DistributionGroup(args params.Entities) (params.DistributionGroupResults, error) {
result := params.DistributionGroupResults{
Results: make([]params.DistributionGroupResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
// If the machine is a controller, return
// controller instances. Otherwise, return
// instances with services in common with the machine
// being provisioned.
if machine.IsManager() {
result.Results[i].Result, err = controllerInstances(p.st)
} else {
result.Results[i].Result, err = commonServiceInstances(p.st, machine)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"DistributionGroup",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"DistributionGroupResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"DistributionGroupResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"DistributionGroupResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// If the machine is a controller, return",
"// controller instances. Otherwise, return",
"// instances with services in common with the machine",
"// being provisioned.",
"if",
"machine",
".",
"IsManager",
"(",
")",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
",",
"err",
"=",
"controllerInstances",
"(",
"p",
".",
"st",
")",
"\n",
"}",
"else",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
",",
"err",
"=",
"commonServiceInstances",
"(",
"p",
".",
"st",
",",
"machine",
")",
"\n",
"}",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // DistributionGroup returns, for each given machine entity,
// a slice of instance.Ids that belong to the same distribution
// group as that machine. This information may be used to
// distribute instances for high availability. | [
"DistributionGroup",
"returns",
"for",
"each",
"given",
"machine",
"entity",
"a",
"slice",
"of",
"instance",
".",
"Ids",
"that",
"belong",
"to",
"the",
"same",
"distribution",
"group",
"as",
"that",
"machine",
".",
"This",
"information",
"may",
"be",
"used",
"to",
"distribute",
"instances",
"for",
"high",
"availability",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L599-L628 |
4,580 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | controllerInstances | func controllerInstances(st *state.State) ([]instance.Id, error) {
info, err := st.ControllerInfo()
if err != nil {
return nil, err
}
instances := make([]instance.Id, 0, len(info.MachineIds))
for _, id := range info.MachineIds {
machine, err := st.Machine(id)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instances = append(instances, instanceId)
} else if !errors.IsNotProvisioned(err) {
return nil, err
}
}
return instances, nil
} | go | func controllerInstances(st *state.State) ([]instance.Id, error) {
info, err := st.ControllerInfo()
if err != nil {
return nil, err
}
instances := make([]instance.Id, 0, len(info.MachineIds))
for _, id := range info.MachineIds {
machine, err := st.Machine(id)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instances = append(instances, instanceId)
} else if !errors.IsNotProvisioned(err) {
return nil, err
}
}
return instances, nil
} | [
"func",
"controllerInstances",
"(",
"st",
"*",
"state",
".",
"State",
")",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"st",
".",
"ControllerInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"instances",
":=",
"make",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"0",
",",
"len",
"(",
"info",
".",
"MachineIds",
")",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"info",
".",
"MachineIds",
"{",
"machine",
",",
"err",
":=",
"st",
".",
"Machine",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"instanceId",
",",
"err",
":=",
"machine",
".",
"InstanceId",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"instances",
"=",
"append",
"(",
"instances",
",",
"instanceId",
")",
"\n",
"}",
"else",
"if",
"!",
"errors",
".",
"IsNotProvisioned",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"instances",
",",
"nil",
"\n",
"}"
] | // controllerInstances returns all environ manager instances. | [
"controllerInstances",
"returns",
"all",
"environ",
"manager",
"instances",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L631-L650 |
4,581 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | commonServiceInstances | func commonServiceInstances(st *state.State, m *state.Machine) ([]instance.Id, error) {
units, err := m.Units()
if err != nil {
return nil, err
}
instanceIdSet := make(set.Strings)
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
instanceIds, err := state.ApplicationInstances(st, unit.ApplicationName())
if err != nil {
return nil, err
}
for _, instanceId := range instanceIds {
instanceIdSet.Add(string(instanceId))
}
}
instanceIds := make([]instance.Id, instanceIdSet.Size())
// Sort values to simplify testing.
for i, instanceId := range instanceIdSet.SortedValues() {
instanceIds[i] = instance.Id(instanceId)
}
return instanceIds, nil
} | go | func commonServiceInstances(st *state.State, m *state.Machine) ([]instance.Id, error) {
units, err := m.Units()
if err != nil {
return nil, err
}
instanceIdSet := make(set.Strings)
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
instanceIds, err := state.ApplicationInstances(st, unit.ApplicationName())
if err != nil {
return nil, err
}
for _, instanceId := range instanceIds {
instanceIdSet.Add(string(instanceId))
}
}
instanceIds := make([]instance.Id, instanceIdSet.Size())
// Sort values to simplify testing.
for i, instanceId := range instanceIdSet.SortedValues() {
instanceIds[i] = instance.Id(instanceId)
}
return instanceIds, nil
} | [
"func",
"commonServiceInstances",
"(",
"st",
"*",
"state",
".",
"State",
",",
"m",
"*",
"state",
".",
"Machine",
")",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"units",
",",
"err",
":=",
"m",
".",
"Units",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"instanceIdSet",
":=",
"make",
"(",
"set",
".",
"Strings",
")",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"units",
"{",
"if",
"!",
"unit",
".",
"IsPrincipal",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"instanceIds",
",",
"err",
":=",
"state",
".",
"ApplicationInstances",
"(",
"st",
",",
"unit",
".",
"ApplicationName",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"instanceId",
":=",
"range",
"instanceIds",
"{",
"instanceIdSet",
".",
"Add",
"(",
"string",
"(",
"instanceId",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"instanceIds",
":=",
"make",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"instanceIdSet",
".",
"Size",
"(",
")",
")",
"\n",
"// Sort values to simplify testing.",
"for",
"i",
",",
"instanceId",
":=",
"range",
"instanceIdSet",
".",
"SortedValues",
"(",
")",
"{",
"instanceIds",
"[",
"i",
"]",
"=",
"instance",
".",
"Id",
"(",
"instanceId",
")",
"\n",
"}",
"\n",
"return",
"instanceIds",
",",
"nil",
"\n",
"}"
] | // commonServiceInstances returns instances with
// services in common with the specified machine. | [
"commonServiceInstances",
"returns",
"instances",
"with",
"services",
"in",
"common",
"with",
"the",
"specified",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L654-L678 |
4,582 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | DistributionGroupByMachineId | func (p *ProvisionerAPI) DistributionGroupByMachineId(args params.Entities) (params.StringsResults, error) {
result := params.StringsResults{
Results: make([]params.StringsResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return params.StringsResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
// If the machine is a controller, return
// controller instances. Otherwise, return
// instances with services in common with the machine
// being provisioned.
if machine.IsManager() {
result.Results[i].Result, err = controllerMachineIds(p.st, machine)
} else {
result.Results[i].Result, err = commonApplicationMachineId(p.st, machine)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) DistributionGroupByMachineId(args params.Entities) (params.StringsResults, error) {
result := params.StringsResults{
Results: make([]params.StringsResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return params.StringsResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
// If the machine is a controller, return
// controller instances. Otherwise, return
// instances with services in common with the machine
// being provisioned.
if machine.IsManager() {
result.Results[i].Result, err = controllerMachineIds(p.st, machine)
} else {
result.Results[i].Result, err = commonApplicationMachineId(p.st, machine)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"DistributionGroupByMachineId",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"StringsResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"StringsResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"StringsResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"StringsResults",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// If the machine is a controller, return",
"// controller instances. Otherwise, return",
"// instances with services in common with the machine",
"// being provisioned.",
"if",
"machine",
".",
"IsManager",
"(",
")",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
",",
"err",
"=",
"controllerMachineIds",
"(",
"p",
".",
"st",
",",
"machine",
")",
"\n",
"}",
"else",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
",",
"err",
"=",
"commonApplicationMachineId",
"(",
"p",
".",
"st",
",",
"machine",
")",
"\n",
"}",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // DistributionGroupByMachineId returns, for each given machine entity,
// a slice of machine.Ids that belong to the same distribution
// group as that machine. This information may be used to
// distribute instances for high availability. | [
"DistributionGroupByMachineId",
"returns",
"for",
"each",
"given",
"machine",
"entity",
"a",
"slice",
"of",
"machine",
".",
"Ids",
"that",
"belong",
"to",
"the",
"same",
"distribution",
"group",
"as",
"that",
"machine",
".",
"This",
"information",
"may",
"be",
"used",
"to",
"distribute",
"instances",
"for",
"high",
"availability",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L687-L716 |
4,583 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | controllerMachineIds | func controllerMachineIds(st *state.State, m *state.Machine) ([]string, error) {
info, err := st.ControllerInfo()
if err != nil {
return nil, err
}
result := set.NewStrings(info.MachineIds...)
result.Remove(m.Id())
return result.SortedValues(), nil
} | go | func controllerMachineIds(st *state.State, m *state.Machine) ([]string, error) {
info, err := st.ControllerInfo()
if err != nil {
return nil, err
}
result := set.NewStrings(info.MachineIds...)
result.Remove(m.Id())
return result.SortedValues(), nil
} | [
"func",
"controllerMachineIds",
"(",
"st",
"*",
"state",
".",
"State",
",",
"m",
"*",
"state",
".",
"Machine",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"st",
".",
"ControllerInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"set",
".",
"NewStrings",
"(",
"info",
".",
"MachineIds",
"...",
")",
"\n",
"result",
".",
"Remove",
"(",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"return",
"result",
".",
"SortedValues",
"(",
")",
",",
"nil",
"\n",
"}"
] | // controllerMachineIds returns a slice of all other environ manager machine.Ids. | [
"controllerMachineIds",
"returns",
"a",
"slice",
"of",
"all",
"other",
"environ",
"manager",
"machine",
".",
"Ids",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L719-L727 |
4,584 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | commonApplicationMachineId | func commonApplicationMachineId(st *state.State, m *state.Machine) ([]string, error) {
applications := m.Principals()
var union set.Strings
for _, app := range applications {
machines, err := state.ApplicationMachines(st, app)
if err != nil {
return nil, err
}
union = union.Union(set.NewStrings(machines...))
}
union.Remove(m.Id())
return union.SortedValues(), nil
} | go | func commonApplicationMachineId(st *state.State, m *state.Machine) ([]string, error) {
applications := m.Principals()
var union set.Strings
for _, app := range applications {
machines, err := state.ApplicationMachines(st, app)
if err != nil {
return nil, err
}
union = union.Union(set.NewStrings(machines...))
}
union.Remove(m.Id())
return union.SortedValues(), nil
} | [
"func",
"commonApplicationMachineId",
"(",
"st",
"*",
"state",
".",
"State",
",",
"m",
"*",
"state",
".",
"Machine",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"applications",
":=",
"m",
".",
"Principals",
"(",
")",
"\n",
"var",
"union",
"set",
".",
"Strings",
"\n",
"for",
"_",
",",
"app",
":=",
"range",
"applications",
"{",
"machines",
",",
"err",
":=",
"state",
".",
"ApplicationMachines",
"(",
"st",
",",
"app",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"union",
"=",
"union",
".",
"Union",
"(",
"set",
".",
"NewStrings",
"(",
"machines",
"...",
")",
")",
"\n",
"}",
"\n",
"union",
".",
"Remove",
"(",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"return",
"union",
".",
"SortedValues",
"(",
")",
",",
"nil",
"\n",
"}"
] | // commonApplicationMachineId returns a slice of machine.Ids with
// applications in common with the specified machine. | [
"commonApplicationMachineId",
"returns",
"a",
"slice",
"of",
"machine",
".",
"Ids",
"with",
"applications",
"in",
"common",
"with",
"the",
"specified",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L731-L743 |
4,585 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | Constraints | func (p *ProvisionerAPI) Constraints(args params.Entities) (params.ConstraintsResults, error) {
result := params.ConstraintsResults{
Results: make([]params.ConstraintsResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
var cons constraints.Value
cons, err = machine.Constraints()
if err == nil {
result.Results[i].Constraints = cons
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) Constraints(args params.Entities) (params.ConstraintsResults, error) {
result := params.ConstraintsResults{
Results: make([]params.ConstraintsResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
var cons constraints.Value
cons, err = machine.Constraints()
if err == nil {
result.Results[i].Constraints = cons
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"Constraints",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"ConstraintsResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ConstraintsResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ConstraintsResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"var",
"cons",
"constraints",
".",
"Value",
"\n",
"cons",
",",
"err",
"=",
"machine",
".",
"Constraints",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Constraints",
"=",
"cons",
"\n",
"}",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Constraints returns the constraints for each given machine entity. | [
"Constraints",
"returns",
"the",
"constraints",
"for",
"each",
"given",
"machine",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L746-L771 |
4,586 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | SetInstanceInfo | func (p *ProvisionerAPI) SetInstanceInfo(args params.InstancesInfo) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Machines)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
setInstanceInfo := func(arg params.InstanceInfo) error {
tag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
return common.ErrPerm
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
return err
}
volumes, err := storagecommon.VolumesToState(arg.Volumes)
if err != nil {
return err
}
volumeAttachments, err := storagecommon.VolumeAttachmentInfosToState(arg.VolumeAttachments)
if err != nil {
return err
}
devicesArgs, devicesAddrs := networkingcommon.NetworkConfigsToStateArgs(arg.NetworkConfig)
err = machine.SetInstanceInfo(
arg.InstanceId, arg.DisplayName, arg.Nonce, arg.Characteristics,
devicesArgs, devicesAddrs,
volumes, volumeAttachments, arg.CharmProfiles,
)
if err != nil {
return errors.Annotatef(err, "cannot record provisioning info for %q", arg.InstanceId)
}
return nil
}
for i, arg := range args.Machines {
err := setInstanceInfo(arg)
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) SetInstanceInfo(args params.InstancesInfo) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Machines)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
setInstanceInfo := func(arg params.InstanceInfo) error {
tag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
return common.ErrPerm
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
return err
}
volumes, err := storagecommon.VolumesToState(arg.Volumes)
if err != nil {
return err
}
volumeAttachments, err := storagecommon.VolumeAttachmentInfosToState(arg.VolumeAttachments)
if err != nil {
return err
}
devicesArgs, devicesAddrs := networkingcommon.NetworkConfigsToStateArgs(arg.NetworkConfig)
err = machine.SetInstanceInfo(
arg.InstanceId, arg.DisplayName, arg.Nonce, arg.Characteristics,
devicesArgs, devicesAddrs,
volumes, volumeAttachments, arg.CharmProfiles,
)
if err != nil {
return errors.Annotatef(err, "cannot record provisioning info for %q", arg.InstanceId)
}
return nil
}
for i, arg := range args.Machines {
err := setInstanceInfo(arg)
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"SetInstanceInfo",
"(",
"args",
"params",
".",
"InstancesInfo",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Machines",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n",
"setInstanceInfo",
":=",
"func",
"(",
"arg",
"params",
".",
"InstanceInfo",
")",
"error",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"volumes",
",",
"err",
":=",
"storagecommon",
".",
"VolumesToState",
"(",
"arg",
".",
"Volumes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"volumeAttachments",
",",
"err",
":=",
"storagecommon",
".",
"VolumeAttachmentInfosToState",
"(",
"arg",
".",
"VolumeAttachments",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"devicesArgs",
",",
"devicesAddrs",
":=",
"networkingcommon",
".",
"NetworkConfigsToStateArgs",
"(",
"arg",
".",
"NetworkConfig",
")",
"\n\n",
"err",
"=",
"machine",
".",
"SetInstanceInfo",
"(",
"arg",
".",
"InstanceId",
",",
"arg",
".",
"DisplayName",
",",
"arg",
".",
"Nonce",
",",
"arg",
".",
"Characteristics",
",",
"devicesArgs",
",",
"devicesAddrs",
",",
"volumes",
",",
"volumeAttachments",
",",
"arg",
".",
"CharmProfiles",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"arg",
".",
"InstanceId",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Machines",
"{",
"err",
":=",
"setInstanceInfo",
"(",
"arg",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetInstanceInfo sets the provider specific machine id, nonce,
// metadata and network info for each given machine. Once set, the
// instance id cannot be changed. | [
"SetInstanceInfo",
"sets",
"the",
"provider",
"specific",
"machine",
"id",
"nonce",
"metadata",
"and",
"network",
"info",
"for",
"each",
"given",
"machine",
".",
"Once",
"set",
"the",
"instance",
"id",
"cannot",
"be",
"changed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L776-L819 |
4,587 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | WatchMachineErrorRetry | func (p *ProvisionerAPI) WatchMachineErrorRetry() (params.NotifyWatchResult, error) {
result := params.NotifyWatchResult{}
if !p.authorizer.AuthController() {
return result, common.ErrPerm
}
watch := newWatchMachineErrorRetry()
// Consume any initial event and forward it to the result.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = p.resources.Register(watch)
} else {
return result, watcher.EnsureErr(watch)
}
return result, nil
} | go | func (p *ProvisionerAPI) WatchMachineErrorRetry() (params.NotifyWatchResult, error) {
result := params.NotifyWatchResult{}
if !p.authorizer.AuthController() {
return result, common.ErrPerm
}
watch := newWatchMachineErrorRetry()
// Consume any initial event and forward it to the result.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = p.resources.Register(watch)
} else {
return result, watcher.EnsureErr(watch)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"WatchMachineErrorRetry",
"(",
")",
"(",
"params",
".",
"NotifyWatchResult",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"NotifyWatchResult",
"{",
"}",
"\n",
"if",
"!",
"p",
".",
"authorizer",
".",
"AuthController",
"(",
")",
"{",
"return",
"result",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"watch",
":=",
"newWatchMachineErrorRetry",
"(",
")",
"\n",
"// Consume any initial event and forward it to the result.",
"if",
"_",
",",
"ok",
":=",
"<-",
"watch",
".",
"Changes",
"(",
")",
";",
"ok",
"{",
"result",
".",
"NotifyWatcherId",
"=",
"p",
".",
"resources",
".",
"Register",
"(",
"watch",
")",
"\n",
"}",
"else",
"{",
"return",
"result",
",",
"watcher",
".",
"EnsureErr",
"(",
"watch",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // WatchMachineErrorRetry returns a NotifyWatcher that notifies when
// the provisioner should retry provisioning machines with transient errors. | [
"WatchMachineErrorRetry",
"returns",
"a",
"NotifyWatcher",
"that",
"notifies",
"when",
"the",
"provisioner",
"should",
"retry",
"provisioning",
"machines",
"with",
"transient",
"errors",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L823-L836 |
4,588 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | ReleaseContainerAddresses | func (p *ProvisionerAPI) ReleaseContainerAddresses(args params.Entities) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return result, errors.Trace(err)
}
// Loop over the passed container tags.
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
logger.Warningf("failed to parse machine tag %q: %v", entity.Tag, err)
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
// The auth function (canAccess) checks that the machine is a
// top level machine (we filter those out next) or that the
// machine has the host as a parent.
guest, err := p.getMachine(canAccess, tag)
if err != nil {
logger.Warningf("failed to get machine %q: %v", tag, err)
result.Results[i].Error = common.ServerError(err)
continue
} else if !guest.IsContainer() {
err = errors.Errorf("cannot mark addresses for removal for %q: not a container", tag)
result.Results[i].Error = common.ServerError(err)
continue
}
// TODO(dimitern): Release those via the provider once we have
// Environ.ReleaseContainerAddresses. See LP bug http://pad.lv/1585878
err = guest.RemoveAllAddresses()
if err != nil {
logger.Warningf("failed to remove container %q addresses: %v", tag, err)
result.Results[i].Error = common.ServerError(err)
continue
}
}
return result, nil
} | go | func (p *ProvisionerAPI) ReleaseContainerAddresses(args params.Entities) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return result, errors.Trace(err)
}
// Loop over the passed container tags.
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
logger.Warningf("failed to parse machine tag %q: %v", entity.Tag, err)
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
// The auth function (canAccess) checks that the machine is a
// top level machine (we filter those out next) or that the
// machine has the host as a parent.
guest, err := p.getMachine(canAccess, tag)
if err != nil {
logger.Warningf("failed to get machine %q: %v", tag, err)
result.Results[i].Error = common.ServerError(err)
continue
} else if !guest.IsContainer() {
err = errors.Errorf("cannot mark addresses for removal for %q: not a container", tag)
result.Results[i].Error = common.ServerError(err)
continue
}
// TODO(dimitern): Release those via the provider once we have
// Environ.ReleaseContainerAddresses. See LP bug http://pad.lv/1585878
err = guest.RemoveAllAddresses()
if err != nil {
logger.Warningf("failed to remove container %q addresses: %v", tag, err)
result.Results[i].Error = common.ServerError(err)
continue
}
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"ReleaseContainerAddresses",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"result",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Loop over the passed container tags.",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"entity",
".",
"Tag",
",",
"err",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// The auth function (canAccess) checks that the machine is a",
"// top level machine (we filter those out next) or that the",
"// machine has the host as a parent.",
"guest",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"tag",
",",
"err",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"else",
"if",
"!",
"guest",
".",
"IsContainer",
"(",
")",
"{",
"err",
"=",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// TODO(dimitern): Release those via the provider once we have",
"// Environ.ReleaseContainerAddresses. See LP bug http://pad.lv/1585878",
"err",
"=",
"guest",
".",
"RemoveAllAddresses",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"tag",
",",
"err",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // ReleaseContainerAddresses finds addresses allocated to a container and marks
// them as Dead, to be released and removed. It accepts container tags as
// arguments. | [
"ReleaseContainerAddresses",
"finds",
"addresses",
"allocated",
"to",
"a",
"container",
"and",
"marks",
"them",
"as",
"Dead",
"to",
"be",
"released",
"and",
"removed",
".",
"It",
"accepts",
"container",
"tags",
"as",
"arguments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L853-L897 |
4,589 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | prepareContainerAccessEnvironment | func (p *ProvisionerAPI) prepareContainerAccessEnvironment() (environs.Environ, *state.Machine, common.AuthFunc, error) {
env, err := environs.GetEnviron(p.configGetter, environs.New)
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
// TODO(jam): 2017-02-01 NetworkingEnvironFromModelConfig used to do this, but it doesn't feel good
if env.Config().Type() == "dummy" {
return nil, nil, nil, errors.NotSupportedf("dummy provider network config")
}
canAccess, err := p.getAuthFunc()
if err != nil {
return nil, nil, nil, errors.Annotate(err, "cannot authenticate request")
}
hostAuthTag := p.authorizer.GetAuthTag()
if hostAuthTag == nil {
return nil, nil, nil, errors.Errorf("authenticated entity tag is nil")
}
hostTag, err := names.ParseMachineTag(hostAuthTag.String())
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
host, err := p.getMachine(canAccess, hostTag)
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
return env, host, canAccess, nil
} | go | func (p *ProvisionerAPI) prepareContainerAccessEnvironment() (environs.Environ, *state.Machine, common.AuthFunc, error) {
env, err := environs.GetEnviron(p.configGetter, environs.New)
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
// TODO(jam): 2017-02-01 NetworkingEnvironFromModelConfig used to do this, but it doesn't feel good
if env.Config().Type() == "dummy" {
return nil, nil, nil, errors.NotSupportedf("dummy provider network config")
}
canAccess, err := p.getAuthFunc()
if err != nil {
return nil, nil, nil, errors.Annotate(err, "cannot authenticate request")
}
hostAuthTag := p.authorizer.GetAuthTag()
if hostAuthTag == nil {
return nil, nil, nil, errors.Errorf("authenticated entity tag is nil")
}
hostTag, err := names.ParseMachineTag(hostAuthTag.String())
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
host, err := p.getMachine(canAccess, hostTag)
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
return env, host, canAccess, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"prepareContainerAccessEnvironment",
"(",
")",
"(",
"environs",
".",
"Environ",
",",
"*",
"state",
".",
"Machine",
",",
"common",
".",
"AuthFunc",
",",
"error",
")",
"{",
"env",
",",
"err",
":=",
"environs",
".",
"GetEnviron",
"(",
"p",
".",
"configGetter",
",",
"environs",
".",
"New",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// TODO(jam): 2017-02-01 NetworkingEnvironFromModelConfig used to do this, but it doesn't feel good",
"if",
"env",
".",
"Config",
"(",
")",
".",
"Type",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"hostAuthTag",
":=",
"p",
".",
"authorizer",
".",
"GetAuthTag",
"(",
")",
"\n",
"if",
"hostAuthTag",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"hostTag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"hostAuthTag",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"host",
",",
"err",
":=",
"p",
".",
"getMachine",
"(",
"canAccess",
",",
"hostTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"env",
",",
"host",
",",
"canAccess",
",",
"nil",
"\n",
"}"
] | // prepareContainerAccessEnvironment retrieves the environment, host machine, and access
// for working with containers. | [
"prepareContainerAccessEnvironment",
"retrieves",
"the",
"environment",
"host",
"machine",
"and",
"access",
"for",
"working",
"with",
"containers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L1158-L1185 |
4,590 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | HostChangesForContainers | func (p *ProvisionerAPI) HostChangesForContainers(args params.Entities) (params.HostNetworkChangeResults, error) {
ctx := &hostChangesContext{
result: params.HostNetworkChangeResults{
Results: make([]params.HostNetworkChange, len(args.Entities)),
},
}
if err := p.processEachContainer(args, ctx); err != nil {
return ctx.result, errors.Trace(err)
}
return ctx.result, nil
} | go | func (p *ProvisionerAPI) HostChangesForContainers(args params.Entities) (params.HostNetworkChangeResults, error) {
ctx := &hostChangesContext{
result: params.HostNetworkChangeResults{
Results: make([]params.HostNetworkChange, len(args.Entities)),
},
}
if err := p.processEachContainer(args, ctx); err != nil {
return ctx.result, errors.Trace(err)
}
return ctx.result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"HostChangesForContainers",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"HostNetworkChangeResults",
",",
"error",
")",
"{",
"ctx",
":=",
"&",
"hostChangesContext",
"{",
"result",
":",
"params",
".",
"HostNetworkChangeResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"HostNetworkChange",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"processEachContainer",
"(",
"args",
",",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ctx",
".",
"result",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"result",
",",
"nil",
"\n",
"}"
] | // HostChangesForContainers returns the set of changes that need to be done
// to the host machine to prepare it for the containers to be created.
// Pass in a list of the containers that you want the changes for. | [
"HostChangesForContainers",
"returns",
"the",
"set",
"of",
"changes",
"that",
"need",
"to",
"be",
"done",
"to",
"the",
"host",
"machine",
"to",
"prepare",
"it",
"for",
"the",
"containers",
"to",
"be",
"created",
".",
"Pass",
"in",
"a",
"list",
"of",
"the",
"containers",
"that",
"you",
"want",
"the",
"changes",
"for",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L1230-L1240 |
4,591 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | SetError | func (ctx *containerProfileContext) SetError(idx int, err error) {
ctx.result.Results[idx].Error = common.ServerError(err)
} | go | func (ctx *containerProfileContext) SetError(idx int, err error) {
ctx.result.Results[idx].Error = common.ServerError(err)
} | [
"func",
"(",
"ctx",
"*",
"containerProfileContext",
")",
"SetError",
"(",
"idx",
"int",
",",
"err",
"error",
")",
"{",
"ctx",
".",
"result",
".",
"Results",
"[",
"idx",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}"
] | // Implements perContainerHandler.SetError | [
"Implements",
"perContainerHandler",
".",
"SetError"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L1288-L1290 |
4,592 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | SetModificationStatus | func (p *ProvisionerAPI) SetModificationStatus(args params.SetStatus) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return result, errors.Trace(err)
}
for i, arg := range args.Entities {
err = p.setOneModificationStatus(canAccess, arg)
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | go | func (p *ProvisionerAPI) SetModificationStatus(args params.SetStatus) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return result, errors.Trace(err)
}
for i, arg := range args.Entities {
err = p.setOneModificationStatus(canAccess, arg)
result.Results[i].Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"SetModificationStatus",
"(",
"args",
"params",
".",
"SetStatus",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"result",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"err",
"=",
"p",
".",
"setOneModificationStatus",
"(",
"canAccess",
",",
"arg",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetModificationStatus updates the instance whilst changes are occurring. This
// is different from SetStatus and SetInstanceStatus, by the fact this holds
// information about the ongoing changes that are happening to instances.
// Consider LXD Profile updates that can modify a instance, but may not cause
// the instance to be placed into a error state. This modification status
// serves the purpose of highlighting that to the operator.
// Only machine tags are accepted. | [
"SetModificationStatus",
"updates",
"the",
"instance",
"whilst",
"changes",
"are",
"occurring",
".",
"This",
"is",
"different",
"from",
"SetStatus",
"and",
"SetInstanceStatus",
"by",
"the",
"fact",
"this",
"holds",
"information",
"about",
"the",
"ongoing",
"changes",
"that",
"are",
"happening",
"to",
"instances",
".",
"Consider",
"LXD",
"Profile",
"updates",
"that",
"can",
"modify",
"a",
"instance",
"but",
"may",
"not",
"cause",
"the",
"instance",
"to",
"be",
"placed",
"into",
"a",
"error",
"state",
".",
"This",
"modification",
"status",
"serves",
"the",
"purpose",
"of",
"highlighting",
"that",
"to",
"the",
"operator",
".",
"Only",
"machine",
"tags",
"are",
"accepted",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L1413-L1427 |
4,593 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | MarkMachinesForRemoval | func (p *ProvisionerAPI) MarkMachinesForRemoval(machines params.Entities) (params.ErrorResults, error) {
results := make([]params.ErrorResult, len(machines.Entities))
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return params.ErrorResults{}, errors.Trace(err)
}
for i, machine := range machines.Entities {
results[i].Error = common.ServerError(p.markOneMachineForRemoval(machine.Tag, canAccess))
}
return params.ErrorResults{Results: results}, nil
} | go | func (p *ProvisionerAPI) MarkMachinesForRemoval(machines params.Entities) (params.ErrorResults, error) {
results := make([]params.ErrorResult, len(machines.Entities))
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return params.ErrorResults{}, errors.Trace(err)
}
for i, machine := range machines.Entities {
results[i].Error = common.ServerError(p.markOneMachineForRemoval(machine.Tag, canAccess))
}
return params.ErrorResults{Results: results}, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPI",
")",
"MarkMachinesForRemoval",
"(",
"machines",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"machines",
".",
"Entities",
")",
")",
"\n",
"canAccess",
",",
"err",
":=",
"p",
".",
"getAuthFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"machine",
":=",
"range",
"machines",
".",
"Entities",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"p",
".",
"markOneMachineForRemoval",
"(",
"machine",
".",
"Tag",
",",
"canAccess",
")",
")",
"\n",
"}",
"\n",
"return",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"results",
"}",
",",
"nil",
"\n",
"}"
] | // MarkMachinesForRemoval indicates that the specified machines are
// ready to have any provider-level resources cleaned up and then be
// removed. | [
"MarkMachinesForRemoval",
"indicates",
"that",
"the",
"specified",
"machines",
"are",
"ready",
"to",
"have",
"any",
"provider",
"-",
"level",
"resources",
"cleaned",
"up",
"and",
"then",
"be",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L1462-L1473 |
4,594 | juju/juju | apiserver/facades/agent/provisioner/provisioner.go | RemoveUpgradeCharmProfileData | func (p *ProvisionerAPIV8) RemoveUpgradeCharmProfileData(args params.Entities) (params.ErrorResults, error) {
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
return results, nil
} | go | func (p *ProvisionerAPIV8) RemoveUpgradeCharmProfileData(args params.Entities) (params.ErrorResults, error) {
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
return results, nil
} | [
"func",
"(",
"p",
"*",
"ProvisionerAPIV8",
")",
"RemoveUpgradeCharmProfileData",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"results",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // RemoveUpgradeCharmProfileData completely removes the instance charm profile
// data for a machine, even if the machine is dead.
//
// Remove in juju 3. Upgrading existing charm profiles is now handled
// in the instance mutater worker. This is for compatibility only with
// older provisioners. | [
"RemoveUpgradeCharmProfileData",
"completely",
"removes",
"the",
"instance",
"charm",
"profile",
"data",
"for",
"a",
"machine",
"even",
"if",
"the",
"machine",
"is",
"dead",
".",
"Remove",
"in",
"juju",
"3",
".",
"Upgrading",
"existing",
"charm",
"profiles",
"is",
"now",
"handled",
"in",
"the",
"instance",
"mutater",
"worker",
".",
"This",
"is",
"for",
"compatibility",
"only",
"with",
"older",
"provisioners",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/provisioner.go#L1558-L1563 |
4,595 | juju/juju | caas/kubernetes/provider/dockerconfig.go | extractRegistryURL | func extractRegistryURL(imagePath string) (string, error) {
imageNamed, err := reference.ParseNormalizedNamed(imagePath)
if err != nil {
return "", errors.Annotate(err, "extracting registry from path")
}
return reference.Domain(imageNamed), nil
} | go | func extractRegistryURL(imagePath string) (string, error) {
imageNamed, err := reference.ParseNormalizedNamed(imagePath)
if err != nil {
return "", errors.Annotate(err, "extracting registry from path")
}
return reference.Domain(imageNamed), nil
} | [
"func",
"extractRegistryURL",
"(",
"imagePath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"imageNamed",
",",
"err",
":=",
"reference",
".",
"ParseNormalizedNamed",
"(",
"imagePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"reference",
".",
"Domain",
"(",
"imageNamed",
")",
",",
"nil",
"\n",
"}"
] | // extractRegistryName returns the registry URL part of an images path | [
"extractRegistryName",
"returns",
"the",
"registry",
"URL",
"part",
"of",
"an",
"images",
"path"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/dockerconfig.go#L58-L64 |
4,596 | juju/juju | worker/uniter/relation/state.go | copy | func (s *State) copy() *State {
copy := &State{
RelationId: s.RelationId,
ChangedPending: s.ChangedPending,
}
if s.Members != nil {
copy.Members = map[string]int64{}
for m, v := range s.Members {
copy.Members[m] = v
}
}
return copy
} | go | func (s *State) copy() *State {
copy := &State{
RelationId: s.RelationId,
ChangedPending: s.ChangedPending,
}
if s.Members != nil {
copy.Members = map[string]int64{}
for m, v := range s.Members {
copy.Members[m] = v
}
}
return copy
} | [
"func",
"(",
"s",
"*",
"State",
")",
"copy",
"(",
")",
"*",
"State",
"{",
"copy",
":=",
"&",
"State",
"{",
"RelationId",
":",
"s",
".",
"RelationId",
",",
"ChangedPending",
":",
"s",
".",
"ChangedPending",
",",
"}",
"\n",
"if",
"s",
".",
"Members",
"!=",
"nil",
"{",
"copy",
".",
"Members",
"=",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
"\n",
"for",
"m",
",",
"v",
":=",
"range",
"s",
".",
"Members",
"{",
"copy",
".",
"Members",
"[",
"m",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"copy",
"\n",
"}"
] | // copy returns an independent copy of the state. | [
"copy",
"returns",
"an",
"independent",
"copy",
"of",
"the",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/relation/state.go#L38-L50 |
4,597 | juju/juju | worker/uniter/relation/state.go | Validate | func (s *State) Validate(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "inappropriate %q for %q", hi.Kind, hi.RemoteUnit)
if hi.RelationId != s.RelationId {
return fmt.Errorf("expected relation %d, got relation %d", s.RelationId, hi.RelationId)
}
if s.Members == nil {
return fmt.Errorf(`relation is broken and cannot be changed further`)
}
unit, kind := hi.RemoteUnit, hi.Kind
if kind == hooks.RelationBroken {
if len(s.Members) == 0 {
return nil
}
return fmt.Errorf(`cannot run "relation-broken" while units still present`)
}
if s.ChangedPending != "" {
if unit != s.ChangedPending || kind != hooks.RelationChanged {
return fmt.Errorf(`expected "relation-changed" for %q`, s.ChangedPending)
}
} else if _, joined := s.Members[unit]; joined && kind == hooks.RelationJoined {
return fmt.Errorf("unit already joined")
} else if !joined && kind != hooks.RelationJoined {
return fmt.Errorf("unit has not joined")
}
return nil
} | go | func (s *State) Validate(hi hook.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "inappropriate %q for %q", hi.Kind, hi.RemoteUnit)
if hi.RelationId != s.RelationId {
return fmt.Errorf("expected relation %d, got relation %d", s.RelationId, hi.RelationId)
}
if s.Members == nil {
return fmt.Errorf(`relation is broken and cannot be changed further`)
}
unit, kind := hi.RemoteUnit, hi.Kind
if kind == hooks.RelationBroken {
if len(s.Members) == 0 {
return nil
}
return fmt.Errorf(`cannot run "relation-broken" while units still present`)
}
if s.ChangedPending != "" {
if unit != s.ChangedPending || kind != hooks.RelationChanged {
return fmt.Errorf(`expected "relation-changed" for %q`, s.ChangedPending)
}
} else if _, joined := s.Members[unit]; joined && kind == hooks.RelationJoined {
return fmt.Errorf("unit already joined")
} else if !joined && kind != hooks.RelationJoined {
return fmt.Errorf("unit has not joined")
}
return nil
} | [
"func",
"(",
"s",
"*",
"State",
")",
"Validate",
"(",
"hi",
"hook",
".",
"Info",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"hi",
".",
"Kind",
",",
"hi",
".",
"RemoteUnit",
")",
"\n",
"if",
"hi",
".",
"RelationId",
"!=",
"s",
".",
"RelationId",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"RelationId",
",",
"hi",
".",
"RelationId",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Members",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"`relation is broken and cannot be changed further`",
")",
"\n",
"}",
"\n",
"unit",
",",
"kind",
":=",
"hi",
".",
"RemoteUnit",
",",
"hi",
".",
"Kind",
"\n",
"if",
"kind",
"==",
"hooks",
".",
"RelationBroken",
"{",
"if",
"len",
"(",
"s",
".",
"Members",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"`cannot run \"relation-broken\" while units still present`",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"ChangedPending",
"!=",
"\"",
"\"",
"{",
"if",
"unit",
"!=",
"s",
".",
"ChangedPending",
"||",
"kind",
"!=",
"hooks",
".",
"RelationChanged",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"`expected \"relation-changed\" for %q`",
",",
"s",
".",
"ChangedPending",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"_",
",",
"joined",
":=",
"s",
".",
"Members",
"[",
"unit",
"]",
";",
"joined",
"&&",
"kind",
"==",
"hooks",
".",
"RelationJoined",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"!",
"joined",
"&&",
"kind",
"!=",
"hooks",
".",
"RelationJoined",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate returns an error if the supplied hook.Info does not represent
// a valid change to the relation 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. | [
"Validate",
"returns",
"an",
"error",
"if",
"the",
"supplied",
"hook",
".",
"Info",
"does",
"not",
"represent",
"a",
"valid",
"change",
"to",
"the",
"relation",
"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",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/relation/state.go#L56-L81 |
4,598 | juju/juju | worker/uniter/relation/state.go | ReadStateDir | func ReadStateDir(dirPath string, relationId int) (d *StateDir, err error) {
d = &StateDir{
filepath.Join(dirPath, strconv.Itoa(relationId)),
State{relationId, map[string]int64{}, ""},
}
defer errors.DeferredAnnotatef(&err, "cannot load relation state from %q", d.path)
if _, err := os.Stat(d.path); os.IsNotExist(err) {
return d, nil
} else if err != nil {
return nil, err
}
fis, err := ioutil.ReadDir(d.path)
if err != nil {
return nil, err
}
for _, fi := range fis {
// Entries with names ending in "-" followed by an integer must be
// files containing valid unit data; all other names are ignored.
name := fi.Name()
i := strings.LastIndex(name, "-")
if i == -1 {
continue
}
svcName := name[:i]
unitId := name[i+1:]
if _, err := strconv.Atoi(unitId); err != nil {
continue
}
unitName := svcName + "/" + unitId
var info diskInfo
if err = utils.ReadYaml(filepath.Join(d.path, name), &info); err != nil {
return nil, fmt.Errorf("invalid unit file %q: %v", name, err)
}
if info.ChangeVersion == nil {
return nil, fmt.Errorf(`invalid unit file %q: "changed-version" not set`, name)
}
d.state.Members[unitName] = *info.ChangeVersion
if info.ChangedPending {
if d.state.ChangedPending != "" {
return nil, fmt.Errorf("%q and %q both have pending changed hooks", d.state.ChangedPending, unitName)
}
d.state.ChangedPending = unitName
}
}
return d, nil
} | go | func ReadStateDir(dirPath string, relationId int) (d *StateDir, err error) {
d = &StateDir{
filepath.Join(dirPath, strconv.Itoa(relationId)),
State{relationId, map[string]int64{}, ""},
}
defer errors.DeferredAnnotatef(&err, "cannot load relation state from %q", d.path)
if _, err := os.Stat(d.path); os.IsNotExist(err) {
return d, nil
} else if err != nil {
return nil, err
}
fis, err := ioutil.ReadDir(d.path)
if err != nil {
return nil, err
}
for _, fi := range fis {
// Entries with names ending in "-" followed by an integer must be
// files containing valid unit data; all other names are ignored.
name := fi.Name()
i := strings.LastIndex(name, "-")
if i == -1 {
continue
}
svcName := name[:i]
unitId := name[i+1:]
if _, err := strconv.Atoi(unitId); err != nil {
continue
}
unitName := svcName + "/" + unitId
var info diskInfo
if err = utils.ReadYaml(filepath.Join(d.path, name), &info); err != nil {
return nil, fmt.Errorf("invalid unit file %q: %v", name, err)
}
if info.ChangeVersion == nil {
return nil, fmt.Errorf(`invalid unit file %q: "changed-version" not set`, name)
}
d.state.Members[unitName] = *info.ChangeVersion
if info.ChangedPending {
if d.state.ChangedPending != "" {
return nil, fmt.Errorf("%q and %q both have pending changed hooks", d.state.ChangedPending, unitName)
}
d.state.ChangedPending = unitName
}
}
return d, nil
} | [
"func",
"ReadStateDir",
"(",
"dirPath",
"string",
",",
"relationId",
"int",
")",
"(",
"d",
"*",
"StateDir",
",",
"err",
"error",
")",
"{",
"d",
"=",
"&",
"StateDir",
"{",
"filepath",
".",
"Join",
"(",
"dirPath",
",",
"strconv",
".",
"Itoa",
"(",
"relationId",
")",
")",
",",
"State",
"{",
"relationId",
",",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
",",
"\"",
"\"",
"}",
",",
"}",
"\n",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"d",
".",
"path",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"d",
".",
"path",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"d",
",",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fis",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"d",
".",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"// Entries with names ending in \"-\" followed by an integer must be",
"// files containing valid unit data; all other names are ignored.",
"name",
":=",
"fi",
".",
"Name",
"(",
")",
"\n",
"i",
":=",
"strings",
".",
"LastIndex",
"(",
"name",
",",
"\"",
"\"",
")",
"\n",
"if",
"i",
"==",
"-",
"1",
"{",
"continue",
"\n",
"}",
"\n",
"svcName",
":=",
"name",
"[",
":",
"i",
"]",
"\n",
"unitId",
":=",
"name",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"if",
"_",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"unitId",
")",
";",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"unitName",
":=",
"svcName",
"+",
"\"",
"\"",
"+",
"unitId",
"\n",
"var",
"info",
"diskInfo",
"\n",
"if",
"err",
"=",
"utils",
".",
"ReadYaml",
"(",
"filepath",
".",
"Join",
"(",
"d",
".",
"path",
",",
"name",
")",
",",
"&",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"info",
".",
"ChangeVersion",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"`invalid unit file %q: \"changed-version\" not set`",
",",
"name",
")",
"\n",
"}",
"\n",
"d",
".",
"state",
".",
"Members",
"[",
"unitName",
"]",
"=",
"*",
"info",
".",
"ChangeVersion",
"\n",
"if",
"info",
".",
"ChangedPending",
"{",
"if",
"d",
".",
"state",
".",
"ChangedPending",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"d",
".",
"state",
".",
"ChangedPending",
",",
"unitName",
")",
"\n",
"}",
"\n",
"d",
".",
"state",
".",
"ChangedPending",
"=",
"unitName",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"d",
",",
"nil",
"\n",
"}"
] | // ReadStateDir loads a StateDir from the subdirectory of dirPath named
// for the supplied RelationId. If the directory does not exist, no error
// is returned, | [
"ReadStateDir",
"loads",
"a",
"StateDir",
"from",
"the",
"subdirectory",
"of",
"dirPath",
"named",
"for",
"the",
"supplied",
"RelationId",
".",
"If",
"the",
"directory",
"does",
"not",
"exist",
"no",
"error",
"is",
"returned"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/relation/state.go#L104-L149 |
4,599 | juju/juju | worker/uniter/relation/state.go | ReadAllStateDirs | func ReadAllStateDirs(dirPath string) (dirs map[int]*StateDir, err error) {
defer errors.DeferredAnnotatef(&err, "cannot load relations 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
}
dirs = map[int]*StateDir{}
for _, fi := range fis {
// Entries with integer names must be directories containing StateDir
// data; all other names will be ignored.
relationId, err := strconv.Atoi(fi.Name())
if err != nil {
// This doesn't look like a relation.
continue
}
dir, err := ReadStateDir(dirPath, relationId)
if err != nil {
return nil, err
}
dirs[relationId] = dir
}
return dirs, nil
} | go | func ReadAllStateDirs(dirPath string) (dirs map[int]*StateDir, err error) {
defer errors.DeferredAnnotatef(&err, "cannot load relations 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
}
dirs = map[int]*StateDir{}
for _, fi := range fis {
// Entries with integer names must be directories containing StateDir
// data; all other names will be ignored.
relationId, err := strconv.Atoi(fi.Name())
if err != nil {
// This doesn't look like a relation.
continue
}
dir, err := ReadStateDir(dirPath, relationId)
if err != nil {
return nil, err
}
dirs[relationId] = dir
}
return dirs, nil
} | [
"func",
"ReadAllStateDirs",
"(",
"dirPath",
"string",
")",
"(",
"dirs",
"map",
"[",
"int",
"]",
"*",
"StateDir",
",",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"dirPath",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dirPath",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fis",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"dirPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"dirs",
"=",
"map",
"[",
"int",
"]",
"*",
"StateDir",
"{",
"}",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"// Entries with integer names must be directories containing StateDir",
"// data; all other names will be ignored.",
"relationId",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// This doesn't look like a relation.",
"continue",
"\n",
"}",
"\n",
"dir",
",",
"err",
":=",
"ReadStateDir",
"(",
"dirPath",
",",
"relationId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"dirs",
"[",
"relationId",
"]",
"=",
"dir",
"\n",
"}",
"\n",
"return",
"dirs",
",",
"nil",
"\n",
"}"
] | // ReadAllStateDirs loads and returns every StateDir persisted directly inside
// the supplied dirPath. If dirPath does not exist, no error is returned. | [
"ReadAllStateDirs",
"loads",
"and",
"returns",
"every",
"StateDir",
"persisted",
"directly",
"inside",
"the",
"supplied",
"dirPath",
".",
"If",
"dirPath",
"does",
"not",
"exist",
"no",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/relation/state.go#L153-L180 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.