id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
154,300 |
juju/juju
|
provider/gce/google/conn.go
|
AvailabilityZones
|
func (gc *Connection) AvailabilityZones(region string) ([]AvailabilityZone, error) {
rawZones, err := gc.raw.ListAvailabilityZones(gc.projectID, region)
if err != nil {
return nil, errors.Trace(err)
}
var zones []AvailabilityZone
for _, rawZone := range rawZones {
zones = append(zones, AvailabilityZone{rawZone})
}
return zones, nil
}
|
go
|
func (gc *Connection) AvailabilityZones(region string) ([]AvailabilityZone, error) {
rawZones, err := gc.raw.ListAvailabilityZones(gc.projectID, region)
if err != nil {
return nil, errors.Trace(err)
}
var zones []AvailabilityZone
for _, rawZone := range rawZones {
zones = append(zones, AvailabilityZone{rawZone})
}
return zones, nil
}
|
[
"func",
"(",
"gc",
"*",
"Connection",
")",
"AvailabilityZones",
"(",
"region",
"string",
")",
"(",
"[",
"]",
"AvailabilityZone",
",",
"error",
")",
"{",
"rawZones",
",",
"err",
":=",
"gc",
".",
"raw",
".",
"ListAvailabilityZones",
"(",
"gc",
".",
"projectID",
",",
"region",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"zones",
"[",
"]",
"AvailabilityZone",
"\n",
"for",
"_",
",",
"rawZone",
":=",
"range",
"rawZones",
"{",
"zones",
"=",
"append",
"(",
"zones",
",",
"AvailabilityZone",
"{",
"rawZone",
"}",
")",
"\n",
"}",
"\n",
"return",
"zones",
",",
"nil",
"\n",
"}"
] |
// AvailabilityZones returns the list of availability zones for a given
// GCE region. If none are found the the list is empty. Any failure in
// the low-level request is returned as an error.
|
[
"AvailabilityZones",
"returns",
"the",
"list",
"of",
"availability",
"zones",
"for",
"a",
"given",
"GCE",
"region",
".",
"If",
"none",
"are",
"found",
"the",
"the",
"list",
"is",
"empty",
".",
"Any",
"failure",
"in",
"the",
"low",
"-",
"level",
"request",
"is",
"returned",
"as",
"an",
"error",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn.go#L164-L175
|
154,301 |
juju/juju
|
worker/common/charmrunner/logger.go
|
NewHookLogger
|
func NewHookLogger(logger loggo.Logger, outReader io.ReadCloser) *HookLogger {
return &HookLogger{
r: outReader,
done: make(chan struct{}),
logger: logger,
}
}
|
go
|
func NewHookLogger(logger loggo.Logger, outReader io.ReadCloser) *HookLogger {
return &HookLogger{
r: outReader,
done: make(chan struct{}),
logger: logger,
}
}
|
[
"func",
"NewHookLogger",
"(",
"logger",
"loggo",
".",
"Logger",
",",
"outReader",
"io",
".",
"ReadCloser",
")",
"*",
"HookLogger",
"{",
"return",
"&",
"HookLogger",
"{",
"r",
":",
"outReader",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"}"
] |
// NewHookLogger creates a new hook logger.
|
[
"NewHookLogger",
"creates",
"a",
"new",
"hook",
"logger",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/common/charmrunner/logger.go#L18-L24
|
154,302 |
juju/juju
|
worker/common/charmrunner/logger.go
|
Run
|
func (l *HookLogger) Run() {
defer close(l.done)
defer l.r.Close()
br := bufio.NewReaderSize(l.r, 4096)
for {
line, _, err := br.ReadLine()
if err != nil {
if err != io.EOF {
logger.Errorf("cannot read hook output: %v", err)
}
break
}
l.mu.Lock()
if l.stopped {
l.mu.Unlock()
return
}
l.logger.Debugf("%s", line)
l.mu.Unlock()
}
}
|
go
|
func (l *HookLogger) Run() {
defer close(l.done)
defer l.r.Close()
br := bufio.NewReaderSize(l.r, 4096)
for {
line, _, err := br.ReadLine()
if err != nil {
if err != io.EOF {
logger.Errorf("cannot read hook output: %v", err)
}
break
}
l.mu.Lock()
if l.stopped {
l.mu.Unlock()
return
}
l.logger.Debugf("%s", line)
l.mu.Unlock()
}
}
|
[
"func",
"(",
"l",
"*",
"HookLogger",
")",
"Run",
"(",
")",
"{",
"defer",
"close",
"(",
"l",
".",
"done",
")",
"\n",
"defer",
"l",
".",
"r",
".",
"Close",
"(",
")",
"\n",
"br",
":=",
"bufio",
".",
"NewReaderSize",
"(",
"l",
".",
"r",
",",
"4096",
")",
"\n",
"for",
"{",
"line",
",",
"_",
",",
"err",
":=",
"br",
".",
"ReadLine",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"!=",
"io",
".",
"EOF",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"l",
".",
"stopped",
"{",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"l",
".",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"line",
")",
"\n",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// Run starts the hook logger.
|
[
"Run",
"starts",
"the",
"hook",
"logger",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/common/charmrunner/logger.go#L36-L56
|
154,303 |
juju/juju
|
worker/common/charmrunner/logger.go
|
Stop
|
func (l *HookLogger) Stop() {
// We can see the process exit before the logger has processed
// all its output, so allow a moment for the data buffered
// in the pipe to be processed. We don't wait indefinitely though,
// because the hook may have started a background process
// that keeps the pipe open.
select {
case <-l.done:
case <-time.After(100 * time.Millisecond):
}
// We can't close the pipe asynchronously, so just
// stifle output instead.
l.mu.Lock()
l.stopped = true
l.mu.Unlock()
}
|
go
|
func (l *HookLogger) Stop() {
// We can see the process exit before the logger has processed
// all its output, so allow a moment for the data buffered
// in the pipe to be processed. We don't wait indefinitely though,
// because the hook may have started a background process
// that keeps the pipe open.
select {
case <-l.done:
case <-time.After(100 * time.Millisecond):
}
// We can't close the pipe asynchronously, so just
// stifle output instead.
l.mu.Lock()
l.stopped = true
l.mu.Unlock()
}
|
[
"func",
"(",
"l",
"*",
"HookLogger",
")",
"Stop",
"(",
")",
"{",
"// We can see the process exit before the logger has processed",
"// all its output, so allow a moment for the data buffered",
"// in the pipe to be processed. We don't wait indefinitely though,",
"// because the hook may have started a background process",
"// that keeps the pipe open.",
"select",
"{",
"case",
"<-",
"l",
".",
"done",
":",
"case",
"<-",
"time",
".",
"After",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
":",
"}",
"\n",
"// We can't close the pipe asynchronously, so just",
"// stifle output instead.",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"stopped",
"=",
"true",
"\n",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Stop stops the hook logger.
|
[
"Stop",
"stops",
"the",
"hook",
"logger",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/common/charmrunner/logger.go#L59-L74
|
154,304 |
juju/juju
|
core/life/life.go
|
Validate
|
func (v Value) Validate() error {
switch v {
case Alive, Dying, Dead:
return nil
}
return errors.NotValidf("life value %q", v)
}
|
go
|
func (v Value) Validate() error {
switch v {
case Alive, Dying, Dead:
return nil
}
return errors.NotValidf("life value %q", v)
}
|
[
"func",
"(",
"v",
"Value",
")",
"Validate",
"(",
")",
"error",
"{",
"switch",
"v",
"{",
"case",
"Alive",
",",
"Dying",
",",
"Dead",
":",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}"
] |
// Validate returns an error if the value is not known.
|
[
"Validate",
"returns",
"an",
"error",
"if",
"the",
"value",
"is",
"not",
"known",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/life/life.go#L26-L32
|
154,305 |
juju/juju
|
cmd/juju/application/suspendrelation.go
|
NewSuspendRelationCommand
|
func NewSuspendRelationCommand() cmd.Command {
cmd := &suspendRelationCommand{}
cmd.newAPIFunc = func() (SetRelationSuspendedAPI, error) {
root, err := cmd.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return application.NewClient(root), nil
}
return modelcmd.Wrap(cmd)
}
|
go
|
func NewSuspendRelationCommand() cmd.Command {
cmd := &suspendRelationCommand{}
cmd.newAPIFunc = func() (SetRelationSuspendedAPI, error) {
root, err := cmd.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return application.NewClient(root), nil
}
return modelcmd.Wrap(cmd)
}
|
[
"func",
"NewSuspendRelationCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"cmd",
":=",
"&",
"suspendRelationCommand",
"{",
"}",
"\n",
"cmd",
".",
"newAPIFunc",
"=",
"func",
"(",
")",
"(",
"SetRelationSuspendedAPI",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"cmd",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"application",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"modelcmd",
".",
"Wrap",
"(",
"cmd",
")",
"\n",
"}"
] |
// NewSuspendRelationCommand returns a command to suspend a relation.
|
[
"NewSuspendRelationCommand",
"returns",
"a",
"command",
"to",
"suspend",
"a",
"relation",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/suspendrelation.go#L40-L50
|
154,306 |
juju/juju
|
api/machiner/machine.go
|
Refresh
|
func (m *Machine) Refresh() error {
life, err := m.st.machineLife(m.tag)
if err != nil {
return err
}
m.life = life
return nil
}
|
go
|
func (m *Machine) Refresh() error {
life, err := m.st.machineLife(m.tag)
if err != nil {
return err
}
m.life = life
return nil
}
|
[
"func",
"(",
"m",
"*",
"Machine",
")",
"Refresh",
"(",
")",
"error",
"{",
"life",
",",
"err",
":=",
"m",
".",
"st",
".",
"machineLife",
"(",
"m",
".",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"m",
".",
"life",
"=",
"life",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Refresh updates the cached local copy of the machine's data.
|
[
"Refresh",
"updates",
"the",
"cached",
"local",
"copy",
"of",
"the",
"machine",
"s",
"data",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machiner/machine.go#L35-L42
|
154,307 |
juju/juju
|
api/machiner/machine.go
|
SetMachineAddresses
|
func (m *Machine) SetMachineAddresses(addresses []network.Address) error {
var result params.ErrorResults
args := params.SetMachinesAddresses{
MachineAddresses: []params.MachineAddresses{
{Tag: m.Tag().String(), Addresses: params.FromNetworkAddresses(addresses...)},
},
}
err := m.st.facade.FacadeCall("SetMachineAddresses", args, &result)
if err != nil {
return err
}
return result.OneError()
}
|
go
|
func (m *Machine) SetMachineAddresses(addresses []network.Address) error {
var result params.ErrorResults
args := params.SetMachinesAddresses{
MachineAddresses: []params.MachineAddresses{
{Tag: m.Tag().String(), Addresses: params.FromNetworkAddresses(addresses...)},
},
}
err := m.st.facade.FacadeCall("SetMachineAddresses", args, &result)
if err != nil {
return err
}
return result.OneError()
}
|
[
"func",
"(",
"m",
"*",
"Machine",
")",
"SetMachineAddresses",
"(",
"addresses",
"[",
"]",
"network",
".",
"Address",
")",
"error",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"SetMachinesAddresses",
"{",
"MachineAddresses",
":",
"[",
"]",
"params",
".",
"MachineAddresses",
"{",
"{",
"Tag",
":",
"m",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
",",
"Addresses",
":",
"params",
".",
"FromNetworkAddresses",
"(",
"addresses",
"...",
")",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"OneError",
"(",
")",
"\n",
"}"
] |
// SetMachineAddresses sets the machine determined addresses of the machine.
|
[
"SetMachineAddresses",
"sets",
"the",
"machine",
"determined",
"addresses",
"of",
"the",
"machine",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machiner/machine.go#L60-L72
|
154,308 |
juju/juju
|
api/machiner/machine.go
|
Watch
|
func (m *Machine) Watch() (watcher.NotifyWatcher, error) {
return common.Watch(m.st.facade, "Watch", m.tag)
}
|
go
|
func (m *Machine) Watch() (watcher.NotifyWatcher, error) {
return common.Watch(m.st.facade, "Watch", m.tag)
}
|
[
"func",
"(",
"m",
"*",
"Machine",
")",
"Watch",
"(",
")",
"(",
"watcher",
".",
"NotifyWatcher",
",",
"error",
")",
"{",
"return",
"common",
".",
"Watch",
"(",
"m",
".",
"st",
".",
"facade",
",",
"\"",
"\"",
",",
"m",
".",
"tag",
")",
"\n",
"}"
] |
// Watch returns a watcher for observing changes to the machine.
|
[
"Watch",
"returns",
"a",
"watcher",
"for",
"observing",
"changes",
"to",
"the",
"machine",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machiner/machine.go#L89-L91
|
154,309 |
juju/juju
|
api/machiner/machine.go
|
Jobs
|
func (m *Machine) Jobs() (*params.JobsResult, error) {
var results params.JobsResults
args := params.Entities{
Entities: []params.Entity{{Tag: m.Tag().String()}},
}
err := m.st.facade.FacadeCall("Jobs", args, &results)
if err != nil {
return nil, errors.Annotate(err, "error from FacadeCall")
}
if len(results.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
return &result, nil
}
|
go
|
func (m *Machine) Jobs() (*params.JobsResult, error) {
var results params.JobsResults
args := params.Entities{
Entities: []params.Entity{{Tag: m.Tag().String()}},
}
err := m.st.facade.FacadeCall("Jobs", args, &results)
if err != nil {
return nil, errors.Annotate(err, "error from FacadeCall")
}
if len(results.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
return &result, nil
}
|
[
"func",
"(",
"m",
"*",
"Machine",
")",
"Jobs",
"(",
")",
"(",
"*",
"params",
".",
"JobsResult",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"JobsResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"&",
"result",
",",
"nil",
"\n",
"}"
] |
// Jobs returns a list of jobs for the machine.
|
[
"Jobs",
"returns",
"a",
"list",
"of",
"jobs",
"for",
"the",
"machine",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machiner/machine.go#L94-L111
|
154,310 |
juju/juju
|
api/machiner/machine.go
|
SetObservedNetworkConfig
|
func (m *Machine) SetObservedNetworkConfig(netConfig []params.NetworkConfig) error {
args := params.SetMachineNetworkConfig{
Tag: m.Tag().String(),
Config: netConfig,
}
err := m.st.facade.FacadeCall("SetObservedNetworkConfig", args, nil)
if err != nil {
return errors.Trace(err)
}
return nil
}
|
go
|
func (m *Machine) SetObservedNetworkConfig(netConfig []params.NetworkConfig) error {
args := params.SetMachineNetworkConfig{
Tag: m.Tag().String(),
Config: netConfig,
}
err := m.st.facade.FacadeCall("SetObservedNetworkConfig", args, nil)
if err != nil {
return errors.Trace(err)
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Machine",
")",
"SetObservedNetworkConfig",
"(",
"netConfig",
"[",
"]",
"params",
".",
"NetworkConfig",
")",
"error",
"{",
"args",
":=",
"params",
".",
"SetMachineNetworkConfig",
"{",
"Tag",
":",
"m",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
",",
"Config",
":",
"netConfig",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetObservedNetworkConfig sets the machine network config as observed on the
// machine.
|
[
"SetObservedNetworkConfig",
"sets",
"the",
"machine",
"network",
"config",
"as",
"observed",
"on",
"the",
"machine",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machiner/machine.go#L115-L125
|
154,311 |
juju/juju
|
environs/cloudspec.go
|
Validate
|
func (cs CloudSpec) Validate() error {
if cs.Type == "" {
return errors.NotValidf("empty Type")
}
if !names.IsValidCloud(cs.Name) {
return errors.NotValidf("cloud name %q", cs.Name)
}
return nil
}
|
go
|
func (cs CloudSpec) Validate() error {
if cs.Type == "" {
return errors.NotValidf("empty Type")
}
if !names.IsValidCloud(cs.Name) {
return errors.NotValidf("cloud name %q", cs.Name)
}
return nil
}
|
[
"func",
"(",
"cs",
"CloudSpec",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"cs",
".",
"Type",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"names",
".",
"IsValidCloud",
"(",
"cs",
".",
"Name",
")",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"cs",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate validates that the CloudSpec is well-formed. It does
// not ensure that the cloud type and credentials are valid.
|
[
"Validate",
"validates",
"that",
"the",
"CloudSpec",
"is",
"well",
"-",
"formed",
".",
"It",
"does",
"not",
"ensure",
"that",
"the",
"cloud",
"type",
"and",
"credentials",
"are",
"valid",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/cloudspec.go#L49-L57
|
154,312 |
juju/juju
|
environs/cloudspec.go
|
MakeCloudSpec
|
func MakeCloudSpec(cloud jujucloud.Cloud, cloudRegionName string, credential *jujucloud.Credential) (CloudSpec, error) {
cloudSpec := CloudSpec{
Type: cloud.Type,
Name: cloud.Name,
Region: cloudRegionName,
Endpoint: cloud.Endpoint,
IdentityEndpoint: cloud.IdentityEndpoint,
StorageEndpoint: cloud.StorageEndpoint,
CACertificates: cloud.CACertificates,
Credential: credential,
}
if cloudRegionName != "" {
cloudRegion, err := jujucloud.RegionByName(cloud.Regions, cloudRegionName)
if err != nil {
return CloudSpec{}, errors.Annotate(err, "getting cloud region definition")
}
cloudSpec.Endpoint = cloudRegion.Endpoint
cloudSpec.IdentityEndpoint = cloudRegion.IdentityEndpoint
cloudSpec.StorageEndpoint = cloudRegion.StorageEndpoint
}
return cloudSpec, nil
}
|
go
|
func MakeCloudSpec(cloud jujucloud.Cloud, cloudRegionName string, credential *jujucloud.Credential) (CloudSpec, error) {
cloudSpec := CloudSpec{
Type: cloud.Type,
Name: cloud.Name,
Region: cloudRegionName,
Endpoint: cloud.Endpoint,
IdentityEndpoint: cloud.IdentityEndpoint,
StorageEndpoint: cloud.StorageEndpoint,
CACertificates: cloud.CACertificates,
Credential: credential,
}
if cloudRegionName != "" {
cloudRegion, err := jujucloud.RegionByName(cloud.Regions, cloudRegionName)
if err != nil {
return CloudSpec{}, errors.Annotate(err, "getting cloud region definition")
}
cloudSpec.Endpoint = cloudRegion.Endpoint
cloudSpec.IdentityEndpoint = cloudRegion.IdentityEndpoint
cloudSpec.StorageEndpoint = cloudRegion.StorageEndpoint
}
return cloudSpec, nil
}
|
[
"func",
"MakeCloudSpec",
"(",
"cloud",
"jujucloud",
".",
"Cloud",
",",
"cloudRegionName",
"string",
",",
"credential",
"*",
"jujucloud",
".",
"Credential",
")",
"(",
"CloudSpec",
",",
"error",
")",
"{",
"cloudSpec",
":=",
"CloudSpec",
"{",
"Type",
":",
"cloud",
".",
"Type",
",",
"Name",
":",
"cloud",
".",
"Name",
",",
"Region",
":",
"cloudRegionName",
",",
"Endpoint",
":",
"cloud",
".",
"Endpoint",
",",
"IdentityEndpoint",
":",
"cloud",
".",
"IdentityEndpoint",
",",
"StorageEndpoint",
":",
"cloud",
".",
"StorageEndpoint",
",",
"CACertificates",
":",
"cloud",
".",
"CACertificates",
",",
"Credential",
":",
"credential",
",",
"}",
"\n",
"if",
"cloudRegionName",
"!=",
"\"",
"\"",
"{",
"cloudRegion",
",",
"err",
":=",
"jujucloud",
".",
"RegionByName",
"(",
"cloud",
".",
"Regions",
",",
"cloudRegionName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"CloudSpec",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cloudSpec",
".",
"Endpoint",
"=",
"cloudRegion",
".",
"Endpoint",
"\n",
"cloudSpec",
".",
"IdentityEndpoint",
"=",
"cloudRegion",
".",
"IdentityEndpoint",
"\n",
"cloudSpec",
".",
"StorageEndpoint",
"=",
"cloudRegion",
".",
"StorageEndpoint",
"\n",
"}",
"\n",
"return",
"cloudSpec",
",",
"nil",
"\n",
"}"
] |
// MakeCloudSpec returns a CloudSpec from the given
// Cloud, cloud and region names, and credential.
|
[
"MakeCloudSpec",
"returns",
"a",
"CloudSpec",
"from",
"the",
"given",
"Cloud",
"cloud",
"and",
"region",
"names",
"and",
"credential",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/cloudspec.go#L61-L82
|
154,313 |
juju/juju
|
environs/cloudspec.go
|
NewCloudRegionSpec
|
func NewCloudRegionSpec(cloud, region string) (*CloudRegionSpec, error) {
if cloud == "" {
return nil, errors.New("cloud is required to be non empty")
}
return &CloudRegionSpec{Cloud: cloud, Region: region}, nil
}
|
go
|
func NewCloudRegionSpec(cloud, region string) (*CloudRegionSpec, error) {
if cloud == "" {
return nil, errors.New("cloud is required to be non empty")
}
return &CloudRegionSpec{Cloud: cloud, Region: region}, nil
}
|
[
"func",
"NewCloudRegionSpec",
"(",
"cloud",
",",
"region",
"string",
")",
"(",
"*",
"CloudRegionSpec",
",",
"error",
")",
"{",
"if",
"cloud",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"CloudRegionSpec",
"{",
"Cloud",
":",
"cloud",
",",
"Region",
":",
"region",
"}",
",",
"nil",
"\n",
"}"
] |
// NewCloudRegionSpec returns a CloudRegionSpec ensuring cloud arg is not empty.
|
[
"NewCloudRegionSpec",
"returns",
"a",
"CloudRegionSpec",
"ensuring",
"cloud",
"arg",
"is",
"not",
"empty",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/cloudspec.go#L96-L101
|
154,314 |
juju/juju
|
logfwd/syslog/config.go
|
Validate
|
func (cfg RawConfig) Validate() error {
if err := cfg.validateHost(); err != nil {
return errors.Trace(err)
}
if cfg.Enabled || cfg.ClientKey != "" || cfg.ClientCert != "" || cfg.CACert != "" {
if _, err := cfg.tlsConfig(); err != nil {
return errors.Annotate(err, "validating TLS config")
}
}
return nil
}
|
go
|
func (cfg RawConfig) Validate() error {
if err := cfg.validateHost(); err != nil {
return errors.Trace(err)
}
if cfg.Enabled || cfg.ClientKey != "" || cfg.ClientCert != "" || cfg.CACert != "" {
if _, err := cfg.tlsConfig(); err != nil {
return errors.Annotate(err, "validating TLS config")
}
}
return nil
}
|
[
"func",
"(",
"cfg",
"RawConfig",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"cfg",
".",
"validateHost",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"cfg",
".",
"Enabled",
"||",
"cfg",
".",
"ClientKey",
"!=",
"\"",
"\"",
"||",
"cfg",
".",
"ClientCert",
"!=",
"\"",
"\"",
"||",
"cfg",
".",
"CACert",
"!=",
"\"",
"\"",
"{",
"if",
"_",
",",
"err",
":=",
"cfg",
".",
"tlsConfig",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate ensures that the config is currently valid.
|
[
"Validate",
"ensures",
"that",
"the",
"config",
"is",
"currently",
"valid",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/logfwd/syslog/config.go#L43-L54
|
154,315 |
juju/juju
|
caas/kubernetes/provider/precheck.go
|
PrecheckInstance
|
func (k *kubernetesClient) PrecheckInstance(ctx context.ProviderCallContext, params environs.PrecheckInstanceParams) error {
// Ensure there are no unsupported constraints.
// Clouds generally don't enforce this but we will
// for Kubernetes deployments.
validator, err := k.ConstraintsValidator(ctx)
if err != nil {
return errors.Trace(err)
}
unsupported, err := validator.Validate(params.Constraints)
if err != nil {
return errors.NotValidf("constraints %q", params.Constraints.String())
}
if len(unsupported) > 0 {
return errors.NotSupportedf("constraints %v", strings.Join(unsupported, ","))
}
if params.Series != k8sSeries {
return errors.NotValidf("series %q", params.Series)
}
if params.Placement != "" {
return errors.NotValidf("placement directive %q", params.Placement)
}
if params.Constraints.Tags == nil {
return nil
}
affinityLabels := *params.Constraints.Tags
labelsString := strings.Join(affinityLabels, ",")
for _, labelPair := range affinityLabels {
parts := strings.Split(labelPair, "=")
if len(parts) != 2 {
return errors.Errorf("invalid node affinity constraints: %v", labelsString)
}
key := strings.Trim(parts[0], " ")
if strings.HasPrefix(key, "^") {
if len(key) == 1 {
return errors.Errorf("invalid node affinity constraints: %v", labelsString)
}
}
}
return nil
}
|
go
|
func (k *kubernetesClient) PrecheckInstance(ctx context.ProviderCallContext, params environs.PrecheckInstanceParams) error {
// Ensure there are no unsupported constraints.
// Clouds generally don't enforce this but we will
// for Kubernetes deployments.
validator, err := k.ConstraintsValidator(ctx)
if err != nil {
return errors.Trace(err)
}
unsupported, err := validator.Validate(params.Constraints)
if err != nil {
return errors.NotValidf("constraints %q", params.Constraints.String())
}
if len(unsupported) > 0 {
return errors.NotSupportedf("constraints %v", strings.Join(unsupported, ","))
}
if params.Series != k8sSeries {
return errors.NotValidf("series %q", params.Series)
}
if params.Placement != "" {
return errors.NotValidf("placement directive %q", params.Placement)
}
if params.Constraints.Tags == nil {
return nil
}
affinityLabels := *params.Constraints.Tags
labelsString := strings.Join(affinityLabels, ",")
for _, labelPair := range affinityLabels {
parts := strings.Split(labelPair, "=")
if len(parts) != 2 {
return errors.Errorf("invalid node affinity constraints: %v", labelsString)
}
key := strings.Trim(parts[0], " ")
if strings.HasPrefix(key, "^") {
if len(key) == 1 {
return errors.Errorf("invalid node affinity constraints: %v", labelsString)
}
}
}
return nil
}
|
[
"func",
"(",
"k",
"*",
"kubernetesClient",
")",
"PrecheckInstance",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"params",
"environs",
".",
"PrecheckInstanceParams",
")",
"error",
"{",
"// Ensure there are no unsupported constraints.",
"// Clouds generally don't enforce this but we will",
"// for Kubernetes deployments.",
"validator",
",",
"err",
":=",
"k",
".",
"ConstraintsValidator",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"unsupported",
",",
"err",
":=",
"validator",
".",
"Validate",
"(",
"params",
".",
"Constraints",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"params",
".",
"Constraints",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"unsupported",
")",
">",
"0",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"unsupported",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"if",
"params",
".",
"Series",
"!=",
"k8sSeries",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"params",
".",
"Series",
")",
"\n",
"}",
"\n\n",
"if",
"params",
".",
"Placement",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"params",
".",
"Placement",
")",
"\n",
"}",
"\n",
"if",
"params",
".",
"Constraints",
".",
"Tags",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"affinityLabels",
":=",
"*",
"params",
".",
"Constraints",
".",
"Tags",
"\n",
"labelsString",
":=",
"strings",
".",
"Join",
"(",
"affinityLabels",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"labelPair",
":=",
"range",
"affinityLabels",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"labelPair",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"labelsString",
")",
"\n",
"}",
"\n",
"key",
":=",
"strings",
".",
"Trim",
"(",
"parts",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
"{",
"if",
"len",
"(",
"key",
")",
"==",
"1",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"labelsString",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// PrecheckInstance performs a preflight check on the specified
// series and constraints, ensuring that they are possibly valid for
// creating an instance in this model.
//
// PrecheckInstance is best effort, and not guaranteed to eliminate
// all invalid parameters. If PrecheckInstance returns nil, it is not
// guaranteed that the constraints are valid; if a non-nil error is
// returned, then the constraints are definitely invalid.
|
[
"PrecheckInstance",
"performs",
"a",
"preflight",
"check",
"on",
"the",
"specified",
"series",
"and",
"constraints",
"ensuring",
"that",
"they",
"are",
"possibly",
"valid",
"for",
"creating",
"an",
"instance",
"in",
"this",
"model",
".",
"PrecheckInstance",
"is",
"best",
"effort",
"and",
"not",
"guaranteed",
"to",
"eliminate",
"all",
"invalid",
"parameters",
".",
"If",
"PrecheckInstance",
"returns",
"nil",
"it",
"is",
"not",
"guaranteed",
"that",
"the",
"constraints",
"are",
"valid",
";",
"if",
"a",
"non",
"-",
"nil",
"error",
"is",
"returned",
"then",
"the",
"constraints",
"are",
"definitely",
"invalid",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/precheck.go#L24-L65
|
154,316 |
juju/juju
|
core/cache/controller.go
|
Validate
|
func (c *ControllerConfig) Validate() error {
if c.Changes == nil {
return errors.NotValidf("nil Changes")
}
return nil
}
|
go
|
func (c *ControllerConfig) Validate() error {
if c.Changes == nil {
return errors.NotValidf("nil Changes")
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"ControllerConfig",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Changes",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate ensures the controller has the right values to be created.
|
[
"Validate",
"ensures",
"the",
"controller",
"has",
"the",
"right",
"values",
"to",
"be",
"created",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L32-L37
|
154,317 |
juju/juju
|
core/cache/controller.go
|
NewController
|
func NewController(config ControllerConfig) (*Controller, error) {
c, err := newController(config, newResidentManager(config.Changes))
return c, errors.Trace(err)
}
|
go
|
func NewController(config ControllerConfig) (*Controller, error) {
c, err := newController(config, newResidentManager(config.Changes))
return c, errors.Trace(err)
}
|
[
"func",
"NewController",
"(",
"config",
"ControllerConfig",
")",
"(",
"*",
"Controller",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"newController",
"(",
"config",
",",
"newResidentManager",
"(",
"config",
".",
"Changes",
")",
")",
"\n",
"return",
"c",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] |
// NewController creates a new cached controller instance.
// The changes channel is what is used to supply the cache with the changes
// in order for the cache to be kept up to date.
|
[
"NewController",
"creates",
"a",
"new",
"cached",
"controller",
"instance",
".",
"The",
"changes",
"channel",
"is",
"what",
"is",
"used",
"to",
"supply",
"the",
"cache",
"with",
"the",
"changes",
"in",
"order",
"for",
"the",
"cache",
"to",
"be",
"kept",
"up",
"to",
"date",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L58-L61
|
154,318 |
juju/juju
|
core/cache/controller.go
|
newController
|
func newController(config ControllerConfig, manager *residentManager) (*Controller, error) {
if err := config.Validate(); err != nil {
return nil, errors.Trace(err)
}
c := &Controller{
manager: manager,
changes: config.Changes,
notify: config.Notify,
models: make(map[string]*Model),
hub: pubsub.NewSimpleHub(&pubsub.SimpleHubConfig{
// TODO: (thumper) add a get child method to loggers.
Logger: loggo.GetLogger("juju.core.cache.hub"),
}),
metrics: createControllerGauges(),
}
manager.dying = c.tomb.Dying()
c.tomb.Go(c.loop)
return c, nil
}
|
go
|
func newController(config ControllerConfig, manager *residentManager) (*Controller, error) {
if err := config.Validate(); err != nil {
return nil, errors.Trace(err)
}
c := &Controller{
manager: manager,
changes: config.Changes,
notify: config.Notify,
models: make(map[string]*Model),
hub: pubsub.NewSimpleHub(&pubsub.SimpleHubConfig{
// TODO: (thumper) add a get child method to loggers.
Logger: loggo.GetLogger("juju.core.cache.hub"),
}),
metrics: createControllerGauges(),
}
manager.dying = c.tomb.Dying()
c.tomb.Go(c.loop)
return c, nil
}
|
[
"func",
"newController",
"(",
"config",
"ControllerConfig",
",",
"manager",
"*",
"residentManager",
")",
"(",
"*",
"Controller",
",",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"Controller",
"{",
"manager",
":",
"manager",
",",
"changes",
":",
"config",
".",
"Changes",
",",
"notify",
":",
"config",
".",
"Notify",
",",
"models",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Model",
")",
",",
"hub",
":",
"pubsub",
".",
"NewSimpleHub",
"(",
"&",
"pubsub",
".",
"SimpleHubConfig",
"{",
"// TODO: (thumper) add a get child method to loggers.",
"Logger",
":",
"loggo",
".",
"GetLogger",
"(",
"\"",
"\"",
")",
",",
"}",
")",
",",
"metrics",
":",
"createControllerGauges",
"(",
")",
",",
"}",
"\n\n",
"manager",
".",
"dying",
"=",
"c",
".",
"tomb",
".",
"Dying",
"(",
")",
"\n",
"c",
".",
"tomb",
".",
"Go",
"(",
"c",
".",
"loop",
")",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// newController is the internal constructor that allows supply of a manager.
|
[
"newController",
"is",
"the",
"internal",
"constructor",
"that",
"allows",
"supply",
"of",
"a",
"manager",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L64-L84
|
154,319 |
juju/juju
|
core/cache/controller.go
|
ModelUUIDs
|
func (c *Controller) ModelUUIDs() []string {
c.mu.Lock()
result := make([]string, 0, len(c.models))
for uuid := range c.models {
result = append(result, uuid)
}
c.mu.Unlock()
return result
}
|
go
|
func (c *Controller) ModelUUIDs() []string {
c.mu.Lock()
result := make([]string, 0, len(c.models))
for uuid := range c.models {
result = append(result, uuid)
}
c.mu.Unlock()
return result
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"ModelUUIDs",
"(",
")",
"[",
"]",
"string",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"result",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"c",
".",
"models",
")",
")",
"\n",
"for",
"uuid",
":=",
"range",
"c",
".",
"models",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"uuid",
")",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"result",
"\n",
"}"
] |
// ModelUUIDs returns the UUIDs of the models in the cache.
|
[
"ModelUUIDs",
"returns",
"the",
"UUIDs",
"of",
"the",
"models",
"in",
"the",
"cache",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L155-L165
|
154,320 |
juju/juju
|
core/cache/controller.go
|
Model
|
func (c *Controller) Model(uuid string) (*Model, error) {
c.mu.Lock()
defer c.mu.Unlock()
model, found := c.models[uuid]
if !found {
return nil, errors.NotFoundf("model %q", uuid)
}
return model, nil
}
|
go
|
func (c *Controller) Model(uuid string) (*Model, error) {
c.mu.Lock()
defer c.mu.Unlock()
model, found := c.models[uuid]
if !found {
return nil, errors.NotFoundf("model %q", uuid)
}
return model, nil
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"Model",
"(",
"uuid",
"string",
")",
"(",
"*",
"Model",
",",
"error",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"model",
",",
"found",
":=",
"c",
".",
"models",
"[",
"uuid",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"uuid",
")",
"\n",
"}",
"\n",
"return",
"model",
",",
"nil",
"\n",
"}"
] |
// Model returns the model for the specified UUID.
// If the model isn't found, a NotFoundError is returned.
|
[
"Model",
"returns",
"the",
"model",
"for",
"the",
"specified",
"UUID",
".",
"If",
"the",
"model",
"isn",
"t",
"found",
"a",
"NotFoundError",
"is",
"returned",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L179-L188
|
154,321 |
juju/juju
|
core/cache/controller.go
|
updateModel
|
func (c *Controller) updateModel(ch ModelChange) {
c.ensureModel(ch.ModelUUID).setDetails(ch)
}
|
go
|
func (c *Controller) updateModel(ch ModelChange) {
c.ensureModel(ch.ModelUUID).setDetails(ch)
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"updateModel",
"(",
"ch",
"ModelChange",
")",
"{",
"c",
".",
"ensureModel",
"(",
"ch",
".",
"ModelUUID",
")",
".",
"setDetails",
"(",
"ch",
")",
"\n",
"}"
] |
// updateModel will add or update the model details as
// described in the ModelChange.
|
[
"updateModel",
"will",
"add",
"or",
"update",
"the",
"model",
"details",
"as",
"described",
"in",
"the",
"ModelChange",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L192-L194
|
154,322 |
juju/juju
|
core/cache/controller.go
|
removeModel
|
func (c *Controller) removeModel(ch RemoveModel) error {
c.mu.Lock()
defer c.mu.Unlock()
mod, ok := c.models[ch.ModelUUID]
if ok {
if err := mod.evict(); err != nil {
return errors.Trace(err)
}
delete(c.models, ch.ModelUUID)
}
return nil
}
|
go
|
func (c *Controller) removeModel(ch RemoveModel) error {
c.mu.Lock()
defer c.mu.Unlock()
mod, ok := c.models[ch.ModelUUID]
if ok {
if err := mod.evict(); err != nil {
return errors.Trace(err)
}
delete(c.models, ch.ModelUUID)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"removeModel",
"(",
"ch",
"RemoveModel",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"mod",
",",
"ok",
":=",
"c",
".",
"models",
"[",
"ch",
".",
"ModelUUID",
"]",
"\n",
"if",
"ok",
"{",
"if",
"err",
":=",
"mod",
".",
"evict",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"delete",
"(",
"c",
".",
"models",
",",
"ch",
".",
"ModelUUID",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// removeModel removes the model from the cache.
|
[
"removeModel",
"removes",
"the",
"model",
"from",
"the",
"cache",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L197-L209
|
154,323 |
juju/juju
|
core/cache/controller.go
|
updateApplication
|
func (c *Controller) updateApplication(ch ApplicationChange) {
c.ensureModel(ch.ModelUUID).updateApplication(ch, c.manager)
}
|
go
|
func (c *Controller) updateApplication(ch ApplicationChange) {
c.ensureModel(ch.ModelUUID).updateApplication(ch, c.manager)
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"updateApplication",
"(",
"ch",
"ApplicationChange",
")",
"{",
"c",
".",
"ensureModel",
"(",
"ch",
".",
"ModelUUID",
")",
".",
"updateApplication",
"(",
"ch",
",",
"c",
".",
"manager",
")",
"\n",
"}"
] |
// updateApplication adds or updates the application in the specified model.
|
[
"updateApplication",
"adds",
"or",
"updates",
"the",
"application",
"in",
"the",
"specified",
"model",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L212-L214
|
154,324 |
juju/juju
|
core/cache/controller.go
|
removeApplication
|
func (c *Controller) removeApplication(ch RemoveApplication) error {
return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeApplication(ch) }))
}
|
go
|
func (c *Controller) removeApplication(ch RemoveApplication) error {
return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeApplication(ch) }))
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"removeApplication",
"(",
"ch",
"RemoveApplication",
")",
"error",
"{",
"return",
"errors",
".",
"Trace",
"(",
"c",
".",
"removeResident",
"(",
"ch",
".",
"ModelUUID",
",",
"func",
"(",
"m",
"*",
"Model",
")",
"error",
"{",
"return",
"m",
".",
"removeApplication",
"(",
"ch",
")",
"}",
")",
")",
"\n",
"}"
] |
// removeApplication removes the application for the cached model.
// If the cache does not have the model loaded for the application yet,
// then it will not have the application cached.
|
[
"removeApplication",
"removes",
"the",
"application",
"for",
"the",
"cached",
"model",
".",
"If",
"the",
"cache",
"does",
"not",
"have",
"the",
"model",
"loaded",
"for",
"the",
"application",
"yet",
"then",
"it",
"will",
"not",
"have",
"the",
"application",
"cached",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L219-L221
|
154,325 |
juju/juju
|
core/cache/controller.go
|
updateUnit
|
func (c *Controller) updateUnit(ch UnitChange) {
c.ensureModel(ch.ModelUUID).updateUnit(ch, c.manager)
}
|
go
|
func (c *Controller) updateUnit(ch UnitChange) {
c.ensureModel(ch.ModelUUID).updateUnit(ch, c.manager)
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"updateUnit",
"(",
"ch",
"UnitChange",
")",
"{",
"c",
".",
"ensureModel",
"(",
"ch",
".",
"ModelUUID",
")",
".",
"updateUnit",
"(",
"ch",
",",
"c",
".",
"manager",
")",
"\n",
"}"
] |
// updateUnit adds or updates the unit in the specified model.
|
[
"updateUnit",
"adds",
"or",
"updates",
"the",
"unit",
"in",
"the",
"specified",
"model",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L232-L234
|
154,326 |
juju/juju
|
core/cache/controller.go
|
removeUnit
|
func (c *Controller) removeUnit(ch RemoveUnit) error {
return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeUnit(ch) }))
}
|
go
|
func (c *Controller) removeUnit(ch RemoveUnit) error {
return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeUnit(ch) }))
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"removeUnit",
"(",
"ch",
"RemoveUnit",
")",
"error",
"{",
"return",
"errors",
".",
"Trace",
"(",
"c",
".",
"removeResident",
"(",
"ch",
".",
"ModelUUID",
",",
"func",
"(",
"m",
"*",
"Model",
")",
"error",
"{",
"return",
"m",
".",
"removeUnit",
"(",
"ch",
")",
"}",
")",
")",
"\n",
"}"
] |
// removeUnit removes the unit from the cached model.
// If the cache does not have the model loaded for the unit yet,
// then it will not have the unit cached.
|
[
"removeUnit",
"removes",
"the",
"unit",
"from",
"the",
"cached",
"model",
".",
"If",
"the",
"cache",
"does",
"not",
"have",
"the",
"model",
"loaded",
"for",
"the",
"unit",
"yet",
"then",
"it",
"will",
"not",
"have",
"the",
"unit",
"cached",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L239-L241
|
154,327 |
juju/juju
|
core/cache/controller.go
|
updateMachine
|
func (c *Controller) updateMachine(ch MachineChange) {
c.ensureModel(ch.ModelUUID).updateMachine(ch, c.manager)
}
|
go
|
func (c *Controller) updateMachine(ch MachineChange) {
c.ensureModel(ch.ModelUUID).updateMachine(ch, c.manager)
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"updateMachine",
"(",
"ch",
"MachineChange",
")",
"{",
"c",
".",
"ensureModel",
"(",
"ch",
".",
"ModelUUID",
")",
".",
"updateMachine",
"(",
"ch",
",",
"c",
".",
"manager",
")",
"\n",
"}"
] |
// updateMachine adds or updates the machine in the specified model.
|
[
"updateMachine",
"adds",
"or",
"updates",
"the",
"machine",
"in",
"the",
"specified",
"model",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L244-L246
|
154,328 |
juju/juju
|
core/cache/controller.go
|
removeMachine
|
func (c *Controller) removeMachine(ch RemoveMachine) error {
return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeMachine(ch) }))
}
|
go
|
func (c *Controller) removeMachine(ch RemoveMachine) error {
return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeMachine(ch) }))
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"removeMachine",
"(",
"ch",
"RemoveMachine",
")",
"error",
"{",
"return",
"errors",
".",
"Trace",
"(",
"c",
".",
"removeResident",
"(",
"ch",
".",
"ModelUUID",
",",
"func",
"(",
"m",
"*",
"Model",
")",
"error",
"{",
"return",
"m",
".",
"removeMachine",
"(",
"ch",
")",
"}",
")",
")",
"\n",
"}"
] |
// removeMachine removes the machine from the cached model.
// If the cache does not have the model loaded for the machine yet,
// then it will not have the machine cached.
|
[
"removeMachine",
"removes",
"the",
"machine",
"from",
"the",
"cached",
"model",
".",
"If",
"the",
"cache",
"does",
"not",
"have",
"the",
"model",
"loaded",
"for",
"the",
"machine",
"yet",
"then",
"it",
"will",
"not",
"have",
"the",
"machine",
"cached",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L251-L253
|
154,329 |
juju/juju
|
core/cache/controller.go
|
ensureModel
|
func (c *Controller) ensureModel(modelUUID string) *Model {
c.mu.Lock()
model, found := c.models[modelUUID]
if !found {
model = newModel(c.metrics, c.hub, c.manager.new())
c.models[modelUUID] = model
} else {
model.setStale(false)
}
c.mu.Unlock()
return model
}
|
go
|
func (c *Controller) ensureModel(modelUUID string) *Model {
c.mu.Lock()
model, found := c.models[modelUUID]
if !found {
model = newModel(c.metrics, c.hub, c.manager.new())
c.models[modelUUID] = model
} else {
model.setStale(false)
}
c.mu.Unlock()
return model
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"ensureModel",
"(",
"modelUUID",
"string",
")",
"*",
"Model",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"model",
",",
"found",
":=",
"c",
".",
"models",
"[",
"modelUUID",
"]",
"\n",
"if",
"!",
"found",
"{",
"model",
"=",
"newModel",
"(",
"c",
".",
"metrics",
",",
"c",
".",
"hub",
",",
"c",
".",
"manager",
".",
"new",
"(",
")",
")",
"\n",
"c",
".",
"models",
"[",
"modelUUID",
"]",
"=",
"model",
"\n",
"}",
"else",
"{",
"model",
".",
"setStale",
"(",
"false",
")",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"model",
"\n",
"}"
] |
// ensureModel retrieves the cached model for the input UUID,
// or adds it if not found.
// It is likely that we will receive a change update for the model before we
// get an update for one of its entities, but the cache needs to be resilient
// enough to make sure that we can handle when this is not the case.
// No model returned by this method is ever considered to be stale.
|
[
"ensureModel",
"retrieves",
"the",
"cached",
"model",
"for",
"the",
"input",
"UUID",
"or",
"adds",
"it",
"if",
"not",
"found",
".",
"It",
"is",
"likely",
"that",
"we",
"will",
"receive",
"a",
"change",
"update",
"for",
"the",
"model",
"before",
"we",
"get",
"an",
"update",
"for",
"one",
"of",
"its",
"entities",
"but",
"the",
"cache",
"needs",
"to",
"be",
"resilient",
"enough",
"to",
"make",
"sure",
"that",
"we",
"can",
"handle",
"when",
"this",
"is",
"not",
"the",
"case",
".",
"No",
"model",
"returned",
"by",
"this",
"method",
"is",
"ever",
"considered",
"to",
"be",
"stale",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/controller.go#L273-L286
|
154,330 |
juju/juju
|
cmd/juju/common/cloud.go
|
IsChooseCloudRegionError
|
func IsChooseCloudRegionError(err error) bool {
_, ok := errors.Cause(err).(chooseCloudRegionError)
return ok
}
|
go
|
func IsChooseCloudRegionError(err error) bool {
_, ok := errors.Cause(err).(chooseCloudRegionError)
return ok
}
|
[
"func",
"IsChooseCloudRegionError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"chooseCloudRegionError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] |
// IsChooseCloudRegionError reports whether or not the given
// error was returned from ChooseCloudRegion.
|
[
"IsChooseCloudRegionError",
"reports",
"whether",
"or",
"not",
"the",
"given",
"error",
"was",
"returned",
"from",
"ChooseCloudRegion",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L24-L27
|
154,331 |
juju/juju
|
cmd/juju/common/cloud.go
|
CloudOrProvider
|
func CloudOrProvider(cloudName string, cloudByNameFunc func(string) (*jujucloud.Cloud, error)) (cloud *jujucloud.Cloud, err error) {
if cloud, err = cloudByNameFunc(cloudName); err != nil {
if !errors.IsNotFound(err) {
return nil, err
}
builtInClouds, err := BuiltInClouds()
if err != nil {
return nil, errors.Trace(err)
}
if builtIn, ok := builtInClouds[cloudName]; !ok {
return nil, errors.NotValidf("cloud %v", cloudName)
} else {
cloud = &builtIn
}
}
return cloud, nil
}
|
go
|
func CloudOrProvider(cloudName string, cloudByNameFunc func(string) (*jujucloud.Cloud, error)) (cloud *jujucloud.Cloud, err error) {
if cloud, err = cloudByNameFunc(cloudName); err != nil {
if !errors.IsNotFound(err) {
return nil, err
}
builtInClouds, err := BuiltInClouds()
if err != nil {
return nil, errors.Trace(err)
}
if builtIn, ok := builtInClouds[cloudName]; !ok {
return nil, errors.NotValidf("cloud %v", cloudName)
} else {
cloud = &builtIn
}
}
return cloud, nil
}
|
[
"func",
"CloudOrProvider",
"(",
"cloudName",
"string",
",",
"cloudByNameFunc",
"func",
"(",
"string",
")",
"(",
"*",
"jujucloud",
".",
"Cloud",
",",
"error",
")",
")",
"(",
"cloud",
"*",
"jujucloud",
".",
"Cloud",
",",
"err",
"error",
")",
"{",
"if",
"cloud",
",",
"err",
"=",
"cloudByNameFunc",
"(",
"cloudName",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"builtInClouds",
",",
"err",
":=",
"BuiltInClouds",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"builtIn",
",",
"ok",
":=",
"builtInClouds",
"[",
"cloudName",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"cloudName",
")",
"\n",
"}",
"else",
"{",
"cloud",
"=",
"&",
"builtIn",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"cloud",
",",
"nil",
"\n",
"}"
] |
// CloudOrProvider finds and returns cloud or provider.
|
[
"CloudOrProvider",
"finds",
"and",
"returns",
"cloud",
"or",
"provider",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L30-L46
|
154,332 |
juju/juju
|
cmd/juju/common/cloud.go
|
ChooseCloudRegion
|
func ChooseCloudRegion(cloud jujucloud.Cloud, regionName string) (jujucloud.Region, error) {
if regionName != "" {
region, err := jujucloud.RegionByName(cloud.Regions, regionName)
if err != nil {
return jujucloud.Region{}, errors.Trace(chooseCloudRegionError{err})
}
return *region, nil
}
if len(cloud.Regions) > 0 {
// No region was specified, use the first region in the list.
return cloud.Regions[0], nil
}
return jujucloud.Region{
"", // no region name
cloud.Endpoint,
cloud.IdentityEndpoint,
cloud.StorageEndpoint,
}, nil
}
|
go
|
func ChooseCloudRegion(cloud jujucloud.Cloud, regionName string) (jujucloud.Region, error) {
if regionName != "" {
region, err := jujucloud.RegionByName(cloud.Regions, regionName)
if err != nil {
return jujucloud.Region{}, errors.Trace(chooseCloudRegionError{err})
}
return *region, nil
}
if len(cloud.Regions) > 0 {
// No region was specified, use the first region in the list.
return cloud.Regions[0], nil
}
return jujucloud.Region{
"", // no region name
cloud.Endpoint,
cloud.IdentityEndpoint,
cloud.StorageEndpoint,
}, nil
}
|
[
"func",
"ChooseCloudRegion",
"(",
"cloud",
"jujucloud",
".",
"Cloud",
",",
"regionName",
"string",
")",
"(",
"jujucloud",
".",
"Region",
",",
"error",
")",
"{",
"if",
"regionName",
"!=",
"\"",
"\"",
"{",
"region",
",",
"err",
":=",
"jujucloud",
".",
"RegionByName",
"(",
"cloud",
".",
"Regions",
",",
"regionName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jujucloud",
".",
"Region",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"chooseCloudRegionError",
"{",
"err",
"}",
")",
"\n",
"}",
"\n",
"return",
"*",
"region",
",",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"cloud",
".",
"Regions",
")",
">",
"0",
"{",
"// No region was specified, use the first region in the list.",
"return",
"cloud",
".",
"Regions",
"[",
"0",
"]",
",",
"nil",
"\n",
"}",
"\n",
"return",
"jujucloud",
".",
"Region",
"{",
"\"",
"\"",
",",
"// no region name",
"cloud",
".",
"Endpoint",
",",
"cloud",
".",
"IdentityEndpoint",
",",
"cloud",
".",
"StorageEndpoint",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// ChooseCloudRegion returns the cloud.Region to use, based on the specified
// region name. If no region name is specified, and there is at least one
// region, we use the first region in the list. If there are no regions, then
// we return a region with no name, having the same endpoints as the cloud.
|
[
"ChooseCloudRegion",
"returns",
"the",
"cloud",
".",
"Region",
"to",
"use",
"based",
"on",
"the",
"specified",
"region",
"name",
".",
"If",
"no",
"region",
"name",
"is",
"specified",
"and",
"there",
"is",
"at",
"least",
"one",
"region",
"we",
"use",
"the",
"first",
"region",
"in",
"the",
"list",
".",
"If",
"there",
"are",
"no",
"regions",
"then",
"we",
"return",
"a",
"region",
"with",
"no",
"name",
"having",
"the",
"same",
"endpoints",
"as",
"the",
"cloud",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L52-L70
|
154,333 |
juju/juju
|
cmd/juju/common/cloud.go
|
BuiltInClouds
|
func BuiltInClouds() (map[string]jujucloud.Cloud, error) {
allClouds := make(map[string]jujucloud.Cloud)
for _, providerType := range environs.RegisteredProviders() {
p, err := environs.Provider(providerType)
if err != nil {
return nil, errors.Trace(err)
}
detector, ok := p.(environs.CloudDetector)
if !ok {
continue
}
clouds, err := detector.DetectClouds()
if err != nil {
return nil, errors.Annotatef(
err, "detecting clouds for provider %q",
providerType,
)
}
for _, cloud := range clouds {
allClouds[cloud.Name] = cloud
}
}
return allClouds, nil
}
|
go
|
func BuiltInClouds() (map[string]jujucloud.Cloud, error) {
allClouds := make(map[string]jujucloud.Cloud)
for _, providerType := range environs.RegisteredProviders() {
p, err := environs.Provider(providerType)
if err != nil {
return nil, errors.Trace(err)
}
detector, ok := p.(environs.CloudDetector)
if !ok {
continue
}
clouds, err := detector.DetectClouds()
if err != nil {
return nil, errors.Annotatef(
err, "detecting clouds for provider %q",
providerType,
)
}
for _, cloud := range clouds {
allClouds[cloud.Name] = cloud
}
}
return allClouds, nil
}
|
[
"func",
"BuiltInClouds",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"jujucloud",
".",
"Cloud",
",",
"error",
")",
"{",
"allClouds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"jujucloud",
".",
"Cloud",
")",
"\n",
"for",
"_",
",",
"providerType",
":=",
"range",
"environs",
".",
"RegisteredProviders",
"(",
")",
"{",
"p",
",",
"err",
":=",
"environs",
".",
"Provider",
"(",
"providerType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"detector",
",",
"ok",
":=",
"p",
".",
"(",
"environs",
".",
"CloudDetector",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"clouds",
",",
"err",
":=",
"detector",
".",
"DetectClouds",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"providerType",
",",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"cloud",
":=",
"range",
"clouds",
"{",
"allClouds",
"[",
"cloud",
".",
"Name",
"]",
"=",
"cloud",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allClouds",
",",
"nil",
"\n",
"}"
] |
// BuiltInClouds returns cloud information for those
// providers which are built in to Juju.
|
[
"BuiltInClouds",
"returns",
"cloud",
"information",
"for",
"those",
"providers",
"which",
"are",
"built",
"in",
"to",
"Juju",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L74-L97
|
154,334 |
juju/juju
|
cmd/juju/common/cloud.go
|
CloudByName
|
func CloudByName(cloudName string) (*jujucloud.Cloud, error) {
cloud, err := jujucloud.CloudByName(cloudName)
if err != nil {
if errors.IsNotFound(err) {
// Check built in clouds like localhost (lxd).
builtinClouds, err := BuiltInClouds()
if err != nil {
return nil, errors.Trace(err)
}
aCloud, found := builtinClouds[cloudName]
if !found {
return nil, errors.NotFoundf("cloud %s", cloudName)
}
return &aCloud, nil
}
return nil, errors.Trace(err)
}
return cloud, nil
}
|
go
|
func CloudByName(cloudName string) (*jujucloud.Cloud, error) {
cloud, err := jujucloud.CloudByName(cloudName)
if err != nil {
if errors.IsNotFound(err) {
// Check built in clouds like localhost (lxd).
builtinClouds, err := BuiltInClouds()
if err != nil {
return nil, errors.Trace(err)
}
aCloud, found := builtinClouds[cloudName]
if !found {
return nil, errors.NotFoundf("cloud %s", cloudName)
}
return &aCloud, nil
}
return nil, errors.Trace(err)
}
return cloud, nil
}
|
[
"func",
"CloudByName",
"(",
"cloudName",
"string",
")",
"(",
"*",
"jujucloud",
".",
"Cloud",
",",
"error",
")",
"{",
"cloud",
",",
"err",
":=",
"jujucloud",
".",
"CloudByName",
"(",
"cloudName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"// Check built in clouds like localhost (lxd).",
"builtinClouds",
",",
"err",
":=",
"BuiltInClouds",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"aCloud",
",",
"found",
":=",
"builtinClouds",
"[",
"cloudName",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"cloudName",
")",
"\n",
"}",
"\n",
"return",
"&",
"aCloud",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"cloud",
",",
"nil",
"\n",
"}"
] |
// CloudByName returns a cloud for given name
// regardless of whether it's public, private or builtin cloud.
// Not to be confused with cloud.CloudByName which does not cater
// for built-in clouds like localhost.
|
[
"CloudByName",
"returns",
"a",
"cloud",
"for",
"given",
"name",
"regardless",
"of",
"whether",
"it",
"s",
"public",
"private",
"or",
"builtin",
"cloud",
".",
"Not",
"to",
"be",
"confused",
"with",
"cloud",
".",
"CloudByName",
"which",
"does",
"not",
"cater",
"for",
"built",
"-",
"in",
"clouds",
"like",
"localhost",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L103-L121
|
154,335 |
juju/juju
|
cmd/juju/common/cloud.go
|
CloudSchemaByType
|
func CloudSchemaByType(cloudType string) (environschema.Fields, error) {
provider, err := environs.Provider(cloudType)
if err != nil {
return nil, err
}
ps, ok := provider.(environs.ProviderSchema)
if !ok {
return nil, errors.NotImplementedf("environs.ProviderSchema")
}
providerSchema := ps.Schema()
if providerSchema == nil {
return nil, errors.New("Failed to retrieve Provider Schema")
}
return providerSchema, nil
}
|
go
|
func CloudSchemaByType(cloudType string) (environschema.Fields, error) {
provider, err := environs.Provider(cloudType)
if err != nil {
return nil, err
}
ps, ok := provider.(environs.ProviderSchema)
if !ok {
return nil, errors.NotImplementedf("environs.ProviderSchema")
}
providerSchema := ps.Schema()
if providerSchema == nil {
return nil, errors.New("Failed to retrieve Provider Schema")
}
return providerSchema, nil
}
|
[
"func",
"CloudSchemaByType",
"(",
"cloudType",
"string",
")",
"(",
"environschema",
".",
"Fields",
",",
"error",
")",
"{",
"provider",
",",
"err",
":=",
"environs",
".",
"Provider",
"(",
"cloudType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ps",
",",
"ok",
":=",
"provider",
".",
"(",
"environs",
".",
"ProviderSchema",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NotImplementedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"providerSchema",
":=",
"ps",
".",
"Schema",
"(",
")",
"\n",
"if",
"providerSchema",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"providerSchema",
",",
"nil",
"\n",
"}"
] |
// CloudSchemaByType returns the Schema for a given cloud type.
// If the ProviderSchema is not implemented for the given cloud
// type, a NotFound error is returned.
|
[
"CloudSchemaByType",
"returns",
"the",
"Schema",
"for",
"a",
"given",
"cloud",
"type",
".",
"If",
"the",
"ProviderSchema",
"is",
"not",
"implemented",
"for",
"the",
"given",
"cloud",
"type",
"a",
"NotFound",
"error",
"is",
"returned",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L126-L140
|
154,336 |
juju/juju
|
cmd/juju/common/cloud.go
|
ProviderConfigSchemaSourceByType
|
func ProviderConfigSchemaSourceByType(cloudType string) (config.ConfigSchemaSource, error) {
provider, err := environs.Provider(cloudType)
if err != nil {
return nil, err
}
if cs, ok := provider.(config.ConfigSchemaSource); ok {
return cs, nil
}
return nil, errors.NotImplementedf("config.ConfigSource")
}
|
go
|
func ProviderConfigSchemaSourceByType(cloudType string) (config.ConfigSchemaSource, error) {
provider, err := environs.Provider(cloudType)
if err != nil {
return nil, err
}
if cs, ok := provider.(config.ConfigSchemaSource); ok {
return cs, nil
}
return nil, errors.NotImplementedf("config.ConfigSource")
}
|
[
"func",
"ProviderConfigSchemaSourceByType",
"(",
"cloudType",
"string",
")",
"(",
"config",
".",
"ConfigSchemaSource",
",",
"error",
")",
"{",
"provider",
",",
"err",
":=",
"environs",
".",
"Provider",
"(",
"cloudType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"cs",
",",
"ok",
":=",
"provider",
".",
"(",
"config",
".",
"ConfigSchemaSource",
")",
";",
"ok",
"{",
"return",
"cs",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"NotImplementedf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// ProviderConfigSchemaSourceByType returns a config.ConfigSchemaSource
// for the environ provider, found for the given cloud type, or an error.
|
[
"ProviderConfigSchemaSourceByType",
"returns",
"a",
"config",
".",
"ConfigSchemaSource",
"for",
"the",
"environ",
"provider",
"found",
"for",
"the",
"given",
"cloud",
"type",
"or",
"an",
"error",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/cloud.go#L144-L153
|
154,337 |
juju/juju
|
worker/gate/manifold.go
|
Unlock
|
func (l *lock) Unlock() {
l.mu.Lock()
defer l.mu.Unlock()
select {
case <-l.ch:
default:
close(l.ch)
}
}
|
go
|
func (l *lock) Unlock() {
l.mu.Lock()
defer l.mu.Unlock()
select {
case <-l.ch:
default:
close(l.ch)
}
}
|
[
"func",
"(",
"l",
"*",
"lock",
")",
"Unlock",
"(",
")",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"l",
".",
"ch",
":",
"default",
":",
"close",
"(",
"l",
".",
"ch",
")",
"\n",
"}",
"\n",
"}"
] |
// Unlock implements Unlocker.
|
[
"Unlock",
"implements",
"Unlocker",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/gate/manifold.go#L82-L90
|
154,338 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeParams
|
func VolumeParams(
v state.Volume,
storageInstance state.StorageInstance,
modelUUID, controllerUUID string,
environConfig *config.Config,
poolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
) (params.VolumeParams, error) {
var pool string
var size uint64
if stateVolumeParams, ok := v.Params(); ok {
pool = stateVolumeParams.Pool
size = stateVolumeParams.Size
} else {
volumeInfo, err := v.Info()
if err != nil {
return params.VolumeParams{}, errors.Trace(err)
}
pool = volumeInfo.Pool
size = volumeInfo.Size
}
volumeTags, err := StorageTags(storageInstance, modelUUID, controllerUUID, environConfig)
if err != nil {
return params.VolumeParams{}, errors.Annotate(err, "computing storage tags")
}
providerType, cfg, err := StoragePoolConfig(pool, poolManager, registry)
if err != nil {
return params.VolumeParams{}, errors.Trace(err)
}
return params.VolumeParams{
v.Tag().String(),
size,
string(providerType),
cfg.Attrs(),
volumeTags,
nil, // attachment params set by the caller
}, nil
}
|
go
|
func VolumeParams(
v state.Volume,
storageInstance state.StorageInstance,
modelUUID, controllerUUID string,
environConfig *config.Config,
poolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
) (params.VolumeParams, error) {
var pool string
var size uint64
if stateVolumeParams, ok := v.Params(); ok {
pool = stateVolumeParams.Pool
size = stateVolumeParams.Size
} else {
volumeInfo, err := v.Info()
if err != nil {
return params.VolumeParams{}, errors.Trace(err)
}
pool = volumeInfo.Pool
size = volumeInfo.Size
}
volumeTags, err := StorageTags(storageInstance, modelUUID, controllerUUID, environConfig)
if err != nil {
return params.VolumeParams{}, errors.Annotate(err, "computing storage tags")
}
providerType, cfg, err := StoragePoolConfig(pool, poolManager, registry)
if err != nil {
return params.VolumeParams{}, errors.Trace(err)
}
return params.VolumeParams{
v.Tag().String(),
size,
string(providerType),
cfg.Attrs(),
volumeTags,
nil, // attachment params set by the caller
}, nil
}
|
[
"func",
"VolumeParams",
"(",
"v",
"state",
".",
"Volume",
",",
"storageInstance",
"state",
".",
"StorageInstance",
",",
"modelUUID",
",",
"controllerUUID",
"string",
",",
"environConfig",
"*",
"config",
".",
"Config",
",",
"poolManager",
"poolmanager",
".",
"PoolManager",
",",
"registry",
"storage",
".",
"ProviderRegistry",
",",
")",
"(",
"params",
".",
"VolumeParams",
",",
"error",
")",
"{",
"var",
"pool",
"string",
"\n",
"var",
"size",
"uint64",
"\n",
"if",
"stateVolumeParams",
",",
"ok",
":=",
"v",
".",
"Params",
"(",
")",
";",
"ok",
"{",
"pool",
"=",
"stateVolumeParams",
".",
"Pool",
"\n",
"size",
"=",
"stateVolumeParams",
".",
"Size",
"\n",
"}",
"else",
"{",
"volumeInfo",
",",
"err",
":=",
"v",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"VolumeParams",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"pool",
"=",
"volumeInfo",
".",
"Pool",
"\n",
"size",
"=",
"volumeInfo",
".",
"Size",
"\n",
"}",
"\n\n",
"volumeTags",
",",
"err",
":=",
"StorageTags",
"(",
"storageInstance",
",",
"modelUUID",
",",
"controllerUUID",
",",
"environConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"VolumeParams",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"providerType",
",",
"cfg",
",",
"err",
":=",
"StoragePoolConfig",
"(",
"pool",
",",
"poolManager",
",",
"registry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"VolumeParams",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"params",
".",
"VolumeParams",
"{",
"v",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
",",
"size",
",",
"string",
"(",
"providerType",
")",
",",
"cfg",
".",
"Attrs",
"(",
")",
",",
"volumeTags",
",",
"nil",
",",
"// attachment params set by the caller",
"}",
",",
"nil",
"\n",
"}"
] |
// VolumeParams returns the parameters for creating or destroying
// the given volume.
|
[
"VolumeParams",
"returns",
"the",
"parameters",
"for",
"creating",
"or",
"destroying",
"the",
"given",
"volume",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L19-L59
|
154,339 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
StoragePoolConfig
|
func StoragePoolConfig(name string, poolManager poolmanager.PoolManager, registry storage.ProviderRegistry) (storage.ProviderType, *storage.Config, error) {
pool, err := poolManager.Get(name)
if errors.IsNotFound(err) {
// If not a storage pool, then maybe a provider type.
providerType := storage.ProviderType(name)
if _, err1 := registry.StorageProvider(providerType); err1 != nil {
return "", nil, errors.Trace(err)
}
return providerType, &storage.Config{}, nil
} else if err != nil {
return "", nil, errors.Annotatef(err, "getting pool %q", name)
}
return pool.Provider(), pool, nil
}
|
go
|
func StoragePoolConfig(name string, poolManager poolmanager.PoolManager, registry storage.ProviderRegistry) (storage.ProviderType, *storage.Config, error) {
pool, err := poolManager.Get(name)
if errors.IsNotFound(err) {
// If not a storage pool, then maybe a provider type.
providerType := storage.ProviderType(name)
if _, err1 := registry.StorageProvider(providerType); err1 != nil {
return "", nil, errors.Trace(err)
}
return providerType, &storage.Config{}, nil
} else if err != nil {
return "", nil, errors.Annotatef(err, "getting pool %q", name)
}
return pool.Provider(), pool, nil
}
|
[
"func",
"StoragePoolConfig",
"(",
"name",
"string",
",",
"poolManager",
"poolmanager",
".",
"PoolManager",
",",
"registry",
"storage",
".",
"ProviderRegistry",
")",
"(",
"storage",
".",
"ProviderType",
",",
"*",
"storage",
".",
"Config",
",",
"error",
")",
"{",
"pool",
",",
"err",
":=",
"poolManager",
".",
"Get",
"(",
"name",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"// If not a storage pool, then maybe a provider type.",
"providerType",
":=",
"storage",
".",
"ProviderType",
"(",
"name",
")",
"\n",
"if",
"_",
",",
"err1",
":=",
"registry",
".",
"StorageProvider",
"(",
"providerType",
")",
";",
"err1",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"providerType",
",",
"&",
"storage",
".",
"Config",
"{",
"}",
",",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"pool",
".",
"Provider",
"(",
")",
",",
"pool",
",",
"nil",
"\n",
"}"
] |
// StoragePoolConfig returns the storage provider type and
// configuration for a named storage pool. If there is no
// such pool with the specified name, but it identifies a
// storage provider, then that type will be returned with a
// nil configuration.
|
[
"StoragePoolConfig",
"returns",
"the",
"storage",
"provider",
"type",
"and",
"configuration",
"for",
"a",
"named",
"storage",
"pool",
".",
"If",
"there",
"is",
"no",
"such",
"pool",
"with",
"the",
"specified",
"name",
"but",
"it",
"identifies",
"a",
"storage",
"provider",
"then",
"that",
"type",
"will",
"be",
"returned",
"with",
"a",
"nil",
"configuration",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L66-L79
|
154,340 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumesToState
|
func VolumesToState(in []params.Volume) (map[names.VolumeTag]state.VolumeInfo, error) {
m := make(map[names.VolumeTag]state.VolumeInfo)
for _, v := range in {
tag, volumeInfo, err := VolumeToState(v)
if err != nil {
return nil, errors.Trace(err)
}
m[tag] = volumeInfo
}
return m, nil
}
|
go
|
func VolumesToState(in []params.Volume) (map[names.VolumeTag]state.VolumeInfo, error) {
m := make(map[names.VolumeTag]state.VolumeInfo)
for _, v := range in {
tag, volumeInfo, err := VolumeToState(v)
if err != nil {
return nil, errors.Trace(err)
}
m[tag] = volumeInfo
}
return m, nil
}
|
[
"func",
"VolumesToState",
"(",
"in",
"[",
"]",
"params",
".",
"Volume",
")",
"(",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"state",
".",
"VolumeInfo",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"state",
".",
"VolumeInfo",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"in",
"{",
"tag",
",",
"volumeInfo",
",",
"err",
":=",
"VolumeToState",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"m",
"[",
"tag",
"]",
"=",
"volumeInfo",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// VolumesToState converts a slice of params.Volume to a mapping
// of volume tags to state.VolumeInfo.
|
[
"VolumesToState",
"converts",
"a",
"slice",
"of",
"params",
".",
"Volume",
"to",
"a",
"mapping",
"of",
"volume",
"tags",
"to",
"state",
".",
"VolumeInfo",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L83-L93
|
154,341 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeToState
|
func VolumeToState(v params.Volume) (names.VolumeTag, state.VolumeInfo, error) {
if v.VolumeTag == "" {
return names.VolumeTag{}, state.VolumeInfo{}, errors.New("Tag is empty")
}
volumeTag, err := names.ParseVolumeTag(v.VolumeTag)
if err != nil {
return names.VolumeTag{}, state.VolumeInfo{}, errors.Trace(err)
}
return volumeTag, state.VolumeInfo{
v.Info.HardwareId,
v.Info.WWN,
v.Info.Size,
"", // pool is set by state
v.Info.VolumeId,
v.Info.Persistent,
}, nil
}
|
go
|
func VolumeToState(v params.Volume) (names.VolumeTag, state.VolumeInfo, error) {
if v.VolumeTag == "" {
return names.VolumeTag{}, state.VolumeInfo{}, errors.New("Tag is empty")
}
volumeTag, err := names.ParseVolumeTag(v.VolumeTag)
if err != nil {
return names.VolumeTag{}, state.VolumeInfo{}, errors.Trace(err)
}
return volumeTag, state.VolumeInfo{
v.Info.HardwareId,
v.Info.WWN,
v.Info.Size,
"", // pool is set by state
v.Info.VolumeId,
v.Info.Persistent,
}, nil
}
|
[
"func",
"VolumeToState",
"(",
"v",
"params",
".",
"Volume",
")",
"(",
"names",
".",
"VolumeTag",
",",
"state",
".",
"VolumeInfo",
",",
"error",
")",
"{",
"if",
"v",
".",
"VolumeTag",
"==",
"\"",
"\"",
"{",
"return",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"state",
".",
"VolumeInfo",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"volumeTag",
",",
"err",
":=",
"names",
".",
"ParseVolumeTag",
"(",
"v",
".",
"VolumeTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"state",
".",
"VolumeInfo",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"volumeTag",
",",
"state",
".",
"VolumeInfo",
"{",
"v",
".",
"Info",
".",
"HardwareId",
",",
"v",
".",
"Info",
".",
"WWN",
",",
"v",
".",
"Info",
".",
"Size",
",",
"\"",
"\"",
",",
"// pool is set by state",
"v",
".",
"Info",
".",
"VolumeId",
",",
"v",
".",
"Info",
".",
"Persistent",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// VolumeToState converts a params.Volume to state.VolumeInfo
// and names.VolumeTag.
|
[
"VolumeToState",
"converts",
"a",
"params",
".",
"Volume",
"to",
"state",
".",
"VolumeInfo",
"and",
"names",
".",
"VolumeTag",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L97-L113
|
154,342 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeFromState
|
func VolumeFromState(v state.Volume) (params.Volume, error) {
info, err := v.Info()
if err != nil {
return params.Volume{}, errors.Trace(err)
}
return params.Volume{
v.VolumeTag().String(),
VolumeInfoFromState(info),
}, nil
}
|
go
|
func VolumeFromState(v state.Volume) (params.Volume, error) {
info, err := v.Info()
if err != nil {
return params.Volume{}, errors.Trace(err)
}
return params.Volume{
v.VolumeTag().String(),
VolumeInfoFromState(info),
}, nil
}
|
[
"func",
"VolumeFromState",
"(",
"v",
"state",
".",
"Volume",
")",
"(",
"params",
".",
"Volume",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"v",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"Volume",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"params",
".",
"Volume",
"{",
"v",
".",
"VolumeTag",
"(",
")",
".",
"String",
"(",
")",
",",
"VolumeInfoFromState",
"(",
"info",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// VolumeFromState converts a state.Volume to params.Volume.
|
[
"VolumeFromState",
"converts",
"a",
"state",
".",
"Volume",
"to",
"params",
".",
"Volume",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L116-L125
|
154,343 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeInfoFromState
|
func VolumeInfoFromState(info state.VolumeInfo) params.VolumeInfo {
return params.VolumeInfo{
info.VolumeId,
info.HardwareId,
info.WWN,
info.Pool,
info.Size,
info.Persistent,
}
}
|
go
|
func VolumeInfoFromState(info state.VolumeInfo) params.VolumeInfo {
return params.VolumeInfo{
info.VolumeId,
info.HardwareId,
info.WWN,
info.Pool,
info.Size,
info.Persistent,
}
}
|
[
"func",
"VolumeInfoFromState",
"(",
"info",
"state",
".",
"VolumeInfo",
")",
"params",
".",
"VolumeInfo",
"{",
"return",
"params",
".",
"VolumeInfo",
"{",
"info",
".",
"VolumeId",
",",
"info",
".",
"HardwareId",
",",
"info",
".",
"WWN",
",",
"info",
".",
"Pool",
",",
"info",
".",
"Size",
",",
"info",
".",
"Persistent",
",",
"}",
"\n",
"}"
] |
// VolumeInfoFromState converts a state.VolumeInfo to params.VolumeInfo.
|
[
"VolumeInfoFromState",
"converts",
"a",
"state",
".",
"VolumeInfo",
"to",
"params",
".",
"VolumeInfo",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L128-L137
|
154,344 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeAttachmentPlanFromState
|
func VolumeAttachmentPlanFromState(v state.VolumeAttachmentPlan) (params.VolumeAttachmentPlan, error) {
planInfo, err := v.PlanInfo()
if err != nil {
return params.VolumeAttachmentPlan{}, errors.Trace(err)
}
blockInfo, err := v.BlockDeviceInfo()
if err != nil {
if !errors.IsNotFound(err) {
return params.VolumeAttachmentPlan{}, errors.Trace(err)
}
}
return params.VolumeAttachmentPlan{
VolumeTag: v.Volume().String(),
MachineTag: v.Machine().String(),
Life: params.Life(v.Life().String()),
PlanInfo: VolumeAttachmentPlanInfoFromState(planInfo),
BlockDevice: VolumeAttachmentPlanBlockInfoFromState(blockInfo),
}, nil
}
|
go
|
func VolumeAttachmentPlanFromState(v state.VolumeAttachmentPlan) (params.VolumeAttachmentPlan, error) {
planInfo, err := v.PlanInfo()
if err != nil {
return params.VolumeAttachmentPlan{}, errors.Trace(err)
}
blockInfo, err := v.BlockDeviceInfo()
if err != nil {
if !errors.IsNotFound(err) {
return params.VolumeAttachmentPlan{}, errors.Trace(err)
}
}
return params.VolumeAttachmentPlan{
VolumeTag: v.Volume().String(),
MachineTag: v.Machine().String(),
Life: params.Life(v.Life().String()),
PlanInfo: VolumeAttachmentPlanInfoFromState(planInfo),
BlockDevice: VolumeAttachmentPlanBlockInfoFromState(blockInfo),
}, nil
}
|
[
"func",
"VolumeAttachmentPlanFromState",
"(",
"v",
"state",
".",
"VolumeAttachmentPlan",
")",
"(",
"params",
".",
"VolumeAttachmentPlan",
",",
"error",
")",
"{",
"planInfo",
",",
"err",
":=",
"v",
".",
"PlanInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"VolumeAttachmentPlan",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"blockInfo",
",",
"err",
":=",
"v",
".",
"BlockDeviceInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"params",
".",
"VolumeAttachmentPlan",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"params",
".",
"VolumeAttachmentPlan",
"{",
"VolumeTag",
":",
"v",
".",
"Volume",
"(",
")",
".",
"String",
"(",
")",
",",
"MachineTag",
":",
"v",
".",
"Machine",
"(",
")",
".",
"String",
"(",
")",
",",
"Life",
":",
"params",
".",
"Life",
"(",
"v",
".",
"Life",
"(",
")",
".",
"String",
"(",
")",
")",
",",
"PlanInfo",
":",
"VolumeAttachmentPlanInfoFromState",
"(",
"planInfo",
")",
",",
"BlockDevice",
":",
"VolumeAttachmentPlanBlockInfoFromState",
"(",
"blockInfo",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// VolumeAttachmentPlanFromState converts a state.VolumeAttachmentPlan to params.VolumeAttachmentPlan.
|
[
"VolumeAttachmentPlanFromState",
"converts",
"a",
"state",
".",
"VolumeAttachmentPlan",
"to",
"params",
".",
"VolumeAttachmentPlan",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L140-L159
|
154,345 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeAttachmentFromState
|
func VolumeAttachmentFromState(v state.VolumeAttachment) (params.VolumeAttachment, error) {
info, err := v.Info()
if err != nil {
return params.VolumeAttachment{}, errors.Trace(err)
}
return params.VolumeAttachment{
v.Volume().String(),
v.Host().String(),
VolumeAttachmentInfoFromState(info),
}, nil
}
|
go
|
func VolumeAttachmentFromState(v state.VolumeAttachment) (params.VolumeAttachment, error) {
info, err := v.Info()
if err != nil {
return params.VolumeAttachment{}, errors.Trace(err)
}
return params.VolumeAttachment{
v.Volume().String(),
v.Host().String(),
VolumeAttachmentInfoFromState(info),
}, nil
}
|
[
"func",
"VolumeAttachmentFromState",
"(",
"v",
"state",
".",
"VolumeAttachment",
")",
"(",
"params",
".",
"VolumeAttachment",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"v",
".",
"Info",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"VolumeAttachment",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"params",
".",
"VolumeAttachment",
"{",
"v",
".",
"Volume",
"(",
")",
".",
"String",
"(",
")",
",",
"v",
".",
"Host",
"(",
")",
".",
"String",
"(",
")",
",",
"VolumeAttachmentInfoFromState",
"(",
"info",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// VolumeAttachmentFromState converts a state.VolumeAttachment to params.VolumeAttachment.
|
[
"VolumeAttachmentFromState",
"converts",
"a",
"state",
".",
"VolumeAttachment",
"to",
"params",
".",
"VolumeAttachment",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L185-L195
|
154,346 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeAttachmentInfoFromState
|
func VolumeAttachmentInfoFromState(info state.VolumeAttachmentInfo) params.VolumeAttachmentInfo {
planInfo := ¶ms.VolumeAttachmentPlanInfo{}
if info.PlanInfo != nil {
planInfo.DeviceType = info.PlanInfo.DeviceType
planInfo.DeviceAttributes = info.PlanInfo.DeviceAttributes
} else {
planInfo = nil
}
return params.VolumeAttachmentInfo{
info.DeviceName,
info.DeviceLink,
info.BusAddress,
info.ReadOnly,
planInfo,
}
}
|
go
|
func VolumeAttachmentInfoFromState(info state.VolumeAttachmentInfo) params.VolumeAttachmentInfo {
planInfo := ¶ms.VolumeAttachmentPlanInfo{}
if info.PlanInfo != nil {
planInfo.DeviceType = info.PlanInfo.DeviceType
planInfo.DeviceAttributes = info.PlanInfo.DeviceAttributes
} else {
planInfo = nil
}
return params.VolumeAttachmentInfo{
info.DeviceName,
info.DeviceLink,
info.BusAddress,
info.ReadOnly,
planInfo,
}
}
|
[
"func",
"VolumeAttachmentInfoFromState",
"(",
"info",
"state",
".",
"VolumeAttachmentInfo",
")",
"params",
".",
"VolumeAttachmentInfo",
"{",
"planInfo",
":=",
"&",
"params",
".",
"VolumeAttachmentPlanInfo",
"{",
"}",
"\n",
"if",
"info",
".",
"PlanInfo",
"!=",
"nil",
"{",
"planInfo",
".",
"DeviceType",
"=",
"info",
".",
"PlanInfo",
".",
"DeviceType",
"\n",
"planInfo",
".",
"DeviceAttributes",
"=",
"info",
".",
"PlanInfo",
".",
"DeviceAttributes",
"\n",
"}",
"else",
"{",
"planInfo",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"params",
".",
"VolumeAttachmentInfo",
"{",
"info",
".",
"DeviceName",
",",
"info",
".",
"DeviceLink",
",",
"info",
".",
"BusAddress",
",",
"info",
".",
"ReadOnly",
",",
"planInfo",
",",
"}",
"\n",
"}"
] |
// VolumeAttachmentInfoFromState converts a state.VolumeAttachmentInfo to params.VolumeAttachmentInfo.
|
[
"VolumeAttachmentInfoFromState",
"converts",
"a",
"state",
".",
"VolumeAttachmentInfo",
"to",
"params",
".",
"VolumeAttachmentInfo",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L198-L213
|
154,347 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeAttachmentInfosToState
|
func VolumeAttachmentInfosToState(in map[string]params.VolumeAttachmentInfo) (map[names.VolumeTag]state.VolumeAttachmentInfo, error) {
m := make(map[names.VolumeTag]state.VolumeAttachmentInfo)
for k, v := range in {
volumeTag, err := names.ParseVolumeTag(k)
if err != nil {
return nil, errors.Trace(err)
}
m[volumeTag] = VolumeAttachmentInfoToState(v)
}
return m, nil
}
|
go
|
func VolumeAttachmentInfosToState(in map[string]params.VolumeAttachmentInfo) (map[names.VolumeTag]state.VolumeAttachmentInfo, error) {
m := make(map[names.VolumeTag]state.VolumeAttachmentInfo)
for k, v := range in {
volumeTag, err := names.ParseVolumeTag(k)
if err != nil {
return nil, errors.Trace(err)
}
m[volumeTag] = VolumeAttachmentInfoToState(v)
}
return m, nil
}
|
[
"func",
"VolumeAttachmentInfosToState",
"(",
"in",
"map",
"[",
"string",
"]",
"params",
".",
"VolumeAttachmentInfo",
")",
"(",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"state",
".",
"VolumeAttachmentInfo",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"names",
".",
"VolumeTag",
"]",
"state",
".",
"VolumeAttachmentInfo",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"in",
"{",
"volumeTag",
",",
"err",
":=",
"names",
".",
"ParseVolumeTag",
"(",
"k",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"m",
"[",
"volumeTag",
"]",
"=",
"VolumeAttachmentInfoToState",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// VolumeAttachmentInfosToState converts a map of volume tags to
// params.VolumeAttachmentInfo to a map of volume tags to
// state.VolumeAttachmentInfo.
|
[
"VolumeAttachmentInfosToState",
"converts",
"a",
"map",
"of",
"volume",
"tags",
"to",
"params",
".",
"VolumeAttachmentInfo",
"to",
"a",
"map",
"of",
"volume",
"tags",
"to",
"state",
".",
"VolumeAttachmentInfo",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L218-L228
|
154,348 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeAttachmentToState
|
func VolumeAttachmentToState(in params.VolumeAttachment) (names.MachineTag, names.VolumeTag, state.VolumeAttachmentInfo, error) {
machineTag, err := names.ParseMachineTag(in.MachineTag)
if err != nil {
return names.MachineTag{}, names.VolumeTag{}, state.VolumeAttachmentInfo{}, err
}
volumeTag, err := names.ParseVolumeTag(in.VolumeTag)
if err != nil {
return names.MachineTag{}, names.VolumeTag{}, state.VolumeAttachmentInfo{}, err
}
info := VolumeAttachmentInfoToState(in.Info)
return machineTag, volumeTag, info, nil
}
|
go
|
func VolumeAttachmentToState(in params.VolumeAttachment) (names.MachineTag, names.VolumeTag, state.VolumeAttachmentInfo, error) {
machineTag, err := names.ParseMachineTag(in.MachineTag)
if err != nil {
return names.MachineTag{}, names.VolumeTag{}, state.VolumeAttachmentInfo{}, err
}
volumeTag, err := names.ParseVolumeTag(in.VolumeTag)
if err != nil {
return names.MachineTag{}, names.VolumeTag{}, state.VolumeAttachmentInfo{}, err
}
info := VolumeAttachmentInfoToState(in.Info)
return machineTag, volumeTag, info, nil
}
|
[
"func",
"VolumeAttachmentToState",
"(",
"in",
"params",
".",
"VolumeAttachment",
")",
"(",
"names",
".",
"MachineTag",
",",
"names",
".",
"VolumeTag",
",",
"state",
".",
"VolumeAttachmentInfo",
",",
"error",
")",
"{",
"machineTag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"in",
".",
"MachineTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"names",
".",
"MachineTag",
"{",
"}",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"state",
".",
"VolumeAttachmentInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"volumeTag",
",",
"err",
":=",
"names",
".",
"ParseVolumeTag",
"(",
"in",
".",
"VolumeTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"names",
".",
"MachineTag",
"{",
"}",
",",
"names",
".",
"VolumeTag",
"{",
"}",
",",
"state",
".",
"VolumeAttachmentInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"info",
":=",
"VolumeAttachmentInfoToState",
"(",
"in",
".",
"Info",
")",
"\n",
"return",
"machineTag",
",",
"volumeTag",
",",
"info",
",",
"nil",
"\n",
"}"
] |
// VolumeAttachmentToState converts a params.VolumeAttachment
// to a state.VolumeAttachmentInfo and tags.
|
[
"VolumeAttachmentToState",
"converts",
"a",
"params",
".",
"VolumeAttachment",
"to",
"a",
"state",
".",
"VolumeAttachmentInfo",
"and",
"tags",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L262-L273
|
154,349 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
VolumeAttachmentInfoToState
|
func VolumeAttachmentInfoToState(in params.VolumeAttachmentInfo) state.VolumeAttachmentInfo {
planInfo := &state.VolumeAttachmentPlanInfo{}
if in.PlanInfo != nil {
planInfo.DeviceAttributes = in.PlanInfo.DeviceAttributes
planInfo.DeviceType = in.PlanInfo.DeviceType
} else {
planInfo = nil
}
return state.VolumeAttachmentInfo{
in.DeviceName,
in.DeviceLink,
in.BusAddress,
in.ReadOnly,
planInfo,
}
}
|
go
|
func VolumeAttachmentInfoToState(in params.VolumeAttachmentInfo) state.VolumeAttachmentInfo {
planInfo := &state.VolumeAttachmentPlanInfo{}
if in.PlanInfo != nil {
planInfo.DeviceAttributes = in.PlanInfo.DeviceAttributes
planInfo.DeviceType = in.PlanInfo.DeviceType
} else {
planInfo = nil
}
return state.VolumeAttachmentInfo{
in.DeviceName,
in.DeviceLink,
in.BusAddress,
in.ReadOnly,
planInfo,
}
}
|
[
"func",
"VolumeAttachmentInfoToState",
"(",
"in",
"params",
".",
"VolumeAttachmentInfo",
")",
"state",
".",
"VolumeAttachmentInfo",
"{",
"planInfo",
":=",
"&",
"state",
".",
"VolumeAttachmentPlanInfo",
"{",
"}",
"\n",
"if",
"in",
".",
"PlanInfo",
"!=",
"nil",
"{",
"planInfo",
".",
"DeviceAttributes",
"=",
"in",
".",
"PlanInfo",
".",
"DeviceAttributes",
"\n",
"planInfo",
".",
"DeviceType",
"=",
"in",
".",
"PlanInfo",
".",
"DeviceType",
"\n",
"}",
"else",
"{",
"planInfo",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"state",
".",
"VolumeAttachmentInfo",
"{",
"in",
".",
"DeviceName",
",",
"in",
".",
"DeviceLink",
",",
"in",
".",
"BusAddress",
",",
"in",
".",
"ReadOnly",
",",
"planInfo",
",",
"}",
"\n",
"}"
] |
// VolumeAttachmentInfoToState converts a params.VolumeAttachmentInfo
// to a state.VolumeAttachmentInfo.
|
[
"VolumeAttachmentInfoToState",
"converts",
"a",
"params",
".",
"VolumeAttachmentInfo",
"to",
"a",
"state",
".",
"VolumeAttachmentInfo",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L289-L304
|
154,350 |
juju/juju
|
apiserver/common/storagecommon/volumes.go
|
ParseVolumeAttachmentIds
|
func ParseVolumeAttachmentIds(stringIds []string) ([]params.MachineStorageId, error) {
ids := make([]params.MachineStorageId, len(stringIds))
for i, s := range stringIds {
m, v, err := state.ParseVolumeAttachmentId(s)
if err != nil {
return nil, err
}
ids[i] = params.MachineStorageId{
MachineTag: m.String(),
AttachmentTag: v.String(),
}
}
return ids, nil
}
|
go
|
func ParseVolumeAttachmentIds(stringIds []string) ([]params.MachineStorageId, error) {
ids := make([]params.MachineStorageId, len(stringIds))
for i, s := range stringIds {
m, v, err := state.ParseVolumeAttachmentId(s)
if err != nil {
return nil, err
}
ids[i] = params.MachineStorageId{
MachineTag: m.String(),
AttachmentTag: v.String(),
}
}
return ids, nil
}
|
[
"func",
"ParseVolumeAttachmentIds",
"(",
"stringIds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"MachineStorageId",
",",
"error",
")",
"{",
"ids",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"MachineStorageId",
",",
"len",
"(",
"stringIds",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"stringIds",
"{",
"m",
",",
"v",
",",
"err",
":=",
"state",
".",
"ParseVolumeAttachmentId",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ids",
"[",
"i",
"]",
"=",
"params",
".",
"MachineStorageId",
"{",
"MachineTag",
":",
"m",
".",
"String",
"(",
")",
",",
"AttachmentTag",
":",
"v",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] |
// ParseVolumeAttachmentIds parses the strings, returning machine storage IDs.
|
[
"ParseVolumeAttachmentIds",
"parses",
"the",
"strings",
"returning",
"machine",
"storage",
"IDs",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/storagecommon/volumes.go#L307-L320
|
154,351 |
juju/juju
|
upgrades/steps_222.go
|
stateStepsFor222
|
func stateStepsFor222() []Step {
return []Step{
&upgradeStep{
description: "add environ-version to model docs",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddModelEnvironVersion()
},
},
}
}
|
go
|
func stateStepsFor222() []Step {
return []Step{
&upgradeStep{
description: "add environ-version to model docs",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddModelEnvironVersion()
},
},
}
}
|
[
"func",
"stateStepsFor222",
"(",
")",
"[",
"]",
"Step",
"{",
"return",
"[",
"]",
"Step",
"{",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"AddModelEnvironVersion",
"(",
")",
"\n",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] |
// stateStepsFor222 returns upgrade steps for Juju 2.2.2 that manipulate state directly.
|
[
"stateStepsFor222",
"returns",
"upgrade",
"steps",
"for",
"Juju",
"2",
".",
"2",
".",
"2",
"that",
"manipulate",
"state",
"directly",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_222.go#L7-L17
|
154,352 |
juju/juju
|
provider/vsphere/environ_network.go
|
OpenPorts
|
func (*environ) OpenPorts(rules []network.IngressRule) error {
return errors.Trace(errors.NotSupportedf("ClosePorts"))
}
|
go
|
func (*environ) OpenPorts(rules []network.IngressRule) error {
return errors.Trace(errors.NotSupportedf("ClosePorts"))
}
|
[
"func",
"(",
"*",
"environ",
")",
"OpenPorts",
"(",
"rules",
"[",
"]",
"network",
".",
"IngressRule",
")",
"error",
"{",
"return",
"errors",
".",
"Trace",
"(",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] |
// OpenPorts is part of the environs.Firewaller interface.
|
[
"OpenPorts",
"is",
"part",
"of",
"the",
"environs",
".",
"Firewaller",
"interface",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/vsphere/environ_network.go#L13-L15
|
154,353 |
juju/juju
|
provider/vsphere/environ_network.go
|
IngressRules
|
func (*environ) IngressRules() ([]network.IngressRule, error) {
return nil, errors.Trace(errors.NotSupportedf("Ports"))
}
|
go
|
func (*environ) IngressRules() ([]network.IngressRule, error) {
return nil, errors.Trace(errors.NotSupportedf("Ports"))
}
|
[
"func",
"(",
"*",
"environ",
")",
"IngressRules",
"(",
")",
"(",
"[",
"]",
"network",
".",
"IngressRule",
",",
"error",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] |
// IngressPorts is part of the environs.Firewaller interface.
|
[
"IngressPorts",
"is",
"part",
"of",
"the",
"environs",
".",
"Firewaller",
"interface",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/vsphere/environ_network.go#L23-L25
|
154,354 |
juju/juju
|
state/life_ns.go
|
destroyOp
|
func (nsLife_) destroyOp(entities mongo.Collection, docID string, update bson.D) (txn.Op, error) {
op, err := nsLife.aliveOp(entities, docID)
if err != nil {
return txn.Op{}, errors.Trace(err)
}
setDying := bson.D{{"$set", bson.D{{"life", Dying}}}}
op.Update = append(setDying, update...)
return op, nil
}
|
go
|
func (nsLife_) destroyOp(entities mongo.Collection, docID string, update bson.D) (txn.Op, error) {
op, err := nsLife.aliveOp(entities, docID)
if err != nil {
return txn.Op{}, errors.Trace(err)
}
setDying := bson.D{{"$set", bson.D{{"life", Dying}}}}
op.Update = append(setDying, update...)
return op, nil
}
|
[
"func",
"(",
"nsLife_",
")",
"destroyOp",
"(",
"entities",
"mongo",
".",
"Collection",
",",
"docID",
"string",
",",
"update",
"bson",
".",
"D",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"op",
",",
"err",
":=",
"nsLife",
".",
"aliveOp",
"(",
"entities",
",",
"docID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"setDying",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Dying",
"}",
"}",
"}",
"}",
"\n",
"op",
".",
"Update",
"=",
"append",
"(",
"setDying",
",",
"update",
"...",
")",
"\n",
"return",
"op",
",",
"nil",
"\n",
"}"
] |
// destroyOp returns errNotAlive if the identified entity is not Alive;
// or a txn.Op that will fail if the condition no longer holds, and
// otherwise set Life to Dying and make any other updates supplied in
// update.
|
[
"destroyOp",
"returns",
"errNotAlive",
"if",
"the",
"identified",
"entity",
"is",
"not",
"Alive",
";",
"or",
"a",
"txn",
".",
"Op",
"that",
"will",
"fail",
"if",
"the",
"condition",
"no",
"longer",
"holds",
"and",
"otherwise",
"set",
"Life",
"to",
"Dying",
"and",
"make",
"any",
"other",
"updates",
"supplied",
"in",
"update",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/life_ns.go#L31-L39
|
154,355 |
juju/juju
|
state/life_ns.go
|
dieOp
|
func (nsLife_) dieOp(entities mongo.Collection, docID string, update bson.D) (txn.Op, error) {
life, err := nsLife.read(entities, docID)
if errors.IsNotFound(err) {
return txn.Op{}, errAlreadyDead
} else if err != nil {
return txn.Op{}, errors.Trace(err)
}
switch life {
case Alive:
return txn.Op{}, errNotDying
case Dead:
return txn.Op{}, errAlreadyDead
}
setDead := bson.D{{"$set", bson.D{{"life", Dead}}}}
return txn.Op{
C: entities.Name(),
Id: docID,
Assert: nsLife.dying(),
Update: append(setDead, update...),
}, nil
}
|
go
|
func (nsLife_) dieOp(entities mongo.Collection, docID string, update bson.D) (txn.Op, error) {
life, err := nsLife.read(entities, docID)
if errors.IsNotFound(err) {
return txn.Op{}, errAlreadyDead
} else if err != nil {
return txn.Op{}, errors.Trace(err)
}
switch life {
case Alive:
return txn.Op{}, errNotDying
case Dead:
return txn.Op{}, errAlreadyDead
}
setDead := bson.D{{"$set", bson.D{{"life", Dead}}}}
return txn.Op{
C: entities.Name(),
Id: docID,
Assert: nsLife.dying(),
Update: append(setDead, update...),
}, nil
}
|
[
"func",
"(",
"nsLife_",
")",
"dieOp",
"(",
"entities",
"mongo",
".",
"Collection",
",",
"docID",
"string",
",",
"update",
"bson",
".",
"D",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"life",
",",
"err",
":=",
"nsLife",
".",
"read",
"(",
"entities",
",",
"docID",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errAlreadyDead",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"switch",
"life",
"{",
"case",
"Alive",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errNotDying",
"\n",
"case",
"Dead",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errAlreadyDead",
"\n",
"}",
"\n",
"setDead",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Dead",
"}",
"}",
"}",
"}",
"\n",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"entities",
".",
"Name",
"(",
")",
",",
"Id",
":",
"docID",
",",
"Assert",
":",
"nsLife",
".",
"dying",
"(",
")",
",",
"Update",
":",
"append",
"(",
"setDead",
",",
"update",
"...",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// dieOp returns errNotDying if the identified entity is Alive, or
// errAlreadyDead if the entity is Dead or gone; or a txn.Op that will
// fail if the condition no longer holds, and otherwise set Life to
// Dead, and make any other updates supplied in update.
|
[
"dieOp",
"returns",
"errNotDying",
"if",
"the",
"identified",
"entity",
"is",
"Alive",
"or",
"errAlreadyDead",
"if",
"the",
"entity",
"is",
"Dead",
"or",
"gone",
";",
"or",
"a",
"txn",
".",
"Op",
"that",
"will",
"fail",
"if",
"the",
"condition",
"no",
"longer",
"holds",
"and",
"otherwise",
"set",
"Life",
"to",
"Dead",
"and",
"make",
"any",
"other",
"updates",
"supplied",
"in",
"update",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/life_ns.go#L45-L65
|
154,356 |
juju/juju
|
state/life_ns.go
|
aliveOp
|
func (nsLife_) aliveOp(entities mongo.Collection, docID string) (txn.Op, error) {
op, err := nsLife.checkOp(entities, docID, nsLife.alive())
switch errors.Cause(err) {
case nil:
case errCheckFailed:
return txn.Op{}, notAliveErr
default:
return txn.Op{}, errors.Trace(err)
}
return op, nil
}
|
go
|
func (nsLife_) aliveOp(entities mongo.Collection, docID string) (txn.Op, error) {
op, err := nsLife.checkOp(entities, docID, nsLife.alive())
switch errors.Cause(err) {
case nil:
case errCheckFailed:
return txn.Op{}, notAliveErr
default:
return txn.Op{}, errors.Trace(err)
}
return op, nil
}
|
[
"func",
"(",
"nsLife_",
")",
"aliveOp",
"(",
"entities",
"mongo",
".",
"Collection",
",",
"docID",
"string",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"op",
",",
"err",
":=",
"nsLife",
".",
"checkOp",
"(",
"entities",
",",
"docID",
",",
"nsLife",
".",
"alive",
"(",
")",
")",
"\n",
"switch",
"errors",
".",
"Cause",
"(",
"err",
")",
"{",
"case",
"nil",
":",
"case",
"errCheckFailed",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"notAliveErr",
"\n",
"default",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"op",
",",
"nil",
"\n",
"}"
] |
// aliveOp returns errNotAlive if the identified entity is not Alive; or
// a txn.Op that will fail if the condition no longer holds.
|
[
"aliveOp",
"returns",
"errNotAlive",
"if",
"the",
"identified",
"entity",
"is",
"not",
"Alive",
";",
"or",
"a",
"txn",
".",
"Op",
"that",
"will",
"fail",
"if",
"the",
"condition",
"no",
"longer",
"holds",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/life_ns.go#L69-L79
|
154,357 |
juju/juju
|
state/life_ns.go
|
dyingOp
|
func (nsLife_) dyingOp(entities mongo.Collection, docID string) (txn.Op, error) {
op, err := nsLife.checkOp(entities, docID, nsLife.dying())
switch errors.Cause(err) {
case nil:
case errCheckFailed:
return txn.Op{}, errNotDying
default:
return txn.Op{}, errors.Trace(err)
}
return op, nil
}
|
go
|
func (nsLife_) dyingOp(entities mongo.Collection, docID string) (txn.Op, error) {
op, err := nsLife.checkOp(entities, docID, nsLife.dying())
switch errors.Cause(err) {
case nil:
case errCheckFailed:
return txn.Op{}, errNotDying
default:
return txn.Op{}, errors.Trace(err)
}
return op, nil
}
|
[
"func",
"(",
"nsLife_",
")",
"dyingOp",
"(",
"entities",
"mongo",
".",
"Collection",
",",
"docID",
"string",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"op",
",",
"err",
":=",
"nsLife",
".",
"checkOp",
"(",
"entities",
",",
"docID",
",",
"nsLife",
".",
"dying",
"(",
")",
")",
"\n",
"switch",
"errors",
".",
"Cause",
"(",
"err",
")",
"{",
"case",
"nil",
":",
"case",
"errCheckFailed",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errNotDying",
"\n",
"default",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"op",
",",
"nil",
"\n",
"}"
] |
// dyingOp returns errNotDying if the identified entity is not Dying; or
// a txn.Op that will fail if the condition no longer holds.
|
[
"dyingOp",
"returns",
"errNotDying",
"if",
"the",
"identified",
"entity",
"is",
"not",
"Dying",
";",
"or",
"a",
"txn",
".",
"Op",
"that",
"will",
"fail",
"if",
"the",
"condition",
"no",
"longer",
"holds",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/life_ns.go#L83-L93
|
154,358 |
juju/juju
|
state/life_ns.go
|
notDeadOp
|
func (nsLife_) notDeadOp(entities mongo.Collection, docID string) (txn.Op, error) {
op, err := nsLife.checkOp(entities, docID, nsLife.notDead())
switch errors.Cause(err) {
case nil:
case errCheckFailed:
return txn.Op{}, errDeadOrGone
default:
return txn.Op{}, errors.Trace(err)
}
return op, nil
}
|
go
|
func (nsLife_) notDeadOp(entities mongo.Collection, docID string) (txn.Op, error) {
op, err := nsLife.checkOp(entities, docID, nsLife.notDead())
switch errors.Cause(err) {
case nil:
case errCheckFailed:
return txn.Op{}, errDeadOrGone
default:
return txn.Op{}, errors.Trace(err)
}
return op, nil
}
|
[
"func",
"(",
"nsLife_",
")",
"notDeadOp",
"(",
"entities",
"mongo",
".",
"Collection",
",",
"docID",
"string",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"op",
",",
"err",
":=",
"nsLife",
".",
"checkOp",
"(",
"entities",
",",
"docID",
",",
"nsLife",
".",
"notDead",
"(",
")",
")",
"\n",
"switch",
"errors",
".",
"Cause",
"(",
"err",
")",
"{",
"case",
"nil",
":",
"case",
"errCheckFailed",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errDeadOrGone",
"\n",
"default",
":",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"op",
",",
"nil",
"\n",
"}"
] |
// notDeadOp returns errDeadOrGone if the identified entity is not Alive
// or Dying, or a txn.Op that will fail if the condition no longer
// holds.
|
[
"notDeadOp",
"returns",
"errDeadOrGone",
"if",
"the",
"identified",
"entity",
"is",
"not",
"Alive",
"or",
"Dying",
"or",
"a",
"txn",
".",
"Op",
"that",
"will",
"fail",
"if",
"the",
"condition",
"no",
"longer",
"holds",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/life_ns.go#L98-L108
|
154,359 |
juju/juju
|
upgrades/steps_20.go
|
stateStepsFor20
|
func stateStepsFor20() []Step {
return []Step{
&upgradeStep{
description: "strip @local from local user names",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().StripLocalUserDomain()
},
},
&upgradeStep{
description: "rename addmodel permission to add-model",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RenameAddModelPermission()
},
},
}
}
|
go
|
func stateStepsFor20() []Step {
return []Step{
&upgradeStep{
description: "strip @local from local user names",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().StripLocalUserDomain()
},
},
&upgradeStep{
description: "rename addmodel permission to add-model",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RenameAddModelPermission()
},
},
}
}
|
[
"func",
"stateStepsFor20",
"(",
")",
"[",
"]",
"Step",
"{",
"return",
"[",
"]",
"Step",
"{",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"StripLocalUserDomain",
"(",
")",
"\n",
"}",
",",
"}",
",",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"RenameAddModelPermission",
"(",
")",
"\n",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] |
// stateStepsFor20 returns upgrade steps for Juju 2.0 that manipulate state directly.
|
[
"stateStepsFor20",
"returns",
"upgrade",
"steps",
"for",
"Juju",
"2",
".",
"0",
"that",
"manipulate",
"state",
"directly",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_20.go#L12-L29
|
154,360 |
juju/juju
|
upgrades/steps_20.go
|
stepsFor20
|
func stepsFor20() []Step {
return []Step{
&upgradeStep{
description: "remove apiserver charm get cache",
targets: []Target{Controller},
run: removeCharmGetCache,
},
}
}
|
go
|
func stepsFor20() []Step {
return []Step{
&upgradeStep{
description: "remove apiserver charm get cache",
targets: []Target{Controller},
run: removeCharmGetCache,
},
}
}
|
[
"func",
"stepsFor20",
"(",
")",
"[",
"]",
"Step",
"{",
"return",
"[",
"]",
"Step",
"{",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"Controller",
"}",
",",
"run",
":",
"removeCharmGetCache",
",",
"}",
",",
"}",
"\n",
"}"
] |
// stepsFor20 returns upgrade steps for Juju 2.0 that only need the API.
|
[
"stepsFor20",
"returns",
"upgrade",
"steps",
"for",
"Juju",
"2",
".",
"0",
"that",
"only",
"need",
"the",
"API",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_20.go#L32-L40
|
154,361 |
juju/juju
|
upgrades/steps_20.go
|
removeCharmGetCache
|
func removeCharmGetCache(context Context) error {
dataDir := context.AgentConfig().DataDir()
cacheDir := filepath.Join(dataDir, "charm-get-cache")
return os.RemoveAll(cacheDir)
}
|
go
|
func removeCharmGetCache(context Context) error {
dataDir := context.AgentConfig().DataDir()
cacheDir := filepath.Join(dataDir, "charm-get-cache")
return os.RemoveAll(cacheDir)
}
|
[
"func",
"removeCharmGetCache",
"(",
"context",
"Context",
")",
"error",
"{",
"dataDir",
":=",
"context",
".",
"AgentConfig",
"(",
")",
".",
"DataDir",
"(",
")",
"\n",
"cacheDir",
":=",
"filepath",
".",
"Join",
"(",
"dataDir",
",",
"\"",
"\"",
")",
"\n",
"return",
"os",
".",
"RemoveAll",
"(",
"cacheDir",
")",
"\n",
"}"
] |
// removeCharmGetCache removes the cache directory that was previously
// used by the charms API endpoint. It is no longer necessary.
|
[
"removeCharmGetCache",
"removes",
"the",
"cache",
"directory",
"that",
"was",
"previously",
"used",
"by",
"the",
"charms",
"API",
"endpoint",
".",
"It",
"is",
"no",
"longer",
"necessary",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_20.go#L44-L48
|
154,362 |
juju/juju
|
state/cloudcredentials.go
|
CloudCredential
|
func (st *State) CloudCredential(tag names.CloudCredentialTag) (Credential, error) {
coll, cleanup := st.db().GetCollection(cloudCredentialsC)
defer cleanup()
var doc cloudCredentialDoc
err := coll.FindId(cloudCredentialDocID(tag)).One(&doc)
if err == mgo.ErrNotFound {
return Credential{}, errors.NotFoundf(
"cloud credential %q", tag.Id(),
)
} else if err != nil {
return Credential{}, errors.Annotatef(
err, "getting cloud credential %q", tag.Id(),
)
}
return Credential{doc}, nil
}
|
go
|
func (st *State) CloudCredential(tag names.CloudCredentialTag) (Credential, error) {
coll, cleanup := st.db().GetCollection(cloudCredentialsC)
defer cleanup()
var doc cloudCredentialDoc
err := coll.FindId(cloudCredentialDocID(tag)).One(&doc)
if err == mgo.ErrNotFound {
return Credential{}, errors.NotFoundf(
"cloud credential %q", tag.Id(),
)
} else if err != nil {
return Credential{}, errors.Annotatef(
err, "getting cloud credential %q", tag.Id(),
)
}
return Credential{doc}, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"CloudCredential",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
")",
"(",
"Credential",
",",
"error",
")",
"{",
"coll",
",",
"cleanup",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"cloudCredentialsC",
")",
"\n",
"defer",
"cleanup",
"(",
")",
"\n\n",
"var",
"doc",
"cloudCredentialDoc",
"\n",
"err",
":=",
"coll",
".",
"FindId",
"(",
"cloudCredentialDocID",
"(",
"tag",
")",
")",
".",
"One",
"(",
"&",
"doc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"Credential",
"{",
"}",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
",",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Credential",
"{",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"Credential",
"{",
"doc",
"}",
",",
"nil",
"\n",
"}"
] |
// CloudCredential returns the cloud credential for the given tag.
|
[
"CloudCredential",
"returns",
"the",
"cloud",
"credential",
"for",
"the",
"given",
"tag",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L65-L81
|
154,363 |
juju/juju
|
state/cloudcredentials.go
|
CloudCredentials
|
func (st *State) CloudCredentials(user names.UserTag, cloudName string) (map[string]Credential, error) {
coll, cleanup := st.db().GetCollection(cloudCredentialsC)
defer cleanup()
credentials := make(map[string]Credential)
iter := coll.Find(bson.D{
{"owner", user.Id()},
{"cloud", cloudName},
}).Iter()
defer iter.Close()
var doc cloudCredentialDoc
for iter.Next(&doc) {
tag, err := doc.cloudCredentialTag()
if err != nil {
return nil, errors.Trace(err)
}
credentials[tag.Id()] = Credential{doc}
}
if err := iter.Close(); err != nil {
return nil, errors.Annotatef(
err, "cannot get cloud credentials for user %q, cloud %q",
user.Id(), cloudName,
)
}
return credentials, nil
}
|
go
|
func (st *State) CloudCredentials(user names.UserTag, cloudName string) (map[string]Credential, error) {
coll, cleanup := st.db().GetCollection(cloudCredentialsC)
defer cleanup()
credentials := make(map[string]Credential)
iter := coll.Find(bson.D{
{"owner", user.Id()},
{"cloud", cloudName},
}).Iter()
defer iter.Close()
var doc cloudCredentialDoc
for iter.Next(&doc) {
tag, err := doc.cloudCredentialTag()
if err != nil {
return nil, errors.Trace(err)
}
credentials[tag.Id()] = Credential{doc}
}
if err := iter.Close(); err != nil {
return nil, errors.Annotatef(
err, "cannot get cloud credentials for user %q, cloud %q",
user.Id(), cloudName,
)
}
return credentials, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"CloudCredentials",
"(",
"user",
"names",
".",
"UserTag",
",",
"cloudName",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"Credential",
",",
"error",
")",
"{",
"coll",
",",
"cleanup",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"cloudCredentialsC",
")",
"\n",
"defer",
"cleanup",
"(",
")",
"\n\n",
"credentials",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Credential",
")",
"\n",
"iter",
":=",
"coll",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"cloudName",
"}",
",",
"}",
")",
".",
"Iter",
"(",
")",
"\n",
"defer",
"iter",
".",
"Close",
"(",
")",
"\n\n",
"var",
"doc",
"cloudCredentialDoc",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"doc",
")",
"{",
"tag",
",",
"err",
":=",
"doc",
".",
"cloudCredentialTag",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"credentials",
"[",
"tag",
".",
"Id",
"(",
")",
"]",
"=",
"Credential",
"{",
"doc",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iter",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
",",
"cloudName",
",",
")",
"\n",
"}",
"\n",
"return",
"credentials",
",",
"nil",
"\n",
"}"
] |
// CloudCredentials returns the user's cloud credentials for a given cloud,
// keyed by credential name.
|
[
"CloudCredentials",
"returns",
"the",
"user",
"s",
"cloud",
"credentials",
"for",
"a",
"given",
"cloud",
"keyed",
"by",
"credential",
"name",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L85-L111
|
154,364 |
juju/juju
|
state/cloudcredentials.go
|
UpdateCloudCredential
|
func (st *State) UpdateCloudCredential(tag names.CloudCredentialTag, credential cloud.Credential) error {
credentials := map[names.CloudCredentialTag]Credential{
tag: convertCloudCredentialToState(tag, credential),
}
annotationMsg := "updating cloud credentials"
buildTxn := func(attempt int) ([]txn.Op, error) {
cloudName := tag.Cloud().Id()
cloud, err := st.Cloud(cloudName)
if err != nil {
return nil, errors.Trace(err)
}
ops, err := validateCloudCredentials(cloud, credentials)
if err != nil {
return nil, errors.Trace(err)
}
_, err = st.CloudCredential(tag)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Maskf(err, "fetching cloud credentials")
}
if err == nil {
ops = append(ops, updateCloudCredentialOp(tag, credential))
} else {
annotationMsg = "creating cloud credential"
if credential.Invalid || credential.InvalidReason != "" {
return nil, errors.NotSupportedf("adding invalid credential")
}
ops = append(ops, createCloudCredentialOp(tag, credential))
}
return ops, nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Annotate(err, annotationMsg)
}
return nil
}
|
go
|
func (st *State) UpdateCloudCredential(tag names.CloudCredentialTag, credential cloud.Credential) error {
credentials := map[names.CloudCredentialTag]Credential{
tag: convertCloudCredentialToState(tag, credential),
}
annotationMsg := "updating cloud credentials"
buildTxn := func(attempt int) ([]txn.Op, error) {
cloudName := tag.Cloud().Id()
cloud, err := st.Cloud(cloudName)
if err != nil {
return nil, errors.Trace(err)
}
ops, err := validateCloudCredentials(cloud, credentials)
if err != nil {
return nil, errors.Trace(err)
}
_, err = st.CloudCredential(tag)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Maskf(err, "fetching cloud credentials")
}
if err == nil {
ops = append(ops, updateCloudCredentialOp(tag, credential))
} else {
annotationMsg = "creating cloud credential"
if credential.Invalid || credential.InvalidReason != "" {
return nil, errors.NotSupportedf("adding invalid credential")
}
ops = append(ops, createCloudCredentialOp(tag, credential))
}
return ops, nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Annotate(err, annotationMsg)
}
return nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"UpdateCloudCredential",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
",",
"credential",
"cloud",
".",
"Credential",
")",
"error",
"{",
"credentials",
":=",
"map",
"[",
"names",
".",
"CloudCredentialTag",
"]",
"Credential",
"{",
"tag",
":",
"convertCloudCredentialToState",
"(",
"tag",
",",
"credential",
")",
",",
"}",
"\n",
"annotationMsg",
":=",
"\"",
"\"",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"cloudName",
":=",
"tag",
".",
"Cloud",
"(",
")",
".",
"Id",
"(",
")",
"\n",
"cloud",
",",
"err",
":=",
"st",
".",
"Cloud",
"(",
"cloudName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ops",
",",
"err",
":=",
"validateCloudCredentials",
"(",
"cloud",
",",
"credentials",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"st",
".",
"CloudCredential",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Maskf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"ops",
"=",
"append",
"(",
"ops",
",",
"updateCloudCredentialOp",
"(",
"tag",
",",
"credential",
")",
")",
"\n",
"}",
"else",
"{",
"annotationMsg",
"=",
"\"",
"\"",
"\n",
"if",
"credential",
".",
"Invalid",
"||",
"credential",
".",
"InvalidReason",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"createCloudCredentialOp",
"(",
"tag",
",",
"credential",
")",
")",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"annotationMsg",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UpdateCloudCredential adds or updates a cloud credential with the given tag.
|
[
"UpdateCloudCredential",
"adds",
"or",
"updates",
"a",
"cloud",
"credential",
"with",
"the",
"given",
"tag",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L114-L148
|
154,365 |
juju/juju
|
state/cloudcredentials.go
|
InvalidateCloudCredential
|
func (st *State) InvalidateCloudCredential(tag names.CloudCredentialTag, reason string) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
_, err := st.CloudCredential(tag)
if err != nil {
return nil, errors.Trace(err)
}
ops := []txn.Op{{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{
{"invalid", true},
{"invalid-reason", reason},
}}},
}}
return ops, nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Annotatef(err, "invalidating cloud credential %v", tag.Id())
}
return nil
}
|
go
|
func (st *State) InvalidateCloudCredential(tag names.CloudCredentialTag, reason string) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
_, err := st.CloudCredential(tag)
if err != nil {
return nil, errors.Trace(err)
}
ops := []txn.Op{{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{
{"invalid", true},
{"invalid-reason", reason},
}}},
}}
return ops, nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Annotatef(err, "invalidating cloud credential %v", tag.Id())
}
return nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"InvalidateCloudCredential",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
",",
"reason",
"string",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"st",
".",
"CloudCredential",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"cloudCredentialsC",
",",
"Id",
":",
"cloudCredentialDocID",
"(",
"tag",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"true",
"}",
",",
"{",
"\"",
"\"",
",",
"reason",
"}",
",",
"}",
"}",
"}",
",",
"}",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// InvalidateCloudCredential marks a cloud credential with the given tag as invalid.
|
[
"InvalidateCloudCredential",
"marks",
"a",
"cloud",
"credential",
"with",
"the",
"given",
"tag",
"as",
"invalid",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L151-L173
|
154,366 |
juju/juju
|
state/cloudcredentials.go
|
RemoveCloudCredential
|
func (st *State) RemoveCloudCredential(tag names.CloudCredentialTag) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
_, err := st.CloudCredential(tag)
if errors.IsNotFound(err) {
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
return removeCloudCredentialOps(tag), nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Annotate(err, "removing cloud credential")
}
return nil
}
|
go
|
func (st *State) RemoveCloudCredential(tag names.CloudCredentialTag) error {
buildTxn := func(attempt int) ([]txn.Op, error) {
_, err := st.CloudCredential(tag)
if errors.IsNotFound(err) {
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
return removeCloudCredentialOps(tag), nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Annotate(err, "removing cloud credential")
}
return nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"RemoveCloudCredential",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"st",
".",
"CloudCredential",
"(",
"tag",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"removeCloudCredentialOps",
"(",
"tag",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RemoveCloudCredential removes a cloud credential with the given tag.
|
[
"RemoveCloudCredential",
"removes",
"a",
"cloud",
"credential",
"with",
"the",
"given",
"tag",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L176-L191
|
154,367 |
juju/juju
|
state/cloudcredentials.go
|
createCloudCredentialOp
|
func createCloudCredentialOp(tag names.CloudCredentialTag, cred cloud.Credential) txn.Op {
return txn.Op{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocMissing,
Insert: &cloudCredentialDoc{
Owner: tag.Owner().Id(),
Cloud: tag.Cloud().Id(),
Name: tag.Name(),
AuthType: string(cred.AuthType()),
Attributes: cred.Attributes(),
Revoked: cred.Revoked,
},
}
}
|
go
|
func createCloudCredentialOp(tag names.CloudCredentialTag, cred cloud.Credential) txn.Op {
return txn.Op{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocMissing,
Insert: &cloudCredentialDoc{
Owner: tag.Owner().Id(),
Cloud: tag.Cloud().Id(),
Name: tag.Name(),
AuthType: string(cred.AuthType()),
Attributes: cred.Attributes(),
Revoked: cred.Revoked,
},
}
}
|
[
"func",
"createCloudCredentialOp",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
",",
"cred",
"cloud",
".",
"Credential",
")",
"txn",
".",
"Op",
"{",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"cloudCredentialsC",
",",
"Id",
":",
"cloudCredentialDocID",
"(",
"tag",
")",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"&",
"cloudCredentialDoc",
"{",
"Owner",
":",
"tag",
".",
"Owner",
"(",
")",
".",
"Id",
"(",
")",
",",
"Cloud",
":",
"tag",
".",
"Cloud",
"(",
")",
".",
"Id",
"(",
")",
",",
"Name",
":",
"tag",
".",
"Name",
"(",
")",
",",
"AuthType",
":",
"string",
"(",
"cred",
".",
"AuthType",
"(",
")",
")",
",",
"Attributes",
":",
"cred",
".",
"Attributes",
"(",
")",
",",
"Revoked",
":",
"cred",
".",
"Revoked",
",",
"}",
",",
"}",
"\n",
"}"
] |
// createCloudCredentialOp returns a txn.Op that will create
// a cloud credential.
|
[
"createCloudCredentialOp",
"returns",
"a",
"txn",
".",
"Op",
"that",
"will",
"create",
"a",
"cloud",
"credential",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L195-L209
|
154,368 |
juju/juju
|
state/cloudcredentials.go
|
updateCloudCredentialOp
|
func updateCloudCredentialOp(tag names.CloudCredentialTag, cred cloud.Credential) txn.Op {
return txn.Op{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{
{"auth-type", string(cred.AuthType())},
{"attributes", cred.Attributes()},
{"revoked", cred.Revoked},
{"invalid", cred.Invalid},
{"invalid-reason", cred.InvalidReason},
}}},
}
}
|
go
|
func updateCloudCredentialOp(tag names.CloudCredentialTag, cred cloud.Credential) txn.Op {
return txn.Op{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{
{"auth-type", string(cred.AuthType())},
{"attributes", cred.Attributes()},
{"revoked", cred.Revoked},
{"invalid", cred.Invalid},
{"invalid-reason", cred.InvalidReason},
}}},
}
}
|
[
"func",
"updateCloudCredentialOp",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
",",
"cred",
"cloud",
".",
"Credential",
")",
"txn",
".",
"Op",
"{",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"cloudCredentialsC",
",",
"Id",
":",
"cloudCredentialDocID",
"(",
"tag",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"string",
"(",
"cred",
".",
"AuthType",
"(",
")",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"cred",
".",
"Attributes",
"(",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"cred",
".",
"Revoked",
"}",
",",
"{",
"\"",
"\"",
",",
"cred",
".",
"Invalid",
"}",
",",
"{",
"\"",
"\"",
",",
"cred",
".",
"InvalidReason",
"}",
",",
"}",
"}",
"}",
",",
"}",
"\n",
"}"
] |
// updateCloudCredentialOp returns a txn.Op that will update
// a cloud credential.
|
[
"updateCloudCredentialOp",
"returns",
"a",
"txn",
".",
"Op",
"that",
"will",
"update",
"a",
"cloud",
"credential",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L213-L226
|
154,369 |
juju/juju
|
state/cloudcredentials.go
|
removeCloudCredentialOps
|
func removeCloudCredentialOps(tag names.CloudCredentialTag) []txn.Op {
return []txn.Op{{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocExists,
Remove: true,
}}
}
|
go
|
func removeCloudCredentialOps(tag names.CloudCredentialTag) []txn.Op {
return []txn.Op{{
C: cloudCredentialsC,
Id: cloudCredentialDocID(tag),
Assert: txn.DocExists,
Remove: true,
}}
}
|
[
"func",
"removeCloudCredentialOps",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
")",
"[",
"]",
"txn",
".",
"Op",
"{",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"cloudCredentialsC",
",",
"Id",
":",
"cloudCredentialDocID",
"(",
"tag",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Remove",
":",
"true",
",",
"}",
"}",
"\n",
"}"
] |
// removeCloudCredentialOp returns a txn.Op that will remove
// a cloud credential.
|
[
"removeCloudCredentialOp",
"returns",
"a",
"txn",
".",
"Op",
"that",
"will",
"remove",
"a",
"cloud",
"credential",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L230-L237
|
154,370 |
juju/juju
|
state/cloudcredentials.go
|
WatchCredential
|
func (st *State) WatchCredential(cred names.CloudCredentialTag) NotifyWatcher {
filter := func(rawId interface{}) bool {
id, ok := rawId.(string)
if !ok {
return false
}
return id == cloudCredentialDocID(cred)
}
return newNotifyCollWatcher(st, cloudCredentialsC, filter)
}
|
go
|
func (st *State) WatchCredential(cred names.CloudCredentialTag) NotifyWatcher {
filter := func(rawId interface{}) bool {
id, ok := rawId.(string)
if !ok {
return false
}
return id == cloudCredentialDocID(cred)
}
return newNotifyCollWatcher(st, cloudCredentialsC, filter)
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"WatchCredential",
"(",
"cred",
"names",
".",
"CloudCredentialTag",
")",
"NotifyWatcher",
"{",
"filter",
":=",
"func",
"(",
"rawId",
"interface",
"{",
"}",
")",
"bool",
"{",
"id",
",",
"ok",
":=",
"rawId",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"id",
"==",
"cloudCredentialDocID",
"(",
"cred",
")",
"\n",
"}",
"\n",
"return",
"newNotifyCollWatcher",
"(",
"st",
",",
"cloudCredentialsC",
",",
"filter",
")",
"\n",
"}"
] |
// WatchCredential returns a new NotifyWatcher watching for
// changes to the specified credential.
|
[
"WatchCredential",
"returns",
"a",
"new",
"NotifyWatcher",
"watching",
"for",
"changes",
"to",
"the",
"specified",
"credential",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L309-L318
|
154,371 |
juju/juju
|
state/cloudcredentials.go
|
AllCloudCredentials
|
func (st *State) AllCloudCredentials(user names.UserTag) ([]Credential, error) {
coll, cleanup := st.db().GetCollection(cloudCredentialsC)
defer cleanup()
// There are 2 ways of getting a credential for a user:
// 1. user name stored in the credential tag (aka doc id);
// 2. look up using Owner field.
// We use Owner field below as credential tag or doc ID may be changed
// in the future to be a real Primary Key that has nothing to do with
// the data it identifies, i.e. no business meaning.
clause := bson.D{{"owner", user.Id()}}
var docs []cloudCredentialDoc
err := coll.Find(clause).Sort("cloud").All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "getting cloud credentials for %q", user.Id())
}
if len(docs) == 0 {
return nil, errors.NotFoundf("cloud credentials for %q", user.Id())
}
credentials := make([]Credential, len(docs))
for i, doc := range docs {
credentials[i] = Credential{doc}
}
return credentials, nil
}
|
go
|
func (st *State) AllCloudCredentials(user names.UserTag) ([]Credential, error) {
coll, cleanup := st.db().GetCollection(cloudCredentialsC)
defer cleanup()
// There are 2 ways of getting a credential for a user:
// 1. user name stored in the credential tag (aka doc id);
// 2. look up using Owner field.
// We use Owner field below as credential tag or doc ID may be changed
// in the future to be a real Primary Key that has nothing to do with
// the data it identifies, i.e. no business meaning.
clause := bson.D{{"owner", user.Id()}}
var docs []cloudCredentialDoc
err := coll.Find(clause).Sort("cloud").All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "getting cloud credentials for %q", user.Id())
}
if len(docs) == 0 {
return nil, errors.NotFoundf("cloud credentials for %q", user.Id())
}
credentials := make([]Credential, len(docs))
for i, doc := range docs {
credentials[i] = Credential{doc}
}
return credentials, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"AllCloudCredentials",
"(",
"user",
"names",
".",
"UserTag",
")",
"(",
"[",
"]",
"Credential",
",",
"error",
")",
"{",
"coll",
",",
"cleanup",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"cloudCredentialsC",
")",
"\n",
"defer",
"cleanup",
"(",
")",
"\n\n",
"// There are 2 ways of getting a credential for a user:",
"// 1. user name stored in the credential tag (aka doc id);",
"// 2. look up using Owner field.",
"// We use Owner field below as credential tag or doc ID may be changed",
"// in the future to be a real Primary Key that has nothing to do with",
"// the data it identifies, i.e. no business meaning.",
"clause",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
"}",
"}",
"\n\n",
"var",
"docs",
"[",
"]",
"cloudCredentialDoc",
"\n",
"err",
":=",
"coll",
".",
"Find",
"(",
"clause",
")",
".",
"Sort",
"(",
"\"",
"\"",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"docs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"user",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n\n",
"credentials",
":=",
"make",
"(",
"[",
"]",
"Credential",
",",
"len",
"(",
"docs",
")",
")",
"\n",
"for",
"i",
",",
"doc",
":=",
"range",
"docs",
"{",
"credentials",
"[",
"i",
"]",
"=",
"Credential",
"{",
"doc",
"}",
"\n",
"}",
"\n",
"return",
"credentials",
",",
"nil",
"\n",
"}"
] |
// AllCloudCredentials returns all cloud credentials stored on the controller
// for a given user.
|
[
"AllCloudCredentials",
"returns",
"all",
"cloud",
"credentials",
"stored",
"on",
"the",
"controller",
"for",
"a",
"given",
"user",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L322-L349
|
154,372 |
juju/juju
|
state/cloudcredentials.go
|
CredentialModels
|
func (st *State) CredentialModels(tag names.CloudCredentialTag) (map[string]string, error) {
coll, cleanup := st.db().GetCollection(modelsC)
defer cleanup()
sel := bson.D{
{"cloud-credential", tag.Id()},
{"life", bson.D{{"$ne", Dead}}},
}
var docs []modelDoc
err := coll.Find(sel).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "getting models that use cloud credential %q", tag.Id())
}
if len(docs) == 0 {
return nil, errors.NotFoundf("models that use cloud credentials %q", tag.Id())
}
results := make(map[string]string, len(docs))
for _, model := range docs {
results[model.UUID] = model.Name
}
return results, nil
}
|
go
|
func (st *State) CredentialModels(tag names.CloudCredentialTag) (map[string]string, error) {
coll, cleanup := st.db().GetCollection(modelsC)
defer cleanup()
sel := bson.D{
{"cloud-credential", tag.Id()},
{"life", bson.D{{"$ne", Dead}}},
}
var docs []modelDoc
err := coll.Find(sel).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "getting models that use cloud credential %q", tag.Id())
}
if len(docs) == 0 {
return nil, errors.NotFoundf("models that use cloud credentials %q", tag.Id())
}
results := make(map[string]string, len(docs))
for _, model := range docs {
results[model.UUID] = model.Name
}
return results, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"CredentialModels",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"coll",
",",
"cleanup",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelsC",
")",
"\n",
"defer",
"cleanup",
"(",
")",
"\n\n",
"sel",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
"}",
",",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Dead",
"}",
"}",
"}",
",",
"}",
"\n\n",
"var",
"docs",
"[",
"]",
"modelDoc",
"\n",
"err",
":=",
"coll",
".",
"Find",
"(",
"sel",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"docs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n\n",
"results",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"docs",
")",
")",
"\n",
"for",
"_",
",",
"model",
":=",
"range",
"docs",
"{",
"results",
"[",
"model",
".",
"UUID",
"]",
"=",
"model",
".",
"Name",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] |
// CredentialModels returns all models that use given cloud credential.
|
[
"CredentialModels",
"returns",
"all",
"models",
"that",
"use",
"given",
"cloud",
"credential",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L352-L375
|
154,373 |
juju/juju
|
state/cloudcredentials.go
|
CredentialModelsAndOwnerAccess
|
func (st *State) CredentialModelsAndOwnerAccess(tag names.CloudCredentialTag) ([]CredentialOwnerModelAccess, error) {
models, err := st.CredentialModels(tag)
if err != nil {
return nil, errors.Trace(err)
}
var results []CredentialOwnerModelAccess
for uuid, name := range models {
ownerAccess, err := st.UserAccess(tag.Owner(), names.NewModelTag(uuid))
if err != nil {
if errors.IsNotFound(err) {
results = append(results, CredentialOwnerModelAccess{ModelName: name, ModelUUID: uuid, OwnerAccess: permission.NoAccess})
continue
}
results = append(results, CredentialOwnerModelAccess{ModelName: name, ModelUUID: uuid, Error: errors.Trace(err)})
continue
}
results = append(results, CredentialOwnerModelAccess{ModelName: name, ModelUUID: uuid, OwnerAccess: ownerAccess.Access})
}
return results, nil
}
|
go
|
func (st *State) CredentialModelsAndOwnerAccess(tag names.CloudCredentialTag) ([]CredentialOwnerModelAccess, error) {
models, err := st.CredentialModels(tag)
if err != nil {
return nil, errors.Trace(err)
}
var results []CredentialOwnerModelAccess
for uuid, name := range models {
ownerAccess, err := st.UserAccess(tag.Owner(), names.NewModelTag(uuid))
if err != nil {
if errors.IsNotFound(err) {
results = append(results, CredentialOwnerModelAccess{ModelName: name, ModelUUID: uuid, OwnerAccess: permission.NoAccess})
continue
}
results = append(results, CredentialOwnerModelAccess{ModelName: name, ModelUUID: uuid, Error: errors.Trace(err)})
continue
}
results = append(results, CredentialOwnerModelAccess{ModelName: name, ModelUUID: uuid, OwnerAccess: ownerAccess.Access})
}
return results, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"CredentialModelsAndOwnerAccess",
"(",
"tag",
"names",
".",
"CloudCredentialTag",
")",
"(",
"[",
"]",
"CredentialOwnerModelAccess",
",",
"error",
")",
"{",
"models",
",",
"err",
":=",
"st",
".",
"CredentialModels",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"results",
"[",
"]",
"CredentialOwnerModelAccess",
"\n",
"for",
"uuid",
",",
"name",
":=",
"range",
"models",
"{",
"ownerAccess",
",",
"err",
":=",
"st",
".",
"UserAccess",
"(",
"tag",
".",
"Owner",
"(",
")",
",",
"names",
".",
"NewModelTag",
"(",
"uuid",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"CredentialOwnerModelAccess",
"{",
"ModelName",
":",
"name",
",",
"ModelUUID",
":",
"uuid",
",",
"OwnerAccess",
":",
"permission",
".",
"NoAccess",
"}",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"=",
"append",
"(",
"results",
",",
"CredentialOwnerModelAccess",
"{",
"ModelName",
":",
"name",
",",
"ModelUUID",
":",
"uuid",
",",
"Error",
":",
"errors",
".",
"Trace",
"(",
"err",
")",
"}",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"=",
"append",
"(",
"results",
",",
"CredentialOwnerModelAccess",
"{",
"ModelName",
":",
"name",
",",
"ModelUUID",
":",
"uuid",
",",
"OwnerAccess",
":",
"ownerAccess",
".",
"Access",
"}",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] |
// CredentialModelsAndOwnerAccess returns all models that use given cloud credential as well as
// what access the credential owner has on these models.
|
[
"CredentialModelsAndOwnerAccess",
"returns",
"all",
"models",
"that",
"use",
"given",
"cloud",
"credential",
"as",
"well",
"as",
"what",
"access",
"the",
"credential",
"owner",
"has",
"on",
"these",
"models",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/cloudcredentials.go#L388-L408
|
154,374 |
juju/juju
|
worker/proxyupdater/manifold.go
|
Manifold
|
func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
if config.WorkerFunc == nil {
return nil, errors.NotValidf("missing WorkerFunc")
}
if config.InProcessUpdate == nil {
return nil, errors.NotValidf("missing InProcessUpdate")
}
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
agentConfig := agent.CurrentConfig()
proxyAPI, err := proxyupdater.NewAPI(apiCaller, agentConfig.Tag())
if err != nil {
return nil, err
}
w, err := config.WorkerFunc(Config{
SystemdFiles: []string{"/etc/juju-proxy-systemd.conf"},
EnvFiles: []string{"/etc/juju-proxy.conf"},
RegistryPath: `HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings`,
API: proxyAPI,
ExternalUpdate: config.ExternalUpdate,
InProcessUpdate: config.InProcessUpdate,
Logger: config.Logger,
RunFunc: config.RunFunc,
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
},
}
}
|
go
|
func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
if config.WorkerFunc == nil {
return nil, errors.NotValidf("missing WorkerFunc")
}
if config.InProcessUpdate == nil {
return nil, errors.NotValidf("missing InProcessUpdate")
}
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
agentConfig := agent.CurrentConfig()
proxyAPI, err := proxyupdater.NewAPI(apiCaller, agentConfig.Tag())
if err != nil {
return nil, err
}
w, err := config.WorkerFunc(Config{
SystemdFiles: []string{"/etc/juju-proxy-systemd.conf"},
EnvFiles: []string{"/etc/juju-proxy.conf"},
RegistryPath: `HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings`,
API: proxyAPI,
ExternalUpdate: config.ExternalUpdate,
InProcessUpdate: config.InProcessUpdate,
Logger: config.Logger,
RunFunc: config.RunFunc,
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
},
}
}
|
[
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"return",
"dependency",
".",
"Manifold",
"{",
"Inputs",
":",
"[",
"]",
"string",
"{",
"config",
".",
"AgentName",
",",
"config",
".",
"APICallerName",
",",
"}",
",",
"Start",
":",
"func",
"(",
"context",
"dependency",
".",
"Context",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"if",
"config",
".",
"WorkerFunc",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"InProcessUpdate",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"agent",
"agent",
".",
"Agent",
"\n",
"if",
"err",
":=",
"context",
".",
"Get",
"(",
"config",
".",
"AgentName",
",",
"&",
"agent",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"apiCaller",
"base",
".",
"APICaller",
"\n",
"if",
"err",
":=",
"context",
".",
"Get",
"(",
"config",
".",
"APICallerName",
",",
"&",
"apiCaller",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"agentConfig",
":=",
"agent",
".",
"CurrentConfig",
"(",
")",
"\n",
"proxyAPI",
",",
"err",
":=",
"proxyupdater",
".",
"NewAPI",
"(",
"apiCaller",
",",
"agentConfig",
".",
"Tag",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"w",
",",
"err",
":=",
"config",
".",
"WorkerFunc",
"(",
"Config",
"{",
"SystemdFiles",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"EnvFiles",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"RegistryPath",
":",
"`HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings`",
",",
"API",
":",
"proxyAPI",
",",
"ExternalUpdate",
":",
"config",
".",
"ExternalUpdate",
",",
"InProcessUpdate",
":",
"config",
".",
"InProcessUpdate",
",",
"Logger",
":",
"config",
".",
"Logger",
",",
"RunFunc",
":",
"config",
".",
"RunFunc",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}",
",",
"}",
"\n",
"}"
] |
// Manifold returns a dependency manifold that runs a proxy updater worker,
// using the api connection resource named in the supplied config.
|
[
"Manifold",
"returns",
"a",
"dependency",
"manifold",
"that",
"runs",
"a",
"proxy",
"updater",
"worker",
"using",
"the",
"api",
"connection",
"resource",
"named",
"in",
"the",
"supplied",
"config",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/proxyupdater/manifold.go#L39-L82
|
154,375 |
juju/juju
|
provider/gce/google/conn_machines.go
|
ListMachineTypes
|
func (gce *Connection) ListMachineTypes(zone string) ([]MachineType, error) {
machines, err := gce.raw.ListMachineTypes(gce.projectID, zone)
if err != nil {
return nil, errors.Trace(err)
}
res := make([]MachineType, len(machines.Items))
for i, machine := range machines.Items {
deprecated := false
if machine.Deprecated != nil {
deprecated = machine.Deprecated.State != ""
}
res[i] = MachineType{
CreationTimestamp: machine.CreationTimestamp,
Deprecated: deprecated,
Description: machine.Description,
GuestCpus: machine.GuestCpus,
Id: machine.Id,
ImageSpaceGb: machine.ImageSpaceGb,
Kind: machine.Kind,
MaximumPersistentDisks: machine.MaximumPersistentDisks,
MaximumPersistentDisksSizeGb: machine.MaximumPersistentDisksSizeGb,
MemoryMb: machine.MemoryMb,
Name: machine.Name,
}
}
return res, nil
}
|
go
|
func (gce *Connection) ListMachineTypes(zone string) ([]MachineType, error) {
machines, err := gce.raw.ListMachineTypes(gce.projectID, zone)
if err != nil {
return nil, errors.Trace(err)
}
res := make([]MachineType, len(machines.Items))
for i, machine := range machines.Items {
deprecated := false
if machine.Deprecated != nil {
deprecated = machine.Deprecated.State != ""
}
res[i] = MachineType{
CreationTimestamp: machine.CreationTimestamp,
Deprecated: deprecated,
Description: machine.Description,
GuestCpus: machine.GuestCpus,
Id: machine.Id,
ImageSpaceGb: machine.ImageSpaceGb,
Kind: machine.Kind,
MaximumPersistentDisks: machine.MaximumPersistentDisks,
MaximumPersistentDisksSizeGb: machine.MaximumPersistentDisksSizeGb,
MemoryMb: machine.MemoryMb,
Name: machine.Name,
}
}
return res, nil
}
|
[
"func",
"(",
"gce",
"*",
"Connection",
")",
"ListMachineTypes",
"(",
"zone",
"string",
")",
"(",
"[",
"]",
"MachineType",
",",
"error",
")",
"{",
"machines",
",",
"err",
":=",
"gce",
".",
"raw",
".",
"ListMachineTypes",
"(",
"gce",
".",
"projectID",
",",
"zone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"res",
":=",
"make",
"(",
"[",
"]",
"MachineType",
",",
"len",
"(",
"machines",
".",
"Items",
")",
")",
"\n",
"for",
"i",
",",
"machine",
":=",
"range",
"machines",
".",
"Items",
"{",
"deprecated",
":=",
"false",
"\n",
"if",
"machine",
".",
"Deprecated",
"!=",
"nil",
"{",
"deprecated",
"=",
"machine",
".",
"Deprecated",
".",
"State",
"!=",
"\"",
"\"",
"\n",
"}",
"\n",
"res",
"[",
"i",
"]",
"=",
"MachineType",
"{",
"CreationTimestamp",
":",
"machine",
".",
"CreationTimestamp",
",",
"Deprecated",
":",
"deprecated",
",",
"Description",
":",
"machine",
".",
"Description",
",",
"GuestCpus",
":",
"machine",
".",
"GuestCpus",
",",
"Id",
":",
"machine",
".",
"Id",
",",
"ImageSpaceGb",
":",
"machine",
".",
"ImageSpaceGb",
",",
"Kind",
":",
"machine",
".",
"Kind",
",",
"MaximumPersistentDisks",
":",
"machine",
".",
"MaximumPersistentDisks",
",",
"MaximumPersistentDisksSizeGb",
":",
"machine",
".",
"MaximumPersistentDisksSizeGb",
",",
"MemoryMb",
":",
"machine",
".",
"MemoryMb",
",",
"Name",
":",
"machine",
".",
"Name",
",",
"}",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// ListMachineTypes returns a list of MachineType available for the
// given zone.
|
[
"ListMachineTypes",
"returns",
"a",
"list",
"of",
"MachineType",
"available",
"for",
"the",
"given",
"zone",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_machines.go#L10-L36
|
154,376 |
juju/juju
|
worker/raft/raftforwarder/manifold.go
|
NewTarget
|
func NewTarget(st *state.State, logFile io.Writer, errorLog Logger) raftlease.NotifyTarget {
return st.LeaseNotifyTarget(logFile, errorLog)
}
|
go
|
func NewTarget(st *state.State, logFile io.Writer, errorLog Logger) raftlease.NotifyTarget {
return st.LeaseNotifyTarget(logFile, errorLog)
}
|
[
"func",
"NewTarget",
"(",
"st",
"*",
"state",
".",
"State",
",",
"logFile",
"io",
".",
"Writer",
",",
"errorLog",
"Logger",
")",
"raftlease",
".",
"NotifyTarget",
"{",
"return",
"st",
".",
"LeaseNotifyTarget",
"(",
"logFile",
",",
"errorLog",
")",
"\n",
"}"
] |
// NewTarget is a shim to construct a raftlease.NotifyTarget for testability.
|
[
"NewTarget",
"is",
"a",
"shim",
"to",
"construct",
"a",
"raftlease",
".",
"NotifyTarget",
"for",
"testability",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/raftforwarder/manifold.go#L146-L148
|
154,377 |
juju/juju
|
api/bundle/client.go
|
ExportBundle
|
func (c *Client) ExportBundle() (string, error) {
var result params.StringResult
if bestVer := c.BestAPIVersion(); bestVer < 2 {
return "", errors.Errorf("this controller version does not support bundle export feature.")
}
if err := c.facade.FacadeCall("ExportBundle", nil, &result); err != nil {
return "", errors.Trace(err)
}
if result.Error != nil {
return "", errors.Trace(result.Error)
}
return result.Result, nil
}
|
go
|
func (c *Client) ExportBundle() (string, error) {
var result params.StringResult
if bestVer := c.BestAPIVersion(); bestVer < 2 {
return "", errors.Errorf("this controller version does not support bundle export feature.")
}
if err := c.facade.FacadeCall("ExportBundle", nil, &result); err != nil {
return "", errors.Trace(err)
}
if result.Error != nil {
return "", errors.Trace(result.Error)
}
return result.Result, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ExportBundle",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"StringResult",
"\n",
"if",
"bestVer",
":=",
"c",
".",
"BestAPIVersion",
"(",
")",
";",
"bestVer",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"nil",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"result",
".",
"Error",
")",
"\n",
"}",
"\n\n",
"return",
"result",
".",
"Result",
",",
"nil",
"\n",
"}"
] |
// ExportBundle exports the current model configuration.
|
[
"ExportBundle",
"exports",
"the",
"current",
"model",
"configuration",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/bundle/client.go#L34-L49
|
154,378 |
juju/juju
|
state/user.go
|
AddUser
|
func (st *State) AddUser(name, displayName, password, creator string) (*User, error) {
return st.addUser(name, displayName, password, creator, nil)
}
|
go
|
func (st *State) AddUser(name, displayName, password, creator string) (*User, error) {
return st.addUser(name, displayName, password, creator, nil)
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"AddUser",
"(",
"name",
",",
"displayName",
",",
"password",
",",
"creator",
"string",
")",
"(",
"*",
"User",
",",
"error",
")",
"{",
"return",
"st",
".",
"addUser",
"(",
"name",
",",
"displayName",
",",
"password",
",",
"creator",
",",
"nil",
")",
"\n",
"}"
] |
// AddUser adds a user to the database.
|
[
"AddUser",
"adds",
"a",
"user",
"to",
"the",
"database",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L52-L54
|
154,379 |
juju/juju
|
state/user.go
|
AddUserWithSecretKey
|
func (st *State) AddUserWithSecretKey(name, displayName, creator string) (*User, error) {
secretKey, err := generateSecretKey()
if err != nil {
return nil, errors.Trace(err)
}
return st.addUser(name, displayName, "", creator, secretKey)
}
|
go
|
func (st *State) AddUserWithSecretKey(name, displayName, creator string) (*User, error) {
secretKey, err := generateSecretKey()
if err != nil {
return nil, errors.Trace(err)
}
return st.addUser(name, displayName, "", creator, secretKey)
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"AddUserWithSecretKey",
"(",
"name",
",",
"displayName",
",",
"creator",
"string",
")",
"(",
"*",
"User",
",",
"error",
")",
"{",
"secretKey",
",",
"err",
":=",
"generateSecretKey",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st",
".",
"addUser",
"(",
"name",
",",
"displayName",
",",
"\"",
"\"",
",",
"creator",
",",
"secretKey",
")",
"\n",
"}"
] |
// AddUserWithSecretKey adds the user with the specified name, and assigns it
// a randomly generated secret key. This secret key may be used for the user
// and controller to mutually authenticate one another, without without relying
// on TLS certificates.
//
// The new user will not have a password. A password must be set, clearing the
// secret key in the process, before the user can login normally.
|
[
"AddUserWithSecretKey",
"adds",
"the",
"user",
"with",
"the",
"specified",
"name",
"and",
"assigns",
"it",
"a",
"randomly",
"generated",
"secret",
"key",
".",
"This",
"secret",
"key",
"may",
"be",
"used",
"for",
"the",
"user",
"and",
"controller",
"to",
"mutually",
"authenticate",
"one",
"another",
"without",
"without",
"relying",
"on",
"TLS",
"certificates",
".",
"The",
"new",
"user",
"will",
"not",
"have",
"a",
"password",
".",
"A",
"password",
"must",
"be",
"set",
"clearing",
"the",
"secret",
"key",
"in",
"the",
"process",
"before",
"the",
"user",
"can",
"login",
"normally",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L63-L69
|
154,380 |
juju/juju
|
state/user.go
|
RemoveUser
|
func (st *State) RemoveUser(tag names.UserTag) error {
name := strings.ToLower(tag.Name())
u, err := st.User(tag)
if err != nil {
return errors.Trace(err)
}
if u.IsDeleted() {
return nil
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
// If it is not our first attempt, refresh the user.
if err := u.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
ops := []txn.Op{{
Id: name,
C: usersC,
Assert: txn.DocExists,
Update: bson.M{"$set": bson.M{"deleted": true}},
}}
return ops, nil
}
return st.db().Run(buildTxn)
}
|
go
|
func (st *State) RemoveUser(tag names.UserTag) error {
name := strings.ToLower(tag.Name())
u, err := st.User(tag)
if err != nil {
return errors.Trace(err)
}
if u.IsDeleted() {
return nil
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
// If it is not our first attempt, refresh the user.
if err := u.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
ops := []txn.Op{{
Id: name,
C: usersC,
Assert: txn.DocExists,
Update: bson.M{"$set": bson.M{"deleted": true}},
}}
return ops, nil
}
return st.db().Run(buildTxn)
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"RemoveUser",
"(",
"tag",
"names",
".",
"UserTag",
")",
"error",
"{",
"name",
":=",
"strings",
".",
"ToLower",
"(",
"tag",
".",
"Name",
"(",
")",
")",
"\n\n",
"u",
",",
"err",
":=",
"st",
".",
"User",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"u",
".",
"IsDeleted",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"// If it is not our first attempt, refresh the user.",
"if",
"err",
":=",
"u",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"Id",
":",
"name",
",",
"C",
":",
"usersC",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"true",
"}",
"}",
",",
"}",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"return",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] |
// RemoveUser marks the user as deleted. This obviates the ability of a user
// to function, but keeps the userDoc retaining provenance, i.e. auditing.
|
[
"RemoveUser",
"marks",
"the",
"user",
"as",
"deleted",
".",
"This",
"obviates",
"the",
"ability",
"of",
"a",
"user",
"to",
"function",
"but",
"keeps",
"the",
"userDoc",
"retaining",
"provenance",
"i",
".",
"e",
".",
"auditing",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L128-L155
|
154,381 |
juju/juju
|
state/user.go
|
getUser
|
func (st *State) getUser(name string, udoc *userDoc) error {
users, closer := st.db().GetCollection(usersC)
defer closer()
name = strings.ToLower(name)
err := users.Find(bson.D{{"_id", name}}).One(udoc)
if err == mgo.ErrNotFound {
err = errors.NotFoundf("user %q", name)
}
// DateCreated is inserted as UTC, but read out as local time. So we
// convert it back to UTC here.
udoc.DateCreated = udoc.DateCreated.UTC()
return err
}
|
go
|
func (st *State) getUser(name string, udoc *userDoc) error {
users, closer := st.db().GetCollection(usersC)
defer closer()
name = strings.ToLower(name)
err := users.Find(bson.D{{"_id", name}}).One(udoc)
if err == mgo.ErrNotFound {
err = errors.NotFoundf("user %q", name)
}
// DateCreated is inserted as UTC, but read out as local time. So we
// convert it back to UTC here.
udoc.DateCreated = udoc.DateCreated.UTC()
return err
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"getUser",
"(",
"name",
"string",
",",
"udoc",
"*",
"userDoc",
")",
"error",
"{",
"users",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"usersC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"name",
"=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n",
"err",
":=",
"users",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"name",
"}",
"}",
")",
".",
"One",
"(",
"udoc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"err",
"=",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"// DateCreated is inserted as UTC, but read out as local time. So we",
"// convert it back to UTC here.",
"udoc",
".",
"DateCreated",
"=",
"udoc",
".",
"DateCreated",
".",
"UTC",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// getUser fetches information about the user with the
// given name into the provided userDoc.
|
[
"getUser",
"fetches",
"information",
"about",
"the",
"user",
"with",
"the",
"given",
"name",
"into",
"the",
"provided",
"userDoc",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L189-L202
|
154,382 |
juju/juju
|
state/user.go
|
User
|
func (st *State) User(tag names.UserTag) (*User, error) {
if !tag.IsLocal() {
return nil, errors.NotFoundf("user %q", tag.Id())
}
user := &User{st: st}
if err := st.getUser(tag.Name(), &user.doc); err != nil {
return nil, errors.Trace(err)
}
if user.doc.Deleted {
// This error is returned to the apiserver and from there to the api
// client. So we don't annotate with information regarding deletion.
// TODO(redir): We'll return a deletedUserError in the future so we can
// return more appropriate errors, e.g. username not available.
return nil, DeletedUserError{UserName: user.Name()}
}
return user, nil
}
|
go
|
func (st *State) User(tag names.UserTag) (*User, error) {
if !tag.IsLocal() {
return nil, errors.NotFoundf("user %q", tag.Id())
}
user := &User{st: st}
if err := st.getUser(tag.Name(), &user.doc); err != nil {
return nil, errors.Trace(err)
}
if user.doc.Deleted {
// This error is returned to the apiserver and from there to the api
// client. So we don't annotate with information regarding deletion.
// TODO(redir): We'll return a deletedUserError in the future so we can
// return more appropriate errors, e.g. username not available.
return nil, DeletedUserError{UserName: user.Name()}
}
return user, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"User",
"(",
"tag",
"names",
".",
"UserTag",
")",
"(",
"*",
"User",
",",
"error",
")",
"{",
"if",
"!",
"tag",
".",
"IsLocal",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"user",
":=",
"&",
"User",
"{",
"st",
":",
"st",
"}",
"\n",
"if",
"err",
":=",
"st",
".",
"getUser",
"(",
"tag",
".",
"Name",
"(",
")",
",",
"&",
"user",
".",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"user",
".",
"doc",
".",
"Deleted",
"{",
"// This error is returned to the apiserver and from there to the api",
"// client. So we don't annotate with information regarding deletion.",
"// TODO(redir): We'll return a deletedUserError in the future so we can",
"// return more appropriate errors, e.g. username not available.",
"return",
"nil",
",",
"DeletedUserError",
"{",
"UserName",
":",
"user",
".",
"Name",
"(",
")",
"}",
"\n",
"}",
"\n",
"return",
"user",
",",
"nil",
"\n",
"}"
] |
// User returns the state User for the given name.
|
[
"User",
"returns",
"the",
"state",
"User",
"for",
"the",
"given",
"name",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L205-L221
|
154,383 |
juju/juju
|
state/user.go
|
AllUsers
|
func (st *State) AllUsers(includeDeactivated bool) ([]*User, error) {
var result []*User
users, closer := st.db().GetCollection(usersC)
defer closer()
var query bson.D
// TODO(redir): Provide option to retrieve deleted users in future PR.
// e.g. if !includeDelted.
// Ensure the query checks for users without the deleted attribute, and
// also that if it does that the value is not true. fwereade wanted to be
// sure we cannot miss users that previously existed without the deleted
// attr. Since this will only be in 2.0 that should never happen, but...
// belt and suspenders.
query = append(query, bson.DocElem{
"deleted", bson.D{{"$ne", true}},
})
// As above, in the case that a user previously existed and doesn't have a
// deactivated attribute, we make sure the query checks for the existence
// of the attribute, and if it exists that it is not true.
if !includeDeactivated {
query = append(query, bson.DocElem{
"deactivated", bson.D{{"$ne", true}},
})
}
iter := users.Find(query).Iter()
defer iter.Close()
var doc userDoc
for iter.Next(&doc) {
result = append(result, &User{st: st, doc: doc})
}
if err := iter.Close(); err != nil {
return nil, errors.Trace(err)
}
// Always return a predictable order, sort by Name.
sort.Sort(userList(result))
return result, nil
}
|
go
|
func (st *State) AllUsers(includeDeactivated bool) ([]*User, error) {
var result []*User
users, closer := st.db().GetCollection(usersC)
defer closer()
var query bson.D
// TODO(redir): Provide option to retrieve deleted users in future PR.
// e.g. if !includeDelted.
// Ensure the query checks for users without the deleted attribute, and
// also that if it does that the value is not true. fwereade wanted to be
// sure we cannot miss users that previously existed without the deleted
// attr. Since this will only be in 2.0 that should never happen, but...
// belt and suspenders.
query = append(query, bson.DocElem{
"deleted", bson.D{{"$ne", true}},
})
// As above, in the case that a user previously existed and doesn't have a
// deactivated attribute, we make sure the query checks for the existence
// of the attribute, and if it exists that it is not true.
if !includeDeactivated {
query = append(query, bson.DocElem{
"deactivated", bson.D{{"$ne", true}},
})
}
iter := users.Find(query).Iter()
defer iter.Close()
var doc userDoc
for iter.Next(&doc) {
result = append(result, &User{st: st, doc: doc})
}
if err := iter.Close(); err != nil {
return nil, errors.Trace(err)
}
// Always return a predictable order, sort by Name.
sort.Sort(userList(result))
return result, nil
}
|
[
"func",
"(",
"st",
"*",
"State",
")",
"AllUsers",
"(",
"includeDeactivated",
"bool",
")",
"(",
"[",
"]",
"*",
"User",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"*",
"User",
"\n\n",
"users",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"usersC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"query",
"bson",
".",
"D",
"\n",
"// TODO(redir): Provide option to retrieve deleted users in future PR.",
"// e.g. if !includeDelted.",
"// Ensure the query checks for users without the deleted attribute, and",
"// also that if it does that the value is not true. fwereade wanted to be",
"// sure we cannot miss users that previously existed without the deleted",
"// attr. Since this will only be in 2.0 that should never happen, but...",
"// belt and suspenders.",
"query",
"=",
"append",
"(",
"query",
",",
"bson",
".",
"DocElem",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"true",
"}",
"}",
",",
"}",
")",
"\n\n",
"// As above, in the case that a user previously existed and doesn't have a",
"// deactivated attribute, we make sure the query checks for the existence",
"// of the attribute, and if it exists that it is not true.",
"if",
"!",
"includeDeactivated",
"{",
"query",
"=",
"append",
"(",
"query",
",",
"bson",
".",
"DocElem",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"true",
"}",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"iter",
":=",
"users",
".",
"Find",
"(",
"query",
")",
".",
"Iter",
"(",
")",
"\n",
"defer",
"iter",
".",
"Close",
"(",
")",
"\n\n",
"var",
"doc",
"userDoc",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"doc",
")",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"User",
"{",
"st",
":",
"st",
",",
"doc",
":",
"doc",
"}",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"iter",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Always return a predictable order, sort by Name.",
"sort",
".",
"Sort",
"(",
"userList",
"(",
"result",
")",
")",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// AllUsers returns a slice of state.User. This includes all active users. If
// includeDeactivated is true it also returns inactive users. At this point it
// never returns deleted users.
|
[
"AllUsers",
"returns",
"a",
"slice",
"of",
"state",
".",
"User",
".",
"This",
"includes",
"all",
"active",
"users",
".",
"If",
"includeDeactivated",
"is",
"true",
"it",
"also",
"returns",
"inactive",
"users",
".",
"At",
"this",
"point",
"it",
"never",
"returns",
"deleted",
"users",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L226-L265
|
154,384 |
juju/juju
|
state/user.go
|
UserTag
|
func (u *User) UserTag() names.UserTag {
name := u.doc.Name
return names.NewLocalUserTag(name)
}
|
go
|
func (u *User) UserTag() names.UserTag {
name := u.doc.Name
return names.NewLocalUserTag(name)
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"UserTag",
"(",
")",
"names",
".",
"UserTag",
"{",
"name",
":=",
"u",
".",
"doc",
".",
"Name",
"\n",
"return",
"names",
".",
"NewLocalUserTag",
"(",
"name",
")",
"\n",
"}"
] |
// UserTag returns the Tag for the User.
|
[
"UserTag",
"returns",
"the",
"Tag",
"for",
"the",
"User",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L330-L333
|
154,385 |
juju/juju
|
state/user.go
|
LastLogin
|
func (u *User) LastLogin() (time.Time, error) {
lastLogins, closer := u.st.db().GetRawCollection(userLastLoginC)
defer closer()
var lastLogin userLastLoginDoc
err := lastLogins.FindId(u.doc.DocID).Select(bson.D{{"last-login", 1}}).One(&lastLogin)
if err != nil {
if err == mgo.ErrNotFound {
err = errors.Wrap(err, NeverLoggedInError(u.UserTag().Name()))
}
return time.Time{}, errors.Trace(err)
}
return lastLogin.LastLogin.UTC(), nil
}
|
go
|
func (u *User) LastLogin() (time.Time, error) {
lastLogins, closer := u.st.db().GetRawCollection(userLastLoginC)
defer closer()
var lastLogin userLastLoginDoc
err := lastLogins.FindId(u.doc.DocID).Select(bson.D{{"last-login", 1}}).One(&lastLogin)
if err != nil {
if err == mgo.ErrNotFound {
err = errors.Wrap(err, NeverLoggedInError(u.UserTag().Name()))
}
return time.Time{}, errors.Trace(err)
}
return lastLogin.LastLogin.UTC(), nil
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"LastLogin",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"lastLogins",
",",
"closer",
":=",
"u",
".",
"st",
".",
"db",
"(",
")",
".",
"GetRawCollection",
"(",
"userLastLoginC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"lastLogin",
"userLastLoginDoc",
"\n",
"err",
":=",
"lastLogins",
".",
"FindId",
"(",
"u",
".",
"doc",
".",
"DocID",
")",
".",
"Select",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"1",
"}",
"}",
")",
".",
"One",
"(",
"&",
"lastLogin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"err",
"=",
"errors",
".",
"Wrap",
"(",
"err",
",",
"NeverLoggedInError",
"(",
"u",
".",
"UserTag",
"(",
")",
".",
"Name",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"lastLogin",
".",
"LastLogin",
".",
"UTC",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// LastLogin returns when this User last connected through the API in UTC.
// The resulting time will be nil if the user has never logged in. In the
// normal case, the LastLogin is the last time that the user connected through
// the API server.
|
[
"LastLogin",
"returns",
"when",
"this",
"User",
"last",
"connected",
"through",
"the",
"API",
"in",
"UTC",
".",
"The",
"resulting",
"time",
"will",
"be",
"nil",
"if",
"the",
"user",
"has",
"never",
"logged",
"in",
".",
"In",
"the",
"normal",
"case",
"the",
"LastLogin",
"is",
"the",
"last",
"time",
"that",
"the",
"user",
"connected",
"through",
"the",
"API",
"server",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L339-L353
|
154,386 |
juju/juju
|
state/user.go
|
IsNeverLoggedInError
|
func IsNeverLoggedInError(err error) bool {
_, ok := errors.Cause(err).(NeverLoggedInError)
return ok
}
|
go
|
func IsNeverLoggedInError(err error) bool {
_, ok := errors.Cause(err).(NeverLoggedInError)
return ok
}
|
[
"func",
"IsNeverLoggedInError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"NeverLoggedInError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] |
// IsNeverLoggedInError returns true if err is of type NeverLoggedInError.
|
[
"IsNeverLoggedInError",
"returns",
"true",
"if",
"err",
"is",
"of",
"type",
"NeverLoggedInError",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L365-L368
|
154,387 |
juju/juju
|
state/user.go
|
SetPassword
|
func (u *User) SetPassword(password string) error {
if err := u.ensureNotDeleted(); err != nil {
return errors.Annotate(err, "cannot set password")
}
salt, err := utils.RandomSalt()
if err != nil {
return err
}
return u.SetPasswordHash(utils.UserPasswordHash(password, salt), salt)
}
|
go
|
func (u *User) SetPassword(password string) error {
if err := u.ensureNotDeleted(); err != nil {
return errors.Annotate(err, "cannot set password")
}
salt, err := utils.RandomSalt()
if err != nil {
return err
}
return u.SetPasswordHash(utils.UserPasswordHash(password, salt), salt)
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"SetPassword",
"(",
"password",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"u",
".",
"ensureNotDeleted",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"salt",
",",
"err",
":=",
"utils",
".",
"RandomSalt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"u",
".",
"SetPasswordHash",
"(",
"utils",
".",
"UserPasswordHash",
"(",
"password",
",",
"salt",
")",
",",
"salt",
")",
"\n",
"}"
] |
// SetPassword sets the password associated with the User.
|
[
"SetPassword",
"sets",
"the",
"password",
"associated",
"with",
"the",
"User",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L402-L411
|
154,388 |
juju/juju
|
state/user.go
|
SetPasswordHash
|
func (u *User) SetPasswordHash(pwHash string, pwSalt string) error {
if err := u.ensureNotDeleted(); err != nil {
// If we do get a late set of the password this is fine b/c we have an
// explicit check before login.
return errors.Annotate(err, "cannot set password hash")
}
update := bson.D{{"$set", bson.D{
{"passwordhash", pwHash},
{"passwordsalt", pwSalt},
}}}
if u.doc.SecretKey != nil {
update = append(update,
bson.DocElem{"$unset", bson.D{{"secretkey", ""}}},
)
}
ops := []txn.Op{{
C: usersC,
Id: u.Name(),
Assert: txn.DocExists,
Update: update,
}}
if err := u.st.db().RunTransaction(ops); err != nil {
return errors.Annotatef(err, "cannot set password of user %q", u.Name())
}
u.doc.PasswordHash = pwHash
u.doc.PasswordSalt = pwSalt
u.doc.SecretKey = nil
return nil
}
|
go
|
func (u *User) SetPasswordHash(pwHash string, pwSalt string) error {
if err := u.ensureNotDeleted(); err != nil {
// If we do get a late set of the password this is fine b/c we have an
// explicit check before login.
return errors.Annotate(err, "cannot set password hash")
}
update := bson.D{{"$set", bson.D{
{"passwordhash", pwHash},
{"passwordsalt", pwSalt},
}}}
if u.doc.SecretKey != nil {
update = append(update,
bson.DocElem{"$unset", bson.D{{"secretkey", ""}}},
)
}
ops := []txn.Op{{
C: usersC,
Id: u.Name(),
Assert: txn.DocExists,
Update: update,
}}
if err := u.st.db().RunTransaction(ops); err != nil {
return errors.Annotatef(err, "cannot set password of user %q", u.Name())
}
u.doc.PasswordHash = pwHash
u.doc.PasswordSalt = pwSalt
u.doc.SecretKey = nil
return nil
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"SetPasswordHash",
"(",
"pwHash",
"string",
",",
"pwSalt",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"u",
".",
"ensureNotDeleted",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"// If we do get a late set of the password this is fine b/c we have an",
"// explicit check before login.",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"update",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"pwHash",
"}",
",",
"{",
"\"",
"\"",
",",
"pwSalt",
"}",
",",
"}",
"}",
"}",
"\n",
"if",
"u",
".",
"doc",
".",
"SecretKey",
"!=",
"nil",
"{",
"update",
"=",
"append",
"(",
"update",
",",
"bson",
".",
"DocElem",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"}",
"}",
",",
")",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"usersC",
",",
"Id",
":",
"u",
".",
"Name",
"(",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"update",
",",
"}",
"}",
"\n",
"if",
"err",
":=",
"u",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"u",
".",
"doc",
".",
"PasswordHash",
"=",
"pwHash",
"\n",
"u",
".",
"doc",
".",
"PasswordSalt",
"=",
"pwSalt",
"\n",
"u",
".",
"doc",
".",
"SecretKey",
"=",
"nil",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetPasswordHash stores the hash and the salt of the
// password. If the User has a secret key set then it
// will be cleared.
|
[
"SetPasswordHash",
"stores",
"the",
"hash",
"and",
"the",
"salt",
"of",
"the",
"password",
".",
"If",
"the",
"User",
"has",
"a",
"secret",
"key",
"set",
"then",
"it",
"will",
"be",
"cleared",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L416-L444
|
154,389 |
juju/juju
|
state/user.go
|
PasswordValid
|
func (u *User) PasswordValid(password string) bool {
// If the User is deactivated or deleted, there is no point in carrying on.
// Since any authentication checks are done very soon after the user is
// read from the database, there is a very small timeframe where an user
// could be disabled after it has been read but prior to being checked, but
// in practice, this isn't a problem.
if u.IsDisabled() || u.IsDeleted() {
return false
}
if u.doc.PasswordSalt != "" {
return utils.UserPasswordHash(password, u.doc.PasswordSalt) == u.doc.PasswordHash
}
return false
}
|
go
|
func (u *User) PasswordValid(password string) bool {
// If the User is deactivated or deleted, there is no point in carrying on.
// Since any authentication checks are done very soon after the user is
// read from the database, there is a very small timeframe where an user
// could be disabled after it has been read but prior to being checked, but
// in practice, this isn't a problem.
if u.IsDisabled() || u.IsDeleted() {
return false
}
if u.doc.PasswordSalt != "" {
return utils.UserPasswordHash(password, u.doc.PasswordSalt) == u.doc.PasswordHash
}
return false
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"PasswordValid",
"(",
"password",
"string",
")",
"bool",
"{",
"// If the User is deactivated or deleted, there is no point in carrying on.",
"// Since any authentication checks are done very soon after the user is",
"// read from the database, there is a very small timeframe where an user",
"// could be disabled after it has been read but prior to being checked, but",
"// in practice, this isn't a problem.",
"if",
"u",
".",
"IsDisabled",
"(",
")",
"||",
"u",
".",
"IsDeleted",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"u",
".",
"doc",
".",
"PasswordSalt",
"!=",
"\"",
"\"",
"{",
"return",
"utils",
".",
"UserPasswordHash",
"(",
"password",
",",
"u",
".",
"doc",
".",
"PasswordSalt",
")",
"==",
"u",
".",
"doc",
".",
"PasswordHash",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// PasswordValid returns whether the given password is valid for the User. The
// caller should call user.Refresh before calling this.
|
[
"PasswordValid",
"returns",
"whether",
"the",
"given",
"password",
"is",
"valid",
"for",
"the",
"User",
".",
"The",
"caller",
"should",
"call",
"user",
".",
"Refresh",
"before",
"calling",
"this",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L448-L461
|
154,390 |
juju/juju
|
state/user.go
|
Refresh
|
func (u *User) Refresh() error {
var udoc userDoc
if err := u.st.getUser(u.Name(), &udoc); err != nil {
return err
}
u.doc = udoc
return nil
}
|
go
|
func (u *User) Refresh() error {
var udoc userDoc
if err := u.st.getUser(u.Name(), &udoc); err != nil {
return err
}
u.doc = udoc
return nil
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"Refresh",
"(",
")",
"error",
"{",
"var",
"udoc",
"userDoc",
"\n",
"if",
"err",
":=",
"u",
".",
"st",
".",
"getUser",
"(",
"u",
".",
"Name",
"(",
")",
",",
"&",
"udoc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"u",
".",
"doc",
"=",
"udoc",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Refresh refreshes information about the User from the state.
|
[
"Refresh",
"refreshes",
"information",
"about",
"the",
"User",
"from",
"the",
"state",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L464-L471
|
154,391 |
juju/juju
|
state/user.go
|
Disable
|
func (u *User) Disable() error {
if err := u.ensureNotDeleted(); err != nil {
return errors.Annotate(err, "cannot disable")
}
owner, err := u.st.ControllerOwner()
if err != nil {
return errors.Trace(err)
}
if u.doc.Name == owner.Name() {
return errors.Unauthorizedf("cannot disable controller model owner")
}
return errors.Annotatef(u.setDeactivated(true), "cannot disable user %q", u.Name())
}
|
go
|
func (u *User) Disable() error {
if err := u.ensureNotDeleted(); err != nil {
return errors.Annotate(err, "cannot disable")
}
owner, err := u.st.ControllerOwner()
if err != nil {
return errors.Trace(err)
}
if u.doc.Name == owner.Name() {
return errors.Unauthorizedf("cannot disable controller model owner")
}
return errors.Annotatef(u.setDeactivated(true), "cannot disable user %q", u.Name())
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"Disable",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"u",
".",
"ensureNotDeleted",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"owner",
",",
"err",
":=",
"u",
".",
"st",
".",
"ControllerOwner",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"u",
".",
"doc",
".",
"Name",
"==",
"owner",
".",
"Name",
"(",
")",
"{",
"return",
"errors",
".",
"Unauthorizedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"u",
".",
"setDeactivated",
"(",
"true",
")",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}"
] |
// Disable deactivates the user. Disabled identities cannot log in.
|
[
"Disable",
"deactivates",
"the",
"user",
".",
"Disabled",
"identities",
"cannot",
"log",
"in",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L474-L486
|
154,392 |
juju/juju
|
state/user.go
|
Enable
|
func (u *User) Enable() error {
if err := u.ensureNotDeleted(); err != nil {
return errors.Annotate(err, "cannot enable")
}
return errors.Annotatef(u.setDeactivated(false), "cannot enable user %q", u.Name())
}
|
go
|
func (u *User) Enable() error {
if err := u.ensureNotDeleted(); err != nil {
return errors.Annotate(err, "cannot enable")
}
return errors.Annotatef(u.setDeactivated(false), "cannot enable user %q", u.Name())
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"Enable",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"u",
".",
"ensureNotDeleted",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"u",
".",
"setDeactivated",
"(",
"false",
")",
",",
"\"",
"\"",
",",
"u",
".",
"Name",
"(",
")",
")",
"\n",
"}"
] |
// Enable reactivates the user, setting disabled to false.
|
[
"Enable",
"reactivates",
"the",
"user",
"setting",
"disabled",
"to",
"false",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L489-L494
|
154,393 |
juju/juju
|
state/user.go
|
ensureNotDeleted
|
func (u *User) ensureNotDeleted() error {
if err := u.Refresh(); err != nil {
return errors.Trace(err)
}
if u.doc.Deleted {
return DeletedUserError{u.Name()}
}
return nil
}
|
go
|
func (u *User) ensureNotDeleted() error {
if err := u.Refresh(); err != nil {
return errors.Trace(err)
}
if u.doc.Deleted {
return DeletedUserError{u.Name()}
}
return nil
}
|
[
"func",
"(",
"u",
"*",
"User",
")",
"ensureNotDeleted",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"u",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"u",
".",
"doc",
".",
"Deleted",
"{",
"return",
"DeletedUserError",
"{",
"u",
".",
"Name",
"(",
")",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ensureNotDeleted refreshes the user to ensure it wasn't deleted since we
// acquired it.
|
[
"ensureNotDeleted",
"refreshes",
"the",
"user",
"to",
"ensure",
"it",
"wasn",
"t",
"deleted",
"since",
"we",
"acquired",
"it",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L538-L546
|
154,394 |
juju/juju
|
state/user.go
|
generateSecretKey
|
func generateSecretKey() ([]byte, error) {
var secretKey [32]byte
if _, err := rand.Read(secretKey[:]); err != nil {
return nil, errors.Trace(err)
}
return secretKey[:], nil
}
|
go
|
func generateSecretKey() ([]byte, error) {
var secretKey [32]byte
if _, err := rand.Read(secretKey[:]); err != nil {
return nil, errors.Trace(err)
}
return secretKey[:], nil
}
|
[
"func",
"generateSecretKey",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"secretKey",
"[",
"32",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"rand",
".",
"Read",
"(",
"secretKey",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"secretKey",
"[",
":",
"]",
",",
"nil",
"\n",
"}"
] |
// generateSecretKey generates a random, 32-byte secret key.
|
[
"generateSecretKey",
"generates",
"a",
"random",
"32",
"-",
"byte",
"secret",
"key",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/user.go#L595-L601
|
154,395 |
juju/juju
|
worker/logger/logger.go
|
NewLogger
|
func NewLogger(api LoggerAPI, tag names.Tag, loggingOverride string, updateCallback func(string) error) (worker.Worker, error) {
logger := &Logger{
api: api,
tag: tag,
updateCallback: updateCallback,
lastConfig: loggo.LoggerInfo(),
configOverride: loggingOverride,
}
log.Debugf("initial log config: %q", logger.lastConfig)
w, err := watcher.NewNotifyWorker(watcher.NotifyConfig{
Handler: logger,
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
|
go
|
func NewLogger(api LoggerAPI, tag names.Tag, loggingOverride string, updateCallback func(string) error) (worker.Worker, error) {
logger := &Logger{
api: api,
tag: tag,
updateCallback: updateCallback,
lastConfig: loggo.LoggerInfo(),
configOverride: loggingOverride,
}
log.Debugf("initial log config: %q", logger.lastConfig)
w, err := watcher.NewNotifyWorker(watcher.NotifyConfig{
Handler: logger,
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
|
[
"func",
"NewLogger",
"(",
"api",
"LoggerAPI",
",",
"tag",
"names",
".",
"Tag",
",",
"loggingOverride",
"string",
",",
"updateCallback",
"func",
"(",
"string",
")",
"error",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"logger",
":=",
"&",
"Logger",
"{",
"api",
":",
"api",
",",
"tag",
":",
"tag",
",",
"updateCallback",
":",
"updateCallback",
",",
"lastConfig",
":",
"loggo",
".",
"LoggerInfo",
"(",
")",
",",
"configOverride",
":",
"loggingOverride",
",",
"}",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"logger",
".",
"lastConfig",
")",
"\n\n",
"w",
",",
"err",
":=",
"watcher",
".",
"NewNotifyWorker",
"(",
"watcher",
".",
"NotifyConfig",
"{",
"Handler",
":",
"logger",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] |
// NewLogger returns a worker.Worker that uses the notify watcher returned
// from the setup.
|
[
"NewLogger",
"returns",
"a",
"worker",
".",
"Worker",
"that",
"uses",
"the",
"notify",
"watcher",
"returned",
"from",
"the",
"setup",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/logger/logger.go#L35-L52
|
154,396 |
juju/juju
|
upgrades/steps_24.go
|
stateStepsFor24
|
func stateStepsFor24() []Step {
return []Step{
&upgradeStep{
description: "move or drop the old audit log collection",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().MoveOldAuditLog()
},
},
&upgradeStep{
description: "move controller info Mongo space to controller config HA space if valid",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().MoveMongoSpaceToHASpaceConfig()
},
},
&upgradeStep{
description: "create empty application settings for all applications",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().CreateMissingApplicationConfig()
},
},
&upgradeStep{
description: "remove votingmachineids",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RemoveVotingMachineIds()
},
},
&upgradeStep{
description: "add cloud model counts",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddCloudModelCounts()
},
},
&upgradeStep{
description: "bootstrap raft cluster",
targets: []Target{Controller},
run: BootstrapRaft,
},
}
}
|
go
|
func stateStepsFor24() []Step {
return []Step{
&upgradeStep{
description: "move or drop the old audit log collection",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().MoveOldAuditLog()
},
},
&upgradeStep{
description: "move controller info Mongo space to controller config HA space if valid",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().MoveMongoSpaceToHASpaceConfig()
},
},
&upgradeStep{
description: "create empty application settings for all applications",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().CreateMissingApplicationConfig()
},
},
&upgradeStep{
description: "remove votingmachineids",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RemoveVotingMachineIds()
},
},
&upgradeStep{
description: "add cloud model counts",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddCloudModelCounts()
},
},
&upgradeStep{
description: "bootstrap raft cluster",
targets: []Target{Controller},
run: BootstrapRaft,
},
}
}
|
[
"func",
"stateStepsFor24",
"(",
")",
"[",
"]",
"Step",
"{",
"return",
"[",
"]",
"Step",
"{",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"MoveOldAuditLog",
"(",
")",
"\n",
"}",
",",
"}",
",",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"MoveMongoSpaceToHASpaceConfig",
"(",
")",
"\n",
"}",
",",
"}",
",",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"CreateMissingApplicationConfig",
"(",
")",
"\n",
"}",
",",
"}",
",",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"RemoveVotingMachineIds",
"(",
")",
"\n",
"}",
",",
"}",
",",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"DatabaseMaster",
"}",
",",
"run",
":",
"func",
"(",
"context",
"Context",
")",
"error",
"{",
"return",
"context",
".",
"State",
"(",
")",
".",
"AddCloudModelCounts",
"(",
")",
"\n",
"}",
",",
"}",
",",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"Controller",
"}",
",",
"run",
":",
"BootstrapRaft",
",",
"}",
",",
"}",
"\n",
"}"
] |
// stateStepsFor24 returns upgrade steps for Juju 2.4.0 that manipulate state directly.
|
[
"stateStepsFor24",
"returns",
"upgrade",
"steps",
"for",
"Juju",
"2",
".",
"4",
".",
"0",
"that",
"manipulate",
"state",
"directly",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_24.go#L17-L60
|
154,397 |
juju/juju
|
upgrades/steps_24.go
|
stepsFor24
|
func stepsFor24() []Step {
return []Step{
&upgradeStep{
description: "Install the service file in Standard location '/lib/systemd'",
targets: []Target{AllMachines},
run: installServiceFile,
},
}
}
|
go
|
func stepsFor24() []Step {
return []Step{
&upgradeStep{
description: "Install the service file in Standard location '/lib/systemd'",
targets: []Target{AllMachines},
run: installServiceFile,
},
}
}
|
[
"func",
"stepsFor24",
"(",
")",
"[",
"]",
"Step",
"{",
"return",
"[",
"]",
"Step",
"{",
"&",
"upgradeStep",
"{",
"description",
":",
"\"",
"\"",
",",
"targets",
":",
"[",
"]",
"Target",
"{",
"AllMachines",
"}",
",",
"run",
":",
"installServiceFile",
",",
"}",
",",
"}",
"\n",
"}"
] |
// stepsFor24 returns upgrade steps for Juju 2.4.
|
[
"stepsFor24",
"returns",
"upgrade",
"steps",
"for",
"Juju",
"2",
".",
"4",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_24.go#L63-L71
|
154,398 |
juju/juju
|
cmd/juju/romulus/commands/commands.go
|
RegisterAll
|
func RegisterAll(r commandRegister) {
r.Register(agree.NewAgreeCommand())
r.Register(listagreements.NewListAgreementsCommand())
r.Register(budget.NewBudgetCommand())
r.Register(createwallet.NewCreateWalletCommand())
r.Register(listplans.NewListPlansCommand())
r.Register(setwallet.NewSetWalletCommand())
r.Register(setplan.NewSetPlanCommand())
r.Register(showwallet.NewShowWalletCommand())
r.Register(sla.NewSLACommand())
r.Register(listwallets.NewListWalletsCommand())
}
|
go
|
func RegisterAll(r commandRegister) {
r.Register(agree.NewAgreeCommand())
r.Register(listagreements.NewListAgreementsCommand())
r.Register(budget.NewBudgetCommand())
r.Register(createwallet.NewCreateWalletCommand())
r.Register(listplans.NewListPlansCommand())
r.Register(setwallet.NewSetWalletCommand())
r.Register(setplan.NewSetPlanCommand())
r.Register(showwallet.NewShowWalletCommand())
r.Register(sla.NewSLACommand())
r.Register(listwallets.NewListWalletsCommand())
}
|
[
"func",
"RegisterAll",
"(",
"r",
"commandRegister",
")",
"{",
"r",
".",
"Register",
"(",
"agree",
".",
"NewAgreeCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"listagreements",
".",
"NewListAgreementsCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"budget",
".",
"NewBudgetCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"createwallet",
".",
"NewCreateWalletCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"listplans",
".",
"NewListPlansCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"setwallet",
".",
"NewSetWalletCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"setplan",
".",
"NewSetPlanCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"showwallet",
".",
"NewShowWalletCommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"sla",
".",
"NewSLACommand",
"(",
")",
")",
"\n",
"r",
".",
"Register",
"(",
"listwallets",
".",
"NewListWalletsCommand",
"(",
")",
")",
"\n",
"}"
] |
// RegisterAll registers all romulus commands with the
// provided command registry.
|
[
"RegisterAll",
"registers",
"all",
"romulus",
"commands",
"with",
"the",
"provided",
"command",
"registry",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/commands/commands.go#L28-L39
|
154,399 |
juju/juju
|
migration/dialopts.go
|
ControllerDialOpts
|
func ControllerDialOpts() api.DialOpts {
return api.DialOpts{
DialAddressInterval: 50 * time.Millisecond,
Timeout: 1 * time.Second,
RetryDelay: 100 * time.Millisecond,
}
}
|
go
|
func ControllerDialOpts() api.DialOpts {
return api.DialOpts{
DialAddressInterval: 50 * time.Millisecond,
Timeout: 1 * time.Second,
RetryDelay: 100 * time.Millisecond,
}
}
|
[
"func",
"ControllerDialOpts",
"(",
")",
"api",
".",
"DialOpts",
"{",
"return",
"api",
".",
"DialOpts",
"{",
"DialAddressInterval",
":",
"50",
"*",
"time",
".",
"Millisecond",
",",
"Timeout",
":",
"1",
"*",
"time",
".",
"Second",
",",
"RetryDelay",
":",
"100",
"*",
"time",
".",
"Millisecond",
",",
"}",
"\n",
"}"
] |
// ControllerDialOpts returns dial parameters suitable for connecting
// from the source controller to the target controller during model
// migrations. The total attempt time can't be too long because the
// areas of the code which make these connections need to be
// interruptable but a number of retries is useful to deal with short
// lived issues.
|
[
"ControllerDialOpts",
"returns",
"dial",
"parameters",
"suitable",
"for",
"connecting",
"from",
"the",
"source",
"controller",
"to",
"the",
"target",
"controller",
"during",
"model",
"migrations",
".",
"The",
"total",
"attempt",
"time",
"can",
"t",
"be",
"too",
"long",
"because",
"the",
"areas",
"of",
"the",
"code",
"which",
"make",
"these",
"connections",
"need",
"to",
"be",
"interruptable",
"but",
"a",
"number",
"of",
"retries",
"is",
"useful",
"to",
"deal",
"with",
"short",
"lived",
"issues",
"."
] |
ba728eedb1e44937c7bdc59f374b06400d0c7133
|
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/dialopts.go#L18-L24
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.