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
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,400 | juju/juju | state/volume.go | PlanInfo | func (v *volumeAttachmentPlan) PlanInfo() (VolumeAttachmentPlanInfo, error) {
if v.doc.PlanInfo == nil {
return VolumeAttachmentPlanInfo{}, errors.NotProvisionedf("volume attachment plan %q on %q", v.doc.Volume, v.doc.Machine)
}
return *v.doc.PlanInfo, nil
} | go | func (v *volumeAttachmentPlan) PlanInfo() (VolumeAttachmentPlanInfo, error) {
if v.doc.PlanInfo == nil {
return VolumeAttachmentPlanInfo{}, errors.NotProvisionedf("volume attachment plan %q on %q", v.doc.Volume, v.doc.Machine)
}
return *v.doc.PlanInfo, nil
} | [
"func",
"(",
"v",
"*",
"volumeAttachmentPlan",
")",
"PlanInfo",
"(",
")",
"(",
"VolumeAttachmentPlanInfo",
",",
"error",
")",
"{",
"if",
"v",
".",
"doc",
".",
"PlanInfo",
"==",
"nil",
"{",
"return",
"VolumeAttachmentPlanInfo",
"{",
"}",
",",
"errors",
".",
"NotProvisionedf",
"(",
"\"",
"\"",
",",
"v",
".",
"doc",
".",
"Volume",
",",
"v",
".",
"doc",
".",
"Machine",
")",
"\n",
"}",
"\n",
"return",
"*",
"v",
".",
"doc",
".",
"PlanInfo",
",",
"nil",
"\n",
"}"
] | // PlanInfo is required to implement VolumeAttachment. | [
"PlanInfo",
"is",
"required",
"to",
"implement",
"VolumeAttachment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L335-L340 |
3,401 | juju/juju | state/volume.go | Volume | func (v *volumeAttachment) Volume() names.VolumeTag {
return names.NewVolumeTag(v.doc.Volume)
} | go | func (v *volumeAttachment) Volume() names.VolumeTag {
return names.NewVolumeTag(v.doc.Volume)
} | [
"func",
"(",
"v",
"*",
"volumeAttachment",
")",
"Volume",
"(",
")",
"names",
".",
"VolumeTag",
"{",
"return",
"names",
".",
"NewVolumeTag",
"(",
"v",
".",
"doc",
".",
"Volume",
")",
"\n",
"}"
] | // Volume is required to implement VolumeAttachment. | [
"Volume",
"is",
"required",
"to",
"implement",
"VolumeAttachment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L350-L352 |
3,402 | juju/juju | state/volume.go | Info | func (v *volumeAttachment) Info() (VolumeAttachmentInfo, error) {
if v.doc.Info == nil {
host := storageAttachmentHost(v.doc.Host)
return VolumeAttachmentInfo{}, errors.NotProvisionedf("volume attachment %q on %q", v.doc.Volume, names.ReadableString(host))
}
return *v.doc.Info, nil
} | go | func (v *volumeAttachment) Info() (VolumeAttachmentInfo, error) {
if v.doc.Info == nil {
host := storageAttachmentHost(v.doc.Host)
return VolumeAttachmentInfo{}, errors.NotProvisionedf("volume attachment %q on %q", v.doc.Volume, names.ReadableString(host))
}
return *v.doc.Info, nil
} | [
"func",
"(",
"v",
"*",
"volumeAttachment",
")",
"Info",
"(",
")",
"(",
"VolumeAttachmentInfo",
",",
"error",
")",
"{",
"if",
"v",
".",
"doc",
".",
"Info",
"==",
"nil",
"{",
"host",
":=",
"storageAttachmentHost",
"(",
"v",
".",
"doc",
".",
"Host",
")",
"\n",
"return",
"VolumeAttachmentInfo",
"{",
"}",
",",
"errors",
".",
"NotProvisionedf",
"(",
"\"",
"\"",
",",
"v",
".",
"doc",
".",
"Volume",
",",
"names",
".",
"ReadableString",
"(",
"host",
")",
")",
"\n",
"}",
"\n",
"return",
"*",
"v",
".",
"doc",
".",
"Info",
",",
"nil",
"\n",
"}"
] | // Info is required to implement VolumeAttachment. | [
"Info",
"is",
"required",
"to",
"implement",
"VolumeAttachment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L365-L371 |
3,403 | juju/juju | state/volume.go | Params | func (v *volumeAttachment) Params() (VolumeAttachmentParams, bool) {
if v.doc.Params == nil {
return VolumeAttachmentParams{}, false
}
return *v.doc.Params, true
} | go | func (v *volumeAttachment) Params() (VolumeAttachmentParams, bool) {
if v.doc.Params == nil {
return VolumeAttachmentParams{}, false
}
return *v.doc.Params, true
} | [
"func",
"(",
"v",
"*",
"volumeAttachment",
")",
"Params",
"(",
")",
"(",
"VolumeAttachmentParams",
",",
"bool",
")",
"{",
"if",
"v",
".",
"doc",
".",
"Params",
"==",
"nil",
"{",
"return",
"VolumeAttachmentParams",
"{",
"}",
",",
"false",
"\n",
"}",
"\n",
"return",
"*",
"v",
".",
"doc",
".",
"Params",
",",
"true",
"\n",
"}"
] | // Params is required to implement VolumeAttachment. | [
"Params",
"is",
"required",
"to",
"implement",
"VolumeAttachment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L374-L379 |
3,404 | juju/juju | state/volume.go | Volume | func (sb *storageBackend) Volume(tag names.VolumeTag) (Volume, error) {
v, err := getVolumeByTag(sb.mb, tag)
return v, err
} | go | func (sb *storageBackend) Volume(tag names.VolumeTag) (Volume, error) {
v, err := getVolumeByTag(sb.mb, tag)
return v, err
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"Volume",
"(",
"tag",
"names",
".",
"VolumeTag",
")",
"(",
"Volume",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"getVolumeByTag",
"(",
"sb",
".",
"mb",
",",
"tag",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // Volume returns the Volume with the specified name. | [
"Volume",
"returns",
"the",
"Volume",
"with",
"the",
"specified",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L382-L385 |
3,405 | juju/juju | state/volume.go | StorageInstanceVolume | func (sb *storageBackend) StorageInstanceVolume(tag names.StorageTag) (Volume, error) {
v, err := sb.storageInstanceVolume(tag)
return v, err
} | go | func (sb *storageBackend) StorageInstanceVolume(tag names.StorageTag) (Volume, error) {
v, err := sb.storageInstanceVolume(tag)
return v, err
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"StorageInstanceVolume",
"(",
"tag",
"names",
".",
"StorageTag",
")",
"(",
"Volume",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"sb",
".",
"storageInstanceVolume",
"(",
"tag",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // StorageInstanceVolume returns the Volume assigned to the specified
// storage instance. | [
"StorageInstanceVolume",
"returns",
"the",
"Volume",
"assigned",
"to",
"the",
"specified",
"storage",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L466-L469 |
3,406 | juju/juju | state/volume.go | VolumeAttachment | func (sb *storageBackend) VolumeAttachment(host names.Tag, volume names.VolumeTag) (VolumeAttachment, error) {
coll, cleanup := sb.mb.db().GetCollection(volumeAttachmentsC)
defer cleanup()
var att volumeAttachment
err := coll.FindId(volumeAttachmentId(host.Id(), volume.Id())).One(&att.doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("volume %q on %q", volume.Id(), names.ReadableString(host))
} else if err != nil {
return nil, errors.Annotatef(err, "getting volume %q on %q", volume.Id(), names.ReadableString(host))
}
return &att, nil
} | go | func (sb *storageBackend) VolumeAttachment(host names.Tag, volume names.VolumeTag) (VolumeAttachment, error) {
coll, cleanup := sb.mb.db().GetCollection(volumeAttachmentsC)
defer cleanup()
var att volumeAttachment
err := coll.FindId(volumeAttachmentId(host.Id(), volume.Id())).One(&att.doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("volume %q on %q", volume.Id(), names.ReadableString(host))
} else if err != nil {
return nil, errors.Annotatef(err, "getting volume %q on %q", volume.Id(), names.ReadableString(host))
}
return &att, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"VolumeAttachment",
"(",
"host",
"names",
".",
"Tag",
",",
"volume",
"names",
".",
"VolumeTag",
")",
"(",
"VolumeAttachment",
",",
"error",
")",
"{",
"coll",
",",
"cleanup",
":=",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"volumeAttachmentsC",
")",
"\n",
"defer",
"cleanup",
"(",
")",
"\n\n",
"var",
"att",
"volumeAttachment",
"\n",
"err",
":=",
"coll",
".",
"FindId",
"(",
"volumeAttachmentId",
"(",
"host",
".",
"Id",
"(",
")",
",",
"volume",
".",
"Id",
"(",
")",
")",
")",
".",
"One",
"(",
"&",
"att",
".",
"doc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
",",
"names",
".",
"ReadableString",
"(",
"host",
")",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
",",
"names",
".",
"ReadableString",
"(",
"host",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"att",
",",
"nil",
"\n",
"}"
] | // VolumeAttachment returns the VolumeAttachment corresponding to
// the specified volume and machine. | [
"VolumeAttachment",
"returns",
"the",
"VolumeAttachment",
"corresponding",
"to",
"the",
"specified",
"volume",
"and",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L473-L485 |
3,407 | juju/juju | state/volume.go | MachineVolumeAttachments | func (sb *storageBackend) MachineVolumeAttachments(machine names.MachineTag) ([]VolumeAttachment, error) {
attachments, err := sb.volumeAttachments(bson.D{{"hostid", machine.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for machine %q", machine.Id())
}
return attachments, nil
} | go | func (sb *storageBackend) MachineVolumeAttachments(machine names.MachineTag) ([]VolumeAttachment, error) {
attachments, err := sb.volumeAttachments(bson.D{{"hostid", machine.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for machine %q", machine.Id())
}
return attachments, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"MachineVolumeAttachments",
"(",
"machine",
"names",
".",
"MachineTag",
")",
"(",
"[",
"]",
"VolumeAttachment",
",",
"error",
")",
"{",
"attachments",
",",
"err",
":=",
"sb",
".",
"volumeAttachments",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"machine",
".",
"Id",
"(",
")",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"machine",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"attachments",
",",
"nil",
"\n",
"}"
] | // MachineVolumeAttachments returns all of the VolumeAttachments for the
// specified machine. | [
"MachineVolumeAttachments",
"returns",
"all",
"of",
"the",
"VolumeAttachments",
"for",
"the",
"specified",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L503-L509 |
3,408 | juju/juju | state/volume.go | UnitVolumeAttachments | func (sb *storageBackend) UnitVolumeAttachments(unit names.UnitTag) ([]VolumeAttachment, error) {
attachments, err := sb.volumeAttachments(bson.D{{"hostid", unit.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for unit %q", unit.Id())
}
return attachments, nil
} | go | func (sb *storageBackend) UnitVolumeAttachments(unit names.UnitTag) ([]VolumeAttachment, error) {
attachments, err := sb.volumeAttachments(bson.D{{"hostid", unit.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for unit %q", unit.Id())
}
return attachments, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"UnitVolumeAttachments",
"(",
"unit",
"names",
".",
"UnitTag",
")",
"(",
"[",
"]",
"VolumeAttachment",
",",
"error",
")",
"{",
"attachments",
",",
"err",
":=",
"sb",
".",
"volumeAttachments",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"unit",
".",
"Id",
"(",
")",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"unit",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"attachments",
",",
"nil",
"\n",
"}"
] | // UnitVolumeAttachments returns all of the VolumeAttachments for the
// specified unit. | [
"UnitVolumeAttachments",
"returns",
"all",
"of",
"the",
"VolumeAttachments",
"for",
"the",
"specified",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L513-L519 |
3,409 | juju/juju | state/volume.go | VolumeAttachments | func (sb *storageBackend) VolumeAttachments(volume names.VolumeTag) ([]VolumeAttachment, error) {
attachments, err := sb.volumeAttachments(bson.D{{"volumeid", volume.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for volume %q", volume.Id())
}
return attachments, nil
} | go | func (sb *storageBackend) VolumeAttachments(volume names.VolumeTag) ([]VolumeAttachment, error) {
attachments, err := sb.volumeAttachments(bson.D{{"volumeid", volume.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for volume %q", volume.Id())
}
return attachments, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"VolumeAttachments",
"(",
"volume",
"names",
".",
"VolumeTag",
")",
"(",
"[",
"]",
"VolumeAttachment",
",",
"error",
")",
"{",
"attachments",
",",
"err",
":=",
"sb",
".",
"volumeAttachments",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"attachments",
",",
"nil",
"\n",
"}"
] | // VolumeAttachments returns all of the VolumeAttachments for the specified
// volume. | [
"VolumeAttachments",
"returns",
"all",
"of",
"the",
"VolumeAttachments",
"for",
"the",
"specified",
"volume",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L523-L529 |
3,410 | juju/juju | state/volume.go | VolumeAttachmentPlans | func (sb *storageBackend) VolumeAttachmentPlans(volume names.VolumeTag) ([]VolumeAttachmentPlan, error) {
attachmentPlans, err := sb.volumeAttachmentPlans(bson.D{{"volumeid", volume.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachment plans for volume %q", volume.Id())
}
return attachmentPlans, nil
} | go | func (sb *storageBackend) VolumeAttachmentPlans(volume names.VolumeTag) ([]VolumeAttachmentPlan, error) {
attachmentPlans, err := sb.volumeAttachmentPlans(bson.D{{"volumeid", volume.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachment plans for volume %q", volume.Id())
}
return attachmentPlans, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"VolumeAttachmentPlans",
"(",
"volume",
"names",
".",
"VolumeTag",
")",
"(",
"[",
"]",
"VolumeAttachmentPlan",
",",
"error",
")",
"{",
"attachmentPlans",
",",
"err",
":=",
"sb",
".",
"volumeAttachmentPlans",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"attachmentPlans",
",",
"nil",
"\n",
"}"
] | // VolumeAttachmentPlans returns all of the VolumeAttachmentPlans for the specified
// volume. | [
"VolumeAttachmentPlans",
"returns",
"all",
"of",
"the",
"VolumeAttachmentPlans",
"for",
"the",
"specified",
"volume",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L560-L566 |
3,411 | juju/juju | state/volume.go | removeMachineVolumesOps | func (sb *storageBackend) removeMachineVolumesOps(m *Machine) ([]txn.Op, error) {
// A machine cannot transition to Dead if it has any detachable storage
// attached, so any attachments are for machine-bound storage.
//
// Even if a volume is "non-detachable", there still exist volume
// attachments, and they may be removed independently of the volume.
// For example, the user may request that the volume be destroyed.
// This will cause the volume to become Dying, and the attachment to
// be Dying, then Dead, and finally removed. Only once the attachment
// is removed will the volume transition to Dead and then be removed.
// Therefore, there may be volumes that are bound, but not attached,
// to the machine.
machineVolumes, err := sb.volumes(bson.D{{"hostid", m.Id()}})
if err != nil {
return nil, errors.Trace(err)
}
ops := make([]txn.Op, 0, 2*len(machineVolumes)+len(m.doc.Volumes))
for _, volumeId := range m.doc.Volumes {
ops = append(ops, txn.Op{
C: volumeAttachmentsC,
Id: volumeAttachmentId(m.Id(), volumeId),
Assert: txn.DocExists,
Remove: true,
})
}
for _, v := range machineVolumes {
if v.doc.StorageId != "" {
// The volume is assigned to a storage instance;
// make sure we also remove the storage instance.
// There should be no storage attachments remaining,
// as the units must have been removed before the
// machine can be; and the storage attachments must
// have been removed before the unit can be.
ops = append(ops,
txn.Op{
C: storageInstancesC,
Id: v.doc.StorageId,
Assert: txn.DocExists,
Remove: true,
},
)
}
ops = append(ops, sb.removeVolumeOps(v.VolumeTag())...)
}
return ops, nil
} | go | func (sb *storageBackend) removeMachineVolumesOps(m *Machine) ([]txn.Op, error) {
// A machine cannot transition to Dead if it has any detachable storage
// attached, so any attachments are for machine-bound storage.
//
// Even if a volume is "non-detachable", there still exist volume
// attachments, and they may be removed independently of the volume.
// For example, the user may request that the volume be destroyed.
// This will cause the volume to become Dying, and the attachment to
// be Dying, then Dead, and finally removed. Only once the attachment
// is removed will the volume transition to Dead and then be removed.
// Therefore, there may be volumes that are bound, but not attached,
// to the machine.
machineVolumes, err := sb.volumes(bson.D{{"hostid", m.Id()}})
if err != nil {
return nil, errors.Trace(err)
}
ops := make([]txn.Op, 0, 2*len(machineVolumes)+len(m.doc.Volumes))
for _, volumeId := range m.doc.Volumes {
ops = append(ops, txn.Op{
C: volumeAttachmentsC,
Id: volumeAttachmentId(m.Id(), volumeId),
Assert: txn.DocExists,
Remove: true,
})
}
for _, v := range machineVolumes {
if v.doc.StorageId != "" {
// The volume is assigned to a storage instance;
// make sure we also remove the storage instance.
// There should be no storage attachments remaining,
// as the units must have been removed before the
// machine can be; and the storage attachments must
// have been removed before the unit can be.
ops = append(ops,
txn.Op{
C: storageInstancesC,
Id: v.doc.StorageId,
Assert: txn.DocExists,
Remove: true,
},
)
}
ops = append(ops, sb.removeVolumeOps(v.VolumeTag())...)
}
return ops, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"removeMachineVolumesOps",
"(",
"m",
"*",
"Machine",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"// A machine cannot transition to Dead if it has any detachable storage",
"// attached, so any attachments are for machine-bound storage.",
"//",
"// Even if a volume is \"non-detachable\", there still exist volume",
"// attachments, and they may be removed independently of the volume.",
"// For example, the user may request that the volume be destroyed.",
"// This will cause the volume to become Dying, and the attachment to",
"// be Dying, then Dead, and finally removed. Only once the attachment",
"// is removed will the volume transition to Dead and then be removed.",
"// Therefore, there may be volumes that are bound, but not attached,",
"// to the machine.",
"machineVolumes",
",",
"err",
":=",
"sb",
".",
"volumes",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ops",
":=",
"make",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"0",
",",
"2",
"*",
"len",
"(",
"machineVolumes",
")",
"+",
"len",
"(",
"m",
".",
"doc",
".",
"Volumes",
")",
")",
"\n",
"for",
"_",
",",
"volumeId",
":=",
"range",
"m",
".",
"doc",
".",
"Volumes",
"{",
"ops",
"=",
"append",
"(",
"ops",
",",
"txn",
".",
"Op",
"{",
"C",
":",
"volumeAttachmentsC",
",",
"Id",
":",
"volumeAttachmentId",
"(",
"m",
".",
"Id",
"(",
")",
",",
"volumeId",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Remove",
":",
"true",
",",
"}",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"machineVolumes",
"{",
"if",
"v",
".",
"doc",
".",
"StorageId",
"!=",
"\"",
"\"",
"{",
"// The volume is assigned to a storage instance;",
"// make sure we also remove the storage instance.",
"// There should be no storage attachments remaining,",
"// as the units must have been removed before the",
"// machine can be; and the storage attachments must",
"// have been removed before the unit can be.",
"ops",
"=",
"append",
"(",
"ops",
",",
"txn",
".",
"Op",
"{",
"C",
":",
"storageInstancesC",
",",
"Id",
":",
"v",
".",
"doc",
".",
"StorageId",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Remove",
":",
"true",
",",
"}",
",",
")",
"\n",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"sb",
".",
"removeVolumeOps",
"(",
"v",
".",
"VolumeTag",
"(",
")",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}"
] | // removeMachineVolumesOps returns txn.Ops to remove non-persistent volumes
// bound or attached to the specified machine. This is used when the given
// machine is being removed from state. | [
"removeMachineVolumesOps",
"returns",
"txn",
".",
"Ops",
"to",
"remove",
"non",
"-",
"persistent",
"volumes",
"bound",
"or",
"attached",
"to",
"the",
"specified",
"machine",
".",
"This",
"is",
"used",
"when",
"the",
"given",
"machine",
"is",
"being",
"removed",
"from",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L598-L644 |
3,412 | juju/juju | state/volume.go | isDetachableVolumeTag | func isDetachableVolumeTag(db Database, tag names.VolumeTag) (bool, error) {
doc, err := getVolumeDocByTag(db, tag)
if err != nil {
return false, errors.Trace(err)
}
return detachableVolumeDoc(&doc), nil
} | go | func isDetachableVolumeTag(db Database, tag names.VolumeTag) (bool, error) {
doc, err := getVolumeDocByTag(db, tag)
if err != nil {
return false, errors.Trace(err)
}
return detachableVolumeDoc(&doc), nil
} | [
"func",
"isDetachableVolumeTag",
"(",
"db",
"Database",
",",
"tag",
"names",
".",
"VolumeTag",
")",
"(",
"bool",
",",
"error",
")",
"{",
"doc",
",",
"err",
":=",
"getVolumeDocByTag",
"(",
"db",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"detachableVolumeDoc",
"(",
"&",
"doc",
")",
",",
"nil",
"\n",
"}"
] | // isDetachableVolumeTag reports whether or not the volume with the specified
// tag is detachable. | [
"isDetachableVolumeTag",
"reports",
"whether",
"or",
"not",
"the",
"volume",
"with",
"the",
"specified",
"tag",
"is",
"detachable",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L648-L654 |
3,413 | juju/juju | state/volume.go | isDetachableVolumePool | func isDetachableVolumePool(im *storageBackend, pool string) (bool, error) {
_, provider, _, err := poolStorageProvider(im, pool)
if err != nil {
return false, errors.Trace(err)
}
if provider.Scope() == storage.ScopeMachine {
// Any storage created by a machine cannot be detached from
// the machine, and must be destroyed along with it.
return false, nil
}
if provider.Dynamic() {
// NOTE(axw) In theory, we don't know ahead of time
// whether the storage will be Persistent, as the model
// allows for a dynamic storage provider to create non-
// persistent storage. None of the storage providers do
// this, so we assume it will be persistent for now.
//
// TODO(axw) get rid of the Persistent field from Volume
// and Filesystem. We only need to care whether the
// storage is dynamic and model-scoped.
return true, nil
}
// Volume is static, so it will be tied to the machine.
return false, nil
} | go | func isDetachableVolumePool(im *storageBackend, pool string) (bool, error) {
_, provider, _, err := poolStorageProvider(im, pool)
if err != nil {
return false, errors.Trace(err)
}
if provider.Scope() == storage.ScopeMachine {
// Any storage created by a machine cannot be detached from
// the machine, and must be destroyed along with it.
return false, nil
}
if provider.Dynamic() {
// NOTE(axw) In theory, we don't know ahead of time
// whether the storage will be Persistent, as the model
// allows for a dynamic storage provider to create non-
// persistent storage. None of the storage providers do
// this, so we assume it will be persistent for now.
//
// TODO(axw) get rid of the Persistent field from Volume
// and Filesystem. We only need to care whether the
// storage is dynamic and model-scoped.
return true, nil
}
// Volume is static, so it will be tied to the machine.
return false, nil
} | [
"func",
"isDetachableVolumePool",
"(",
"im",
"*",
"storageBackend",
",",
"pool",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"provider",
",",
"_",
",",
"err",
":=",
"poolStorageProvider",
"(",
"im",
",",
"pool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"provider",
".",
"Scope",
"(",
")",
"==",
"storage",
".",
"ScopeMachine",
"{",
"// Any storage created by a machine cannot be detached from",
"// the machine, and must be destroyed along with it.",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"if",
"provider",
".",
"Dynamic",
"(",
")",
"{",
"// NOTE(axw) In theory, we don't know ahead of time",
"// whether the storage will be Persistent, as the model",
"// allows for a dynamic storage provider to create non-",
"// persistent storage. None of the storage providers do",
"// this, so we assume it will be persistent for now.",
"//",
"// TODO(axw) get rid of the Persistent field from Volume",
"// and Filesystem. We only need to care whether the",
"// storage is dynamic and model-scoped.",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"// Volume is static, so it will be tied to the machine.",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // isDetachableVolumePool reports whether or not the given storage
// pool will create a volume that is not inherently bound to a machine,
// and therefore can be detached. | [
"isDetachableVolumePool",
"reports",
"whether",
"or",
"not",
"the",
"given",
"storage",
"pool",
"will",
"create",
"a",
"volume",
"that",
"is",
"not",
"inherently",
"bound",
"to",
"a",
"machine",
"and",
"therefore",
"can",
"be",
"detached",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L675-L699 |
3,414 | juju/juju | state/volume.go | DetachVolume | func (sb *storageBackend) DetachVolume(host names.Tag, volume names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "detaching volume %s from %s", volume.Id(), names.ReadableString(host))
// If the volume is backing a filesystem, the volume cannot be detached
// until the filesystem has been detached.
if _, err := sb.volumeFilesystemAttachment(host, volume); err == nil {
return &errContainsFilesystem{errors.New("volume contains attached filesystem")}
} else if !errors.IsNotFound(err) {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
va, err := sb.VolumeAttachment(host, volume)
if err != nil {
return nil, errors.Trace(err)
}
if va.Life() != Alive {
return nil, jujutxn.ErrNoOperations
}
detachable, err := isDetachableVolumeTag(sb.mb.db(), volume)
if err != nil {
return nil, errors.Trace(err)
}
if !detachable {
return nil, errors.New("volume is not detachable")
}
if plans, err := sb.machineVolumeAttachmentPlans(host, volume); err != nil {
return nil, errors.Trace(err)
} else {
if len(plans) > 0 {
return detachStorageAttachmentOps(host, volume), nil
}
}
return detachVolumeOps(host, volume), nil
}
return sb.mb.db().Run(buildTxn)
} | go | func (sb *storageBackend) DetachVolume(host names.Tag, volume names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "detaching volume %s from %s", volume.Id(), names.ReadableString(host))
// If the volume is backing a filesystem, the volume cannot be detached
// until the filesystem has been detached.
if _, err := sb.volumeFilesystemAttachment(host, volume); err == nil {
return &errContainsFilesystem{errors.New("volume contains attached filesystem")}
} else if !errors.IsNotFound(err) {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
va, err := sb.VolumeAttachment(host, volume)
if err != nil {
return nil, errors.Trace(err)
}
if va.Life() != Alive {
return nil, jujutxn.ErrNoOperations
}
detachable, err := isDetachableVolumeTag(sb.mb.db(), volume)
if err != nil {
return nil, errors.Trace(err)
}
if !detachable {
return nil, errors.New("volume is not detachable")
}
if plans, err := sb.machineVolumeAttachmentPlans(host, volume); err != nil {
return nil, errors.Trace(err)
} else {
if len(plans) > 0 {
return detachStorageAttachmentOps(host, volume), nil
}
}
return detachVolumeOps(host, volume), nil
}
return sb.mb.db().Run(buildTxn)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"DetachVolume",
"(",
"host",
"names",
".",
"Tag",
",",
"volume",
"names",
".",
"VolumeTag",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
",",
"names",
".",
"ReadableString",
"(",
"host",
")",
")",
"\n",
"// If the volume is backing a filesystem, the volume cannot be detached",
"// until the filesystem has been detached.",
"if",
"_",
",",
"err",
":=",
"sb",
".",
"volumeFilesystemAttachment",
"(",
"host",
",",
"volume",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"&",
"errContainsFilesystem",
"{",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"}",
"\n",
"}",
"else",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"va",
",",
"err",
":=",
"sb",
".",
"VolumeAttachment",
"(",
"host",
",",
"volume",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"va",
".",
"Life",
"(",
")",
"!=",
"Alive",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"detachable",
",",
"err",
":=",
"isDetachableVolumeTag",
"(",
"sb",
".",
"mb",
".",
"db",
"(",
")",
",",
"volume",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"detachable",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"plans",
",",
"err",
":=",
"sb",
".",
"machineVolumeAttachmentPlans",
"(",
"host",
",",
"volume",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"if",
"len",
"(",
"plans",
")",
">",
"0",
"{",
"return",
"detachStorageAttachmentOps",
"(",
"host",
",",
"volume",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"detachVolumeOps",
"(",
"host",
",",
"volume",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // DetachVolume marks the volume attachment identified by the specified machine
// and volume tags as Dying, if it is Alive. DetachVolume will fail with a
// IsContainsFilesystem error if the volume contains an attached filesystem; the
// filesystem attachment must be removed first. DetachVolume will fail for
// inherently machine-bound volumes. | [
"DetachVolume",
"marks",
"the",
"volume",
"attachment",
"identified",
"by",
"the",
"specified",
"machine",
"and",
"volume",
"tags",
"as",
"Dying",
"if",
"it",
"is",
"Alive",
".",
"DetachVolume",
"will",
"fail",
"with",
"a",
"IsContainsFilesystem",
"error",
"if",
"the",
"volume",
"contains",
"an",
"attached",
"filesystem",
";",
"the",
"filesystem",
"attachment",
"must",
"be",
"removed",
"first",
".",
"DetachVolume",
"will",
"fail",
"for",
"inherently",
"machine",
"-",
"bound",
"volumes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L706-L740 |
3,415 | juju/juju | state/volume.go | RemoveVolumeAttachment | func (sb *storageBackend) RemoveVolumeAttachment(host names.Tag, volume names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "removing attachment of volume %s from %s", volume.Id(), names.ReadableString(host))
buildTxn := func(attempt int) ([]txn.Op, error) {
attachment, err := sb.VolumeAttachment(host, volume)
if errors.IsNotFound(err) && attempt > 0 {
// We only ignore IsNotFound on attempts after the
// first, since we expect the volume attachment to
// be there initially.
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
if attachment.Life() != Dying {
return nil, errors.New("volume attachment is not dying")
}
v, err := getVolumeByTag(sb.mb, volume)
if err != nil {
return nil, errors.Trace(err)
}
return removeVolumeAttachmentOps(host, v), nil
}
return sb.mb.db().Run(buildTxn)
} | go | func (sb *storageBackend) RemoveVolumeAttachment(host names.Tag, volume names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "removing attachment of volume %s from %s", volume.Id(), names.ReadableString(host))
buildTxn := func(attempt int) ([]txn.Op, error) {
attachment, err := sb.VolumeAttachment(host, volume)
if errors.IsNotFound(err) && attempt > 0 {
// We only ignore IsNotFound on attempts after the
// first, since we expect the volume attachment to
// be there initially.
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
if attachment.Life() != Dying {
return nil, errors.New("volume attachment is not dying")
}
v, err := getVolumeByTag(sb.mb, volume)
if err != nil {
return nil, errors.Trace(err)
}
return removeVolumeAttachmentOps(host, v), nil
}
return sb.mb.db().Run(buildTxn)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"RemoveVolumeAttachment",
"(",
"host",
"names",
".",
"Tag",
",",
"volume",
"names",
".",
"VolumeTag",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
",",
"names",
".",
"ReadableString",
"(",
"host",
")",
")",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"attachment",
",",
"err",
":=",
"sb",
".",
"VolumeAttachment",
"(",
"host",
",",
"volume",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"&&",
"attempt",
">",
"0",
"{",
"// We only ignore IsNotFound on attempts after the",
"// first, since we expect the volume attachment to",
"// be there initially.",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"attachment",
".",
"Life",
"(",
")",
"!=",
"Dying",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"getVolumeByTag",
"(",
"sb",
".",
"mb",
",",
"volume",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"removeVolumeAttachmentOps",
"(",
"host",
",",
"v",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // RemoveVolumeAttachment removes the volume attachment from state.
// RemoveVolumeAttachment will fail if the attachment is not Dying. | [
"RemoveVolumeAttachment",
"removes",
"the",
"volume",
"attachment",
"from",
"state",
".",
"RemoveVolumeAttachment",
"will",
"fail",
"if",
"the",
"attachment",
"is",
"not",
"Dying",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L771-L794 |
3,416 | juju/juju | state/volume.go | DestroyVolume | func (sb *storageBackend) DestroyVolume(tag names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "destroying volume %s", tag.Id())
if _, err := sb.VolumeFilesystem(tag); err == nil {
return &errContainsFilesystem{errors.New("volume contains filesystem")}
} else if !errors.IsNotFound(err) {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
volume, err := getVolumeByTag(sb.mb, tag)
if errors.IsNotFound(err) && attempt > 0 {
// On the first attempt, we expect it to exist.
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
if volume.doc.StorageId != "" {
return nil, errors.Errorf(
"volume is assigned to %s",
names.ReadableString(names.NewStorageTag(volume.doc.StorageId)),
)
}
if volume.Life() != Alive {
return nil, jujutxn.ErrNoOperations
}
hasNoStorageAssignment := bson.D{{"$or", []bson.D{
{{"storageid", ""}},
{{"storageid", bson.D{{"$exists", false}}}},
}}}
return destroyVolumeOps(sb, volume, false, hasNoStorageAssignment)
}
return sb.mb.db().Run(buildTxn)
} | go | func (sb *storageBackend) DestroyVolume(tag names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "destroying volume %s", tag.Id())
if _, err := sb.VolumeFilesystem(tag); err == nil {
return &errContainsFilesystem{errors.New("volume contains filesystem")}
} else if !errors.IsNotFound(err) {
return errors.Trace(err)
}
buildTxn := func(attempt int) ([]txn.Op, error) {
volume, err := getVolumeByTag(sb.mb, tag)
if errors.IsNotFound(err) && attempt > 0 {
// On the first attempt, we expect it to exist.
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
if volume.doc.StorageId != "" {
return nil, errors.Errorf(
"volume is assigned to %s",
names.ReadableString(names.NewStorageTag(volume.doc.StorageId)),
)
}
if volume.Life() != Alive {
return nil, jujutxn.ErrNoOperations
}
hasNoStorageAssignment := bson.D{{"$or", []bson.D{
{{"storageid", ""}},
{{"storageid", bson.D{{"$exists", false}}}},
}}}
return destroyVolumeOps(sb, volume, false, hasNoStorageAssignment)
}
return sb.mb.db().Run(buildTxn)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"DestroyVolume",
"(",
"tag",
"names",
".",
"VolumeTag",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"sb",
".",
"VolumeFilesystem",
"(",
"tag",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"&",
"errContainsFilesystem",
"{",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"}",
"\n",
"}",
"else",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"volume",
",",
"err",
":=",
"getVolumeByTag",
"(",
"sb",
".",
"mb",
",",
"tag",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"&&",
"attempt",
">",
"0",
"{",
"// On the first attempt, we expect it to exist.",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"volume",
".",
"doc",
".",
"StorageId",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"names",
".",
"ReadableString",
"(",
"names",
".",
"NewStorageTag",
"(",
"volume",
".",
"doc",
".",
"StorageId",
")",
")",
",",
")",
"\n",
"}",
"\n",
"if",
"volume",
".",
"Life",
"(",
")",
"!=",
"Alive",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"hasNoStorageAssignment",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"[",
"]",
"bson",
".",
"D",
"{",
"{",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"}",
",",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"false",
"}",
"}",
"}",
"}",
",",
"}",
"}",
"}",
"\n",
"return",
"destroyVolumeOps",
"(",
"sb",
",",
"volume",
",",
"false",
",",
"hasNoStorageAssignment",
")",
"\n",
"}",
"\n",
"return",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // DestroyVolume ensures that the volume and any attachments to it will be
// destroyed and removed from state at some point in the future. DestroyVolume
// will fail with an IsContainsFilesystem error if the volume contains a
// filesystem; the filesystem must be fully removed first. | [
"DestroyVolume",
"ensures",
"that",
"the",
"volume",
"and",
"any",
"attachments",
"to",
"it",
"will",
"be",
"destroyed",
"and",
"removed",
"from",
"state",
"at",
"some",
"point",
"in",
"the",
"future",
".",
"DestroyVolume",
"will",
"fail",
"with",
"an",
"IsContainsFilesystem",
"error",
"if",
"the",
"volume",
"contains",
"a",
"filesystem",
";",
"the",
"filesystem",
"must",
"be",
"fully",
"removed",
"first",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L875-L906 |
3,417 | juju/juju | state/volume.go | RemoveVolume | func (sb *storageBackend) RemoveVolume(tag names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "removing volume %s", tag.Id())
buildTxn := func(attempt int) ([]txn.Op, error) {
volume, err := sb.Volume(tag)
if errors.IsNotFound(err) {
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
if volume.Life() != Dead {
return nil, errors.New("volume is not dead")
}
return sb.removeVolumeOps(tag), nil
}
return sb.mb.db().Run(buildTxn)
} | go | func (sb *storageBackend) RemoveVolume(tag names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "removing volume %s", tag.Id())
buildTxn := func(attempt int) ([]txn.Op, error) {
volume, err := sb.Volume(tag)
if errors.IsNotFound(err) {
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
if volume.Life() != Dead {
return nil, errors.New("volume is not dead")
}
return sb.removeVolumeOps(tag), nil
}
return sb.mb.db().Run(buildTxn)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"RemoveVolume",
"(",
"tag",
"names",
".",
"VolumeTag",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"volume",
",",
"err",
":=",
"sb",
".",
"Volume",
"(",
"tag",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"volume",
".",
"Life",
"(",
")",
"!=",
"Dead",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sb",
".",
"removeVolumeOps",
"(",
"tag",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // RemoveVolume removes the volume from state. RemoveVolume will fail if
// the volume is not Dead, which implies that it still has attachments. | [
"RemoveVolume",
"removes",
"the",
"volume",
"from",
"state",
".",
"RemoveVolume",
"will",
"fail",
"if",
"the",
"volume",
"is",
"not",
"Dead",
"which",
"implies",
"that",
"it",
"still",
"has",
"attachments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L964-L979 |
3,418 | juju/juju | state/volume.go | addVolumeOps | func (sb *storageBackend) addVolumeOps(params VolumeParams, hostId string) ([]txn.Op, names.VolumeTag, error) {
params, err := sb.volumeParamsWithDefaults(params)
if err != nil {
return nil, names.VolumeTag{}, errors.Trace(err)
}
detachable, err := isDetachableVolumePool(sb, params.Pool)
if err != nil {
return nil, names.VolumeTag{}, errors.Trace(err)
}
origHostId := hostId
hostId, err = sb.validateVolumeParams(params, hostId)
if err != nil {
return nil, names.VolumeTag{}, errors.Annotate(err, "validating volume params")
}
name, err := newVolumeName(sb.mb, hostId)
if err != nil {
return nil, names.VolumeTag{}, errors.Annotate(err, "cannot generate volume name")
}
statusDoc := statusDoc{
Status: status.Pending,
Updated: sb.mb.clock().Now().UnixNano(),
}
doc := volumeDoc{
Name: name,
StorageId: params.storage.Id(),
}
if params.volumeInfo != nil {
// We're importing an already provisioned volume into the
// model. Set provisioned info rather than params, and set
// the status to "detached".
statusDoc.Status = status.Detached
doc.Info = params.volumeInfo
} else {
// Every new volume is created with one attachment.
doc.Params = ¶ms
doc.AttachmentCount = 1
}
if !detachable {
doc.HostId = origHostId
}
return sb.newVolumeOps(doc, statusDoc), names.NewVolumeTag(name), nil
} | go | func (sb *storageBackend) addVolumeOps(params VolumeParams, hostId string) ([]txn.Op, names.VolumeTag, error) {
params, err := sb.volumeParamsWithDefaults(params)
if err != nil {
return nil, names.VolumeTag{}, errors.Trace(err)
}
detachable, err := isDetachableVolumePool(sb, params.Pool)
if err != nil {
return nil, names.VolumeTag{}, errors.Trace(err)
}
origHostId := hostId
hostId, err = sb.validateVolumeParams(params, hostId)
if err != nil {
return nil, names.VolumeTag{}, errors.Annotate(err, "validating volume params")
}
name, err := newVolumeName(sb.mb, hostId)
if err != nil {
return nil, names.VolumeTag{}, errors.Annotate(err, "cannot generate volume name")
}
statusDoc := statusDoc{
Status: status.Pending,
Updated: sb.mb.clock().Now().UnixNano(),
}
doc := volumeDoc{
Name: name,
StorageId: params.storage.Id(),
}
if params.volumeInfo != nil {
// We're importing an already provisioned volume into the
// model. Set provisioned info rather than params, and set
// the status to "detached".
statusDoc.Status = status.Detached
doc.Info = params.volumeInfo
} else {
// Every new volume is created with one attachment.
doc.Params = ¶ms
doc.AttachmentCount = 1
}
if !detachable {
doc.HostId = origHostId
}
return sb.newVolumeOps(doc, statusDoc), names.NewVolumeTag(name), nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"addVolumeOps",
"(",
"params",
"VolumeParams",
",",
"hostId",
"string",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"names",
".",
"VolumeTag",
",",
"error",
")",
"{",
"params",
",",
"err",
":=",
"sb",
".",
"volumeParamsWithDefaults",
"(",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"detachable",
",",
"err",
":=",
"isDetachableVolumePool",
"(",
"sb",
",",
"params",
".",
"Pool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"origHostId",
":=",
"hostId",
"\n",
"hostId",
",",
"err",
"=",
"sb",
".",
"validateVolumeParams",
"(",
"params",
",",
"hostId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"name",
",",
"err",
":=",
"newVolumeName",
"(",
"sb",
".",
"mb",
",",
"hostId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"statusDoc",
":=",
"statusDoc",
"{",
"Status",
":",
"status",
".",
"Pending",
",",
"Updated",
":",
"sb",
".",
"mb",
".",
"clock",
"(",
")",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
",",
"}",
"\n",
"doc",
":=",
"volumeDoc",
"{",
"Name",
":",
"name",
",",
"StorageId",
":",
"params",
".",
"storage",
".",
"Id",
"(",
")",
",",
"}",
"\n",
"if",
"params",
".",
"volumeInfo",
"!=",
"nil",
"{",
"// We're importing an already provisioned volume into the",
"// model. Set provisioned info rather than params, and set",
"// the status to \"detached\".",
"statusDoc",
".",
"Status",
"=",
"status",
".",
"Detached",
"\n",
"doc",
".",
"Info",
"=",
"params",
".",
"volumeInfo",
"\n",
"}",
"else",
"{",
"// Every new volume is created with one attachment.",
"doc",
".",
"Params",
"=",
"&",
"params",
"\n",
"doc",
".",
"AttachmentCount",
"=",
"1",
"\n",
"}",
"\n",
"if",
"!",
"detachable",
"{",
"doc",
".",
"HostId",
"=",
"origHostId",
"\n",
"}",
"\n",
"return",
"sb",
".",
"newVolumeOps",
"(",
"doc",
",",
"statusDoc",
")",
",",
"names",
".",
"NewVolumeTag",
"(",
"name",
")",
",",
"nil",
"\n",
"}"
] | // addVolumeOps returns txn.Ops to create a new volume with the specified
// parameters. If the supplied host ID is non-empty, and the storage
// provider is machine-scoped, then the volume will be scoped to that
// machine. | [
"addVolumeOps",
"returns",
"txn",
".",
"Ops",
"to",
"create",
"a",
"new",
"volume",
"with",
"the",
"specified",
"parameters",
".",
"If",
"the",
"supplied",
"host",
"ID",
"is",
"non",
"-",
"empty",
"and",
"the",
"storage",
"provider",
"is",
"machine",
"-",
"scoped",
"then",
"the",
"volume",
"will",
"be",
"scoped",
"to",
"that",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1014-L1055 |
3,419 | juju/juju | state/volume.go | validateVolumeParams | func (sb *storageBackend) validateVolumeParams(params VolumeParams, machineId string) (maybeMachineId string, _ error) {
if err := validateStoragePool(sb, params.Pool, storage.StorageKindBlock, &machineId); err != nil {
return "", err
}
if params.Size == 0 {
return "", errors.New("invalid size 0")
}
return machineId, nil
} | go | func (sb *storageBackend) validateVolumeParams(params VolumeParams, machineId string) (maybeMachineId string, _ error) {
if err := validateStoragePool(sb, params.Pool, storage.StorageKindBlock, &machineId); err != nil {
return "", err
}
if params.Size == 0 {
return "", errors.New("invalid size 0")
}
return machineId, nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"validateVolumeParams",
"(",
"params",
"VolumeParams",
",",
"machineId",
"string",
")",
"(",
"maybeMachineId",
"string",
",",
"_",
"error",
")",
"{",
"if",
"err",
":=",
"validateStoragePool",
"(",
"sb",
",",
"params",
".",
"Pool",
",",
"storage",
".",
"StorageKindBlock",
",",
"&",
"machineId",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"params",
".",
"Size",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"machineId",
",",
"nil",
"\n",
"}"
] | // validateVolumeParams validates the volume parameters, and returns the
// machine ID to use as the scope in the volume tag. | [
"validateVolumeParams",
"validates",
"the",
"volume",
"parameters",
"and",
"returns",
"the",
"machine",
"ID",
"to",
"use",
"as",
"the",
"scope",
"in",
"the",
"volume",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1092-L1100 |
3,420 | juju/juju | state/volume.go | ParseVolumeAttachmentId | func ParseVolumeAttachmentId(id string) (names.Tag, names.VolumeTag, error) {
fields := strings.SplitN(id, ":", 2)
isValidHost := names.IsValidMachine(fields[0]) || names.IsValidUnit(fields[0])
if len(fields) != 2 || !isValidHost || !names.IsValidVolume(fields[1]) {
return names.MachineTag{}, names.VolumeTag{}, errors.Errorf("invalid volume attachment ID %q", id)
}
var hostTag names.Tag
if names.IsValidMachine(fields[0]) {
hostTag = names.NewMachineTag(fields[0])
} else {
hostTag = names.NewUnitTag(fields[0])
}
volumeTag := names.NewVolumeTag(fields[1])
return hostTag, volumeTag, nil
} | go | func ParseVolumeAttachmentId(id string) (names.Tag, names.VolumeTag, error) {
fields := strings.SplitN(id, ":", 2)
isValidHost := names.IsValidMachine(fields[0]) || names.IsValidUnit(fields[0])
if len(fields) != 2 || !isValidHost || !names.IsValidVolume(fields[1]) {
return names.MachineTag{}, names.VolumeTag{}, errors.Errorf("invalid volume attachment ID %q", id)
}
var hostTag names.Tag
if names.IsValidMachine(fields[0]) {
hostTag = names.NewMachineTag(fields[0])
} else {
hostTag = names.NewUnitTag(fields[0])
}
volumeTag := names.NewVolumeTag(fields[1])
return hostTag, volumeTag, nil
} | [
"func",
"ParseVolumeAttachmentId",
"(",
"id",
"string",
")",
"(",
"names",
".",
"Tag",
",",
"names",
".",
"VolumeTag",
",",
"error",
")",
"{",
"fields",
":=",
"strings",
".",
"SplitN",
"(",
"id",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"isValidHost",
":=",
"names",
".",
"IsValidMachine",
"(",
"fields",
"[",
"0",
"]",
")",
"||",
"names",
".",
"IsValidUnit",
"(",
"fields",
"[",
"0",
"]",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"!=",
"2",
"||",
"!",
"isValidHost",
"||",
"!",
"names",
".",
"IsValidVolume",
"(",
"fields",
"[",
"1",
"]",
")",
"{",
"return",
"names",
".",
"MachineTag",
"{",
"}",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"var",
"hostTag",
"names",
".",
"Tag",
"\n",
"if",
"names",
".",
"IsValidMachine",
"(",
"fields",
"[",
"0",
"]",
")",
"{",
"hostTag",
"=",
"names",
".",
"NewMachineTag",
"(",
"fields",
"[",
"0",
"]",
")",
"\n",
"}",
"else",
"{",
"hostTag",
"=",
"names",
".",
"NewUnitTag",
"(",
"fields",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"volumeTag",
":=",
"names",
".",
"NewVolumeTag",
"(",
"fields",
"[",
"1",
"]",
")",
"\n",
"return",
"hostTag",
",",
"volumeTag",
",",
"nil",
"\n",
"}"
] | // ParseVolumeAttachmentId parses a string as a volume attachment ID,
// returning the host and volume components. | [
"ParseVolumeAttachmentId",
"parses",
"a",
"string",
"as",
"a",
"volume",
"attachment",
"ID",
"returning",
"the",
"host",
"and",
"volume",
"components",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1110-L1124 |
3,421 | juju/juju | state/volume.go | createMachineVolumeAttachmentsOps | func createMachineVolumeAttachmentsOps(hostId string, attachments []volumeAttachmentTemplate) []txn.Op {
ops := make([]txn.Op, len(attachments))
for i, attachment := range attachments {
paramsCopy := attachment.params
ops[i] = txn.Op{
C: volumeAttachmentsC,
Id: volumeAttachmentId(hostId, attachment.tag.Id()),
Assert: txn.DocMissing,
Insert: &volumeAttachmentDoc{
Volume: attachment.tag.Id(),
Host: hostId,
Params: ¶msCopy,
},
}
if attachment.existing {
ops = append(ops, txn.Op{
C: volumesC,
Id: attachment.tag.Id(),
Assert: txn.DocExists,
Update: bson.D{{"$inc", bson.D{{"attachmentcount", 1}}}},
})
}
}
return ops
} | go | func createMachineVolumeAttachmentsOps(hostId string, attachments []volumeAttachmentTemplate) []txn.Op {
ops := make([]txn.Op, len(attachments))
for i, attachment := range attachments {
paramsCopy := attachment.params
ops[i] = txn.Op{
C: volumeAttachmentsC,
Id: volumeAttachmentId(hostId, attachment.tag.Id()),
Assert: txn.DocMissing,
Insert: &volumeAttachmentDoc{
Volume: attachment.tag.Id(),
Host: hostId,
Params: ¶msCopy,
},
}
if attachment.existing {
ops = append(ops, txn.Op{
C: volumesC,
Id: attachment.tag.Id(),
Assert: txn.DocExists,
Update: bson.D{{"$inc", bson.D{{"attachmentcount", 1}}}},
})
}
}
return ops
} | [
"func",
"createMachineVolumeAttachmentsOps",
"(",
"hostId",
"string",
",",
"attachments",
"[",
"]",
"volumeAttachmentTemplate",
")",
"[",
"]",
"txn",
".",
"Op",
"{",
"ops",
":=",
"make",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"len",
"(",
"attachments",
")",
")",
"\n",
"for",
"i",
",",
"attachment",
":=",
"range",
"attachments",
"{",
"paramsCopy",
":=",
"attachment",
".",
"params",
"\n",
"ops",
"[",
"i",
"]",
"=",
"txn",
".",
"Op",
"{",
"C",
":",
"volumeAttachmentsC",
",",
"Id",
":",
"volumeAttachmentId",
"(",
"hostId",
",",
"attachment",
".",
"tag",
".",
"Id",
"(",
")",
")",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"&",
"volumeAttachmentDoc",
"{",
"Volume",
":",
"attachment",
".",
"tag",
".",
"Id",
"(",
")",
",",
"Host",
":",
"hostId",
",",
"Params",
":",
"&",
"paramsCopy",
",",
"}",
",",
"}",
"\n",
"if",
"attachment",
".",
"existing",
"{",
"ops",
"=",
"append",
"(",
"ops",
",",
"txn",
".",
"Op",
"{",
"C",
":",
"volumesC",
",",
"Id",
":",
"attachment",
".",
"tag",
".",
"Id",
"(",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"1",
"}",
"}",
"}",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ops",
"\n",
"}"
] | // createMachineVolumeAttachmentInfo creates volume attachments
// for the specified host, and attachment parameters keyed
// by volume tags. The caller is responsible for incrementing
// the volume's attachmentcount field. | [
"createMachineVolumeAttachmentInfo",
"creates",
"volume",
"attachments",
"for",
"the",
"specified",
"host",
"and",
"attachment",
"parameters",
"keyed",
"by",
"volume",
"tags",
".",
"The",
"caller",
"is",
"responsible",
"for",
"incrementing",
"the",
"volume",
"s",
"attachmentcount",
"field",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1136-L1160 |
3,422 | juju/juju | state/volume.go | setMachineVolumeAttachmentInfo | func setMachineVolumeAttachmentInfo(sb *storageBackend, machineId string, attachments map[names.VolumeTag]VolumeAttachmentInfo) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set volume attachment info for machine %s", machineId)
machineTag := names.NewMachineTag(machineId)
for volumeTag, info := range attachments {
if err := sb.setVolumeAttachmentInfo(machineTag, volumeTag, info); err != nil {
return errors.Annotatef(err, "setting attachment info for volume %s", volumeTag.Id())
}
}
return nil
} | go | func setMachineVolumeAttachmentInfo(sb *storageBackend, machineId string, attachments map[names.VolumeTag]VolumeAttachmentInfo) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set volume attachment info for machine %s", machineId)
machineTag := names.NewMachineTag(machineId)
for volumeTag, info := range attachments {
if err := sb.setVolumeAttachmentInfo(machineTag, volumeTag, info); err != nil {
return errors.Annotatef(err, "setting attachment info for volume %s", volumeTag.Id())
}
}
return nil
} | [
"func",
"setMachineVolumeAttachmentInfo",
"(",
"sb",
"*",
"storageBackend",
",",
"machineId",
"string",
",",
"attachments",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"VolumeAttachmentInfo",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"machineId",
")",
"\n",
"machineTag",
":=",
"names",
".",
"NewMachineTag",
"(",
"machineId",
")",
"\n",
"for",
"volumeTag",
",",
"info",
":=",
"range",
"attachments",
"{",
"if",
"err",
":=",
"sb",
".",
"setVolumeAttachmentInfo",
"(",
"machineTag",
",",
"volumeTag",
",",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"volumeTag",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // setMachineVolumeAttachmentInfo sets the volume attachment
// info for the specified machine. Each volume attachment info
// structure is keyed by the name of the volume it corresponds
// to. | [
"setMachineVolumeAttachmentInfo",
"sets",
"the",
"volume",
"attachment",
"info",
"for",
"the",
"specified",
"machine",
".",
"Each",
"volume",
"attachment",
"info",
"structure",
"is",
"keyed",
"by",
"the",
"name",
"of",
"the",
"volume",
"it",
"corresponds",
"to",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1166-L1175 |
3,423 | juju/juju | state/volume.go | SetVolumeAttachmentInfo | func (sb *storageBackend) SetVolumeAttachmentInfo(hostTag names.Tag, volumeTag names.VolumeTag, info VolumeAttachmentInfo) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set info for volume attachment %s:%s", volumeTag.Id(), hostTag.Id())
v, err := sb.Volume(volumeTag)
if err != nil {
return errors.Trace(err)
}
// Ensure volume is provisioned before setting attachment info.
// A volume cannot go from being provisioned to unprovisioned,
// so there is no txn.Op for this below.
if _, err := v.Info(); err != nil {
return errors.Trace(err)
}
// Also ensure the machine is provisioned.
if _, ok := hostTag.(names.MachineTag); ok {
m, err := sb.machine(hostTag.Id())
if err != nil {
return errors.Trace(err)
}
if _, err := m.InstanceId(); err != nil {
return errors.Trace(err)
}
}
return sb.setVolumeAttachmentInfo(hostTag, volumeTag, info)
} | go | func (sb *storageBackend) SetVolumeAttachmentInfo(hostTag names.Tag, volumeTag names.VolumeTag, info VolumeAttachmentInfo) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set info for volume attachment %s:%s", volumeTag.Id(), hostTag.Id())
v, err := sb.Volume(volumeTag)
if err != nil {
return errors.Trace(err)
}
// Ensure volume is provisioned before setting attachment info.
// A volume cannot go from being provisioned to unprovisioned,
// so there is no txn.Op for this below.
if _, err := v.Info(); err != nil {
return errors.Trace(err)
}
// Also ensure the machine is provisioned.
if _, ok := hostTag.(names.MachineTag); ok {
m, err := sb.machine(hostTag.Id())
if err != nil {
return errors.Trace(err)
}
if _, err := m.InstanceId(); err != nil {
return errors.Trace(err)
}
}
return sb.setVolumeAttachmentInfo(hostTag, volumeTag, info)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"SetVolumeAttachmentInfo",
"(",
"hostTag",
"names",
".",
"Tag",
",",
"volumeTag",
"names",
".",
"VolumeTag",
",",
"info",
"VolumeAttachmentInfo",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"volumeTag",
".",
"Id",
"(",
")",
",",
"hostTag",
".",
"Id",
"(",
")",
")",
"\n",
"v",
",",
"err",
":=",
"sb",
".",
"Volume",
"(",
"volumeTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Ensure volume is provisioned before setting attachment info.",
"// A volume cannot go from being provisioned to unprovisioned,",
"// so there is no txn.Op for this below.",
"if",
"_",
",",
"err",
":=",
"v",
".",
"Info",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Also ensure the machine is provisioned.",
"if",
"_",
",",
"ok",
":=",
"hostTag",
".",
"(",
"names",
".",
"MachineTag",
")",
";",
"ok",
"{",
"m",
",",
"err",
":=",
"sb",
".",
"machine",
"(",
"hostTag",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"m",
".",
"InstanceId",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"sb",
".",
"setVolumeAttachmentInfo",
"(",
"hostTag",
",",
"volumeTag",
",",
"info",
")",
"\n",
"}"
] | // SetVolumeAttachmentInfo sets the VolumeAttachmentInfo for the specified
// volume attachment. | [
"SetVolumeAttachmentInfo",
"sets",
"the",
"VolumeAttachmentInfo",
"for",
"the",
"specified",
"volume",
"attachment",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1179-L1202 |
3,424 | juju/juju | state/volume.go | RemoveVolumeAttachmentPlan | func (sb *storageBackend) RemoveVolumeAttachmentPlan(hostTag names.Tag, volume names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "removing attachment plan of volume %s from machine %s", volume.Id(), hostTag.Id())
buildTxn := func(attempt int) ([]txn.Op, error) {
plans, err := sb.machineVolumeAttachmentPlans(hostTag, volume)
if errors.IsNotFound(err) {
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
// We should only have one plan for a volume
if plans != nil && len(plans) > 0 {
if plans[0].Life() != Dying {
return nil, jujutxn.ErrNoOperations
}
} else {
return nil, jujutxn.ErrNoOperations
}
return removeVolumeAttachmentPlanOps(hostTag, volume), nil
}
return sb.mb.db().Run(buildTxn)
} | go | func (sb *storageBackend) RemoveVolumeAttachmentPlan(hostTag names.Tag, volume names.VolumeTag) (err error) {
defer errors.DeferredAnnotatef(&err, "removing attachment plan of volume %s from machine %s", volume.Id(), hostTag.Id())
buildTxn := func(attempt int) ([]txn.Op, error) {
plans, err := sb.machineVolumeAttachmentPlans(hostTag, volume)
if errors.IsNotFound(err) {
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
// We should only have one plan for a volume
if plans != nil && len(plans) > 0 {
if plans[0].Life() != Dying {
return nil, jujutxn.ErrNoOperations
}
} else {
return nil, jujutxn.ErrNoOperations
}
return removeVolumeAttachmentPlanOps(hostTag, volume), nil
}
return sb.mb.db().Run(buildTxn)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"RemoveVolumeAttachmentPlan",
"(",
"hostTag",
"names",
".",
"Tag",
",",
"volume",
"names",
".",
"VolumeTag",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"volume",
".",
"Id",
"(",
")",
",",
"hostTag",
".",
"Id",
"(",
")",
")",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"plans",
",",
"err",
":=",
"sb",
".",
"machineVolumeAttachmentPlans",
"(",
"hostTag",
",",
"volume",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// We should only have one plan for a volume",
"if",
"plans",
"!=",
"nil",
"&&",
"len",
"(",
"plans",
")",
">",
"0",
"{",
"if",
"plans",
"[",
"0",
"]",
".",
"Life",
"(",
")",
"!=",
"Dying",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"return",
"removeVolumeAttachmentPlanOps",
"(",
"hostTag",
",",
"volume",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // RemoveVolumeAttachmentPlan removes the volume attachment plan from state. | [
"RemoveVolumeAttachmentPlan",
"removes",
"the",
"volume",
"attachment",
"plan",
"from",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1361-L1382 |
3,425 | juju/juju | state/volume.go | removeVolumeAttachmentPlanOps | func removeVolumeAttachmentPlanOps(hostTag names.Tag, volume names.VolumeTag) []txn.Op {
detachOps := detachVolumeOps(hostTag, volume)
removeOps := []txn.Op{{
C: volumeAttachmentPlanC,
Id: volumeAttachmentId(hostTag.Id(), volume.Id()),
Assert: bson.D{{"life", Dying}},
Remove: true,
}}
removeOps = append(removeOps, detachOps...)
return removeOps
} | go | func removeVolumeAttachmentPlanOps(hostTag names.Tag, volume names.VolumeTag) []txn.Op {
detachOps := detachVolumeOps(hostTag, volume)
removeOps := []txn.Op{{
C: volumeAttachmentPlanC,
Id: volumeAttachmentId(hostTag.Id(), volume.Id()),
Assert: bson.D{{"life", Dying}},
Remove: true,
}}
removeOps = append(removeOps, detachOps...)
return removeOps
} | [
"func",
"removeVolumeAttachmentPlanOps",
"(",
"hostTag",
"names",
".",
"Tag",
",",
"volume",
"names",
".",
"VolumeTag",
")",
"[",
"]",
"txn",
".",
"Op",
"{",
"detachOps",
":=",
"detachVolumeOps",
"(",
"hostTag",
",",
"volume",
")",
"\n",
"removeOps",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"volumeAttachmentPlanC",
",",
"Id",
":",
"volumeAttachmentId",
"(",
"hostTag",
".",
"Id",
"(",
")",
",",
"volume",
".",
"Id",
"(",
")",
")",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Dying",
"}",
"}",
",",
"Remove",
":",
"true",
",",
"}",
"}",
"\n",
"removeOps",
"=",
"append",
"(",
"removeOps",
",",
"detachOps",
"...",
")",
"\n",
"return",
"removeOps",
"\n",
"}"
] | // removeVolumeAttachmentPlanOps removes the plan from state and sets the volume attachment to Dying.
// this will trigger the storageprovisioner on the controller to eventually detach the volume from
// the machine. | [
"removeVolumeAttachmentPlanOps",
"removes",
"the",
"plan",
"from",
"state",
"and",
"sets",
"the",
"volume",
"attachment",
"to",
"Dying",
".",
"this",
"will",
"trigger",
"the",
"storageprovisioner",
"on",
"the",
"controller",
"to",
"eventually",
"detach",
"the",
"volume",
"from",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1387-L1397 |
3,426 | juju/juju | state/volume.go | setProvisionedVolumeInfo | func setProvisionedVolumeInfo(sb *storageBackend, volumes map[names.VolumeTag]VolumeInfo) error {
for volumeTag, info := range volumes {
if err := sb.SetVolumeInfo(volumeTag, info); err != nil {
return errors.Trace(err)
}
}
return nil
} | go | func setProvisionedVolumeInfo(sb *storageBackend, volumes map[names.VolumeTag]VolumeInfo) error {
for volumeTag, info := range volumes {
if err := sb.SetVolumeInfo(volumeTag, info); err != nil {
return errors.Trace(err)
}
}
return nil
} | [
"func",
"setProvisionedVolumeInfo",
"(",
"sb",
"*",
"storageBackend",
",",
"volumes",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"VolumeInfo",
")",
"error",
"{",
"for",
"volumeTag",
",",
"info",
":=",
"range",
"volumes",
"{",
"if",
"err",
":=",
"sb",
".",
"SetVolumeInfo",
"(",
"volumeTag",
",",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // setProvisionedVolumeInfo sets the initial info for newly
// provisioned volumes. If non-empty, machineId must be the
// machine ID associated with the volumes. | [
"setProvisionedVolumeInfo",
"sets",
"the",
"initial",
"info",
"for",
"newly",
"provisioned",
"volumes",
".",
"If",
"non",
"-",
"empty",
"machineId",
"must",
"be",
"the",
"machine",
"ID",
"associated",
"with",
"the",
"volumes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1402-L1409 |
3,427 | juju/juju | state/volume.go | SetVolumeInfo | func (sb *storageBackend) SetVolumeInfo(tag names.VolumeTag, info VolumeInfo) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set info for volume %q", tag.Id())
if info.VolumeId == "" {
return errors.New("volume ID not set")
}
// TODO(axw) we should reject info without VolumeId set; can't do this
// until the providers all set it correctly.
buildTxn := func(attempt int) ([]txn.Op, error) {
v, err := sb.Volume(tag)
if err != nil {
return nil, errors.Trace(err)
}
// If the volume has parameters, unset them when
// we set info for the first time, ensuring that
// params and info are mutually exclusive.
var unsetParams bool
var ops []txn.Op
if params, ok := v.Params(); ok {
info.Pool = params.Pool
unsetParams = true
} else {
// Ensure immutable properties do not change.
oldInfo, err := v.Info()
if err != nil {
return nil, err
}
if err := validateVolumeInfoChange(info, oldInfo); err != nil {
return nil, err
}
}
ops = append(ops, setVolumeInfoOps(tag, info, unsetParams)...)
return ops, nil
}
return sb.mb.db().Run(buildTxn)
} | go | func (sb *storageBackend) SetVolumeInfo(tag names.VolumeTag, info VolumeInfo) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set info for volume %q", tag.Id())
if info.VolumeId == "" {
return errors.New("volume ID not set")
}
// TODO(axw) we should reject info without VolumeId set; can't do this
// until the providers all set it correctly.
buildTxn := func(attempt int) ([]txn.Op, error) {
v, err := sb.Volume(tag)
if err != nil {
return nil, errors.Trace(err)
}
// If the volume has parameters, unset them when
// we set info for the first time, ensuring that
// params and info are mutually exclusive.
var unsetParams bool
var ops []txn.Op
if params, ok := v.Params(); ok {
info.Pool = params.Pool
unsetParams = true
} else {
// Ensure immutable properties do not change.
oldInfo, err := v.Info()
if err != nil {
return nil, err
}
if err := validateVolumeInfoChange(info, oldInfo); err != nil {
return nil, err
}
}
ops = append(ops, setVolumeInfoOps(tag, info, unsetParams)...)
return ops, nil
}
return sb.mb.db().Run(buildTxn)
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"SetVolumeInfo",
"(",
"tag",
"names",
".",
"VolumeTag",
",",
"info",
"VolumeInfo",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"info",
".",
"VolumeId",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// TODO(axw) we should reject info without VolumeId set; can't do this",
"// until the providers all set it correctly.",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"sb",
".",
"Volume",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// If the volume has parameters, unset them when",
"// we set info for the first time, ensuring that",
"// params and info are mutually exclusive.",
"var",
"unsetParams",
"bool",
"\n",
"var",
"ops",
"[",
"]",
"txn",
".",
"Op",
"\n",
"if",
"params",
",",
"ok",
":=",
"v",
".",
"Params",
"(",
")",
";",
"ok",
"{",
"info",
".",
"Pool",
"=",
"params",
".",
"Pool",
"\n",
"unsetParams",
"=",
"true",
"\n",
"}",
"else",
"{",
"// Ensure immutable properties do not change.",
"oldInfo",
",",
"err",
":=",
"v",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"validateVolumeInfoChange",
"(",
"info",
",",
"oldInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"setVolumeInfoOps",
"(",
"tag",
",",
"info",
",",
"unsetParams",
")",
"...",
")",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"return",
"sb",
".",
"mb",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // SetVolumeInfo sets the VolumeInfo for the specified volume. | [
"SetVolumeInfo",
"sets",
"the",
"VolumeInfo",
"for",
"the",
"specified",
"volume",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1412-L1446 |
3,428 | juju/juju | state/volume.go | AllVolumes | func (sb *storageBackend) AllVolumes() ([]Volume, error) {
volumes, err := sb.volumes(nil)
if err != nil {
return nil, errors.Annotate(err, "cannot get volumes")
}
return volumesToInterfaces(volumes), nil
} | go | func (sb *storageBackend) AllVolumes() ([]Volume, error) {
volumes, err := sb.volumes(nil)
if err != nil {
return nil, errors.Annotate(err, "cannot get volumes")
}
return volumesToInterfaces(volumes), nil
} | [
"func",
"(",
"sb",
"*",
"storageBackend",
")",
"AllVolumes",
"(",
")",
"(",
"[",
"]",
"Volume",
",",
"error",
")",
"{",
"volumes",
",",
"err",
":=",
"sb",
".",
"volumes",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"volumesToInterfaces",
"(",
"volumes",
")",
",",
"nil",
"\n",
"}"
] | // AllVolumes returns all Volumes scoped to the model. | [
"AllVolumes",
"returns",
"all",
"Volumes",
"scoped",
"to",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L1483-L1489 |
3,429 | juju/juju | worker/instancepoller/updater.go | watchMachinesLoop | func watchMachinesLoop(context updaterContext, machinesWatcher watcher.StringsWatcher) (err error) {
p := &updater{
context: context,
machines: make(map[names.MachineTag]chan struct{}),
machineDead: make(chan machine),
}
defer func() {
// TODO(fwereade): is this a home-grown sync.WaitGroup or something?
// strongly suspect these machine goroutines could be managed rather
// less opaquely if we made them all workers.
for len(p.machines) > 0 {
delete(p.machines, (<-p.machineDead).Tag())
}
}()
for {
select {
case <-p.context.dying():
return p.context.errDying()
case ids, ok := <-machinesWatcher.Changes():
if !ok {
return errors.New("machines watcher closed")
}
tags := make([]names.MachineTag, len(ids))
for i := range ids {
tags[i] = names.NewMachineTag(ids[i])
}
if err := p.startMachines(tags); err != nil {
return err
}
case m := <-p.machineDead:
delete(p.machines, m.Tag())
}
}
} | go | func watchMachinesLoop(context updaterContext, machinesWatcher watcher.StringsWatcher) (err error) {
p := &updater{
context: context,
machines: make(map[names.MachineTag]chan struct{}),
machineDead: make(chan machine),
}
defer func() {
// TODO(fwereade): is this a home-grown sync.WaitGroup or something?
// strongly suspect these machine goroutines could be managed rather
// less opaquely if we made them all workers.
for len(p.machines) > 0 {
delete(p.machines, (<-p.machineDead).Tag())
}
}()
for {
select {
case <-p.context.dying():
return p.context.errDying()
case ids, ok := <-machinesWatcher.Changes():
if !ok {
return errors.New("machines watcher closed")
}
tags := make([]names.MachineTag, len(ids))
for i := range ids {
tags[i] = names.NewMachineTag(ids[i])
}
if err := p.startMachines(tags); err != nil {
return err
}
case m := <-p.machineDead:
delete(p.machines, m.Tag())
}
}
} | [
"func",
"watchMachinesLoop",
"(",
"context",
"updaterContext",
",",
"machinesWatcher",
"watcher",
".",
"StringsWatcher",
")",
"(",
"err",
"error",
")",
"{",
"p",
":=",
"&",
"updater",
"{",
"context",
":",
"context",
",",
"machines",
":",
"make",
"(",
"map",
"[",
"names",
".",
"MachineTag",
"]",
"chan",
"struct",
"{",
"}",
")",
",",
"machineDead",
":",
"make",
"(",
"chan",
"machine",
")",
",",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"// TODO(fwereade): is this a home-grown sync.WaitGroup or something?",
"// strongly suspect these machine goroutines could be managed rather",
"// less opaquely if we made them all workers.",
"for",
"len",
"(",
"p",
".",
"machines",
")",
">",
"0",
"{",
"delete",
"(",
"p",
".",
"machines",
",",
"(",
"<-",
"p",
".",
"machineDead",
")",
".",
"Tag",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"p",
".",
"context",
".",
"dying",
"(",
")",
":",
"return",
"p",
".",
"context",
".",
"errDying",
"(",
")",
"\n",
"case",
"ids",
",",
"ok",
":=",
"<-",
"machinesWatcher",
".",
"Changes",
"(",
")",
":",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"tags",
":=",
"make",
"(",
"[",
"]",
"names",
".",
"MachineTag",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"ids",
"{",
"tags",
"[",
"i",
"]",
"=",
"names",
".",
"NewMachineTag",
"(",
"ids",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"startMachines",
"(",
"tags",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"case",
"m",
":=",
"<-",
"p",
".",
"machineDead",
":",
"delete",
"(",
"p",
".",
"machines",
",",
"m",
".",
"Tag",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // watchMachinesLoop watches for changes provided by the given
// machinesWatcher and starts machine goroutines to deal with them,
// using the provided newMachineContext function to create the
// appropriate context for each new machine tag. | [
"watchMachinesLoop",
"watches",
"for",
"changes",
"provided",
"by",
"the",
"given",
"machinesWatcher",
"and",
"starts",
"machine",
"goroutines",
"to",
"deal",
"with",
"them",
"using",
"the",
"provided",
"newMachineContext",
"function",
"to",
"create",
"the",
"appropriate",
"context",
"for",
"each",
"new",
"machine",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancepoller/updater.go#L86-L119 |
3,430 | juju/juju | worker/instancepoller/updater.go | runMachine | func runMachine(context machineContext, m machine, changed <-chan struct{}, died chan<- machine, clock clock.Clock) {
defer func() {
// We can't just send on the died channel because the
// central loop might be trying to write to us on the
// changed channel.
for {
select {
case died <- m:
return
case <-changed:
}
}
}()
if err := machineLoop(context, m, changed, clock); err != nil {
context.kill(err)
}
} | go | func runMachine(context machineContext, m machine, changed <-chan struct{}, died chan<- machine, clock clock.Clock) {
defer func() {
// We can't just send on the died channel because the
// central loop might be trying to write to us on the
// changed channel.
for {
select {
case died <- m:
return
case <-changed:
}
}
}()
if err := machineLoop(context, m, changed, clock); err != nil {
context.kill(err)
}
} | [
"func",
"runMachine",
"(",
"context",
"machineContext",
",",
"m",
"machine",
",",
"changed",
"<-",
"chan",
"struct",
"{",
"}",
",",
"died",
"chan",
"<-",
"machine",
",",
"clock",
"clock",
".",
"Clock",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"// We can't just send on the died channel because the",
"// central loop might be trying to write to us on the",
"// changed channel.",
"for",
"{",
"select",
"{",
"case",
"died",
"<-",
"m",
":",
"return",
"\n",
"case",
"<-",
"changed",
":",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"if",
"err",
":=",
"machineLoop",
"(",
"context",
",",
"m",
",",
"changed",
",",
"clock",
")",
";",
"err",
"!=",
"nil",
"{",
"context",
".",
"kill",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // runMachine processes the address and status publishing for a given machine.
// We assume that the machine is alive when this is first called. | [
"runMachine",
"processes",
"the",
"address",
"and",
"status",
"publishing",
"for",
"a",
"given",
"machine",
".",
"We",
"assume",
"that",
"the",
"machine",
"is",
"alive",
"when",
"this",
"is",
"first",
"called",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancepoller/updater.go#L166-L182 |
3,431 | juju/juju | worker/instancepoller/updater.go | pollInstanceInfo | func pollInstanceInfo(context machineContext, m machine) (instInfo instanceInfo, err error) {
instInfo = instanceInfo{}
instId, err := m.InstanceId()
// We can't ask the machine for its addresses if it isn't provisioned yet.
if params.IsCodeNotProvisioned(err) {
return instanceInfo{}, err
}
if err != nil {
return instanceInfo{}, errors.Annotate(err, "cannot get machine's instance id")
}
instInfo, err = context.instanceInfo(instId)
if err != nil {
// TODO (anastasiamac 2016-02-01) This does not look like it needs to be removed now.
if params.IsCodeNotImplemented(err) {
return instanceInfo{}, err
}
logger.Warningf("cannot get instance info for instance %q: %v", instId, err)
return instInfo, nil
}
if instStat, err := m.InstanceStatus(); err != nil {
// This should never occur since the machine is provisioned.
// But just in case, we reset polled status so we try again next time.
logger.Warningf("cannot get current instance status for machine %v: %v", m.Id(), err)
instInfo.status = instance.Status{status.Unknown, ""}
} else {
// TODO(perrito666) add status validation.
currentInstStatus := instance.Status{
Status: status.Status(instStat.Status),
Message: instStat.Info,
}
if instInfo.status != currentInstStatus {
logger.Infof("machine %q instance status changed from %q to %q", m.Id(), currentInstStatus, instInfo.status)
if err = m.SetInstanceStatus(instInfo.status.Status, instInfo.status.Message, nil); err != nil {
logger.Errorf("cannot set instance status on %q: %v", m, err)
return instanceInfo{}, err
}
}
}
if m.Life() != params.Dead {
providerAddresses, err := m.ProviderAddresses()
if err != nil {
return instanceInfo{}, err
}
if !addressesEqual(providerAddresses, instInfo.addresses) {
logger.Infof("machine %q has new addresses: %v", m.Id(), instInfo.addresses)
if err := m.SetProviderAddresses(instInfo.addresses...); err != nil {
logger.Errorf("cannot set addresses on %q: %v", m, err)
return instanceInfo{}, err
}
}
}
return instInfo, nil
} | go | func pollInstanceInfo(context machineContext, m machine) (instInfo instanceInfo, err error) {
instInfo = instanceInfo{}
instId, err := m.InstanceId()
// We can't ask the machine for its addresses if it isn't provisioned yet.
if params.IsCodeNotProvisioned(err) {
return instanceInfo{}, err
}
if err != nil {
return instanceInfo{}, errors.Annotate(err, "cannot get machine's instance id")
}
instInfo, err = context.instanceInfo(instId)
if err != nil {
// TODO (anastasiamac 2016-02-01) This does not look like it needs to be removed now.
if params.IsCodeNotImplemented(err) {
return instanceInfo{}, err
}
logger.Warningf("cannot get instance info for instance %q: %v", instId, err)
return instInfo, nil
}
if instStat, err := m.InstanceStatus(); err != nil {
// This should never occur since the machine is provisioned.
// But just in case, we reset polled status so we try again next time.
logger.Warningf("cannot get current instance status for machine %v: %v", m.Id(), err)
instInfo.status = instance.Status{status.Unknown, ""}
} else {
// TODO(perrito666) add status validation.
currentInstStatus := instance.Status{
Status: status.Status(instStat.Status),
Message: instStat.Info,
}
if instInfo.status != currentInstStatus {
logger.Infof("machine %q instance status changed from %q to %q", m.Id(), currentInstStatus, instInfo.status)
if err = m.SetInstanceStatus(instInfo.status.Status, instInfo.status.Message, nil); err != nil {
logger.Errorf("cannot set instance status on %q: %v", m, err)
return instanceInfo{}, err
}
}
}
if m.Life() != params.Dead {
providerAddresses, err := m.ProviderAddresses()
if err != nil {
return instanceInfo{}, err
}
if !addressesEqual(providerAddresses, instInfo.addresses) {
logger.Infof("machine %q has new addresses: %v", m.Id(), instInfo.addresses)
if err := m.SetProviderAddresses(instInfo.addresses...); err != nil {
logger.Errorf("cannot set addresses on %q: %v", m, err)
return instanceInfo{}, err
}
}
}
return instInfo, nil
} | [
"func",
"pollInstanceInfo",
"(",
"context",
"machineContext",
",",
"m",
"machine",
")",
"(",
"instInfo",
"instanceInfo",
",",
"err",
"error",
")",
"{",
"instInfo",
"=",
"instanceInfo",
"{",
"}",
"\n",
"instId",
",",
"err",
":=",
"m",
".",
"InstanceId",
"(",
")",
"\n",
"// We can't ask the machine for its addresses if it isn't provisioned yet.",
"if",
"params",
".",
"IsCodeNotProvisioned",
"(",
"err",
")",
"{",
"return",
"instanceInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"instanceInfo",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"instInfo",
",",
"err",
"=",
"context",
".",
"instanceInfo",
"(",
"instId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO (anastasiamac 2016-02-01) This does not look like it needs to be removed now.",
"if",
"params",
".",
"IsCodeNotImplemented",
"(",
"err",
")",
"{",
"return",
"instanceInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"instId",
",",
"err",
")",
"\n",
"return",
"instInfo",
",",
"nil",
"\n",
"}",
"\n",
"if",
"instStat",
",",
"err",
":=",
"m",
".",
"InstanceStatus",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"// This should never occur since the machine is provisioned.",
"// But just in case, we reset polled status so we try again next time.",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"err",
")",
"\n",
"instInfo",
".",
"status",
"=",
"instance",
".",
"Status",
"{",
"status",
".",
"Unknown",
",",
"\"",
"\"",
"}",
"\n",
"}",
"else",
"{",
"// TODO(perrito666) add status validation.",
"currentInstStatus",
":=",
"instance",
".",
"Status",
"{",
"Status",
":",
"status",
".",
"Status",
"(",
"instStat",
".",
"Status",
")",
",",
"Message",
":",
"instStat",
".",
"Info",
",",
"}",
"\n",
"if",
"instInfo",
".",
"status",
"!=",
"currentInstStatus",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"currentInstStatus",
",",
"instInfo",
".",
"status",
")",
"\n",
"if",
"err",
"=",
"m",
".",
"SetInstanceStatus",
"(",
"instInfo",
".",
"status",
".",
"Status",
",",
"instInfo",
".",
"status",
".",
"Message",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
",",
"err",
")",
"\n",
"return",
"instanceInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"}",
"\n",
"if",
"m",
".",
"Life",
"(",
")",
"!=",
"params",
".",
"Dead",
"{",
"providerAddresses",
",",
"err",
":=",
"m",
".",
"ProviderAddresses",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"instanceInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"addressesEqual",
"(",
"providerAddresses",
",",
"instInfo",
".",
"addresses",
")",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"instInfo",
".",
"addresses",
")",
"\n",
"if",
"err",
":=",
"m",
".",
"SetProviderAddresses",
"(",
"instInfo",
".",
"addresses",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
",",
"err",
")",
"\n",
"return",
"instanceInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"instInfo",
",",
"nil",
"\n",
"}"
] | // pollInstanceInfo checks the current provider addresses and status
// for the given machine's instance, and sets them on the machine if they've changed. | [
"pollInstanceInfo",
"checks",
"the",
"current",
"provider",
"addresses",
"and",
"status",
"for",
"the",
"given",
"machine",
"s",
"instance",
"and",
"sets",
"them",
"on",
"the",
"machine",
"if",
"they",
"ve",
"changed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancepoller/updater.go#L251-L304 |
3,432 | juju/juju | worker/instancepoller/updater.go | addressesEqual | func addressesEqual(a0, a1 []network.Address) bool {
if len(a0) != len(a1) {
logger.Tracef("address lists have different lengths %d != %d for %v != %v",
len(a0), len(a1), a0, a1)
return false
}
ca0 := make([]network.Address, len(a0))
copy(ca0, a0)
network.SortAddresses(ca0)
ca1 := make([]network.Address, len(a1))
copy(ca1, a1)
network.SortAddresses(ca1)
for i := range ca0 {
if ca0[i] != ca1[i] {
logger.Tracef("address entry at offset %d has a different value for %v != %v",
i, ca0, ca1)
return false
}
}
return true
} | go | func addressesEqual(a0, a1 []network.Address) bool {
if len(a0) != len(a1) {
logger.Tracef("address lists have different lengths %d != %d for %v != %v",
len(a0), len(a1), a0, a1)
return false
}
ca0 := make([]network.Address, len(a0))
copy(ca0, a0)
network.SortAddresses(ca0)
ca1 := make([]network.Address, len(a1))
copy(ca1, a1)
network.SortAddresses(ca1)
for i := range ca0 {
if ca0[i] != ca1[i] {
logger.Tracef("address entry at offset %d has a different value for %v != %v",
i, ca0, ca1)
return false
}
}
return true
} | [
"func",
"addressesEqual",
"(",
"a0",
",",
"a1",
"[",
"]",
"network",
".",
"Address",
")",
"bool",
"{",
"if",
"len",
"(",
"a0",
")",
"!=",
"len",
"(",
"a1",
")",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"len",
"(",
"a0",
")",
",",
"len",
"(",
"a1",
")",
",",
"a0",
",",
"a1",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"ca0",
":=",
"make",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"len",
"(",
"a0",
")",
")",
"\n",
"copy",
"(",
"ca0",
",",
"a0",
")",
"\n",
"network",
".",
"SortAddresses",
"(",
"ca0",
")",
"\n",
"ca1",
":=",
"make",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"len",
"(",
"a1",
")",
")",
"\n",
"copy",
"(",
"ca1",
",",
"a1",
")",
"\n",
"network",
".",
"SortAddresses",
"(",
"ca1",
")",
"\n\n",
"for",
"i",
":=",
"range",
"ca0",
"{",
"if",
"ca0",
"[",
"i",
"]",
"!=",
"ca1",
"[",
"i",
"]",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"i",
",",
"ca0",
",",
"ca1",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // addressesEqual compares the addresses of the machine and the instance information. | [
"addressesEqual",
"compares",
"the",
"addresses",
"of",
"the",
"machine",
"and",
"the",
"instance",
"information",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancepoller/updater.go#L307-L329 |
3,433 | juju/juju | state/collection.go | Count | func (c *modelStateCollection) Count() (int, error) {
return c.WriteCollection.Find(bson.D{{"model-uuid", c.modelUUID}}).Count()
} | go | func (c *modelStateCollection) Count() (int, error) {
return c.WriteCollection.Find(bson.D{{"model-uuid", c.modelUUID}}).Count()
} | [
"func",
"(",
"c",
"*",
"modelStateCollection",
")",
"Count",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"c",
".",
"WriteCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"c",
".",
"modelUUID",
"}",
"}",
")",
".",
"Count",
"(",
")",
"\n",
"}"
] | // Count returns the number of documents in the collection that belong
// to the model that the modelStateCollection is filtering on. | [
"Count",
"returns",
"the",
"number",
"of",
"documents",
"in",
"the",
"collection",
"that",
"belong",
"to",
"the",
"model",
"that",
"the",
"modelStateCollection",
"is",
"filtering",
"on",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/collection.go#L33-L35 |
3,434 | juju/juju | state/collection.go | Insert | func (c *modelStateCollection) Insert(docs ...interface{}) error {
var mungedDocs []interface{}
for _, doc := range docs {
mungedDoc, err := mungeDocForMultiModel(doc, c.modelUUID, modelUUIDRequired)
if err != nil {
return errors.Trace(err)
}
mungedDocs = append(mungedDocs, mungedDoc)
}
return c.WriteCollection.Insert(mungedDocs...)
} | go | func (c *modelStateCollection) Insert(docs ...interface{}) error {
var mungedDocs []interface{}
for _, doc := range docs {
mungedDoc, err := mungeDocForMultiModel(doc, c.modelUUID, modelUUIDRequired)
if err != nil {
return errors.Trace(err)
}
mungedDocs = append(mungedDocs, mungedDoc)
}
return c.WriteCollection.Insert(mungedDocs...)
} | [
"func",
"(",
"c",
"*",
"modelStateCollection",
")",
"Insert",
"(",
"docs",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"mungedDocs",
"[",
"]",
"interface",
"{",
"}",
"\n",
"for",
"_",
",",
"doc",
":=",
"range",
"docs",
"{",
"mungedDoc",
",",
"err",
":=",
"mungeDocForMultiModel",
"(",
"doc",
",",
"c",
".",
"modelUUID",
",",
"modelUUIDRequired",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"mungedDocs",
"=",
"append",
"(",
"mungedDocs",
",",
"mungedDoc",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"WriteCollection",
".",
"Insert",
"(",
"mungedDocs",
"...",
")",
"\n",
"}"
] | // Insert adds one or more documents to a collection. If the document
// id is a string the model UUID prefix will be automatically
// added to it. The model-uuid field will also be automatically added if
// it is missing. An error will be returned if an model-uuid field is
// provided but is the wrong value. | [
"Insert",
"adds",
"one",
"or",
"more",
"documents",
"to",
"a",
"collection",
".",
"If",
"the",
"document",
"id",
"is",
"a",
"string",
"the",
"model",
"UUID",
"prefix",
"will",
"be",
"automatically",
"added",
"to",
"it",
".",
"The",
"model",
"-",
"uuid",
"field",
"will",
"also",
"be",
"automatically",
"added",
"if",
"it",
"is",
"missing",
".",
"An",
"error",
"will",
"be",
"returned",
"if",
"an",
"model",
"-",
"uuid",
"field",
"is",
"provided",
"but",
"is",
"the",
"wrong",
"value",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/collection.go#L68-L78 |
3,435 | juju/juju | state/collection.go | UpdateId | func (c *modelStateCollection) UpdateId(id interface{}, update interface{}) error {
if sid, ok := id.(string); ok {
return c.WriteCollection.UpdateId(ensureModelUUID(c.modelUUID, sid), update)
}
return c.WriteCollection.UpdateId(bson.D{{"_id", id}}, update)
} | go | func (c *modelStateCollection) UpdateId(id interface{}, update interface{}) error {
if sid, ok := id.(string); ok {
return c.WriteCollection.UpdateId(ensureModelUUID(c.modelUUID, sid), update)
}
return c.WriteCollection.UpdateId(bson.D{{"_id", id}}, update)
} | [
"func",
"(",
"c",
"*",
"modelStateCollection",
")",
"UpdateId",
"(",
"id",
"interface",
"{",
"}",
",",
"update",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"sid",
",",
"ok",
":=",
"id",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"c",
".",
"WriteCollection",
".",
"UpdateId",
"(",
"ensureModelUUID",
"(",
"c",
".",
"modelUUID",
",",
"sid",
")",
",",
"update",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"WriteCollection",
".",
"UpdateId",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"id",
"}",
"}",
",",
"update",
")",
"\n",
"}"
] | // UpdateId finds a single document by _id and modifies it according to the
// update document. The id must be a string or bson.ObjectId. The model
// UUID will be automatically prefixed on to the id if it's a string and the
// prefix isn't there already. | [
"UpdateId",
"finds",
"a",
"single",
"document",
"by",
"_id",
"and",
"modifies",
"it",
"according",
"to",
"the",
"update",
"document",
".",
"The",
"id",
"must",
"be",
"a",
"string",
"or",
"bson",
".",
"ObjectId",
".",
"The",
"model",
"UUID",
"will",
"be",
"automatically",
"prefixed",
"on",
"to",
"the",
"id",
"if",
"it",
"s",
"a",
"string",
"and",
"the",
"prefix",
"isn",
"t",
"there",
"already",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/collection.go#L100-L105 |
3,436 | juju/juju | apiserver/facades/client/action/run.go | getAllUnitNames | func getAllUnitNames(st *state.State, units, services []string) (result []names.Tag, err error) {
var leaders map[string]string
getLeader := func(appName string) (string, error) {
if leaders == nil {
var err error
leaders, err = st.ApplicationLeaders()
if err != nil {
return "", err
}
}
if leader, ok := leaders[appName]; ok {
return leader, nil
}
return "", errors.Errorf("could not determine leader for %q", appName)
}
// Replace units matching $app/leader with the appropriate unit for
// the leader.
unitsSet := set.NewStrings()
for _, unit := range units {
if !strings.HasSuffix(unit, "leader") {
unitsSet.Add(unit)
continue
}
app := strings.Split(unit, "/")[0]
leaderUnit, err := getLeader(app)
if err != nil {
return nil, common.ServerError(err)
}
unitsSet.Add(leaderUnit)
}
for _, name := range services {
service, err := st.Application(name)
if err != nil {
return nil, err
}
units, err := service.AllUnits()
if err != nil {
return nil, err
}
for _, unit := range units {
unitsSet.Add(unit.Name())
}
}
for _, unitName := range unitsSet.SortedValues() {
if !names.IsValidUnit(unitName) {
return nil, errors.Errorf("invalid unit name %q", unitName)
}
result = append(result, names.NewUnitTag(unitName))
}
return result, nil
} | go | func getAllUnitNames(st *state.State, units, services []string) (result []names.Tag, err error) {
var leaders map[string]string
getLeader := func(appName string) (string, error) {
if leaders == nil {
var err error
leaders, err = st.ApplicationLeaders()
if err != nil {
return "", err
}
}
if leader, ok := leaders[appName]; ok {
return leader, nil
}
return "", errors.Errorf("could not determine leader for %q", appName)
}
// Replace units matching $app/leader with the appropriate unit for
// the leader.
unitsSet := set.NewStrings()
for _, unit := range units {
if !strings.HasSuffix(unit, "leader") {
unitsSet.Add(unit)
continue
}
app := strings.Split(unit, "/")[0]
leaderUnit, err := getLeader(app)
if err != nil {
return nil, common.ServerError(err)
}
unitsSet.Add(leaderUnit)
}
for _, name := range services {
service, err := st.Application(name)
if err != nil {
return nil, err
}
units, err := service.AllUnits()
if err != nil {
return nil, err
}
for _, unit := range units {
unitsSet.Add(unit.Name())
}
}
for _, unitName := range unitsSet.SortedValues() {
if !names.IsValidUnit(unitName) {
return nil, errors.Errorf("invalid unit name %q", unitName)
}
result = append(result, names.NewUnitTag(unitName))
}
return result, nil
} | [
"func",
"getAllUnitNames",
"(",
"st",
"*",
"state",
".",
"State",
",",
"units",
",",
"services",
"[",
"]",
"string",
")",
"(",
"result",
"[",
"]",
"names",
".",
"Tag",
",",
"err",
"error",
")",
"{",
"var",
"leaders",
"map",
"[",
"string",
"]",
"string",
"\n",
"getLeader",
":=",
"func",
"(",
"appName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"leaders",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n",
"leaders",
",",
"err",
"=",
"st",
".",
"ApplicationLeaders",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"leader",
",",
"ok",
":=",
"leaders",
"[",
"appName",
"]",
";",
"ok",
"{",
"return",
"leader",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"appName",
")",
"\n",
"}",
"\n\n",
"// Replace units matching $app/leader with the appropriate unit for",
"// the leader.",
"unitsSet",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"units",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"unit",
",",
"\"",
"\"",
")",
"{",
"unitsSet",
".",
"Add",
"(",
"unit",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"app",
":=",
"strings",
".",
"Split",
"(",
"unit",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"leaderUnit",
",",
"err",
":=",
"getLeader",
"(",
"app",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"unitsSet",
".",
"Add",
"(",
"leaderUnit",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"name",
":=",
"range",
"services",
"{",
"service",
",",
"err",
":=",
"st",
".",
"Application",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"units",
",",
"err",
":=",
"service",
".",
"AllUnits",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"units",
"{",
"unitsSet",
".",
"Add",
"(",
"unit",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"unitName",
":=",
"range",
"unitsSet",
".",
"SortedValues",
"(",
")",
"{",
"if",
"!",
"names",
".",
"IsValidUnit",
"(",
"unitName",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"unitName",
")",
"\n",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"names",
".",
"NewUnitTag",
"(",
"unitName",
")",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // getAllUnitNames returns a sequence of valid Unit objects from state. If any
// of the application names or unit names are not found, an error is returned. | [
"getAllUnitNames",
"returns",
"a",
"sequence",
"of",
"valid",
"Unit",
"objects",
"from",
"state",
".",
"If",
"any",
"of",
"the",
"application",
"names",
"or",
"unit",
"names",
"are",
"not",
"found",
"an",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/action/run.go#L22-L76 |
3,437 | juju/juju | apiserver/facades/client/action/run.go | Run | func (a *ActionAPI) Run(run params.RunParams) (results params.ActionResults, err error) {
if err := a.checkCanAdmin(); err != nil {
return results, err
}
if err := a.check.ChangeAllowed(); err != nil {
return results, errors.Trace(err)
}
units, err := getAllUnitNames(a.state, run.Units, run.Applications)
if err != nil {
return results, errors.Trace(err)
}
machines := make([]names.Tag, len(run.Machines))
for i, machineId := range run.Machines {
if !names.IsValidMachine(machineId) {
return results, errors.Errorf("invalid machine id %q", machineId)
}
machines[i] = names.NewMachineTag(machineId)
}
actionParams := a.createActionsParams(append(units, machines...), run.Commands, run.Timeout)
return queueActions(a, actionParams)
} | go | func (a *ActionAPI) Run(run params.RunParams) (results params.ActionResults, err error) {
if err := a.checkCanAdmin(); err != nil {
return results, err
}
if err := a.check.ChangeAllowed(); err != nil {
return results, errors.Trace(err)
}
units, err := getAllUnitNames(a.state, run.Units, run.Applications)
if err != nil {
return results, errors.Trace(err)
}
machines := make([]names.Tag, len(run.Machines))
for i, machineId := range run.Machines {
if !names.IsValidMachine(machineId) {
return results, errors.Errorf("invalid machine id %q", machineId)
}
machines[i] = names.NewMachineTag(machineId)
}
actionParams := a.createActionsParams(append(units, machines...), run.Commands, run.Timeout)
return queueActions(a, actionParams)
} | [
"func",
"(",
"a",
"*",
"ActionAPI",
")",
"Run",
"(",
"run",
"params",
".",
"RunParams",
")",
"(",
"results",
"params",
".",
"ActionResults",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"a",
".",
"checkCanAdmin",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"a",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"units",
",",
"err",
":=",
"getAllUnitNames",
"(",
"a",
".",
"state",
",",
"run",
".",
"Units",
",",
"run",
".",
"Applications",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"machines",
":=",
"make",
"(",
"[",
"]",
"names",
".",
"Tag",
",",
"len",
"(",
"run",
".",
"Machines",
")",
")",
"\n",
"for",
"i",
",",
"machineId",
":=",
"range",
"run",
".",
"Machines",
"{",
"if",
"!",
"names",
".",
"IsValidMachine",
"(",
"machineId",
")",
"{",
"return",
"results",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"machineId",
")",
"\n",
"}",
"\n",
"machines",
"[",
"i",
"]",
"=",
"names",
".",
"NewMachineTag",
"(",
"machineId",
")",
"\n",
"}",
"\n\n",
"actionParams",
":=",
"a",
".",
"createActionsParams",
"(",
"append",
"(",
"units",
",",
"machines",
"...",
")",
",",
"run",
".",
"Commands",
",",
"run",
".",
"Timeout",
")",
"\n\n",
"return",
"queueActions",
"(",
"a",
",",
"actionParams",
")",
"\n",
"}"
] | // Run the commands specified on the machines identified through the
// list of machines, units and services. | [
"Run",
"the",
"commands",
"specified",
"on",
"the",
"machines",
"identified",
"through",
"the",
"list",
"of",
"machines",
"units",
"and",
"services",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/action/run.go#L80-L105 |
3,438 | juju/juju | apiserver/facades/client/action/run.go | RunOnAllMachines | func (a *ActionAPI) RunOnAllMachines(run params.RunParams) (results params.ActionResults, err error) {
if err := a.checkCanAdmin(); err != nil {
return results, err
}
if err := a.check.ChangeAllowed(); err != nil {
return results, errors.Trace(err)
}
machines, err := a.state.AllMachines()
if err != nil {
return results, err
}
machineTags := make([]names.Tag, len(machines))
for i, machine := range machines {
machineTags[i] = machine.Tag()
}
actionParams := a.createActionsParams(machineTags, run.Commands, run.Timeout)
return queueActions(a, actionParams)
} | go | func (a *ActionAPI) RunOnAllMachines(run params.RunParams) (results params.ActionResults, err error) {
if err := a.checkCanAdmin(); err != nil {
return results, err
}
if err := a.check.ChangeAllowed(); err != nil {
return results, errors.Trace(err)
}
machines, err := a.state.AllMachines()
if err != nil {
return results, err
}
machineTags := make([]names.Tag, len(machines))
for i, machine := range machines {
machineTags[i] = machine.Tag()
}
actionParams := a.createActionsParams(machineTags, run.Commands, run.Timeout)
return queueActions(a, actionParams)
} | [
"func",
"(",
"a",
"*",
"ActionAPI",
")",
"RunOnAllMachines",
"(",
"run",
"params",
".",
"RunParams",
")",
"(",
"results",
"params",
".",
"ActionResults",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"a",
".",
"checkCanAdmin",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"a",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"machines",
",",
"err",
":=",
"a",
".",
"state",
".",
"AllMachines",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"err",
"\n",
"}",
"\n",
"machineTags",
":=",
"make",
"(",
"[",
"]",
"names",
".",
"Tag",
",",
"len",
"(",
"machines",
")",
")",
"\n",
"for",
"i",
",",
"machine",
":=",
"range",
"machines",
"{",
"machineTags",
"[",
"i",
"]",
"=",
"machine",
".",
"Tag",
"(",
")",
"\n",
"}",
"\n\n",
"actionParams",
":=",
"a",
".",
"createActionsParams",
"(",
"machineTags",
",",
"run",
".",
"Commands",
",",
"run",
".",
"Timeout",
")",
"\n\n",
"return",
"queueActions",
"(",
"a",
",",
"actionParams",
")",
"\n",
"}"
] | // RunOnAllMachines attempts to run the specified command on all the machines. | [
"RunOnAllMachines",
"attempts",
"to",
"run",
"the",
"specified",
"command",
"on",
"all",
"the",
"machines",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/action/run.go#L108-L129 |
3,439 | juju/juju | worker/migrationflag/manifold.go | bounceErrChanged | func bounceErrChanged(err error) error {
if errors.Cause(err) == ErrChanged {
return dependency.ErrBounce
}
return err
} | go | func bounceErrChanged(err error) error {
if errors.Cause(err) == ErrChanged {
return dependency.ErrBounce
}
return err
} | [
"func",
"bounceErrChanged",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"ErrChanged",
"{",
"return",
"dependency",
".",
"ErrBounce",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // bounceErrChanged converts ErrChanged to dependency.ErrBounce. | [
"bounceErrChanged",
"converts",
"ErrChanged",
"to",
"dependency",
".",
"ErrBounce",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/migrationflag/manifold.go#L81-L86 |
3,440 | juju/juju | upgrades/steps_237.go | stateStepsFor237 | func stateStepsFor237() []Step {
return []Step{
&upgradeStep{
description: "ensure container-image-stream isn't set in applications",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RemoveContainerImageStreamFromNonModelSettings()
},
},
}
} | go | func stateStepsFor237() []Step {
return []Step{
&upgradeStep{
description: "ensure container-image-stream isn't set in applications",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RemoveContainerImageStreamFromNonModelSettings()
},
},
}
} | [
"func",
"stateStepsFor237",
"(",
")",
"[",
"]",
"Step",
"{",
"return",
"[",
"]",
"Step",
"{",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"RemoveContainerImageStreamFromNonModelSettings",
"(",
")",
"\n",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] | // stateStepsFor237 returns upgrade steps for Juju 2.3.7 that manipulate state directly. | [
"stateStepsFor237",
"returns",
"upgrade",
"steps",
"for",
"Juju",
"2",
".",
"3",
".",
"7",
"that",
"manipulate",
"state",
"directly",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_237.go#L7-L17 |
3,441 | juju/juju | cmd/jujud/main.go | hookToolMain | func hookToolMain(commandName string, ctx *cmd.Context, args []string) (code int, err error) {
code = 1
contextId, err := getenv("JUJU_CONTEXT_ID")
if err != nil {
return
}
dir, err := getwd()
if err != nil {
return
}
req := jujuc.Request{
ContextId: contextId,
Dir: dir,
CommandName: commandName,
Args: args[1:],
}
socketPath, err := getenv("JUJU_AGENT_SOCKET")
if err != nil {
return
}
client, err := sockets.Dial(socketPath)
if err != nil {
return
}
defer client.Close()
var resp exec.ExecResponse
err = client.Call("Jujuc.Main", req, &resp)
if err != nil && err.Error() == jujuc.ErrNoStdin.Error() {
req.Stdin, err = ioutil.ReadAll(os.Stdin)
if err != nil {
err = errors.Annotate(err, "cannot read stdin")
return
}
req.StdinSet = true
err = client.Call("Jujuc.Main", req, &resp)
}
if err != nil {
return
}
os.Stdout.Write(resp.Stdout)
os.Stderr.Write(resp.Stderr)
return resp.Code, nil
} | go | func hookToolMain(commandName string, ctx *cmd.Context, args []string) (code int, err error) {
code = 1
contextId, err := getenv("JUJU_CONTEXT_ID")
if err != nil {
return
}
dir, err := getwd()
if err != nil {
return
}
req := jujuc.Request{
ContextId: contextId,
Dir: dir,
CommandName: commandName,
Args: args[1:],
}
socketPath, err := getenv("JUJU_AGENT_SOCKET")
if err != nil {
return
}
client, err := sockets.Dial(socketPath)
if err != nil {
return
}
defer client.Close()
var resp exec.ExecResponse
err = client.Call("Jujuc.Main", req, &resp)
if err != nil && err.Error() == jujuc.ErrNoStdin.Error() {
req.Stdin, err = ioutil.ReadAll(os.Stdin)
if err != nil {
err = errors.Annotate(err, "cannot read stdin")
return
}
req.StdinSet = true
err = client.Call("Jujuc.Main", req, &resp)
}
if err != nil {
return
}
os.Stdout.Write(resp.Stdout)
os.Stderr.Write(resp.Stderr)
return resp.Code, nil
} | [
"func",
"hookToolMain",
"(",
"commandName",
"string",
",",
"ctx",
"*",
"cmd",
".",
"Context",
",",
"args",
"[",
"]",
"string",
")",
"(",
"code",
"int",
",",
"err",
"error",
")",
"{",
"code",
"=",
"1",
"\n",
"contextId",
",",
"err",
":=",
"getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"dir",
",",
"err",
":=",
"getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"req",
":=",
"jujuc",
".",
"Request",
"{",
"ContextId",
":",
"contextId",
",",
"Dir",
":",
"dir",
",",
"CommandName",
":",
"commandName",
",",
"Args",
":",
"args",
"[",
"1",
":",
"]",
",",
"}",
"\n",
"socketPath",
",",
"err",
":=",
"getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"client",
",",
"err",
":=",
"sockets",
".",
"Dial",
"(",
"socketPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"client",
".",
"Close",
"(",
")",
"\n",
"var",
"resp",
"exec",
".",
"ExecResponse",
"\n",
"err",
"=",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"req",
",",
"&",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
".",
"Error",
"(",
")",
"==",
"jujuc",
".",
"ErrNoStdin",
".",
"Error",
"(",
")",
"{",
"req",
".",
"Stdin",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"os",
".",
"Stdin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"req",
".",
"StdinSet",
"=",
"true",
"\n",
"err",
"=",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"req",
",",
"&",
"resp",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"os",
".",
"Stdout",
".",
"Write",
"(",
"resp",
".",
"Stdout",
")",
"\n",
"os",
".",
"Stderr",
".",
"Write",
"(",
"resp",
".",
"Stderr",
")",
"\n",
"return",
"resp",
".",
"Code",
",",
"nil",
"\n",
"}"
] | // hookToolMain uses JUJU_CONTEXT_ID and JUJU_AGENT_SOCKET to ask a running unit agent
// to execute a Command on our behalf. Individual commands should be exposed
// by symlinking the command name to this executable. | [
"hookToolMain",
"uses",
"JUJU_CONTEXT_ID",
"and",
"JUJU_AGENT_SOCKET",
"to",
"ask",
"a",
"running",
"unit",
"agent",
"to",
"execute",
"a",
"Command",
"on",
"our",
"behalf",
".",
"Individual",
"commands",
"should",
"be",
"exposed",
"by",
"symlinking",
"the",
"command",
"name",
"to",
"this",
"executable",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/main.go#L97-L139 |
3,442 | juju/juju | cmd/jujud/main.go | jujuDMain | func jujuDMain(args []string, ctx *cmd.Context) (code int, err error) {
// Assuming an average of 200 bytes per log message, use up to
// 200MB for the log buffer.
defer logger.Debugf("jujud complete, code %d, err %v", code, err)
bufferedLogger, err := logsender.InstallBufferedLogWriter(1048576)
if err != nil {
return 1, errors.Trace(err)
}
// Set the default transport to use the in-process proxy
// configuration.
if err := proxy.DefaultConfig.Set(proxyutils.DetectProxies()); err != nil {
return 1, errors.Trace(err)
}
if err := proxy.DefaultConfig.InstallInDefaultTransport(); err != nil {
return 1, errors.Trace(err)
}
jujud := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujud",
Doc: jujudDoc,
})
jujud.Log.NewWriter = func(target io.Writer) loggo.Writer {
return &jujudWriter{target: target}
}
jujud.Register(agentcmd.NewBootstrapCommand())
// TODO(katco-): AgentConf type is doing too much. The
// MachineAgent type has called out the separate concerns; the
// AgentConf should be split up to follow suit.
agentConf := agentcmd.NewAgentConf("")
machineAgentFactory := agentcmd.MachineAgentFactoryFn(
agentConf,
bufferedLogger,
agentcmd.DefaultIntrospectionSocketName,
upgrades.PreUpgradeSteps,
"",
)
jujud.Register(agentcmd.NewMachineAgentCmd(ctx, machineAgentFactory, agentConf, agentConf))
unitAgent, err := agentcmd.NewUnitAgent(ctx, bufferedLogger)
if err != nil {
return -1, errors.Trace(err)
}
jujud.Register(unitAgent)
caasOperatorAgent, err := agentcmd.NewCaasOperatorAgent(ctx, bufferedLogger)
if err != nil {
return -1, errors.Trace(err)
}
jujud.Register(caasOperatorAgent)
jujud.Register(agentcmd.NewCheckConnectionCommand(agentConf, agentcmd.ConnectAsAgent))
code = cmd.Main(jujud, ctx, args[1:])
return code, nil
} | go | func jujuDMain(args []string, ctx *cmd.Context) (code int, err error) {
// Assuming an average of 200 bytes per log message, use up to
// 200MB for the log buffer.
defer logger.Debugf("jujud complete, code %d, err %v", code, err)
bufferedLogger, err := logsender.InstallBufferedLogWriter(1048576)
if err != nil {
return 1, errors.Trace(err)
}
// Set the default transport to use the in-process proxy
// configuration.
if err := proxy.DefaultConfig.Set(proxyutils.DetectProxies()); err != nil {
return 1, errors.Trace(err)
}
if err := proxy.DefaultConfig.InstallInDefaultTransport(); err != nil {
return 1, errors.Trace(err)
}
jujud := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujud",
Doc: jujudDoc,
})
jujud.Log.NewWriter = func(target io.Writer) loggo.Writer {
return &jujudWriter{target: target}
}
jujud.Register(agentcmd.NewBootstrapCommand())
// TODO(katco-): AgentConf type is doing too much. The
// MachineAgent type has called out the separate concerns; the
// AgentConf should be split up to follow suit.
agentConf := agentcmd.NewAgentConf("")
machineAgentFactory := agentcmd.MachineAgentFactoryFn(
agentConf,
bufferedLogger,
agentcmd.DefaultIntrospectionSocketName,
upgrades.PreUpgradeSteps,
"",
)
jujud.Register(agentcmd.NewMachineAgentCmd(ctx, machineAgentFactory, agentConf, agentConf))
unitAgent, err := agentcmd.NewUnitAgent(ctx, bufferedLogger)
if err != nil {
return -1, errors.Trace(err)
}
jujud.Register(unitAgent)
caasOperatorAgent, err := agentcmd.NewCaasOperatorAgent(ctx, bufferedLogger)
if err != nil {
return -1, errors.Trace(err)
}
jujud.Register(caasOperatorAgent)
jujud.Register(agentcmd.NewCheckConnectionCommand(agentConf, agentcmd.ConnectAsAgent))
code = cmd.Main(jujud, ctx, args[1:])
return code, nil
} | [
"func",
"jujuDMain",
"(",
"args",
"[",
"]",
"string",
",",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"(",
"code",
"int",
",",
"err",
"error",
")",
"{",
"// Assuming an average of 200 bytes per log message, use up to",
"// 200MB for the log buffer.",
"defer",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"code",
",",
"err",
")",
"\n",
"bufferedLogger",
",",
"err",
":=",
"logsender",
".",
"InstallBufferedLogWriter",
"(",
"1048576",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"1",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Set the default transport to use the in-process proxy",
"// configuration.",
"if",
"err",
":=",
"proxy",
".",
"DefaultConfig",
".",
"Set",
"(",
"proxyutils",
".",
"DetectProxies",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"1",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"proxy",
".",
"DefaultConfig",
".",
"InstallInDefaultTransport",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"1",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"jujud",
":=",
"jujucmd",
".",
"NewSuperCommand",
"(",
"cmd",
".",
"SuperCommandParams",
"{",
"Name",
":",
"\"",
"\"",
",",
"Doc",
":",
"jujudDoc",
",",
"}",
")",
"\n\n",
"jujud",
".",
"Log",
".",
"NewWriter",
"=",
"func",
"(",
"target",
"io",
".",
"Writer",
")",
"loggo",
".",
"Writer",
"{",
"return",
"&",
"jujudWriter",
"{",
"target",
":",
"target",
"}",
"\n",
"}",
"\n\n",
"jujud",
".",
"Register",
"(",
"agentcmd",
".",
"NewBootstrapCommand",
"(",
")",
")",
"\n\n",
"// TODO(katco-): AgentConf type is doing too much. The",
"// MachineAgent type has called out the separate concerns; the",
"// AgentConf should be split up to follow suit.",
"agentConf",
":=",
"agentcmd",
".",
"NewAgentConf",
"(",
"\"",
"\"",
")",
"\n",
"machineAgentFactory",
":=",
"agentcmd",
".",
"MachineAgentFactoryFn",
"(",
"agentConf",
",",
"bufferedLogger",
",",
"agentcmd",
".",
"DefaultIntrospectionSocketName",
",",
"upgrades",
".",
"PreUpgradeSteps",
",",
"\"",
"\"",
",",
")",
"\n",
"jujud",
".",
"Register",
"(",
"agentcmd",
".",
"NewMachineAgentCmd",
"(",
"ctx",
",",
"machineAgentFactory",
",",
"agentConf",
",",
"agentConf",
")",
")",
"\n\n",
"unitAgent",
",",
"err",
":=",
"agentcmd",
".",
"NewUnitAgent",
"(",
"ctx",
",",
"bufferedLogger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"jujud",
".",
"Register",
"(",
"unitAgent",
")",
"\n\n",
"caasOperatorAgent",
",",
"err",
":=",
"agentcmd",
".",
"NewCaasOperatorAgent",
"(",
"ctx",
",",
"bufferedLogger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"jujud",
".",
"Register",
"(",
"caasOperatorAgent",
")",
"\n\n",
"jujud",
".",
"Register",
"(",
"agentcmd",
".",
"NewCheckConnectionCommand",
"(",
"agentConf",
",",
"agentcmd",
".",
"ConnectAsAgent",
")",
")",
"\n\n",
"code",
"=",
"cmd",
".",
"Main",
"(",
"jujud",
",",
"ctx",
",",
"args",
"[",
"1",
":",
"]",
")",
"\n",
"return",
"code",
",",
"nil",
"\n",
"}"
] | // Main registers subcommands for the jujud executable, and hands over control
// to the cmd package. | [
"Main",
"registers",
"subcommands",
"for",
"the",
"jujud",
"executable",
"and",
"hands",
"over",
"control",
"to",
"the",
"cmd",
"package",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/main.go#L143-L201 |
3,443 | juju/juju | worker/storageprovisioner/caasworker.go | saveApplicationWorker | func (p *provisioner) saveApplicationWorker(appName string, aw worker.Worker) {
p.mu.Lock()
defer p.mu.Unlock()
if p.provisioners == nil {
p.provisioners = make(map[string]worker.Worker)
}
p.provisioners[appName] = aw
} | go | func (p *provisioner) saveApplicationWorker(appName string, aw worker.Worker) {
p.mu.Lock()
defer p.mu.Unlock()
if p.provisioners == nil {
p.provisioners = make(map[string]worker.Worker)
}
p.provisioners[appName] = aw
} | [
"func",
"(",
"p",
"*",
"provisioner",
")",
"saveApplicationWorker",
"(",
"appName",
"string",
",",
"aw",
"worker",
".",
"Worker",
")",
"{",
"p",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"p",
".",
"provisioners",
"==",
"nil",
"{",
"p",
".",
"provisioners",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"worker",
".",
"Worker",
")",
"\n",
"}",
"\n",
"p",
".",
"provisioners",
"[",
"appName",
"]",
"=",
"aw",
"\n",
"}"
] | // These helper methods protect the provisioners map so we can access for testing. | [
"These",
"helper",
"methods",
"protect",
"the",
"provisioners",
"map",
"so",
"we",
"can",
"access",
"for",
"testing",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/caasworker.go#L62-L70 |
3,444 | juju/juju | api/action/run.go | RunOnAllMachines | func (c *Client) RunOnAllMachines(commands string, timeout time.Duration) ([]params.ActionResult, error) {
var results params.ActionResults
args := params.RunParams{Commands: commands, Timeout: timeout}
err := c.facade.FacadeCall("RunOnAllMachines", args, &results)
return results.Results, err
} | go | func (c *Client) RunOnAllMachines(commands string, timeout time.Duration) ([]params.ActionResult, error) {
var results params.ActionResults
args := params.RunParams{Commands: commands, Timeout: timeout}
err := c.facade.FacadeCall("RunOnAllMachines", args, &results)
return results.Results, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RunOnAllMachines",
"(",
"commands",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"[",
"]",
"params",
".",
"ActionResult",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"ActionResults",
"\n",
"args",
":=",
"params",
".",
"RunParams",
"{",
"Commands",
":",
"commands",
",",
"Timeout",
":",
"timeout",
"}",
"\n",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"return",
"results",
".",
"Results",
",",
"err",
"\n",
"}"
] | // RunOnAllMachines runs the command on all the machines with the specified
// timeout. | [
"RunOnAllMachines",
"runs",
"the",
"command",
"on",
"all",
"the",
"machines",
"with",
"the",
"specified",
"timeout",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/action/run.go#L14-L19 |
3,445 | juju/juju | api/action/run.go | Run | func (c *Client) Run(run params.RunParams) ([]params.ActionResult, error) {
var results params.ActionResults
err := c.facade.FacadeCall("Run", run, &results)
return results.Results, err
} | go | func (c *Client) Run(run params.RunParams) ([]params.ActionResult, error) {
var results params.ActionResults
err := c.facade.FacadeCall("Run", run, &results)
return results.Results, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Run",
"(",
"run",
"params",
".",
"RunParams",
")",
"(",
"[",
"]",
"params",
".",
"ActionResult",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"ActionResults",
"\n",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"run",
",",
"&",
"results",
")",
"\n",
"return",
"results",
".",
"Results",
",",
"err",
"\n",
"}"
] | // Run the Commands specified on the machines identified through the ids
// provided in the machines, applications and units slices. | [
"Run",
"the",
"Commands",
"specified",
"on",
"the",
"machines",
"identified",
"through",
"the",
"ids",
"provided",
"in",
"the",
"machines",
"applications",
"and",
"units",
"slices",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/action/run.go#L23-L27 |
3,446 | juju/juju | state/stateenvirons/config.go | CloudAPIVersion | func (g EnvironConfigGetter) CloudAPIVersion(spec environs.CloudSpec) (string, error) {
// Only CAAS models have an API version we care about right now.
if g.Model.Type() == state.ModelTypeIAAS {
return "", nil
}
cfg, err := g.ModelConfig()
if err != nil {
return "", errors.Trace(err)
}
ctrlCfg, err := g.ControllerConfig()
if err != nil {
return "", errors.Trace(err)
}
newBroker := g.NewContainerBroker
if newBroker == nil {
newBroker = caas.New
}
broker, err := newBroker(environs.OpenParams{
ControllerUUID: ctrlCfg.ControllerUUID(),
Cloud: spec,
Config: cfg,
})
if err != nil {
return "", errors.Trace(err)
}
return broker.APIVersion()
} | go | func (g EnvironConfigGetter) CloudAPIVersion(spec environs.CloudSpec) (string, error) {
// Only CAAS models have an API version we care about right now.
if g.Model.Type() == state.ModelTypeIAAS {
return "", nil
}
cfg, err := g.ModelConfig()
if err != nil {
return "", errors.Trace(err)
}
ctrlCfg, err := g.ControllerConfig()
if err != nil {
return "", errors.Trace(err)
}
newBroker := g.NewContainerBroker
if newBroker == nil {
newBroker = caas.New
}
broker, err := newBroker(environs.OpenParams{
ControllerUUID: ctrlCfg.ControllerUUID(),
Cloud: spec,
Config: cfg,
})
if err != nil {
return "", errors.Trace(err)
}
return broker.APIVersion()
} | [
"func",
"(",
"g",
"EnvironConfigGetter",
")",
"CloudAPIVersion",
"(",
"spec",
"environs",
".",
"CloudSpec",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Only CAAS models have an API version we care about right now.",
"if",
"g",
".",
"Model",
".",
"Type",
"(",
")",
"==",
"state",
".",
"ModelTypeIAAS",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"cfg",
",",
"err",
":=",
"g",
".",
"ModelConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ctrlCfg",
",",
"err",
":=",
"g",
".",
"ControllerConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"newBroker",
":=",
"g",
".",
"NewContainerBroker",
"\n",
"if",
"newBroker",
"==",
"nil",
"{",
"newBroker",
"=",
"caas",
".",
"New",
"\n",
"}",
"\n",
"broker",
",",
"err",
":=",
"newBroker",
"(",
"environs",
".",
"OpenParams",
"{",
"ControllerUUID",
":",
"ctrlCfg",
".",
"ControllerUUID",
"(",
")",
",",
"Cloud",
":",
"spec",
",",
"Config",
":",
"cfg",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"broker",
".",
"APIVersion",
"(",
")",
"\n",
"}"
] | // CloudAPIVersion returns the cloud API version for the cloud with the given spec. | [
"CloudAPIVersion",
"returns",
"the",
"cloud",
"API",
"version",
"for",
"the",
"cloud",
"with",
"the",
"given",
"spec",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/config.go#L31-L57 |
3,447 | juju/juju | state/stateenvirons/config.go | GetNewEnvironFunc | func GetNewEnvironFunc(newEnviron environs.NewEnvironFunc) NewEnvironFunc {
return func(st *state.State) (environs.Environ, error) {
m, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
g := EnvironConfigGetter{State: st, Model: m}
return environs.GetEnviron(g, newEnviron)
}
} | go | func GetNewEnvironFunc(newEnviron environs.NewEnvironFunc) NewEnvironFunc {
return func(st *state.State) (environs.Environ, error) {
m, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
g := EnvironConfigGetter{State: st, Model: m}
return environs.GetEnviron(g, newEnviron)
}
} | [
"func",
"GetNewEnvironFunc",
"(",
"newEnviron",
"environs",
".",
"NewEnvironFunc",
")",
"NewEnvironFunc",
"{",
"return",
"func",
"(",
"st",
"*",
"state",
".",
"State",
")",
"(",
"environs",
".",
"Environ",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"g",
":=",
"EnvironConfigGetter",
"{",
"State",
":",
"st",
",",
"Model",
":",
"m",
"}",
"\n",
"return",
"environs",
".",
"GetEnviron",
"(",
"g",
",",
"newEnviron",
")",
"\n",
"}",
"\n",
"}"
] | // GetNewEnvironFunc returns a NewEnvironFunc, that constructs Environs
// using the given environs.NewEnvironFunc. | [
"GetNewEnvironFunc",
"returns",
"a",
"NewEnvironFunc",
"that",
"constructs",
"Environs",
"using",
"the",
"given",
"environs",
".",
"NewEnvironFunc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/config.go#L102-L111 |
3,448 | juju/juju | state/stateenvirons/config.go | GetNewCAASBrokerFunc | func GetNewCAASBrokerFunc(newBroker caas.NewContainerBrokerFunc) NewCAASBrokerFunc {
return func(st *state.State) (caas.Broker, error) {
m, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
g := EnvironConfigGetter{State: st, Model: m}
cloudSpec, err := g.CloudSpec()
if err != nil {
return nil, errors.Trace(err)
}
cfg, err := g.ModelConfig()
if err != nil {
return nil, errors.Trace(err)
}
ctrlCfg, err := g.ControllerConfig()
if err != nil {
return nil, errors.Trace(err)
}
return newBroker(environs.OpenParams{
ControllerUUID: ctrlCfg.ControllerUUID(),
Cloud: cloudSpec,
Config: cfg,
})
}
} | go | func GetNewCAASBrokerFunc(newBroker caas.NewContainerBrokerFunc) NewCAASBrokerFunc {
return func(st *state.State) (caas.Broker, error) {
m, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
g := EnvironConfigGetter{State: st, Model: m}
cloudSpec, err := g.CloudSpec()
if err != nil {
return nil, errors.Trace(err)
}
cfg, err := g.ModelConfig()
if err != nil {
return nil, errors.Trace(err)
}
ctrlCfg, err := g.ControllerConfig()
if err != nil {
return nil, errors.Trace(err)
}
return newBroker(environs.OpenParams{
ControllerUUID: ctrlCfg.ControllerUUID(),
Cloud: cloudSpec,
Config: cfg,
})
}
} | [
"func",
"GetNewCAASBrokerFunc",
"(",
"newBroker",
"caas",
".",
"NewContainerBrokerFunc",
")",
"NewCAASBrokerFunc",
"{",
"return",
"func",
"(",
"st",
"*",
"state",
".",
"State",
")",
"(",
"caas",
".",
"Broker",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"g",
":=",
"EnvironConfigGetter",
"{",
"State",
":",
"st",
",",
"Model",
":",
"m",
"}",
"\n",
"cloudSpec",
",",
"err",
":=",
"g",
".",
"CloudSpec",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"cfg",
",",
"err",
":=",
"g",
".",
"ModelConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ctrlCfg",
",",
"err",
":=",
"g",
".",
"ControllerConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"newBroker",
"(",
"environs",
".",
"OpenParams",
"{",
"ControllerUUID",
":",
"ctrlCfg",
".",
"ControllerUUID",
"(",
")",
",",
"Cloud",
":",
"cloudSpec",
",",
"Config",
":",
"cfg",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // GetNewCAASBrokerFunc returns a NewCAASBrokerFunc, that constructs CAAS brokers
// using the given caas.NewContainerBrokerFunc. | [
"GetNewCAASBrokerFunc",
"returns",
"a",
"NewCAASBrokerFunc",
"that",
"constructs",
"CAAS",
"brokers",
"using",
"the",
"given",
"caas",
".",
"NewContainerBrokerFunc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/config.go#L119-L144 |
3,449 | juju/juju | state/modeluser.go | setModelAccess | func (st *State) setModelAccess(access permission.Access, userGlobalKey, modelUUID string) error {
if err := permission.ValidateModelAccess(access); err != nil {
return errors.Trace(err)
}
op := updatePermissionOp(modelKey(modelUUID), userGlobalKey, access)
err := st.db().RunTransactionFor(modelUUID, []txn.Op{op})
if err == txn.ErrAborted {
return errors.NotFoundf("existing permissions")
}
return errors.Trace(err)
} | go | func (st *State) setModelAccess(access permission.Access, userGlobalKey, modelUUID string) error {
if err := permission.ValidateModelAccess(access); err != nil {
return errors.Trace(err)
}
op := updatePermissionOp(modelKey(modelUUID), userGlobalKey, access)
err := st.db().RunTransactionFor(modelUUID, []txn.Op{op})
if err == txn.ErrAborted {
return errors.NotFoundf("existing permissions")
}
return errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"setModelAccess",
"(",
"access",
"permission",
".",
"Access",
",",
"userGlobalKey",
",",
"modelUUID",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"permission",
".",
"ValidateModelAccess",
"(",
"access",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"op",
":=",
"updatePermissionOp",
"(",
"modelKey",
"(",
"modelUUID",
")",
",",
"userGlobalKey",
",",
"access",
")",
"\n",
"err",
":=",
"st",
".",
"db",
"(",
")",
".",
"RunTransactionFor",
"(",
"modelUUID",
",",
"[",
"]",
"txn",
".",
"Op",
"{",
"op",
"}",
")",
"\n",
"if",
"err",
"==",
"txn",
".",
"ErrAborted",
"{",
"return",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // setModelAccess changes the user's access permissions on the model. | [
"setModelAccess",
"changes",
"the",
"user",
"s",
"access",
"permissions",
"on",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L34-L44 |
3,450 | juju/juju | state/modeluser.go | LastModelConnection | func (m *Model) LastModelConnection(user names.UserTag) (time.Time, error) {
lastConnections, closer := m.st.db().GetRawCollection(modelUserLastConnectionC)
defer closer()
username := user.Id()
var lastConn modelUserLastConnectionDoc
err := lastConnections.FindId(m.st.docID(username)).Select(bson.D{{"last-connection", 1}}).One(&lastConn)
if err != nil {
if err == mgo.ErrNotFound {
err = errors.Wrap(err, NeverConnectedError(username))
}
return time.Time{}, errors.Trace(err)
}
return lastConn.LastConnection.UTC(), nil
} | go | func (m *Model) LastModelConnection(user names.UserTag) (time.Time, error) {
lastConnections, closer := m.st.db().GetRawCollection(modelUserLastConnectionC)
defer closer()
username := user.Id()
var lastConn modelUserLastConnectionDoc
err := lastConnections.FindId(m.st.docID(username)).Select(bson.D{{"last-connection", 1}}).One(&lastConn)
if err != nil {
if err == mgo.ErrNotFound {
err = errors.Wrap(err, NeverConnectedError(username))
}
return time.Time{}, errors.Trace(err)
}
return lastConn.LastConnection.UTC(), nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"LastModelConnection",
"(",
"user",
"names",
".",
"UserTag",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"lastConnections",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetRawCollection",
"(",
"modelUserLastConnectionC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"username",
":=",
"user",
".",
"Id",
"(",
")",
"\n",
"var",
"lastConn",
"modelUserLastConnectionDoc",
"\n",
"err",
":=",
"lastConnections",
".",
"FindId",
"(",
"m",
".",
"st",
".",
"docID",
"(",
"username",
")",
")",
".",
"Select",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"1",
"}",
"}",
")",
".",
"One",
"(",
"&",
"lastConn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"err",
"=",
"errors",
".",
"Wrap",
"(",
"err",
",",
"NeverConnectedError",
"(",
"username",
")",
")",
"\n",
"}",
"\n",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"lastConn",
".",
"LastConnection",
".",
"UTC",
"(",
")",
",",
"nil",
"\n",
"}"
] | // LastModelConnection returns when this User last connected through the API
// in UTC. The resulting time will be nil if the user has never logged in. | [
"LastModelConnection",
"returns",
"when",
"this",
"User",
"last",
"connected",
"through",
"the",
"API",
"in",
"UTC",
".",
"The",
"resulting",
"time",
"will",
"be",
"nil",
"if",
"the",
"user",
"has",
"never",
"logged",
"in",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L48-L63 |
3,451 | juju/juju | state/modeluser.go | IsNeverConnectedError | func IsNeverConnectedError(err error) bool {
_, ok := errors.Cause(err).(NeverConnectedError)
return ok
} | go | func IsNeverConnectedError(err error) bool {
_, ok := errors.Cause(err).(NeverConnectedError)
return ok
} | [
"func",
"IsNeverConnectedError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"NeverConnectedError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsNeverConnectedError returns true if err is of type NeverConnectedError. | [
"IsNeverConnectedError",
"returns",
"true",
"if",
"err",
"is",
"of",
"type",
"NeverConnectedError",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L76-L79 |
3,452 | juju/juju | state/modeluser.go | UpdateLastModelConnection | func (m *Model) UpdateLastModelConnection(user names.UserTag) error {
return m.updateLastModelConnection(user, m.st.nowToTheSecond())
} | go | func (m *Model) UpdateLastModelConnection(user names.UserTag) error {
return m.updateLastModelConnection(user, m.st.nowToTheSecond())
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"UpdateLastModelConnection",
"(",
"user",
"names",
".",
"UserTag",
")",
"error",
"{",
"return",
"m",
".",
"updateLastModelConnection",
"(",
"user",
",",
"m",
".",
"st",
".",
"nowToTheSecond",
"(",
")",
")",
"\n",
"}"
] | // UpdateLastModelConnection updates the last connection time of the model user. | [
"UpdateLastModelConnection",
"updates",
"the",
"last",
"connection",
"time",
"of",
"the",
"model",
"user",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L82-L84 |
3,453 | juju/juju | state/modeluser.go | modelUser | func (st *State) modelUser(modelUUID string, user names.UserTag) (userAccessDoc, error) {
modelUser := userAccessDoc{}
modelUsers, closer := st.db().GetCollectionFor(modelUUID, modelUsersC)
defer closer()
username := strings.ToLower(user.Id())
err := modelUsers.FindId(username).One(&modelUser)
if err == mgo.ErrNotFound {
return userAccessDoc{}, errors.NotFoundf("model user %q", username)
}
if err != nil {
return userAccessDoc{}, errors.Trace(err)
}
// DateCreated is inserted as UTC, but read out as local time. So we
// convert it back to UTC here.
modelUser.DateCreated = modelUser.DateCreated.UTC()
return modelUser, nil
} | go | func (st *State) modelUser(modelUUID string, user names.UserTag) (userAccessDoc, error) {
modelUser := userAccessDoc{}
modelUsers, closer := st.db().GetCollectionFor(modelUUID, modelUsersC)
defer closer()
username := strings.ToLower(user.Id())
err := modelUsers.FindId(username).One(&modelUser)
if err == mgo.ErrNotFound {
return userAccessDoc{}, errors.NotFoundf("model user %q", username)
}
if err != nil {
return userAccessDoc{}, errors.Trace(err)
}
// DateCreated is inserted as UTC, but read out as local time. So we
// convert it back to UTC here.
modelUser.DateCreated = modelUser.DateCreated.UTC()
return modelUser, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"modelUser",
"(",
"modelUUID",
"string",
",",
"user",
"names",
".",
"UserTag",
")",
"(",
"userAccessDoc",
",",
"error",
")",
"{",
"modelUser",
":=",
"userAccessDoc",
"{",
"}",
"\n",
"modelUsers",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollectionFor",
"(",
"modelUUID",
",",
"modelUsersC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"username",
":=",
"strings",
".",
"ToLower",
"(",
"user",
".",
"Id",
"(",
")",
")",
"\n",
"err",
":=",
"modelUsers",
".",
"FindId",
"(",
"username",
")",
".",
"One",
"(",
"&",
"modelUser",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"userAccessDoc",
"{",
"}",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"username",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"userAccessDoc",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// DateCreated is inserted as UTC, but read out as local time. So we",
"// convert it back to UTC here.",
"modelUser",
".",
"DateCreated",
"=",
"modelUser",
".",
"DateCreated",
".",
"UTC",
"(",
")",
"\n",
"return",
"modelUser",
",",
"nil",
"\n",
"}"
] | // ModelUser a model userAccessDoc. | [
"ModelUser",
"a",
"model",
"userAccessDoc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L108-L125 |
3,454 | juju/juju | state/modeluser.go | removeModelUser | func (st *State) removeModelUser(user names.UserTag) error {
ops := removeModelUserOps(st.ModelUUID(), user)
err := st.db().RunTransaction(ops)
if err == txn.ErrAborted {
err = errors.NewNotFound(nil, fmt.Sprintf("model user %q does not exist", user.Id()))
}
if err != nil {
return errors.Trace(err)
}
return nil
} | go | func (st *State) removeModelUser(user names.UserTag) error {
ops := removeModelUserOps(st.ModelUUID(), user)
err := st.db().RunTransaction(ops)
if err == txn.ErrAborted {
err = errors.NewNotFound(nil, fmt.Sprintf("model user %q does not exist", user.Id()))
}
if err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"removeModelUser",
"(",
"user",
"names",
".",
"UserTag",
")",
"error",
"{",
"ops",
":=",
"removeModelUserOps",
"(",
"st",
".",
"ModelUUID",
"(",
")",
",",
"user",
")",
"\n",
"err",
":=",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
"\n",
"if",
"err",
"==",
"txn",
".",
"ErrAborted",
"{",
"err",
"=",
"errors",
".",
"NewNotFound",
"(",
"nil",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // removeModelUser removes a user from the database. | [
"removeModelUser",
"removes",
"a",
"user",
"from",
"the",
"database",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L162-L172 |
3,455 | juju/juju | state/modeluser.go | isUserSuperuser | func (st *State) isUserSuperuser(user names.UserTag) (bool, error) {
access, err := st.UserAccess(user, st.controllerTag)
if err != nil {
// TODO(jam): 2017-11-27 We weren't suppressing NotFound here so that we would know when someone asked for
// the list of models of a user that doesn't exist.
// However, now we will not even check if its a known user if they aren't asking for all=true.
return false, errors.Trace(err)
}
isControllerSuperuser := (access.Access == permission.SuperuserAccess)
return isControllerSuperuser, nil
} | go | func (st *State) isUserSuperuser(user names.UserTag) (bool, error) {
access, err := st.UserAccess(user, st.controllerTag)
if err != nil {
// TODO(jam): 2017-11-27 We weren't suppressing NotFound here so that we would know when someone asked for
// the list of models of a user that doesn't exist.
// However, now we will not even check if its a known user if they aren't asking for all=true.
return false, errors.Trace(err)
}
isControllerSuperuser := (access.Access == permission.SuperuserAccess)
return isControllerSuperuser, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"isUserSuperuser",
"(",
"user",
"names",
".",
"UserTag",
")",
"(",
"bool",
",",
"error",
")",
"{",
"access",
",",
"err",
":=",
"st",
".",
"UserAccess",
"(",
"user",
",",
"st",
".",
"controllerTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO(jam): 2017-11-27 We weren't suppressing NotFound here so that we would know when someone asked for",
"// the list of models of a user that doesn't exist.",
"// However, now we will not even check if its a known user if they aren't asking for all=true.",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"isControllerSuperuser",
":=",
"(",
"access",
".",
"Access",
"==",
"permission",
".",
"SuperuserAccess",
")",
"\n",
"return",
"isControllerSuperuser",
",",
"nil",
"\n",
"}"
] | // isUserSuperuser if this user has the Superuser access on the controller. | [
"isUserSuperuser",
"if",
"this",
"user",
"has",
"the",
"Superuser",
"access",
"on",
"the",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L175-L185 |
3,456 | juju/juju | state/modeluser.go | modelQueryForUser | func (st *State) modelQueryForUser(user names.UserTag, isSuperuser bool) (mongo.Query, SessionCloser, error) {
var modelQuery mongo.Query
models, closer := st.db().GetCollection(modelsC)
if isSuperuser {
// Fast path, we just return all the models that aren't Importing
modelQuery = models.Find(bson.M{"migration-mode": bson.M{"$ne": MigrationModeImporting}})
} else {
// Start by looking up model uuids that the user has access to, and then load only the records that are
// included in that set
var modelUUID struct {
UUID string `bson:"object-uuid"`
}
modelUsers, userCloser := st.db().GetRawCollection(modelUsersC)
defer userCloser()
query := modelUsers.Find(bson.D{{"user", user.Id()}})
query.Select(bson.M{"object-uuid": 1, "_id": 0})
query.Batch(100)
iter := query.Iter()
var modelUUIDs []string
for iter.Next(&modelUUID) {
modelUUIDs = append(modelUUIDs, modelUUID.UUID)
}
if err := iter.Close(); err != nil {
closer()
return nil, nil, errors.Trace(err)
}
modelQuery = models.Find(bson.M{
"_id": bson.M{"$in": modelUUIDs},
"migration-mode": bson.M{"$ne": MigrationModeImporting},
})
}
modelQuery.Sort("name", "owner")
return modelQuery, closer, nil
} | go | func (st *State) modelQueryForUser(user names.UserTag, isSuperuser bool) (mongo.Query, SessionCloser, error) {
var modelQuery mongo.Query
models, closer := st.db().GetCollection(modelsC)
if isSuperuser {
// Fast path, we just return all the models that aren't Importing
modelQuery = models.Find(bson.M{"migration-mode": bson.M{"$ne": MigrationModeImporting}})
} else {
// Start by looking up model uuids that the user has access to, and then load only the records that are
// included in that set
var modelUUID struct {
UUID string `bson:"object-uuid"`
}
modelUsers, userCloser := st.db().GetRawCollection(modelUsersC)
defer userCloser()
query := modelUsers.Find(bson.D{{"user", user.Id()}})
query.Select(bson.M{"object-uuid": 1, "_id": 0})
query.Batch(100)
iter := query.Iter()
var modelUUIDs []string
for iter.Next(&modelUUID) {
modelUUIDs = append(modelUUIDs, modelUUID.UUID)
}
if err := iter.Close(); err != nil {
closer()
return nil, nil, errors.Trace(err)
}
modelQuery = models.Find(bson.M{
"_id": bson.M{"$in": modelUUIDs},
"migration-mode": bson.M{"$ne": MigrationModeImporting},
})
}
modelQuery.Sort("name", "owner")
return modelQuery, closer, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"modelQueryForUser",
"(",
"user",
"names",
".",
"UserTag",
",",
"isSuperuser",
"bool",
")",
"(",
"mongo",
".",
"Query",
",",
"SessionCloser",
",",
"error",
")",
"{",
"var",
"modelQuery",
"mongo",
".",
"Query",
"\n",
"models",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelsC",
")",
"\n",
"if",
"isSuperuser",
"{",
"// Fast path, we just return all the models that aren't Importing",
"modelQuery",
"=",
"models",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"MigrationModeImporting",
"}",
"}",
")",
"\n",
"}",
"else",
"{",
"// Start by looking up model uuids that the user has access to, and then load only the records that are",
"// included in that set",
"var",
"modelUUID",
"struct",
"{",
"UUID",
"string",
"`bson:\"object-uuid\"`",
"\n",
"}",
"\n",
"modelUsers",
",",
"userCloser",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetRawCollection",
"(",
"modelUsersC",
")",
"\n",
"defer",
"userCloser",
"(",
")",
"\n",
"query",
":=",
"modelUsers",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
"}",
"}",
")",
"\n",
"query",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
",",
"\"",
"\"",
":",
"0",
"}",
")",
"\n",
"query",
".",
"Batch",
"(",
"100",
")",
"\n",
"iter",
":=",
"query",
".",
"Iter",
"(",
")",
"\n",
"var",
"modelUUIDs",
"[",
"]",
"string",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"modelUUID",
")",
"{",
"modelUUIDs",
"=",
"append",
"(",
"modelUUIDs",
",",
"modelUUID",
".",
"UUID",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iter",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"closer",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"modelQuery",
"=",
"models",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"modelUUIDs",
"}",
",",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"MigrationModeImporting",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"modelQuery",
".",
"Sort",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"modelQuery",
",",
"closer",
",",
"nil",
"\n",
"}"
] | // modelsForUser gives you the information about all models that a user has access to.
// This includes the name and UUID, as well as the last time the user connected to that model. | [
"modelsForUser",
"gives",
"you",
"the",
"information",
"about",
"all",
"models",
"that",
"a",
"user",
"has",
"access",
"to",
".",
"This",
"includes",
"the",
"name",
"and",
"UUID",
"as",
"well",
"as",
"the",
"last",
"time",
"the",
"user",
"connected",
"to",
"that",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L234-L267 |
3,457 | juju/juju | state/modeluser.go | ModelBasicInfoForUser | func (st *State) ModelBasicInfoForUser(user names.UserTag) ([]ModelAccessInfo, error) {
isSuperuser, err := st.isUserSuperuser(user)
if err != nil {
return nil, errors.Trace(err)
}
modelQuery, closer1, err := st.modelQueryForUser(user, isSuperuser)
if err != nil {
return nil, errors.Trace(err)
}
defer closer1()
modelQuery.Select(bson.M{"_id": 1, "name": 1, "owner": 1, "type": 1})
var accessInfo []ModelAccessInfo
if err := modelQuery.All(&accessInfo); err != nil {
return nil, errors.Trace(err)
}
// Now we need to find the last-connection time for each model for this user
username := user.Id()
connDocIds := make([]string, len(accessInfo))
for i, acc := range accessInfo {
connDocIds[i] = acc.UUID + ":" + username
}
lastConnections, closer2 := st.db().GetRawCollection(modelUserLastConnectionC)
defer closer2()
query := lastConnections.Find(bson.M{"_id": bson.M{"$in": connDocIds}})
query.Select(bson.M{"last-connection": 1, "_id": 0, "model-uuid": 1})
query.Batch(100)
iter := query.Iter()
lastConns := make(map[string]time.Time, len(connDocIds))
var connInfo modelUserLastConnectionDoc
for iter.Next(&connInfo) {
lastConns[connInfo.ModelUUID] = connInfo.LastConnection
}
if err := iter.Close(); err != nil {
return nil, errors.Trace(err)
}
for i := range accessInfo {
uuid := accessInfo[i].UUID
accessInfo[i].LastConnection = lastConns[uuid]
}
return accessInfo, nil
} | go | func (st *State) ModelBasicInfoForUser(user names.UserTag) ([]ModelAccessInfo, error) {
isSuperuser, err := st.isUserSuperuser(user)
if err != nil {
return nil, errors.Trace(err)
}
modelQuery, closer1, err := st.modelQueryForUser(user, isSuperuser)
if err != nil {
return nil, errors.Trace(err)
}
defer closer1()
modelQuery.Select(bson.M{"_id": 1, "name": 1, "owner": 1, "type": 1})
var accessInfo []ModelAccessInfo
if err := modelQuery.All(&accessInfo); err != nil {
return nil, errors.Trace(err)
}
// Now we need to find the last-connection time for each model for this user
username := user.Id()
connDocIds := make([]string, len(accessInfo))
for i, acc := range accessInfo {
connDocIds[i] = acc.UUID + ":" + username
}
lastConnections, closer2 := st.db().GetRawCollection(modelUserLastConnectionC)
defer closer2()
query := lastConnections.Find(bson.M{"_id": bson.M{"$in": connDocIds}})
query.Select(bson.M{"last-connection": 1, "_id": 0, "model-uuid": 1})
query.Batch(100)
iter := query.Iter()
lastConns := make(map[string]time.Time, len(connDocIds))
var connInfo modelUserLastConnectionDoc
for iter.Next(&connInfo) {
lastConns[connInfo.ModelUUID] = connInfo.LastConnection
}
if err := iter.Close(); err != nil {
return nil, errors.Trace(err)
}
for i := range accessInfo {
uuid := accessInfo[i].UUID
accessInfo[i].LastConnection = lastConns[uuid]
}
return accessInfo, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ModelBasicInfoForUser",
"(",
"user",
"names",
".",
"UserTag",
")",
"(",
"[",
"]",
"ModelAccessInfo",
",",
"error",
")",
"{",
"isSuperuser",
",",
"err",
":=",
"st",
".",
"isUserSuperuser",
"(",
"user",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"modelQuery",
",",
"closer1",
",",
"err",
":=",
"st",
".",
"modelQueryForUser",
"(",
"user",
",",
"isSuperuser",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"closer1",
"(",
")",
"\n",
"modelQuery",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
",",
"\"",
"\"",
":",
"1",
",",
"\"",
"\"",
":",
"1",
",",
"\"",
"\"",
":",
"1",
"}",
")",
"\n",
"var",
"accessInfo",
"[",
"]",
"ModelAccessInfo",
"\n",
"if",
"err",
":=",
"modelQuery",
".",
"All",
"(",
"&",
"accessInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Now we need to find the last-connection time for each model for this user",
"username",
":=",
"user",
".",
"Id",
"(",
")",
"\n",
"connDocIds",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"accessInfo",
")",
")",
"\n",
"for",
"i",
",",
"acc",
":=",
"range",
"accessInfo",
"{",
"connDocIds",
"[",
"i",
"]",
"=",
"acc",
".",
"UUID",
"+",
"\"",
"\"",
"+",
"username",
"\n",
"}",
"\n",
"lastConnections",
",",
"closer2",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetRawCollection",
"(",
"modelUserLastConnectionC",
")",
"\n",
"defer",
"closer2",
"(",
")",
"\n",
"query",
":=",
"lastConnections",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"connDocIds",
"}",
"}",
")",
"\n",
"query",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
",",
"\"",
"\"",
":",
"0",
",",
"\"",
"\"",
":",
"1",
"}",
")",
"\n",
"query",
".",
"Batch",
"(",
"100",
")",
"\n",
"iter",
":=",
"query",
".",
"Iter",
"(",
")",
"\n",
"lastConns",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"time",
".",
"Time",
",",
"len",
"(",
"connDocIds",
")",
")",
"\n",
"var",
"connInfo",
"modelUserLastConnectionDoc",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"connInfo",
")",
"{",
"lastConns",
"[",
"connInfo",
".",
"ModelUUID",
"]",
"=",
"connInfo",
".",
"LastConnection",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iter",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"accessInfo",
"{",
"uuid",
":=",
"accessInfo",
"[",
"i",
"]",
".",
"UUID",
"\n",
"accessInfo",
"[",
"i",
"]",
".",
"LastConnection",
"=",
"lastConns",
"[",
"uuid",
"]",
"\n",
"}",
"\n",
"return",
"accessInfo",
",",
"nil",
"\n",
"}"
] | // ModelBasicInfoForUser gives you the information about all models that a user has access to.
// This includes the name and UUID, as well as the last time the user connected to that model. | [
"ModelBasicInfoForUser",
"gives",
"you",
"the",
"information",
"about",
"all",
"models",
"that",
"a",
"user",
"has",
"access",
"to",
".",
"This",
"includes",
"the",
"name",
"and",
"UUID",
"as",
"well",
"as",
"the",
"last",
"time",
"the",
"user",
"connected",
"to",
"that",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L279-L319 |
3,458 | juju/juju | state/modeluser.go | IsControllerAdmin | func (st *State) IsControllerAdmin(user names.UserTag) (bool, error) {
model, err := st.Model()
if err != nil {
return false, errors.Trace(err)
}
ua, err := st.UserAccess(user, model.ControllerTag())
if errors.IsNotFound(err) {
return false, nil
}
if err != nil {
return false, errors.Trace(err)
}
return ua.Access == permission.SuperuserAccess, nil
} | go | func (st *State) IsControllerAdmin(user names.UserTag) (bool, error) {
model, err := st.Model()
if err != nil {
return false, errors.Trace(err)
}
ua, err := st.UserAccess(user, model.ControllerTag())
if errors.IsNotFound(err) {
return false, nil
}
if err != nil {
return false, errors.Trace(err)
}
return ua.Access == permission.SuperuserAccess, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"IsControllerAdmin",
"(",
"user",
"names",
".",
"UserTag",
")",
"(",
"bool",
",",
"error",
")",
"{",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ua",
",",
"err",
":=",
"st",
".",
"UserAccess",
"(",
"user",
",",
"model",
".",
"ControllerTag",
"(",
")",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ua",
".",
"Access",
"==",
"permission",
".",
"SuperuserAccess",
",",
"nil",
"\n",
"}"
] | // IsControllerAdmin returns true if the user specified has Super User Access. | [
"IsControllerAdmin",
"returns",
"true",
"if",
"the",
"user",
"specified",
"has",
"Super",
"User",
"Access",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/modeluser.go#L379-L392 |
3,459 | juju/juju | agent/agent.go | SetAPIHostPorts | func (s APIHostPortsSetter) SetAPIHostPorts(servers [][]network.HostPort) error {
return s.ChangeConfig(func(c ConfigSetter) error {
c.SetAPIHostPorts(servers)
return nil
})
} | go | func (s APIHostPortsSetter) SetAPIHostPorts(servers [][]network.HostPort) error {
return s.ChangeConfig(func(c ConfigSetter) error {
c.SetAPIHostPorts(servers)
return nil
})
} | [
"func",
"(",
"s",
"APIHostPortsSetter",
")",
"SetAPIHostPorts",
"(",
"servers",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
")",
"error",
"{",
"return",
"s",
".",
"ChangeConfig",
"(",
"func",
"(",
"c",
"ConfigSetter",
")",
"error",
"{",
"c",
".",
"SetAPIHostPorts",
"(",
"servers",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] | // SetAPIHostPorts is the APIAddressSetter interface. | [
"SetAPIHostPorts",
"is",
"the",
"APIAddressSetter",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L73-L78 |
3,460 | juju/juju | agent/agent.go | Migrate | func (p *Paths) Migrate(newPaths Paths) {
if newPaths.DataDir != "" {
p.DataDir = newPaths.DataDir
}
if newPaths.LogDir != "" {
p.LogDir = newPaths.LogDir
}
if newPaths.MetricsSpoolDir != "" {
p.MetricsSpoolDir = newPaths.MetricsSpoolDir
}
if newPaths.ConfDir != "" {
p.ConfDir = newPaths.ConfDir
}
} | go | func (p *Paths) Migrate(newPaths Paths) {
if newPaths.DataDir != "" {
p.DataDir = newPaths.DataDir
}
if newPaths.LogDir != "" {
p.LogDir = newPaths.LogDir
}
if newPaths.MetricsSpoolDir != "" {
p.MetricsSpoolDir = newPaths.MetricsSpoolDir
}
if newPaths.ConfDir != "" {
p.ConfDir = newPaths.ConfDir
}
} | [
"func",
"(",
"p",
"*",
"Paths",
")",
"Migrate",
"(",
"newPaths",
"Paths",
")",
"{",
"if",
"newPaths",
".",
"DataDir",
"!=",
"\"",
"\"",
"{",
"p",
".",
"DataDir",
"=",
"newPaths",
".",
"DataDir",
"\n",
"}",
"\n",
"if",
"newPaths",
".",
"LogDir",
"!=",
"\"",
"\"",
"{",
"p",
".",
"LogDir",
"=",
"newPaths",
".",
"LogDir",
"\n",
"}",
"\n",
"if",
"newPaths",
".",
"MetricsSpoolDir",
"!=",
"\"",
"\"",
"{",
"p",
".",
"MetricsSpoolDir",
"=",
"newPaths",
".",
"MetricsSpoolDir",
"\n",
"}",
"\n",
"if",
"newPaths",
".",
"ConfDir",
"!=",
"\"",
"\"",
"{",
"p",
".",
"ConfDir",
"=",
"newPaths",
".",
"ConfDir",
"\n",
"}",
"\n",
"}"
] | // Migrate assigns the directory locations specified from the new path configuration. | [
"Migrate",
"assigns",
"the",
"directory",
"locations",
"specified",
"from",
"the",
"new",
"path",
"configuration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L97-L110 |
3,461 | juju/juju | agent/agent.go | NewPathsWithDefaults | func NewPathsWithDefaults(p Paths) Paths {
paths := DefaultPaths
if p.DataDir != "" {
paths.DataDir = p.DataDir
}
if p.LogDir != "" {
paths.LogDir = p.LogDir
}
if p.MetricsSpoolDir != "" {
paths.MetricsSpoolDir = p.MetricsSpoolDir
}
if p.ConfDir != "" {
paths.ConfDir = p.ConfDir
}
return paths
} | go | func NewPathsWithDefaults(p Paths) Paths {
paths := DefaultPaths
if p.DataDir != "" {
paths.DataDir = p.DataDir
}
if p.LogDir != "" {
paths.LogDir = p.LogDir
}
if p.MetricsSpoolDir != "" {
paths.MetricsSpoolDir = p.MetricsSpoolDir
}
if p.ConfDir != "" {
paths.ConfDir = p.ConfDir
}
return paths
} | [
"func",
"NewPathsWithDefaults",
"(",
"p",
"Paths",
")",
"Paths",
"{",
"paths",
":=",
"DefaultPaths",
"\n",
"if",
"p",
".",
"DataDir",
"!=",
"\"",
"\"",
"{",
"paths",
".",
"DataDir",
"=",
"p",
".",
"DataDir",
"\n",
"}",
"\n",
"if",
"p",
".",
"LogDir",
"!=",
"\"",
"\"",
"{",
"paths",
".",
"LogDir",
"=",
"p",
".",
"LogDir",
"\n",
"}",
"\n",
"if",
"p",
".",
"MetricsSpoolDir",
"!=",
"\"",
"\"",
"{",
"paths",
".",
"MetricsSpoolDir",
"=",
"p",
".",
"MetricsSpoolDir",
"\n",
"}",
"\n",
"if",
"p",
".",
"ConfDir",
"!=",
"\"",
"\"",
"{",
"paths",
".",
"ConfDir",
"=",
"p",
".",
"ConfDir",
"\n",
"}",
"\n",
"return",
"paths",
"\n",
"}"
] | // NewPathsWithDefaults returns a Paths struct initialized with default locations if not otherwise specified. | [
"NewPathsWithDefaults",
"returns",
"a",
"Paths",
"struct",
"initialized",
"with",
"default",
"locations",
"if",
"not",
"otherwise",
"specified",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L113-L128 |
3,462 | juju/juju | agent/agent.go | LogFilename | func LogFilename(c Config) string {
return filepath.Join(c.LogDir(), c.Tag().String()+".log")
} | go | func LogFilename(c Config) string {
return filepath.Join(c.LogDir(), c.Tag().String()+".log")
} | [
"func",
"LogFilename",
"(",
"c",
"Config",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"c",
".",
"LogDir",
"(",
")",
",",
"c",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
")",
"\n",
"}"
] | // LogFileName returns the filename for the Agent's log file. | [
"LogFileName",
"returns",
"the",
"filename",
"for",
"the",
"Agent",
"s",
"log",
"file",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L322-L324 |
3,463 | juju/juju | agent/agent.go | MachineLockLogFilename | func MachineLockLogFilename(c Config) string {
return filepath.Join(c.LogDir(), machinelock.Filename)
} | go | func MachineLockLogFilename(c Config) string {
return filepath.Join(c.LogDir(), machinelock.Filename)
} | [
"func",
"MachineLockLogFilename",
"(",
"c",
"Config",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"c",
".",
"LogDir",
"(",
")",
",",
"machinelock",
".",
"Filename",
")",
"\n",
"}"
] | // MachineLockLogFilename returns the filename for the machine lock log file. | [
"MachineLockLogFilename",
"returns",
"the",
"filename",
"for",
"the",
"machine",
"lock",
"log",
"file",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L327-L329 |
3,464 | juju/juju | agent/agent.go | NewAgentConfig | func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error) {
if configParams.Paths.DataDir == "" {
return nil, errors.Trace(requiredError("data directory"))
}
if configParams.Tag == nil {
return nil, errors.Trace(requiredError("entity tag"))
}
switch configParams.Tag.(type) {
case names.MachineTag, names.UnitTag, names.ApplicationTag:
// These are the only three type of tags that can represent an agent
// IAAS - machine and unit
// CAAS - application
default:
return nil, errors.Errorf("entity tag must be MachineTag, UnitTag or ApplicationTag, got %T", configParams.Tag)
}
if configParams.UpgradedToVersion == version.Zero {
return nil, errors.Trace(requiredError("upgradedToVersion"))
}
if configParams.Password == "" {
return nil, errors.Trace(requiredError("password"))
}
if uuid := configParams.Controller.Id(); uuid == "" {
return nil, errors.Trace(requiredError("controller"))
} else if !names.IsValidController(uuid) {
return nil, errors.Errorf("%q is not a valid controller uuid", uuid)
}
if uuid := configParams.Model.Id(); uuid == "" {
return nil, errors.Trace(requiredError("model"))
} else if !names.IsValidModel(uuid) {
return nil, errors.Errorf("%q is not a valid model uuid", uuid)
}
if len(configParams.CACert) == 0 {
return nil, errors.Trace(requiredError("CA certificate"))
}
// Note that the password parts of the state and api information are
// blank. This is by design: we want to generate a secure password
// for new agents. So, we create this config without a current password
// which signals to apicaller worker that it should try to connect using old password.
// When/if this connection is successful, apicaller worker will generate
// a new secure password and update this agent's config.
config := &configInternal{
paths: NewPathsWithDefaults(configParams.Paths),
jobs: configParams.Jobs,
upgradedToVersion: configParams.UpgradedToVersion,
tag: configParams.Tag,
nonce: configParams.Nonce,
controller: configParams.Controller,
model: configParams.Model,
caCert: configParams.CACert,
oldPassword: configParams.Password,
values: configParams.Values,
mongoVersion: configParams.MongoVersion.String(),
mongoMemoryProfile: configParams.MongoMemoryProfile.String(),
}
if len(configParams.APIAddresses) > 0 {
config.apiDetails = &apiDetails{
addresses: configParams.APIAddresses,
}
}
if err := config.check(); err != nil {
return nil, err
}
if config.values == nil {
config.values = make(map[string]string)
}
config.configFilePath = ConfigPath(config.paths.DataDir, config.tag)
return config, nil
} | go | func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error) {
if configParams.Paths.DataDir == "" {
return nil, errors.Trace(requiredError("data directory"))
}
if configParams.Tag == nil {
return nil, errors.Trace(requiredError("entity tag"))
}
switch configParams.Tag.(type) {
case names.MachineTag, names.UnitTag, names.ApplicationTag:
// These are the only three type of tags that can represent an agent
// IAAS - machine and unit
// CAAS - application
default:
return nil, errors.Errorf("entity tag must be MachineTag, UnitTag or ApplicationTag, got %T", configParams.Tag)
}
if configParams.UpgradedToVersion == version.Zero {
return nil, errors.Trace(requiredError("upgradedToVersion"))
}
if configParams.Password == "" {
return nil, errors.Trace(requiredError("password"))
}
if uuid := configParams.Controller.Id(); uuid == "" {
return nil, errors.Trace(requiredError("controller"))
} else if !names.IsValidController(uuid) {
return nil, errors.Errorf("%q is not a valid controller uuid", uuid)
}
if uuid := configParams.Model.Id(); uuid == "" {
return nil, errors.Trace(requiredError("model"))
} else if !names.IsValidModel(uuid) {
return nil, errors.Errorf("%q is not a valid model uuid", uuid)
}
if len(configParams.CACert) == 0 {
return nil, errors.Trace(requiredError("CA certificate"))
}
// Note that the password parts of the state and api information are
// blank. This is by design: we want to generate a secure password
// for new agents. So, we create this config without a current password
// which signals to apicaller worker that it should try to connect using old password.
// When/if this connection is successful, apicaller worker will generate
// a new secure password and update this agent's config.
config := &configInternal{
paths: NewPathsWithDefaults(configParams.Paths),
jobs: configParams.Jobs,
upgradedToVersion: configParams.UpgradedToVersion,
tag: configParams.Tag,
nonce: configParams.Nonce,
controller: configParams.Controller,
model: configParams.Model,
caCert: configParams.CACert,
oldPassword: configParams.Password,
values: configParams.Values,
mongoVersion: configParams.MongoVersion.String(),
mongoMemoryProfile: configParams.MongoMemoryProfile.String(),
}
if len(configParams.APIAddresses) > 0 {
config.apiDetails = &apiDetails{
addresses: configParams.APIAddresses,
}
}
if err := config.check(); err != nil {
return nil, err
}
if config.values == nil {
config.values = make(map[string]string)
}
config.configFilePath = ConfigPath(config.paths.DataDir, config.tag)
return config, nil
} | [
"func",
"NewAgentConfig",
"(",
"configParams",
"AgentConfigParams",
")",
"(",
"ConfigSetterWriter",
",",
"error",
")",
"{",
"if",
"configParams",
".",
"Paths",
".",
"DataDir",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"configParams",
".",
"Tag",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"switch",
"configParams",
".",
"Tag",
".",
"(",
"type",
")",
"{",
"case",
"names",
".",
"MachineTag",
",",
"names",
".",
"UnitTag",
",",
"names",
".",
"ApplicationTag",
":",
"// These are the only three type of tags that can represent an agent",
"// IAAS - machine and unit",
"// CAAS - application",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"configParams",
".",
"Tag",
")",
"\n",
"}",
"\n",
"if",
"configParams",
".",
"UpgradedToVersion",
"==",
"version",
".",
"Zero",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"configParams",
".",
"Password",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"uuid",
":=",
"configParams",
".",
"Controller",
".",
"Id",
"(",
")",
";",
"uuid",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"else",
"if",
"!",
"names",
".",
"IsValidController",
"(",
"uuid",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"uuid",
")",
"\n",
"}",
"\n",
"if",
"uuid",
":=",
"configParams",
".",
"Model",
".",
"Id",
"(",
")",
";",
"uuid",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"else",
"if",
"!",
"names",
".",
"IsValidModel",
"(",
"uuid",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"uuid",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"configParams",
".",
"CACert",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"// Note that the password parts of the state and api information are",
"// blank. This is by design: we want to generate a secure password",
"// for new agents. So, we create this config without a current password",
"// which signals to apicaller worker that it should try to connect using old password.",
"// When/if this connection is successful, apicaller worker will generate",
"// a new secure password and update this agent's config.",
"config",
":=",
"&",
"configInternal",
"{",
"paths",
":",
"NewPathsWithDefaults",
"(",
"configParams",
".",
"Paths",
")",
",",
"jobs",
":",
"configParams",
".",
"Jobs",
",",
"upgradedToVersion",
":",
"configParams",
".",
"UpgradedToVersion",
",",
"tag",
":",
"configParams",
".",
"Tag",
",",
"nonce",
":",
"configParams",
".",
"Nonce",
",",
"controller",
":",
"configParams",
".",
"Controller",
",",
"model",
":",
"configParams",
".",
"Model",
",",
"caCert",
":",
"configParams",
".",
"CACert",
",",
"oldPassword",
":",
"configParams",
".",
"Password",
",",
"values",
":",
"configParams",
".",
"Values",
",",
"mongoVersion",
":",
"configParams",
".",
"MongoVersion",
".",
"String",
"(",
")",
",",
"mongoMemoryProfile",
":",
"configParams",
".",
"MongoMemoryProfile",
".",
"String",
"(",
")",
",",
"}",
"\n",
"if",
"len",
"(",
"configParams",
".",
"APIAddresses",
")",
">",
"0",
"{",
"config",
".",
"apiDetails",
"=",
"&",
"apiDetails",
"{",
"addresses",
":",
"configParams",
".",
"APIAddresses",
",",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"config",
".",
"check",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"config",
".",
"values",
"==",
"nil",
"{",
"config",
".",
"values",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"config",
".",
"configFilePath",
"=",
"ConfigPath",
"(",
"config",
".",
"paths",
".",
"DataDir",
",",
"config",
".",
"tag",
")",
"\n",
"return",
"config",
",",
"nil",
"\n",
"}"
] | // NewAgentConfig returns a new config object suitable for use for a
// machine or unit agent. | [
"NewAgentConfig",
"returns",
"a",
"new",
"config",
"object",
"suitable",
"for",
"use",
"for",
"a",
"machine",
"or",
"unit",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L414-L481 |
3,465 | juju/juju | agent/agent.go | NewStateMachineConfig | func NewStateMachineConfig(configParams AgentConfigParams, serverInfo params.StateServingInfo) (ConfigSetterWriter, error) {
if serverInfo.Cert == "" {
return nil, errors.Trace(requiredError("controller cert"))
}
if serverInfo.PrivateKey == "" {
return nil, errors.Trace(requiredError("controller key"))
}
if serverInfo.CAPrivateKey == "" {
return nil, errors.Trace(requiredError("ca cert key"))
}
if serverInfo.StatePort == 0 {
return nil, errors.Trace(requiredError("state port"))
}
if serverInfo.APIPort == 0 {
return nil, errors.Trace(requiredError("api port"))
}
config, err := NewAgentConfig(configParams)
if err != nil {
return nil, err
}
config.SetStateServingInfo(serverInfo)
return config, nil
} | go | func NewStateMachineConfig(configParams AgentConfigParams, serverInfo params.StateServingInfo) (ConfigSetterWriter, error) {
if serverInfo.Cert == "" {
return nil, errors.Trace(requiredError("controller cert"))
}
if serverInfo.PrivateKey == "" {
return nil, errors.Trace(requiredError("controller key"))
}
if serverInfo.CAPrivateKey == "" {
return nil, errors.Trace(requiredError("ca cert key"))
}
if serverInfo.StatePort == 0 {
return nil, errors.Trace(requiredError("state port"))
}
if serverInfo.APIPort == 0 {
return nil, errors.Trace(requiredError("api port"))
}
config, err := NewAgentConfig(configParams)
if err != nil {
return nil, err
}
config.SetStateServingInfo(serverInfo)
return config, nil
} | [
"func",
"NewStateMachineConfig",
"(",
"configParams",
"AgentConfigParams",
",",
"serverInfo",
"params",
".",
"StateServingInfo",
")",
"(",
"ConfigSetterWriter",
",",
"error",
")",
"{",
"if",
"serverInfo",
".",
"Cert",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"serverInfo",
".",
"PrivateKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"serverInfo",
".",
"CAPrivateKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"serverInfo",
".",
"StatePort",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"serverInfo",
".",
"APIPort",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"requiredError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"config",
",",
"err",
":=",
"NewAgentConfig",
"(",
"configParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"config",
".",
"SetStateServingInfo",
"(",
"serverInfo",
")",
"\n",
"return",
"config",
",",
"nil",
"\n",
"}"
] | // NewStateMachineConfig returns a configuration suitable for
// a machine running the controller. | [
"NewStateMachineConfig",
"returns",
"a",
"configuration",
"suitable",
"for",
"a",
"machine",
"running",
"the",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L485-L507 |
3,466 | juju/juju | agent/agent.go | Dir | func Dir(dataDir string, tag names.Tag) string {
// Note: must use path, not filepath, as this
// function is used by the client on Windows.
return path.Join(BaseDir(dataDir), tag.String())
} | go | func Dir(dataDir string, tag names.Tag) string {
// Note: must use path, not filepath, as this
// function is used by the client on Windows.
return path.Join(BaseDir(dataDir), tag.String())
} | [
"func",
"Dir",
"(",
"dataDir",
"string",
",",
"tag",
"names",
".",
"Tag",
")",
"string",
"{",
"// Note: must use path, not filepath, as this",
"// function is used by the client on Windows.",
"return",
"path",
".",
"Join",
"(",
"BaseDir",
"(",
"dataDir",
")",
",",
"tag",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // Dir returns the agent-specific data directory. | [
"Dir",
"returns",
"the",
"agent",
"-",
"specific",
"data",
"directory",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L518-L522 |
3,467 | juju/juju | agent/agent.go | ReadConfig | func ReadConfig(configFilePath string) (ConfigSetterWriter, error) {
var (
format formatter
config *configInternal
)
configData, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, errors.Annotatef(err, "cannot read agent config %q", configFilePath)
}
format, config, err = parseConfigData(configData)
if err != nil {
return nil, err
}
logger.Debugf("read agent config, format %q", format.version())
config.configFilePath = configFilePath
return config, nil
} | go | func ReadConfig(configFilePath string) (ConfigSetterWriter, error) {
var (
format formatter
config *configInternal
)
configData, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, errors.Annotatef(err, "cannot read agent config %q", configFilePath)
}
format, config, err = parseConfigData(configData)
if err != nil {
return nil, err
}
logger.Debugf("read agent config, format %q", format.version())
config.configFilePath = configFilePath
return config, nil
} | [
"func",
"ReadConfig",
"(",
"configFilePath",
"string",
")",
"(",
"ConfigSetterWriter",
",",
"error",
")",
"{",
"var",
"(",
"format",
"formatter",
"\n",
"config",
"*",
"configInternal",
"\n",
")",
"\n",
"configData",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"configFilePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"configFilePath",
")",
"\n",
"}",
"\n",
"format",
",",
"config",
",",
"err",
"=",
"parseConfigData",
"(",
"configData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"format",
".",
"version",
"(",
")",
")",
"\n",
"config",
".",
"configFilePath",
"=",
"configFilePath",
"\n",
"return",
"config",
",",
"nil",
"\n",
"}"
] | // ReadConfig reads configuration data from the given location. | [
"ReadConfig",
"reads",
"configuration",
"data",
"from",
"the",
"given",
"location",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L532-L548 |
3,468 | juju/juju | agent/agent.go | MongoVersion | func (c *configInternal) MongoVersion() mongo.Version {
v, err := mongo.NewVersion(c.mongoVersion)
if err != nil {
return mongo.Mongo24
}
return v
} | go | func (c *configInternal) MongoVersion() mongo.Version {
v, err := mongo.NewVersion(c.mongoVersion)
if err != nil {
return mongo.Mongo24
}
return v
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"MongoVersion",
"(",
")",
"mongo",
".",
"Version",
"{",
"v",
",",
"err",
":=",
"mongo",
".",
"NewVersion",
"(",
"c",
".",
"mongoVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mongo",
".",
"Mongo24",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] | // MongoVersion implements Config. | [
"MongoVersion",
"implements",
"Config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L736-L742 |
3,469 | juju/juju | agent/agent.go | MongoMemoryProfile | func (c *configInternal) MongoMemoryProfile() mongo.MemoryProfile {
mprof := mongo.MemoryProfile(c.mongoMemoryProfile)
if err := mprof.Validate(); err != nil {
return mongo.MemoryProfileLow
}
return mongo.MemoryProfile(c.mongoMemoryProfile)
} | go | func (c *configInternal) MongoMemoryProfile() mongo.MemoryProfile {
mprof := mongo.MemoryProfile(c.mongoMemoryProfile)
if err := mprof.Validate(); err != nil {
return mongo.MemoryProfileLow
}
return mongo.MemoryProfile(c.mongoMemoryProfile)
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"MongoMemoryProfile",
"(",
")",
"mongo",
".",
"MemoryProfile",
"{",
"mprof",
":=",
"mongo",
".",
"MemoryProfile",
"(",
"c",
".",
"mongoMemoryProfile",
")",
"\n",
"if",
"err",
":=",
"mprof",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"mongo",
".",
"MemoryProfileLow",
"\n",
"}",
"\n",
"return",
"mongo",
".",
"MemoryProfile",
"(",
"c",
".",
"mongoMemoryProfile",
")",
"\n",
"}"
] | // MongoMemoryProfile implements Config. | [
"MongoMemoryProfile",
"implements",
"Config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L745-L751 |
3,470 | juju/juju | agent/agent.go | SetMongoVersion | func (c *configInternal) SetMongoVersion(v mongo.Version) {
c.mongoVersion = v.String()
} | go | func (c *configInternal) SetMongoVersion(v mongo.Version) {
c.mongoVersion = v.String()
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"SetMongoVersion",
"(",
"v",
"mongo",
".",
"Version",
")",
"{",
"c",
".",
"mongoVersion",
"=",
"v",
".",
"String",
"(",
")",
"\n",
"}"
] | // SetMongoVersion implements configSetterOnly. | [
"SetMongoVersion",
"implements",
"configSetterOnly",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L754-L756 |
3,471 | juju/juju | agent/agent.go | SetMongoMemoryProfile | func (c *configInternal) SetMongoMemoryProfile(v mongo.MemoryProfile) {
c.mongoMemoryProfile = v.String()
} | go | func (c *configInternal) SetMongoMemoryProfile(v mongo.MemoryProfile) {
c.mongoMemoryProfile = v.String()
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"SetMongoMemoryProfile",
"(",
"v",
"mongo",
".",
"MemoryProfile",
")",
"{",
"c",
".",
"mongoMemoryProfile",
"=",
"v",
".",
"String",
"(",
")",
"\n",
"}"
] | // SetMongoMemoryProfile implements configSetterOnly. | [
"SetMongoMemoryProfile",
"implements",
"configSetterOnly",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L759-L761 |
3,472 | juju/juju | agent/agent.go | WriteCommands | func (c *configInternal) WriteCommands(renderer shell.Renderer) ([]string, error) {
data, err := c.Render()
if err != nil {
return nil, errors.Trace(err)
}
commands := renderer.MkdirAll(c.Dir())
filename := c.File(AgentConfigFilename)
commands = append(commands, renderer.WriteFile(filename, data)...)
commands = append(commands, renderer.Chmod(filename, 0600)...)
return commands, nil
} | go | func (c *configInternal) WriteCommands(renderer shell.Renderer) ([]string, error) {
data, err := c.Render()
if err != nil {
return nil, errors.Trace(err)
}
commands := renderer.MkdirAll(c.Dir())
filename := c.File(AgentConfigFilename)
commands = append(commands, renderer.WriteFile(filename, data)...)
commands = append(commands, renderer.Chmod(filename, 0600)...)
return commands, nil
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"WriteCommands",
"(",
"renderer",
"shell",
".",
"Renderer",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"c",
".",
"Render",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"commands",
":=",
"renderer",
".",
"MkdirAll",
"(",
"c",
".",
"Dir",
"(",
")",
")",
"\n",
"filename",
":=",
"c",
".",
"File",
"(",
"AgentConfigFilename",
")",
"\n",
"commands",
"=",
"append",
"(",
"commands",
",",
"renderer",
".",
"WriteFile",
"(",
"filename",
",",
"data",
")",
"...",
")",
"\n",
"commands",
"=",
"append",
"(",
"commands",
",",
"renderer",
".",
"Chmod",
"(",
"filename",
",",
"0600",
")",
"...",
")",
"\n",
"return",
"commands",
",",
"nil",
"\n",
"}"
] | // WriteCommands is defined on Config interface. | [
"WriteCommands",
"is",
"defined",
"on",
"Config",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L789-L799 |
3,473 | juju/juju | agent/agent.go | APIInfo | func (c *configInternal) APIInfo() (*api.Info, bool) {
if c.apiDetails == nil || c.apiDetails.addresses == nil {
return nil, false
}
servingInfo, isController := c.StateServingInfo()
addrs := c.apiDetails.addresses
// For controller we return only localhost - we should not connect
// to other controllers if we can talk locally.
if isController {
port := servingInfo.APIPort
// If the controller has been configured with a controller api port,
// we return that instead of the normal api port.
if servingInfo.ControllerAPIPort != 0 {
port = servingInfo.ControllerAPIPort
}
// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4
// loopback, and when/if this changes localhost should resolve
// to IPv6 loopback in any case (lp:1644009). Review.
localAPIAddr := net.JoinHostPort("localhost", strconv.Itoa(port))
addrs = []string{localAPIAddr}
}
return &api.Info{
Addrs: addrs,
Password: c.apiDetails.password,
CACert: c.caCert,
Tag: c.tag,
Nonce: c.nonce,
ModelTag: c.model,
}, true
} | go | func (c *configInternal) APIInfo() (*api.Info, bool) {
if c.apiDetails == nil || c.apiDetails.addresses == nil {
return nil, false
}
servingInfo, isController := c.StateServingInfo()
addrs := c.apiDetails.addresses
// For controller we return only localhost - we should not connect
// to other controllers if we can talk locally.
if isController {
port := servingInfo.APIPort
// If the controller has been configured with a controller api port,
// we return that instead of the normal api port.
if servingInfo.ControllerAPIPort != 0 {
port = servingInfo.ControllerAPIPort
}
// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4
// loopback, and when/if this changes localhost should resolve
// to IPv6 loopback in any case (lp:1644009). Review.
localAPIAddr := net.JoinHostPort("localhost", strconv.Itoa(port))
addrs = []string{localAPIAddr}
}
return &api.Info{
Addrs: addrs,
Password: c.apiDetails.password,
CACert: c.caCert,
Tag: c.tag,
Nonce: c.nonce,
ModelTag: c.model,
}, true
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"APIInfo",
"(",
")",
"(",
"*",
"api",
".",
"Info",
",",
"bool",
")",
"{",
"if",
"c",
".",
"apiDetails",
"==",
"nil",
"||",
"c",
".",
"apiDetails",
".",
"addresses",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"servingInfo",
",",
"isController",
":=",
"c",
".",
"StateServingInfo",
"(",
")",
"\n",
"addrs",
":=",
"c",
".",
"apiDetails",
".",
"addresses",
"\n",
"// For controller we return only localhost - we should not connect",
"// to other controllers if we can talk locally.",
"if",
"isController",
"{",
"port",
":=",
"servingInfo",
".",
"APIPort",
"\n",
"// If the controller has been configured with a controller api port,",
"// we return that instead of the normal api port.",
"if",
"servingInfo",
".",
"ControllerAPIPort",
"!=",
"0",
"{",
"port",
"=",
"servingInfo",
".",
"ControllerAPIPort",
"\n",
"}",
"\n",
"// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4",
"// loopback, and when/if this changes localhost should resolve",
"// to IPv6 loopback in any case (lp:1644009). Review.",
"localAPIAddr",
":=",
"net",
".",
"JoinHostPort",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"port",
")",
")",
"\n",
"addrs",
"=",
"[",
"]",
"string",
"{",
"localAPIAddr",
"}",
"\n",
"}",
"\n",
"return",
"&",
"api",
".",
"Info",
"{",
"Addrs",
":",
"addrs",
",",
"Password",
":",
"c",
".",
"apiDetails",
".",
"password",
",",
"CACert",
":",
"c",
".",
"caCert",
",",
"Tag",
":",
"c",
".",
"tag",
",",
"Nonce",
":",
"c",
".",
"nonce",
",",
"ModelTag",
":",
"c",
".",
"model",
",",
"}",
",",
"true",
"\n",
"}"
] | // APIInfo is defined on Config interface. | [
"APIInfo",
"is",
"defined",
"on",
"Config",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L802-L831 |
3,474 | juju/juju | agent/agent.go | MongoInfo | func (c *configInternal) MongoInfo() (info *mongo.MongoInfo, ok bool) {
ssi, ok := c.StateServingInfo()
if !ok {
return nil, false
}
// We return localhost first and then all addresses of known API
// endpoints - this lets us connect to other Mongo instances and start
// state even if our own Mongo has not started yet (see lp:1749383 #1).
// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4 loopback,
// and when/if this changes localhost should resolve to IPv6 loopback
// in any case (lp:1644009). Review.
local := net.JoinHostPort("localhost", strconv.Itoa(ssi.StatePort))
addrs := []string{local}
for _, addr := range c.apiDetails.addresses {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, false
}
if host := net.JoinHostPort(host, strconv.Itoa(ssi.StatePort)); host != local {
addrs = append(addrs, host)
}
}
return &mongo.MongoInfo{
Info: mongo.Info{
Addrs: addrs,
CACert: c.caCert,
},
Password: c.statePassword,
Tag: c.tag,
}, true
} | go | func (c *configInternal) MongoInfo() (info *mongo.MongoInfo, ok bool) {
ssi, ok := c.StateServingInfo()
if !ok {
return nil, false
}
// We return localhost first and then all addresses of known API
// endpoints - this lets us connect to other Mongo instances and start
// state even if our own Mongo has not started yet (see lp:1749383 #1).
// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4 loopback,
// and when/if this changes localhost should resolve to IPv6 loopback
// in any case (lp:1644009). Review.
local := net.JoinHostPort("localhost", strconv.Itoa(ssi.StatePort))
addrs := []string{local}
for _, addr := range c.apiDetails.addresses {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, false
}
if host := net.JoinHostPort(host, strconv.Itoa(ssi.StatePort)); host != local {
addrs = append(addrs, host)
}
}
return &mongo.MongoInfo{
Info: mongo.Info{
Addrs: addrs,
CACert: c.caCert,
},
Password: c.statePassword,
Tag: c.tag,
}, true
} | [
"func",
"(",
"c",
"*",
"configInternal",
")",
"MongoInfo",
"(",
")",
"(",
"info",
"*",
"mongo",
".",
"MongoInfo",
",",
"ok",
"bool",
")",
"{",
"ssi",
",",
"ok",
":=",
"c",
".",
"StateServingInfo",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"// We return localhost first and then all addresses of known API",
"// endpoints - this lets us connect to other Mongo instances and start",
"// state even if our own Mongo has not started yet (see lp:1749383 #1).",
"// TODO(macgreagoir) IPv6. Ubuntu still always provides IPv4 loopback,",
"// and when/if this changes localhost should resolve to IPv6 loopback",
"// in any case (lp:1644009). Review.",
"local",
":=",
"net",
".",
"JoinHostPort",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"ssi",
".",
"StatePort",
")",
")",
"\n",
"addrs",
":=",
"[",
"]",
"string",
"{",
"local",
"}",
"\n\n",
"for",
"_",
",",
"addr",
":=",
"range",
"c",
".",
"apiDetails",
".",
"addresses",
"{",
"host",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"if",
"host",
":=",
"net",
".",
"JoinHostPort",
"(",
"host",
",",
"strconv",
".",
"Itoa",
"(",
"ssi",
".",
"StatePort",
")",
")",
";",
"host",
"!=",
"local",
"{",
"addrs",
"=",
"append",
"(",
"addrs",
",",
"host",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"mongo",
".",
"MongoInfo",
"{",
"Info",
":",
"mongo",
".",
"Info",
"{",
"Addrs",
":",
"addrs",
",",
"CACert",
":",
"c",
".",
"caCert",
",",
"}",
",",
"Password",
":",
"c",
".",
"statePassword",
",",
"Tag",
":",
"c",
".",
"tag",
",",
"}",
",",
"true",
"\n",
"}"
] | // MongoInfo is defined on Config interface. | [
"MongoInfo",
"is",
"defined",
"on",
"Config",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agent.go#L834-L865 |
3,475 | juju/juju | apiserver/restrict_caasmodel.go | isCAASModelFacade | func isCAASModelFacade(facadeName string) bool {
return caasModelFacadeNames.Contains(facadeName) ||
commonModelFacadeNames.Contains(facadeName) ||
commonFacadeNames.Contains(facadeName)
} | go | func isCAASModelFacade(facadeName string) bool {
return caasModelFacadeNames.Contains(facadeName) ||
commonModelFacadeNames.Contains(facadeName) ||
commonFacadeNames.Contains(facadeName)
} | [
"func",
"isCAASModelFacade",
"(",
"facadeName",
"string",
")",
"bool",
"{",
"return",
"caasModelFacadeNames",
".",
"Contains",
"(",
"facadeName",
")",
"||",
"commonModelFacadeNames",
".",
"Contains",
"(",
"facadeName",
")",
"||",
"commonFacadeNames",
".",
"Contains",
"(",
"facadeName",
")",
"\n",
"}"
] | // isCAASModelFacade reports whether the given facade name can be accessed
// using the controller connection. | [
"isCAASModelFacade",
"reports",
"whether",
"the",
"given",
"facade",
"name",
"can",
"be",
"accessed",
"using",
"the",
"controller",
"connection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/restrict_caasmodel.go#L94-L98 |
3,476 | juju/juju | cmd/juju/common/errors.go | UserErr | func (e *TermsRequiredError) UserErr() error {
terms := strings.Join(e.Terms, " ")
return errors.Wrap(e,
errors.Errorf(`Declined: some terms require agreement. Try: "juju agree %s"`, terms))
} | go | func (e *TermsRequiredError) UserErr() error {
terms := strings.Join(e.Terms, " ")
return errors.Wrap(e,
errors.Errorf(`Declined: some terms require agreement. Try: "juju agree %s"`, terms))
} | [
"func",
"(",
"e",
"*",
"TermsRequiredError",
")",
"UserErr",
"(",
")",
"error",
"{",
"terms",
":=",
"strings",
".",
"Join",
"(",
"e",
".",
"Terms",
",",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"Wrap",
"(",
"e",
",",
"errors",
".",
"Errorf",
"(",
"`Declined: some terms require agreement. Try: \"juju agree %s\"`",
",",
"terms",
")",
")",
"\n",
"}"
] | // UserErr returns an error containing a user-friendly message describing how
// to agree to required terms. | [
"UserErr",
"returns",
"an",
"error",
"containing",
"a",
"user",
"-",
"friendly",
"message",
"describing",
"how",
"to",
"agree",
"to",
"required",
"terms",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/errors.go#L56-L60 |
3,477 | juju/juju | environs/instances/image.go | String | func (ic *InstanceConstraint) String() string {
return fmt.Sprintf(
"{region: %s, series: %s, arches: %s, constraints: %s, storage: %s}",
ic.Region,
ic.Series,
ic.Arches,
ic.Constraints,
ic.Storage,
)
} | go | func (ic *InstanceConstraint) String() string {
return fmt.Sprintf(
"{region: %s, series: %s, arches: %s, constraints: %s, storage: %s}",
ic.Region,
ic.Series,
ic.Arches,
ic.Constraints,
ic.Storage,
)
} | [
"func",
"(",
"ic",
"*",
"InstanceConstraint",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ic",
".",
"Region",
",",
"ic",
".",
"Series",
",",
"ic",
".",
"Arches",
",",
"ic",
".",
"Constraints",
",",
"ic",
".",
"Storage",
",",
")",
"\n",
"}"
] | // String returns a human readable form of this InstanceConstraint. | [
"String",
"returns",
"a",
"human",
"readable",
"form",
"of",
"this",
"InstanceConstraint",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/instances/image.go#L39-L48 |
3,478 | juju/juju | environs/instances/image.go | match | func (image Image) match(itype InstanceType) imageMatch {
if !image.matchArch(itype.Arches) {
return nonMatch
}
if itype.VirtType == nil || image.VirtType == *itype.VirtType {
return exactMatch
}
if image.VirtType == "" {
// Image doesn't specify virtualisation type. We allow it
// to match, but prefer exact matches.
return partialMatch
}
return nonMatch
} | go | func (image Image) match(itype InstanceType) imageMatch {
if !image.matchArch(itype.Arches) {
return nonMatch
}
if itype.VirtType == nil || image.VirtType == *itype.VirtType {
return exactMatch
}
if image.VirtType == "" {
// Image doesn't specify virtualisation type. We allow it
// to match, but prefer exact matches.
return partialMatch
}
return nonMatch
} | [
"func",
"(",
"image",
"Image",
")",
"match",
"(",
"itype",
"InstanceType",
")",
"imageMatch",
"{",
"if",
"!",
"image",
".",
"matchArch",
"(",
"itype",
".",
"Arches",
")",
"{",
"return",
"nonMatch",
"\n",
"}",
"\n",
"if",
"itype",
".",
"VirtType",
"==",
"nil",
"||",
"image",
".",
"VirtType",
"==",
"*",
"itype",
".",
"VirtType",
"{",
"return",
"exactMatch",
"\n",
"}",
"\n",
"if",
"image",
".",
"VirtType",
"==",
"\"",
"\"",
"{",
"// Image doesn't specify virtualisation type. We allow it",
"// to match, but prefer exact matches.",
"return",
"partialMatch",
"\n",
"}",
"\n",
"return",
"nonMatch",
"\n",
"}"
] | // match returns true if the image can run on the supplied instance type. | [
"match",
"returns",
"true",
"if",
"the",
"image",
"can",
"run",
"on",
"the",
"supplied",
"instance",
"type",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/instances/image.go#L170-L183 |
3,479 | juju/juju | worker/externalcontrollerupdater/externalcontrollerupdater.go | New | func New(
externalControllers ExternalControllerUpdaterClient,
newExternalControllerWatcherClient NewExternalControllerWatcherClientFunc,
clock clock.Clock,
) (worker.Worker, error) {
w := updaterWorker{
watchExternalControllers: externalControllers.WatchExternalControllers,
externalControllerInfo: externalControllers.ExternalControllerInfo,
setExternalControllerInfo: externalControllers.SetExternalControllerInfo,
newExternalControllerWatcherClient: newExternalControllerWatcherClient,
runner: worker.NewRunner(worker.RunnerParams{
// One of the controller watchers fails should not
// prevent the others from running.
IsFatal: func(error) bool { return false },
// If the API connection fails, try again in 1 minute.
RestartDelay: time.Minute,
Clock: clock,
}),
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &w.catacomb,
Work: w.loop,
Init: []worker.Worker{w.runner},
}); err != nil {
return nil, errors.Trace(err)
}
return &w, nil
} | go | func New(
externalControllers ExternalControllerUpdaterClient,
newExternalControllerWatcherClient NewExternalControllerWatcherClientFunc,
clock clock.Clock,
) (worker.Worker, error) {
w := updaterWorker{
watchExternalControllers: externalControllers.WatchExternalControllers,
externalControllerInfo: externalControllers.ExternalControllerInfo,
setExternalControllerInfo: externalControllers.SetExternalControllerInfo,
newExternalControllerWatcherClient: newExternalControllerWatcherClient,
runner: worker.NewRunner(worker.RunnerParams{
// One of the controller watchers fails should not
// prevent the others from running.
IsFatal: func(error) bool { return false },
// If the API connection fails, try again in 1 minute.
RestartDelay: time.Minute,
Clock: clock,
}),
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &w.catacomb,
Work: w.loop,
Init: []worker.Worker{w.runner},
}); err != nil {
return nil, errors.Trace(err)
}
return &w, nil
} | [
"func",
"New",
"(",
"externalControllers",
"ExternalControllerUpdaterClient",
",",
"newExternalControllerWatcherClient",
"NewExternalControllerWatcherClientFunc",
",",
"clock",
"clock",
".",
"Clock",
",",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"w",
":=",
"updaterWorker",
"{",
"watchExternalControllers",
":",
"externalControllers",
".",
"WatchExternalControllers",
",",
"externalControllerInfo",
":",
"externalControllers",
".",
"ExternalControllerInfo",
",",
"setExternalControllerInfo",
":",
"externalControllers",
".",
"SetExternalControllerInfo",
",",
"newExternalControllerWatcherClient",
":",
"newExternalControllerWatcherClient",
",",
"runner",
":",
"worker",
".",
"NewRunner",
"(",
"worker",
".",
"RunnerParams",
"{",
"// One of the controller watchers fails should not",
"// prevent the others from running.",
"IsFatal",
":",
"func",
"(",
"error",
")",
"bool",
"{",
"return",
"false",
"}",
",",
"// If the API connection fails, try again in 1 minute.",
"RestartDelay",
":",
"time",
".",
"Minute",
",",
"Clock",
":",
"clock",
",",
"}",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"catacomb",
".",
"Invoke",
"(",
"catacomb",
".",
"Plan",
"{",
"Site",
":",
"&",
"w",
".",
"catacomb",
",",
"Work",
":",
"w",
".",
"loop",
",",
"Init",
":",
"[",
"]",
"worker",
".",
"Worker",
"{",
"w",
".",
"runner",
"}",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"w",
",",
"nil",
"\n",
"}"
] | // New returns a new external controller updater worker. | [
"New",
"returns",
"a",
"new",
"external",
"controller",
"updater",
"worker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/externalcontrollerupdater/externalcontrollerupdater.go#L58-L86 |
3,480 | juju/juju | provider/common/mocks/availability_zone.go | NewMockAvailabilityZone | func NewMockAvailabilityZone(ctrl *gomock.Controller) *MockAvailabilityZone {
mock := &MockAvailabilityZone{ctrl: ctrl}
mock.recorder = &MockAvailabilityZoneMockRecorder{mock}
return mock
} | go | func NewMockAvailabilityZone(ctrl *gomock.Controller) *MockAvailabilityZone {
mock := &MockAvailabilityZone{ctrl: ctrl}
mock.recorder = &MockAvailabilityZoneMockRecorder{mock}
return mock
} | [
"func",
"NewMockAvailabilityZone",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockAvailabilityZone",
"{",
"mock",
":=",
"&",
"MockAvailabilityZone",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockAvailabilityZoneMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockAvailabilityZone creates a new mock instance | [
"NewMockAvailabilityZone",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/availability_zone.go#L24-L28 |
3,481 | juju/juju | provider/common/mocks/availability_zone.go | Available | func (m *MockAvailabilityZone) Available() bool {
ret := m.ctrl.Call(m, "Available")
ret0, _ := ret[0].(bool)
return ret0
} | go | func (m *MockAvailabilityZone) Available() bool {
ret := m.ctrl.Call(m, "Available")
ret0, _ := ret[0].(bool)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockAvailabilityZone",
")",
"Available",
"(",
")",
"bool",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Available mocks base method | [
"Available",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/availability_zone.go#L36-L40 |
3,482 | juju/juju | provider/common/mocks/availability_zone.go | Available | func (mr *MockAvailabilityZoneMockRecorder) Available() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Available", reflect.TypeOf((*MockAvailabilityZone)(nil).Available))
} | go | func (mr *MockAvailabilityZoneMockRecorder) Available() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Available", reflect.TypeOf((*MockAvailabilityZone)(nil).Available))
} | [
"func",
"(",
"mr",
"*",
"MockAvailabilityZoneMockRecorder",
")",
"Available",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockAvailabilityZone",
")",
"(",
"nil",
")",
".",
"Available",
")",
")",
"\n",
"}"
] | // Available indicates an expected call of Available | [
"Available",
"indicates",
"an",
"expected",
"call",
"of",
"Available"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/availability_zone.go#L43-L45 |
3,483 | juju/juju | apiserver/logsink/mocks/metrics_collector_mock.go | NewMockMetricsCollector | func NewMockMetricsCollector(ctrl *gomock.Controller) *MockMetricsCollector {
mock := &MockMetricsCollector{ctrl: ctrl}
mock.recorder = &MockMetricsCollectorMockRecorder{mock}
return mock
} | go | func NewMockMetricsCollector(ctrl *gomock.Controller) *MockMetricsCollector {
mock := &MockMetricsCollector{ctrl: ctrl}
mock.recorder = &MockMetricsCollectorMockRecorder{mock}
return mock
} | [
"func",
"NewMockMetricsCollector",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockMetricsCollector",
"{",
"mock",
":=",
"&",
"MockMetricsCollector",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockMetricsCollectorMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockMetricsCollector creates a new mock instance | [
"NewMockMetricsCollector",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/mocks/metrics_collector_mock.go#L25-L29 |
3,484 | juju/juju | apiserver/logsink/mocks/metrics_collector_mock.go | Connections | func (m *MockMetricsCollector) Connections() prometheus.Gauge {
ret := m.ctrl.Call(m, "Connections")
ret0, _ := ret[0].(prometheus.Gauge)
return ret0
} | go | func (m *MockMetricsCollector) Connections() prometheus.Gauge {
ret := m.ctrl.Call(m, "Connections")
ret0, _ := ret[0].(prometheus.Gauge)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMetricsCollector",
")",
"Connections",
"(",
")",
"prometheus",
".",
"Gauge",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"prometheus",
".",
"Gauge",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Connections mocks base method | [
"Connections",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/mocks/metrics_collector_mock.go#L37-L41 |
3,485 | juju/juju | apiserver/logsink/mocks/metrics_collector_mock.go | LogReadCount | func (m *MockMetricsCollector) LogReadCount(arg0, arg1 string) prometheus.Counter {
ret := m.ctrl.Call(m, "LogReadCount", arg0, arg1)
ret0, _ := ret[0].(prometheus.Counter)
return ret0
} | go | func (m *MockMetricsCollector) LogReadCount(arg0, arg1 string) prometheus.Counter {
ret := m.ctrl.Call(m, "LogReadCount", arg0, arg1)
ret0, _ := ret[0].(prometheus.Counter)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMetricsCollector",
")",
"LogReadCount",
"(",
"arg0",
",",
"arg1",
"string",
")",
"prometheus",
".",
"Counter",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"prometheus",
".",
"Counter",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // LogReadCount mocks base method | [
"LogReadCount",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/mocks/metrics_collector_mock.go#L49-L53 |
3,486 | juju/juju | apiserver/logsink/mocks/metrics_collector_mock.go | LogReadCount | func (mr *MockMetricsCollectorMockRecorder) LogReadCount(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LogReadCount", reflect.TypeOf((*MockMetricsCollector)(nil).LogReadCount), arg0, arg1)
} | go | func (mr *MockMetricsCollectorMockRecorder) LogReadCount(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LogReadCount", reflect.TypeOf((*MockMetricsCollector)(nil).LogReadCount), arg0, arg1)
} | [
"func",
"(",
"mr",
"*",
"MockMetricsCollectorMockRecorder",
")",
"LogReadCount",
"(",
"arg0",
",",
"arg1",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMetricsCollector",
")",
"(",
"nil",
")",
".",
"LogReadCount",
")",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // LogReadCount indicates an expected call of LogReadCount | [
"LogReadCount",
"indicates",
"an",
"expected",
"call",
"of",
"LogReadCount"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/mocks/metrics_collector_mock.go#L56-L58 |
3,487 | juju/juju | apiserver/logsink/mocks/metrics_collector_mock.go | PingFailureCount | func (m *MockMetricsCollector) PingFailureCount(arg0 string) prometheus.Counter {
ret := m.ctrl.Call(m, "PingFailureCount", arg0)
ret0, _ := ret[0].(prometheus.Counter)
return ret0
} | go | func (m *MockMetricsCollector) PingFailureCount(arg0 string) prometheus.Counter {
ret := m.ctrl.Call(m, "PingFailureCount", arg0)
ret0, _ := ret[0].(prometheus.Counter)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMetricsCollector",
")",
"PingFailureCount",
"(",
"arg0",
"string",
")",
"prometheus",
".",
"Counter",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"prometheus",
".",
"Counter",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // PingFailureCount mocks base method | [
"PingFailureCount",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/mocks/metrics_collector_mock.go#L73-L77 |
3,488 | juju/juju | apiserver/logsink/mocks/metrics_collector_mock.go | TotalConnections | func (m *MockMetricsCollector) TotalConnections() prometheus.Counter {
ret := m.ctrl.Call(m, "TotalConnections")
ret0, _ := ret[0].(prometheus.Counter)
return ret0
} | go | func (m *MockMetricsCollector) TotalConnections() prometheus.Counter {
ret := m.ctrl.Call(m, "TotalConnections")
ret0, _ := ret[0].(prometheus.Counter)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMetricsCollector",
")",
"TotalConnections",
"(",
")",
"prometheus",
".",
"Counter",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"prometheus",
".",
"Counter",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // TotalConnections mocks base method | [
"TotalConnections",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/mocks/metrics_collector_mock.go#L85-L89 |
3,489 | juju/juju | worker/applicationscaler/shim.go | NewFacade | func NewFacade(apiCaller base.APICaller) (Facade, error) {
return applicationscaler.NewAPI(
apiCaller,
watcher.NewStringsWatcher,
), nil
} | go | func NewFacade(apiCaller base.APICaller) (Facade, error) {
return applicationscaler.NewAPI(
apiCaller,
watcher.NewStringsWatcher,
), nil
} | [
"func",
"NewFacade",
"(",
"apiCaller",
"base",
".",
"APICaller",
")",
"(",
"Facade",
",",
"error",
")",
"{",
"return",
"applicationscaler",
".",
"NewAPI",
"(",
"apiCaller",
",",
"watcher",
".",
"NewStringsWatcher",
",",
")",
",",
"nil",
"\n",
"}"
] | // NewFacade creates a Facade from a base.APICaller.
// It's a sensible value for ManifoldConfig.NewFacade. | [
"NewFacade",
"creates",
"a",
"Facade",
"from",
"a",
"base",
".",
"APICaller",
".",
"It",
"s",
"a",
"sensible",
"value",
"for",
"ManifoldConfig",
".",
"NewFacade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/applicationscaler/shim.go#L14-L19 |
3,490 | juju/juju | worker/raft/rafttransport/streamlayer.go | Close | func (l *streamLayer) Close() error {
l.tomb.Kill(nil)
return l.tomb.Wait()
} | go | func (l *streamLayer) Close() error {
l.tomb.Kill(nil)
return l.tomb.Wait()
} | [
"func",
"(",
"l",
"*",
"streamLayer",
")",
"Close",
"(",
")",
"error",
"{",
"l",
".",
"tomb",
".",
"Kill",
"(",
"nil",
")",
"\n",
"return",
"l",
".",
"tomb",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Close closes the layer. | [
"Close",
"closes",
"the",
"layer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/rafttransport/streamlayer.go#L108-L111 |
3,491 | juju/juju | worker/raft/rafttransport/streamlayer.go | Addr | func (l *streamLayer) Addr() net.Addr {
select {
case <-l.tomb.Dying():
return invalidAddr
case <-l.clock.After(AddrTimeout):
logger.Errorf("streamLayer.Addr timed out waiting for API address")
// Stop this (and parent) worker.
l.tomb.Kill(ErrAddressTimeout)
return invalidAddr
case addr := <-l.addr:
return addr
}
} | go | func (l *streamLayer) Addr() net.Addr {
select {
case <-l.tomb.Dying():
return invalidAddr
case <-l.clock.After(AddrTimeout):
logger.Errorf("streamLayer.Addr timed out waiting for API address")
// Stop this (and parent) worker.
l.tomb.Kill(ErrAddressTimeout)
return invalidAddr
case addr := <-l.addr:
return addr
}
} | [
"func",
"(",
"l",
"*",
"streamLayer",
")",
"Addr",
"(",
")",
"net",
".",
"Addr",
"{",
"select",
"{",
"case",
"<-",
"l",
".",
"tomb",
".",
"Dying",
"(",
")",
":",
"return",
"invalidAddr",
"\n",
"case",
"<-",
"l",
".",
"clock",
".",
"After",
"(",
"AddrTimeout",
")",
":",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"// Stop this (and parent) worker.",
"l",
".",
"tomb",
".",
"Kill",
"(",
"ErrAddressTimeout",
")",
"\n",
"return",
"invalidAddr",
"\n",
"case",
"addr",
":=",
"<-",
"l",
".",
"addr",
":",
"return",
"addr",
"\n",
"}",
"\n",
"}"
] | // Addr returns the local address for the layer. | [
"Addr",
"returns",
"the",
"local",
"address",
"for",
"the",
"layer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/rafttransport/streamlayer.go#L116-L128 |
3,492 | juju/juju | component/all/resource.go | registerForServer | func (r resources) registerForServer() error {
r.registerState()
r.registerAgentWorkers()
r.registerHookContext()
return nil
} | go | func (r resources) registerForServer() error {
r.registerState()
r.registerAgentWorkers()
r.registerHookContext()
return nil
} | [
"func",
"(",
"r",
"resources",
")",
"registerForServer",
"(",
")",
"error",
"{",
"r",
".",
"registerState",
"(",
")",
"\n",
"r",
".",
"registerAgentWorkers",
"(",
")",
"\n",
"r",
".",
"registerHookContext",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // RegisterForServer is the top-level registration method
// for the component in a jujud context. | [
"RegisterForServer",
"is",
"the",
"top",
"-",
"level",
"registration",
"method",
"for",
"the",
"component",
"in",
"a",
"jujud",
"context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/component/all/resource.go#L28-L33 |
3,493 | juju/juju | component/all/resource.go | registerAgentWorkers | func (r resources) registerAgentWorkers() {
if !markRegistered(resource.ComponentName, "agent-workers") {
return
}
charmrevisionupdater.RegisterLatestCharmHandler("resources", resourceadapters.NewLatestCharmHandler)
} | go | func (r resources) registerAgentWorkers() {
if !markRegistered(resource.ComponentName, "agent-workers") {
return
}
charmrevisionupdater.RegisterLatestCharmHandler("resources", resourceadapters.NewLatestCharmHandler)
} | [
"func",
"(",
"r",
"resources",
")",
"registerAgentWorkers",
"(",
")",
"{",
"if",
"!",
"markRegistered",
"(",
"resource",
".",
"ComponentName",
",",
"\"",
"\"",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"charmrevisionupdater",
".",
"RegisterLatestCharmHandler",
"(",
"\"",
"\"",
",",
"resourceadapters",
".",
"NewLatestCharmHandler",
")",
"\n",
"}"
] | // registerAgentWorkers adds the resources workers to the agents. | [
"registerAgentWorkers",
"adds",
"the",
"resources",
"workers",
"to",
"the",
"agents",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/component/all/resource.go#L44-L50 |
3,494 | juju/juju | provider/common/mocks/zoned_environ.go | NewMockZonedEnviron | func NewMockZonedEnviron(ctrl *gomock.Controller) *MockZonedEnviron {
mock := &MockZonedEnviron{ctrl: ctrl}
mock.recorder = &MockZonedEnvironMockRecorder{mock}
return mock
} | go | func NewMockZonedEnviron(ctrl *gomock.Controller) *MockZonedEnviron {
mock := &MockZonedEnviron{ctrl: ctrl}
mock.recorder = &MockZonedEnvironMockRecorder{mock}
return mock
} | [
"func",
"NewMockZonedEnviron",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockZonedEnviron",
"{",
"mock",
":=",
"&",
"MockZonedEnviron",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockZonedEnvironMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockZonedEnviron creates a new mock instance | [
"NewMockZonedEnviron",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L33-L37 |
3,495 | juju/juju | provider/common/mocks/zoned_environ.go | AdoptResources | func (m *MockZonedEnviron) AdoptResources(arg0 context.ProviderCallContext, arg1 string, arg2 version.Number) error {
ret := m.ctrl.Call(m, "AdoptResources", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockZonedEnviron) AdoptResources(arg0 context.ProviderCallContext, arg1 string, arg2 version.Number) error {
ret := m.ctrl.Call(m, "AdoptResources", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockZonedEnviron",
")",
"AdoptResources",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
",",
"arg1",
"string",
",",
"arg2",
"version",
".",
"Number",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // AdoptResources mocks base method | [
"AdoptResources",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L45-L49 |
3,496 | juju/juju | provider/common/mocks/zoned_environ.go | AvailabilityZones | func (m *MockZonedEnviron) AvailabilityZones(arg0 context.ProviderCallContext) ([]common.AvailabilityZone, error) {
ret := m.ctrl.Call(m, "AvailabilityZones", arg0)
ret0, _ := ret[0].([]common.AvailabilityZone)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockZonedEnviron) AvailabilityZones(arg0 context.ProviderCallContext) ([]common.AvailabilityZone, error) {
ret := m.ctrl.Call(m, "AvailabilityZones", arg0)
ret0, _ := ret[0].([]common.AvailabilityZone)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockZonedEnviron",
")",
"AvailabilityZones",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"common",
".",
"AvailabilityZone",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"common",
".",
"AvailabilityZone",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // AvailabilityZones mocks base method | [
"AvailabilityZones",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L70-L75 |
3,497 | juju/juju | provider/common/mocks/zoned_environ.go | ConstraintsValidator | func (m *MockZonedEnviron) ConstraintsValidator(arg0 context.ProviderCallContext) (constraints.Validator, error) {
ret := m.ctrl.Call(m, "ConstraintsValidator", arg0)
ret0, _ := ret[0].(constraints.Validator)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockZonedEnviron) ConstraintsValidator(arg0 context.ProviderCallContext) (constraints.Validator, error) {
ret := m.ctrl.Call(m, "ConstraintsValidator", arg0)
ret0, _ := ret[0].(constraints.Validator)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockZonedEnviron",
")",
"ConstraintsValidator",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
")",
"(",
"constraints",
".",
"Validator",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"constraints",
".",
"Validator",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ConstraintsValidator mocks base method | [
"ConstraintsValidator",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L108-L113 |
3,498 | juju/juju | provider/common/mocks/zoned_environ.go | DeriveAvailabilityZones | func (m *MockZonedEnviron) DeriveAvailabilityZones(arg0 context.ProviderCallContext, arg1 environs.StartInstanceParams) ([]string, error) {
ret := m.ctrl.Call(m, "DeriveAvailabilityZones", arg0, arg1)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockZonedEnviron) DeriveAvailabilityZones(arg0 context.ProviderCallContext, arg1 environs.StartInstanceParams) ([]string, error) {
ret := m.ctrl.Call(m, "DeriveAvailabilityZones", arg0, arg1)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockZonedEnviron",
")",
"DeriveAvailabilityZones",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
",",
"arg1",
"environs",
".",
"StartInstanceParams",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // DeriveAvailabilityZones mocks base method | [
"DeriveAvailabilityZones",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L146-L151 |
3,499 | juju/juju | provider/common/mocks/zoned_environ.go | Destroy | func (m *MockZonedEnviron) Destroy(arg0 context.ProviderCallContext) error {
ret := m.ctrl.Call(m, "Destroy", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockZonedEnviron) Destroy(arg0 context.ProviderCallContext) error {
ret := m.ctrl.Call(m, "Destroy", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockZonedEnviron",
")",
"Destroy",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Destroy mocks base method | [
"Destroy",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L159-L163 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.