id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,800 | juju/juju | state/machine.go | SetMongoPassword | func (m *Machine) SetMongoPassword(password string) error {
if !m.IsManager() {
return errors.NotSupportedf("setting mongo password for non-controller machine %v", m)
}
return mongo.SetAdminMongoPassword(m.st.session, m.Tag().String(), password)
} | go | func (m *Machine) SetMongoPassword(password string) error {
if !m.IsManager() {
return errors.NotSupportedf("setting mongo password for non-controller machine %v", m)
}
return mongo.SetAdminMongoPassword(m.st.session, m.Tag().String(), password)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetMongoPassword",
"(",
"password",
"string",
")",
"error",
"{",
"if",
"!",
"m",
".",
"IsManager",
"(",
")",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"return",
"mongo",
".",
"SetAdminMongoPassword",
"(",
"m",
".",
"st",
".",
"session",
",",
"m",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
",",
"password",
")",
"\n",
"}"
] | // SetMongoPassword sets the password the agent responsible for the machine
// should use to communicate with the controllers. Previous passwords
// are invalidated. | [
"SetMongoPassword",
"sets",
"the",
"password",
"the",
"agent",
"responsible",
"for",
"the",
"machine",
"should",
"use",
"to",
"communicate",
"with",
"the",
"controllers",
".",
"Previous",
"passwords",
"are",
"invalidated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L528-L533 |
4,801 | juju/juju | state/machine.go | PasswordValid | func (m *Machine) PasswordValid(password string) bool {
agentHash := utils.AgentPasswordHash(password)
return agentHash == m.doc.PasswordHash
} | go | func (m *Machine) PasswordValid(password string) bool {
agentHash := utils.AgentPasswordHash(password)
return agentHash == m.doc.PasswordHash
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"PasswordValid",
"(",
"password",
"string",
")",
"bool",
"{",
"agentHash",
":=",
"utils",
".",
"AgentPasswordHash",
"(",
"password",
")",
"\n",
"return",
"agentHash",
"==",
"m",
".",
"doc",
".",
"PasswordHash",
"\n",
"}"
] | // PasswordValid returns whether the given password is valid
// for the given machine. | [
"PasswordValid",
"returns",
"whether",
"the",
"given",
"password",
"is",
"valid",
"for",
"the",
"given",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L565-L568 |
4,802 | juju/juju | state/machine.go | ForceDestroy | func (m *Machine) ForceDestroy(maxWait time.Duration) error {
ops, err := m.forceDestroyOps(maxWait)
if err != nil {
return errors.Trace(err)
}
if err := m.st.db().RunTransaction(ops); err != txn.ErrAborted {
return errors.Annotatef(err, "failed to run transaction: %s", pretty.Sprint(ops))
}
return nil
} | go | func (m *Machine) ForceDestroy(maxWait time.Duration) error {
ops, err := m.forceDestroyOps(maxWait)
if err != nil {
return errors.Trace(err)
}
if err := m.st.db().RunTransaction(ops); err != txn.ErrAborted {
return errors.Annotatef(err, "failed to run transaction: %s", pretty.Sprint(ops))
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"ForceDestroy",
"(",
"maxWait",
"time",
".",
"Duration",
")",
"error",
"{",
"ops",
",",
"err",
":=",
"m",
".",
"forceDestroyOps",
"(",
"maxWait",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
";",
"err",
"!=",
"txn",
".",
"ErrAborted",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"pretty",
".",
"Sprint",
"(",
"ops",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ForceDestroy queues the machine for complete removal, including the
// destruction of all units and containers on the machine. | [
"ForceDestroy",
"queues",
"the",
"machine",
"for",
"complete",
"removal",
"including",
"the",
"destruction",
"of",
"all",
"units",
"and",
"containers",
"on",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L581-L590 |
4,803 | juju/juju | state/machine.go | ParentId | func (m *Machine) ParentId() (string, bool) {
parentId := ParentId(m.Id())
return parentId, parentId != ""
} | go | func (m *Machine) ParentId() (string, bool) {
parentId := ParentId(m.Id())
return parentId, parentId != ""
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"ParentId",
"(",
")",
"(",
"string",
",",
"bool",
")",
"{",
"parentId",
":=",
"ParentId",
"(",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"return",
"parentId",
",",
"parentId",
"!=",
"\"",
"\"",
"\n",
"}"
] | // ParentId returns the Id of the host machine if this machine is a container. | [
"ParentId",
"returns",
"the",
"Id",
"of",
"the",
"host",
"machine",
"if",
"this",
"machine",
"is",
"a",
"container",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L683-L686 |
4,804 | juju/juju | state/machine.go | IsHasContainersError | func IsHasContainersError(err error) bool {
_, ok := errors.Cause(err).(*HasContainersError)
return ok
} | go | func IsHasContainersError(err error) bool {
_, ok := errors.Cause(err).(*HasContainersError)
return ok
} | [
"func",
"IsHasContainersError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"HasContainersError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsHasContainersError reports whether or not the error is a
// HasContainersError, indicating that an attempt to destroy
// a machine failed due to it having containers. | [
"IsHasContainersError",
"reports",
"whether",
"or",
"not",
"the",
"error",
"is",
"a",
"HasContainersError",
"indicating",
"that",
"an",
"attempt",
"to",
"destroy",
"a",
"machine",
"failed",
"due",
"to",
"it",
"having",
"containers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L706-L709 |
4,805 | juju/juju | state/machine.go | IsHasAttachmentsError | func IsHasAttachmentsError(err error) bool {
_, ok := errors.Cause(err).(*HasAttachmentsError)
return ok
} | go | func IsHasAttachmentsError(err error) bool {
_, ok := errors.Cause(err).(*HasAttachmentsError)
return ok
} | [
"func",
"IsHasAttachmentsError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"HasAttachmentsError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsHasAttachmentsError reports whether or not the error is a
// HasAttachmentsError, indicating that an attempt to destroy
// a machine failed due to it having storage attachments. | [
"IsHasAttachmentsError",
"reports",
"whether",
"or",
"not",
"the",
"error",
"is",
"a",
"HasAttachmentsError",
"indicating",
"that",
"an",
"attempt",
"to",
"destroy",
"a",
"machine",
"failed",
"due",
"to",
"it",
"having",
"storage",
"attachments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L728-L731 |
4,806 | juju/juju | state/machine.go | Remove | func (m *Machine) Remove() (err error) {
defer errors.DeferredAnnotatef(&err, "cannot remove machine %s", m.doc.Id)
logger.Tracef("removing machine %q", m.Id())
// Local variable so we can re-get the machine without disrupting
// the caller.
machine := m
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt != 0 {
machine, err = machine.st.Machine(machine.Id())
if errors.IsNotFound(err) {
// The machine's gone away, that's fine.
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
}
ops, err := machine.removeOps()
if err != nil {
return nil, errors.Trace(err)
}
return ops, nil
}
return m.st.db().Run(buildTxn)
} | go | func (m *Machine) Remove() (err error) {
defer errors.DeferredAnnotatef(&err, "cannot remove machine %s", m.doc.Id)
logger.Tracef("removing machine %q", m.Id())
// Local variable so we can re-get the machine without disrupting
// the caller.
machine := m
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt != 0 {
machine, err = machine.st.Machine(machine.Id())
if errors.IsNotFound(err) {
// The machine's gone away, that's fine.
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
}
ops, err := machine.removeOps()
if err != nil {
return nil, errors.Trace(err)
}
return ops, nil
}
return m.st.db().Run(buildTxn)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Remove",
"(",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"m",
".",
"doc",
".",
"Id",
")",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"// Local variable so we can re-get the machine without disrupting",
"// the caller.",
"machine",
":=",
"m",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
"!=",
"0",
"{",
"machine",
",",
"err",
"=",
"machine",
".",
"st",
".",
"Machine",
"(",
"machine",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"// The machine's gone away, that's fine.",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ops",
",",
"err",
":=",
"machine",
".",
"removeOps",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"return",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // Remove removes the machine from state. It will fail if the machine
// is not Dead. | [
"Remove",
"removes",
"the",
"machine",
"from",
"state",
".",
"It",
"will",
"fail",
"if",
"the",
"machine",
"is",
"not",
"Dead",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1067-L1091 |
4,807 | juju/juju | state/machine.go | Refresh | func (m *Machine) Refresh() error {
mdoc, err := m.st.getMachineDoc(m.Id())
if err != nil {
if errors.IsNotFound(err) {
return err
}
return errors.Annotatef(err, "cannot refresh machine %v", m)
}
m.doc = *mdoc
return nil
} | go | func (m *Machine) Refresh() error {
mdoc, err := m.st.getMachineDoc(m.Id())
if err != nil {
if errors.IsNotFound(err) {
return err
}
return errors.Annotatef(err, "cannot refresh machine %v", m)
}
m.doc = *mdoc
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Refresh",
"(",
")",
"error",
"{",
"mdoc",
",",
"err",
":=",
"m",
".",
"st",
".",
"getMachineDoc",
"(",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"m",
".",
"doc",
"=",
"*",
"mdoc",
"\n",
"return",
"nil",
"\n",
"}"
] | // Refresh refreshes the contents of the machine from the underlying
// state. It returns an error that satisfies errors.IsNotFound if the
// machine has been removed. | [
"Refresh",
"refreshes",
"the",
"contents",
"of",
"the",
"machine",
"from",
"the",
"underlying",
"state",
".",
"It",
"returns",
"an",
"error",
"that",
"satisfies",
"errors",
".",
"IsNotFound",
"if",
"the",
"machine",
"has",
"been",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1096-L1106 |
4,808 | juju/juju | state/machine.go | SetAgentPresence | func (m *Machine) SetAgentPresence() (*presence.Pinger, error) {
presenceCollection := m.st.getPresenceCollection()
recorder := m.st.getPingBatcher()
p := presence.NewPinger(presenceCollection, m.st.modelTag, m.globalKey(),
func() presence.PingRecorder { return m.st.getPingBatcher() })
err := p.Start()
if err != nil {
return nil, err
}
// Make sure this Agent status is written to the database before returning.
recorder.Sync()
// We preform a manual sync here so that the
// presence pinger has the most up-to-date information when it
// starts. This ensures that commands run immediately after bootstrap
// like status or enable-ha will have an accurate values
// for agent-state.
//
// TODO: Does not work for multiple controllers. Trigger a sync across all controllers.
if m.IsManager() {
m.st.workers.presenceWatcher().Sync()
}
return p, nil
} | go | func (m *Machine) SetAgentPresence() (*presence.Pinger, error) {
presenceCollection := m.st.getPresenceCollection()
recorder := m.st.getPingBatcher()
p := presence.NewPinger(presenceCollection, m.st.modelTag, m.globalKey(),
func() presence.PingRecorder { return m.st.getPingBatcher() })
err := p.Start()
if err != nil {
return nil, err
}
// Make sure this Agent status is written to the database before returning.
recorder.Sync()
// We preform a manual sync here so that the
// presence pinger has the most up-to-date information when it
// starts. This ensures that commands run immediately after bootstrap
// like status or enable-ha will have an accurate values
// for agent-state.
//
// TODO: Does not work for multiple controllers. Trigger a sync across all controllers.
if m.IsManager() {
m.st.workers.presenceWatcher().Sync()
}
return p, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetAgentPresence",
"(",
")",
"(",
"*",
"presence",
".",
"Pinger",
",",
"error",
")",
"{",
"presenceCollection",
":=",
"m",
".",
"st",
".",
"getPresenceCollection",
"(",
")",
"\n",
"recorder",
":=",
"m",
".",
"st",
".",
"getPingBatcher",
"(",
")",
"\n",
"p",
":=",
"presence",
".",
"NewPinger",
"(",
"presenceCollection",
",",
"m",
".",
"st",
".",
"modelTag",
",",
"m",
".",
"globalKey",
"(",
")",
",",
"func",
"(",
")",
"presence",
".",
"PingRecorder",
"{",
"return",
"m",
".",
"st",
".",
"getPingBatcher",
"(",
")",
"}",
")",
"\n",
"err",
":=",
"p",
".",
"Start",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Make sure this Agent status is written to the database before returning.",
"recorder",
".",
"Sync",
"(",
")",
"\n",
"// We preform a manual sync here so that the",
"// presence pinger has the most up-to-date information when it",
"// starts. This ensures that commands run immediately after bootstrap",
"// like status or enable-ha will have an accurate values",
"// for agent-state.",
"//",
"// TODO: Does not work for multiple controllers. Trigger a sync across all controllers.",
"if",
"m",
".",
"IsManager",
"(",
")",
"{",
"m",
".",
"st",
".",
"workers",
".",
"presenceWatcher",
"(",
")",
".",
"Sync",
"(",
")",
"\n",
"}",
"\n",
"return",
"p",
",",
"nil",
"\n",
"}"
] | // SetAgentPresence signals that the agent for machine m is alive.
// It returns the started pinger. | [
"SetAgentPresence",
"signals",
"that",
"the",
"agent",
"for",
"machine",
"m",
"is",
"alive",
".",
"It",
"returns",
"the",
"started",
"pinger",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1144-L1166 |
4,809 | juju/juju | state/machine.go | InstanceId | func (m *Machine) InstanceId() (instance.Id, error) {
instId, _, err := m.InstanceNames()
return instId, err
} | go | func (m *Machine) InstanceId() (instance.Id, error) {
instId, _, err := m.InstanceNames()
return instId, err
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"InstanceId",
"(",
")",
"(",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"instId",
",",
"_",
",",
"err",
":=",
"m",
".",
"InstanceNames",
"(",
")",
"\n",
"return",
"instId",
",",
"err",
"\n",
"}"
] | // InstanceId returns the provider specific instance id for this
// machine, or a NotProvisionedError, if not set. | [
"InstanceId",
"returns",
"the",
"provider",
"specific",
"instance",
"id",
"for",
"this",
"machine",
"or",
"a",
"NotProvisionedError",
"if",
"not",
"set",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1170-L1173 |
4,810 | juju/juju | state/machine.go | InstanceNames | func (m *Machine) InstanceNames() (instance.Id, string, error) {
instData, err := getInstanceData(m.st, m.Id())
if errors.IsNotFound(err) {
err = errors.NotProvisionedf("machine %v", m.Id())
}
if err != nil {
return "", "", err
}
return instData.InstanceId, instData.DisplayName, nil
} | go | func (m *Machine) InstanceNames() (instance.Id, string, error) {
instData, err := getInstanceData(m.st, m.Id())
if errors.IsNotFound(err) {
err = errors.NotProvisionedf("machine %v", m.Id())
}
if err != nil {
return "", "", err
}
return instData.InstanceId, instData.DisplayName, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"InstanceNames",
"(",
")",
"(",
"instance",
".",
"Id",
",",
"string",
",",
"error",
")",
"{",
"instData",
",",
"err",
":=",
"getInstanceData",
"(",
"m",
".",
"st",
",",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"err",
"=",
"errors",
".",
"NotProvisionedf",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"instData",
".",
"InstanceId",
",",
"instData",
".",
"DisplayName",
",",
"nil",
"\n",
"}"
] | // InstanceNames returns both the provider's instance id and a user-friendly
// display name. The display name is intended used for human input and
// is ignored internally. | [
"InstanceNames",
"returns",
"both",
"the",
"provider",
"s",
"instance",
"id",
"and",
"a",
"user",
"-",
"friendly",
"display",
"name",
".",
"The",
"display",
"name",
"is",
"intended",
"used",
"for",
"human",
"input",
"and",
"is",
"ignored",
"internally",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1178-L1187 |
4,811 | juju/juju | state/machine.go | InstanceStatus | func (m *Machine) InstanceStatus() (status.StatusInfo, error) {
machineStatus, err := getStatus(m.st.db(), m.globalInstanceKey(), "instance")
if err != nil {
logger.Warningf("error when retrieving instance status for machine: %s, %v", m.Id(), err)
return status.StatusInfo{}, err
}
return machineStatus, nil
} | go | func (m *Machine) InstanceStatus() (status.StatusInfo, error) {
machineStatus, err := getStatus(m.st.db(), m.globalInstanceKey(), "instance")
if err != nil {
logger.Warningf("error when retrieving instance status for machine: %s, %v", m.Id(), err)
return status.StatusInfo{}, err
}
return machineStatus, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"InstanceStatus",
"(",
")",
"(",
"status",
".",
"StatusInfo",
",",
"error",
")",
"{",
"machineStatus",
",",
"err",
":=",
"getStatus",
"(",
"m",
".",
"st",
".",
"db",
"(",
")",
",",
"m",
".",
"globalInstanceKey",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"err",
")",
"\n",
"return",
"status",
".",
"StatusInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"machineStatus",
",",
"nil",
"\n",
"}"
] | // InstanceStatus returns the provider specific instance status for this machine,
// or a NotProvisionedError if instance is not yet provisioned. | [
"InstanceStatus",
"returns",
"the",
"provider",
"specific",
"instance",
"status",
"for",
"this",
"machine",
"or",
"a",
"NotProvisionedError",
"if",
"instance",
"is",
"not",
"yet",
"provisioned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1191-L1198 |
4,812 | juju/juju | state/machine.go | SetInstanceStatus | func (m *Machine) SetInstanceStatus(sInfo status.StatusInfo) (err error) {
return setStatus(m.st.db(), setStatusParams{
badge: "instance",
globalKey: m.globalInstanceKey(),
status: sInfo.Status,
message: sInfo.Message,
rawData: sInfo.Data,
updated: timeOrNow(sInfo.Since, m.st.clock()),
})
} | go | func (m *Machine) SetInstanceStatus(sInfo status.StatusInfo) (err error) {
return setStatus(m.st.db(), setStatusParams{
badge: "instance",
globalKey: m.globalInstanceKey(),
status: sInfo.Status,
message: sInfo.Message,
rawData: sInfo.Data,
updated: timeOrNow(sInfo.Since, m.st.clock()),
})
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetInstanceStatus",
"(",
"sInfo",
"status",
".",
"StatusInfo",
")",
"(",
"err",
"error",
")",
"{",
"return",
"setStatus",
"(",
"m",
".",
"st",
".",
"db",
"(",
")",
",",
"setStatusParams",
"{",
"badge",
":",
"\"",
"\"",
",",
"globalKey",
":",
"m",
".",
"globalInstanceKey",
"(",
")",
",",
"status",
":",
"sInfo",
".",
"Status",
",",
"message",
":",
"sInfo",
".",
"Message",
",",
"rawData",
":",
"sInfo",
".",
"Data",
",",
"updated",
":",
"timeOrNow",
"(",
"sInfo",
".",
"Since",
",",
"m",
".",
"st",
".",
"clock",
"(",
")",
")",
",",
"}",
")",
"\n",
"}"
] | // SetInstanceStatus sets the provider specific instance status for a machine. | [
"SetInstanceStatus",
"sets",
"the",
"provider",
"specific",
"instance",
"status",
"for",
"a",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1201-L1210 |
4,813 | juju/juju | state/machine.go | ModificationStatus | func (m *Machine) ModificationStatus() (status.StatusInfo, error) {
machineStatus, err := getStatus(m.st.db(), m.globalModificationKey(), "modification")
if err != nil {
logger.Warningf("error when retrieving instance status for machine: %s, %v", m.Id(), err)
return status.StatusInfo{}, err
}
return machineStatus, nil
} | go | func (m *Machine) ModificationStatus() (status.StatusInfo, error) {
machineStatus, err := getStatus(m.st.db(), m.globalModificationKey(), "modification")
if err != nil {
logger.Warningf("error when retrieving instance status for machine: %s, %v", m.Id(), err)
return status.StatusInfo{}, err
}
return machineStatus, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"ModificationStatus",
"(",
")",
"(",
"status",
".",
"StatusInfo",
",",
"error",
")",
"{",
"machineStatus",
",",
"err",
":=",
"getStatus",
"(",
"m",
".",
"st",
".",
"db",
"(",
")",
",",
"m",
".",
"globalModificationKey",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"err",
")",
"\n",
"return",
"status",
".",
"StatusInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"machineStatus",
",",
"nil",
"\n",
"}"
] | // ModificationStatus returns the provider specific modification status for
// this machine or NotProvisionedError if instance is not yet provisioned. | [
"ModificationStatus",
"returns",
"the",
"provider",
"specific",
"modification",
"status",
"for",
"this",
"machine",
"or",
"NotProvisionedError",
"if",
"instance",
"is",
"not",
"yet",
"provisioned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1228-L1235 |
4,814 | juju/juju | state/machine.go | AvailabilityZone | func (m *Machine) AvailabilityZone() (string, error) {
instData, err := getInstanceData(m.st, m.Id())
if errors.IsNotFound(err) {
return "", errors.Trace(errors.NotProvisionedf("machine %v", m.Id()))
}
if err != nil {
return "", errors.Trace(err)
}
var zone string
if instData.AvailZone != nil {
zone = *instData.AvailZone
}
return zone, nil
} | go | func (m *Machine) AvailabilityZone() (string, error) {
instData, err := getInstanceData(m.st, m.Id())
if errors.IsNotFound(err) {
return "", errors.Trace(errors.NotProvisionedf("machine %v", m.Id()))
}
if err != nil {
return "", errors.Trace(err)
}
var zone string
if instData.AvailZone != nil {
zone = *instData.AvailZone
}
return zone, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"AvailabilityZone",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"instData",
",",
"err",
":=",
"getInstanceData",
"(",
"m",
".",
"st",
",",
"m",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"errors",
".",
"NotProvisionedf",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"zone",
"string",
"\n",
"if",
"instData",
".",
"AvailZone",
"!=",
"nil",
"{",
"zone",
"=",
"*",
"instData",
".",
"AvailZone",
"\n",
"}",
"\n",
"return",
"zone",
",",
"nil",
"\n",
"}"
] | // AvailabilityZone returns the provier-specific instance availability
// zone in which the machine was provisioned. | [
"AvailabilityZone",
"returns",
"the",
"provier",
"-",
"specific",
"instance",
"availability",
"zone",
"in",
"which",
"the",
"machine",
"was",
"provisioned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1253-L1266 |
4,815 | juju/juju | state/machine.go | ApplicationNames | func (m *Machine) ApplicationNames() ([]string, error) {
units, err := m.Units()
if err != nil {
return nil, errors.Trace(err)
}
apps := set.NewStrings()
for _, unit := range units {
apps.Add(unit.ApplicationName())
}
return apps.SortedValues(), nil
} | go | func (m *Machine) ApplicationNames() ([]string, error) {
units, err := m.Units()
if err != nil {
return nil, errors.Trace(err)
}
apps := set.NewStrings()
for _, unit := range units {
apps.Add(unit.ApplicationName())
}
return apps.SortedValues(), nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"ApplicationNames",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"units",
",",
"err",
":=",
"m",
".",
"Units",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"apps",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"units",
"{",
"apps",
".",
"Add",
"(",
"unit",
".",
"ApplicationName",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"apps",
".",
"SortedValues",
"(",
")",
",",
"nil",
"\n",
"}"
] | // ApplicationNames returns the names of applications
// represented by units running on the machine. | [
"ApplicationNames",
"returns",
"the",
"names",
"of",
"applications",
"represented",
"by",
"units",
"running",
"on",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1270-L1280 |
4,816 | juju/juju | state/machine.go | Units | func (m *Machine) Units() (units []*Unit, err error) {
defer errors.DeferredAnnotatef(&err, "cannot get units assigned to machine %v", m)
unitsCollection, closer := m.st.db().GetCollection(unitsC)
defer closer()
pudocs := []unitDoc{}
err = unitsCollection.Find(bson.D{{"machineid", m.doc.Id}}).All(&pudocs)
if err != nil {
return nil, err
}
model, err := m.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
for _, pudoc := range pudocs {
units = append(units, newUnit(m.st, model.Type(), &pudoc))
docs := []unitDoc{}
err = unitsCollection.Find(bson.D{{"principal", pudoc.Name}}).All(&docs)
if err != nil {
return nil, err
}
for _, doc := range docs {
units = append(units, newUnit(m.st, model.Type(), &doc))
}
}
return units, nil
} | go | func (m *Machine) Units() (units []*Unit, err error) {
defer errors.DeferredAnnotatef(&err, "cannot get units assigned to machine %v", m)
unitsCollection, closer := m.st.db().GetCollection(unitsC)
defer closer()
pudocs := []unitDoc{}
err = unitsCollection.Find(bson.D{{"machineid", m.doc.Id}}).All(&pudocs)
if err != nil {
return nil, err
}
model, err := m.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
for _, pudoc := range pudocs {
units = append(units, newUnit(m.st, model.Type(), &pudoc))
docs := []unitDoc{}
err = unitsCollection.Find(bson.D{{"principal", pudoc.Name}}).All(&docs)
if err != nil {
return nil, err
}
for _, doc := range docs {
units = append(units, newUnit(m.st, model.Type(), &doc))
}
}
return units, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Units",
"(",
")",
"(",
"units",
"[",
"]",
"*",
"Unit",
",",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"m",
")",
"\n",
"unitsCollection",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"unitsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"pudocs",
":=",
"[",
"]",
"unitDoc",
"{",
"}",
"\n",
"err",
"=",
"unitsCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"m",
".",
"doc",
".",
"Id",
"}",
"}",
")",
".",
"All",
"(",
"&",
"pudocs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"model",
",",
"err",
":=",
"m",
".",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"pudoc",
":=",
"range",
"pudocs",
"{",
"units",
"=",
"append",
"(",
"units",
",",
"newUnit",
"(",
"m",
".",
"st",
",",
"model",
".",
"Type",
"(",
")",
",",
"&",
"pudoc",
")",
")",
"\n",
"docs",
":=",
"[",
"]",
"unitDoc",
"{",
"}",
"\n",
"err",
"=",
"unitsCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"pudoc",
".",
"Name",
"}",
"}",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"doc",
":=",
"range",
"docs",
"{",
"units",
"=",
"append",
"(",
"units",
",",
"newUnit",
"(",
"m",
".",
"st",
",",
"model",
".",
"Type",
"(",
")",
",",
"&",
"doc",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"units",
",",
"nil",
"\n",
"}"
] | // Units returns all the units that have been assigned to the machine. | [
"Units",
"returns",
"all",
"the",
"units",
"that",
"have",
"been",
"assigned",
"to",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1283-L1309 |
4,817 | juju/juju | state/machine.go | DesiredSpaces | func (m *Machine) DesiredSpaces() (set.Strings, error) {
spaces := set.NewStrings()
units, err := m.Units()
if err != nil {
return nil, errors.Trace(err)
}
constraints, err := m.Constraints()
if err != nil {
return nil, errors.Trace(err)
}
// We ignore negative spaces as it doesn't change what spaces we do want.
positiveSpaces, _ := convertSpacesFromConstraints(constraints.Spaces)
for _, space := range positiveSpaces {
spaces.Add(space)
}
bindings := set.NewStrings()
for _, unit := range units {
app, err := unit.Application()
if err != nil {
return nil, errors.Trace(err)
}
endpointBindings, err := app.EndpointBindings()
for _, space := range endpointBindings {
if space != "" {
bindings.Add(space)
}
}
}
logger.Tracef("machine %q found constraints %s and bindings %s",
m.Id(), network.QuoteSpaceSet(spaces), network.QuoteSpaceSet(bindings))
return spaces.Union(bindings), nil
} | go | func (m *Machine) DesiredSpaces() (set.Strings, error) {
spaces := set.NewStrings()
units, err := m.Units()
if err != nil {
return nil, errors.Trace(err)
}
constraints, err := m.Constraints()
if err != nil {
return nil, errors.Trace(err)
}
// We ignore negative spaces as it doesn't change what spaces we do want.
positiveSpaces, _ := convertSpacesFromConstraints(constraints.Spaces)
for _, space := range positiveSpaces {
spaces.Add(space)
}
bindings := set.NewStrings()
for _, unit := range units {
app, err := unit.Application()
if err != nil {
return nil, errors.Trace(err)
}
endpointBindings, err := app.EndpointBindings()
for _, space := range endpointBindings {
if space != "" {
bindings.Add(space)
}
}
}
logger.Tracef("machine %q found constraints %s and bindings %s",
m.Id(), network.QuoteSpaceSet(spaces), network.QuoteSpaceSet(bindings))
return spaces.Union(bindings), nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"DesiredSpaces",
"(",
")",
"(",
"set",
".",
"Strings",
",",
"error",
")",
"{",
"spaces",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"units",
",",
"err",
":=",
"m",
".",
"Units",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"constraints",
",",
"err",
":=",
"m",
".",
"Constraints",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// We ignore negative spaces as it doesn't change what spaces we do want.",
"positiveSpaces",
",",
"_",
":=",
"convertSpacesFromConstraints",
"(",
"constraints",
".",
"Spaces",
")",
"\n",
"for",
"_",
",",
"space",
":=",
"range",
"positiveSpaces",
"{",
"spaces",
".",
"Add",
"(",
"space",
")",
"\n",
"}",
"\n",
"bindings",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"units",
"{",
"app",
",",
"err",
":=",
"unit",
".",
"Application",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"endpointBindings",
",",
"err",
":=",
"app",
".",
"EndpointBindings",
"(",
")",
"\n",
"for",
"_",
",",
"space",
":=",
"range",
"endpointBindings",
"{",
"if",
"space",
"!=",
"\"",
"\"",
"{",
"bindings",
".",
"Add",
"(",
"space",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"network",
".",
"QuoteSpaceSet",
"(",
"spaces",
")",
",",
"network",
".",
"QuoteSpaceSet",
"(",
"bindings",
")",
")",
"\n",
"return",
"spaces",
".",
"Union",
"(",
"bindings",
")",
",",
"nil",
"\n",
"}"
] | // DesiredSpaces returns the name of all spaces that this machine needs
// access to. This is the combined value of all of the direct constraints
// for the machine, as well as the spaces listed for all bindings of units
// being deployed to that machine. | [
"DesiredSpaces",
"returns",
"the",
"name",
"of",
"all",
"spaces",
"that",
"this",
"machine",
"needs",
"access",
"to",
".",
"This",
"is",
"the",
"combined",
"value",
"of",
"all",
"of",
"the",
"direct",
"constraints",
"for",
"the",
"machine",
"as",
"well",
"as",
"the",
"spaces",
"listed",
"for",
"all",
"bindings",
"of",
"units",
"being",
"deployed",
"to",
"that",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1348-L1379 |
4,818 | juju/juju | state/machine.go | SetInstanceInfo | func (m *Machine) SetInstanceInfo(
id instance.Id, displayName string, nonce string, characteristics *instance.HardwareCharacteristics,
devicesArgs []LinkLayerDeviceArgs, devicesAddrs []LinkLayerDeviceAddress,
volumes map[names.VolumeTag]VolumeInfo,
volumeAttachments map[names.VolumeTag]VolumeAttachmentInfo,
charmProfiles []string,
) error {
logger.Tracef(
"setting instance info: machine %v, deviceAddrs: %#v, devicesArgs: %#v",
m.Id(), devicesAddrs, devicesArgs)
if err := m.SetParentLinkLayerDevicesBeforeTheirChildren(devicesArgs); err != nil {
return errors.Trace(err)
}
if err := m.SetDevicesAddressesIdempotently(devicesAddrs); err != nil {
return errors.Trace(err)
}
sb, err := NewStorageBackend(m.st)
if err != nil {
return errors.Trace(err)
}
// Record volumes and volume attachments, and set the initial
// status: attached or attaching.
if err := setProvisionedVolumeInfo(sb, volumes); err != nil {
return errors.Trace(err)
}
if err := setMachineVolumeAttachmentInfo(sb, m.Id(), volumeAttachments); err != nil {
return errors.Trace(err)
}
volumeStatus := make(map[names.VolumeTag]status.Status)
for tag := range volumes {
volumeStatus[tag] = status.Attaching
}
for tag := range volumeAttachments {
volumeStatus[tag] = status.Attached
}
for tag, volStatus := range volumeStatus {
vol, err := sb.Volume(tag)
if err != nil {
return errors.Trace(err)
}
if err := vol.SetStatus(status.StatusInfo{
Status: volStatus,
}); err != nil {
return errors.Annotatef(
err, "setting status of %s", names.ReadableString(tag),
)
}
}
if err := m.SetProvisioned(id, displayName, nonce, characteristics); err != nil {
return errors.Trace(err)
}
return m.SetCharmProfiles(charmProfiles)
} | go | func (m *Machine) SetInstanceInfo(
id instance.Id, displayName string, nonce string, characteristics *instance.HardwareCharacteristics,
devicesArgs []LinkLayerDeviceArgs, devicesAddrs []LinkLayerDeviceAddress,
volumes map[names.VolumeTag]VolumeInfo,
volumeAttachments map[names.VolumeTag]VolumeAttachmentInfo,
charmProfiles []string,
) error {
logger.Tracef(
"setting instance info: machine %v, deviceAddrs: %#v, devicesArgs: %#v",
m.Id(), devicesAddrs, devicesArgs)
if err := m.SetParentLinkLayerDevicesBeforeTheirChildren(devicesArgs); err != nil {
return errors.Trace(err)
}
if err := m.SetDevicesAddressesIdempotently(devicesAddrs); err != nil {
return errors.Trace(err)
}
sb, err := NewStorageBackend(m.st)
if err != nil {
return errors.Trace(err)
}
// Record volumes and volume attachments, and set the initial
// status: attached or attaching.
if err := setProvisionedVolumeInfo(sb, volumes); err != nil {
return errors.Trace(err)
}
if err := setMachineVolumeAttachmentInfo(sb, m.Id(), volumeAttachments); err != nil {
return errors.Trace(err)
}
volumeStatus := make(map[names.VolumeTag]status.Status)
for tag := range volumes {
volumeStatus[tag] = status.Attaching
}
for tag := range volumeAttachments {
volumeStatus[tag] = status.Attached
}
for tag, volStatus := range volumeStatus {
vol, err := sb.Volume(tag)
if err != nil {
return errors.Trace(err)
}
if err := vol.SetStatus(status.StatusInfo{
Status: volStatus,
}); err != nil {
return errors.Annotatef(
err, "setting status of %s", names.ReadableString(tag),
)
}
}
if err := m.SetProvisioned(id, displayName, nonce, characteristics); err != nil {
return errors.Trace(err)
}
return m.SetCharmProfiles(charmProfiles)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetInstanceInfo",
"(",
"id",
"instance",
".",
"Id",
",",
"displayName",
"string",
",",
"nonce",
"string",
",",
"characteristics",
"*",
"instance",
".",
"HardwareCharacteristics",
",",
"devicesArgs",
"[",
"]",
"LinkLayerDeviceArgs",
",",
"devicesAddrs",
"[",
"]",
"LinkLayerDeviceAddress",
",",
"volumes",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"VolumeInfo",
",",
"volumeAttachments",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"VolumeAttachmentInfo",
",",
"charmProfiles",
"[",
"]",
"string",
",",
")",
"error",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"m",
".",
"Id",
"(",
")",
",",
"devicesAddrs",
",",
"devicesArgs",
")",
"\n\n",
"if",
"err",
":=",
"m",
".",
"SetParentLinkLayerDevicesBeforeTheirChildren",
"(",
"devicesArgs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"SetDevicesAddressesIdempotently",
"(",
"devicesAddrs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"sb",
",",
"err",
":=",
"NewStorageBackend",
"(",
"m",
".",
"st",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Record volumes and volume attachments, and set the initial",
"// status: attached or attaching.",
"if",
"err",
":=",
"setProvisionedVolumeInfo",
"(",
"sb",
",",
"volumes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"setMachineVolumeAttachmentInfo",
"(",
"sb",
",",
"m",
".",
"Id",
"(",
")",
",",
"volumeAttachments",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"volumeStatus",
":=",
"make",
"(",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"status",
".",
"Status",
")",
"\n",
"for",
"tag",
":=",
"range",
"volumes",
"{",
"volumeStatus",
"[",
"tag",
"]",
"=",
"status",
".",
"Attaching",
"\n",
"}",
"\n",
"for",
"tag",
":=",
"range",
"volumeAttachments",
"{",
"volumeStatus",
"[",
"tag",
"]",
"=",
"status",
".",
"Attached",
"\n",
"}",
"\n",
"for",
"tag",
",",
"volStatus",
":=",
"range",
"volumeStatus",
"{",
"vol",
",",
"err",
":=",
"sb",
".",
"Volume",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"vol",
".",
"SetStatus",
"(",
"status",
".",
"StatusInfo",
"{",
"Status",
":",
"volStatus",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"names",
".",
"ReadableString",
"(",
"tag",
")",
",",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"SetProvisioned",
"(",
"id",
",",
"displayName",
",",
"nonce",
",",
"characteristics",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"SetCharmProfiles",
"(",
"charmProfiles",
")",
"\n",
"}"
] | // SetInstanceInfo is used to provision a machine and in one step sets it's
// instance id, nonce, hardware characteristics, add link-layer devices and set
// their addresses as needed. After, set charm profiles if needed. | [
"SetInstanceInfo",
"is",
"used",
"to",
"provision",
"a",
"machine",
"and",
"in",
"one",
"step",
"sets",
"it",
"s",
"instance",
"id",
"nonce",
"hardware",
"characteristics",
"add",
"link",
"-",
"layer",
"devices",
"and",
"set",
"their",
"addresses",
"as",
"needed",
".",
"After",
"set",
"charm",
"profiles",
"if",
"needed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1464-L1520 |
4,819 | juju/juju | state/machine.go | Addresses | func (m *Machine) Addresses() (addresses []network.Address) {
return network.MergedAddresses(networkAddresses(m.doc.MachineAddresses), networkAddresses(m.doc.Addresses))
} | go | func (m *Machine) Addresses() (addresses []network.Address) {
return network.MergedAddresses(networkAddresses(m.doc.MachineAddresses), networkAddresses(m.doc.Addresses))
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Addresses",
"(",
")",
"(",
"addresses",
"[",
"]",
"network",
".",
"Address",
")",
"{",
"return",
"network",
".",
"MergedAddresses",
"(",
"networkAddresses",
"(",
"m",
".",
"doc",
".",
"MachineAddresses",
")",
",",
"networkAddresses",
"(",
"m",
".",
"doc",
".",
"Addresses",
")",
")",
"\n",
"}"
] | // Addresses returns any hostnames and ips associated with a machine,
// determined both by the machine itself, and by asking the provider.
//
// The addresses returned by the provider shadow any of the addresses
// that the machine reported with the same address value.
// Provider-reported addresses always come before machine-reported
// addresses. Duplicates are removed. | [
"Addresses",
"returns",
"any",
"hostnames",
"and",
"ips",
"associated",
"with",
"a",
"machine",
"determined",
"both",
"by",
"the",
"machine",
"itself",
"and",
"by",
"asking",
"the",
"provider",
".",
"The",
"addresses",
"returned",
"by",
"the",
"provider",
"shadow",
"any",
"of",
"the",
"addresses",
"that",
"the",
"machine",
"reported",
"with",
"the",
"same",
"address",
"value",
".",
"Provider",
"-",
"reported",
"addresses",
"always",
"come",
"before",
"machine",
"-",
"reported",
"addresses",
".",
"Duplicates",
"are",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1529-L1531 |
4,820 | juju/juju | state/machine.go | maybeGetNewAddress | func maybeGetNewAddress(
addr address,
providerAddresses,
machineAddresses []address,
getAddr func([]address) network.Address,
checkScope func(address) bool,
) (address, bool) {
// For picking the best address, try provider addresses first.
var newAddr address
netAddr := getAddr(providerAddresses)
if netAddr.Value == "" {
netAddr = getAddr(machineAddresses)
newAddr = fromNetworkAddress(netAddr, OriginMachine)
} else {
newAddr = fromNetworkAddress(netAddr, OriginProvider)
}
// The order of these checks is important. If the stored address is
// empty we *always* want to check for a new address so we do that
// first. If the stored address is unavailable we also *must* check for
// a new address so we do that next. If the original is a machine
// address and a provider address is available we want to switch to
// that. Finally we check to see if a better match on scope from the
// same origin is available.
if addr.Value == "" {
return newAddr, newAddr.Value != ""
}
if !containsAddress(providerAddresses, addr) && !containsAddress(machineAddresses, addr) {
return newAddr, true
}
if Origin(addr.Origin) != OriginProvider && Origin(newAddr.Origin) == OriginProvider {
return newAddr, true
}
if !checkScope(addr) {
// If addr.Origin is machine and newAddr.Origin is provider we will
// have already caught that, and for the inverse we don't want to
// replace the address.
if addr.Origin == newAddr.Origin {
return newAddr, checkScope(newAddr)
}
}
return addr, false
} | go | func maybeGetNewAddress(
addr address,
providerAddresses,
machineAddresses []address,
getAddr func([]address) network.Address,
checkScope func(address) bool,
) (address, bool) {
// For picking the best address, try provider addresses first.
var newAddr address
netAddr := getAddr(providerAddresses)
if netAddr.Value == "" {
netAddr = getAddr(machineAddresses)
newAddr = fromNetworkAddress(netAddr, OriginMachine)
} else {
newAddr = fromNetworkAddress(netAddr, OriginProvider)
}
// The order of these checks is important. If the stored address is
// empty we *always* want to check for a new address so we do that
// first. If the stored address is unavailable we also *must* check for
// a new address so we do that next. If the original is a machine
// address and a provider address is available we want to switch to
// that. Finally we check to see if a better match on scope from the
// same origin is available.
if addr.Value == "" {
return newAddr, newAddr.Value != ""
}
if !containsAddress(providerAddresses, addr) && !containsAddress(machineAddresses, addr) {
return newAddr, true
}
if Origin(addr.Origin) != OriginProvider && Origin(newAddr.Origin) == OriginProvider {
return newAddr, true
}
if !checkScope(addr) {
// If addr.Origin is machine and newAddr.Origin is provider we will
// have already caught that, and for the inverse we don't want to
// replace the address.
if addr.Origin == newAddr.Origin {
return newAddr, checkScope(newAddr)
}
}
return addr, false
} | [
"func",
"maybeGetNewAddress",
"(",
"addr",
"address",
",",
"providerAddresses",
",",
"machineAddresses",
"[",
"]",
"address",
",",
"getAddr",
"func",
"(",
"[",
"]",
"address",
")",
"network",
".",
"Address",
",",
"checkScope",
"func",
"(",
"address",
")",
"bool",
",",
")",
"(",
"address",
",",
"bool",
")",
"{",
"// For picking the best address, try provider addresses first.",
"var",
"newAddr",
"address",
"\n",
"netAddr",
":=",
"getAddr",
"(",
"providerAddresses",
")",
"\n",
"if",
"netAddr",
".",
"Value",
"==",
"\"",
"\"",
"{",
"netAddr",
"=",
"getAddr",
"(",
"machineAddresses",
")",
"\n",
"newAddr",
"=",
"fromNetworkAddress",
"(",
"netAddr",
",",
"OriginMachine",
")",
"\n",
"}",
"else",
"{",
"newAddr",
"=",
"fromNetworkAddress",
"(",
"netAddr",
",",
"OriginProvider",
")",
"\n",
"}",
"\n",
"// The order of these checks is important. If the stored address is",
"// empty we *always* want to check for a new address so we do that",
"// first. If the stored address is unavailable we also *must* check for",
"// a new address so we do that next. If the original is a machine",
"// address and a provider address is available we want to switch to",
"// that. Finally we check to see if a better match on scope from the",
"// same origin is available.",
"if",
"addr",
".",
"Value",
"==",
"\"",
"\"",
"{",
"return",
"newAddr",
",",
"newAddr",
".",
"Value",
"!=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"!",
"containsAddress",
"(",
"providerAddresses",
",",
"addr",
")",
"&&",
"!",
"containsAddress",
"(",
"machineAddresses",
",",
"addr",
")",
"{",
"return",
"newAddr",
",",
"true",
"\n",
"}",
"\n",
"if",
"Origin",
"(",
"addr",
".",
"Origin",
")",
"!=",
"OriginProvider",
"&&",
"Origin",
"(",
"newAddr",
".",
"Origin",
")",
"==",
"OriginProvider",
"{",
"return",
"newAddr",
",",
"true",
"\n",
"}",
"\n",
"if",
"!",
"checkScope",
"(",
"addr",
")",
"{",
"// If addr.Origin is machine and newAddr.Origin is provider we will",
"// have already caught that, and for the inverse we don't want to",
"// replace the address.",
"if",
"addr",
".",
"Origin",
"==",
"newAddr",
".",
"Origin",
"{",
"return",
"newAddr",
",",
"checkScope",
"(",
"newAddr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"addr",
",",
"false",
"\n",
"}"
] | // maybeGetNewAddress determines if the current address is the most appropriate
// match, and if not it selects the best from the slice of all available
// addresses. It returns the new address and a bool indicating if a different
// one was picked. | [
"maybeGetNewAddress",
"determines",
"if",
"the",
"current",
"address",
"is",
"the",
"most",
"appropriate",
"match",
"and",
"if",
"not",
"it",
"selects",
"the",
"best",
"from",
"the",
"slice",
"of",
"all",
"available",
"addresses",
".",
"It",
"returns",
"the",
"new",
"address",
"and",
"a",
"bool",
"indicating",
"if",
"a",
"different",
"one",
"was",
"picked",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1557-L1598 |
4,821 | juju/juju | state/machine.go | SetProviderAddresses | func (m *Machine) SetProviderAddresses(addresses ...network.Address) error {
err := m.setAddresses(nil, &addresses)
return errors.Annotatef(err, "cannot set addresses of machine %v", m)
} | go | func (m *Machine) SetProviderAddresses(addresses ...network.Address) error {
err := m.setAddresses(nil, &addresses)
return errors.Annotatef(err, "cannot set addresses of machine %v", m)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetProviderAddresses",
"(",
"addresses",
"...",
"network",
".",
"Address",
")",
"error",
"{",
"err",
":=",
"m",
".",
"setAddresses",
"(",
"nil",
",",
"&",
"addresses",
")",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"m",
")",
"\n",
"}"
] | // SetProviderAddresses records any addresses related to the machine, sourced
// by asking the provider. | [
"SetProviderAddresses",
"records",
"any",
"addresses",
"related",
"to",
"the",
"machine",
"sourced",
"by",
"asking",
"the",
"provider",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1703-L1706 |
4,822 | juju/juju | state/machine.go | ProviderAddresses | func (m *Machine) ProviderAddresses() (addresses []network.Address) {
for _, address := range m.doc.Addresses {
addresses = append(addresses, address.networkAddress())
}
return
} | go | func (m *Machine) ProviderAddresses() (addresses []network.Address) {
for _, address := range m.doc.Addresses {
addresses = append(addresses, address.networkAddress())
}
return
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"ProviderAddresses",
"(",
")",
"(",
"addresses",
"[",
"]",
"network",
".",
"Address",
")",
"{",
"for",
"_",
",",
"address",
":=",
"range",
"m",
".",
"doc",
".",
"Addresses",
"{",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"address",
".",
"networkAddress",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ProviderAddresses returns any hostnames and ips associated with a machine,
// as determined by asking the provider. | [
"ProviderAddresses",
"returns",
"any",
"hostnames",
"and",
"ips",
"associated",
"with",
"a",
"machine",
"as",
"determined",
"by",
"asking",
"the",
"provider",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1710-L1715 |
4,823 | juju/juju | state/machine.go | MachineAddresses | func (m *Machine) MachineAddresses() (addresses []network.Address) {
for _, address := range m.doc.MachineAddresses {
addresses = append(addresses, address.networkAddress())
}
return
} | go | func (m *Machine) MachineAddresses() (addresses []network.Address) {
for _, address := range m.doc.MachineAddresses {
addresses = append(addresses, address.networkAddress())
}
return
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"MachineAddresses",
"(",
")",
"(",
"addresses",
"[",
"]",
"network",
".",
"Address",
")",
"{",
"for",
"_",
",",
"address",
":=",
"range",
"m",
".",
"doc",
".",
"MachineAddresses",
"{",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"address",
".",
"networkAddress",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // MachineAddresses returns any hostnames and ips associated with a machine,
// determined by asking the machine itself. | [
"MachineAddresses",
"returns",
"any",
"hostnames",
"and",
"ips",
"associated",
"with",
"a",
"machine",
"determined",
"by",
"asking",
"the",
"machine",
"itself",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1719-L1724 |
4,824 | juju/juju | state/machine.go | CheckProvisioned | func (m *Machine) CheckProvisioned(nonce string) bool {
return nonce == m.doc.Nonce && nonce != ""
} | go | func (m *Machine) CheckProvisioned(nonce string) bool {
return nonce == m.doc.Nonce && nonce != ""
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"CheckProvisioned",
"(",
"nonce",
"string",
")",
"bool",
"{",
"return",
"nonce",
"==",
"m",
".",
"doc",
".",
"Nonce",
"&&",
"nonce",
"!=",
"\"",
"\"",
"\n",
"}"
] | // CheckProvisioned returns true if the machine was provisioned with the given nonce. | [
"CheckProvisioned",
"returns",
"true",
"if",
"the",
"machine",
"was",
"provisioned",
"with",
"the",
"given",
"nonce",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1826-L1828 |
4,825 | juju/juju | state/machine.go | Constraints | func (m *Machine) Constraints() (constraints.Value, error) {
return readConstraints(m.st, m.globalKey())
} | go | func (m *Machine) Constraints() (constraints.Value, error) {
return readConstraints(m.st, m.globalKey())
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Constraints",
"(",
")",
"(",
"constraints",
".",
"Value",
",",
"error",
")",
"{",
"return",
"readConstraints",
"(",
"m",
".",
"st",
",",
"m",
".",
"globalKey",
"(",
")",
")",
"\n",
"}"
] | // Constraints returns the exact constraints that should apply when provisioning
// an instance for the machine. | [
"Constraints",
"returns",
"the",
"exact",
"constraints",
"that",
"should",
"apply",
"when",
"provisioning",
"an",
"instance",
"for",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1843-L1845 |
4,826 | juju/juju | state/machine.go | SetConstraints | func (m *Machine) SetConstraints(cons constraints.Value) (err error) {
op := m.UpdateOperation()
op.Constraints = &cons
return m.st.ApplyOperation(op)
} | go | func (m *Machine) SetConstraints(cons constraints.Value) (err error) {
op := m.UpdateOperation()
op.Constraints = &cons
return m.st.ApplyOperation(op)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetConstraints",
"(",
"cons",
"constraints",
".",
"Value",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"m",
".",
"UpdateOperation",
"(",
")",
"\n",
"op",
".",
"Constraints",
"=",
"&",
"cons",
"\n",
"return",
"m",
".",
"st",
".",
"ApplyOperation",
"(",
"op",
")",
"\n",
"}"
] | // SetConstraints sets the exact constraints to apply when provisioning an
// instance for the machine. It will fail if the machine is Dead, or if it
// is already provisioned. | [
"SetConstraints",
"sets",
"the",
"exact",
"constraints",
"to",
"apply",
"when",
"provisioning",
"an",
"instance",
"for",
"the",
"machine",
".",
"It",
"will",
"fail",
"if",
"the",
"machine",
"is",
"Dead",
"or",
"if",
"it",
"is",
"already",
"provisioned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1850-L1854 |
4,827 | juju/juju | state/machine.go | Status | func (m *Machine) Status() (status.StatusInfo, error) {
mStatus, err := getStatus(m.st.db(), m.globalKey(), "machine")
if err != nil {
return mStatus, err
}
return mStatus, nil
} | go | func (m *Machine) Status() (status.StatusInfo, error) {
mStatus, err := getStatus(m.st.db(), m.globalKey(), "machine")
if err != nil {
return mStatus, err
}
return mStatus, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Status",
"(",
")",
"(",
"status",
".",
"StatusInfo",
",",
"error",
")",
"{",
"mStatus",
",",
"err",
":=",
"getStatus",
"(",
"m",
".",
"st",
".",
"db",
"(",
")",
",",
"m",
".",
"globalKey",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mStatus",
",",
"err",
"\n",
"}",
"\n",
"return",
"mStatus",
",",
"nil",
"\n",
"}"
] | // Status returns the status of the machine. | [
"Status",
"returns",
"the",
"status",
"of",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1891-L1897 |
4,828 | juju/juju | state/machine.go | SetStatus | func (m *Machine) SetStatus(statusInfo status.StatusInfo) error {
switch statusInfo.Status {
case status.Started, status.Stopped:
case status.Error:
if statusInfo.Message == "" {
return errors.Errorf("cannot set status %q without info", statusInfo.Status)
}
case status.Pending:
// If a machine is not yet provisioned, we allow its status
// to be set back to pending (when a retry is to occur).
_, err := m.InstanceId()
allowPending := errors.IsNotProvisioned(err)
if allowPending {
break
}
fallthrough
case status.Down:
return errors.Errorf("cannot set status %q", statusInfo.Status)
default:
return errors.Errorf("cannot set invalid status %q", statusInfo.Status)
}
return setStatus(m.st.db(), setStatusParams{
badge: "machine",
globalKey: m.globalKey(),
status: statusInfo.Status,
message: statusInfo.Message,
rawData: statusInfo.Data,
updated: timeOrNow(statusInfo.Since, m.st.clock()),
})
} | go | func (m *Machine) SetStatus(statusInfo status.StatusInfo) error {
switch statusInfo.Status {
case status.Started, status.Stopped:
case status.Error:
if statusInfo.Message == "" {
return errors.Errorf("cannot set status %q without info", statusInfo.Status)
}
case status.Pending:
// If a machine is not yet provisioned, we allow its status
// to be set back to pending (when a retry is to occur).
_, err := m.InstanceId()
allowPending := errors.IsNotProvisioned(err)
if allowPending {
break
}
fallthrough
case status.Down:
return errors.Errorf("cannot set status %q", statusInfo.Status)
default:
return errors.Errorf("cannot set invalid status %q", statusInfo.Status)
}
return setStatus(m.st.db(), setStatusParams{
badge: "machine",
globalKey: m.globalKey(),
status: statusInfo.Status,
message: statusInfo.Message,
rawData: statusInfo.Data,
updated: timeOrNow(statusInfo.Since, m.st.clock()),
})
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetStatus",
"(",
"statusInfo",
"status",
".",
"StatusInfo",
")",
"error",
"{",
"switch",
"statusInfo",
".",
"Status",
"{",
"case",
"status",
".",
"Started",
",",
"status",
".",
"Stopped",
":",
"case",
"status",
".",
"Error",
":",
"if",
"statusInfo",
".",
"Message",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"statusInfo",
".",
"Status",
")",
"\n",
"}",
"\n",
"case",
"status",
".",
"Pending",
":",
"// If a machine is not yet provisioned, we allow its status",
"// to be set back to pending (when a retry is to occur).",
"_",
",",
"err",
":=",
"m",
".",
"InstanceId",
"(",
")",
"\n",
"allowPending",
":=",
"errors",
".",
"IsNotProvisioned",
"(",
"err",
")",
"\n",
"if",
"allowPending",
"{",
"break",
"\n",
"}",
"\n",
"fallthrough",
"\n",
"case",
"status",
".",
"Down",
":",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"statusInfo",
".",
"Status",
")",
"\n",
"default",
":",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"statusInfo",
".",
"Status",
")",
"\n",
"}",
"\n",
"return",
"setStatus",
"(",
"m",
".",
"st",
".",
"db",
"(",
")",
",",
"setStatusParams",
"{",
"badge",
":",
"\"",
"\"",
",",
"globalKey",
":",
"m",
".",
"globalKey",
"(",
")",
",",
"status",
":",
"statusInfo",
".",
"Status",
",",
"message",
":",
"statusInfo",
".",
"Message",
",",
"rawData",
":",
"statusInfo",
".",
"Data",
",",
"updated",
":",
"timeOrNow",
"(",
"statusInfo",
".",
"Since",
",",
"m",
".",
"st",
".",
"clock",
"(",
")",
")",
",",
"}",
")",
"\n",
"}"
] | // SetStatus sets the status of the machine. | [
"SetStatus",
"sets",
"the",
"status",
"of",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1900-L1929 |
4,829 | juju/juju | state/machine.go | SupportedContainers | func (m *Machine) SupportedContainers() ([]instance.ContainerType, bool) {
return m.doc.SupportedContainers, m.doc.SupportedContainersKnown
} | go | func (m *Machine) SupportedContainers() ([]instance.ContainerType, bool) {
return m.doc.SupportedContainers, m.doc.SupportedContainersKnown
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SupportedContainers",
"(",
")",
"(",
"[",
"]",
"instance",
".",
"ContainerType",
",",
"bool",
")",
"{",
"return",
"m",
".",
"doc",
".",
"SupportedContainers",
",",
"m",
".",
"doc",
".",
"SupportedContainersKnown",
"\n",
"}"
] | // SupportedContainers returns any containers this machine is capable of hosting, and a bool
// indicating if the supported containers have been determined or not. | [
"SupportedContainers",
"returns",
"any",
"containers",
"this",
"machine",
"is",
"capable",
"of",
"hosting",
"and",
"a",
"bool",
"indicating",
"if",
"the",
"supported",
"containers",
"have",
"been",
"determined",
"or",
"not",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1950-L1952 |
4,830 | juju/juju | state/machine.go | SupportsNoContainers | func (m *Machine) SupportsNoContainers() (err error) {
if err = m.updateSupportedContainers([]instance.ContainerType{}); err != nil {
return err
}
return m.markInvalidContainers()
} | go | func (m *Machine) SupportsNoContainers() (err error) {
if err = m.updateSupportedContainers([]instance.ContainerType{}); err != nil {
return err
}
return m.markInvalidContainers()
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SupportsNoContainers",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"updateSupportedContainers",
"(",
"[",
"]",
"instance",
".",
"ContainerType",
"{",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"m",
".",
"markInvalidContainers",
"(",
")",
"\n",
"}"
] | // SupportsNoContainers records the fact that this machine doesn't support any containers. | [
"SupportsNoContainers",
"records",
"the",
"fact",
"that",
"this",
"machine",
"doesn",
"t",
"support",
"any",
"containers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1955-L1960 |
4,831 | juju/juju | state/machine.go | SetSupportedContainers | func (m *Machine) SetSupportedContainers(containers []instance.ContainerType) (err error) {
if len(containers) == 0 {
return fmt.Errorf("at least one valid container type is required")
}
for _, container := range containers {
if container == instance.NONE {
return fmt.Errorf("%q is not a valid container type", container)
}
}
if err = m.updateSupportedContainers(containers); err != nil {
return err
}
return m.markInvalidContainers()
} | go | func (m *Machine) SetSupportedContainers(containers []instance.ContainerType) (err error) {
if len(containers) == 0 {
return fmt.Errorf("at least one valid container type is required")
}
for _, container := range containers {
if container == instance.NONE {
return fmt.Errorf("%q is not a valid container type", container)
}
}
if err = m.updateSupportedContainers(containers); err != nil {
return err
}
return m.markInvalidContainers()
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetSupportedContainers",
"(",
"containers",
"[",
"]",
"instance",
".",
"ContainerType",
")",
"(",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"containers",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"container",
":=",
"range",
"containers",
"{",
"if",
"container",
"==",
"instance",
".",
"NONE",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"container",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"=",
"m",
".",
"updateSupportedContainers",
"(",
"containers",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"m",
".",
"markInvalidContainers",
"(",
")",
"\n",
"}"
] | // SetSupportedContainers sets the list of containers supported by this machine. | [
"SetSupportedContainers",
"sets",
"the",
"list",
"of",
"containers",
"supported",
"by",
"this",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1963-L1976 |
4,832 | juju/juju | state/machine.go | updateSupportedContainers | func (m *Machine) updateSupportedContainers(supportedContainers []instance.ContainerType) (err error) {
if m.doc.SupportedContainersKnown {
if len(m.doc.SupportedContainers) == len(supportedContainers) {
equal := true
types := make(map[instance.ContainerType]struct{}, len(m.doc.SupportedContainers))
for _, v := range m.doc.SupportedContainers {
types[v] = struct{}{}
}
for _, v := range supportedContainers {
if _, ok := types[v]; !ok {
equal = false
break
}
}
if equal {
return nil
}
}
}
ops := []txn.Op{
{
C: machinesC,
Id: m.doc.DocID,
Assert: notDeadDoc,
Update: bson.D{
{"$set", bson.D{
{"supportedcontainers", supportedContainers},
{"supportedcontainersknown", true},
}}},
},
}
if err = m.st.db().RunTransaction(ops); err != nil {
err = onAbort(err, ErrDead)
logger.Errorf("cannot update supported containers of machine %v: %v", m, err)
return err
}
m.doc.SupportedContainers = supportedContainers
m.doc.SupportedContainersKnown = true
return nil
} | go | func (m *Machine) updateSupportedContainers(supportedContainers []instance.ContainerType) (err error) {
if m.doc.SupportedContainersKnown {
if len(m.doc.SupportedContainers) == len(supportedContainers) {
equal := true
types := make(map[instance.ContainerType]struct{}, len(m.doc.SupportedContainers))
for _, v := range m.doc.SupportedContainers {
types[v] = struct{}{}
}
for _, v := range supportedContainers {
if _, ok := types[v]; !ok {
equal = false
break
}
}
if equal {
return nil
}
}
}
ops := []txn.Op{
{
C: machinesC,
Id: m.doc.DocID,
Assert: notDeadDoc,
Update: bson.D{
{"$set", bson.D{
{"supportedcontainers", supportedContainers},
{"supportedcontainersknown", true},
}}},
},
}
if err = m.st.db().RunTransaction(ops); err != nil {
err = onAbort(err, ErrDead)
logger.Errorf("cannot update supported containers of machine %v: %v", m, err)
return err
}
m.doc.SupportedContainers = supportedContainers
m.doc.SupportedContainersKnown = true
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"updateSupportedContainers",
"(",
"supportedContainers",
"[",
"]",
"instance",
".",
"ContainerType",
")",
"(",
"err",
"error",
")",
"{",
"if",
"m",
".",
"doc",
".",
"SupportedContainersKnown",
"{",
"if",
"len",
"(",
"m",
".",
"doc",
".",
"SupportedContainers",
")",
"==",
"len",
"(",
"supportedContainers",
")",
"{",
"equal",
":=",
"true",
"\n",
"types",
":=",
"make",
"(",
"map",
"[",
"instance",
".",
"ContainerType",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"m",
".",
"doc",
".",
"SupportedContainers",
")",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"m",
".",
"doc",
".",
"SupportedContainers",
"{",
"types",
"[",
"v",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"supportedContainers",
"{",
"if",
"_",
",",
"ok",
":=",
"types",
"[",
"v",
"]",
";",
"!",
"ok",
"{",
"equal",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"equal",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"machinesC",
",",
"Id",
":",
"m",
".",
"doc",
".",
"DocID",
",",
"Assert",
":",
"notDeadDoc",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"supportedContainers",
"}",
",",
"{",
"\"",
"\"",
",",
"true",
"}",
",",
"}",
"}",
"}",
",",
"}",
",",
"}",
"\n",
"if",
"err",
"=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"onAbort",
"(",
"err",
",",
"ErrDead",
")",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"m",
".",
"doc",
".",
"SupportedContainers",
"=",
"supportedContainers",
"\n",
"m",
".",
"doc",
".",
"SupportedContainersKnown",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] | // updateSupportedContainers sets the supported containers on this host machine. | [
"updateSupportedContainers",
"sets",
"the",
"supported",
"containers",
"on",
"this",
"host",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L1988-L2027 |
4,833 | juju/juju | state/machine.go | markInvalidContainers | func (m *Machine) markInvalidContainers() error {
currentContainers, err := m.Containers()
if err != nil {
return err
}
for _, containerId := range currentContainers {
if !isSupportedContainer(ContainerTypeFromId(containerId), m.doc.SupportedContainers) {
container, err := m.st.Machine(containerId)
if err != nil {
logger.Errorf("loading container %v to mark as invalid: %v", containerId, err)
continue
}
// There should never be a circumstance where an unsupported container is started.
// Nonetheless, we check and log an error if such a situation arises.
statusInfo, err := container.Status()
if err != nil {
logger.Errorf("finding status of container %v to mark as invalid: %v", containerId, err)
continue
}
if statusInfo.Status == status.Pending {
containerType := ContainerTypeFromId(containerId)
now := m.st.clock().Now()
s := status.StatusInfo{
Status: status.Error,
Message: "unsupported container",
Data: map[string]interface{}{"type": containerType},
Since: &now,
}
container.SetStatus(s)
} else {
logger.Errorf("unsupported container %v has unexpected status %v", containerId, statusInfo.Status)
}
}
}
return nil
} | go | func (m *Machine) markInvalidContainers() error {
currentContainers, err := m.Containers()
if err != nil {
return err
}
for _, containerId := range currentContainers {
if !isSupportedContainer(ContainerTypeFromId(containerId), m.doc.SupportedContainers) {
container, err := m.st.Machine(containerId)
if err != nil {
logger.Errorf("loading container %v to mark as invalid: %v", containerId, err)
continue
}
// There should never be a circumstance where an unsupported container is started.
// Nonetheless, we check and log an error if such a situation arises.
statusInfo, err := container.Status()
if err != nil {
logger.Errorf("finding status of container %v to mark as invalid: %v", containerId, err)
continue
}
if statusInfo.Status == status.Pending {
containerType := ContainerTypeFromId(containerId)
now := m.st.clock().Now()
s := status.StatusInfo{
Status: status.Error,
Message: "unsupported container",
Data: map[string]interface{}{"type": containerType},
Since: &now,
}
container.SetStatus(s)
} else {
logger.Errorf("unsupported container %v has unexpected status %v", containerId, statusInfo.Status)
}
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"markInvalidContainers",
"(",
")",
"error",
"{",
"currentContainers",
",",
"err",
":=",
"m",
".",
"Containers",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"containerId",
":=",
"range",
"currentContainers",
"{",
"if",
"!",
"isSupportedContainer",
"(",
"ContainerTypeFromId",
"(",
"containerId",
")",
",",
"m",
".",
"doc",
".",
"SupportedContainers",
")",
"{",
"container",
",",
"err",
":=",
"m",
".",
"st",
".",
"Machine",
"(",
"containerId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"containerId",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"// There should never be a circumstance where an unsupported container is started.",
"// Nonetheless, we check and log an error if such a situation arises.",
"statusInfo",
",",
"err",
":=",
"container",
".",
"Status",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"containerId",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"statusInfo",
".",
"Status",
"==",
"status",
".",
"Pending",
"{",
"containerType",
":=",
"ContainerTypeFromId",
"(",
"containerId",
")",
"\n",
"now",
":=",
"m",
".",
"st",
".",
"clock",
"(",
")",
".",
"Now",
"(",
")",
"\n",
"s",
":=",
"status",
".",
"StatusInfo",
"{",
"Status",
":",
"status",
".",
"Error",
",",
"Message",
":",
"\"",
"\"",
",",
"Data",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"containerType",
"}",
",",
"Since",
":",
"&",
"now",
",",
"}",
"\n",
"container",
".",
"SetStatus",
"(",
"s",
")",
"\n",
"}",
"else",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"containerId",
",",
"statusInfo",
".",
"Status",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // markInvalidContainers sets the status of any container belonging to this machine
// as being in error if the container type is not supported. | [
"markInvalidContainers",
"sets",
"the",
"status",
"of",
"any",
"container",
"belonging",
"to",
"this",
"machine",
"as",
"being",
"in",
"error",
"if",
"the",
"container",
"type",
"is",
"not",
"supported",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2031-L2066 |
4,834 | juju/juju | state/machine.go | SetMachineBlockDevices | func (m *Machine) SetMachineBlockDevices(info ...BlockDeviceInfo) error {
return setMachineBlockDevices(m.st, m.Id(), info)
} | go | func (m *Machine) SetMachineBlockDevices(info ...BlockDeviceInfo) error {
return setMachineBlockDevices(m.st, m.Id(), info)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetMachineBlockDevices",
"(",
"info",
"...",
"BlockDeviceInfo",
")",
"error",
"{",
"return",
"setMachineBlockDevices",
"(",
"m",
".",
"st",
",",
"m",
".",
"Id",
"(",
")",
",",
"info",
")",
"\n",
"}"
] | // SetMachineBlockDevices sets the block devices visible on the machine. | [
"SetMachineBlockDevices",
"sets",
"the",
"block",
"devices",
"visible",
"on",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2069-L2071 |
4,835 | juju/juju | state/machine.go | VolumeAttachments | func (m *Machine) VolumeAttachments() ([]VolumeAttachment, error) {
sb, err := NewStorageBackend(m.st)
if err != nil {
return nil, errors.Trace(err)
}
return sb.MachineVolumeAttachments(m.MachineTag())
} | go | func (m *Machine) VolumeAttachments() ([]VolumeAttachment, error) {
sb, err := NewStorageBackend(m.st)
if err != nil {
return nil, errors.Trace(err)
}
return sb.MachineVolumeAttachments(m.MachineTag())
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"VolumeAttachments",
"(",
")",
"(",
"[",
"]",
"VolumeAttachment",
",",
"error",
")",
"{",
"sb",
",",
"err",
":=",
"NewStorageBackend",
"(",
"m",
".",
"st",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"sb",
".",
"MachineVolumeAttachments",
"(",
"m",
".",
"MachineTag",
"(",
")",
")",
"\n",
"}"
] | // VolumeAttachments returns the machine's volume attachments. | [
"VolumeAttachments",
"returns",
"the",
"machine",
"s",
"volume",
"attachments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2074-L2080 |
4,836 | juju/juju | state/machine.go | AddAction | func (m *Machine) AddAction(name string, payload map[string]interface{}) (Action, error) {
spec, ok := actions.PredefinedActionsSpec[name]
if !ok {
return nil, errors.Errorf("cannot add action %q to a machine; only predefined actions allowed", name)
}
// Reject bad payloads before attempting to insert defaults.
err := spec.ValidateParams(payload)
if err != nil {
return nil, err
}
payloadWithDefaults, err := spec.InsertDefaults(payload)
if err != nil {
return nil, err
}
model, err := m.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return model.EnqueueAction(m.Tag(), name, payloadWithDefaults)
} | go | func (m *Machine) AddAction(name string, payload map[string]interface{}) (Action, error) {
spec, ok := actions.PredefinedActionsSpec[name]
if !ok {
return nil, errors.Errorf("cannot add action %q to a machine; only predefined actions allowed", name)
}
// Reject bad payloads before attempting to insert defaults.
err := spec.ValidateParams(payload)
if err != nil {
return nil, err
}
payloadWithDefaults, err := spec.InsertDefaults(payload)
if err != nil {
return nil, err
}
model, err := m.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return model.EnqueueAction(m.Tag(), name, payloadWithDefaults)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"AddAction",
"(",
"name",
"string",
",",
"payload",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"Action",
",",
"error",
")",
"{",
"spec",
",",
"ok",
":=",
"actions",
".",
"PredefinedActionsSpec",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"// Reject bad payloads before attempting to insert defaults.",
"err",
":=",
"spec",
".",
"ValidateParams",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"payloadWithDefaults",
",",
"err",
":=",
"spec",
".",
"InsertDefaults",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"model",
",",
"err",
":=",
"m",
".",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"model",
".",
"EnqueueAction",
"(",
"m",
".",
"Tag",
"(",
")",
",",
"name",
",",
"payloadWithDefaults",
")",
"\n",
"}"
] | // AddAction is part of the ActionReceiver interface. | [
"AddAction",
"is",
"part",
"of",
"the",
"ActionReceiver",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2083-L2105 |
4,837 | juju/juju | state/machine.go | CancelAction | func (m *Machine) CancelAction(action Action) (Action, error) {
return action.Finish(ActionResults{Status: ActionCancelled})
} | go | func (m *Machine) CancelAction(action Action) (Action, error) {
return action.Finish(ActionResults{Status: ActionCancelled})
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"CancelAction",
"(",
"action",
"Action",
")",
"(",
"Action",
",",
"error",
")",
"{",
"return",
"action",
".",
"Finish",
"(",
"ActionResults",
"{",
"Status",
":",
"ActionCancelled",
"}",
")",
"\n",
"}"
] | // CancelAction is part of the ActionReceiver interface. | [
"CancelAction",
"is",
"part",
"of",
"the",
"ActionReceiver",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2108-L2110 |
4,838 | juju/juju | state/machine.go | UpdateMachineSeries | func (m *Machine) UpdateMachineSeries(series string, force bool) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := m.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
// Exit early if the Machine series doesn't need to change.
if m.Series() == series {
return nil, jujutxn.ErrNoOperations
}
principals := m.Principals() // unit names
verifiedUnits, err := m.VerifyUnitsSeries(principals, series, force)
if err != nil {
return nil, err
}
ops := []txn.Op{{
C: machinesC,
Id: m.doc.DocID,
Assert: bson.D{{"life", Alive}, {"principals", principals}},
Update: bson.D{{"$set", bson.D{{"series", series}}}},
}}
for _, unit := range verifiedUnits {
curl, _ := unit.CharmURL()
ops = append(ops, txn.Op{
C: unitsC,
Id: unit.doc.DocID,
Assert: bson.D{{"life", Alive},
{"charmurl", curl},
{"subordinates", unit.SubordinateNames()}},
Update: bson.D{{"$set", bson.D{{"series", series}}}},
})
}
return ops, nil
}
err := m.st.db().Run(buildTxn)
return errors.Annotatef(err, "updating series for machine %q", m)
} | go | func (m *Machine) UpdateMachineSeries(series string, force bool) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := m.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
// Exit early if the Machine series doesn't need to change.
if m.Series() == series {
return nil, jujutxn.ErrNoOperations
}
principals := m.Principals() // unit names
verifiedUnits, err := m.VerifyUnitsSeries(principals, series, force)
if err != nil {
return nil, err
}
ops := []txn.Op{{
C: machinesC,
Id: m.doc.DocID,
Assert: bson.D{{"life", Alive}, {"principals", principals}},
Update: bson.D{{"$set", bson.D{{"series", series}}}},
}}
for _, unit := range verifiedUnits {
curl, _ := unit.CharmURL()
ops = append(ops, txn.Op{
C: unitsC,
Id: unit.doc.DocID,
Assert: bson.D{{"life", Alive},
{"charmurl", curl},
{"subordinates", unit.SubordinateNames()}},
Update: bson.D{{"$set", bson.D{{"series", series}}}},
})
}
return ops, nil
}
err := m.st.db().Run(buildTxn)
return errors.Annotatef(err, "updating series for machine %q", m)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"UpdateMachineSeries",
"(",
"series",
"string",
",",
"force",
"bool",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"m",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Exit early if the Machine series doesn't need to change.",
"if",
"m",
".",
"Series",
"(",
")",
"==",
"series",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n\n",
"principals",
":=",
"m",
".",
"Principals",
"(",
")",
"// unit names",
"\n",
"verifiedUnits",
",",
"err",
":=",
"m",
".",
"VerifyUnitsSeries",
"(",
"principals",
",",
"series",
",",
"force",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"machinesC",
",",
"Id",
":",
"m",
".",
"doc",
".",
"DocID",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Alive",
"}",
",",
"{",
"\"",
"\"",
",",
"principals",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"series",
"}",
"}",
"}",
"}",
",",
"}",
"}",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"verifiedUnits",
"{",
"curl",
",",
"_",
":=",
"unit",
".",
"CharmURL",
"(",
")",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"txn",
".",
"Op",
"{",
"C",
":",
"unitsC",
",",
"Id",
":",
"unit",
".",
"doc",
".",
"DocID",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Alive",
"}",
",",
"{",
"\"",
"\"",
",",
"curl",
"}",
",",
"{",
"\"",
"\"",
",",
"unit",
".",
"SubordinateNames",
"(",
")",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"series",
"}",
"}",
"}",
"}",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"m",
")",
"\n",
"}"
] | // UpdateMachineSeries updates the series for the Machine. | [
"UpdateMachineSeries",
"updates",
"the",
"series",
"for",
"the",
"Machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2138-L2178 |
4,839 | juju/juju | state/machine.go | VerifyUnitsSeries | func (m *Machine) VerifyUnitsSeries(unitNames []string, series string, force bool) ([]*Unit, error) {
var results []*Unit
for _, u := range unitNames {
unit, err := m.st.Unit(u)
if err != nil {
return nil, err
}
app, err := unit.Application()
if err != nil {
return nil, err
}
err = app.VerifySupportedSeries(series, force)
if err != nil {
return nil, err
}
subordinates := unit.SubordinateNames()
subUnits, err := m.VerifyUnitsSeries(subordinates, series, force)
if err != nil {
return nil, err
}
results = append(results, unit)
results = append(results, subUnits...)
}
return results, nil
} | go | func (m *Machine) VerifyUnitsSeries(unitNames []string, series string, force bool) ([]*Unit, error) {
var results []*Unit
for _, u := range unitNames {
unit, err := m.st.Unit(u)
if err != nil {
return nil, err
}
app, err := unit.Application()
if err != nil {
return nil, err
}
err = app.VerifySupportedSeries(series, force)
if err != nil {
return nil, err
}
subordinates := unit.SubordinateNames()
subUnits, err := m.VerifyUnitsSeries(subordinates, series, force)
if err != nil {
return nil, err
}
results = append(results, unit)
results = append(results, subUnits...)
}
return results, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"VerifyUnitsSeries",
"(",
"unitNames",
"[",
"]",
"string",
",",
"series",
"string",
",",
"force",
"bool",
")",
"(",
"[",
"]",
"*",
"Unit",
",",
"error",
")",
"{",
"var",
"results",
"[",
"]",
"*",
"Unit",
"\n",
"for",
"_",
",",
"u",
":=",
"range",
"unitNames",
"{",
"unit",
",",
"err",
":=",
"m",
".",
"st",
".",
"Unit",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"unit",
".",
"Application",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"app",
".",
"VerifySupportedSeries",
"(",
"series",
",",
"force",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"subordinates",
":=",
"unit",
".",
"SubordinateNames",
"(",
")",
"\n",
"subUnits",
",",
"err",
":=",
"m",
".",
"VerifyUnitsSeries",
"(",
"subordinates",
",",
"series",
",",
"force",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"results",
"=",
"append",
"(",
"results",
",",
"unit",
")",
"\n",
"results",
"=",
"append",
"(",
"results",
",",
"subUnits",
"...",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // VerifyUnitsSeries iterates over the units with the input names, and checks
// that the application for each supports the input series.
// Recursion is used to verify all subordinates, with the results accrued into
// a slice before returning. | [
"VerifyUnitsSeries",
"iterates",
"over",
"the",
"units",
"with",
"the",
"input",
"names",
"and",
"checks",
"that",
"the",
"application",
"for",
"each",
"supports",
"the",
"input",
"series",
".",
"Recursion",
"is",
"used",
"to",
"verify",
"all",
"subordinates",
"with",
"the",
"results",
"accrued",
"into",
"a",
"slice",
"before",
"returning",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2184-L2209 |
4,840 | juju/juju | state/machine.go | UpdateOperation | func (m *Machine) UpdateOperation() *UpdateMachineOperation {
return &UpdateMachineOperation{m: &Machine{st: m.st, doc: m.doc}}
} | go | func (m *Machine) UpdateOperation() *UpdateMachineOperation {
return &UpdateMachineOperation{m: &Machine{st: m.st, doc: m.doc}}
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"UpdateOperation",
"(",
")",
"*",
"UpdateMachineOperation",
"{",
"return",
"&",
"UpdateMachineOperation",
"{",
"m",
":",
"&",
"Machine",
"{",
"st",
":",
"m",
".",
"st",
",",
"doc",
":",
"m",
".",
"doc",
"}",
"}",
"\n",
"}"
] | // UpdateOperation returns a model operation that will update the machine. | [
"UpdateOperation",
"returns",
"a",
"model",
"operation",
"that",
"will",
"update",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine.go#L2212-L2214 |
4,841 | juju/juju | apiserver/common/life.go | NewLifeGetter | func NewLifeGetter(st state.EntityFinder, getCanRead GetAuthFunc) *LifeGetter {
return &LifeGetter{
st: st,
getCanRead: getCanRead,
}
} | go | func NewLifeGetter(st state.EntityFinder, getCanRead GetAuthFunc) *LifeGetter {
return &LifeGetter{
st: st,
getCanRead: getCanRead,
}
} | [
"func",
"NewLifeGetter",
"(",
"st",
"state",
".",
"EntityFinder",
",",
"getCanRead",
"GetAuthFunc",
")",
"*",
"LifeGetter",
"{",
"return",
"&",
"LifeGetter",
"{",
"st",
":",
"st",
",",
"getCanRead",
":",
"getCanRead",
",",
"}",
"\n",
"}"
] | // NewLifeGetter returns a new LifeGetter. The GetAuthFunc will be used on
// each invocation of Life to determine current permissions. | [
"NewLifeGetter",
"returns",
"a",
"new",
"LifeGetter",
".",
"The",
"GetAuthFunc",
"will",
"be",
"used",
"on",
"each",
"invocation",
"of",
"Life",
"to",
"determine",
"current",
"permissions",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/life.go#L22-L27 |
4,842 | juju/juju | apiserver/common/life.go | Life | func (lg *LifeGetter) Life(args params.Entities) (params.LifeResults, error) {
result := params.LifeResults{
Results: make([]params.LifeResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
canRead, err := lg.getCanRead()
if err != nil {
return params.LifeResults{}, errors.Trace(err)
}
for i, entity := range args.Entities {
tag, err := names.ParseTag(entity.Tag)
if err != nil {
result.Results[i].Error = ServerError(ErrPerm)
continue
}
err = ErrPerm
if canRead(tag) {
result.Results[i].Life, err = lg.oneLife(tag)
}
result.Results[i].Error = ServerError(err)
}
return result, nil
} | go | func (lg *LifeGetter) Life(args params.Entities) (params.LifeResults, error) {
result := params.LifeResults{
Results: make([]params.LifeResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
canRead, err := lg.getCanRead()
if err != nil {
return params.LifeResults{}, errors.Trace(err)
}
for i, entity := range args.Entities {
tag, err := names.ParseTag(entity.Tag)
if err != nil {
result.Results[i].Error = ServerError(ErrPerm)
continue
}
err = ErrPerm
if canRead(tag) {
result.Results[i].Life, err = lg.oneLife(tag)
}
result.Results[i].Error = ServerError(err)
}
return result, nil
} | [
"func",
"(",
"lg",
"*",
"LifeGetter",
")",
"Life",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"LifeResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"LifeResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"LifeResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"if",
"len",
"(",
"args",
".",
"Entities",
")",
"==",
"0",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"canRead",
",",
"err",
":=",
"lg",
".",
"getCanRead",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"LifeResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseTag",
"(",
"entity",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"err",
"=",
"ErrPerm",
"\n",
"if",
"canRead",
"(",
"tag",
")",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Life",
",",
"err",
"=",
"lg",
".",
"oneLife",
"(",
"tag",
")",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Life returns the life status of every supplied entity, where available. | [
"Life",
"returns",
"the",
"life",
"status",
"of",
"every",
"supplied",
"entity",
"where",
"available",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/life.go#L42-L66 |
4,843 | juju/juju | state/lease/schema.go | entry | func (doc leaseDoc) entry() (string, entry, error) {
if err := doc.validate(); err != nil {
return "", entry{}, errors.Trace(err)
}
entry := entry{
holder: doc.Holder,
start: toTime(doc.Start),
duration: doc.Duration,
writer: doc.Writer,
}
return doc.Name, entry, nil
} | go | func (doc leaseDoc) entry() (string, entry, error) {
if err := doc.validate(); err != nil {
return "", entry{}, errors.Trace(err)
}
entry := entry{
holder: doc.Holder,
start: toTime(doc.Start),
duration: doc.Duration,
writer: doc.Writer,
}
return doc.Name, entry, nil
} | [
"func",
"(",
"doc",
"leaseDoc",
")",
"entry",
"(",
")",
"(",
"string",
",",
"entry",
",",
"error",
")",
"{",
"if",
"err",
":=",
"doc",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"entry",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"entry",
":=",
"entry",
"{",
"holder",
":",
"doc",
".",
"Holder",
",",
"start",
":",
"toTime",
"(",
"doc",
".",
"Start",
")",
",",
"duration",
":",
"doc",
".",
"Duration",
",",
"writer",
":",
"doc",
".",
"Writer",
",",
"}",
"\n",
"return",
"doc",
".",
"Name",
",",
"entry",
",",
"nil",
"\n",
"}"
] | // entry returns the lease name and an entry corresponding to the document. If
// the document cannot be validated, it returns an error. | [
"entry",
"returns",
"the",
"lease",
"name",
"and",
"an",
"entry",
"corresponding",
"to",
"the",
"document",
".",
"If",
"the",
"document",
"cannot",
"be",
"validated",
"it",
"returns",
"an",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/lease/schema.go#L87-L98 |
4,844 | juju/juju | state/lease/schema.go | newLeaseDoc | func newLeaseDoc(namespace, name string, entry entry) (*leaseDoc, error) {
doc := &leaseDoc{
Id: leaseDocId(namespace, name),
Namespace: namespace,
Name: name,
Holder: entry.holder,
Start: toInt64(entry.start),
Duration: entry.duration,
Writer: entry.writer,
}
if err := doc.validate(); err != nil {
return nil, errors.Trace(err)
}
return doc, nil
} | go | func newLeaseDoc(namespace, name string, entry entry) (*leaseDoc, error) {
doc := &leaseDoc{
Id: leaseDocId(namespace, name),
Namespace: namespace,
Name: name,
Holder: entry.holder,
Start: toInt64(entry.start),
Duration: entry.duration,
Writer: entry.writer,
}
if err := doc.validate(); err != nil {
return nil, errors.Trace(err)
}
return doc, nil
} | [
"func",
"newLeaseDoc",
"(",
"namespace",
",",
"name",
"string",
",",
"entry",
"entry",
")",
"(",
"*",
"leaseDoc",
",",
"error",
")",
"{",
"doc",
":=",
"&",
"leaseDoc",
"{",
"Id",
":",
"leaseDocId",
"(",
"namespace",
",",
"name",
")",
",",
"Namespace",
":",
"namespace",
",",
"Name",
":",
"name",
",",
"Holder",
":",
"entry",
".",
"holder",
",",
"Start",
":",
"toInt64",
"(",
"entry",
".",
"start",
")",
",",
"Duration",
":",
"entry",
".",
"duration",
",",
"Writer",
":",
"entry",
".",
"writer",
",",
"}",
"\n",
"if",
"err",
":=",
"doc",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"doc",
",",
"nil",
"\n",
"}"
] | // newLeaseDoc returns a valid lease document encoding the supplied lease and
// entry in the supplied namespace, or an error. | [
"newLeaseDoc",
"returns",
"a",
"valid",
"lease",
"document",
"encoding",
"the",
"supplied",
"lease",
"and",
"entry",
"in",
"the",
"supplied",
"namespace",
"or",
"an",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/lease/schema.go#L102-L116 |
4,845 | juju/juju | resource/resource.go | Validate | func (res Resource) Validate() error {
// TODO(ericsnow) Ensure that the "placeholder" fields are not set
// if IsLocalPlaceholder() returns true (and that they *are* set
// otherwise)? Also ensure an "upload" origin in the "placeholder"
// case?
if err := res.Resource.Validate(); err != nil {
return errors.Annotate(err, "bad info")
}
if res.ApplicationID == "" {
return errors.NewNotValid(nil, "missing application ID")
}
// TODO(ericsnow) Require that Username be set if timestamp is?
if res.Timestamp.IsZero() && res.Username != "" {
return errors.NewNotValid(nil, "missing timestamp")
}
return nil
} | go | func (res Resource) Validate() error {
// TODO(ericsnow) Ensure that the "placeholder" fields are not set
// if IsLocalPlaceholder() returns true (and that they *are* set
// otherwise)? Also ensure an "upload" origin in the "placeholder"
// case?
if err := res.Resource.Validate(); err != nil {
return errors.Annotate(err, "bad info")
}
if res.ApplicationID == "" {
return errors.NewNotValid(nil, "missing application ID")
}
// TODO(ericsnow) Require that Username be set if timestamp is?
if res.Timestamp.IsZero() && res.Username != "" {
return errors.NewNotValid(nil, "missing timestamp")
}
return nil
} | [
"func",
"(",
"res",
"Resource",
")",
"Validate",
"(",
")",
"error",
"{",
"// TODO(ericsnow) Ensure that the \"placeholder\" fields are not set",
"// if IsLocalPlaceholder() returns true (and that they *are* set",
"// otherwise)? Also ensure an \"upload\" origin in the \"placeholder\"",
"// case?",
"if",
"err",
":=",
"res",
".",
"Resource",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"res",
".",
"ApplicationID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// TODO(ericsnow) Require that Username be set if timestamp is?",
"if",
"res",
".",
"Timestamp",
".",
"IsZero",
"(",
")",
"&&",
"res",
".",
"Username",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate ensures that the spec is valid. | [
"Validate",
"ensures",
"that",
"the",
"spec",
"is",
"valid",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/resource.go#L71-L92 |
4,846 | juju/juju | resource/resource.go | TimestampGranular | func (res Resource) TimestampGranular() time.Time {
return time.Unix(res.Timestamp.Unix(), 0)
} | go | func (res Resource) TimestampGranular() time.Time {
return time.Unix(res.Timestamp.Unix(), 0)
} | [
"func",
"(",
"res",
"Resource",
")",
"TimestampGranular",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Unix",
"(",
"res",
".",
"Timestamp",
".",
"Unix",
"(",
")",
",",
"0",
")",
"\n",
"}"
] | // TimestampGranular returns the timestamp at a resolution of 1 second. | [
"TimestampGranular",
"returns",
"the",
"timestamp",
"at",
"a",
"resolution",
"of",
"1",
"second",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/resource.go#L101-L103 |
4,847 | juju/juju | resource/resource.go | RevisionString | func (res Resource) RevisionString() string {
switch res.Origin {
case resource.OriginUpload:
if res.IsPlaceholder() {
return "-"
}
return res.TimestampGranular().UTC().String()
case resource.OriginStore:
return fmt.Sprintf("%d", res.Revision)
default:
// note: this should probably never happen.
return "-"
}
} | go | func (res Resource) RevisionString() string {
switch res.Origin {
case resource.OriginUpload:
if res.IsPlaceholder() {
return "-"
}
return res.TimestampGranular().UTC().String()
case resource.OriginStore:
return fmt.Sprintf("%d", res.Revision)
default:
// note: this should probably never happen.
return "-"
}
} | [
"func",
"(",
"res",
"Resource",
")",
"RevisionString",
"(",
")",
"string",
"{",
"switch",
"res",
".",
"Origin",
"{",
"case",
"resource",
".",
"OriginUpload",
":",
"if",
"res",
".",
"IsPlaceholder",
"(",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"res",
".",
"TimestampGranular",
"(",
")",
".",
"UTC",
"(",
")",
".",
"String",
"(",
")",
"\n",
"case",
"resource",
".",
"OriginStore",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"res",
".",
"Revision",
")",
"\n",
"default",
":",
"// note: this should probably never happen.",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
] | // RevisionString returns the human-readable revision for the resource. | [
"RevisionString",
"returns",
"the",
"human",
"-",
"readable",
"revision",
"for",
"the",
"resource",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/resource.go#L106-L119 |
4,848 | juju/juju | resource/resource.go | AsMap | func AsMap(resources []Resource) map[string]Resource {
results := make(map[string]Resource, len(resources))
for _, res := range resources {
results[res.Name] = res
}
return results
} | go | func AsMap(resources []Resource) map[string]Resource {
results := make(map[string]Resource, len(resources))
for _, res := range resources {
results[res.Name] = res
}
return results
} | [
"func",
"AsMap",
"(",
"resources",
"[",
"]",
"Resource",
")",
"map",
"[",
"string",
"]",
"Resource",
"{",
"results",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Resource",
",",
"len",
"(",
"resources",
")",
")",
"\n",
"for",
"_",
",",
"res",
":=",
"range",
"resources",
"{",
"results",
"[",
"res",
".",
"Name",
"]",
"=",
"res",
"\n",
"}",
"\n",
"return",
"results",
"\n",
"}"
] | // AsMap returns the mapping of resource name to info for each of the
// given resources. | [
"AsMap",
"returns",
"the",
"mapping",
"of",
"resource",
"name",
"to",
"info",
"for",
"each",
"of",
"the",
"given",
"resources",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/resource.go#L123-L129 |
4,849 | juju/juju | worker/metricworker/sender.go | newSender | func newSender(client metricsmanager.MetricsManagerClient, notify chan string) worker.Worker {
f := func(stopCh <-chan struct{}) error {
err := client.SendMetrics()
if err != nil {
senderLogger.Warningf("failed to send metrics %v - will retry later", err)
return nil
}
select {
case notify <- "senderCalled":
default:
}
return nil
}
return jworker.NewPeriodicWorker(f, senderPeriod, jworker.NewTimer)
} | go | func newSender(client metricsmanager.MetricsManagerClient, notify chan string) worker.Worker {
f := func(stopCh <-chan struct{}) error {
err := client.SendMetrics()
if err != nil {
senderLogger.Warningf("failed to send metrics %v - will retry later", err)
return nil
}
select {
case notify <- "senderCalled":
default:
}
return nil
}
return jworker.NewPeriodicWorker(f, senderPeriod, jworker.NewTimer)
} | [
"func",
"newSender",
"(",
"client",
"metricsmanager",
".",
"MetricsManagerClient",
",",
"notify",
"chan",
"string",
")",
"worker",
".",
"Worker",
"{",
"f",
":=",
"func",
"(",
"stopCh",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"err",
":=",
"client",
".",
"SendMetrics",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"senderLogger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"select",
"{",
"case",
"notify",
"<-",
"\"",
"\"",
":",
"default",
":",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"jworker",
".",
"NewPeriodicWorker",
"(",
"f",
",",
"senderPeriod",
",",
"jworker",
".",
"NewTimer",
")",
"\n",
"}"
] | // NewSender creates a new periodic worker that sends metrics
// to a collection service. | [
"NewSender",
"creates",
"a",
"new",
"periodic",
"worker",
"that",
"sends",
"metrics",
"to",
"a",
"collection",
"service",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/metricworker/sender.go#L22-L36 |
4,850 | juju/juju | cmd/output/output.go | TabWriter | func TabWriter(writer io.Writer) *ansiterm.TabWriter {
const (
// To format things into columns.
minwidth = 0
tabwidth = 1
padding = 2
padchar = ' '
flags = 0
)
return ansiterm.NewTabWriter(writer, minwidth, tabwidth, padding, padchar, flags)
} | go | func TabWriter(writer io.Writer) *ansiterm.TabWriter {
const (
// To format things into columns.
minwidth = 0
tabwidth = 1
padding = 2
padchar = ' '
flags = 0
)
return ansiterm.NewTabWriter(writer, minwidth, tabwidth, padding, padchar, flags)
} | [
"func",
"TabWriter",
"(",
"writer",
"io",
".",
"Writer",
")",
"*",
"ansiterm",
".",
"TabWriter",
"{",
"const",
"(",
"// To format things into columns.",
"minwidth",
"=",
"0",
"\n",
"tabwidth",
"=",
"1",
"\n",
"padding",
"=",
"2",
"\n",
"padchar",
"=",
"' '",
"\n",
"flags",
"=",
"0",
"\n",
")",
"\n",
"return",
"ansiterm",
".",
"NewTabWriter",
"(",
"writer",
",",
"minwidth",
",",
"tabwidth",
",",
"padding",
",",
"padchar",
",",
"flags",
")",
"\n",
"}"
] | // TabWriter returns a new tab writer with common layout definition. | [
"TabWriter",
"returns",
"a",
"new",
"tab",
"writer",
"with",
"common",
"layout",
"definition",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/output/output.go#L24-L34 |
4,851 | juju/juju | cmd/output/output.go | Print | func (w *Wrapper) Print(values ...interface{}) {
for _, v := range values {
fmt.Fprintf(w, "%v\t", v)
}
} | go | func (w *Wrapper) Print(values ...interface{}) {
for _, v := range values {
fmt.Fprintf(w, "%v\t", v)
}
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"Print",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}"
] | // Print writes each value followed by a tab. | [
"Print",
"writes",
"each",
"value",
"followed",
"by",
"a",
"tab",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/output/output.go#L42-L46 |
4,852 | juju/juju | cmd/output/output.go | Printf | func (w *Wrapper) Printf(format string, values ...interface{}) {
fmt.Fprintf(w, format+"\t", values...)
} | go | func (w *Wrapper) Printf(format string, values ...interface{}) {
fmt.Fprintf(w, format+"\t", values...)
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"Printf",
"(",
"format",
"string",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"format",
"+",
"\"",
"\\t",
"\"",
",",
"values",
"...",
")",
"\n",
"}"
] | // Printf writes the formatted text followed by a tab. | [
"Printf",
"writes",
"the",
"formatted",
"text",
"followed",
"by",
"a",
"tab",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/output/output.go#L49-L51 |
4,853 | juju/juju | cmd/output/output.go | Println | func (w *Wrapper) Println(values ...interface{}) {
for i, v := range values {
if i != len(values)-1 {
fmt.Fprintf(w, "%v\t", v)
} else {
fmt.Fprintf(w, "%v", v)
}
}
fmt.Fprintln(w)
} | go | func (w *Wrapper) Println(values ...interface{}) {
for i, v := range values {
if i != len(values)-1 {
fmt.Fprintf(w, "%v\t", v)
} else {
fmt.Fprintf(w, "%v", v)
}
}
fmt.Fprintln(w)
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"Println",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"values",
"{",
"if",
"i",
"!=",
"len",
"(",
"values",
")",
"-",
"1",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\"",
",",
"v",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
")",
"\n",
"}"
] | // Println writes many tab separated values finished with a new line. | [
"Println",
"writes",
"many",
"tab",
"separated",
"values",
"finished",
"with",
"a",
"new",
"line",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/output/output.go#L54-L63 |
4,854 | juju/juju | cmd/output/output.go | PrintColor | func (w *Wrapper) PrintColor(ctx *ansiterm.Context, value interface{}) {
if ctx != nil {
ctx.Fprintf(w.TabWriter, "%v\t", value)
} else {
fmt.Fprintf(w, "%v\t", value)
}
} | go | func (w *Wrapper) PrintColor(ctx *ansiterm.Context, value interface{}) {
if ctx != nil {
ctx.Fprintf(w.TabWriter, "%v\t", value)
} else {
fmt.Fprintf(w, "%v\t", value)
}
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"PrintColor",
"(",
"ctx",
"*",
"ansiterm",
".",
"Context",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"ctx",
"!=",
"nil",
"{",
"ctx",
".",
"Fprintf",
"(",
"w",
".",
"TabWriter",
",",
"\"",
"\\t",
"\"",
",",
"value",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\"",
",",
"value",
")",
"\n",
"}",
"\n",
"}"
] | // PrintColor writes the value out in the color context specified. | [
"PrintColor",
"writes",
"the",
"value",
"out",
"in",
"the",
"color",
"context",
"specified",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/output/output.go#L66-L72 |
4,855 | juju/juju | cmd/output/output.go | PrintStatus | func (w *Wrapper) PrintStatus(status status.Status) {
w.PrintColor(statusColors[status], status)
} | go | func (w *Wrapper) PrintStatus(status status.Status) {
w.PrintColor(statusColors[status], status)
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"PrintStatus",
"(",
"status",
"status",
".",
"Status",
")",
"{",
"w",
".",
"PrintColor",
"(",
"statusColors",
"[",
"status",
"]",
",",
"status",
")",
"\n",
"}"
] | // PrintStatus writes out the status value in the standard color. | [
"PrintStatus",
"writes",
"out",
"the",
"status",
"value",
"in",
"the",
"standard",
"color",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/output/output.go#L75-L77 |
4,856 | juju/juju | cmd/juju/commands/debughooks.go | Run | func (c *debugHooksCommand) Run(ctx *cmd.Context) error {
err := c.initRun()
if err != nil {
return err
}
defer c.cleanupRun()
err = c.validateHooksOrActions()
if err != nil {
return err
}
debugctx := unitdebug.NewHooksContext(c.Target)
script := base64.StdEncoding.EncodeToString([]byte(unitdebug.ClientScript(debugctx, c.hooks)))
innercmd := fmt.Sprintf(`F=$(mktemp); echo %s | base64 -d > $F; . $F`, script)
args := []string{fmt.Sprintf("sudo /bin/bash -c '%s'", innercmd)}
c.Args = args
return c.sshCommand.Run(ctx)
} | go | func (c *debugHooksCommand) Run(ctx *cmd.Context) error {
err := c.initRun()
if err != nil {
return err
}
defer c.cleanupRun()
err = c.validateHooksOrActions()
if err != nil {
return err
}
debugctx := unitdebug.NewHooksContext(c.Target)
script := base64.StdEncoding.EncodeToString([]byte(unitdebug.ClientScript(debugctx, c.hooks)))
innercmd := fmt.Sprintf(`F=$(mktemp); echo %s | base64 -d > $F; . $F`, script)
args := []string{fmt.Sprintf("sudo /bin/bash -c '%s'", innercmd)}
c.Args = args
return c.sshCommand.Run(ctx)
} | [
"func",
"(",
"c",
"*",
"debugHooksCommand",
")",
"Run",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"error",
"{",
"err",
":=",
"c",
".",
"initRun",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"c",
".",
"cleanupRun",
"(",
")",
"\n",
"err",
"=",
"c",
".",
"validateHooksOrActions",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"debugctx",
":=",
"unitdebug",
".",
"NewHooksContext",
"(",
"c",
".",
"Target",
")",
"\n",
"script",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"[",
"]",
"byte",
"(",
"unitdebug",
".",
"ClientScript",
"(",
"debugctx",
",",
"c",
".",
"hooks",
")",
")",
")",
"\n",
"innercmd",
":=",
"fmt",
".",
"Sprintf",
"(",
"`F=$(mktemp); echo %s | base64 -d > $F; . $F`",
",",
"script",
")",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"innercmd",
")",
"}",
"\n",
"c",
".",
"Args",
"=",
"args",
"\n",
"return",
"c",
".",
"sshCommand",
".",
"Run",
"(",
"ctx",
")",
"\n",
"}"
] | // Run ensures c.Target is a unit, and resolves its address,
// and connects to it via SSH to execute the debug-hooks
// script. | [
"Run",
"ensures",
"c",
".",
"Target",
"is",
"a",
"unit",
"and",
"resolves",
"its",
"address",
"and",
"connects",
"to",
"it",
"via",
"SSH",
"to",
"execute",
"the",
"debug",
"-",
"hooks",
"script",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/debughooks.go#L183-L199 |
4,857 | juju/juju | apiserver/common/modeldestroy.go | DestroyController | func DestroyController(
st ModelManagerBackend,
destroyHostedModels bool,
destroyStorage *bool,
) error {
modelTag := st.ModelTag()
controllerModelTag := st.ControllerModelTag()
if modelTag != controllerModelTag {
return errors.Errorf(
"expected state for controller model UUID %v, got %v",
controllerModelTag.Id(),
modelTag.Id(),
)
}
if destroyHostedModels {
uuids, err := st.AllModelUUIDs()
if err != nil {
return errors.Trace(err)
}
for _, uuid := range uuids {
modelSt, release, err := st.GetBackend(uuid)
if err != nil {
if errors.IsNotFound(err) {
// Model is already in the process of being destroyed.
continue
}
return errors.Trace(err)
}
defer release()
check := NewBlockChecker(modelSt)
if err = check.DestroyAllowed(); err != nil {
return errors.Trace(err)
}
err = sendMetrics(modelSt)
if err != nil {
logger.Errorf("failed to send leftover metrics: %v", err)
}
}
}
return destroyModel(st, state.DestroyModelParams{
DestroyHostedModels: destroyHostedModels,
DestroyStorage: destroyStorage,
})
} | go | func DestroyController(
st ModelManagerBackend,
destroyHostedModels bool,
destroyStorage *bool,
) error {
modelTag := st.ModelTag()
controllerModelTag := st.ControllerModelTag()
if modelTag != controllerModelTag {
return errors.Errorf(
"expected state for controller model UUID %v, got %v",
controllerModelTag.Id(),
modelTag.Id(),
)
}
if destroyHostedModels {
uuids, err := st.AllModelUUIDs()
if err != nil {
return errors.Trace(err)
}
for _, uuid := range uuids {
modelSt, release, err := st.GetBackend(uuid)
if err != nil {
if errors.IsNotFound(err) {
// Model is already in the process of being destroyed.
continue
}
return errors.Trace(err)
}
defer release()
check := NewBlockChecker(modelSt)
if err = check.DestroyAllowed(); err != nil {
return errors.Trace(err)
}
err = sendMetrics(modelSt)
if err != nil {
logger.Errorf("failed to send leftover metrics: %v", err)
}
}
}
return destroyModel(st, state.DestroyModelParams{
DestroyHostedModels: destroyHostedModels,
DestroyStorage: destroyStorage,
})
} | [
"func",
"DestroyController",
"(",
"st",
"ModelManagerBackend",
",",
"destroyHostedModels",
"bool",
",",
"destroyStorage",
"*",
"bool",
",",
")",
"error",
"{",
"modelTag",
":=",
"st",
".",
"ModelTag",
"(",
")",
"\n",
"controllerModelTag",
":=",
"st",
".",
"ControllerModelTag",
"(",
")",
"\n",
"if",
"modelTag",
"!=",
"controllerModelTag",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"controllerModelTag",
".",
"Id",
"(",
")",
",",
"modelTag",
".",
"Id",
"(",
")",
",",
")",
"\n",
"}",
"\n",
"if",
"destroyHostedModels",
"{",
"uuids",
",",
"err",
":=",
"st",
".",
"AllModelUUIDs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"uuid",
":=",
"range",
"uuids",
"{",
"modelSt",
",",
"release",
",",
"err",
":=",
"st",
".",
"GetBackend",
"(",
"uuid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"// Model is already in the process of being destroyed.",
"continue",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"release",
"(",
")",
"\n\n",
"check",
":=",
"NewBlockChecker",
"(",
"modelSt",
")",
"\n",
"if",
"err",
"=",
"check",
".",
"DestroyAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"sendMetrics",
"(",
"modelSt",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"destroyModel",
"(",
"st",
",",
"state",
".",
"DestroyModelParams",
"{",
"DestroyHostedModels",
":",
"destroyHostedModels",
",",
"DestroyStorage",
":",
"destroyStorage",
",",
"}",
")",
"\n",
"}"
] | // DestroyController sets the controller model to Dying and, if requested,
// schedules cleanups so that all of the hosted models are destroyed, or
// otherwise returns an error indicating that there are hosted models
// remaining. | [
"DestroyController",
"sets",
"the",
"controller",
"model",
"to",
"Dying",
"and",
"if",
"requested",
"schedules",
"cleanups",
"so",
"that",
"all",
"of",
"the",
"hosted",
"models",
"are",
"destroyed",
"or",
"otherwise",
"returns",
"an",
"error",
"indicating",
"that",
"there",
"are",
"hosted",
"models",
"remaining",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/modeldestroy.go#L41-L85 |
4,858 | juju/juju | apiserver/common/modeldestroy.go | DestroyModel | func DestroyModel(
st ModelManagerBackend,
destroyStorage *bool,
force *bool,
maxWait *time.Duration,
) error {
return destroyModel(st, state.DestroyModelParams{
DestroyStorage: destroyStorage,
Force: force,
MaxWait: MaxWait(maxWait),
})
} | go | func DestroyModel(
st ModelManagerBackend,
destroyStorage *bool,
force *bool,
maxWait *time.Duration,
) error {
return destroyModel(st, state.DestroyModelParams{
DestroyStorage: destroyStorage,
Force: force,
MaxWait: MaxWait(maxWait),
})
} | [
"func",
"DestroyModel",
"(",
"st",
"ModelManagerBackend",
",",
"destroyStorage",
"*",
"bool",
",",
"force",
"*",
"bool",
",",
"maxWait",
"*",
"time",
".",
"Duration",
",",
")",
"error",
"{",
"return",
"destroyModel",
"(",
"st",
",",
"state",
".",
"DestroyModelParams",
"{",
"DestroyStorage",
":",
"destroyStorage",
",",
"Force",
":",
"force",
",",
"MaxWait",
":",
"MaxWait",
"(",
"maxWait",
")",
",",
"}",
")",
"\n",
"}"
] | // DestroyModel sets the model to Dying, such that the model's resources will
// be destroyed and the model removed from the controller. | [
"DestroyModel",
"sets",
"the",
"model",
"to",
"Dying",
"such",
"that",
"the",
"model",
"s",
"resources",
"will",
"be",
"destroyed",
"and",
"the",
"model",
"removed",
"from",
"the",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/modeldestroy.go#L89-L100 |
4,859 | juju/juju | cmd/jujud/agent/model/manifolds.go | CAASManifolds | func CAASManifolds(config ManifoldsConfig) dependency.Manifolds {
agentConfig := config.Agent.CurrentConfig()
modelTag := agentConfig.Model()
manifolds := dependency.Manifolds{
// The undertaker is currently the only ifNotAlive worker.
undertakerName: ifNotUpgrading(ifNotAlive(ifCredentialValid(undertaker.Manifold(undertaker.ManifoldConfig{
APICallerName: apiCallerName,
CloudDestroyerName: caasBrokerTrackerName,
NewFacade: undertaker.NewFacade,
NewWorker: undertaker.NewWorker,
NewCredentialValidatorFacade: common.NewCredentialInvalidatorFacade,
})))),
caasBrokerTrackerName: ifResponsible(caasbroker.Manifold(caasbroker.ManifoldConfig{
APICallerName: apiCallerName,
NewContainerBrokerFunc: config.NewContainerBrokerFunc,
})),
caasFirewallerName: ifNotMigrating(caasfirewaller.Manifold(
caasfirewaller.ManifoldConfig{
APICallerName: apiCallerName,
BrokerName: caasBrokerTrackerName,
ControllerUUID: agentConfig.Controller().Id(),
ModelUUID: agentConfig.Model().Id(),
NewClient: func(caller base.APICaller) caasfirewaller.Client {
return caasfirewallerapi.NewClient(caller)
},
NewWorker: caasfirewaller.NewWorker,
},
)),
caasOperatorProvisionerName: ifNotMigrating(caasoperatorprovisioner.Manifold(
caasoperatorprovisioner.ManifoldConfig{
AgentName: agentName,
APICallerName: apiCallerName,
BrokerName: caasBrokerTrackerName,
ClockName: clockName,
NewWorker: caasoperatorprovisioner.NewProvisionerWorker,
},
)),
caasUnitProvisionerName: ifNotMigrating(caasunitprovisioner.Manifold(
caasunitprovisioner.ManifoldConfig{
APICallerName: apiCallerName,
BrokerName: caasBrokerTrackerName,
NewClient: func(caller base.APICaller) caasunitprovisioner.Client {
return caasunitprovisionerapi.NewClient(caller)
},
NewWorker: caasunitprovisioner.NewWorker,
},
)),
environUpgraderName: caasenvironupgrader.Manifold(caasenvironupgrader.ManifoldConfig{
APICallerName: apiCallerName,
GateName: environUpgradeGateName,
ModelTag: modelTag,
NewFacade: caasenvironupgrader.NewFacade,
NewWorker: caasenvironupgrader.NewWorker,
}),
caasStorageProvisionerName: ifNotMigrating(ifCredentialValid(storageprovisioner.ModelManifold(storageprovisioner.ModelManifoldConfig{
APICallerName: apiCallerName,
ClockName: clockName,
StorageRegistryName: caasBrokerTrackerName,
Model: modelTag,
NewCredentialValidatorFacade: common.NewCredentialInvalidatorFacade,
NewWorker: storageprovisioner.NewCaasWorker,
}))),
}
result := commonManifolds(config)
for name, manifold := range manifolds {
result[name] = manifold
}
return result
} | go | func CAASManifolds(config ManifoldsConfig) dependency.Manifolds {
agentConfig := config.Agent.CurrentConfig()
modelTag := agentConfig.Model()
manifolds := dependency.Manifolds{
// The undertaker is currently the only ifNotAlive worker.
undertakerName: ifNotUpgrading(ifNotAlive(ifCredentialValid(undertaker.Manifold(undertaker.ManifoldConfig{
APICallerName: apiCallerName,
CloudDestroyerName: caasBrokerTrackerName,
NewFacade: undertaker.NewFacade,
NewWorker: undertaker.NewWorker,
NewCredentialValidatorFacade: common.NewCredentialInvalidatorFacade,
})))),
caasBrokerTrackerName: ifResponsible(caasbroker.Manifold(caasbroker.ManifoldConfig{
APICallerName: apiCallerName,
NewContainerBrokerFunc: config.NewContainerBrokerFunc,
})),
caasFirewallerName: ifNotMigrating(caasfirewaller.Manifold(
caasfirewaller.ManifoldConfig{
APICallerName: apiCallerName,
BrokerName: caasBrokerTrackerName,
ControllerUUID: agentConfig.Controller().Id(),
ModelUUID: agentConfig.Model().Id(),
NewClient: func(caller base.APICaller) caasfirewaller.Client {
return caasfirewallerapi.NewClient(caller)
},
NewWorker: caasfirewaller.NewWorker,
},
)),
caasOperatorProvisionerName: ifNotMigrating(caasoperatorprovisioner.Manifold(
caasoperatorprovisioner.ManifoldConfig{
AgentName: agentName,
APICallerName: apiCallerName,
BrokerName: caasBrokerTrackerName,
ClockName: clockName,
NewWorker: caasoperatorprovisioner.NewProvisionerWorker,
},
)),
caasUnitProvisionerName: ifNotMigrating(caasunitprovisioner.Manifold(
caasunitprovisioner.ManifoldConfig{
APICallerName: apiCallerName,
BrokerName: caasBrokerTrackerName,
NewClient: func(caller base.APICaller) caasunitprovisioner.Client {
return caasunitprovisionerapi.NewClient(caller)
},
NewWorker: caasunitprovisioner.NewWorker,
},
)),
environUpgraderName: caasenvironupgrader.Manifold(caasenvironupgrader.ManifoldConfig{
APICallerName: apiCallerName,
GateName: environUpgradeGateName,
ModelTag: modelTag,
NewFacade: caasenvironupgrader.NewFacade,
NewWorker: caasenvironupgrader.NewWorker,
}),
caasStorageProvisionerName: ifNotMigrating(ifCredentialValid(storageprovisioner.ModelManifold(storageprovisioner.ModelManifoldConfig{
APICallerName: apiCallerName,
ClockName: clockName,
StorageRegistryName: caasBrokerTrackerName,
Model: modelTag,
NewCredentialValidatorFacade: common.NewCredentialInvalidatorFacade,
NewWorker: storageprovisioner.NewCaasWorker,
}))),
}
result := commonManifolds(config)
for name, manifold := range manifolds {
result[name] = manifold
}
return result
} | [
"func",
"CAASManifolds",
"(",
"config",
"ManifoldsConfig",
")",
"dependency",
".",
"Manifolds",
"{",
"agentConfig",
":=",
"config",
".",
"Agent",
".",
"CurrentConfig",
"(",
")",
"\n",
"modelTag",
":=",
"agentConfig",
".",
"Model",
"(",
")",
"\n",
"manifolds",
":=",
"dependency",
".",
"Manifolds",
"{",
"// The undertaker is currently the only ifNotAlive worker.",
"undertakerName",
":",
"ifNotUpgrading",
"(",
"ifNotAlive",
"(",
"ifCredentialValid",
"(",
"undertaker",
".",
"Manifold",
"(",
"undertaker",
".",
"ManifoldConfig",
"{",
"APICallerName",
":",
"apiCallerName",
",",
"CloudDestroyerName",
":",
"caasBrokerTrackerName",
",",
"NewFacade",
":",
"undertaker",
".",
"NewFacade",
",",
"NewWorker",
":",
"undertaker",
".",
"NewWorker",
",",
"NewCredentialValidatorFacade",
":",
"common",
".",
"NewCredentialInvalidatorFacade",
",",
"}",
")",
")",
")",
")",
",",
"caasBrokerTrackerName",
":",
"ifResponsible",
"(",
"caasbroker",
".",
"Manifold",
"(",
"caasbroker",
".",
"ManifoldConfig",
"{",
"APICallerName",
":",
"apiCallerName",
",",
"NewContainerBrokerFunc",
":",
"config",
".",
"NewContainerBrokerFunc",
",",
"}",
")",
")",
",",
"caasFirewallerName",
":",
"ifNotMigrating",
"(",
"caasfirewaller",
".",
"Manifold",
"(",
"caasfirewaller",
".",
"ManifoldConfig",
"{",
"APICallerName",
":",
"apiCallerName",
",",
"BrokerName",
":",
"caasBrokerTrackerName",
",",
"ControllerUUID",
":",
"agentConfig",
".",
"Controller",
"(",
")",
".",
"Id",
"(",
")",
",",
"ModelUUID",
":",
"agentConfig",
".",
"Model",
"(",
")",
".",
"Id",
"(",
")",
",",
"NewClient",
":",
"func",
"(",
"caller",
"base",
".",
"APICaller",
")",
"caasfirewaller",
".",
"Client",
"{",
"return",
"caasfirewallerapi",
".",
"NewClient",
"(",
"caller",
")",
"\n",
"}",
",",
"NewWorker",
":",
"caasfirewaller",
".",
"NewWorker",
",",
"}",
",",
")",
")",
",",
"caasOperatorProvisionerName",
":",
"ifNotMigrating",
"(",
"caasoperatorprovisioner",
".",
"Manifold",
"(",
"caasoperatorprovisioner",
".",
"ManifoldConfig",
"{",
"AgentName",
":",
"agentName",
",",
"APICallerName",
":",
"apiCallerName",
",",
"BrokerName",
":",
"caasBrokerTrackerName",
",",
"ClockName",
":",
"clockName",
",",
"NewWorker",
":",
"caasoperatorprovisioner",
".",
"NewProvisionerWorker",
",",
"}",
",",
")",
")",
",",
"caasUnitProvisionerName",
":",
"ifNotMigrating",
"(",
"caasunitprovisioner",
".",
"Manifold",
"(",
"caasunitprovisioner",
".",
"ManifoldConfig",
"{",
"APICallerName",
":",
"apiCallerName",
",",
"BrokerName",
":",
"caasBrokerTrackerName",
",",
"NewClient",
":",
"func",
"(",
"caller",
"base",
".",
"APICaller",
")",
"caasunitprovisioner",
".",
"Client",
"{",
"return",
"caasunitprovisionerapi",
".",
"NewClient",
"(",
"caller",
")",
"\n",
"}",
",",
"NewWorker",
":",
"caasunitprovisioner",
".",
"NewWorker",
",",
"}",
",",
")",
")",
",",
"environUpgraderName",
":",
"caasenvironupgrader",
".",
"Manifold",
"(",
"caasenvironupgrader",
".",
"ManifoldConfig",
"{",
"APICallerName",
":",
"apiCallerName",
",",
"GateName",
":",
"environUpgradeGateName",
",",
"ModelTag",
":",
"modelTag",
",",
"NewFacade",
":",
"caasenvironupgrader",
".",
"NewFacade",
",",
"NewWorker",
":",
"caasenvironupgrader",
".",
"NewWorker",
",",
"}",
")",
",",
"caasStorageProvisionerName",
":",
"ifNotMigrating",
"(",
"ifCredentialValid",
"(",
"storageprovisioner",
".",
"ModelManifold",
"(",
"storageprovisioner",
".",
"ModelManifoldConfig",
"{",
"APICallerName",
":",
"apiCallerName",
",",
"ClockName",
":",
"clockName",
",",
"StorageRegistryName",
":",
"caasBrokerTrackerName",
",",
"Model",
":",
"modelTag",
",",
"NewCredentialValidatorFacade",
":",
"common",
".",
"NewCredentialInvalidatorFacade",
",",
"NewWorker",
":",
"storageprovisioner",
".",
"NewCaasWorker",
",",
"}",
")",
")",
")",
",",
"}",
"\n",
"result",
":=",
"commonManifolds",
"(",
"config",
")",
"\n",
"for",
"name",
",",
"manifold",
":=",
"range",
"manifolds",
"{",
"result",
"[",
"name",
"]",
"=",
"manifold",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // CAASManifolds returns a set of interdependent dependency manifolds that will
// run together to administer a CAAS model, as configured. | [
"CAASManifolds",
"returns",
"a",
"set",
"of",
"interdependent",
"dependency",
"manifolds",
"that",
"will",
"run",
"together",
"to",
"administer",
"a",
"CAAS",
"model",
"as",
"configured",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/model/manifolds.go#L417-L487 |
4,860 | juju/juju | worker/raft/raftclusterer/worker.go | NewWorker | func NewWorker(config Config) (worker.Worker, error) {
if err := config.Validate(); err != nil {
return nil, errors.Trace(err)
}
w := &Worker{
config: config,
serverDetails: make(chan apiserver.Details),
}
// Subscribe to API server address changes.
unsubscribe, err := config.Hub.Subscribe(
apiserver.DetailsTopic,
w.apiserverDetailsChanged,
)
if err != nil {
return nil, errors.Annotate(err, "subscribing to apiserver details")
}
// Now that we're subscribed, request the current API server details.
req := apiserver.DetailsRequest{
Requester: "raft-clusterer",
LocalOnly: true,
}
if _, err := config.Hub.Publish(apiserver.DetailsRequestTopic, req); err != nil {
return nil, errors.Annotate(err, "requesting current apiserver details")
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &w.catacomb,
Work: func() error {
defer unsubscribe()
return w.loop()
},
}); err != nil {
unsubscribe()
return nil, errors.Trace(err)
}
return w, nil
} | go | func NewWorker(config Config) (worker.Worker, error) {
if err := config.Validate(); err != nil {
return nil, errors.Trace(err)
}
w := &Worker{
config: config,
serverDetails: make(chan apiserver.Details),
}
// Subscribe to API server address changes.
unsubscribe, err := config.Hub.Subscribe(
apiserver.DetailsTopic,
w.apiserverDetailsChanged,
)
if err != nil {
return nil, errors.Annotate(err, "subscribing to apiserver details")
}
// Now that we're subscribed, request the current API server details.
req := apiserver.DetailsRequest{
Requester: "raft-clusterer",
LocalOnly: true,
}
if _, err := config.Hub.Publish(apiserver.DetailsRequestTopic, req); err != nil {
return nil, errors.Annotate(err, "requesting current apiserver details")
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &w.catacomb,
Work: func() error {
defer unsubscribe()
return w.loop()
},
}); err != nil {
unsubscribe()
return nil, errors.Trace(err)
}
return w, nil
} | [
"func",
"NewWorker",
"(",
"config",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"w",
":=",
"&",
"Worker",
"{",
"config",
":",
"config",
",",
"serverDetails",
":",
"make",
"(",
"chan",
"apiserver",
".",
"Details",
")",
",",
"}",
"\n",
"// Subscribe to API server address changes.",
"unsubscribe",
",",
"err",
":=",
"config",
".",
"Hub",
".",
"Subscribe",
"(",
"apiserver",
".",
"DetailsTopic",
",",
"w",
".",
"apiserverDetailsChanged",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Now that we're subscribed, request the current API server details.",
"req",
":=",
"apiserver",
".",
"DetailsRequest",
"{",
"Requester",
":",
"\"",
"\"",
",",
"LocalOnly",
":",
"true",
",",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"config",
".",
"Hub",
".",
"Publish",
"(",
"apiserver",
".",
"DetailsRequestTopic",
",",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"catacomb",
".",
"Invoke",
"(",
"catacomb",
".",
"Plan",
"{",
"Site",
":",
"&",
"w",
".",
"catacomb",
",",
"Work",
":",
"func",
"(",
")",
"error",
"{",
"defer",
"unsubscribe",
"(",
")",
"\n",
"return",
"w",
".",
"loop",
"(",
")",
"\n",
"}",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"unsubscribe",
"(",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // NewWorker returns a new worker responsible for maintaining
// the raft cluster configuration. | [
"NewWorker",
"returns",
"a",
"new",
"worker",
"responsible",
"for",
"maintaining",
"the",
"raft",
"cluster",
"configuration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/raftclusterer/worker.go#L41-L77 |
4,861 | juju/juju | state/meterstatus.go | String | func (m MeterStatusCode) String() string {
s, ok := meterString[m]
if !ok {
return MeterNotAvailable.String()
}
return s
} | go | func (m MeterStatusCode) String() string {
s, ok := meterString[m]
if !ok {
return MeterNotAvailable.String()
}
return s
} | [
"func",
"(",
"m",
"MeterStatusCode",
")",
"String",
"(",
")",
"string",
"{",
"s",
",",
"ok",
":=",
"meterString",
"[",
"m",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"MeterNotAvailable",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // String returns a human readable string representation of the meter status. | [
"String",
"returns",
"a",
"human",
"readable",
"string",
"representation",
"of",
"the",
"meter",
"status",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/meterstatus.go#L35-L41 |
4,862 | juju/juju | state/meterstatus.go | MeterStatusFromString | func MeterStatusFromString(str string) MeterStatusCode {
for m, s := range meterString {
if s == str {
return m
}
}
return MeterNotAvailable
} | go | func MeterStatusFromString(str string) MeterStatusCode {
for m, s := range meterString {
if s == str {
return m
}
}
return MeterNotAvailable
} | [
"func",
"MeterStatusFromString",
"(",
"str",
"string",
")",
"MeterStatusCode",
"{",
"for",
"m",
",",
"s",
":=",
"range",
"meterString",
"{",
"if",
"s",
"==",
"str",
"{",
"return",
"m",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"MeterNotAvailable",
"\n",
"}"
] | // MeterStatusFromString returns a valid MeterStatusCode given a string representation. | [
"MeterStatusFromString",
"returns",
"a",
"valid",
"MeterStatusCode",
"given",
"a",
"string",
"representation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/meterstatus.go#L44-L51 |
4,863 | juju/juju | state/meterstatus.go | SetMeterStatus | func (u *Unit) SetMeterStatus(codeStr, info string) error {
code, err := isValidMeterStatusCode(codeStr)
if err != nil {
return errors.Trace(err)
}
meterDoc, err := u.getMeterStatusDoc()
if err != nil {
return errors.Annotatef(err, "cannot update meter status for unit %s", u.Name())
}
if meterDoc.Code == code.String() && meterDoc.Info == info {
return nil
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
err := u.Refresh()
if err != nil {
return nil, errors.Trace(err)
}
meterDoc, err = u.getMeterStatusDoc()
if err != nil {
return nil, errors.Annotatef(err, "cannot update meter status for unit %s", u.Name())
}
if meterDoc.Code == code.String() && meterDoc.Info == info {
return nil, jujutxn.ErrNoOperations
}
}
return []txn.Op{
{
C: unitsC,
Id: u.doc.DocID,
Assert: isAliveDoc,
}, {
C: meterStatusC,
Id: u.st.docID(u.globalMeterStatusKey()),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{{"code", code.String()}, {"info", info}}}},
}}, nil
}
return errors.Annotatef(u.st.db().Run(buildTxn), "cannot set meter state for unit %s", u.Name())
} | go | func (u *Unit) SetMeterStatus(codeStr, info string) error {
code, err := isValidMeterStatusCode(codeStr)
if err != nil {
return errors.Trace(err)
}
meterDoc, err := u.getMeterStatusDoc()
if err != nil {
return errors.Annotatef(err, "cannot update meter status for unit %s", u.Name())
}
if meterDoc.Code == code.String() && meterDoc.Info == info {
return nil
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
err := u.Refresh()
if err != nil {
return nil, errors.Trace(err)
}
meterDoc, err = u.getMeterStatusDoc()
if err != nil {
return nil, errors.Annotatef(err, "cannot update meter status for unit %s", u.Name())
}
if meterDoc.Code == code.String() && meterDoc.Info == info {
return nil, jujutxn.ErrNoOperations
}
}
return []txn.Op{
{
C: unitsC,
Id: u.doc.DocID,
Assert: isAliveDoc,
}, {
C: meterStatusC,
Id: u.st.docID(u.globalMeterStatusKey()),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{{"code", code.String()}, {"info", info}}}},
}}, nil
}
return errors.Annotatef(u.st.db().Run(buildTxn), "cannot set meter state for unit %s", u.Name())
} | [
"func",
"(",
"u",
"*",
"Unit",
")",
"SetMeterStatus",
"(",
"codeStr",
",",
"info",
"string",
")",
"error",
"{",
"code",
",",
"err",
":=",
"isValidMeterStatusCode",
"(",
"codeStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"meterDoc",
",",
"err",
":=",
"u",
".",
"getMeterStatusDoc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"meterDoc",
".",
"Code",
"==",
"code",
".",
"String",
"(",
")",
"&&",
"meterDoc",
".",
"Info",
"==",
"info",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"err",
":=",
"u",
".",
"Refresh",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"meterDoc",
",",
"err",
"=",
"u",
".",
"getMeterStatusDoc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"meterDoc",
".",
"Code",
"==",
"code",
".",
"String",
"(",
")",
"&&",
"meterDoc",
".",
"Info",
"==",
"info",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"unitsC",
",",
"Id",
":",
"u",
".",
"doc",
".",
"DocID",
",",
"Assert",
":",
"isAliveDoc",
",",
"}",
",",
"{",
"C",
":",
"meterStatusC",
",",
"Id",
":",
"u",
".",
"st",
".",
"docID",
"(",
"u",
".",
"globalMeterStatusKey",
"(",
")",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"code",
".",
"String",
"(",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"info",
"}",
"}",
"}",
"}",
",",
"}",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"u",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}"
] | // SetMeterStatus sets the meter status for the unit. | [
"SetMeterStatus",
"sets",
"the",
"meter",
"status",
"for",
"the",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/meterstatus.go#L90-L130 |
4,864 | juju/juju | state/meterstatus.go | createMeterStatusOp | func createMeterStatusOp(mb modelBackend, globalKey string, doc *meterStatusDoc) txn.Op {
doc.ModelUUID = mb.modelUUID()
return txn.Op{
C: meterStatusC,
Id: mb.docID(globalKey),
Assert: txn.DocMissing,
Insert: doc,
}
} | go | func createMeterStatusOp(mb modelBackend, globalKey string, doc *meterStatusDoc) txn.Op {
doc.ModelUUID = mb.modelUUID()
return txn.Op{
C: meterStatusC,
Id: mb.docID(globalKey),
Assert: txn.DocMissing,
Insert: doc,
}
} | [
"func",
"createMeterStatusOp",
"(",
"mb",
"modelBackend",
",",
"globalKey",
"string",
",",
"doc",
"*",
"meterStatusDoc",
")",
"txn",
".",
"Op",
"{",
"doc",
".",
"ModelUUID",
"=",
"mb",
".",
"modelUUID",
"(",
")",
"\n",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"meterStatusC",
",",
"Id",
":",
"mb",
".",
"docID",
"(",
"globalKey",
")",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"doc",
",",
"}",
"\n",
"}"
] | // createMeterStatusOp returns the operation needed to create the meter status
// document associated with the given globalKey. | [
"createMeterStatusOp",
"returns",
"the",
"operation",
"needed",
"to",
"create",
"the",
"meter",
"status",
"document",
"associated",
"with",
"the",
"given",
"globalKey",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/meterstatus.go#L134-L142 |
4,865 | juju/juju | state/meterstatus.go | removeMeterStatusOp | func removeMeterStatusOp(mb modelBackend, globalKey string) txn.Op {
return txn.Op{
C: meterStatusC,
Id: mb.docID(globalKey),
Remove: true,
}
} | go | func removeMeterStatusOp(mb modelBackend, globalKey string) txn.Op {
return txn.Op{
C: meterStatusC,
Id: mb.docID(globalKey),
Remove: true,
}
} | [
"func",
"removeMeterStatusOp",
"(",
"mb",
"modelBackend",
",",
"globalKey",
"string",
")",
"txn",
".",
"Op",
"{",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"meterStatusC",
",",
"Id",
":",
"mb",
".",
"docID",
"(",
"globalKey",
")",
",",
"Remove",
":",
"true",
",",
"}",
"\n",
"}"
] | // removeMeterStatusOp returns the operation needed to remove the meter status
// document associated with the given globalKey. | [
"removeMeterStatusOp",
"returns",
"the",
"operation",
"needed",
"to",
"remove",
"the",
"meter",
"status",
"document",
"associated",
"with",
"the",
"given",
"globalKey",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/meterstatus.go#L146-L152 |
4,866 | juju/juju | state/meterstatus.go | GetMeterStatus | func (u *Unit) GetMeterStatus() (MeterStatus, error) {
mm, err := u.st.MetricsManager()
if err != nil {
return MeterStatus{MeterNotAvailable, ""}, errors.Annotatef(err, "cannot retrieve meter status for metrics manager")
}
mmStatus := mm.MeterStatus()
if mmStatus.Code == MeterRed {
return mmStatus, nil
}
status, err := u.getMeterStatusDoc()
if err != nil {
return MeterStatus{MeterNotAvailable, ""}, errors.Annotatef(err, "cannot retrieve meter status for unit %s", u.Name())
}
code := MeterStatusFromString(status.Code)
unitMeterStatus := MeterStatus{code, status.Info}
return combineMeterStatus(mmStatus, unitMeterStatus), nil
} | go | func (u *Unit) GetMeterStatus() (MeterStatus, error) {
mm, err := u.st.MetricsManager()
if err != nil {
return MeterStatus{MeterNotAvailable, ""}, errors.Annotatef(err, "cannot retrieve meter status for metrics manager")
}
mmStatus := mm.MeterStatus()
if mmStatus.Code == MeterRed {
return mmStatus, nil
}
status, err := u.getMeterStatusDoc()
if err != nil {
return MeterStatus{MeterNotAvailable, ""}, errors.Annotatef(err, "cannot retrieve meter status for unit %s", u.Name())
}
code := MeterStatusFromString(status.Code)
unitMeterStatus := MeterStatus{code, status.Info}
return combineMeterStatus(mmStatus, unitMeterStatus), nil
} | [
"func",
"(",
"u",
"*",
"Unit",
")",
"GetMeterStatus",
"(",
")",
"(",
"MeterStatus",
",",
"error",
")",
"{",
"mm",
",",
"err",
":=",
"u",
".",
"st",
".",
"MetricsManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"MeterStatus",
"{",
"MeterNotAvailable",
",",
"\"",
"\"",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"mmStatus",
":=",
"mm",
".",
"MeterStatus",
"(",
")",
"\n",
"if",
"mmStatus",
".",
"Code",
"==",
"MeterRed",
"{",
"return",
"mmStatus",
",",
"nil",
"\n",
"}",
"\n\n",
"status",
",",
"err",
":=",
"u",
".",
"getMeterStatusDoc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"MeterStatus",
"{",
"MeterNotAvailable",
",",
"\"",
"\"",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n\n",
"code",
":=",
"MeterStatusFromString",
"(",
"status",
".",
"Code",
")",
"\n\n",
"unitMeterStatus",
":=",
"MeterStatus",
"{",
"code",
",",
"status",
".",
"Info",
"}",
"\n",
"return",
"combineMeterStatus",
"(",
"mmStatus",
",",
"unitMeterStatus",
")",
",",
"nil",
"\n",
"}"
] | // GetMeterStatus returns the meter status for the unit. | [
"GetMeterStatus",
"returns",
"the",
"meter",
"status",
"for",
"the",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/meterstatus.go#L155-L175 |
4,867 | juju/juju | downloader/downloader.go | Start | func (dlr Downloader) Start(req Request) *Download {
return StartDownload(req, dlr.OpenBlob)
} | go | func (dlr Downloader) Start(req Request) *Download {
return StartDownload(req, dlr.OpenBlob)
} | [
"func",
"(",
"dlr",
"Downloader",
")",
"Start",
"(",
"req",
"Request",
")",
"*",
"Download",
"{",
"return",
"StartDownload",
"(",
"req",
",",
"dlr",
".",
"OpenBlob",
")",
"\n",
"}"
] | // Start starts a new download and returns it. | [
"Start",
"starts",
"a",
"new",
"download",
"and",
"returns",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/downloader/downloader.go#L41-L43 |
4,868 | juju/juju | downloader/downloader.go | Download | func (dlr Downloader) Download(req Request) (string, error) {
if err := os.MkdirAll(req.TargetDir, 0755); err != nil {
return "", errors.Trace(err)
}
dl := dlr.Start(req)
filename, err := dl.Wait()
return filename, errors.Trace(err)
} | go | func (dlr Downloader) Download(req Request) (string, error) {
if err := os.MkdirAll(req.TargetDir, 0755); err != nil {
return "", errors.Trace(err)
}
dl := dlr.Start(req)
filename, err := dl.Wait()
return filename, errors.Trace(err)
} | [
"func",
"(",
"dlr",
"Downloader",
")",
"Download",
"(",
"req",
"Request",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"req",
".",
"TargetDir",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"dl",
":=",
"dlr",
".",
"Start",
"(",
"req",
")",
"\n",
"filename",
",",
"err",
":=",
"dl",
".",
"Wait",
"(",
")",
"\n",
"return",
"filename",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Download starts a new download, waits for it to complete, and
// returns the local name of the file. The download can be aborted by
// closing the Abort channel in the Request provided. | [
"Download",
"starts",
"a",
"new",
"download",
"waits",
"for",
"it",
"to",
"complete",
"and",
"returns",
"the",
"local",
"name",
"of",
"the",
"file",
".",
"The",
"download",
"can",
"be",
"aborted",
"by",
"closing",
"the",
"Abort",
"channel",
"in",
"the",
"Request",
"provided",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/downloader/downloader.go#L48-L55 |
4,869 | juju/juju | worker/containerbroker/mocks/machine_mock.go | NewMockMachineProvisioner | func NewMockMachineProvisioner(ctrl *gomock.Controller) *MockMachineProvisioner {
mock := &MockMachineProvisioner{ctrl: ctrl}
mock.recorder = &MockMachineProvisionerMockRecorder{mock}
return mock
} | go | func NewMockMachineProvisioner(ctrl *gomock.Controller) *MockMachineProvisioner {
mock := &MockMachineProvisioner{ctrl: ctrl}
mock.recorder = &MockMachineProvisionerMockRecorder{mock}
return mock
} | [
"func",
"NewMockMachineProvisioner",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockMachineProvisioner",
"{",
"mock",
":=",
"&",
"MockMachineProvisioner",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockMachineProvisionerMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockMachineProvisioner creates a new mock instance | [
"NewMockMachineProvisioner",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L30-L34 |
4,870 | juju/juju | worker/containerbroker/mocks/machine_mock.go | AvailabilityZone | func (m *MockMachineProvisioner) AvailabilityZone() (string, error) {
ret := m.ctrl.Call(m, "AvailabilityZone")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachineProvisioner) AvailabilityZone() (string, error) {
ret := m.ctrl.Call(m, "AvailabilityZone")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"AvailabilityZone",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // AvailabilityZone mocks base method | [
"AvailabilityZone",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L42-L47 |
4,871 | juju/juju | worker/containerbroker/mocks/machine_mock.go | InstanceStatus | func (m *MockMachineProvisioner) InstanceStatus() (status.Status, string, error) {
ret := m.ctrl.Call(m, "InstanceStatus")
ret0, _ := ret[0].(status.Status)
ret1, _ := ret[1].(string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | go | func (m *MockMachineProvisioner) InstanceStatus() (status.Status, string, error) {
ret := m.ctrl.Call(m, "InstanceStatus")
ret0, _ := ret[0].(status.Status)
ret1, _ := ret[1].(string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"InstanceStatus",
"(",
")",
"(",
"status",
".",
"Status",
",",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"status",
".",
"Status",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"string",
")",
"\n",
"ret2",
",",
"_",
":=",
"ret",
"[",
"2",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
",",
"ret2",
"\n",
"}"
] | // InstanceStatus mocks base method | [
"InstanceStatus",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L105-L111 |
4,872 | juju/juju | worker/containerbroker/mocks/machine_mock.go | KeepInstance | func (m *MockMachineProvisioner) KeepInstance() (bool, error) {
ret := m.ctrl.Call(m, "KeepInstance")
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachineProvisioner) KeepInstance() (bool, error) {
ret := m.ctrl.Call(m, "KeepInstance")
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"KeepInstance",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // KeepInstance mocks base method | [
"KeepInstance",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L119-L124 |
4,873 | juju/juju | worker/containerbroker/mocks/machine_mock.go | MachineTag | func (m *MockMachineProvisioner) MachineTag() names_v2.MachineTag {
ret := m.ctrl.Call(m, "MachineTag")
ret0, _ := ret[0].(names_v2.MachineTag)
return ret0
} | go | func (m *MockMachineProvisioner) MachineTag() names_v2.MachineTag {
ret := m.ctrl.Call(m, "MachineTag")
ret0, _ := ret[0].(names_v2.MachineTag)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"MachineTag",
"(",
")",
"names_v2",
".",
"MachineTag",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"names_v2",
".",
"MachineTag",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // MachineTag mocks base method | [
"MachineTag",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L144-L148 |
4,874 | juju/juju | worker/containerbroker/mocks/machine_mock.go | ModelAgentVersion | func (m *MockMachineProvisioner) ModelAgentVersion() (*version.Number, error) {
ret := m.ctrl.Call(m, "ModelAgentVersion")
ret0, _ := ret[0].(*version.Number)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachineProvisioner) ModelAgentVersion() (*version.Number, error) {
ret := m.ctrl.Call(m, "ModelAgentVersion")
ret0, _ := ret[0].(*version.Number)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"ModelAgentVersion",
"(",
")",
"(",
"*",
"version",
".",
"Number",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"version",
".",
"Number",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ModelAgentVersion mocks base method | [
"ModelAgentVersion",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L168-L173 |
4,875 | juju/juju | worker/containerbroker/mocks/machine_mock.go | ProvisioningInfo | func (m *MockMachineProvisioner) ProvisioningInfo() (*params.ProvisioningInfo, error) {
ret := m.ctrl.Call(m, "ProvisioningInfo")
ret0, _ := ret[0].(*params.ProvisioningInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachineProvisioner) ProvisioningInfo() (*params.ProvisioningInfo, error) {
ret := m.ctrl.Call(m, "ProvisioningInfo")
ret0, _ := ret[0].(*params.ProvisioningInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"ProvisioningInfo",
"(",
")",
"(",
"*",
"params",
".",
"ProvisioningInfo",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"params",
".",
"ProvisioningInfo",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ProvisioningInfo mocks base method | [
"ProvisioningInfo",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L181-L186 |
4,876 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetCharmProfiles | func (m *MockMachineProvisioner) SetCharmProfiles(arg0 []string) error {
ret := m.ctrl.Call(m, "SetCharmProfiles", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachineProvisioner) SetCharmProfiles(arg0 []string) error {
ret := m.ctrl.Call(m, "SetCharmProfiles", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"SetCharmProfiles",
"(",
"arg0",
"[",
"]",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetCharmProfiles mocks base method | [
"SetCharmProfiles",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L218-L222 |
4,877 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetInstanceInfo | func (m *MockMachineProvisioner) SetInstanceInfo(arg0 instance.Id, arg1, arg2 string, arg3 *instance.HardwareCharacteristics, arg4 []params.NetworkConfig, arg5 []params.Volume, arg6 map[string]params.VolumeAttachmentInfo, arg7 []string) error {
ret := m.ctrl.Call(m, "SetInstanceInfo", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachineProvisioner) SetInstanceInfo(arg0 instance.Id, arg1, arg2 string, arg3 *instance.HardwareCharacteristics, arg4 []params.NetworkConfig, arg5 []params.Volume, arg6 map[string]params.VolumeAttachmentInfo, arg7 []string) error {
ret := m.ctrl.Call(m, "SetInstanceInfo", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"SetInstanceInfo",
"(",
"arg0",
"instance",
".",
"Id",
",",
"arg1",
",",
"arg2",
"string",
",",
"arg3",
"*",
"instance",
".",
"HardwareCharacteristics",
",",
"arg4",
"[",
"]",
"params",
".",
"NetworkConfig",
",",
"arg5",
"[",
"]",
"params",
".",
"Volume",
",",
"arg6",
"map",
"[",
"string",
"]",
"params",
".",
"VolumeAttachmentInfo",
",",
"arg7",
"[",
"]",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
",",
"arg5",
",",
"arg6",
",",
"arg7",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetInstanceInfo mocks base method | [
"SetInstanceInfo",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L230-L234 |
4,878 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetInstanceInfo | func (mr *MockMachineProvisionerMockRecorder) SetInstanceInfo(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInstanceInfo", reflect.TypeOf((*MockMachineProvisioner)(nil).SetInstanceInfo), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
} | go | func (mr *MockMachineProvisionerMockRecorder) SetInstanceInfo(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInstanceInfo", reflect.TypeOf((*MockMachineProvisioner)(nil).SetInstanceInfo), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
} | [
"func",
"(",
"mr",
"*",
"MockMachineProvisionerMockRecorder",
")",
"SetInstanceInfo",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
",",
"arg5",
",",
"arg6",
",",
"arg7",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMachineProvisioner",
")",
"(",
"nil",
")",
".",
"SetInstanceInfo",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
",",
"arg5",
",",
"arg6",
",",
"arg7",
")",
"\n",
"}"
] | // SetInstanceInfo indicates an expected call of SetInstanceInfo | [
"SetInstanceInfo",
"indicates",
"an",
"expected",
"call",
"of",
"SetInstanceInfo"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L237-L239 |
4,879 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetStatus | func (m *MockMachineProvisioner) SetStatus(arg0 status.Status, arg1 string, arg2 map[string]interface{}) error {
ret := m.ctrl.Call(m, "SetStatus", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachineProvisioner) SetStatus(arg0 status.Status, arg1 string, arg2 map[string]interface{}) error {
ret := m.ctrl.Call(m, "SetStatus", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"SetStatus",
"(",
"arg0",
"status",
".",
"Status",
",",
"arg1",
"string",
",",
"arg2",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetStatus mocks base method | [
"SetStatus",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L278-L282 |
4,880 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetStatus | func (mr *MockMachineProvisionerMockRecorder) SetStatus(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatus", reflect.TypeOf((*MockMachineProvisioner)(nil).SetStatus), arg0, arg1, arg2)
} | go | func (mr *MockMachineProvisionerMockRecorder) SetStatus(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatus", reflect.TypeOf((*MockMachineProvisioner)(nil).SetStatus), arg0, arg1, arg2)
} | [
"func",
"(",
"mr",
"*",
"MockMachineProvisionerMockRecorder",
")",
"SetStatus",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMachineProvisioner",
")",
"(",
"nil",
")",
".",
"SetStatus",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"}"
] | // SetStatus indicates an expected call of SetStatus | [
"SetStatus",
"indicates",
"an",
"expected",
"call",
"of",
"SetStatus"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L285-L287 |
4,881 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetSupportedContainers | func (m *MockMachineProvisioner) SetSupportedContainers(arg0 ...instance.ContainerType) error {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetSupportedContainers", varargs...)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockMachineProvisioner) SetSupportedContainers(arg0 ...instance.ContainerType) error {
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SetSupportedContainers", varargs...)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"SetSupportedContainers",
"(",
"arg0",
"...",
"instance",
".",
"ContainerType",
")",
"error",
"{",
"varargs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"arg0",
"{",
"varargs",
"=",
"append",
"(",
"varargs",
",",
"a",
")",
"\n",
"}",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"varargs",
"...",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetSupportedContainers mocks base method | [
"SetSupportedContainers",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L290-L298 |
4,882 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SetSupportedContainers | func (mr *MockMachineProvisionerMockRecorder) SetSupportedContainers(arg0 ...interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSupportedContainers", reflect.TypeOf((*MockMachineProvisioner)(nil).SetSupportedContainers), arg0...)
} | go | func (mr *MockMachineProvisionerMockRecorder) SetSupportedContainers(arg0 ...interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSupportedContainers", reflect.TypeOf((*MockMachineProvisioner)(nil).SetSupportedContainers), arg0...)
} | [
"func",
"(",
"mr",
"*",
"MockMachineProvisionerMockRecorder",
")",
"SetSupportedContainers",
"(",
"arg0",
"...",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMachineProvisioner",
")",
"(",
"nil",
")",
".",
"SetSupportedContainers",
")",
",",
"arg0",
"...",
")",
"\n",
"}"
] | // SetSupportedContainers indicates an expected call of SetSupportedContainers | [
"SetSupportedContainers",
"indicates",
"an",
"expected",
"call",
"of",
"SetSupportedContainers"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L301-L303 |
4,883 | juju/juju | worker/containerbroker/mocks/machine_mock.go | SupportedContainers | func (m *MockMachineProvisioner) SupportedContainers() ([]instance.ContainerType, bool, error) {
ret := m.ctrl.Call(m, "SupportedContainers")
ret0, _ := ret[0].([]instance.ContainerType)
ret1, _ := ret[1].(bool)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | go | func (m *MockMachineProvisioner) SupportedContainers() ([]instance.ContainerType, bool, error) {
ret := m.ctrl.Call(m, "SupportedContainers")
ret0, _ := ret[0].([]instance.ContainerType)
ret1, _ := ret[1].(bool)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"SupportedContainers",
"(",
")",
"(",
"[",
"]",
"instance",
".",
"ContainerType",
",",
"bool",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"instance",
".",
"ContainerType",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"bool",
")",
"\n",
"ret2",
",",
"_",
":=",
"ret",
"[",
"2",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
",",
"ret2",
"\n",
"}"
] | // SupportedContainers mocks base method | [
"SupportedContainers",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L332-L338 |
4,884 | juju/juju | worker/containerbroker/mocks/machine_mock.go | WatchAllContainers | func (m *MockMachineProvisioner) WatchAllContainers() (watcher.StringsWatcher, error) {
ret := m.ctrl.Call(m, "WatchAllContainers")
ret0, _ := ret[0].(watcher.StringsWatcher)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockMachineProvisioner) WatchAllContainers() (watcher.StringsWatcher, error) {
ret := m.ctrl.Call(m, "WatchAllContainers")
ret0, _ := ret[0].(watcher.StringsWatcher)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockMachineProvisioner",
")",
"WatchAllContainers",
"(",
")",
"(",
"watcher",
".",
"StringsWatcher",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"watcher",
".",
"StringsWatcher",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // WatchAllContainers mocks base method | [
"WatchAllContainers",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L370-L375 |
4,885 | juju/juju | worker/containerbroker/mocks/machine_mock.go | WatchAllContainers | func (mr *MockMachineProvisionerMockRecorder) WatchAllContainers() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchAllContainers", reflect.TypeOf((*MockMachineProvisioner)(nil).WatchAllContainers))
} | go | func (mr *MockMachineProvisionerMockRecorder) WatchAllContainers() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchAllContainers", reflect.TypeOf((*MockMachineProvisioner)(nil).WatchAllContainers))
} | [
"func",
"(",
"mr",
"*",
"MockMachineProvisionerMockRecorder",
")",
"WatchAllContainers",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMachineProvisioner",
")",
"(",
"nil",
")",
".",
"WatchAllContainers",
")",
")",
"\n",
"}"
] | // WatchAllContainers indicates an expected call of WatchAllContainers | [
"WatchAllContainers",
"indicates",
"an",
"expected",
"call",
"of",
"WatchAllContainers"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_mock.go#L378-L380 |
4,886 | juju/juju | provider/azure/internal/azureauth/utils.go | TokenResource | func TokenResource(uri string) string {
resource := uri
if !strings.HasSuffix(resource, "/") {
resource += "/"
}
return resource
} | go | func TokenResource(uri string) string {
resource := uri
if !strings.HasSuffix(resource, "/") {
resource += "/"
}
return resource
} | [
"func",
"TokenResource",
"(",
"uri",
"string",
")",
"string",
"{",
"resource",
":=",
"uri",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"resource",
",",
"\"",
"\"",
")",
"{",
"resource",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"resource",
"\n",
"}"
] | // TokenResource returns a resource value suitable for auth tokens, based on
// an endpoint URI. | [
"TokenResource",
"returns",
"a",
"resource",
"value",
"suitable",
"for",
"auth",
"tokens",
"based",
"on",
"an",
"endpoint",
"URI",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azureauth/utils.go#L29-L35 |
4,887 | juju/juju | container/kvm/run.go | run | func run(dir, command string, args ...string) (string, error) {
logger.Debugf("(%s) %s %v", dir, command, args)
cmd := exec.Command(command, args...)
if dir != "" {
cmd.Dir = dir
}
out, err := cmd.CombinedOutput()
output := string(out)
logger.Debugf("output: %v", output)
return output, err
} | go | func run(dir, command string, args ...string) (string, error) {
logger.Debugf("(%s) %s %v", dir, command, args)
cmd := exec.Command(command, args...)
if dir != "" {
cmd.Dir = dir
}
out, err := cmd.CombinedOutput()
output := string(out)
logger.Debugf("output: %v", output)
return output, err
} | [
"func",
"run",
"(",
"dir",
",",
"command",
"string",
",",
"args",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"dir",
",",
"command",
",",
"args",
")",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
",",
"args",
"...",
")",
"\n",
"if",
"dir",
"!=",
"\"",
"\"",
"{",
"cmd",
".",
"Dir",
"=",
"dir",
"\n",
"}",
"\n\n",
"out",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"output",
":=",
"string",
"(",
"out",
")",
"\n\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"return",
"output",
",",
"err",
"\n",
"}"
] | // run the command and return the combined output. | [
"run",
"the",
"command",
"and",
"return",
"the",
"combined",
"output",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/kvm/run.go#L25-L38 |
4,888 | juju/juju | apiserver/facades/client/application/mocks/interface_mock.go | GetBundle | func (m *MockInterface) GetBundle(arg0 *charm_v6.URL) (charm_v6.Bundle, error) {
ret := m.ctrl.Call(m, "GetBundle", arg0)
ret0, _ := ret[0].(charm_v6.Bundle)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockInterface) GetBundle(arg0 *charm_v6.URL) (charm_v6.Bundle, error) {
ret := m.ctrl.Call(m, "GetBundle", arg0)
ret0, _ := ret[0].(charm_v6.Bundle)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockInterface",
")",
"GetBundle",
"(",
"arg0",
"*",
"charm_v6",
".",
"URL",
")",
"(",
"charm_v6",
".",
"Bundle",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"charm_v6",
".",
"Bundle",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // GetBundle mocks base method | [
"GetBundle",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/interface_mock.go#L50-L55 |
4,889 | juju/juju | cmd/juju/status/utils.go | stringKeysFromMap | func stringKeysFromMap(m interface{}) (keys []string) {
for _, k := range reflect.ValueOf(m).MapKeys() {
keys = append(keys, k.String())
}
return
} | go | func stringKeysFromMap(m interface{}) (keys []string) {
for _, k := range reflect.ValueOf(m).MapKeys() {
keys = append(keys, k.String())
}
return
} | [
"func",
"stringKeysFromMap",
"(",
"m",
"interface",
"{",
"}",
")",
"(",
"keys",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"k",
":=",
"range",
"reflect",
".",
"ValueOf",
"(",
"m",
")",
".",
"MapKeys",
"(",
")",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // stringKeysFromMap takes a map with keys which are strings and returns
// only the keys. | [
"stringKeysFromMap",
"takes",
"a",
"map",
"with",
"keys",
"which",
"are",
"strings",
"and",
"returns",
"only",
"the",
"keys",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/status/utils.go#L15-L20 |
4,890 | juju/juju | cmd/juju/status/utils.go | indent | func indent(prepend string, level int, append string) string {
return fmt.Sprintf("%s%*s%s", prepend, level, "", append)
} | go | func indent(prepend string, level int, append string) string {
return fmt.Sprintf("%s%*s%s", prepend, level, "", append)
} | [
"func",
"indent",
"(",
"prepend",
"string",
",",
"level",
"int",
",",
"append",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"prepend",
",",
"level",
",",
"\"",
"\"",
",",
"append",
")",
"\n",
"}"
] | // indent prepends a format string with the given number of spaces. | [
"indent",
"prepends",
"a",
"format",
"string",
"with",
"the",
"given",
"number",
"of",
"spaces",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/status/utils.go#L36-L38 |
4,891 | juju/juju | worker/raft/simplefsm.go | Logs | func (fsm *SimpleFSM) Logs() [][]byte {
fsm.mu.Lock()
defer fsm.mu.Unlock()
copied := make([][]byte, len(fsm.logs))
copy(copied, fsm.logs)
return copied
} | go | func (fsm *SimpleFSM) Logs() [][]byte {
fsm.mu.Lock()
defer fsm.mu.Unlock()
copied := make([][]byte, len(fsm.logs))
copy(copied, fsm.logs)
return copied
} | [
"func",
"(",
"fsm",
"*",
"SimpleFSM",
")",
"Logs",
"(",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"fsm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"fsm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"copied",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"len",
"(",
"fsm",
".",
"logs",
")",
")",
"\n",
"copy",
"(",
"copied",
",",
"fsm",
".",
"logs",
")",
"\n",
"return",
"copied",
"\n",
"}"
] | // Logs returns the accumulated log data. | [
"Logs",
"returns",
"the",
"accumulated",
"log",
"data",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/simplefsm.go#L22-L28 |
4,892 | juju/juju | worker/raft/simplefsm.go | Apply | func (fsm *SimpleFSM) Apply(log *raft.Log) interface{} {
fsm.mu.Lock()
defer fsm.mu.Unlock()
fsm.logs = append(fsm.logs, log.Data)
return len(fsm.logs)
} | go | func (fsm *SimpleFSM) Apply(log *raft.Log) interface{} {
fsm.mu.Lock()
defer fsm.mu.Unlock()
fsm.logs = append(fsm.logs, log.Data)
return len(fsm.logs)
} | [
"func",
"(",
"fsm",
"*",
"SimpleFSM",
")",
"Apply",
"(",
"log",
"*",
"raft",
".",
"Log",
")",
"interface",
"{",
"}",
"{",
"fsm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"fsm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"fsm",
".",
"logs",
"=",
"append",
"(",
"fsm",
".",
"logs",
",",
"log",
".",
"Data",
")",
"\n",
"return",
"len",
"(",
"fsm",
".",
"logs",
")",
"\n",
"}"
] | // Apply is part of the raft.FSM interface. | [
"Apply",
"is",
"part",
"of",
"the",
"raft",
".",
"FSM",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/simplefsm.go#L31-L36 |
4,893 | juju/juju | worker/raft/simplefsm.go | Snapshot | func (fsm *SimpleFSM) Snapshot() (raft.FSMSnapshot, error) {
fsm.mu.Lock()
defer fsm.mu.Unlock()
copied := make([][]byte, len(fsm.logs))
copy(copied, fsm.logs)
return &SimpleSnapshot{copied, len(copied)}, nil
} | go | func (fsm *SimpleFSM) Snapshot() (raft.FSMSnapshot, error) {
fsm.mu.Lock()
defer fsm.mu.Unlock()
copied := make([][]byte, len(fsm.logs))
copy(copied, fsm.logs)
return &SimpleSnapshot{copied, len(copied)}, nil
} | [
"func",
"(",
"fsm",
"*",
"SimpleFSM",
")",
"Snapshot",
"(",
")",
"(",
"raft",
".",
"FSMSnapshot",
",",
"error",
")",
"{",
"fsm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"fsm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"copied",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"len",
"(",
"fsm",
".",
"logs",
")",
")",
"\n",
"copy",
"(",
"copied",
",",
"fsm",
".",
"logs",
")",
"\n",
"return",
"&",
"SimpleSnapshot",
"{",
"copied",
",",
"len",
"(",
"copied",
")",
"}",
",",
"nil",
"\n",
"}"
] | // Snapshot is part of the raft.FSM interface. | [
"Snapshot",
"is",
"part",
"of",
"the",
"raft",
".",
"FSM",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/simplefsm.go#L39-L45 |
4,894 | juju/juju | worker/raft/simplefsm.go | Restore | func (fsm *SimpleFSM) Restore(rc io.ReadCloser) error {
defer rc.Close()
var logs [][]byte
if err := gob.NewDecoder(rc).Decode(&logs); err != nil {
return err
}
fsm.mu.Lock()
fsm.logs = logs
fsm.mu.Unlock()
return nil
} | go | func (fsm *SimpleFSM) Restore(rc io.ReadCloser) error {
defer rc.Close()
var logs [][]byte
if err := gob.NewDecoder(rc).Decode(&logs); err != nil {
return err
}
fsm.mu.Lock()
fsm.logs = logs
fsm.mu.Unlock()
return nil
} | [
"func",
"(",
"fsm",
"*",
"SimpleFSM",
")",
"Restore",
"(",
"rc",
"io",
".",
"ReadCloser",
")",
"error",
"{",
"defer",
"rc",
".",
"Close",
"(",
")",
"\n",
"var",
"logs",
"[",
"]",
"[",
"]",
"byte",
"\n",
"if",
"err",
":=",
"gob",
".",
"NewDecoder",
"(",
"rc",
")",
".",
"Decode",
"(",
"&",
"logs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fsm",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"fsm",
".",
"logs",
"=",
"logs",
"\n",
"fsm",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Restore is part of the raft.FSM interface. | [
"Restore",
"is",
"part",
"of",
"the",
"raft",
".",
"FSM",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/simplefsm.go#L48-L58 |
4,895 | juju/juju | worker/raft/simplefsm.go | Persist | func (snap *SimpleSnapshot) Persist(sink raft.SnapshotSink) error {
if err := gob.NewEncoder(sink).Encode(snap.logs[:snap.n]); err != nil {
sink.Cancel()
return err
}
sink.Close()
return nil
} | go | func (snap *SimpleSnapshot) Persist(sink raft.SnapshotSink) error {
if err := gob.NewEncoder(sink).Encode(snap.logs[:snap.n]); err != nil {
sink.Cancel()
return err
}
sink.Close()
return nil
} | [
"func",
"(",
"snap",
"*",
"SimpleSnapshot",
")",
"Persist",
"(",
"sink",
"raft",
".",
"SnapshotSink",
")",
"error",
"{",
"if",
"err",
":=",
"gob",
".",
"NewEncoder",
"(",
"sink",
")",
".",
"Encode",
"(",
"snap",
".",
"logs",
"[",
":",
"snap",
".",
"n",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"sink",
".",
"Cancel",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"sink",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Persist is part of the raft.FSMSnapshot interface. | [
"Persist",
"is",
"part",
"of",
"the",
"raft",
".",
"FSMSnapshot",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/simplefsm.go#L68-L75 |
4,896 | juju/juju | controller/authentication/authentication.go | NewAPIAuthenticator | func NewAPIAuthenticator(st *apiprovisioner.State) (AuthenticationProvider, error) {
stateAddresses, err := st.StateAddresses()
if err != nil {
return nil, errors.Trace(err)
}
apiAddresses, err := st.APIAddresses()
if err != nil {
return nil, errors.Trace(err)
}
caCert, err := st.CACert()
if err != nil {
return nil, errors.Trace(err)
}
modelUUID, err := st.ModelUUID()
if err != nil {
return nil, errors.Trace(err)
}
stateInfo := &mongo.MongoInfo{
Info: mongo.Info{
Addrs: stateAddresses,
CACert: caCert,
},
}
apiInfo := &api.Info{
Addrs: apiAddresses,
CACert: caCert,
ModelTag: names.NewModelTag(modelUUID),
}
return &simpleAuth{stateInfo, apiInfo}, nil
} | go | func NewAPIAuthenticator(st *apiprovisioner.State) (AuthenticationProvider, error) {
stateAddresses, err := st.StateAddresses()
if err != nil {
return nil, errors.Trace(err)
}
apiAddresses, err := st.APIAddresses()
if err != nil {
return nil, errors.Trace(err)
}
caCert, err := st.CACert()
if err != nil {
return nil, errors.Trace(err)
}
modelUUID, err := st.ModelUUID()
if err != nil {
return nil, errors.Trace(err)
}
stateInfo := &mongo.MongoInfo{
Info: mongo.Info{
Addrs: stateAddresses,
CACert: caCert,
},
}
apiInfo := &api.Info{
Addrs: apiAddresses,
CACert: caCert,
ModelTag: names.NewModelTag(modelUUID),
}
return &simpleAuth{stateInfo, apiInfo}, nil
} | [
"func",
"NewAPIAuthenticator",
"(",
"st",
"*",
"apiprovisioner",
".",
"State",
")",
"(",
"AuthenticationProvider",
",",
"error",
")",
"{",
"stateAddresses",
",",
"err",
":=",
"st",
".",
"StateAddresses",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"apiAddresses",
",",
"err",
":=",
"st",
".",
"APIAddresses",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"caCert",
",",
"err",
":=",
"st",
".",
"CACert",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"modelUUID",
",",
"err",
":=",
"st",
".",
"ModelUUID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"stateInfo",
":=",
"&",
"mongo",
".",
"MongoInfo",
"{",
"Info",
":",
"mongo",
".",
"Info",
"{",
"Addrs",
":",
"stateAddresses",
",",
"CACert",
":",
"caCert",
",",
"}",
",",
"}",
"\n",
"apiInfo",
":=",
"&",
"api",
".",
"Info",
"{",
"Addrs",
":",
"apiAddresses",
",",
"CACert",
":",
"caCert",
",",
"ModelTag",
":",
"names",
".",
"NewModelTag",
"(",
"modelUUID",
")",
",",
"}",
"\n",
"return",
"&",
"simpleAuth",
"{",
"stateInfo",
",",
"apiInfo",
"}",
",",
"nil",
"\n",
"}"
] | // NewAPIAuthenticator gets the state and api info once from the
// provisioner API. | [
"NewAPIAuthenticator",
"gets",
"the",
"state",
"and",
"api",
"info",
"once",
"from",
"the",
"provisioner",
"API",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/authentication/authentication.go#L33-L62 |
4,897 | juju/juju | controller/authentication/authentication.go | SetupAuthentication | func SetupAuthentication(
machine TaggedPasswordChanger,
stateInfo *mongo.MongoInfo,
apiInfo *api.Info,
) (*mongo.MongoInfo, *api.Info, error) {
auth := simpleAuth{stateInfo, apiInfo}
return auth.SetupAuthentication(machine)
} | go | func SetupAuthentication(
machine TaggedPasswordChanger,
stateInfo *mongo.MongoInfo,
apiInfo *api.Info,
) (*mongo.MongoInfo, *api.Info, error) {
auth := simpleAuth{stateInfo, apiInfo}
return auth.SetupAuthentication(machine)
} | [
"func",
"SetupAuthentication",
"(",
"machine",
"TaggedPasswordChanger",
",",
"stateInfo",
"*",
"mongo",
".",
"MongoInfo",
",",
"apiInfo",
"*",
"api",
".",
"Info",
",",
")",
"(",
"*",
"mongo",
".",
"MongoInfo",
",",
"*",
"api",
".",
"Info",
",",
"error",
")",
"{",
"auth",
":=",
"simpleAuth",
"{",
"stateInfo",
",",
"apiInfo",
"}",
"\n",
"return",
"auth",
".",
"SetupAuthentication",
"(",
"machine",
")",
"\n",
"}"
] | // SetupAuthentication generates a random password for the given machine,
// recording it via the machine's SetPassword method, and updates the
// info arguments with the tag and password. | [
"SetupAuthentication",
"generates",
"a",
"random",
"password",
"for",
"the",
"given",
"machine",
"recording",
"it",
"via",
"the",
"machine",
"s",
"SetPassword",
"method",
"and",
"updates",
"the",
"info",
"arguments",
"with",
"the",
"tag",
"and",
"password",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/authentication/authentication.go#L67-L74 |
4,898 | juju/juju | apiserver/facades/client/firewallrules/firewallrules.go | NewAPI | func NewAPI(
backend Backend,
authorizer facade.Authorizer,
blockChecker BlockChecker,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &API{
backend: backend,
authorizer: authorizer,
check: blockChecker,
}, nil
} | go | func NewAPI(
backend Backend,
authorizer facade.Authorizer,
blockChecker BlockChecker,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &API{
backend: backend,
authorizer: authorizer,
check: blockChecker,
}, nil
} | [
"func",
"NewAPI",
"(",
"backend",
"Backend",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
"blockChecker",
"BlockChecker",
",",
")",
"(",
"*",
"API",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthClient",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"API",
"{",
"backend",
":",
"backend",
",",
"authorizer",
":",
"authorizer",
",",
"check",
":",
"blockChecker",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewAPI returns a new firewallrules API facade. | [
"NewAPI",
"returns",
"a",
"new",
"firewallrules",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/firewallrules/firewallrules.go#L42-L55 |
4,899 | juju/juju | apiserver/facades/client/firewallrules/firewallrules.go | SetFirewallRules | func (api *API) SetFirewallRules(args params.FirewallRuleArgs) (params.ErrorResults, error) {
var errResults params.ErrorResults
if err := api.checkAdmin(); err != nil {
return errResults, errors.Trace(err)
}
if err := api.check.ChangeAllowed(); err != nil {
return errResults, errors.Trace(err)
}
results := make([]params.ErrorResult, len(args.Args))
for i, arg := range args.Args {
logger.Debugf("saving firewall rule %+v", arg)
err := api.backend.SaveFirewallRule(state.FirewallRule{
WellKnownService: state.WellKnownServiceType(arg.KnownService),
WhitelistCIDRs: arg.WhitelistCIDRS,
})
results[i].Error = common.ServerError(err)
}
errResults.Results = results
return errResults, nil
} | go | func (api *API) SetFirewallRules(args params.FirewallRuleArgs) (params.ErrorResults, error) {
var errResults params.ErrorResults
if err := api.checkAdmin(); err != nil {
return errResults, errors.Trace(err)
}
if err := api.check.ChangeAllowed(); err != nil {
return errResults, errors.Trace(err)
}
results := make([]params.ErrorResult, len(args.Args))
for i, arg := range args.Args {
logger.Debugf("saving firewall rule %+v", arg)
err := api.backend.SaveFirewallRule(state.FirewallRule{
WellKnownService: state.WellKnownServiceType(arg.KnownService),
WhitelistCIDRs: arg.WhitelistCIDRS,
})
results[i].Error = common.ServerError(err)
}
errResults.Results = results
return errResults, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"SetFirewallRules",
"(",
"args",
"params",
".",
"FirewallRuleArgs",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"var",
"errResults",
"params",
".",
"ErrorResults",
"\n",
"if",
"err",
":=",
"api",
".",
"checkAdmin",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errResults",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errResults",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"results",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Args",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"arg",
")",
"\n",
"err",
":=",
"api",
".",
"backend",
".",
"SaveFirewallRule",
"(",
"state",
".",
"FirewallRule",
"{",
"WellKnownService",
":",
"state",
".",
"WellKnownServiceType",
"(",
"arg",
".",
"KnownService",
")",
",",
"WhitelistCIDRs",
":",
"arg",
".",
"WhitelistCIDRS",
",",
"}",
")",
"\n",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"errResults",
".",
"Results",
"=",
"results",
"\n",
"return",
"errResults",
",",
"nil",
"\n",
"}"
] | // SetFirewallRules creates or updates the specified firewall rules. | [
"SetFirewallRules",
"creates",
"or",
"updates",
"the",
"specified",
"firewall",
"rules",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/firewallrules/firewallrules.go#L77-L97 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.