id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
153,600
juju/juju
agent/tools/toolsdir.go
ReadTools
func ReadTools(dataDir string, vers version.Binary) (*coretools.Tools, error) { dir := SharedToolsDir(dataDir, vers) toolsData, err := ioutil.ReadFile(path.Join(dir, toolsFile)) if err != nil { return nil, fmt.Errorf("cannot read agent metadata in directory %v: %v", dir, err) } var tools coretools.Tools if err := json.Unmarshal(toolsData, &tools); err != nil { return nil, fmt.Errorf("invalid agent metadata in directory %q: %v", dir, err) } return &tools, nil }
go
func ReadTools(dataDir string, vers version.Binary) (*coretools.Tools, error) { dir := SharedToolsDir(dataDir, vers) toolsData, err := ioutil.ReadFile(path.Join(dir, toolsFile)) if err != nil { return nil, fmt.Errorf("cannot read agent metadata in directory %v: %v", dir, err) } var tools coretools.Tools if err := json.Unmarshal(toolsData, &tools); err != nil { return nil, fmt.Errorf("invalid agent metadata in directory %q: %v", dir, err) } return &tools, nil }
[ "func", "ReadTools", "(", "dataDir", "string", ",", "vers", "version", ".", "Binary", ")", "(", "*", "coretools", ".", "Tools", ",", "error", ")", "{", "dir", ":=", "SharedToolsDir", "(", "dataDir", ",", "vers", ")", "\n", "toolsData", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ".", "Join", "(", "dir", ",", "toolsFile", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ")", "\n", "}", "\n", "var", "tools", "coretools", ".", "Tools", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "toolsData", ",", "&", "tools", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ")", "\n", "}", "\n", "return", "&", "tools", ",", "nil", "\n", "}" ]
// ReadTools checks that the tools information for the given version exists // in the dataDir directory, and returns a Tools instance. // The tools information is json encoded in a text file, "downloaded-tools.txt".
[ "ReadTools", "checks", "that", "the", "tools", "information", "for", "the", "given", "version", "exists", "in", "the", "dataDir", "directory", "and", "returns", "a", "Tools", "instance", ".", "The", "tools", "information", "is", "json", "encoded", "in", "a", "text", "file", "downloaded", "-", "tools", ".", "txt", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/tools/toolsdir.go#L164-L175
153,601
juju/juju
agent/tools/toolsdir.go
ReadGUIArchive
func ReadGUIArchive(dataDir string) (*coretools.GUIArchive, error) { dir := SharedGUIDir(dataDir) toolsData, err := ioutil.ReadFile(path.Join(dir, guiArchiveFile)) if err != nil { if os.IsNotExist(err) { return nil, errors.NotFoundf("GUI metadata") } return nil, fmt.Errorf("cannot read GUI metadata in directory %q: %v", dir, err) } var gui coretools.GUIArchive if err := json.Unmarshal(toolsData, &gui); err != nil { return nil, fmt.Errorf("invalid GUI metadata in directory %q: %v", dir, err) } return &gui, nil }
go
func ReadGUIArchive(dataDir string) (*coretools.GUIArchive, error) { dir := SharedGUIDir(dataDir) toolsData, err := ioutil.ReadFile(path.Join(dir, guiArchiveFile)) if err != nil { if os.IsNotExist(err) { return nil, errors.NotFoundf("GUI metadata") } return nil, fmt.Errorf("cannot read GUI metadata in directory %q: %v", dir, err) } var gui coretools.GUIArchive if err := json.Unmarshal(toolsData, &gui); err != nil { return nil, fmt.Errorf("invalid GUI metadata in directory %q: %v", dir, err) } return &gui, nil }
[ "func", "ReadGUIArchive", "(", "dataDir", "string", ")", "(", "*", "coretools", ".", "GUIArchive", ",", "error", ")", "{", "dir", ":=", "SharedGUIDir", "(", "dataDir", ")", "\n", "toolsData", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ".", "Join", "(", "dir", ",", "guiArchiveFile", ")", ")", "\n", "if", "err", "!=", "nil", "{", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ")", "\n", "}", "\n", "var", "gui", "coretools", ".", "GUIArchive", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "toolsData", ",", "&", "gui", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ")", "\n", "}", "\n", "return", "&", "gui", ",", "nil", "\n", "}" ]
// ReadGUIArchive reads the GUI information from the dataDir directory. // The GUI information is JSON encoded in a text file, "downloaded-gui.txt".
[ "ReadGUIArchive", "reads", "the", "GUI", "information", "from", "the", "dataDir", "directory", ".", "The", "GUI", "information", "is", "JSON", "encoded", "in", "a", "text", "file", "downloaded", "-", "gui", ".", "txt", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/tools/toolsdir.go#L179-L193
153,602
juju/juju
agent/tools/toolsdir.go
ChangeAgentTools
func ChangeAgentTools(dataDir string, agentName string, vers version.Binary) (*coretools.Tools, error) { tools, err := ReadTools(dataDir, vers) if err != nil { return nil, err } // build absolute path to toolsDir. Windows implementation of symlink // will check for the existence of the source file and error if it does // not exists. This is a limitation of junction points (symlinks) on NTFS toolPath := ToolsDir(dataDir, tools.Version.String()) toolsDir := ToolsDir(dataDir, agentName) err = symlink.Replace(toolsDir, toolPath) if err != nil { return nil, fmt.Errorf("cannot replace tools directory: %s", err) } return tools, nil }
go
func ChangeAgentTools(dataDir string, agentName string, vers version.Binary) (*coretools.Tools, error) { tools, err := ReadTools(dataDir, vers) if err != nil { return nil, err } // build absolute path to toolsDir. Windows implementation of symlink // will check for the existence of the source file and error if it does // not exists. This is a limitation of junction points (symlinks) on NTFS toolPath := ToolsDir(dataDir, tools.Version.String()) toolsDir := ToolsDir(dataDir, agentName) err = symlink.Replace(toolsDir, toolPath) if err != nil { return nil, fmt.Errorf("cannot replace tools directory: %s", err) } return tools, nil }
[ "func", "ChangeAgentTools", "(", "dataDir", "string", ",", "agentName", "string", ",", "vers", "version", ".", "Binary", ")", "(", "*", "coretools", ".", "Tools", ",", "error", ")", "{", "tools", ",", "err", ":=", "ReadTools", "(", "dataDir", ",", "vers", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// build absolute path to toolsDir. Windows implementation of symlink", "// will check for the existence of the source file and error if it does", "// not exists. This is a limitation of junction points (symlinks) on NTFS", "toolPath", ":=", "ToolsDir", "(", "dataDir", ",", "tools", ".", "Version", ".", "String", "(", ")", ")", "\n", "toolsDir", ":=", "ToolsDir", "(", "dataDir", ",", "agentName", ")", "\n\n", "err", "=", "symlink", ".", "Replace", "(", "toolsDir", ",", "toolPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "tools", ",", "nil", "\n", "}" ]
// ChangeAgentTools atomically replaces the agent-specific symlink // under dataDir so it points to the previously unpacked // version vers. It returns the new tools read.
[ "ChangeAgentTools", "atomically", "replaces", "the", "agent", "-", "specific", "symlink", "under", "dataDir", "so", "it", "points", "to", "the", "previously", "unpacked", "version", "vers", ".", "It", "returns", "the", "new", "tools", "read", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/tools/toolsdir.go#L198-L214
153,603
juju/juju
agent/tools/toolsdir.go
WriteToolsMetadataData
func WriteToolsMetadataData(dir string, tools *coretools.Tools) error { toolsMetadataData, err := json.Marshal(tools) if err != nil { return err } return ioutil.WriteFile(path.Join(dir, toolsFile), toolsMetadataData, filePerm) }
go
func WriteToolsMetadataData(dir string, tools *coretools.Tools) error { toolsMetadataData, err := json.Marshal(tools) if err != nil { return err } return ioutil.WriteFile(path.Join(dir, toolsFile), toolsMetadataData, filePerm) }
[ "func", "WriteToolsMetadataData", "(", "dir", "string", ",", "tools", "*", "coretools", ".", "Tools", ")", "error", "{", "toolsMetadataData", ",", "err", ":=", "json", ".", "Marshal", "(", "tools", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ioutil", ".", "WriteFile", "(", "path", ".", "Join", "(", "dir", ",", "toolsFile", ")", ",", "toolsMetadataData", ",", "filePerm", ")", "\n", "}" ]
// WriteToolsMetadataData writes the tools metadata file to the given directory.
[ "WriteToolsMetadataData", "writes", "the", "tools", "metadata", "file", "to", "the", "given", "directory", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/tools/toolsdir.go#L217-L223
153,604
juju/juju
apiserver/facades/agent/resourceshookcontext/unitfacade.go
NewHookContextFacade
func NewHookContextFacade(st *state.State, unit *state.Unit) (interface{}, error) { res, err := st.Resources() if err != nil { return nil, errors.Trace(err) } return NewUnitFacade(&resourcesUnitDataStore{res, unit}), nil }
go
func NewHookContextFacade(st *state.State, unit *state.Unit) (interface{}, error) { res, err := st.Resources() if err != nil { return nil, errors.Trace(err) } return NewUnitFacade(&resourcesUnitDataStore{res, unit}), nil }
[ "func", "NewHookContextFacade", "(", "st", "*", "state", ".", "State", ",", "unit", "*", "state", ".", "Unit", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "res", ",", "err", ":=", "st", ".", "Resources", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "NewUnitFacade", "(", "&", "resourcesUnitDataStore", "{", "res", ",", "unit", "}", ")", ",", "nil", "\n", "}" ]
// NewHookContextFacade adapts NewUnitFacade for facade registration.
[ "NewHookContextFacade", "adapts", "NewUnitFacade", "for", "facade", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/resourceshookcontext/unitfacade.go#L19-L25
153,605
juju/juju
apiserver/facades/agent/resourceshookcontext/unitfacade.go
NewStateFacade
func NewStateFacade(ctx facade.Context) (*UnitFacade, error) { authorizer := ctx.Auth() st := ctx.State() if !authorizer.AuthUnitAgent() && !authorizer.AuthApplicationAgent() { return nil, common.ErrPerm } var ( unit *state.Unit err error ) switch tag := authorizer.GetAuthTag().(type) { case names.UnitTag: unit, err = st.Unit(tag.Id()) if err != nil { return nil, errors.Trace(err) } case names.ApplicationTag: // Allow application access for K8s units. As they are all homogeneous any of the units will suffice. app, err := st.Application(tag.Id()) if err != nil { return nil, errors.Trace(err) } allUnits, err := app.AllUnits() if err != nil { return nil, errors.Trace(err) } if len(allUnits) <= 0 { return nil, errors.Errorf("failed to get units for app: %s", app.Name()) } unit = allUnits[0] default: return nil, errors.Errorf("expected names.UnitTag or names.ApplicationTag, got %T", tag) } res, err := st.Resources() if err != nil { return nil, errors.Trace(err) } return NewUnitFacade(&resourcesUnitDataStore{res, unit}), nil }
go
func NewStateFacade(ctx facade.Context) (*UnitFacade, error) { authorizer := ctx.Auth() st := ctx.State() if !authorizer.AuthUnitAgent() && !authorizer.AuthApplicationAgent() { return nil, common.ErrPerm } var ( unit *state.Unit err error ) switch tag := authorizer.GetAuthTag().(type) { case names.UnitTag: unit, err = st.Unit(tag.Id()) if err != nil { return nil, errors.Trace(err) } case names.ApplicationTag: // Allow application access for K8s units. As they are all homogeneous any of the units will suffice. app, err := st.Application(tag.Id()) if err != nil { return nil, errors.Trace(err) } allUnits, err := app.AllUnits() if err != nil { return nil, errors.Trace(err) } if len(allUnits) <= 0 { return nil, errors.Errorf("failed to get units for app: %s", app.Name()) } unit = allUnits[0] default: return nil, errors.Errorf("expected names.UnitTag or names.ApplicationTag, got %T", tag) } res, err := st.Resources() if err != nil { return nil, errors.Trace(err) } return NewUnitFacade(&resourcesUnitDataStore{res, unit}), nil }
[ "func", "NewStateFacade", "(", "ctx", "facade", ".", "Context", ")", "(", "*", "UnitFacade", ",", "error", ")", "{", "authorizer", ":=", "ctx", ".", "Auth", "(", ")", "\n", "st", ":=", "ctx", ".", "State", "(", ")", "\n\n", "if", "!", "authorizer", ".", "AuthUnitAgent", "(", ")", "&&", "!", "authorizer", ".", "AuthApplicationAgent", "(", ")", "{", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}", "\n\n", "var", "(", "unit", "*", "state", ".", "Unit", "\n", "err", "error", "\n", ")", "\n", "switch", "tag", ":=", "authorizer", ".", "GetAuthTag", "(", ")", ".", "(", "type", ")", "{", "case", "names", ".", "UnitTag", ":", "unit", ",", "err", "=", "st", ".", "Unit", "(", "tag", ".", "Id", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "case", "names", ".", "ApplicationTag", ":", "// Allow application access for K8s units. As they are all homogeneous any of the units will suffice.", "app", ",", "err", ":=", "st", ".", "Application", "(", "tag", ".", "Id", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "allUnits", ",", "err", ":=", "app", ".", "AllUnits", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "allUnits", ")", "<=", "0", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "app", ".", "Name", "(", ")", ")", "\n", "}", "\n", "unit", "=", "allUnits", "[", "0", "]", "\n", "default", ":", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "tag", ")", "\n", "}", "\n\n", "res", ",", "err", ":=", "st", ".", "Resources", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "NewUnitFacade", "(", "&", "resourcesUnitDataStore", "{", "res", ",", "unit", "}", ")", ",", "nil", "\n", "}" ]
// NewStateFacade provides the signature to register this resource facade
[ "NewStateFacade", "provides", "the", "signature", "to", "register", "this", "resource", "facade" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/resourceshookcontext/unitfacade.go#L28-L69
153,606
juju/juju
cmd/juju/commands/bootstrap.go
credentialsAndRegionName
func (c *bootstrapCommand) credentialsAndRegionName( ctx *cmd.Context, provider environs.EnvironProvider, cloud jujucloud.Cloud, ) ( creds bootstrapCredentials, regionName string, err error, ) { store := c.ClientStore() // When looking for credentials, we should attempt to see if there are any // credentials that should be registered, before we get or detect them err = common.RegisterCredentials(ctx, store, provider, modelcmd.RegisterCredentialsParams{ Cloud: cloud, }) if err != nil { logger.Errorf("registering credentials errored %s", err) } var detected bool creds.credential, creds.name, regionName, detected, err = common.GetOrDetectCredential( ctx, store, provider, modelcmd.GetCredentialsParams{ Cloud: cloud, CloudRegion: c.Region, CredentialName: c.CredentialName, }, ) switch errors.Cause(err) { case nil: case modelcmd.ErrMultipleCredentials: return bootstrapCredentials{}, "", ambiguousCredentialError case common.ErrMultipleDetectedCredentials: return bootstrapCredentials{}, "", ambiguousDetectedCredentialError default: return bootstrapCredentials{}, "", errors.Trace(err) } logger.Debugf( "authenticating with region %q and credential %q (%v)", regionName, creds.name, creds.credential.Label, ) if detected { creds.detectedName = creds.name creds.name = "" } logger.Tracef("credential: %v", creds.credential) return creds, regionName, nil }
go
func (c *bootstrapCommand) credentialsAndRegionName( ctx *cmd.Context, provider environs.EnvironProvider, cloud jujucloud.Cloud, ) ( creds bootstrapCredentials, regionName string, err error, ) { store := c.ClientStore() // When looking for credentials, we should attempt to see if there are any // credentials that should be registered, before we get or detect them err = common.RegisterCredentials(ctx, store, provider, modelcmd.RegisterCredentialsParams{ Cloud: cloud, }) if err != nil { logger.Errorf("registering credentials errored %s", err) } var detected bool creds.credential, creds.name, regionName, detected, err = common.GetOrDetectCredential( ctx, store, provider, modelcmd.GetCredentialsParams{ Cloud: cloud, CloudRegion: c.Region, CredentialName: c.CredentialName, }, ) switch errors.Cause(err) { case nil: case modelcmd.ErrMultipleCredentials: return bootstrapCredentials{}, "", ambiguousCredentialError case common.ErrMultipleDetectedCredentials: return bootstrapCredentials{}, "", ambiguousDetectedCredentialError default: return bootstrapCredentials{}, "", errors.Trace(err) } logger.Debugf( "authenticating with region %q and credential %q (%v)", regionName, creds.name, creds.credential.Label, ) if detected { creds.detectedName = creds.name creds.name = "" } logger.Tracef("credential: %v", creds.credential) return creds, regionName, nil }
[ "func", "(", "c", "*", "bootstrapCommand", ")", "credentialsAndRegionName", "(", "ctx", "*", "cmd", ".", "Context", ",", "provider", "environs", ".", "EnvironProvider", ",", "cloud", "jujucloud", ".", "Cloud", ",", ")", "(", "creds", "bootstrapCredentials", ",", "regionName", "string", ",", "err", "error", ",", ")", "{", "store", ":=", "c", ".", "ClientStore", "(", ")", "\n\n", "// When looking for credentials, we should attempt to see if there are any", "// credentials that should be registered, before we get or detect them", "err", "=", "common", ".", "RegisterCredentials", "(", "ctx", ",", "store", ",", "provider", ",", "modelcmd", ".", "RegisterCredentialsParams", "{", "Cloud", ":", "cloud", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "var", "detected", "bool", "\n", "creds", ".", "credential", ",", "creds", ".", "name", ",", "regionName", ",", "detected", ",", "err", "=", "common", ".", "GetOrDetectCredential", "(", "ctx", ",", "store", ",", "provider", ",", "modelcmd", ".", "GetCredentialsParams", "{", "Cloud", ":", "cloud", ",", "CloudRegion", ":", "c", ".", "Region", ",", "CredentialName", ":", "c", ".", "CredentialName", ",", "}", ",", ")", "\n", "switch", "errors", ".", "Cause", "(", "err", ")", "{", "case", "nil", ":", "case", "modelcmd", ".", "ErrMultipleCredentials", ":", "return", "bootstrapCredentials", "{", "}", ",", "\"", "\"", ",", "ambiguousCredentialError", "\n", "case", "common", ".", "ErrMultipleDetectedCredentials", ":", "return", "bootstrapCredentials", "{", "}", ",", "\"", "\"", ",", "ambiguousDetectedCredentialError", "\n", "default", ":", "return", "bootstrapCredentials", "{", "}", ",", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "regionName", ",", "creds", ".", "name", ",", "creds", ".", "credential", ".", "Label", ",", ")", "\n", "if", "detected", "{", "creds", ".", "detectedName", "=", "creds", ".", "name", "\n", "creds", ".", "name", "=", "\"", "\"", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "creds", ".", "credential", ")", "\n", "return", "creds", ",", "regionName", ",", "nil", "\n", "}" ]
// Get the credentials and region name.
[ "Get", "the", "credentials", "and", "region", "name", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/bootstrap.go#L978-L1026
153,607
juju/juju
cmd/juju/commands/bootstrap.go
runInteractive
func (c *bootstrapCommand) runInteractive(ctx *cmd.Context) error { scanner := bufio.NewScanner(ctx.Stdin) clouds, err := assembleClouds() if err != nil { return errors.Trace(err) } c.Cloud, err = queryCloud(clouds, lxdnames.DefaultCloud, scanner, ctx.Stdout) if err != nil { return errors.Trace(err) } cloud, err := common.CloudByName(c.Cloud) if err != nil { return errors.Trace(err) } switch len(cloud.Regions) { case 0: // No region to choose, nothing to do. case 1: // If there's just one, don't prompt, just use it. c.Region = cloud.Regions[0].Name default: c.Region, err = queryRegion(c.Cloud, cloud.Regions, scanner, ctx.Stdout) if err != nil { return errors.Trace(err) } } defName := defaultControllerName(c.Cloud, c.Region) c.controllerName, err = queryName(defName, scanner, ctx.Stdout) if err != nil { return errors.Trace(err) } return nil }
go
func (c *bootstrapCommand) runInteractive(ctx *cmd.Context) error { scanner := bufio.NewScanner(ctx.Stdin) clouds, err := assembleClouds() if err != nil { return errors.Trace(err) } c.Cloud, err = queryCloud(clouds, lxdnames.DefaultCloud, scanner, ctx.Stdout) if err != nil { return errors.Trace(err) } cloud, err := common.CloudByName(c.Cloud) if err != nil { return errors.Trace(err) } switch len(cloud.Regions) { case 0: // No region to choose, nothing to do. case 1: // If there's just one, don't prompt, just use it. c.Region = cloud.Regions[0].Name default: c.Region, err = queryRegion(c.Cloud, cloud.Regions, scanner, ctx.Stdout) if err != nil { return errors.Trace(err) } } defName := defaultControllerName(c.Cloud, c.Region) c.controllerName, err = queryName(defName, scanner, ctx.Stdout) if err != nil { return errors.Trace(err) } return nil }
[ "func", "(", "c", "*", "bootstrapCommand", ")", "runInteractive", "(", "ctx", "*", "cmd", ".", "Context", ")", "error", "{", "scanner", ":=", "bufio", ".", "NewScanner", "(", "ctx", ".", "Stdin", ")", "\n", "clouds", ",", "err", ":=", "assembleClouds", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "c", ".", "Cloud", ",", "err", "=", "queryCloud", "(", "clouds", ",", "lxdnames", ".", "DefaultCloud", ",", "scanner", ",", "ctx", ".", "Stdout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "cloud", ",", "err", ":=", "common", ".", "CloudByName", "(", "c", ".", "Cloud", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "switch", "len", "(", "cloud", ".", "Regions", ")", "{", "case", "0", ":", "// No region to choose, nothing to do.", "case", "1", ":", "// If there's just one, don't prompt, just use it.", "c", ".", "Region", "=", "cloud", ".", "Regions", "[", "0", "]", ".", "Name", "\n", "default", ":", "c", ".", "Region", ",", "err", "=", "queryRegion", "(", "c", ".", "Cloud", ",", "cloud", ".", "Regions", ",", "scanner", ",", "ctx", ".", "Stdout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n\n", "defName", ":=", "defaultControllerName", "(", "c", ".", "Cloud", ",", "c", ".", "Region", ")", "\n\n", "c", ".", "controllerName", ",", "err", "=", "queryName", "(", "defName", ",", "scanner", ",", "ctx", ".", "Stdout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// runInteractive queries the user about bootstrap config interactively at the // command prompt.
[ "runInteractive", "queries", "the", "user", "about", "bootstrap", "config", "interactively", "at", "the", "command", "prompt", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/bootstrap.go#L1251-L1286
153,608
juju/juju
cmd/juju/commands/bootstrap.go
checkProviderType
func checkProviderType(envType string) error { featureflag.SetFlagsFromEnvironment(osenv.JujuFeatureFlagEnvKey) flag, ok := provisionalProviders[envType] if ok && !featureflag.Enabled(flag) { msg := `the %q provider is provisional in this version of Juju. To use it anyway, set JUJU_DEV_FEATURE_FLAGS="%s" in your shell model` return errors.Errorf(msg, envType, flag) } return nil }
go
func checkProviderType(envType string) error { featureflag.SetFlagsFromEnvironment(osenv.JujuFeatureFlagEnvKey) flag, ok := provisionalProviders[envType] if ok && !featureflag.Enabled(flag) { msg := `the %q provider is provisional in this version of Juju. To use it anyway, set JUJU_DEV_FEATURE_FLAGS="%s" in your shell model` return errors.Errorf(msg, envType, flag) } return nil }
[ "func", "checkProviderType", "(", "envType", "string", ")", "error", "{", "featureflag", ".", "SetFlagsFromEnvironment", "(", "osenv", ".", "JujuFeatureFlagEnvKey", ")", "\n", "flag", ",", "ok", ":=", "provisionalProviders", "[", "envType", "]", "\n", "if", "ok", "&&", "!", "featureflag", ".", "Enabled", "(", "flag", ")", "{", "msg", ":=", "`the %q provider is provisional in this version of Juju. To use it anyway, set JUJU_DEV_FEATURE_FLAGS=\"%s\" in your shell model`", "\n", "return", "errors", ".", "Errorf", "(", "msg", ",", "envType", ",", "flag", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// checkProviderType ensures the provider type is okay.
[ "checkProviderType", "ensures", "the", "provider", "type", "is", "okay", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/bootstrap.go#L1289-L1297
153,609
juju/juju
cmd/juju/commands/bootstrap.go
handleBootstrapError
func handleBootstrapError(ctx *cmd.Context, cleanup func() error) { ch := make(chan os.Signal, 1) ctx.InterruptNotify(ch) defer ctx.StopInterruptNotify(ch) defer close(ch) go func() { for range ch { fmt.Fprintln(ctx.GetStderr(), "Cleaning up failed bootstrap") } }() logger.Debugf("cleaning up after failed bootstrap") if err := cleanup(); err != nil { logger.Errorf("error cleaning up: %v", err) } }
go
func handleBootstrapError(ctx *cmd.Context, cleanup func() error) { ch := make(chan os.Signal, 1) ctx.InterruptNotify(ch) defer ctx.StopInterruptNotify(ch) defer close(ch) go func() { for range ch { fmt.Fprintln(ctx.GetStderr(), "Cleaning up failed bootstrap") } }() logger.Debugf("cleaning up after failed bootstrap") if err := cleanup(); err != nil { logger.Errorf("error cleaning up: %v", err) } }
[ "func", "handleBootstrapError", "(", "ctx", "*", "cmd", ".", "Context", ",", "cleanup", "func", "(", ")", "error", ")", "{", "ch", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "1", ")", "\n", "ctx", ".", "InterruptNotify", "(", "ch", ")", "\n", "defer", "ctx", ".", "StopInterruptNotify", "(", "ch", ")", "\n", "defer", "close", "(", "ch", ")", "\n", "go", "func", "(", ")", "{", "for", "range", "ch", "{", "fmt", ".", "Fprintln", "(", "ctx", ".", "GetStderr", "(", ")", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "(", ")", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "cleanup", "(", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// handleBootstrapError is called to clean up if bootstrap fails.
[ "handleBootstrapError", "is", "called", "to", "clean", "up", "if", "bootstrap", "fails", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/bootstrap.go#L1300-L1314
153,610
juju/juju
provider/gce/environ_firewall.go
OpenPorts
func (env *environ) OpenPorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { err := env.gce.OpenPorts(env.globalFirewallName(), rules...) return google.HandleCredentialError(errors.Trace(err), ctx) }
go
func (env *environ) OpenPorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { err := env.gce.OpenPorts(env.globalFirewallName(), rules...) return google.HandleCredentialError(errors.Trace(err), ctx) }
[ "func", "(", "env", "*", "environ", ")", "OpenPorts", "(", "ctx", "context", ".", "ProviderCallContext", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "err", ":=", "env", ".", "gce", ".", "OpenPorts", "(", "env", ".", "globalFirewallName", "(", ")", ",", "rules", "...", ")", "\n", "return", "google", ".", "HandleCredentialError", "(", "errors", ".", "Trace", "(", "err", ")", ",", "ctx", ")", "\n", "}" ]
// OpenPorts opens the given port ranges for the whole environment. // Must only be used if the environment was setup with the // FwGlobal firewall mode.
[ "OpenPorts", "opens", "the", "given", "port", "ranges", "for", "the", "whole", "environment", ".", "Must", "only", "be", "used", "if", "the", "environment", "was", "setup", "with", "the", "FwGlobal", "firewall", "mode", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/environ_firewall.go#L23-L26
153,611
juju/juju
payload/status/output_tabular.go
FormatTabular
func FormatTabular(writer io.Writer, value interface{}) error { payloads, valueConverted := value.([]FormattedPayload) if !valueConverted { return errors.Errorf("expected value of type %T, got %T", payloads, value) } // TODO(ericsnow) sort the rows first? tw := output.TabWriter(writer) // Write the header. fmt.Fprintln(tw, tabularSection) fmt.Fprintln(tw, tabularHeader) // Print each payload to its own row. for _, payload := range payloads { // tabularColumns must be kept in sync with these. fmt.Fprintf(tw, tabularRow+"\n", payload.Unit, payload.Machine, payload.Class, payload.Status, payload.Type, payload.ID, strings.Join(payload.Labels, " "), ) } tw.Flush() return nil }
go
func FormatTabular(writer io.Writer, value interface{}) error { payloads, valueConverted := value.([]FormattedPayload) if !valueConverted { return errors.Errorf("expected value of type %T, got %T", payloads, value) } // TODO(ericsnow) sort the rows first? tw := output.TabWriter(writer) // Write the header. fmt.Fprintln(tw, tabularSection) fmt.Fprintln(tw, tabularHeader) // Print each payload to its own row. for _, payload := range payloads { // tabularColumns must be kept in sync with these. fmt.Fprintf(tw, tabularRow+"\n", payload.Unit, payload.Machine, payload.Class, payload.Status, payload.Type, payload.ID, strings.Join(payload.Labels, " "), ) } tw.Flush() return nil }
[ "func", "FormatTabular", "(", "writer", "io", ".", "Writer", ",", "value", "interface", "{", "}", ")", "error", "{", "payloads", ",", "valueConverted", ":=", "value", ".", "(", "[", "]", "FormattedPayload", ")", "\n", "if", "!", "valueConverted", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "payloads", ",", "value", ")", "\n", "}", "\n\n", "// TODO(ericsnow) sort the rows first?", "tw", ":=", "output", ".", "TabWriter", "(", "writer", ")", "\n\n", "// Write the header.", "fmt", ".", "Fprintln", "(", "tw", ",", "tabularSection", ")", "\n", "fmt", ".", "Fprintln", "(", "tw", ",", "tabularHeader", ")", "\n\n", "// Print each payload to its own row.", "for", "_", ",", "payload", ":=", "range", "payloads", "{", "// tabularColumns must be kept in sync with these.", "fmt", ".", "Fprintf", "(", "tw", ",", "tabularRow", "+", "\"", "\\n", "\"", ",", "payload", ".", "Unit", ",", "payload", ".", "Machine", ",", "payload", ".", "Class", ",", "payload", ".", "Status", ",", "payload", ".", "Type", ",", "payload", ".", "ID", ",", "strings", ".", "Join", "(", "payload", ".", "Labels", ",", "\"", "\"", ")", ",", ")", "\n", "}", "\n", "tw", ".", "Flush", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// FormatTabular writes a tabular summary of payloads.
[ "FormatTabular", "writes", "a", "tabular", "summary", "of", "payloads", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/payload/status/output_tabular.go#L34-L64
153,612
juju/juju
storage/poolmanager/defaultpool.go
AddDefaultStoragePools
func AddDefaultStoragePools(p storage.Provider, pm PoolManager) error { for _, pool := range p.DefaultPools() { if err := addDefaultPool(pm, pool); err != nil { return err } } return nil }
go
func AddDefaultStoragePools(p storage.Provider, pm PoolManager) error { for _, pool := range p.DefaultPools() { if err := addDefaultPool(pm, pool); err != nil { return err } } return nil }
[ "func", "AddDefaultStoragePools", "(", "p", "storage", ".", "Provider", ",", "pm", "PoolManager", ")", "error", "{", "for", "_", ",", "pool", ":=", "range", "p", ".", "DefaultPools", "(", ")", "{", "if", "err", ":=", "addDefaultPool", "(", "pm", ",", "pool", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// AddDefaultStoragePools adds the default storage pools for the given // provider to the given pool manager. This is called whenever a new // model is created.
[ "AddDefaultStoragePools", "adds", "the", "default", "storage", "pools", "for", "the", "given", "provider", "to", "the", "given", "pool", "manager", ".", "This", "is", "called", "whenever", "a", "new", "model", "is", "created", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/poolmanager/defaultpool.go#L15-L22
153,613
juju/juju
provider/ec2/provider.go
Open
func (p environProvider) Open(args environs.OpenParams) (environs.Environ, error) { logger.Infof("opening model %q", args.Config.Name()) e := new(environ) e.cloud = args.Cloud e.name = args.Config.Name() // The endpoints in public-clouds.yaml from 2.0-rc2 // and before were wrong, so we use whatever is defined // in goamz/aws if available. if isBrokenCloud(e.cloud) { if region, ok := aws.Regions[e.cloud.Region]; ok { e.cloud.Endpoint = region.EC2Endpoint } } var err error e.ec2, err = awsClient(e.cloud) if err != nil { return nil, errors.Trace(err) } if err := e.SetConfig(args.Config); err != nil { return nil, errors.Trace(err) } return e, nil }
go
func (p environProvider) Open(args environs.OpenParams) (environs.Environ, error) { logger.Infof("opening model %q", args.Config.Name()) e := new(environ) e.cloud = args.Cloud e.name = args.Config.Name() // The endpoints in public-clouds.yaml from 2.0-rc2 // and before were wrong, so we use whatever is defined // in goamz/aws if available. if isBrokenCloud(e.cloud) { if region, ok := aws.Regions[e.cloud.Region]; ok { e.cloud.Endpoint = region.EC2Endpoint } } var err error e.ec2, err = awsClient(e.cloud) if err != nil { return nil, errors.Trace(err) } if err := e.SetConfig(args.Config); err != nil { return nil, errors.Trace(err) } return e, nil }
[ "func", "(", "p", "environProvider", ")", "Open", "(", "args", "environs", ".", "OpenParams", ")", "(", "environs", ".", "Environ", ",", "error", ")", "{", "logger", ".", "Infof", "(", "\"", "\"", ",", "args", ".", "Config", ".", "Name", "(", ")", ")", "\n\n", "e", ":=", "new", "(", "environ", ")", "\n", "e", ".", "cloud", "=", "args", ".", "Cloud", "\n", "e", ".", "name", "=", "args", ".", "Config", ".", "Name", "(", ")", "\n\n", "// The endpoints in public-clouds.yaml from 2.0-rc2", "// and before were wrong, so we use whatever is defined", "// in goamz/aws if available.", "if", "isBrokenCloud", "(", "e", ".", "cloud", ")", "{", "if", "region", ",", "ok", ":=", "aws", ".", "Regions", "[", "e", ".", "cloud", ".", "Region", "]", ";", "ok", "{", "e", ".", "cloud", ".", "Endpoint", "=", "region", ".", "EC2Endpoint", "\n", "}", "\n", "}", "\n\n", "var", "err", "error", "\n", "e", ".", "ec2", ",", "err", "=", "awsClient", "(", "e", ".", "cloud", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "e", ".", "SetConfig", "(", "args", ".", "Config", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "e", ",", "nil", "\n", "}" ]
// Open is specified in the EnvironProvider interface.
[ "Open", "is", "specified", "in", "the", "EnvironProvider", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/ec2/provider.go#L38-L64
153,614
juju/juju
provider/ec2/provider.go
isBrokenCloud
func isBrokenCloud(cloud environs.CloudSpec) bool { // The public-clouds.yaml from 2.0-rc2 and before was // complete nonsense for general regions and for // govcloud. The cn-north-1 region has a trailing slash, // which we don't want as it means we won't match the // simplestreams data. switch cloud.Region { case "us-east-1", "us-west-1", "us-west-2", "eu-west-1", "eu-central-1", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ap-northeast-2", "sa-east-1": return cloud.Endpoint == fmt.Sprintf("https://%s.aws.amazon.com/v1.2/", cloud.Region) case "cn-north-1": return strings.HasSuffix(cloud.Endpoint, "/") case "us-gov-west-1": return cloud.Endpoint == "https://ec2.us-gov-west-1.amazonaws-govcloud.com" } return false }
go
func isBrokenCloud(cloud environs.CloudSpec) bool { // The public-clouds.yaml from 2.0-rc2 and before was // complete nonsense for general regions and for // govcloud. The cn-north-1 region has a trailing slash, // which we don't want as it means we won't match the // simplestreams data. switch cloud.Region { case "us-east-1", "us-west-1", "us-west-2", "eu-west-1", "eu-central-1", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ap-northeast-2", "sa-east-1": return cloud.Endpoint == fmt.Sprintf("https://%s.aws.amazon.com/v1.2/", cloud.Region) case "cn-north-1": return strings.HasSuffix(cloud.Endpoint, "/") case "us-gov-west-1": return cloud.Endpoint == "https://ec2.us-gov-west-1.amazonaws-govcloud.com" } return false }
[ "func", "isBrokenCloud", "(", "cloud", "environs", ".", "CloudSpec", ")", "bool", "{", "// The public-clouds.yaml from 2.0-rc2 and before was", "// complete nonsense for general regions and for", "// govcloud. The cn-north-1 region has a trailing slash,", "// which we don't want as it means we won't match the", "// simplestreams data.", "switch", "cloud", ".", "Region", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "return", "cloud", ".", "Endpoint", "==", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "cloud", ".", "Region", ")", "\n", "case", "\"", "\"", ":", "return", "strings", ".", "HasSuffix", "(", "cloud", ".", "Endpoint", ",", "\"", "\"", ")", "\n", "case", "\"", "\"", ":", "return", "cloud", ".", "Endpoint", "==", "\"", "\"", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isBrokenCloud reports whether the given CloudSpec is from an old, // broken version of public-clouds.yaml.
[ "isBrokenCloud", "reports", "whether", "the", "given", "CloudSpec", "is", "from", "an", "old", "broken", "version", "of", "public", "-", "clouds", ".", "yaml", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/ec2/provider.go#L68-L85
153,615
juju/juju
provider/ec2/provider.go
Validate
func (environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) { newEcfg, err := validateConfig(cfg, old) if err != nil { return nil, fmt.Errorf("invalid EC2 provider config: %v", err) } return newEcfg.Apply(newEcfg.attrs) }
go
func (environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) { newEcfg, err := validateConfig(cfg, old) if err != nil { return nil, fmt.Errorf("invalid EC2 provider config: %v", err) } return newEcfg.Apply(newEcfg.attrs) }
[ "func", "(", "environProvider", ")", "Validate", "(", "cfg", ",", "old", "*", "config", ".", "Config", ")", "(", "valid", "*", "config", ".", "Config", ",", "err", "error", ")", "{", "newEcfg", ",", "err", ":=", "validateConfig", "(", "cfg", ",", "old", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "newEcfg", ".", "Apply", "(", "newEcfg", ".", "attrs", ")", "\n", "}" ]
// Validate is specified in the EnvironProvider interface.
[ "Validate", "is", "specified", "in", "the", "EnvironProvider", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/ec2/provider.go#L149-L155
153,616
juju/juju
state/logdb/buf.go
NewBufferedLogger
func NewBufferedLogger( l Logger, bufferSize int, flushInterval time.Duration, clock clock.Clock, ) *BufferedLogger { return &BufferedLogger{ l: l, buf: make([]state.LogRecord, 0, bufferSize), clock: clock, flushInterval: flushInterval, } }
go
func NewBufferedLogger( l Logger, bufferSize int, flushInterval time.Duration, clock clock.Clock, ) *BufferedLogger { return &BufferedLogger{ l: l, buf: make([]state.LogRecord, 0, bufferSize), clock: clock, flushInterval: flushInterval, } }
[ "func", "NewBufferedLogger", "(", "l", "Logger", ",", "bufferSize", "int", ",", "flushInterval", "time", ".", "Duration", ",", "clock", "clock", ".", "Clock", ",", ")", "*", "BufferedLogger", "{", "return", "&", "BufferedLogger", "{", "l", ":", "l", ",", "buf", ":", "make", "(", "[", "]", "state", ".", "LogRecord", ",", "0", ",", "bufferSize", ")", ",", "clock", ":", "clock", ",", "flushInterval", ":", "flushInterval", ",", "}", "\n", "}" ]
// NewBufferedLogger returns a new BufferedLogger, wrapping the given // Logger with a buffer of the specified size and flush interval.
[ "NewBufferedLogger", "returns", "a", "new", "BufferedLogger", "wrapping", "the", "given", "Logger", "with", "a", "buffer", "of", "the", "specified", "size", "and", "flush", "interval", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logdb/buf.go#L37-L49
153,617
juju/juju
state/logdb/buf.go
Log
func (b *BufferedLogger) Log(in []state.LogRecord) error { b.mu.Lock() defer b.mu.Unlock() for len(in) > 0 { r := cap(b.buf) - len(b.buf) n := len(in) if n > r { n = r } b.buf = append(b.buf, in[:n]...) in = in[n:] if len(b.buf) >= cap(b.buf) { if err := b.flush(); err != nil { return errors.Trace(err) } } } if len(b.buf) > 0 && b.flushTimer == nil { b.flushTimer = b.clock.AfterFunc(b.flushInterval, b.flushOnTimer) } return nil }
go
func (b *BufferedLogger) Log(in []state.LogRecord) error { b.mu.Lock() defer b.mu.Unlock() for len(in) > 0 { r := cap(b.buf) - len(b.buf) n := len(in) if n > r { n = r } b.buf = append(b.buf, in[:n]...) in = in[n:] if len(b.buf) >= cap(b.buf) { if err := b.flush(); err != nil { return errors.Trace(err) } } } if len(b.buf) > 0 && b.flushTimer == nil { b.flushTimer = b.clock.AfterFunc(b.flushInterval, b.flushOnTimer) } return nil }
[ "func", "(", "b", "*", "BufferedLogger", ")", "Log", "(", "in", "[", "]", "state", ".", "LogRecord", ")", "error", "{", "b", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "mu", ".", "Unlock", "(", ")", "\n", "for", "len", "(", "in", ")", ">", "0", "{", "r", ":=", "cap", "(", "b", ".", "buf", ")", "-", "len", "(", "b", ".", "buf", ")", "\n", "n", ":=", "len", "(", "in", ")", "\n", "if", "n", ">", "r", "{", "n", "=", "r", "\n", "}", "\n", "b", ".", "buf", "=", "append", "(", "b", ".", "buf", ",", "in", "[", ":", "n", "]", "...", ")", "\n", "in", "=", "in", "[", "n", ":", "]", "\n", "if", "len", "(", "b", ".", "buf", ")", ">=", "cap", "(", "b", ".", "buf", ")", "{", "if", "err", ":=", "b", ".", "flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "b", ".", "buf", ")", ">", "0", "&&", "b", ".", "flushTimer", "==", "nil", "{", "b", ".", "flushTimer", "=", "b", ".", "clock", ".", "AfterFunc", "(", "b", ".", "flushInterval", ",", "b", ".", "flushOnTimer", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Log is part of the Logger interface. // // BufferedLogger's Log implementation will buffer log records up to // the specified capacity and duration; after either of which is exceeded, // the records will be flushed to the underlying logger.
[ "Log", "is", "part", "of", "the", "Logger", "interface", ".", "BufferedLogger", "s", "Log", "implementation", "will", "buffer", "log", "records", "up", "to", "the", "specified", "capacity", "and", "duration", ";", "after", "either", "of", "which", "is", "exceeded", "the", "records", "will", "be", "flushed", "to", "the", "underlying", "logger", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logdb/buf.go#L56-L77
153,618
juju/juju
state/logdb/buf.go
Flush
func (b *BufferedLogger) Flush() error { b.mu.Lock() b.mu.Unlock() return b.flush() }
go
func (b *BufferedLogger) Flush() error { b.mu.Lock() b.mu.Unlock() return b.flush() }
[ "func", "(", "b", "*", "BufferedLogger", ")", "Flush", "(", ")", "error", "{", "b", ".", "mu", ".", "Lock", "(", ")", "\n", "b", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "b", ".", "flush", "(", ")", "\n", "}" ]
// Flush flushes any buffered log records to the underlying Logger.
[ "Flush", "flushes", "any", "buffered", "log", "records", "to", "the", "underlying", "Logger", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logdb/buf.go#L80-L84
153,619
juju/juju
state/logdb/buf.go
flush
func (b *BufferedLogger) flush() error { if b.flushTimer != nil { b.flushTimer.Stop() b.flushTimer = nil } if len(b.buf) > 0 { if err := b.l.Log(b.buf); err != nil { return errors.Trace(err) } b.buf = b.buf[:0] } return nil }
go
func (b *BufferedLogger) flush() error { if b.flushTimer != nil { b.flushTimer.Stop() b.flushTimer = nil } if len(b.buf) > 0 { if err := b.l.Log(b.buf); err != nil { return errors.Trace(err) } b.buf = b.buf[:0] } return nil }
[ "func", "(", "b", "*", "BufferedLogger", ")", "flush", "(", ")", "error", "{", "if", "b", ".", "flushTimer", "!=", "nil", "{", "b", ".", "flushTimer", ".", "Stop", "(", ")", "\n", "b", ".", "flushTimer", "=", "nil", "\n", "}", "\n", "if", "len", "(", "b", ".", "buf", ")", ">", "0", "{", "if", "err", ":=", "b", ".", "l", ".", "Log", "(", "b", ".", "buf", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "b", ".", "buf", "=", "b", ".", "buf", "[", ":", "0", "]", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// flush flushes any buffered log records to the underlying Logger, and stops // the flush timer if there is one. The caller must be holding b.mu.
[ "flush", "flushes", "any", "buffered", "log", "records", "to", "the", "underlying", "Logger", "and", "stops", "the", "flush", "timer", "if", "there", "is", "one", ".", "The", "caller", "must", "be", "holding", "b", ".", "mu", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logdb/buf.go#L97-L109
153,620
juju/juju
resource/api/upload.go
NewUploadRequest
func NewUploadRequest(application, name, filename string, r io.ReadSeeker) (UploadRequest, error) { if !names.IsValidApplication(application) { return UploadRequest{}, errors.Errorf("invalid application %q", application) } content, err := resource.GenerateContent(r) if err != nil { return UploadRequest{}, errors.Trace(err) } ur := UploadRequest{ Application: application, Name: name, Filename: filename, Size: content.Size, Fingerprint: content.Fingerprint, } return ur, nil }
go
func NewUploadRequest(application, name, filename string, r io.ReadSeeker) (UploadRequest, error) { if !names.IsValidApplication(application) { return UploadRequest{}, errors.Errorf("invalid application %q", application) } content, err := resource.GenerateContent(r) if err != nil { return UploadRequest{}, errors.Trace(err) } ur := UploadRequest{ Application: application, Name: name, Filename: filename, Size: content.Size, Fingerprint: content.Fingerprint, } return ur, nil }
[ "func", "NewUploadRequest", "(", "application", ",", "name", ",", "filename", "string", ",", "r", "io", ".", "ReadSeeker", ")", "(", "UploadRequest", ",", "error", ")", "{", "if", "!", "names", ".", "IsValidApplication", "(", "application", ")", "{", "return", "UploadRequest", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "application", ")", "\n", "}", "\n\n", "content", ",", "err", ":=", "resource", ".", "GenerateContent", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "UploadRequest", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "ur", ":=", "UploadRequest", "{", "Application", ":", "application", ",", "Name", ":", "name", ",", "Filename", ":", "filename", ",", "Size", ":", "content", ".", "Size", ",", "Fingerprint", ":", "content", ".", "Fingerprint", ",", "}", "\n", "return", "ur", ",", "nil", "\n", "}" ]
// NewUploadRequest generates a new upload request for the given resource.
[ "NewUploadRequest", "generates", "a", "new", "upload", "request", "for", "the", "given", "resource", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/api/upload.go#L41-L59
153,621
juju/juju
resource/api/upload.go
HTTPRequest
func (ur UploadRequest) HTTPRequest() (*http.Request, error) { // TODO(ericsnow) What about the rest of the URL? urlStr := NewEndpointPath(ur.Application, ur.Name) req, err := http.NewRequest(http.MethodPut, urlStr, nil) if err != nil { return nil, errors.Trace(err) } req.Header.Set(HeaderContentType, ContentTypeRaw) req.Header.Set(HeaderContentSha384, ur.Fingerprint.String()) req.Header.Set(HeaderContentLength, fmt.Sprint(ur.Size)) setFilename(ur.Filename, req) req.ContentLength = ur.Size if ur.PendingID != "" { query := req.URL.Query() query.Set(QueryParamPendingID, ur.PendingID) req.URL.RawQuery = query.Encode() } return req, nil }
go
func (ur UploadRequest) HTTPRequest() (*http.Request, error) { // TODO(ericsnow) What about the rest of the URL? urlStr := NewEndpointPath(ur.Application, ur.Name) req, err := http.NewRequest(http.MethodPut, urlStr, nil) if err != nil { return nil, errors.Trace(err) } req.Header.Set(HeaderContentType, ContentTypeRaw) req.Header.Set(HeaderContentSha384, ur.Fingerprint.String()) req.Header.Set(HeaderContentLength, fmt.Sprint(ur.Size)) setFilename(ur.Filename, req) req.ContentLength = ur.Size if ur.PendingID != "" { query := req.URL.Query() query.Set(QueryParamPendingID, ur.PendingID) req.URL.RawQuery = query.Encode() } return req, nil }
[ "func", "(", "ur", "UploadRequest", ")", "HTTPRequest", "(", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "// TODO(ericsnow) What about the rest of the URL?", "urlStr", ":=", "NewEndpointPath", "(", "ur", ".", "Application", ",", "ur", ".", "Name", ")", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodPut", ",", "urlStr", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "HeaderContentType", ",", "ContentTypeRaw", ")", "\n", "req", ".", "Header", ".", "Set", "(", "HeaderContentSha384", ",", "ur", ".", "Fingerprint", ".", "String", "(", ")", ")", "\n", "req", ".", "Header", ".", "Set", "(", "HeaderContentLength", ",", "fmt", ".", "Sprint", "(", "ur", ".", "Size", ")", ")", "\n", "setFilename", "(", "ur", ".", "Filename", ",", "req", ")", "\n\n", "req", ".", "ContentLength", "=", "ur", ".", "Size", "\n\n", "if", "ur", ".", "PendingID", "!=", "\"", "\"", "{", "query", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "query", ".", "Set", "(", "QueryParamPendingID", ",", "ur", ".", "PendingID", ")", "\n", "req", ".", "URL", ".", "RawQuery", "=", "query", ".", "Encode", "(", ")", "\n", "}", "\n\n", "return", "req", ",", "nil", "\n", "}" ]
// HTTPRequest generates a new HTTP request.
[ "HTTPRequest", "generates", "a", "new", "HTTP", "request", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/resource/api/upload.go#L83-L106
153,622
juju/juju
core/lease/store.go
LockedTrapdoor
func LockedTrapdoor(attempt int, key interface{}) error { if key != nil { return errors.New("lease substrate not accessible") } return nil }
go
func LockedTrapdoor(attempt int, key interface{}) error { if key != nil { return errors.New("lease substrate not accessible") } return nil }
[ "func", "LockedTrapdoor", "(", "attempt", "int", ",", "key", "interface", "{", "}", ")", "error", "{", "if", "key", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LockedTrapdoor is a Trapdoor suitable for use by substrates that don't want // or need to expose their internals.
[ "LockedTrapdoor", "is", "a", "Trapdoor", "suitable", "for", "use", "by", "substrates", "that", "don", "t", "want", "or", "need", "to", "expose", "their", "internals", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/lease/store.go#L100-L105
153,623
juju/juju
core/lease/store.go
Validate
func (request Request) Validate() error { if err := ValidateString(request.Holder); err != nil { return errors.Annotatef(err, "invalid holder") } if request.Duration <= 0 { return errors.Errorf("invalid duration") } return nil }
go
func (request Request) Validate() error { if err := ValidateString(request.Holder); err != nil { return errors.Annotatef(err, "invalid holder") } if request.Duration <= 0 { return errors.Errorf("invalid duration") } return nil }
[ "func", "(", "request", "Request", ")", "Validate", "(", ")", "error", "{", "if", "err", ":=", "ValidateString", "(", "request", ".", "Holder", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "request", ".", "Duration", "<=", "0", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate returns an error if any fields are invalid or inconsistent.
[ "Validate", "returns", "an", "error", "if", "any", "fields", "are", "invalid", "or", "inconsistent", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/lease/store.go#L118-L126
153,624
juju/juju
apiserver/facades/agent/metricsadder/metricsadder.go
NewMetricsAdderAPI
func NewMetricsAdderAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, ) (*MetricsAdderAPI, error) { // TODO(cmars): remove unit agent auth, once worker/metrics/sender manifold // can be righteously relocated to machine agent. if !authorizer.AuthMachineAgent() && !authorizer.AuthUnitAgent() { return nil, common.ErrPerm } return &MetricsAdderAPI{ state: st, }, nil }
go
func NewMetricsAdderAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, ) (*MetricsAdderAPI, error) { // TODO(cmars): remove unit agent auth, once worker/metrics/sender manifold // can be righteously relocated to machine agent. if !authorizer.AuthMachineAgent() && !authorizer.AuthUnitAgent() { return nil, common.ErrPerm } return &MetricsAdderAPI{ state: st, }, nil }
[ "func", "NewMetricsAdderAPI", "(", "st", "*", "state", ".", "State", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ",", ")", "(", "*", "MetricsAdderAPI", ",", "error", ")", "{", "// TODO(cmars): remove unit agent auth, once worker/metrics/sender manifold", "// can be righteously relocated to machine agent.", "if", "!", "authorizer", ".", "AuthMachineAgent", "(", ")", "&&", "!", "authorizer", ".", "AuthUnitAgent", "(", ")", "{", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "return", "&", "MetricsAdderAPI", "{", "state", ":", "st", ",", "}", ",", "nil", "\n", "}" ]
// NewMetricsAdderAPI creates a new API endpoint for adding metrics to state.
[ "NewMetricsAdderAPI", "creates", "a", "new", "API", "endpoint", "for", "adding", "metrics", "to", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/metricsadder/metricsadder.go#L30-L43
153,625
juju/juju
cmd/juju/application/addrelation.go
validateEndpoints
func (c *addRelationCommand) validateEndpoints(all []string) error { for _, endpoint := range all { // We can only determine if this is a remote endpoint with 100%. // If we cannot parse it, it may still be a valid local endpoint... // so ignoring parsing error, if url, err := crossmodel.ParseOfferURL(endpoint); err == nil { if c.remoteEndpoint != nil { return errors.NotSupportedf("providing more than one remote endpoints") } c.remoteEndpoint = url c.endpoints = append(c.endpoints, url.ApplicationName) continue } // at this stage, we are assuming that this could be a local endpoint if err := validateLocalEndpoint(endpoint, ":"); err != nil { return err } c.endpoints = append(c.endpoints, endpoint) } return nil }
go
func (c *addRelationCommand) validateEndpoints(all []string) error { for _, endpoint := range all { // We can only determine if this is a remote endpoint with 100%. // If we cannot parse it, it may still be a valid local endpoint... // so ignoring parsing error, if url, err := crossmodel.ParseOfferURL(endpoint); err == nil { if c.remoteEndpoint != nil { return errors.NotSupportedf("providing more than one remote endpoints") } c.remoteEndpoint = url c.endpoints = append(c.endpoints, url.ApplicationName) continue } // at this stage, we are assuming that this could be a local endpoint if err := validateLocalEndpoint(endpoint, ":"); err != nil { return err } c.endpoints = append(c.endpoints, endpoint) } return nil }
[ "func", "(", "c", "*", "addRelationCommand", ")", "validateEndpoints", "(", "all", "[", "]", "string", ")", "error", "{", "for", "_", ",", "endpoint", ":=", "range", "all", "{", "// We can only determine if this is a remote endpoint with 100%.", "// If we cannot parse it, it may still be a valid local endpoint...", "// so ignoring parsing error,", "if", "url", ",", "err", ":=", "crossmodel", ".", "ParseOfferURL", "(", "endpoint", ")", ";", "err", "==", "nil", "{", "if", "c", ".", "remoteEndpoint", "!=", "nil", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n", "c", ".", "remoteEndpoint", "=", "url", "\n", "c", ".", "endpoints", "=", "append", "(", "c", ".", "endpoints", ",", "url", ".", "ApplicationName", ")", "\n", "continue", "\n", "}", "\n", "// at this stage, we are assuming that this could be a local endpoint", "if", "err", ":=", "validateLocalEndpoint", "(", "endpoint", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "c", ".", "endpoints", "=", "append", "(", "c", ".", "endpoints", ",", "endpoint", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// validateEndpoints determines if all endpoints are valid. // Each endpoint is either from local application or remote. // If more than one remote endpoint are supplied, the input argument are considered invalid.
[ "validateEndpoints", "determines", "if", "all", "endpoints", "are", "valid", ".", "Each", "endpoint", "is", "either", "from", "local", "application", "or", "remote", ".", "If", "more", "than", "one", "remote", "endpoint", "are", "supplied", "the", "input", "argument", "are", "considered", "invalid", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/addrelation.go#L224-L244
153,626
juju/juju
cmd/juju/application/addrelation.go
validateLocalEndpoint
func validateLocalEndpoint(endpoint string, sep string) error { i := strings.Index(endpoint, sep) applicationName := endpoint if i != -1 { // not a valid endpoint as sep either at the start or the end of the name if i == 0 || i == len(endpoint)-1 { return errors.NotValidf("endpoint %q", endpoint) } parts := strings.SplitN(endpoint, sep, -1) if rightCount := len(parts) == 2; !rightCount { // not valid if there are not exactly 2 parts. return errors.NotValidf("endpoint %q", endpoint) } applicationName = parts[0] if valid := localEndpointRegEx.MatchString(parts[1]); !valid { return errors.NotValidf("endpoint %q", endpoint) } } if valid := names.IsValidApplication(applicationName); !valid { return errors.NotValidf("application name %q", applicationName) } return nil }
go
func validateLocalEndpoint(endpoint string, sep string) error { i := strings.Index(endpoint, sep) applicationName := endpoint if i != -1 { // not a valid endpoint as sep either at the start or the end of the name if i == 0 || i == len(endpoint)-1 { return errors.NotValidf("endpoint %q", endpoint) } parts := strings.SplitN(endpoint, sep, -1) if rightCount := len(parts) == 2; !rightCount { // not valid if there are not exactly 2 parts. return errors.NotValidf("endpoint %q", endpoint) } applicationName = parts[0] if valid := localEndpointRegEx.MatchString(parts[1]); !valid { return errors.NotValidf("endpoint %q", endpoint) } } if valid := names.IsValidApplication(applicationName); !valid { return errors.NotValidf("application name %q", applicationName) } return nil }
[ "func", "validateLocalEndpoint", "(", "endpoint", "string", ",", "sep", "string", ")", "error", "{", "i", ":=", "strings", ".", "Index", "(", "endpoint", ",", "sep", ")", "\n", "applicationName", ":=", "endpoint", "\n", "if", "i", "!=", "-", "1", "{", "// not a valid endpoint as sep either at the start or the end of the name", "if", "i", "==", "0", "||", "i", "==", "len", "(", "endpoint", ")", "-", "1", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "endpoint", ")", "\n", "}", "\n\n", "parts", ":=", "strings", ".", "SplitN", "(", "endpoint", ",", "sep", ",", "-", "1", ")", "\n", "if", "rightCount", ":=", "len", "(", "parts", ")", "==", "2", ";", "!", "rightCount", "{", "// not valid if there are not exactly 2 parts.", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "endpoint", ")", "\n", "}", "\n\n", "applicationName", "=", "parts", "[", "0", "]", "\n\n", "if", "valid", ":=", "localEndpointRegEx", ".", "MatchString", "(", "parts", "[", "1", "]", ")", ";", "!", "valid", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "endpoint", ")", "\n", "}", "\n", "}", "\n\n", "if", "valid", ":=", "names", ".", "IsValidApplication", "(", "applicationName", ")", ";", "!", "valid", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "applicationName", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// validateLocalEndpoint determines if given endpoint could be a valid
[ "validateLocalEndpoint", "determines", "if", "given", "endpoint", "could", "be", "a", "valid" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/addrelation.go#L247-L273
153,627
juju/juju
state/filesystem.go
FilesystemTag
func (f *filesystem) FilesystemTag() names.FilesystemTag { return names.NewFilesystemTag(f.doc.FilesystemId) }
go
func (f *filesystem) FilesystemTag() names.FilesystemTag { return names.NewFilesystemTag(f.doc.FilesystemId) }
[ "func", "(", "f", "*", "filesystem", ")", "FilesystemTag", "(", ")", "names", ".", "FilesystemTag", "{", "return", "names", ".", "NewFilesystemTag", "(", "f", ".", "doc", ".", "FilesystemId", ")", "\n", "}" ]
// FilesystemTag is required to implement Filesystem.
[ "FilesystemTag", "is", "required", "to", "implement", "Filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L208-L210
153,628
juju/juju
state/filesystem.go
Storage
func (f *filesystem) Storage() (names.StorageTag, error) { if f.doc.StorageId == "" { msg := fmt.Sprintf("filesystem %q is not assigned to any storage instance", f.Tag().Id()) return names.StorageTag{}, errors.NewNotAssigned(nil, msg) } return names.NewStorageTag(f.doc.StorageId), nil }
go
func (f *filesystem) Storage() (names.StorageTag, error) { if f.doc.StorageId == "" { msg := fmt.Sprintf("filesystem %q is not assigned to any storage instance", f.Tag().Id()) return names.StorageTag{}, errors.NewNotAssigned(nil, msg) } return names.NewStorageTag(f.doc.StorageId), nil }
[ "func", "(", "f", "*", "filesystem", ")", "Storage", "(", ")", "(", "names", ".", "StorageTag", ",", "error", ")", "{", "if", "f", ".", "doc", ".", "StorageId", "==", "\"", "\"", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "Tag", "(", ")", ".", "Id", "(", ")", ")", "\n", "return", "names", ".", "StorageTag", "{", "}", ",", "errors", ".", "NewNotAssigned", "(", "nil", ",", "msg", ")", "\n", "}", "\n", "return", "names", ".", "NewStorageTag", "(", "f", ".", "doc", ".", "StorageId", ")", ",", "nil", "\n", "}" ]
// Storage is required to implement Filesystem.
[ "Storage", "is", "required", "to", "implement", "Filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L218-L224
153,629
juju/juju
state/filesystem.go
Volume
func (f *filesystem) Volume() (names.VolumeTag, error) { if f.doc.VolumeId == "" { return names.VolumeTag{}, ErrNoBackingVolume } return names.NewVolumeTag(f.doc.VolumeId), nil }
go
func (f *filesystem) Volume() (names.VolumeTag, error) { if f.doc.VolumeId == "" { return names.VolumeTag{}, ErrNoBackingVolume } return names.NewVolumeTag(f.doc.VolumeId), nil }
[ "func", "(", "f", "*", "filesystem", ")", "Volume", "(", ")", "(", "names", ".", "VolumeTag", ",", "error", ")", "{", "if", "f", ".", "doc", ".", "VolumeId", "==", "\"", "\"", "{", "return", "names", ".", "VolumeTag", "{", "}", ",", "ErrNoBackingVolume", "\n", "}", "\n", "return", "names", ".", "NewVolumeTag", "(", "f", ".", "doc", ".", "VolumeId", ")", ",", "nil", "\n", "}" ]
// Volume is required to implement Filesystem.
[ "Volume", "is", "required", "to", "implement", "Filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L227-L232
153,630
juju/juju
state/filesystem.go
Info
func (f *filesystem) Info() (FilesystemInfo, error) { if f.doc.Info == nil { return FilesystemInfo{}, errors.NotProvisionedf("filesystem %q", f.doc.FilesystemId) } return *f.doc.Info, nil }
go
func (f *filesystem) Info() (FilesystemInfo, error) { if f.doc.Info == nil { return FilesystemInfo{}, errors.NotProvisionedf("filesystem %q", f.doc.FilesystemId) } return *f.doc.Info, nil }
[ "func", "(", "f", "*", "filesystem", ")", "Info", "(", ")", "(", "FilesystemInfo", ",", "error", ")", "{", "if", "f", ".", "doc", ".", "Info", "==", "nil", "{", "return", "FilesystemInfo", "{", "}", ",", "errors", ".", "NotProvisionedf", "(", "\"", "\"", ",", "f", ".", "doc", ".", "FilesystemId", ")", "\n", "}", "\n", "return", "*", "f", ".", "doc", ".", "Info", ",", "nil", "\n", "}" ]
// Info is required to implement Filesystem.
[ "Info", "is", "required", "to", "implement", "Filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L235-L240
153,631
juju/juju
state/filesystem.go
Params
func (f *filesystem) Params() (FilesystemParams, bool) { if f.doc.Params == nil { return FilesystemParams{}, false } return *f.doc.Params, true }
go
func (f *filesystem) Params() (FilesystemParams, bool) { if f.doc.Params == nil { return FilesystemParams{}, false } return *f.doc.Params, true }
[ "func", "(", "f", "*", "filesystem", ")", "Params", "(", ")", "(", "FilesystemParams", ",", "bool", ")", "{", "if", "f", ".", "doc", ".", "Params", "==", "nil", "{", "return", "FilesystemParams", "{", "}", ",", "false", "\n", "}", "\n", "return", "*", "f", ".", "doc", ".", "Params", ",", "true", "\n", "}" ]
// Params is required to implement Filesystem.
[ "Params", "is", "required", "to", "implement", "Filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L243-L248
153,632
juju/juju
state/filesystem.go
Filesystem
func (f *filesystemAttachment) Filesystem() names.FilesystemTag { return names.NewFilesystemTag(f.doc.Filesystem) }
go
func (f *filesystemAttachment) Filesystem() names.FilesystemTag { return names.NewFilesystemTag(f.doc.Filesystem) }
[ "func", "(", "f", "*", "filesystemAttachment", ")", "Filesystem", "(", ")", "names", ".", "FilesystemTag", "{", "return", "names", ".", "NewFilesystemTag", "(", "f", ".", "doc", ".", "Filesystem", ")", "\n", "}" ]
// Filesystem is required to implement FilesystemAttachment.
[ "Filesystem", "is", "required", "to", "implement", "FilesystemAttachment", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L295-L297
153,633
juju/juju
state/filesystem.go
Info
func (f *filesystemAttachment) Info() (FilesystemAttachmentInfo, error) { if f.doc.Info == nil { hostTag := storageAttachmentHost(f.doc.Host) return FilesystemAttachmentInfo{}, errors.NotProvisionedf( "filesystem attachment %q on %q", f.doc.Filesystem, names.ReadableString(hostTag)) } return *f.doc.Info, nil }
go
func (f *filesystemAttachment) Info() (FilesystemAttachmentInfo, error) { if f.doc.Info == nil { hostTag := storageAttachmentHost(f.doc.Host) return FilesystemAttachmentInfo{}, errors.NotProvisionedf( "filesystem attachment %q on %q", f.doc.Filesystem, names.ReadableString(hostTag)) } return *f.doc.Info, nil }
[ "func", "(", "f", "*", "filesystemAttachment", ")", "Info", "(", ")", "(", "FilesystemAttachmentInfo", ",", "error", ")", "{", "if", "f", ".", "doc", ".", "Info", "==", "nil", "{", "hostTag", ":=", "storageAttachmentHost", "(", "f", ".", "doc", ".", "Host", ")", "\n", "return", "FilesystemAttachmentInfo", "{", "}", ",", "errors", ".", "NotProvisionedf", "(", "\"", "\"", ",", "f", ".", "doc", ".", "Filesystem", ",", "names", ".", "ReadableString", "(", "hostTag", ")", ")", "\n", "}", "\n", "return", "*", "f", ".", "doc", ".", "Info", ",", "nil", "\n", "}" ]
// Info is required to implement FilesystemAttachment.
[ "Info", "is", "required", "to", "implement", "FilesystemAttachment", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L317-L324
153,634
juju/juju
state/filesystem.go
Params
func (f *filesystemAttachment) Params() (FilesystemAttachmentParams, bool) { if f.doc.Params == nil { return FilesystemAttachmentParams{}, false } return *f.doc.Params, true }
go
func (f *filesystemAttachment) Params() (FilesystemAttachmentParams, bool) { if f.doc.Params == nil { return FilesystemAttachmentParams{}, false } return *f.doc.Params, true }
[ "func", "(", "f", "*", "filesystemAttachment", ")", "Params", "(", ")", "(", "FilesystemAttachmentParams", ",", "bool", ")", "{", "if", "f", ".", "doc", ".", "Params", "==", "nil", "{", "return", "FilesystemAttachmentParams", "{", "}", ",", "false", "\n", "}", "\n", "return", "*", "f", ".", "doc", ".", "Params", ",", "true", "\n", "}" ]
// Params is required to implement FilesystemAttachment.
[ "Params", "is", "required", "to", "implement", "FilesystemAttachment", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L327-L332
153,635
juju/juju
state/filesystem.go
Filesystem
func (sb *storageBackend) Filesystem(tag names.FilesystemTag) (Filesystem, error) { f, err := getFilesystemByTag(sb.mb, tag) return f, err }
go
func (sb *storageBackend) Filesystem(tag names.FilesystemTag) (Filesystem, error) { f, err := getFilesystemByTag(sb.mb, tag) return f, err }
[ "func", "(", "sb", "*", "storageBackend", ")", "Filesystem", "(", "tag", "names", ".", "FilesystemTag", ")", "(", "Filesystem", ",", "error", ")", "{", "f", ",", "err", ":=", "getFilesystemByTag", "(", "sb", ".", "mb", ",", "tag", ")", "\n", "return", "f", ",", "err", "\n", "}" ]
// Filesystem returns the Filesystem with the specified name.
[ "Filesystem", "returns", "the", "Filesystem", "with", "the", "specified", "name", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L335-L338
153,636
juju/juju
state/filesystem.go
StorageInstanceFilesystem
func (sb *storageBackend) StorageInstanceFilesystem(tag names.StorageTag) (Filesystem, error) { f, err := sb.storageInstanceFilesystem(tag) return f, err }
go
func (sb *storageBackend) StorageInstanceFilesystem(tag names.StorageTag) (Filesystem, error) { f, err := sb.storageInstanceFilesystem(tag) return f, err }
[ "func", "(", "sb", "*", "storageBackend", ")", "StorageInstanceFilesystem", "(", "tag", "names", ".", "StorageTag", ")", "(", "Filesystem", ",", "error", ")", "{", "f", ",", "err", ":=", "sb", ".", "storageInstanceFilesystem", "(", "tag", ")", "\n", "return", "f", ",", "err", "\n", "}" ]
// StorageInstanceFilesystem returns the Filesystem assigned to the specified // storage instance.
[ "StorageInstanceFilesystem", "returns", "the", "Filesystem", "assigned", "to", "the", "specified", "storage", "instance", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L356-L359
153,637
juju/juju
state/filesystem.go
VolumeFilesystem
func (sb *storageBackend) VolumeFilesystem(tag names.VolumeTag) (Filesystem, error) { f, err := sb.volumeFilesystem(tag) return f, err }
go
func (sb *storageBackend) VolumeFilesystem(tag names.VolumeTag) (Filesystem, error) { f, err := sb.volumeFilesystem(tag) return f, err }
[ "func", "(", "sb", "*", "storageBackend", ")", "VolumeFilesystem", "(", "tag", "names", ".", "VolumeTag", ")", "(", "Filesystem", ",", "error", ")", "{", "f", ",", "err", ":=", "sb", ".", "volumeFilesystem", "(", "tag", ")", "\n", "return", "f", ",", "err", "\n", "}" ]
// VolumeFilesystem returns the Filesystem backed by the specified volume.
[ "VolumeFilesystem", "returns", "the", "Filesystem", "backed", "by", "the", "specified", "volume", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L368-L371
153,638
juju/juju
state/filesystem.go
FilesystemAttachment
func (sb *storageBackend) FilesystemAttachment(host names.Tag, filesystem names.FilesystemTag) (FilesystemAttachment, error) { coll, cleanup := sb.mb.db().GetCollection(filesystemAttachmentsC) defer cleanup() var att filesystemAttachment err := coll.FindId(filesystemAttachmentId(host.Id(), filesystem.Id())).One(&att.doc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("filesystem %q on %q", filesystem.Id(), names.ReadableString(host)) } else if err != nil { return nil, errors.Annotatef(err, "getting filesystem %q on %q", filesystem.Id(), names.ReadableString(host)) } return &att, nil }
go
func (sb *storageBackend) FilesystemAttachment(host names.Tag, filesystem names.FilesystemTag) (FilesystemAttachment, error) { coll, cleanup := sb.mb.db().GetCollection(filesystemAttachmentsC) defer cleanup() var att filesystemAttachment err := coll.FindId(filesystemAttachmentId(host.Id(), filesystem.Id())).One(&att.doc) if err == mgo.ErrNotFound { return nil, errors.NotFoundf("filesystem %q on %q", filesystem.Id(), names.ReadableString(host)) } else if err != nil { return nil, errors.Annotatef(err, "getting filesystem %q on %q", filesystem.Id(), names.ReadableString(host)) } return &att, nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "FilesystemAttachment", "(", "host", "names", ".", "Tag", ",", "filesystem", "names", ".", "FilesystemTag", ")", "(", "FilesystemAttachment", ",", "error", ")", "{", "coll", ",", "cleanup", ":=", "sb", ".", "mb", ".", "db", "(", ")", ".", "GetCollection", "(", "filesystemAttachmentsC", ")", "\n", "defer", "cleanup", "(", ")", "\n\n", "var", "att", "filesystemAttachment", "\n", "err", ":=", "coll", ".", "FindId", "(", "filesystemAttachmentId", "(", "host", ".", "Id", "(", ")", ",", "filesystem", ".", "Id", "(", ")", ")", ")", ".", "One", "(", "&", "att", ".", "doc", ")", "\n", "if", "err", "==", "mgo", ".", "ErrNotFound", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "filesystem", ".", "Id", "(", ")", ",", "names", ".", "ReadableString", "(", "host", ")", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "filesystem", ".", "Id", "(", ")", ",", "names", ".", "ReadableString", "(", "host", ")", ")", "\n", "}", "\n", "return", "&", "att", ",", "nil", "\n", "}" ]
// FilesystemAttachment returns the FilesystemAttachment corresponding to // the specified filesystem and machine.
[ "FilesystemAttachment", "returns", "the", "FilesystemAttachment", "corresponding", "to", "the", "specified", "filesystem", "and", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L435-L447
153,639
juju/juju
state/filesystem.go
FilesystemAttachments
func (sb *storageBackend) FilesystemAttachments(filesystem names.FilesystemTag) ([]FilesystemAttachment, error) { attachments, err := sb.filesystemAttachments(bson.D{{"filesystemid", filesystem.Id()}}) if err != nil { return nil, errors.Annotatef(err, "getting attachments for filesystem %q", filesystem.Id()) } return attachments, nil }
go
func (sb *storageBackend) FilesystemAttachments(filesystem names.FilesystemTag) ([]FilesystemAttachment, error) { attachments, err := sb.filesystemAttachments(bson.D{{"filesystemid", filesystem.Id()}}) if err != nil { return nil, errors.Annotatef(err, "getting attachments for filesystem %q", filesystem.Id()) } return attachments, nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "FilesystemAttachments", "(", "filesystem", "names", ".", "FilesystemTag", ")", "(", "[", "]", "FilesystemAttachment", ",", "error", ")", "{", "attachments", ",", "err", ":=", "sb", ".", "filesystemAttachments", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "filesystem", ".", "Id", "(", ")", "}", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "filesystem", ".", "Id", "(", ")", ")", "\n", "}", "\n", "return", "attachments", ",", "nil", "\n", "}" ]
// FilesystemAttachments returns all of the FilesystemAttachments for the // specified filesystem.
[ "FilesystemAttachments", "returns", "all", "of", "the", "FilesystemAttachments", "for", "the", "specified", "filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L451-L457
153,640
juju/juju
state/filesystem.go
MachineFilesystemAttachments
func (sb *storageBackend) MachineFilesystemAttachments(machine names.MachineTag) ([]FilesystemAttachment, error) { attachments, err := sb.filesystemAttachments(bson.D{{"hostid", machine.Id()}}) if err != nil { return nil, errors.Annotatef(err, "getting filesystem attachments for %q", names.ReadableString(machine)) } return attachments, nil }
go
func (sb *storageBackend) MachineFilesystemAttachments(machine names.MachineTag) ([]FilesystemAttachment, error) { attachments, err := sb.filesystemAttachments(bson.D{{"hostid", machine.Id()}}) if err != nil { return nil, errors.Annotatef(err, "getting filesystem attachments for %q", names.ReadableString(machine)) } return attachments, nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "MachineFilesystemAttachments", "(", "machine", "names", ".", "MachineTag", ")", "(", "[", "]", "FilesystemAttachment", ",", "error", ")", "{", "attachments", ",", "err", ":=", "sb", ".", "filesystemAttachments", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "machine", ".", "Id", "(", ")", "}", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "names", ".", "ReadableString", "(", "machine", ")", ")", "\n", "}", "\n", "return", "attachments", ",", "nil", "\n", "}" ]
// MachineFilesystemAttachments returns all of the FilesystemAttachments for the // specified machine.
[ "MachineFilesystemAttachments", "returns", "all", "of", "the", "FilesystemAttachments", "for", "the", "specified", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L461-L467
153,641
juju/juju
state/filesystem.go
UnitFilesystemAttachments
func (sb *storageBackend) UnitFilesystemAttachments(unit names.UnitTag) ([]FilesystemAttachment, error) { attachments, err := sb.filesystemAttachments(bson.D{{"hostid", unit.Id()}}) if err != nil { return nil, errors.Annotatef(err, "getting filesystem attachments for %q", names.ReadableString(unit)) } return attachments, nil }
go
func (sb *storageBackend) UnitFilesystemAttachments(unit names.UnitTag) ([]FilesystemAttachment, error) { attachments, err := sb.filesystemAttachments(bson.D{{"hostid", unit.Id()}}) if err != nil { return nil, errors.Annotatef(err, "getting filesystem attachments for %q", names.ReadableString(unit)) } return attachments, nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "UnitFilesystemAttachments", "(", "unit", "names", ".", "UnitTag", ")", "(", "[", "]", "FilesystemAttachment", ",", "error", ")", "{", "attachments", ",", "err", ":=", "sb", ".", "filesystemAttachments", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "unit", ".", "Id", "(", ")", "}", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "names", ".", "ReadableString", "(", "unit", ")", ")", "\n", "}", "\n", "return", "attachments", ",", "nil", "\n", "}" ]
// UnitFilesystemAttachments returns all of the FilesystemAttachments for the // specified unit.
[ "UnitFilesystemAttachments", "returns", "all", "of", "the", "FilesystemAttachments", "for", "the", "specified", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L471-L477
153,642
juju/juju
state/filesystem.go
removeMachineFilesystemsOps
func (sb *storageBackend) removeMachineFilesystemsOps(m *Machine) ([]txn.Op, error) { // A machine cannot transition to Dead if it has any detachable storage // attached, so any attachments are for machine-bound storage. // // Even if a filesystem is "non-detachable", there still exist filesystem // attachments, and they may be removed independently of the filesystem. // For example, the user may request that the filesystem be destroyed. // This will cause the filesystem to become Dying, and the attachment // to be Dying, then Dead, and finally removed. Only once the attachment // is removed will the filesystem transition to Dead and then be removed. // Therefore, there may be filesystems that are bound, but not attached, // to the machine. machineFilesystems, err := sb.filesystems(bson.D{{"hostid", m.Id()}}) if err != nil { return nil, errors.Trace(err) } ops := make([]txn.Op, 0, 2*len(machineFilesystems)+len(m.doc.Filesystems)) for _, filesystemId := range m.doc.Filesystems { ops = append(ops, txn.Op{ C: filesystemAttachmentsC, Id: filesystemAttachmentId(m.Id(), filesystemId), Assert: txn.DocExists, Remove: true, }) } for _, f := range machineFilesystems { if f.doc.StorageId != "" { // The volume is assigned to a storage instance; // make sure we also remove the storage instance. // There should be no storage attachments remaining, // as the units must have been removed before the // machine can be; and the storage attachments must // have been removed before the unit can be. ops = append(ops, txn.Op{ C: storageInstancesC, Id: f.doc.StorageId, Assert: txn.DocExists, Remove: true, }, ) } fsOps, err := removeFilesystemOps(sb, f, f.doc.Releasing, nil) if err != nil { return nil, errors.Trace(err) } ops = append(ops, fsOps...) } return ops, nil }
go
func (sb *storageBackend) removeMachineFilesystemsOps(m *Machine) ([]txn.Op, error) { // A machine cannot transition to Dead if it has any detachable storage // attached, so any attachments are for machine-bound storage. // // Even if a filesystem is "non-detachable", there still exist filesystem // attachments, and they may be removed independently of the filesystem. // For example, the user may request that the filesystem be destroyed. // This will cause the filesystem to become Dying, and the attachment // to be Dying, then Dead, and finally removed. Only once the attachment // is removed will the filesystem transition to Dead and then be removed. // Therefore, there may be filesystems that are bound, but not attached, // to the machine. machineFilesystems, err := sb.filesystems(bson.D{{"hostid", m.Id()}}) if err != nil { return nil, errors.Trace(err) } ops := make([]txn.Op, 0, 2*len(machineFilesystems)+len(m.doc.Filesystems)) for _, filesystemId := range m.doc.Filesystems { ops = append(ops, txn.Op{ C: filesystemAttachmentsC, Id: filesystemAttachmentId(m.Id(), filesystemId), Assert: txn.DocExists, Remove: true, }) } for _, f := range machineFilesystems { if f.doc.StorageId != "" { // The volume is assigned to a storage instance; // make sure we also remove the storage instance. // There should be no storage attachments remaining, // as the units must have been removed before the // machine can be; and the storage attachments must // have been removed before the unit can be. ops = append(ops, txn.Op{ C: storageInstancesC, Id: f.doc.StorageId, Assert: txn.DocExists, Remove: true, }, ) } fsOps, err := removeFilesystemOps(sb, f, f.doc.Releasing, nil) if err != nil { return nil, errors.Trace(err) } ops = append(ops, fsOps...) } return ops, nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "removeMachineFilesystemsOps", "(", "m", "*", "Machine", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "// A machine cannot transition to Dead if it has any detachable storage", "// attached, so any attachments are for machine-bound storage.", "//", "// Even if a filesystem is \"non-detachable\", there still exist filesystem", "// attachments, and they may be removed independently of the filesystem.", "// For example, the user may request that the filesystem be destroyed.", "// This will cause the filesystem to become Dying, and the attachment", "// to be Dying, then Dead, and finally removed. Only once the attachment", "// is removed will the filesystem transition to Dead and then be removed.", "// Therefore, there may be filesystems that are bound, but not attached,", "// to the machine.", "machineFilesystems", ",", "err", ":=", "sb", ".", "filesystems", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "m", ".", "Id", "(", ")", "}", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "ops", ":=", "make", "(", "[", "]", "txn", ".", "Op", ",", "0", ",", "2", "*", "len", "(", "machineFilesystems", ")", "+", "len", "(", "m", ".", "doc", ".", "Filesystems", ")", ")", "\n", "for", "_", ",", "filesystemId", ":=", "range", "m", ".", "doc", ".", "Filesystems", "{", "ops", "=", "append", "(", "ops", ",", "txn", ".", "Op", "{", "C", ":", "filesystemAttachmentsC", ",", "Id", ":", "filesystemAttachmentId", "(", "m", ".", "Id", "(", ")", ",", "filesystemId", ")", ",", "Assert", ":", "txn", ".", "DocExists", ",", "Remove", ":", "true", ",", "}", ")", "\n", "}", "\n", "for", "_", ",", "f", ":=", "range", "machineFilesystems", "{", "if", "f", ".", "doc", ".", "StorageId", "!=", "\"", "\"", "{", "// The volume is assigned to a storage instance;", "// make sure we also remove the storage instance.", "// There should be no storage attachments remaining,", "// as the units must have been removed before the", "// machine can be; and the storage attachments must", "// have been removed before the unit can be.", "ops", "=", "append", "(", "ops", ",", "txn", ".", "Op", "{", "C", ":", "storageInstancesC", ",", "Id", ":", "f", ".", "doc", ".", "StorageId", ",", "Assert", ":", "txn", ".", "DocExists", ",", "Remove", ":", "true", ",", "}", ",", ")", "\n", "}", "\n", "fsOps", ",", "err", ":=", "removeFilesystemOps", "(", "sb", ",", "f", ",", "f", ".", "doc", ".", "Releasing", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "ops", "=", "append", "(", "ops", ",", "fsOps", "...", ")", "\n", "}", "\n", "return", "ops", ",", "nil", "\n", "}" ]
// removeMachineFilesystemsOps returns txn.Ops to remove non-persistent filesystems // attached to the specified machine. This is used when the given machine is // being removed from state.
[ "removeMachineFilesystemsOps", "returns", "txn", ".", "Ops", "to", "remove", "non", "-", "persistent", "filesystems", "attached", "to", "the", "specified", "machine", ".", "This", "is", "used", "when", "the", "given", "machine", "is", "being", "removed", "from", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L500-L549
153,643
juju/juju
state/filesystem.go
isDetachableFilesystemTag
func isDetachableFilesystemTag(db Database, tag names.FilesystemTag) (bool, error) { doc, err := getFilesystemDocByTag(db, tag) if err != nil { return false, errors.Trace(err) } return doc.HostId == "", nil }
go
func isDetachableFilesystemTag(db Database, tag names.FilesystemTag) (bool, error) { doc, err := getFilesystemDocByTag(db, tag) if err != nil { return false, errors.Trace(err) } return doc.HostId == "", nil }
[ "func", "isDetachableFilesystemTag", "(", "db", "Database", ",", "tag", "names", ".", "FilesystemTag", ")", "(", "bool", ",", "error", ")", "{", "doc", ",", "err", ":=", "getFilesystemDocByTag", "(", "db", ",", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "doc", ".", "HostId", "==", "\"", "\"", ",", "nil", "\n", "}" ]
// isDetachableFilesystemTag reports whether or not the filesystem with the // specified tag is detachable.
[ "isDetachableFilesystemTag", "reports", "whether", "or", "not", "the", "filesystem", "with", "the", "specified", "tag", "is", "detachable", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L553-L559
153,644
juju/juju
state/filesystem.go
DetachFilesystem
func (sb *storageBackend) DetachFilesystem(host names.Tag, filesystem names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "detaching filesystem %s from %s", filesystem.Id(), names.ReadableString(host)) buildTxn := func(attempt int) ([]txn.Op, error) { fsa, err := sb.FilesystemAttachment(host, filesystem) if err != nil { return nil, errors.Trace(err) } if fsa.Life() != Alive { return nil, jujutxn.ErrNoOperations } detachable, err := isDetachableFilesystemTag(sb.mb.db(), filesystem) if err != nil { return nil, errors.Trace(err) } if !detachable { return nil, errors.New("filesystem is not detachable") } ops := detachFilesystemOps(host, filesystem) return ops, nil } return sb.mb.db().Run(buildTxn) }
go
func (sb *storageBackend) DetachFilesystem(host names.Tag, filesystem names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "detaching filesystem %s from %s", filesystem.Id(), names.ReadableString(host)) buildTxn := func(attempt int) ([]txn.Op, error) { fsa, err := sb.FilesystemAttachment(host, filesystem) if err != nil { return nil, errors.Trace(err) } if fsa.Life() != Alive { return nil, jujutxn.ErrNoOperations } detachable, err := isDetachableFilesystemTag(sb.mb.db(), filesystem) if err != nil { return nil, errors.Trace(err) } if !detachable { return nil, errors.New("filesystem is not detachable") } ops := detachFilesystemOps(host, filesystem) return ops, nil } return sb.mb.db().Run(buildTxn) }
[ "func", "(", "sb", "*", "storageBackend", ")", "DetachFilesystem", "(", "host", "names", ".", "Tag", ",", "filesystem", "names", ".", "FilesystemTag", ")", "(", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "filesystem", ".", "Id", "(", ")", ",", "names", ".", "ReadableString", "(", "host", ")", ")", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "fsa", ",", "err", ":=", "sb", ".", "FilesystemAttachment", "(", "host", ",", "filesystem", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "fsa", ".", "Life", "(", ")", "!=", "Alive", "{", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "\n", "detachable", ",", "err", ":=", "isDetachableFilesystemTag", "(", "sb", ".", "mb", ".", "db", "(", ")", ",", "filesystem", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "detachable", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "ops", ":=", "detachFilesystemOps", "(", "host", ",", "filesystem", ")", "\n", "return", "ops", ",", "nil", "\n", "}", "\n", "return", "sb", ".", "mb", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// DetachFilesystem marks the filesystem attachment identified by the specified machine // and filesystem tags as Dying, if it is Alive. DetachFilesystem will fail for // inherently machine-bound filesystems.
[ "DetachFilesystem", "marks", "the", "filesystem", "attachment", "identified", "by", "the", "specified", "machine", "and", "filesystem", "tags", "as", "Dying", "if", "it", "is", "Alive", ".", "DetachFilesystem", "will", "fail", "for", "inherently", "machine", "-", "bound", "filesystems", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L598-L619
153,645
juju/juju
state/filesystem.go
RemoveFilesystemAttachment
func (sb *storageBackend) RemoveFilesystemAttachment(host names.Tag, filesystem names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "removing attachment of filesystem %s from %s", filesystem.Id(), names.ReadableString(host)) buildTxn := func(attempt int) ([]txn.Op, error) { attachment, err := sb.FilesystemAttachment(host, filesystem) if errors.IsNotFound(err) && attempt > 0 { // We only ignore IsNotFound on attempts after the // first, since we expect the filesystem attachment to // be there initially. return nil, jujutxn.ErrNoOperations } if err != nil { return nil, errors.Trace(err) } if attachment.Life() != Dying { return nil, errors.New("filesystem attachment is not dying") } f, err := getFilesystemByTag(sb.mb, filesystem) if err != nil { return nil, errors.Trace(err) } ops, err := removeFilesystemAttachmentOps(sb, host, f) if err != nil { return nil, errors.Trace(err) } volumeAttachment, err := sb.filesystemVolumeAttachment(host, filesystem) if err != nil { if errors.Cause(err) != ErrNoBackingVolume && !errors.IsNotFound(err) { return nil, errors.Trace(err) } } else { // The filesystem is backed by a volume. Since the // filesystem has been detached, we should now // detach the volume as well if it is detachable. // If the volume is not detachable, we'll just // destroy it along with the filesystem. volume := volumeAttachment.Volume() detachableVolume, err := isDetachableVolumeTag(sb.mb.db(), volume) if err != nil { return nil, errors.Trace(err) } if detachableVolume { plans, err := sb.machineVolumeAttachmentPlans(host, volume) if err != nil { return nil, errors.Trace(err) } // NOTE(gsamfira): if we're upgrading, we might not have plans set up, // so we check if volume plans were created, and if not, just skip to // detaching the actual disk var volOps []txn.Op if plans == nil || len(plans) == 0 { volOps = detachVolumeOps(host, volume) } else { volOps = detachStorageAttachmentOps(host, volume) } ops = append(ops, volOps...) } } return ops, nil } return sb.mb.db().Run(buildTxn) }
go
func (sb *storageBackend) RemoveFilesystemAttachment(host names.Tag, filesystem names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "removing attachment of filesystem %s from %s", filesystem.Id(), names.ReadableString(host)) buildTxn := func(attempt int) ([]txn.Op, error) { attachment, err := sb.FilesystemAttachment(host, filesystem) if errors.IsNotFound(err) && attempt > 0 { // We only ignore IsNotFound on attempts after the // first, since we expect the filesystem attachment to // be there initially. return nil, jujutxn.ErrNoOperations } if err != nil { return nil, errors.Trace(err) } if attachment.Life() != Dying { return nil, errors.New("filesystem attachment is not dying") } f, err := getFilesystemByTag(sb.mb, filesystem) if err != nil { return nil, errors.Trace(err) } ops, err := removeFilesystemAttachmentOps(sb, host, f) if err != nil { return nil, errors.Trace(err) } volumeAttachment, err := sb.filesystemVolumeAttachment(host, filesystem) if err != nil { if errors.Cause(err) != ErrNoBackingVolume && !errors.IsNotFound(err) { return nil, errors.Trace(err) } } else { // The filesystem is backed by a volume. Since the // filesystem has been detached, we should now // detach the volume as well if it is detachable. // If the volume is not detachable, we'll just // destroy it along with the filesystem. volume := volumeAttachment.Volume() detachableVolume, err := isDetachableVolumeTag(sb.mb.db(), volume) if err != nil { return nil, errors.Trace(err) } if detachableVolume { plans, err := sb.machineVolumeAttachmentPlans(host, volume) if err != nil { return nil, errors.Trace(err) } // NOTE(gsamfira): if we're upgrading, we might not have plans set up, // so we check if volume plans were created, and if not, just skip to // detaching the actual disk var volOps []txn.Op if plans == nil || len(plans) == 0 { volOps = detachVolumeOps(host, volume) } else { volOps = detachStorageAttachmentOps(host, volume) } ops = append(ops, volOps...) } } return ops, nil } return sb.mb.db().Run(buildTxn) }
[ "func", "(", "sb", "*", "storageBackend", ")", "RemoveFilesystemAttachment", "(", "host", "names", ".", "Tag", ",", "filesystem", "names", ".", "FilesystemTag", ")", "(", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "filesystem", ".", "Id", "(", ")", ",", "names", ".", "ReadableString", "(", "host", ")", ")", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "attachment", ",", "err", ":=", "sb", ".", "FilesystemAttachment", "(", "host", ",", "filesystem", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "&&", "attempt", ">", "0", "{", "// We only ignore IsNotFound on attempts after the", "// first, since we expect the filesystem attachment to", "// be there initially.", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "attachment", ".", "Life", "(", ")", "!=", "Dying", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "f", ",", "err", ":=", "getFilesystemByTag", "(", "sb", ".", "mb", ",", "filesystem", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "ops", ",", "err", ":=", "removeFilesystemAttachmentOps", "(", "sb", ",", "host", ",", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "volumeAttachment", ",", "err", ":=", "sb", ".", "filesystemVolumeAttachment", "(", "host", ",", "filesystem", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "!=", "ErrNoBackingVolume", "&&", "!", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "else", "{", "// The filesystem is backed by a volume. Since the", "// filesystem has been detached, we should now", "// detach the volume as well if it is detachable.", "// If the volume is not detachable, we'll just", "// destroy it along with the filesystem.", "volume", ":=", "volumeAttachment", ".", "Volume", "(", ")", "\n", "detachableVolume", ",", "err", ":=", "isDetachableVolumeTag", "(", "sb", ".", "mb", ".", "db", "(", ")", ",", "volume", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "detachableVolume", "{", "plans", ",", "err", ":=", "sb", ".", "machineVolumeAttachmentPlans", "(", "host", ",", "volume", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// NOTE(gsamfira): if we're upgrading, we might not have plans set up,", "// so we check if volume plans were created, and if not, just skip to", "// detaching the actual disk", "var", "volOps", "[", "]", "txn", ".", "Op", "\n", "if", "plans", "==", "nil", "||", "len", "(", "plans", ")", "==", "0", "{", "volOps", "=", "detachVolumeOps", "(", "host", ",", "volume", ")", "\n", "}", "else", "{", "volOps", "=", "detachStorageAttachmentOps", "(", "host", ",", "volume", ")", "\n", "}", "\n", "ops", "=", "append", "(", "ops", ",", "volOps", "...", ")", "\n", "}", "\n", "}", "\n", "return", "ops", ",", "nil", "\n", "}", "\n", "return", "sb", ".", "mb", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// RemoveFilesystemAttachment removes the filesystem attachment from state. // Removing a volume-backed filesystem attachment will cause the volume to // be detached.
[ "RemoveFilesystemAttachment", "removes", "the", "filesystem", "attachment", "from", "state", ".", "Removing", "a", "volume", "-", "backed", "filesystem", "attachment", "will", "cause", "the", "volume", "to", "be", "detached", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L645-L705
153,646
juju/juju
state/filesystem.go
DestroyFilesystem
func (sb *storageBackend) DestroyFilesystem(tag names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "destroying filesystem %s", tag.Id()) buildTxn := func(attempt int) ([]txn.Op, error) { filesystem, err := getFilesystemByTag(sb.mb, tag) if errors.IsNotFound(err) && attempt > 0 { // On the first attempt, we expect it to exist. return nil, jujutxn.ErrNoOperations } else if err != nil { return nil, errors.Trace(err) } if filesystem.Life() != Alive { return nil, jujutxn.ErrNoOperations } if filesystem.doc.StorageId != "" { return nil, errors.Errorf( "filesystem is assigned to %s", names.ReadableString(names.NewStorageTag(filesystem.doc.StorageId)), ) } hasNoStorageAssignment := bson.D{{"$or", []bson.D{ {{"storageid", ""}}, {{"storageid", bson.D{{"$exists", false}}}}, }}} return destroyFilesystemOps(sb, filesystem, false, hasNoStorageAssignment) } return sb.mb.db().Run(buildTxn) }
go
func (sb *storageBackend) DestroyFilesystem(tag names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "destroying filesystem %s", tag.Id()) buildTxn := func(attempt int) ([]txn.Op, error) { filesystem, err := getFilesystemByTag(sb.mb, tag) if errors.IsNotFound(err) && attempt > 0 { // On the first attempt, we expect it to exist. return nil, jujutxn.ErrNoOperations } else if err != nil { return nil, errors.Trace(err) } if filesystem.Life() != Alive { return nil, jujutxn.ErrNoOperations } if filesystem.doc.StorageId != "" { return nil, errors.Errorf( "filesystem is assigned to %s", names.ReadableString(names.NewStorageTag(filesystem.doc.StorageId)), ) } hasNoStorageAssignment := bson.D{{"$or", []bson.D{ {{"storageid", ""}}, {{"storageid", bson.D{{"$exists", false}}}}, }}} return destroyFilesystemOps(sb, filesystem, false, hasNoStorageAssignment) } return sb.mb.db().Run(buildTxn) }
[ "func", "(", "sb", "*", "storageBackend", ")", "DestroyFilesystem", "(", "tag", "names", ".", "FilesystemTag", ")", "(", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "filesystem", ",", "err", ":=", "getFilesystemByTag", "(", "sb", ".", "mb", ",", "tag", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "&&", "attempt", ">", "0", "{", "// On the first attempt, we expect it to exist.", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "filesystem", ".", "Life", "(", ")", "!=", "Alive", "{", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "\n", "if", "filesystem", ".", "doc", ".", "StorageId", "!=", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "names", ".", "ReadableString", "(", "names", ".", "NewStorageTag", "(", "filesystem", ".", "doc", ".", "StorageId", ")", ")", ",", ")", "\n", "}", "\n", "hasNoStorageAssignment", ":=", "bson", ".", "D", "{", "{", "\"", "\"", ",", "[", "]", "bson", ".", "D", "{", "{", "{", "\"", "\"", ",", "\"", "\"", "}", "}", ",", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "false", "}", "}", "}", "}", ",", "}", "}", "}", "\n", "return", "destroyFilesystemOps", "(", "sb", ",", "filesystem", ",", "false", ",", "hasNoStorageAssignment", ")", "\n", "}", "\n", "return", "sb", ".", "mb", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// DestroyFilesystem ensures that the filesystem and any attachments to it will // be destroyed and removed from state at some point in the future.
[ "DestroyFilesystem", "ensures", "that", "the", "filesystem", "and", "any", "attachments", "to", "it", "will", "be", "destroyed", "and", "removed", "from", "state", "at", "some", "point", "in", "the", "future", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L747-L773
153,647
juju/juju
state/filesystem.go
RemoveFilesystem
func (sb *storageBackend) RemoveFilesystem(tag names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "removing filesystem %s", tag.Id()) buildTxn := func(attempt int) ([]txn.Op, error) { filesystem, err := getFilesystemByTag(sb.mb, tag) if errors.IsNotFound(err) { return nil, jujutxn.ErrNoOperations } else if err != nil { return nil, errors.Trace(err) } if filesystem.Life() != Dead { return nil, errors.New("filesystem is not dead") } return removeFilesystemOps(sb, filesystem, false, isDeadDoc) } return sb.mb.db().Run(buildTxn) }
go
func (sb *storageBackend) RemoveFilesystem(tag names.FilesystemTag) (err error) { defer errors.DeferredAnnotatef(&err, "removing filesystem %s", tag.Id()) buildTxn := func(attempt int) ([]txn.Op, error) { filesystem, err := getFilesystemByTag(sb.mb, tag) if errors.IsNotFound(err) { return nil, jujutxn.ErrNoOperations } else if err != nil { return nil, errors.Trace(err) } if filesystem.Life() != Dead { return nil, errors.New("filesystem is not dead") } return removeFilesystemOps(sb, filesystem, false, isDeadDoc) } return sb.mb.db().Run(buildTxn) }
[ "func", "(", "sb", "*", "storageBackend", ")", "RemoveFilesystem", "(", "tag", "names", ".", "FilesystemTag", ")", "(", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "filesystem", ",", "err", ":=", "getFilesystemByTag", "(", "sb", ".", "mb", ",", "tag", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "filesystem", ".", "Life", "(", ")", "!=", "Dead", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "removeFilesystemOps", "(", "sb", ",", "filesystem", ",", "false", ",", "isDeadDoc", ")", "\n", "}", "\n", "return", "sb", ".", "mb", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// RemoveFilesystem removes the filesystem from state. RemoveFilesystem will // fail if there are any attachments remaining, or if the filesystem is not // Dying. Removing a volume-backed filesystem will cause the volume to be // destroyed.
[ "RemoveFilesystem", "removes", "the", "filesystem", "from", "state", ".", "RemoveFilesystem", "will", "fail", "if", "there", "are", "any", "attachments", "remaining", "or", "if", "the", "filesystem", "is", "not", "Dying", ".", "Removing", "a", "volume", "-", "backed", "filesystem", "will", "cause", "the", "volume", "to", "be", "destroyed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L843-L858
153,648
juju/juju
state/filesystem.go
ParseFilesystemAttachmentId
func ParseFilesystemAttachmentId(id string) (names.Tag, names.FilesystemTag, error) { fields := strings.SplitN(id, ":", 2) isValidHost := names.IsValidMachine(fields[0]) || names.IsValidUnit(fields[0]) if len(fields) != 2 || !isValidHost || !names.IsValidFilesystem(fields[1]) { return names.MachineTag{}, names.FilesystemTag{}, errors.Errorf("invalid filesystem attachment ID %q", id) } var hostTag names.Tag if names.IsValidMachine(fields[0]) { hostTag = names.NewMachineTag(fields[0]) } else { hostTag = names.NewUnitTag(fields[0]) } filesystemTag := names.NewFilesystemTag(fields[1]) return hostTag, filesystemTag, nil }
go
func ParseFilesystemAttachmentId(id string) (names.Tag, names.FilesystemTag, error) { fields := strings.SplitN(id, ":", 2) isValidHost := names.IsValidMachine(fields[0]) || names.IsValidUnit(fields[0]) if len(fields) != 2 || !isValidHost || !names.IsValidFilesystem(fields[1]) { return names.MachineTag{}, names.FilesystemTag{}, errors.Errorf("invalid filesystem attachment ID %q", id) } var hostTag names.Tag if names.IsValidMachine(fields[0]) { hostTag = names.NewMachineTag(fields[0]) } else { hostTag = names.NewUnitTag(fields[0]) } filesystemTag := names.NewFilesystemTag(fields[1]) return hostTag, filesystemTag, nil }
[ "func", "ParseFilesystemAttachmentId", "(", "id", "string", ")", "(", "names", ".", "Tag", ",", "names", ".", "FilesystemTag", ",", "error", ")", "{", "fields", ":=", "strings", ".", "SplitN", "(", "id", ",", "\"", "\"", ",", "2", ")", "\n", "isValidHost", ":=", "names", ".", "IsValidMachine", "(", "fields", "[", "0", "]", ")", "||", "names", ".", "IsValidUnit", "(", "fields", "[", "0", "]", ")", "\n", "if", "len", "(", "fields", ")", "!=", "2", "||", "!", "isValidHost", "||", "!", "names", ".", "IsValidFilesystem", "(", "fields", "[", "1", "]", ")", "{", "return", "names", ".", "MachineTag", "{", "}", ",", "names", ".", "FilesystemTag", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "id", ")", "\n", "}", "\n", "var", "hostTag", "names", ".", "Tag", "\n", "if", "names", ".", "IsValidMachine", "(", "fields", "[", "0", "]", ")", "{", "hostTag", "=", "names", ".", "NewMachineTag", "(", "fields", "[", "0", "]", ")", "\n", "}", "else", "{", "hostTag", "=", "names", ".", "NewUnitTag", "(", "fields", "[", "0", "]", ")", "\n", "}", "\n", "filesystemTag", ":=", "names", ".", "NewFilesystemTag", "(", "fields", "[", "1", "]", ")", "\n", "return", "hostTag", ",", "filesystemTag", ",", "nil", "\n", "}" ]
// ParseFilesystemAttachmentId parses a string as a filesystem attachment ID, // returning the host and filesystem components.
[ "ParseFilesystemAttachmentId", "parses", "a", "string", "as", "a", "filesystem", "attachment", "ID", "returning", "the", "host", "and", "filesystem", "components", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1009-L1023
153,649
juju/juju
state/filesystem.go
newFilesystemId
func newFilesystemId(mb modelBackend, hostId string) (string, error) { seq, err := sequence(mb, "filesystem") if err != nil { return "", errors.Trace(err) } id := fmt.Sprint(seq) if hostId != "" { id = hostId + "/" + id } return id, nil }
go
func newFilesystemId(mb modelBackend, hostId string) (string, error) { seq, err := sequence(mb, "filesystem") if err != nil { return "", errors.Trace(err) } id := fmt.Sprint(seq) if hostId != "" { id = hostId + "/" + id } return id, nil }
[ "func", "newFilesystemId", "(", "mb", "modelBackend", ",", "hostId", "string", ")", "(", "string", ",", "error", ")", "{", "seq", ",", "err", ":=", "sequence", "(", "mb", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "id", ":=", "fmt", ".", "Sprint", "(", "seq", ")", "\n", "if", "hostId", "!=", "\"", "\"", "{", "id", "=", "hostId", "+", "\"", "\"", "+", "id", "\n", "}", "\n", "return", "id", ",", "nil", "\n", "}" ]
// newFilesystemId returns a unique filesystem ID. // If the host ID supplied is non-empty, the // filesystem ID will incorporate it as the // filesystem's machine scope.
[ "newFilesystemId", "returns", "a", "unique", "filesystem", "ID", ".", "If", "the", "host", "ID", "supplied", "is", "non", "-", "empty", "the", "filesystem", "ID", "will", "incorporate", "it", "as", "the", "filesystem", "s", "machine", "scope", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1029-L1039
153,650
juju/juju
state/filesystem.go
validateFilesystemParams
func (sb *storageBackend) validateFilesystemParams(params FilesystemParams, machineId string) (maybeMachineId string, _ error) { err := validateStoragePool(sb, params.Pool, storage.StorageKindFilesystem, &machineId) if err != nil { return "", errors.Trace(err) } if params.Size == 0 { return "", errors.New("invalid size 0") } return machineId, nil }
go
func (sb *storageBackend) validateFilesystemParams(params FilesystemParams, machineId string) (maybeMachineId string, _ error) { err := validateStoragePool(sb, params.Pool, storage.StorageKindFilesystem, &machineId) if err != nil { return "", errors.Trace(err) } if params.Size == 0 { return "", errors.New("invalid size 0") } return machineId, nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "validateFilesystemParams", "(", "params", "FilesystemParams", ",", "machineId", "string", ")", "(", "maybeMachineId", "string", ",", "_", "error", ")", "{", "err", ":=", "validateStoragePool", "(", "sb", ",", "params", ".", "Pool", ",", "storage", ".", "StorageKindFilesystem", ",", "&", "machineId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "params", ".", "Size", "==", "0", "{", "return", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "machineId", ",", "nil", "\n", "}" ]
// validateFilesystemParams validates the filesystem parameters, and returns the // machine ID to use as the scope in the filesystem tag.
[ "validateFilesystemParams", "validates", "the", "filesystem", "parameters", "and", "returns", "the", "machine", "ID", "to", "use", "as", "the", "scope", "in", "the", "filesystem", "tag", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1162-L1171
153,651
juju/juju
state/filesystem.go
createMachineFilesystemAttachmentsOps
func createMachineFilesystemAttachmentsOps(hostId string, attachments []filesystemAttachmentTemplate) []txn.Op { ops := make([]txn.Op, len(attachments)) for i, attachment := range attachments { paramsCopy := attachment.params ops[i] = txn.Op{ C: filesystemAttachmentsC, Id: filesystemAttachmentId(hostId, attachment.tag.Id()), Assert: txn.DocMissing, Insert: &filesystemAttachmentDoc{ Filesystem: attachment.tag.Id(), Host: hostId, Params: &paramsCopy, }, } if attachment.existing { ops = append(ops, txn.Op{ C: filesystemsC, Id: attachment.tag.Id(), Assert: txn.DocExists, Update: bson.D{{"$inc", bson.D{{"attachmentcount", 1}}}}, }) } } return ops }
go
func createMachineFilesystemAttachmentsOps(hostId string, attachments []filesystemAttachmentTemplate) []txn.Op { ops := make([]txn.Op, len(attachments)) for i, attachment := range attachments { paramsCopy := attachment.params ops[i] = txn.Op{ C: filesystemAttachmentsC, Id: filesystemAttachmentId(hostId, attachment.tag.Id()), Assert: txn.DocMissing, Insert: &filesystemAttachmentDoc{ Filesystem: attachment.tag.Id(), Host: hostId, Params: &paramsCopy, }, } if attachment.existing { ops = append(ops, txn.Op{ C: filesystemsC, Id: attachment.tag.Id(), Assert: txn.DocExists, Update: bson.D{{"$inc", bson.D{{"attachmentcount", 1}}}}, }) } } return ops }
[ "func", "createMachineFilesystemAttachmentsOps", "(", "hostId", "string", ",", "attachments", "[", "]", "filesystemAttachmentTemplate", ")", "[", "]", "txn", ".", "Op", "{", "ops", ":=", "make", "(", "[", "]", "txn", ".", "Op", ",", "len", "(", "attachments", ")", ")", "\n", "for", "i", ",", "attachment", ":=", "range", "attachments", "{", "paramsCopy", ":=", "attachment", ".", "params", "\n", "ops", "[", "i", "]", "=", "txn", ".", "Op", "{", "C", ":", "filesystemAttachmentsC", ",", "Id", ":", "filesystemAttachmentId", "(", "hostId", ",", "attachment", ".", "tag", ".", "Id", "(", ")", ")", ",", "Assert", ":", "txn", ".", "DocMissing", ",", "Insert", ":", "&", "filesystemAttachmentDoc", "{", "Filesystem", ":", "attachment", ".", "tag", ".", "Id", "(", ")", ",", "Host", ":", "hostId", ",", "Params", ":", "&", "paramsCopy", ",", "}", ",", "}", "\n", "if", "attachment", ".", "existing", "{", "ops", "=", "append", "(", "ops", ",", "txn", ".", "Op", "{", "C", ":", "filesystemsC", ",", "Id", ":", "attachment", ".", "tag", ".", "Id", "(", ")", ",", "Assert", ":", "txn", ".", "DocExists", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "1", "}", "}", "}", "}", ",", "}", ")", "\n", "}", "\n", "}", "\n", "return", "ops", "\n", "}" ]
// createMachineFilesystemAttachmentInfo creates filesystem // attachments for the specified host, and attachment // parameters keyed by filesystem tags.
[ "createMachineFilesystemAttachmentInfo", "creates", "filesystem", "attachments", "for", "the", "specified", "host", "and", "attachment", "parameters", "keyed", "by", "filesystem", "tags", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1183-L1207
153,652
juju/juju
state/filesystem.go
SetFilesystemInfo
func (sb *storageBackend) SetFilesystemInfo(tag names.FilesystemTag, info FilesystemInfo) (err error) { defer errors.DeferredAnnotatef(&err, "cannot set info for filesystem %q", tag.Id()) if info.FilesystemId == "" { return errors.New("filesystem ID not set") } fs, err := sb.Filesystem(tag) if err != nil { return errors.Trace(err) } // If the filesystem is volume-backed, the volume must be provisioned // and attached first. if volumeTag, err := fs.Volume(); err == nil { volumeAttachments, err := sb.VolumeAttachments(volumeTag) if err != nil { return errors.Trace(err) } var anyAttached bool for _, a := range volumeAttachments { if _, err := a.Info(); err == nil { anyAttached = true } else if !errors.IsNotProvisioned(err) { return err } } if !anyAttached { return errors.Errorf( "backing volume %q is not attached", volumeTag.Id(), ) } } else if errors.Cause(err) != ErrNoBackingVolume { return errors.Trace(err) } buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { fs, err = sb.Filesystem(tag) if err != nil { return nil, errors.Trace(err) } } // If the filesystem has parameters, unset them // when we set info for the first time, ensuring // that params and info are mutually exclusive. var unsetParams bool if params, ok := fs.Params(); ok { info.Pool = params.Pool unsetParams = true } else { // Ensure immutable properties do not change. oldInfo, err := fs.Info() if err != nil { return nil, err } if err := validateFilesystemInfoChange(info, oldInfo); err != nil { return nil, err } } ops := setFilesystemInfoOps(tag, info, unsetParams) return ops, nil } return sb.mb.db().Run(buildTxn) }
go
func (sb *storageBackend) SetFilesystemInfo(tag names.FilesystemTag, info FilesystemInfo) (err error) { defer errors.DeferredAnnotatef(&err, "cannot set info for filesystem %q", tag.Id()) if info.FilesystemId == "" { return errors.New("filesystem ID not set") } fs, err := sb.Filesystem(tag) if err != nil { return errors.Trace(err) } // If the filesystem is volume-backed, the volume must be provisioned // and attached first. if volumeTag, err := fs.Volume(); err == nil { volumeAttachments, err := sb.VolumeAttachments(volumeTag) if err != nil { return errors.Trace(err) } var anyAttached bool for _, a := range volumeAttachments { if _, err := a.Info(); err == nil { anyAttached = true } else if !errors.IsNotProvisioned(err) { return err } } if !anyAttached { return errors.Errorf( "backing volume %q is not attached", volumeTag.Id(), ) } } else if errors.Cause(err) != ErrNoBackingVolume { return errors.Trace(err) } buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { fs, err = sb.Filesystem(tag) if err != nil { return nil, errors.Trace(err) } } // If the filesystem has parameters, unset them // when we set info for the first time, ensuring // that params and info are mutually exclusive. var unsetParams bool if params, ok := fs.Params(); ok { info.Pool = params.Pool unsetParams = true } else { // Ensure immutable properties do not change. oldInfo, err := fs.Info() if err != nil { return nil, err } if err := validateFilesystemInfoChange(info, oldInfo); err != nil { return nil, err } } ops := setFilesystemInfoOps(tag, info, unsetParams) return ops, nil } return sb.mb.db().Run(buildTxn) }
[ "func", "(", "sb", "*", "storageBackend", ")", "SetFilesystemInfo", "(", "tag", "names", ".", "FilesystemTag", ",", "info", "FilesystemInfo", ")", "(", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n\n", "if", "info", ".", "FilesystemId", "==", "\"", "\"", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "fs", ",", "err", ":=", "sb", ".", "Filesystem", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// If the filesystem is volume-backed, the volume must be provisioned", "// and attached first.", "if", "volumeTag", ",", "err", ":=", "fs", ".", "Volume", "(", ")", ";", "err", "==", "nil", "{", "volumeAttachments", ",", "err", ":=", "sb", ".", "VolumeAttachments", "(", "volumeTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "var", "anyAttached", "bool", "\n", "for", "_", ",", "a", ":=", "range", "volumeAttachments", "{", "if", "_", ",", "err", ":=", "a", ".", "Info", "(", ")", ";", "err", "==", "nil", "{", "anyAttached", "=", "true", "\n", "}", "else", "if", "!", "errors", ".", "IsNotProvisioned", "(", "err", ")", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "!", "anyAttached", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "volumeTag", ".", "Id", "(", ")", ",", ")", "\n", "}", "\n", "}", "else", "if", "errors", ".", "Cause", "(", "err", ")", "!=", "ErrNoBackingVolume", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "if", "attempt", ">", "0", "{", "fs", ",", "err", "=", "sb", ".", "Filesystem", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "// If the filesystem has parameters, unset them", "// when we set info for the first time, ensuring", "// that params and info are mutually exclusive.", "var", "unsetParams", "bool", "\n", "if", "params", ",", "ok", ":=", "fs", ".", "Params", "(", ")", ";", "ok", "{", "info", ".", "Pool", "=", "params", ".", "Pool", "\n", "unsetParams", "=", "true", "\n", "}", "else", "{", "// Ensure immutable properties do not change.", "oldInfo", ",", "err", ":=", "fs", ".", "Info", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "validateFilesystemInfoChange", "(", "info", ",", "oldInfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "ops", ":=", "setFilesystemInfoOps", "(", "tag", ",", "info", ",", "unsetParams", ")", "\n", "return", "ops", ",", "nil", "\n", "}", "\n", "return", "sb", ".", "mb", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// SetFilesystemInfo sets the FilesystemInfo for the specified filesystem.
[ "SetFilesystemInfo", "sets", "the", "FilesystemInfo", "for", "the", "specified", "filesystem", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1210-L1272
153,653
juju/juju
state/filesystem.go
SetFilesystemAttachmentInfo
func (sb *storageBackend) SetFilesystemAttachmentInfo( hostTag names.Tag, filesystemTag names.FilesystemTag, info FilesystemAttachmentInfo, ) (err error) { defer errors.DeferredAnnotatef(&err, "cannot set info for filesystem attachment %s:%s", filesystemTag.Id(), hostTag.Id()) f, err := sb.Filesystem(filesystemTag) if err != nil { return errors.Trace(err) } // Ensure filesystem is provisioned before setting attachment info. // A filesystem cannot go from being provisioned to unprovisioned, // so there is no txn.Op for this below. if _, err := f.Info(); err != nil { return errors.Trace(err) } // Also ensure the machine is provisioned. if _, ok := hostTag.(names.MachineTag); ok { m, err := sb.machine(hostTag.Id()) if err != nil { return errors.Trace(err) } if _, err := m.InstanceId(); err != nil { return errors.Trace(err) } } buildTxn := func(attempt int) ([]txn.Op, error) { fsa, err := sb.FilesystemAttachment(hostTag, filesystemTag) if err != nil { return nil, errors.Trace(err) } // If the filesystem attachment has parameters, unset them // when we set info for the first time, ensuring that params // and info are mutually exclusive. _, unsetParams := fsa.Params() ops := setFilesystemAttachmentInfoOps(hostTag, filesystemTag, info, unsetParams) return ops, nil } return sb.mb.db().Run(buildTxn) }
go
func (sb *storageBackend) SetFilesystemAttachmentInfo( hostTag names.Tag, filesystemTag names.FilesystemTag, info FilesystemAttachmentInfo, ) (err error) { defer errors.DeferredAnnotatef(&err, "cannot set info for filesystem attachment %s:%s", filesystemTag.Id(), hostTag.Id()) f, err := sb.Filesystem(filesystemTag) if err != nil { return errors.Trace(err) } // Ensure filesystem is provisioned before setting attachment info. // A filesystem cannot go from being provisioned to unprovisioned, // so there is no txn.Op for this below. if _, err := f.Info(); err != nil { return errors.Trace(err) } // Also ensure the machine is provisioned. if _, ok := hostTag.(names.MachineTag); ok { m, err := sb.machine(hostTag.Id()) if err != nil { return errors.Trace(err) } if _, err := m.InstanceId(); err != nil { return errors.Trace(err) } } buildTxn := func(attempt int) ([]txn.Op, error) { fsa, err := sb.FilesystemAttachment(hostTag, filesystemTag) if err != nil { return nil, errors.Trace(err) } // If the filesystem attachment has parameters, unset them // when we set info for the first time, ensuring that params // and info are mutually exclusive. _, unsetParams := fsa.Params() ops := setFilesystemAttachmentInfoOps(hostTag, filesystemTag, info, unsetParams) return ops, nil } return sb.mb.db().Run(buildTxn) }
[ "func", "(", "sb", "*", "storageBackend", ")", "SetFilesystemAttachmentInfo", "(", "hostTag", "names", ".", "Tag", ",", "filesystemTag", "names", ".", "FilesystemTag", ",", "info", "FilesystemAttachmentInfo", ",", ")", "(", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "filesystemTag", ".", "Id", "(", ")", ",", "hostTag", ".", "Id", "(", ")", ")", "\n", "f", ",", "err", ":=", "sb", ".", "Filesystem", "(", "filesystemTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// Ensure filesystem is provisioned before setting attachment info.", "// A filesystem cannot go from being provisioned to unprovisioned,", "// so there is no txn.Op for this below.", "if", "_", ",", "err", ":=", "f", ".", "Info", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// Also ensure the machine is provisioned.", "if", "_", ",", "ok", ":=", "hostTag", ".", "(", "names", ".", "MachineTag", ")", ";", "ok", "{", "m", ",", "err", ":=", "sb", ".", "machine", "(", "hostTag", ".", "Id", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "m", ".", "InstanceId", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "fsa", ",", "err", ":=", "sb", ".", "FilesystemAttachment", "(", "hostTag", ",", "filesystemTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// If the filesystem attachment has parameters, unset them", "// when we set info for the first time, ensuring that params", "// and info are mutually exclusive.", "_", ",", "unsetParams", ":=", "fsa", ".", "Params", "(", ")", "\n", "ops", ":=", "setFilesystemAttachmentInfoOps", "(", "hostTag", ",", "filesystemTag", ",", "info", ",", "unsetParams", ")", "\n", "return", "ops", ",", "nil", "\n", "}", "\n", "return", "sb", ".", "mb", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// SetFilesystemAttachmentInfo sets the FilesystemAttachmentInfo for the // specified filesystem attachment.
[ "SetFilesystemAttachmentInfo", "sets", "the", "FilesystemAttachmentInfo", "for", "the", "specified", "filesystem", "attachment", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1310-L1349
153,654
juju/juju
state/filesystem.go
FilesystemMountPoint
func FilesystemMountPoint( meta charm.Storage, tag names.StorageTag, series string, ) (string, error) { storageDir, err := paths.StorageDir(series) if err != nil { return "", errors.Trace(err) } if strings.HasPrefix(meta.Location, storageDir) { return "", errors.Errorf( "invalid location %q: must not fall within %q", meta.Location, storageDir, ) } if meta.Location != "" && meta.CountMax == 1 { // The location is specified and it's a singleton // store, so just use the location as-is. return meta.Location, nil } // If the location is unspecified then we use // <storage-dir>/<storage-id> as the location. // Otherwise, we use <location>/<storage-id>. if meta.Location != "" { storageDir = meta.Location } return path.Join(storageDir, tag.Id()), nil }
go
func FilesystemMountPoint( meta charm.Storage, tag names.StorageTag, series string, ) (string, error) { storageDir, err := paths.StorageDir(series) if err != nil { return "", errors.Trace(err) } if strings.HasPrefix(meta.Location, storageDir) { return "", errors.Errorf( "invalid location %q: must not fall within %q", meta.Location, storageDir, ) } if meta.Location != "" && meta.CountMax == 1 { // The location is specified and it's a singleton // store, so just use the location as-is. return meta.Location, nil } // If the location is unspecified then we use // <storage-dir>/<storage-id> as the location. // Otherwise, we use <location>/<storage-id>. if meta.Location != "" { storageDir = meta.Location } return path.Join(storageDir, tag.Id()), nil }
[ "func", "FilesystemMountPoint", "(", "meta", "charm", ".", "Storage", ",", "tag", "names", ".", "StorageTag", ",", "series", "string", ",", ")", "(", "string", ",", "error", ")", "{", "storageDir", ",", "err", ":=", "paths", ".", "StorageDir", "(", "series", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "meta", ".", "Location", ",", "storageDir", ")", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "meta", ".", "Location", ",", "storageDir", ",", ")", "\n", "}", "\n", "if", "meta", ".", "Location", "!=", "\"", "\"", "&&", "meta", ".", "CountMax", "==", "1", "{", "// The location is specified and it's a singleton", "// store, so just use the location as-is.", "return", "meta", ".", "Location", ",", "nil", "\n", "}", "\n", "// If the location is unspecified then we use", "// <storage-dir>/<storage-id> as the location.", "// Otherwise, we use <location>/<storage-id>.", "if", "meta", ".", "Location", "!=", "\"", "\"", "{", "storageDir", "=", "meta", ".", "Location", "\n", "}", "\n", "return", "path", ".", "Join", "(", "storageDir", ",", "tag", ".", "Id", "(", ")", ")", ",", "nil", "\n", "}" ]
// FilesystemMountPoint returns a mount point to use for the given charm // storage. For stores with potentially multiple instances, the instance // name is appended to the location.
[ "FilesystemMountPoint", "returns", "a", "mount", "point", "to", "use", "for", "the", "given", "charm", "storage", ".", "For", "stores", "with", "potentially", "multiple", "instances", "the", "instance", "name", "is", "appended", "to", "the", "location", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1377-L1404
153,655
juju/juju
state/filesystem.go
validateFilesystemMountPoints
func validateFilesystemMountPoints(m *Machine, newFilesystems []filesystemAttachmentTemplate) error { sb, err := NewStorageBackend(m.st) if err != nil { return errors.Trace(err) } attachments, err := sb.MachineFilesystemAttachments(m.MachineTag()) if err != nil { return errors.Trace(err) } existing := make(map[names.FilesystemTag]string) for _, a := range attachments { params, ok := a.Params() if ok { existing[a.Filesystem()] = params.Location continue } info, err := a.Info() if err != nil { return errors.Trace(err) } existing[a.Filesystem()] = info.MountPoint } storageName := func( filesystemTag names.FilesystemTag, storageTag names.StorageTag, ) string { if storageTag == (names.StorageTag{}) { return names.ReadableString(filesystemTag) } // We know the tag is valid, so ignore the error. storageName, _ := names.StorageName(storageTag.Id()) return fmt.Sprintf("%q storage", storageName) } containsPath := func(a, b string) bool { a = path.Clean(a) + "/" b = path.Clean(b) + "/" return strings.HasPrefix(b, a) } // These sets are expected to be small, so sorting and comparing // adjacent values is not worth the cost of creating a reverse // lookup from location to filesystem. for _, template := range newFilesystems { newMountPoint := template.params.Location for oldFilesystemTag, oldMountPoint := range existing { var conflicted, swapOrder bool if containsPath(oldMountPoint, newMountPoint) { conflicted = true } else if containsPath(newMountPoint, oldMountPoint) { conflicted = true swapOrder = true } if !conflicted { continue } // Get a helpful identifier for the new filesystem. If it // is being created for a storage instance, then use // the storage name; otherwise use the filesystem name. newStorageName := storageName(template.tag, template.storage) // Likewise for the old filesystem, but this time we'll // need to consult state. oldFilesystem, err := sb.Filesystem(oldFilesystemTag) if err != nil { return errors.Trace(err) } storageTag, err := oldFilesystem.Storage() if errors.IsNotAssigned(err) { storageTag = names.StorageTag{} } else if err != nil { return errors.Trace(err) } oldStorageName := storageName(oldFilesystemTag, storageTag) lhs := fmt.Sprintf("mount point %q for %s", oldMountPoint, oldStorageName) rhs := fmt.Sprintf("mount point %q for %s", newMountPoint, newStorageName) if swapOrder { lhs, rhs = rhs, lhs } return errors.Errorf("%s contains %s", lhs, rhs) } } return nil }
go
func validateFilesystemMountPoints(m *Machine, newFilesystems []filesystemAttachmentTemplate) error { sb, err := NewStorageBackend(m.st) if err != nil { return errors.Trace(err) } attachments, err := sb.MachineFilesystemAttachments(m.MachineTag()) if err != nil { return errors.Trace(err) } existing := make(map[names.FilesystemTag]string) for _, a := range attachments { params, ok := a.Params() if ok { existing[a.Filesystem()] = params.Location continue } info, err := a.Info() if err != nil { return errors.Trace(err) } existing[a.Filesystem()] = info.MountPoint } storageName := func( filesystemTag names.FilesystemTag, storageTag names.StorageTag, ) string { if storageTag == (names.StorageTag{}) { return names.ReadableString(filesystemTag) } // We know the tag is valid, so ignore the error. storageName, _ := names.StorageName(storageTag.Id()) return fmt.Sprintf("%q storage", storageName) } containsPath := func(a, b string) bool { a = path.Clean(a) + "/" b = path.Clean(b) + "/" return strings.HasPrefix(b, a) } // These sets are expected to be small, so sorting and comparing // adjacent values is not worth the cost of creating a reverse // lookup from location to filesystem. for _, template := range newFilesystems { newMountPoint := template.params.Location for oldFilesystemTag, oldMountPoint := range existing { var conflicted, swapOrder bool if containsPath(oldMountPoint, newMountPoint) { conflicted = true } else if containsPath(newMountPoint, oldMountPoint) { conflicted = true swapOrder = true } if !conflicted { continue } // Get a helpful identifier for the new filesystem. If it // is being created for a storage instance, then use // the storage name; otherwise use the filesystem name. newStorageName := storageName(template.tag, template.storage) // Likewise for the old filesystem, but this time we'll // need to consult state. oldFilesystem, err := sb.Filesystem(oldFilesystemTag) if err != nil { return errors.Trace(err) } storageTag, err := oldFilesystem.Storage() if errors.IsNotAssigned(err) { storageTag = names.StorageTag{} } else if err != nil { return errors.Trace(err) } oldStorageName := storageName(oldFilesystemTag, storageTag) lhs := fmt.Sprintf("mount point %q for %s", oldMountPoint, oldStorageName) rhs := fmt.Sprintf("mount point %q for %s", newMountPoint, newStorageName) if swapOrder { lhs, rhs = rhs, lhs } return errors.Errorf("%s contains %s", lhs, rhs) } } return nil }
[ "func", "validateFilesystemMountPoints", "(", "m", "*", "Machine", ",", "newFilesystems", "[", "]", "filesystemAttachmentTemplate", ")", "error", "{", "sb", ",", "err", ":=", "NewStorageBackend", "(", "m", ".", "st", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "attachments", ",", "err", ":=", "sb", ".", "MachineFilesystemAttachments", "(", "m", ".", "MachineTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "existing", ":=", "make", "(", "map", "[", "names", ".", "FilesystemTag", "]", "string", ")", "\n", "for", "_", ",", "a", ":=", "range", "attachments", "{", "params", ",", "ok", ":=", "a", ".", "Params", "(", ")", "\n", "if", "ok", "{", "existing", "[", "a", ".", "Filesystem", "(", ")", "]", "=", "params", ".", "Location", "\n", "continue", "\n", "}", "\n", "info", ",", "err", ":=", "a", ".", "Info", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "existing", "[", "a", ".", "Filesystem", "(", ")", "]", "=", "info", ".", "MountPoint", "\n", "}", "\n\n", "storageName", ":=", "func", "(", "filesystemTag", "names", ".", "FilesystemTag", ",", "storageTag", "names", ".", "StorageTag", ",", ")", "string", "{", "if", "storageTag", "==", "(", "names", ".", "StorageTag", "{", "}", ")", "{", "return", "names", ".", "ReadableString", "(", "filesystemTag", ")", "\n", "}", "\n", "// We know the tag is valid, so ignore the error.", "storageName", ",", "_", ":=", "names", ".", "StorageName", "(", "storageTag", ".", "Id", "(", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "storageName", ")", "\n", "}", "\n\n", "containsPath", ":=", "func", "(", "a", ",", "b", "string", ")", "bool", "{", "a", "=", "path", ".", "Clean", "(", "a", ")", "+", "\"", "\"", "\n", "b", "=", "path", ".", "Clean", "(", "b", ")", "+", "\"", "\"", "\n", "return", "strings", ".", "HasPrefix", "(", "b", ",", "a", ")", "\n", "}", "\n\n", "// These sets are expected to be small, so sorting and comparing", "// adjacent values is not worth the cost of creating a reverse", "// lookup from location to filesystem.", "for", "_", ",", "template", ":=", "range", "newFilesystems", "{", "newMountPoint", ":=", "template", ".", "params", ".", "Location", "\n", "for", "oldFilesystemTag", ",", "oldMountPoint", ":=", "range", "existing", "{", "var", "conflicted", ",", "swapOrder", "bool", "\n", "if", "containsPath", "(", "oldMountPoint", ",", "newMountPoint", ")", "{", "conflicted", "=", "true", "\n", "}", "else", "if", "containsPath", "(", "newMountPoint", ",", "oldMountPoint", ")", "{", "conflicted", "=", "true", "\n", "swapOrder", "=", "true", "\n", "}", "\n", "if", "!", "conflicted", "{", "continue", "\n", "}", "\n\n", "// Get a helpful identifier for the new filesystem. If it", "// is being created for a storage instance, then use", "// the storage name; otherwise use the filesystem name.", "newStorageName", ":=", "storageName", "(", "template", ".", "tag", ",", "template", ".", "storage", ")", "\n\n", "// Likewise for the old filesystem, but this time we'll", "// need to consult state.", "oldFilesystem", ",", "err", ":=", "sb", ".", "Filesystem", "(", "oldFilesystemTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "storageTag", ",", "err", ":=", "oldFilesystem", ".", "Storage", "(", ")", "\n", "if", "errors", ".", "IsNotAssigned", "(", "err", ")", "{", "storageTag", "=", "names", ".", "StorageTag", "{", "}", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "oldStorageName", ":=", "storageName", "(", "oldFilesystemTag", ",", "storageTag", ")", "\n\n", "lhs", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "oldMountPoint", ",", "oldStorageName", ")", "\n", "rhs", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "newMountPoint", ",", "newStorageName", ")", "\n", "if", "swapOrder", "{", "lhs", ",", "rhs", "=", "rhs", ",", "lhs", "\n", "}", "\n", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "lhs", ",", "rhs", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// validateFilesystemMountPoints validates the mount points of filesystems // being attached to the specified machine. If there are any mount point // path conflicts, an error will be returned.
[ "validateFilesystemMountPoints", "validates", "the", "mount", "points", "of", "filesystems", "being", "attached", "to", "the", "specified", "machine", ".", "If", "there", "are", "any", "mount", "point", "path", "conflicts", "an", "error", "will", "be", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1409-L1496
153,656
juju/juju
state/filesystem.go
AllFilesystems
func (sb *storageBackend) AllFilesystems() ([]Filesystem, error) { filesystems, err := sb.filesystems(nil) if err != nil { return nil, errors.Annotate(err, "cannot get filesystems") } return filesystemsToInterfaces(filesystems), nil }
go
func (sb *storageBackend) AllFilesystems() ([]Filesystem, error) { filesystems, err := sb.filesystems(nil) if err != nil { return nil, errors.Annotate(err, "cannot get filesystems") } return filesystemsToInterfaces(filesystems), nil }
[ "func", "(", "sb", "*", "storageBackend", ")", "AllFilesystems", "(", ")", "(", "[", "]", "Filesystem", ",", "error", ")", "{", "filesystems", ",", "err", ":=", "sb", ".", "filesystems", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "filesystemsToInterfaces", "(", "filesystems", ")", ",", "nil", "\n", "}" ]
// AllFilesystems returns all Filesystems for this state.
[ "AllFilesystems", "returns", "all", "Filesystems", "for", "this", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/filesystem.go#L1499-L1505
153,657
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
NewMockContext
func NewMockContext(ctrl *gomock.Controller) *MockContext { mock := &MockContext{ctrl: ctrl} mock.recorder = &MockContextMockRecorder{mock} return mock }
go
func NewMockContext(ctrl *gomock.Controller) *MockContext { mock := &MockContext{ctrl: ctrl} mock.recorder = &MockContextMockRecorder{mock} return mock }
[ "func", "NewMockContext", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockContext", "{", "mock", ":=", "&", "MockContext", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockContextMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockContext creates a new mock instance
[ "NewMockContext", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L31-L35
153,658
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
Auth
func (m *MockContext) Auth() facade.Authorizer { ret := m.ctrl.Call(m, "Auth") ret0, _ := ret[0].(facade.Authorizer) return ret0 }
go
func (m *MockContext) Auth() facade.Authorizer { ret := m.ctrl.Call(m, "Auth") ret0, _ := ret[0].(facade.Authorizer) return ret0 }
[ "func", "(", "m", "*", "MockContext", ")", "Auth", "(", ")", "facade", ".", "Authorizer", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "facade", ".", "Authorizer", ")", "\n", "return", "ret0", "\n", "}" ]
// Auth mocks base method
[ "Auth", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L43-L47
153,659
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
Hub
func (m *MockContext) Hub() facade.Hub { ret := m.ctrl.Call(m, "Hub") ret0, _ := ret[0].(facade.Hub) return ret0 }
go
func (m *MockContext) Hub() facade.Hub { ret := m.ctrl.Call(m, "Hub") ret0, _ := ret[0].(facade.Hub) return ret0 }
[ "func", "(", "m", "*", "MockContext", ")", "Hub", "(", ")", "facade", ".", "Hub", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "facade", ".", "Hub", ")", "\n", "return", "ret0", "\n", "}" ]
// Hub mocks base method
[ "Hub", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L77-L81
153,660
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
LeadershipChecker
func (m *MockContext) LeadershipChecker() (leadership.Checker, error) { ret := m.ctrl.Call(m, "LeadershipChecker") ret0, _ := ret[0].(leadership.Checker) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockContext) LeadershipChecker() (leadership.Checker, error) { ret := m.ctrl.Call(m, "LeadershipChecker") ret0, _ := ret[0].(leadership.Checker) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockContext", ")", "LeadershipChecker", "(", ")", "(", "leadership", ".", "Checker", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "leadership", ".", "Checker", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// LeadershipChecker mocks base method
[ "LeadershipChecker", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L101-L106
153,661
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
LeadershipClaimer
func (m *MockContext) LeadershipClaimer(arg0 string) (leadership.Claimer, error) { ret := m.ctrl.Call(m, "LeadershipClaimer", arg0) ret0, _ := ret[0].(leadership.Claimer) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockContext) LeadershipClaimer(arg0 string) (leadership.Claimer, error) { ret := m.ctrl.Call(m, "LeadershipClaimer", arg0) ret0, _ := ret[0].(leadership.Claimer) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockContext", ")", "LeadershipClaimer", "(", "arg0", "string", ")", "(", "leadership", ".", "Claimer", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "leadership", ".", "Claimer", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// LeadershipClaimer mocks base method
[ "LeadershipClaimer", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L114-L119
153,662
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
LeadershipPinner
func (m *MockContext) LeadershipPinner(arg0 string) (leadership.Pinner, error) { ret := m.ctrl.Call(m, "LeadershipPinner", arg0) ret0, _ := ret[0].(leadership.Pinner) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockContext) LeadershipPinner(arg0 string) (leadership.Pinner, error) { ret := m.ctrl.Call(m, "LeadershipPinner", arg0) ret0, _ := ret[0].(leadership.Pinner) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockContext", ")", "LeadershipPinner", "(", "arg0", "string", ")", "(", "leadership", ".", "Pinner", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "leadership", ".", "Pinner", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// LeadershipPinner mocks base method
[ "LeadershipPinner", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L127-L132
153,663
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
LeadershipReader
func (m *MockContext) LeadershipReader(arg0 string) (leadership.Reader, error) { ret := m.ctrl.Call(m, "LeadershipReader", arg0) ret0, _ := ret[0].(leadership.Reader) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockContext) LeadershipReader(arg0 string) (leadership.Reader, error) { ret := m.ctrl.Call(m, "LeadershipReader", arg0) ret0, _ := ret[0].(leadership.Reader) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockContext", ")", "LeadershipReader", "(", "arg0", "string", ")", "(", "leadership", ".", "Reader", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "leadership", ".", "Reader", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// LeadershipReader mocks base method
[ "LeadershipReader", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L140-L145
153,664
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
Presence
func (m *MockContext) Presence() facade.Presence { ret := m.ctrl.Call(m, "Presence") ret0, _ := ret[0].(facade.Presence) return ret0 }
go
func (m *MockContext) Presence() facade.Presence { ret := m.ctrl.Call(m, "Presence") ret0, _ := ret[0].(facade.Presence) return ret0 }
[ "func", "(", "m", "*", "MockContext", ")", "Presence", "(", ")", "facade", ".", "Presence", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "facade", ".", "Presence", ")", "\n", "return", "ret0", "\n", "}" ]
// Presence mocks base method
[ "Presence", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L153-L157
153,665
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
Resources
func (m *MockContext) Resources() facade.Resources { ret := m.ctrl.Call(m, "Resources") ret0, _ := ret[0].(facade.Resources) return ret0 }
go
func (m *MockContext) Resources() facade.Resources { ret := m.ctrl.Call(m, "Resources") ret0, _ := ret[0].(facade.Resources) return ret0 }
[ "func", "(", "m", "*", "MockContext", ")", "Resources", "(", ")", "facade", ".", "Resources", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "facade", ".", "Resources", ")", "\n", "return", "ret0", "\n", "}" ]
// Resources mocks base method
[ "Resources", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L165-L169
153,666
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
SingularClaimer
func (m *MockContext) SingularClaimer() (lease.Claimer, error) { ret := m.ctrl.Call(m, "SingularClaimer") ret0, _ := ret[0].(lease.Claimer) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockContext) SingularClaimer() (lease.Claimer, error) { ret := m.ctrl.Call(m, "SingularClaimer") ret0, _ := ret[0].(lease.Claimer) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockContext", ")", "SingularClaimer", "(", ")", "(", "lease", ".", "Claimer", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "lease", ".", "Claimer", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// SingularClaimer mocks base method
[ "SingularClaimer", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L177-L182
153,667
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
State
func (m *MockContext) State() *state.State { ret := m.ctrl.Call(m, "State") ret0, _ := ret[0].(*state.State) return ret0 }
go
func (m *MockContext) State() *state.State { ret := m.ctrl.Call(m, "State") ret0, _ := ret[0].(*state.State) return ret0 }
[ "func", "(", "m", "*", "MockContext", ")", "State", "(", ")", "*", "state", ".", "State", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "*", "state", ".", "State", ")", "\n", "return", "ret0", "\n", "}" ]
// State mocks base method
[ "State", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L190-L194
153,668
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
StatePool
func (m *MockContext) StatePool() *state.StatePool { ret := m.ctrl.Call(m, "StatePool") ret0, _ := ret[0].(*state.StatePool) return ret0 }
go
func (m *MockContext) StatePool() *state.StatePool { ret := m.ctrl.Call(m, "StatePool") ret0, _ := ret[0].(*state.StatePool) return ret0 }
[ "func", "(", "m", "*", "MockContext", ")", "StatePool", "(", ")", "*", "state", ".", "StatePool", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "*", "state", ".", "StatePool", ")", "\n", "return", "ret0", "\n", "}" ]
// StatePool mocks base method
[ "StatePool", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L202-L206
153,669
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
NewMockResources
func NewMockResources(ctrl *gomock.Controller) *MockResources { mock := &MockResources{ctrl: ctrl} mock.recorder = &MockResourcesMockRecorder{mock} return mock }
go
func NewMockResources(ctrl *gomock.Controller) *MockResources { mock := &MockResources{ctrl: ctrl} mock.recorder = &MockResourcesMockRecorder{mock} return mock }
[ "func", "NewMockResources", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockResources", "{", "mock", ":=", "&", "MockResources", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockResourcesMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockResources creates a new mock instance
[ "NewMockResources", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L225-L229
153,670
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
NewMockAuthorizer
func NewMockAuthorizer(ctrl *gomock.Controller) *MockAuthorizer { mock := &MockAuthorizer{ctrl: ctrl} mock.recorder = &MockAuthorizerMockRecorder{mock} return mock }
go
func NewMockAuthorizer(ctrl *gomock.Controller) *MockAuthorizer { mock := &MockAuthorizer{ctrl: ctrl} mock.recorder = &MockAuthorizerMockRecorder{mock} return mock }
[ "func", "NewMockAuthorizer", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockAuthorizer", "{", "mock", ":=", "&", "MockAuthorizer", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockAuthorizerMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockAuthorizer creates a new mock instance
[ "NewMockAuthorizer", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L284-L288
153,671
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
AuthController
func (m *MockAuthorizer) AuthController() bool { ret := m.ctrl.Call(m, "AuthController") ret0, _ := ret[0].(bool) return ret0 }
go
func (m *MockAuthorizer) AuthController() bool { ret := m.ctrl.Call(m, "AuthController") ret0, _ := ret[0].(bool) return ret0 }
[ "func", "(", "m", "*", "MockAuthorizer", ")", "AuthController", "(", ")", "bool", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "bool", ")", "\n", "return", "ret0", "\n", "}" ]
// AuthController mocks base method
[ "AuthController", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L320-L324
153,672
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
AuthController
func (mr *MockAuthorizerMockRecorder) AuthController() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthController", reflect.TypeOf((*MockAuthorizer)(nil).AuthController)) }
go
func (mr *MockAuthorizerMockRecorder) AuthController() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthController", reflect.TypeOf((*MockAuthorizer)(nil).AuthController)) }
[ "func", "(", "mr", "*", "MockAuthorizerMockRecorder", ")", "AuthController", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockAuthorizer", ")", "(", "nil", ")", ".", "AuthController", ")", ")", "\n", "}" ]
// AuthController indicates an expected call of AuthController
[ "AuthController", "indicates", "an", "expected", "call", "of", "AuthController" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L327-L329
153,673
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
AuthOwner
func (m *MockAuthorizer) AuthOwner(arg0 names_v2.Tag) bool { ret := m.ctrl.Call(m, "AuthOwner", arg0) ret0, _ := ret[0].(bool) return ret0 }
go
func (m *MockAuthorizer) AuthOwner(arg0 names_v2.Tag) bool { ret := m.ctrl.Call(m, "AuthOwner", arg0) ret0, _ := ret[0].(bool) return ret0 }
[ "func", "(", "m", "*", "MockAuthorizer", ")", "AuthOwner", "(", "arg0", "names_v2", ".", "Tag", ")", "bool", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "bool", ")", "\n", "return", "ret0", "\n", "}" ]
// AuthOwner mocks base method
[ "AuthOwner", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L344-L348
153,674
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
ConnectedModel
func (m *MockAuthorizer) ConnectedModel() string { ret := m.ctrl.Call(m, "ConnectedModel") ret0, _ := ret[0].(string) return ret0 }
go
func (m *MockAuthorizer) ConnectedModel() string { ret := m.ctrl.Call(m, "ConnectedModel") ret0, _ := ret[0].(string) return ret0 }
[ "func", "(", "m", "*", "MockAuthorizer", ")", "ConnectedModel", "(", ")", "string", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "string", ")", "\n", "return", "ret0", "\n", "}" ]
// ConnectedModel mocks base method
[ "ConnectedModel", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L368-L372
153,675
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
GetAuthTag
func (m *MockAuthorizer) GetAuthTag() names_v2.Tag { ret := m.ctrl.Call(m, "GetAuthTag") ret0, _ := ret[0].(names_v2.Tag) return ret0 }
go
func (m *MockAuthorizer) GetAuthTag() names_v2.Tag { ret := m.ctrl.Call(m, "GetAuthTag") ret0, _ := ret[0].(names_v2.Tag) return ret0 }
[ "func", "(", "m", "*", "MockAuthorizer", ")", "GetAuthTag", "(", ")", "names_v2", ".", "Tag", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "names_v2", ".", "Tag", ")", "\n", "return", "ret0", "\n", "}" ]
// GetAuthTag mocks base method
[ "GetAuthTag", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L380-L384
153,676
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
HasPermission
func (m *MockAuthorizer) HasPermission(arg0 permission.Access, arg1 names_v2.Tag) (bool, error) { ret := m.ctrl.Call(m, "HasPermission", arg0, arg1) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockAuthorizer) HasPermission(arg0 permission.Access, arg1 names_v2.Tag) (bool, error) { ret := m.ctrl.Call(m, "HasPermission", arg0, arg1) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockAuthorizer", ")", "HasPermission", "(", "arg0", "permission", ".", "Access", ",", "arg1", "names_v2", ".", "Tag", ")", "(", "bool", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "bool", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// HasPermission mocks base method
[ "HasPermission", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L392-L397
153,677
juju/juju
apiserver/facades/agent/instancemutater/mocks/facade_mock.go
HasPermission
func (mr *MockAuthorizerMockRecorder) HasPermission(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasPermission", reflect.TypeOf((*MockAuthorizer)(nil).HasPermission), arg0, arg1) }
go
func (mr *MockAuthorizerMockRecorder) HasPermission(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasPermission", reflect.TypeOf((*MockAuthorizer)(nil).HasPermission), arg0, arg1) }
[ "func", "(", "mr", "*", "MockAuthorizerMockRecorder", ")", "HasPermission", "(", "arg0", ",", "arg1", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockAuthorizer", ")", "(", "nil", ")", ".", "HasPermission", ")", ",", "arg0", ",", "arg1", ")", "\n", "}" ]
// HasPermission indicates an expected call of HasPermission
[ "HasPermission", "indicates", "an", "expected", "call", "of", "HasPermission" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/instancemutater/mocks/facade_mock.go#L400-L402
153,678
juju/juju
worker/uniter/runlistener.go
NewRunListener
func NewRunListener(cfg RunListenerConfig) (*RunListener, error) { if err := cfg.Validate(); err != nil { return nil, errors.Trace(err) } listener, err := sockets.Listen(cfg.SocketPath) if err != nil { return nil, errors.Trace(err) } runListener := &RunListener{ RunListenerConfig: cfg, listener: listener, server: rpc.NewServer(), closed: make(chan struct{}), closing: make(chan struct{}), } if err := runListener.server.Register(&JujuRunServer{runListener}); err != nil { return nil, errors.Trace(err) } go runListener.Run() return runListener, nil }
go
func NewRunListener(cfg RunListenerConfig) (*RunListener, error) { if err := cfg.Validate(); err != nil { return nil, errors.Trace(err) } listener, err := sockets.Listen(cfg.SocketPath) if err != nil { return nil, errors.Trace(err) } runListener := &RunListener{ RunListenerConfig: cfg, listener: listener, server: rpc.NewServer(), closed: make(chan struct{}), closing: make(chan struct{}), } if err := runListener.server.Register(&JujuRunServer{runListener}); err != nil { return nil, errors.Trace(err) } go runListener.Run() return runListener, nil }
[ "func", "NewRunListener", "(", "cfg", "RunListenerConfig", ")", "(", "*", "RunListener", ",", "error", ")", "{", "if", "err", ":=", "cfg", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "listener", ",", "err", ":=", "sockets", ".", "Listen", "(", "cfg", ".", "SocketPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "runListener", ":=", "&", "RunListener", "{", "RunListenerConfig", ":", "cfg", ",", "listener", ":", "listener", ",", "server", ":", "rpc", ".", "NewServer", "(", ")", ",", "closed", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "closing", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "if", "err", ":=", "runListener", ".", "server", ".", "Register", "(", "&", "JujuRunServer", "{", "runListener", "}", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "go", "runListener", ".", "Run", "(", ")", "\n", "return", "runListener", ",", "nil", "\n", "}" ]
// NewRunListener returns a new RunListener that is listening on given // socket or named pipe passed in. If a valid RunListener is returned, is // has the go routine running, and should be closed by the creator // when they are done with it.
[ "NewRunListener", "returns", "a", "new", "RunListener", "that", "is", "listening", "on", "given", "socket", "or", "named", "pipe", "passed", "in", ".", "If", "a", "valid", "RunListener", "is", "returned", "is", "has", "the", "go", "routine", "running", "and", "should", "be", "closed", "by", "the", "creator", "when", "they", "are", "done", "with", "it", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runlistener.go#L82-L102
153,679
juju/juju
worker/uniter/runlistener.go
Run
func (s *RunListener) Run() (err error) { logger.Debugf("juju-run listener running") var conn net.Conn for { conn, err = s.listener.Accept() if err != nil { break } s.wg.Add(1) go func(conn net.Conn) { s.server.ServeConn(conn) s.wg.Done() }(conn) } logger.Debugf("juju-run listener stopping") select { case <-s.closing: // Someone has called Close(), so it is overwhelmingly likely that // the error from Accept is a direct result of the Listener being // closed, and can therefore be safely ignored. err = nil default: } s.wg.Wait() close(s.closed) return }
go
func (s *RunListener) Run() (err error) { logger.Debugf("juju-run listener running") var conn net.Conn for { conn, err = s.listener.Accept() if err != nil { break } s.wg.Add(1) go func(conn net.Conn) { s.server.ServeConn(conn) s.wg.Done() }(conn) } logger.Debugf("juju-run listener stopping") select { case <-s.closing: // Someone has called Close(), so it is overwhelmingly likely that // the error from Accept is a direct result of the Listener being // closed, and can therefore be safely ignored. err = nil default: } s.wg.Wait() close(s.closed) return }
[ "func", "(", "s", "*", "RunListener", ")", "Run", "(", ")", "(", "err", "error", ")", "{", "logger", ".", "Debugf", "(", "\"", "\"", ")", "\n", "var", "conn", "net", ".", "Conn", "\n", "for", "{", "conn", ",", "err", "=", "s", ".", "listener", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "s", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", "conn", "net", ".", "Conn", ")", "{", "s", ".", "server", ".", "ServeConn", "(", "conn", ")", "\n", "s", ".", "wg", ".", "Done", "(", ")", "\n", "}", "(", "conn", ")", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ")", "\n", "select", "{", "case", "<-", "s", ".", "closing", ":", "// Someone has called Close(), so it is overwhelmingly likely that", "// the error from Accept is a direct result of the Listener being", "// closed, and can therefore be safely ignored.", "err", "=", "nil", "\n", "default", ":", "}", "\n", "s", ".", "wg", ".", "Wait", "(", ")", "\n", "close", "(", "s", ".", "closed", ")", "\n", "return", "\n", "}" ]
// Run accepts new connections until it encounters an error, or until Close is // called, and then blocks until all existing connections have been closed.
[ "Run", "accepts", "new", "connections", "until", "it", "encounters", "an", "error", "or", "until", "Close", "is", "called", "and", "then", "blocks", "until", "all", "existing", "connections", "have", "been", "closed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runlistener.go#L106-L132
153,680
juju/juju
worker/uniter/runlistener.go
RunCommands
func (r *JujuRunServer) RunCommands(args RunCommandsArgs, result *exec.ExecResponse) error { logger.Debugf("RunCommands: %+v", args) runResult, err := r.runner.RunCommands(args) if err != nil { return errors.Annotate(err, "r.runner.RunCommands") } *result = *runResult return err }
go
func (r *JujuRunServer) RunCommands(args RunCommandsArgs, result *exec.ExecResponse) error { logger.Debugf("RunCommands: %+v", args) runResult, err := r.runner.RunCommands(args) if err != nil { return errors.Annotate(err, "r.runner.RunCommands") } *result = *runResult return err }
[ "func", "(", "r", "*", "JujuRunServer", ")", "RunCommands", "(", "args", "RunCommandsArgs", ",", "result", "*", "exec", ".", "ExecResponse", ")", "error", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "args", ")", "\n", "runResult", ",", "err", ":=", "r", ".", "runner", ".", "RunCommands", "(", "args", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "*", "result", "=", "*", "runResult", "\n", "return", "err", "\n", "}" ]
// RunCommands delegates the actual running to the runner and populates the // response structure.
[ "RunCommands", "delegates", "the", "actual", "running", "to", "the", "runner", "and", "populates", "the", "response", "structure", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runlistener.go#L194-L202
153,681
juju/juju
worker/uniter/runlistener.go
NewChannelCommandRunner
func NewChannelCommandRunner(cfg ChannelCommandRunnerConfig) (*ChannelCommandRunner, error) { if err := cfg.Validate(); err != nil { return nil, errors.Trace(err) } return &ChannelCommandRunner{cfg}, nil }
go
func NewChannelCommandRunner(cfg ChannelCommandRunnerConfig) (*ChannelCommandRunner, error) { if err := cfg.Validate(); err != nil { return nil, errors.Trace(err) } return &ChannelCommandRunner{cfg}, nil }
[ "func", "NewChannelCommandRunner", "(", "cfg", "ChannelCommandRunnerConfig", ")", "(", "*", "ChannelCommandRunner", ",", "error", ")", "{", "if", "err", ":=", "cfg", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "&", "ChannelCommandRunner", "{", "cfg", "}", ",", "nil", "\n", "}" ]
// NewChannelCommandRunner returns a new ChannelCommandRunner with the // given configuration.
[ "NewChannelCommandRunner", "returns", "a", "new", "ChannelCommandRunner", "with", "the", "given", "configuration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runlistener.go#L239-L244
153,682
juju/juju
worker/uniter/runlistener.go
RunCommands
func (c *ChannelCommandRunner) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error) { type responseInfo struct { response *exec.ExecResponse err error } // NOTE(axw) the response channel must be synchronous so that the // response is received before the uniter resumes operation, and // potentially aborts. This prevents a race when rebooting. responseChan := make(chan responseInfo) responseFunc := func(response *exec.ExecResponse, err error) { select { case <-c.config.Abort: case responseChan <- responseInfo{response, err}: } } id := c.config.Commands.AddCommand( operation.CommandArgs{ Commands: args.Commands, RelationId: args.RelationId, RemoteUnitName: args.RemoteUnitName, ForceRemoteUnit: args.ForceRemoteUnit, }, responseFunc, ) select { case <-c.config.Abort: return nil, errCommandAborted case c.config.CommandChannel <- id: } select { case <-c.config.Abort: return nil, errCommandAborted case response := <-responseChan: return response.response, response.err } }
go
func (c *ChannelCommandRunner) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error) { type responseInfo struct { response *exec.ExecResponse err error } // NOTE(axw) the response channel must be synchronous so that the // response is received before the uniter resumes operation, and // potentially aborts. This prevents a race when rebooting. responseChan := make(chan responseInfo) responseFunc := func(response *exec.ExecResponse, err error) { select { case <-c.config.Abort: case responseChan <- responseInfo{response, err}: } } id := c.config.Commands.AddCommand( operation.CommandArgs{ Commands: args.Commands, RelationId: args.RelationId, RemoteUnitName: args.RemoteUnitName, ForceRemoteUnit: args.ForceRemoteUnit, }, responseFunc, ) select { case <-c.config.Abort: return nil, errCommandAborted case c.config.CommandChannel <- id: } select { case <-c.config.Abort: return nil, errCommandAborted case response := <-responseChan: return response.response, response.err } }
[ "func", "(", "c", "*", "ChannelCommandRunner", ")", "RunCommands", "(", "args", "RunCommandsArgs", ")", "(", "results", "*", "exec", ".", "ExecResponse", ",", "err", "error", ")", "{", "type", "responseInfo", "struct", "{", "response", "*", "exec", ".", "ExecResponse", "\n", "err", "error", "\n", "}", "\n\n", "// NOTE(axw) the response channel must be synchronous so that the", "// response is received before the uniter resumes operation, and", "// potentially aborts. This prevents a race when rebooting.", "responseChan", ":=", "make", "(", "chan", "responseInfo", ")", "\n", "responseFunc", ":=", "func", "(", "response", "*", "exec", ".", "ExecResponse", ",", "err", "error", ")", "{", "select", "{", "case", "<-", "c", ".", "config", ".", "Abort", ":", "case", "responseChan", "<-", "responseInfo", "{", "response", ",", "err", "}", ":", "}", "\n", "}", "\n\n", "id", ":=", "c", ".", "config", ".", "Commands", ".", "AddCommand", "(", "operation", ".", "CommandArgs", "{", "Commands", ":", "args", ".", "Commands", ",", "RelationId", ":", "args", ".", "RelationId", ",", "RemoteUnitName", ":", "args", ".", "RemoteUnitName", ",", "ForceRemoteUnit", ":", "args", ".", "ForceRemoteUnit", ",", "}", ",", "responseFunc", ",", ")", "\n", "select", "{", "case", "<-", "c", ".", "config", ".", "Abort", ":", "return", "nil", ",", "errCommandAborted", "\n", "case", "c", ".", "config", ".", "CommandChannel", "<-", "id", ":", "}", "\n\n", "select", "{", "case", "<-", "c", ".", "config", ".", "Abort", ":", "return", "nil", ",", "errCommandAborted", "\n", "case", "response", ":=", "<-", "responseChan", ":", "return", "response", ".", "response", ",", "response", ".", "err", "\n", "}", "\n", "}" ]
// RunCommands executes the supplied run commands by registering the // arguments in a runcommands.Commands, and then sending the returned // ID to a channel and waiting for a response callback.
[ "RunCommands", "executes", "the", "supplied", "run", "commands", "by", "registering", "the", "arguments", "in", "a", "runcommands", ".", "Commands", "and", "then", "sending", "the", "returned", "ID", "to", "a", "channel", "and", "waiting", "for", "a", "response", "callback", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runlistener.go#L249-L287
153,683
juju/juju
worker/uniter/runner/jujuc/leader-set.go
NewLeaderSetCommand
func NewLeaderSetCommand(ctx Context) (cmd.Command, error) { return &leaderSetCommand{ctx: ctx}, nil }
go
func NewLeaderSetCommand(ctx Context) (cmd.Command, error) { return &leaderSetCommand{ctx: ctx}, nil }
[ "func", "NewLeaderSetCommand", "(", "ctx", "Context", ")", "(", "cmd", ".", "Command", ",", "error", ")", "{", "return", "&", "leaderSetCommand", "{", "ctx", ":", "ctx", "}", ",", "nil", "\n", "}" ]
// NewLeaderSetCommand returns a new leaderSetCommand with the given context.
[ "NewLeaderSetCommand", "returns", "a", "new", "leaderSetCommand", "with", "the", "given", "context", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/jujuc/leader-set.go#L22-L24
153,684
juju/juju
apiserver/common/action.go
ParamsActionExecutionResultsToStateActionResults
func ParamsActionExecutionResultsToStateActionResults(arg params.ActionExecutionResult) (state.ActionResults, error) { var status state.ActionStatus switch arg.Status { case params.ActionCancelled: status = state.ActionCancelled case params.ActionCompleted: status = state.ActionCompleted case params.ActionFailed: status = state.ActionFailed case params.ActionPending: status = state.ActionPending default: return state.ActionResults{}, errors.Errorf("unrecognized action status '%s'", arg.Status) } return state.ActionResults{ Status: status, Results: arg.Results, Message: arg.Message, }, nil }
go
func ParamsActionExecutionResultsToStateActionResults(arg params.ActionExecutionResult) (state.ActionResults, error) { var status state.ActionStatus switch arg.Status { case params.ActionCancelled: status = state.ActionCancelled case params.ActionCompleted: status = state.ActionCompleted case params.ActionFailed: status = state.ActionFailed case params.ActionPending: status = state.ActionPending default: return state.ActionResults{}, errors.Errorf("unrecognized action status '%s'", arg.Status) } return state.ActionResults{ Status: status, Results: arg.Results, Message: arg.Message, }, nil }
[ "func", "ParamsActionExecutionResultsToStateActionResults", "(", "arg", "params", ".", "ActionExecutionResult", ")", "(", "state", ".", "ActionResults", ",", "error", ")", "{", "var", "status", "state", ".", "ActionStatus", "\n", "switch", "arg", ".", "Status", "{", "case", "params", ".", "ActionCancelled", ":", "status", "=", "state", ".", "ActionCancelled", "\n", "case", "params", ".", "ActionCompleted", ":", "status", "=", "state", ".", "ActionCompleted", "\n", "case", "params", ".", "ActionFailed", ":", "status", "=", "state", ".", "ActionFailed", "\n", "case", "params", ".", "ActionPending", ":", "status", "=", "state", ".", "ActionPending", "\n", "default", ":", "return", "state", ".", "ActionResults", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "arg", ".", "Status", ")", "\n", "}", "\n", "return", "state", ".", "ActionResults", "{", "Status", ":", "status", ",", "Results", ":", "arg", ".", "Results", ",", "Message", ":", "arg", ".", "Message", ",", "}", ",", "nil", "\n", "}" ]
// ParamsActionExecutionResultsToStateActionResults does exactly what // the name implies.
[ "ParamsActionExecutionResultsToStateActionResults", "does", "exactly", "what", "the", "name", "implies", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L19-L38
153,685
juju/juju
apiserver/common/action.go
TagToActionReceiverFn
func TagToActionReceiverFn(findEntity func(names.Tag) (state.Entity, error)) func(tag string) (state.ActionReceiver, error) { return func(tag string) (state.ActionReceiver, error) { receiverTag, err := names.ParseTag(tag) if err != nil { return nil, errors.NotValidf("%s", tag) } entity, err := findEntity(receiverTag) if err != nil { return nil, errors.NotFoundf("%s", receiverTag) } receiver, ok := entity.(state.ActionReceiver) if !ok { return nil, errors.NotImplementedf("action receiver interface on entity %s", tag) } return receiver, nil } }
go
func TagToActionReceiverFn(findEntity func(names.Tag) (state.Entity, error)) func(tag string) (state.ActionReceiver, error) { return func(tag string) (state.ActionReceiver, error) { receiverTag, err := names.ParseTag(tag) if err != nil { return nil, errors.NotValidf("%s", tag) } entity, err := findEntity(receiverTag) if err != nil { return nil, errors.NotFoundf("%s", receiverTag) } receiver, ok := entity.(state.ActionReceiver) if !ok { return nil, errors.NotImplementedf("action receiver interface on entity %s", tag) } return receiver, nil } }
[ "func", "TagToActionReceiverFn", "(", "findEntity", "func", "(", "names", ".", "Tag", ")", "(", "state", ".", "Entity", ",", "error", ")", ")", "func", "(", "tag", "string", ")", "(", "state", ".", "ActionReceiver", ",", "error", ")", "{", "return", "func", "(", "tag", "string", ")", "(", "state", ".", "ActionReceiver", ",", "error", ")", "{", "receiverTag", ",", "err", ":=", "names", ".", "ParseTag", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "tag", ")", "\n", "}", "\n", "entity", ",", "err", ":=", "findEntity", "(", "receiverTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "receiverTag", ")", "\n", "}", "\n", "receiver", ",", "ok", ":=", "entity", ".", "(", "state", ".", "ActionReceiver", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "NotImplementedf", "(", "\"", "\"", ",", "tag", ")", "\n", "}", "\n", "return", "receiver", ",", "nil", "\n", "}", "\n", "}" ]
// TagToActionReceiver takes a tag string and tries to convert it to an // ActionReceiver. It needs a findEntity function passed in that can search for the tags in state.
[ "TagToActionReceiver", "takes", "a", "tag", "string", "and", "tries", "to", "convert", "it", "to", "an", "ActionReceiver", ".", "It", "needs", "a", "findEntity", "function", "passed", "in", "that", "can", "search", "for", "the", "tags", "in", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L42-L58
153,686
juju/juju
apiserver/common/action.go
AuthAndActionFromTagFn
func AuthAndActionFromTagFn(canAccess AuthFunc, getActionByTag func(names.ActionTag) (state.Action, error)) func(string) (state.Action, error) { return func(tag string) (state.Action, error) { actionTag, err := names.ParseActionTag(tag) if err != nil { return nil, errors.Trace(err) } action, err := getActionByTag(actionTag) if err != nil { return nil, errors.Trace(err) } receiverTag, err := names.ActionReceiverTag(action.Receiver()) if err != nil { return nil, errors.Trace(err) } if !canAccess(receiverTag) { return nil, ErrPerm } return action, nil } }
go
func AuthAndActionFromTagFn(canAccess AuthFunc, getActionByTag func(names.ActionTag) (state.Action, error)) func(string) (state.Action, error) { return func(tag string) (state.Action, error) { actionTag, err := names.ParseActionTag(tag) if err != nil { return nil, errors.Trace(err) } action, err := getActionByTag(actionTag) if err != nil { return nil, errors.Trace(err) } receiverTag, err := names.ActionReceiverTag(action.Receiver()) if err != nil { return nil, errors.Trace(err) } if !canAccess(receiverTag) { return nil, ErrPerm } return action, nil } }
[ "func", "AuthAndActionFromTagFn", "(", "canAccess", "AuthFunc", ",", "getActionByTag", "func", "(", "names", ".", "ActionTag", ")", "(", "state", ".", "Action", ",", "error", ")", ")", "func", "(", "string", ")", "(", "state", ".", "Action", ",", "error", ")", "{", "return", "func", "(", "tag", "string", ")", "(", "state", ".", "Action", ",", "error", ")", "{", "actionTag", ",", "err", ":=", "names", ".", "ParseActionTag", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "action", ",", "err", ":=", "getActionByTag", "(", "actionTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "receiverTag", ",", "err", ":=", "names", ".", "ActionReceiverTag", "(", "action", ".", "Receiver", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "canAccess", "(", "receiverTag", ")", "{", "return", "nil", ",", "ErrPerm", "\n", "}", "\n", "return", "action", ",", "nil", "\n", "}", "\n", "}" ]
// AuthAndActionFromTagFn takes in an authorizer function and a function that can fetch action by tags from state // and returns a function that can fetch an action from state by id and check the authorization.
[ "AuthAndActionFromTagFn", "takes", "in", "an", "authorizer", "function", "and", "a", "function", "that", "can", "fetch", "action", "by", "tags", "from", "state", "and", "returns", "a", "function", "that", "can", "fetch", "an", "action", "from", "state", "by", "id", "and", "check", "the", "authorization", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L62-L81
153,687
juju/juju
apiserver/common/action.go
BeginActions
func BeginActions(args params.Entities, actionFn func(string) (state.Action, error)) params.ErrorResults { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Entities))} for i, arg := range args.Entities { action, err := actionFn(arg.Tag) if err != nil { results.Results[i].Error = ServerError(err) continue } _, err = action.Begin() if err != nil { results.Results[i].Error = ServerError(err) continue } } return results }
go
func BeginActions(args params.Entities, actionFn func(string) (state.Action, error)) params.ErrorResults { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Entities))} for i, arg := range args.Entities { action, err := actionFn(arg.Tag) if err != nil { results.Results[i].Error = ServerError(err) continue } _, err = action.Begin() if err != nil { results.Results[i].Error = ServerError(err) continue } } return results }
[ "func", "BeginActions", "(", "args", "params", ".", "Entities", ",", "actionFn", "func", "(", "string", ")", "(", "state", ".", "Action", ",", "error", ")", ")", "params", ".", "ErrorResults", "{", "results", ":=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Entities", ")", ")", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Entities", "{", "action", ",", "err", ":=", "actionFn", "(", "arg", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n\n", "_", ",", "err", "=", "action", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n\n", "return", "results", "\n", "}" ]
// BeginActions calls begin on every action passed in through args. // It's a helper function currently used by the uniter and by machineactions // It needs an actionFn that can fetch an action from state using it's id, that's usually created by AuthAndActionFromTagFn
[ "BeginActions", "calls", "begin", "on", "every", "action", "passed", "in", "through", "args", ".", "It", "s", "a", "helper", "function", "currently", "used", "by", "the", "uniter", "and", "by", "machineactions", "It", "needs", "an", "actionFn", "that", "can", "fetch", "an", "action", "from", "state", "using", "it", "s", "id", "that", "s", "usually", "created", "by", "AuthAndActionFromTagFn" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L86-L104
153,688
juju/juju
apiserver/common/action.go
FinishActions
func FinishActions(args params.ActionExecutionResults, actionFn func(string) (state.Action, error)) params.ErrorResults { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Results))} for i, arg := range args.Results { action, err := actionFn(arg.ActionTag) if err != nil { results.Results[i].Error = ServerError(err) continue } actionResults, err := ParamsActionExecutionResultsToStateActionResults(arg) if err != nil { results.Results[i].Error = ServerError(err) continue } _, err = action.Finish(actionResults) if err != nil { results.Results[i].Error = ServerError(err) continue } } return results }
go
func FinishActions(args params.ActionExecutionResults, actionFn func(string) (state.Action, error)) params.ErrorResults { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Results))} for i, arg := range args.Results { action, err := actionFn(arg.ActionTag) if err != nil { results.Results[i].Error = ServerError(err) continue } actionResults, err := ParamsActionExecutionResultsToStateActionResults(arg) if err != nil { results.Results[i].Error = ServerError(err) continue } _, err = action.Finish(actionResults) if err != nil { results.Results[i].Error = ServerError(err) continue } } return results }
[ "func", "FinishActions", "(", "args", "params", ".", "ActionExecutionResults", ",", "actionFn", "func", "(", "string", ")", "(", "state", ".", "Action", ",", "error", ")", ")", "params", ".", "ErrorResults", "{", "results", ":=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Results", ")", ")", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Results", "{", "action", ",", "err", ":=", "actionFn", "(", "arg", ".", "ActionTag", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "actionResults", ",", "err", ":=", "ParamsActionExecutionResultsToStateActionResults", "(", "arg", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n\n", "_", ",", "err", "=", "action", ".", "Finish", "(", "actionResults", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n\n", "return", "results", "\n", "}" ]
// FinishActions saves the result of a completed Action. // It's a helper function currently used by the uniter and by machineactions // It needs an actionFn that can fetch an action from state using it's id that's usually created by AuthAndActionFromTagFn
[ "FinishActions", "saves", "the", "result", "of", "a", "completed", "Action", ".", "It", "s", "a", "helper", "function", "currently", "used", "by", "the", "uniter", "and", "by", "machineactions", "It", "needs", "an", "actionFn", "that", "can", "fetch", "an", "action", "from", "state", "using", "it", "s", "id", "that", "s", "usually", "created", "by", "AuthAndActionFromTagFn" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L109-L132
153,689
juju/juju
apiserver/common/action.go
Actions
func Actions(args params.Entities, actionFn func(string) (state.Action, error)) params.ActionResults { results := params.ActionResults{ Results: make([]params.ActionResult, len(args.Entities)), } for i, arg := range args.Entities { action, err := actionFn(arg.Tag) if err != nil { results.Results[i].Error = ServerError(err) continue } if action.Status() != state.ActionPending { results.Results[i].Error = ServerError(ErrActionNotAvailable) continue } results.Results[i].Action = &params.Action{ Name: action.Name(), Parameters: action.Parameters(), } } return results }
go
func Actions(args params.Entities, actionFn func(string) (state.Action, error)) params.ActionResults { results := params.ActionResults{ Results: make([]params.ActionResult, len(args.Entities)), } for i, arg := range args.Entities { action, err := actionFn(arg.Tag) if err != nil { results.Results[i].Error = ServerError(err) continue } if action.Status() != state.ActionPending { results.Results[i].Error = ServerError(ErrActionNotAvailable) continue } results.Results[i].Action = &params.Action{ Name: action.Name(), Parameters: action.Parameters(), } } return results }
[ "func", "Actions", "(", "args", "params", ".", "Entities", ",", "actionFn", "func", "(", "string", ")", "(", "state", ".", "Action", ",", "error", ")", ")", "params", ".", "ActionResults", "{", "results", ":=", "params", ".", "ActionResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ActionResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Entities", "{", "action", ",", "err", ":=", "actionFn", "(", "arg", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "action", ".", "Status", "(", ")", "!=", "state", ".", "ActionPending", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "ErrActionNotAvailable", ")", "\n", "continue", "\n", "}", "\n", "results", ".", "Results", "[", "i", "]", ".", "Action", "=", "&", "params", ".", "Action", "{", "Name", ":", "action", ".", "Name", "(", ")", ",", "Parameters", ":", "action", ".", "Parameters", "(", ")", ",", "}", "\n", "}", "\n\n", "return", "results", "\n", "}" ]
// Actions returns the Actions by Tags passed in and ensures that the receiver asking for // them is the same one that has the action. // It's a helper function currently used by the uniter and by machineactions. // It needs an actionFn that can fetch an action from state using it's id that's usually created by AuthAndActionFromTagFn
[ "Actions", "returns", "the", "Actions", "by", "Tags", "passed", "in", "and", "ensures", "that", "the", "receiver", "asking", "for", "them", "is", "the", "same", "one", "that", "has", "the", "action", ".", "It", "s", "a", "helper", "function", "currently", "used", "by", "the", "uniter", "and", "by", "machineactions", ".", "It", "needs", "an", "actionFn", "that", "can", "fetch", "an", "action", "from", "state", "using", "it", "s", "id", "that", "s", "usually", "created", "by", "AuthAndActionFromTagFn" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L138-L160
153,690
juju/juju
apiserver/common/action.go
WatchOneActionReceiverNotifications
func WatchOneActionReceiverNotifications(tagToActionReceiver func(tag string) (state.ActionReceiver, error), registerFunc func(r facade.Resource) string) func(names.Tag) (params.StringsWatchResult, error) { return func(tag names.Tag) (params.StringsWatchResult, error) { nothing := params.StringsWatchResult{} receiver, err := tagToActionReceiver(tag.String()) if err != nil { return nothing, err } watch := receiver.WatchActionNotifications() if changes, ok := <-watch.Changes(); ok { return params.StringsWatchResult{ StringsWatcherId: registerFunc(watch), Changes: changes, }, nil } return nothing, watcher.EnsureErr(watch) } }
go
func WatchOneActionReceiverNotifications(tagToActionReceiver func(tag string) (state.ActionReceiver, error), registerFunc func(r facade.Resource) string) func(names.Tag) (params.StringsWatchResult, error) { return func(tag names.Tag) (params.StringsWatchResult, error) { nothing := params.StringsWatchResult{} receiver, err := tagToActionReceiver(tag.String()) if err != nil { return nothing, err } watch := receiver.WatchActionNotifications() if changes, ok := <-watch.Changes(); ok { return params.StringsWatchResult{ StringsWatcherId: registerFunc(watch), Changes: changes, }, nil } return nothing, watcher.EnsureErr(watch) } }
[ "func", "WatchOneActionReceiverNotifications", "(", "tagToActionReceiver", "func", "(", "tag", "string", ")", "(", "state", ".", "ActionReceiver", ",", "error", ")", ",", "registerFunc", "func", "(", "r", "facade", ".", "Resource", ")", "string", ")", "func", "(", "names", ".", "Tag", ")", "(", "params", ".", "StringsWatchResult", ",", "error", ")", "{", "return", "func", "(", "tag", "names", ".", "Tag", ")", "(", "params", ".", "StringsWatchResult", ",", "error", ")", "{", "nothing", ":=", "params", ".", "StringsWatchResult", "{", "}", "\n", "receiver", ",", "err", ":=", "tagToActionReceiver", "(", "tag", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nothing", ",", "err", "\n", "}", "\n", "watch", ":=", "receiver", ".", "WatchActionNotifications", "(", ")", "\n\n", "if", "changes", ",", "ok", ":=", "<-", "watch", ".", "Changes", "(", ")", ";", "ok", "{", "return", "params", ".", "StringsWatchResult", "{", "StringsWatcherId", ":", "registerFunc", "(", "watch", ")", ",", "Changes", ":", "changes", ",", "}", ",", "nil", "\n", "}", "\n", "return", "nothing", ",", "watcher", ".", "EnsureErr", "(", "watch", ")", "\n", "}", "\n", "}" ]
// WatchOneActionReceiverNotifications to create a watcher for one receiver. // It needs a tagToActionReceiver function and a registerFunc to register // resources. // It's a helper function currently used by the uniter and by machineactions
[ "WatchOneActionReceiverNotifications", "to", "create", "a", "watcher", "for", "one", "receiver", ".", "It", "needs", "a", "tagToActionReceiver", "function", "and", "a", "registerFunc", "to", "register", "resources", ".", "It", "s", "a", "helper", "function", "currently", "used", "by", "the", "uniter", "and", "by", "machineactions" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L166-L183
153,691
juju/juju
apiserver/common/action.go
WatchActionNotifications
func WatchActionNotifications(args params.Entities, canAccess AuthFunc, watchOne func(names.Tag) (params.StringsWatchResult, error)) params.StringsWatchResults { result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } for i, entity := range args.Entities { tag, err := names.ActionReceiverFromTag(entity.Tag) if err != nil { result.Results[i].Error = ServerError(err) continue } err = ErrPerm if canAccess(tag) { result.Results[i], err = watchOne(tag) } result.Results[i].Error = ServerError(err) } return result }
go
func WatchActionNotifications(args params.Entities, canAccess AuthFunc, watchOne func(names.Tag) (params.StringsWatchResult, error)) params.StringsWatchResults { result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } for i, entity := range args.Entities { tag, err := names.ActionReceiverFromTag(entity.Tag) if err != nil { result.Results[i].Error = ServerError(err) continue } err = ErrPerm if canAccess(tag) { result.Results[i], err = watchOne(tag) } result.Results[i].Error = ServerError(err) } return result }
[ "func", "WatchActionNotifications", "(", "args", "params", ".", "Entities", ",", "canAccess", "AuthFunc", ",", "watchOne", "func", "(", "names", ".", "Tag", ")", "(", "params", ".", "StringsWatchResult", ",", "error", ")", ")", "params", ".", "StringsWatchResults", "{", "result", ":=", "params", ".", "StringsWatchResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "StringsWatchResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ActionReceiverFromTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "err", "=", "ErrPerm", "\n", "if", "canAccess", "(", "tag", ")", "{", "result", ".", "Results", "[", "i", "]", ",", "err", "=", "watchOne", "(", "tag", ")", "\n", "}", "\n", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "}", "\n\n", "return", "result", "\n", "}" ]
// WatchActionNotifications returns a StringsWatcher for observing incoming actions towards an actionreceiver. // It's a helper function currently used by the uniter and by machineactions // canAccess is passed in by the respective caller to provide authorization. // watchOne is usually a function created by WatchOneActionReceiverNotifications
[ "WatchActionNotifications", "returns", "a", "StringsWatcher", "for", "observing", "incoming", "actions", "towards", "an", "actionreceiver", ".", "It", "s", "a", "helper", "function", "currently", "used", "by", "the", "uniter", "and", "by", "machineactions", "canAccess", "is", "passed", "in", "by", "the", "respective", "caller", "to", "provide", "authorization", ".", "watchOne", "is", "usually", "a", "function", "created", "by", "WatchOneActionReceiverNotifications" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L189-L208
153,692
juju/juju
apiserver/common/action.go
ConvertActions
func ConvertActions(ar state.ActionReceiver, fn GetActionsFn) ([]params.ActionResult, error) { items := []params.ActionResult{} actions, err := fn() if err != nil { return items, err } for _, action := range actions { if action == nil { continue } items = append(items, MakeActionResult(ar.Tag(), action)) } return items, nil }
go
func ConvertActions(ar state.ActionReceiver, fn GetActionsFn) ([]params.ActionResult, error) { items := []params.ActionResult{} actions, err := fn() if err != nil { return items, err } for _, action := range actions { if action == nil { continue } items = append(items, MakeActionResult(ar.Tag(), action)) } return items, nil }
[ "func", "ConvertActions", "(", "ar", "state", ".", "ActionReceiver", ",", "fn", "GetActionsFn", ")", "(", "[", "]", "params", ".", "ActionResult", ",", "error", ")", "{", "items", ":=", "[", "]", "params", ".", "ActionResult", "{", "}", "\n", "actions", ",", "err", ":=", "fn", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "items", ",", "err", "\n", "}", "\n", "for", "_", ",", "action", ":=", "range", "actions", "{", "if", "action", "==", "nil", "{", "continue", "\n", "}", "\n", "items", "=", "append", "(", "items", ",", "MakeActionResult", "(", "ar", ".", "Tag", "(", ")", ",", "action", ")", ")", "\n", "}", "\n", "return", "items", ",", "nil", "\n", "}" ]
// ConvertActions takes a generic getActionsFn to obtain a slice // of state.Action and then converts them to the API slice of // params.ActionResult.
[ "ConvertActions", "takes", "a", "generic", "getActionsFn", "to", "obtain", "a", "slice", "of", "state", ".", "Action", "and", "then", "converts", "them", "to", "the", "API", "slice", "of", "params", ".", "ActionResult", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L217-L230
153,693
juju/juju
apiserver/common/action.go
MakeActionResult
func MakeActionResult(actionReceiverTag names.Tag, action state.Action) params.ActionResult { output, message := action.Results() return params.ActionResult{ Action: &params.Action{ Receiver: actionReceiverTag.String(), Tag: action.ActionTag().String(), Name: action.Name(), Parameters: action.Parameters(), }, Status: string(action.Status()), Message: message, Output: output, Enqueued: action.Enqueued(), Started: action.Started(), Completed: action.Completed(), } }
go
func MakeActionResult(actionReceiverTag names.Tag, action state.Action) params.ActionResult { output, message := action.Results() return params.ActionResult{ Action: &params.Action{ Receiver: actionReceiverTag.String(), Tag: action.ActionTag().String(), Name: action.Name(), Parameters: action.Parameters(), }, Status: string(action.Status()), Message: message, Output: output, Enqueued: action.Enqueued(), Started: action.Started(), Completed: action.Completed(), } }
[ "func", "MakeActionResult", "(", "actionReceiverTag", "names", ".", "Tag", ",", "action", "state", ".", "Action", ")", "params", ".", "ActionResult", "{", "output", ",", "message", ":=", "action", ".", "Results", "(", ")", "\n", "return", "params", ".", "ActionResult", "{", "Action", ":", "&", "params", ".", "Action", "{", "Receiver", ":", "actionReceiverTag", ".", "String", "(", ")", ",", "Tag", ":", "action", ".", "ActionTag", "(", ")", ".", "String", "(", ")", ",", "Name", ":", "action", ".", "Name", "(", ")", ",", "Parameters", ":", "action", ".", "Parameters", "(", ")", ",", "}", ",", "Status", ":", "string", "(", "action", ".", "Status", "(", ")", ")", ",", "Message", ":", "message", ",", "Output", ":", "output", ",", "Enqueued", ":", "action", ".", "Enqueued", "(", ")", ",", "Started", ":", "action", ".", "Started", "(", ")", ",", "Completed", ":", "action", ".", "Completed", "(", ")", ",", "}", "\n", "}" ]
// MakeActionResult does the actual type conversion from state.Action // to params.ActionResult.
[ "MakeActionResult", "does", "the", "actual", "type", "conversion", "from", "state", ".", "Action", "to", "params", ".", "ActionResult", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/action.go#L234-L250
153,694
juju/juju
cmd/juju/firewall/listrules.go
NewListFirewallRulesCommand
func NewListFirewallRulesCommand() cmd.Command { cmd := &listFirewallRulesCommand{} cmd.newAPIFunc = func() (ListFirewallRulesAPI, error) { root, err := cmd.NewAPIRoot() if err != nil { return nil, errors.Trace(err) } return firewallrules.NewClient(root), nil } return modelcmd.Wrap(cmd) }
go
func NewListFirewallRulesCommand() cmd.Command { cmd := &listFirewallRulesCommand{} cmd.newAPIFunc = func() (ListFirewallRulesAPI, error) { root, err := cmd.NewAPIRoot() if err != nil { return nil, errors.Trace(err) } return firewallrules.NewClient(root), nil } return modelcmd.Wrap(cmd) }
[ "func", "NewListFirewallRulesCommand", "(", ")", "cmd", ".", "Command", "{", "cmd", ":=", "&", "listFirewallRulesCommand", "{", "}", "\n", "cmd", ".", "newAPIFunc", "=", "func", "(", ")", "(", "ListFirewallRulesAPI", ",", "error", ")", "{", "root", ",", "err", ":=", "cmd", ".", "NewAPIRoot", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "firewallrules", ".", "NewClient", "(", "root", ")", ",", "nil", "\n\n", "}", "\n", "return", "modelcmd", ".", "Wrap", "(", "cmd", ")", "\n", "}" ]
// NewListFirewallRulesCommand returns a command to list firewall rules.
[ "NewListFirewallRulesCommand", "returns", "a", "command", "to", "list", "firewall", "rules", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/firewall/listrules.go#L32-L43
153,695
juju/juju
state/refcounts_ns.go
LazyCreateOp
func (ns nsRefcounts_) LazyCreateOp(coll mongo.Collection, key string) (txn.Op, bool, error) { if exists, err := ns.exists(coll, key); err != nil { return txn.Op{}, false, errors.Trace(err) } else if exists { return txn.Op{}, false, nil } return ns.JustCreateOp(coll.Name(), key, 0), true, nil }
go
func (ns nsRefcounts_) LazyCreateOp(coll mongo.Collection, key string) (txn.Op, bool, error) { if exists, err := ns.exists(coll, key); err != nil { return txn.Op{}, false, errors.Trace(err) } else if exists { return txn.Op{}, false, nil } return ns.JustCreateOp(coll.Name(), key, 0), true, nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "LazyCreateOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ")", "(", "txn", ".", "Op", ",", "bool", ",", "error", ")", "{", "if", "exists", ",", "err", ":=", "ns", ".", "exists", "(", "coll", ",", "key", ")", ";", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "false", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "exists", "{", "return", "txn", ".", "Op", "{", "}", ",", "false", ",", "nil", "\n", "}", "\n", "return", "ns", ".", "JustCreateOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "0", ")", ",", "true", ",", "nil", "\n", "}" ]
// LazyCreateOp returns a txn.Op that creates a refcount document; or // false if the document already exists.
[ "LazyCreateOp", "returns", "a", "txn", ".", "Op", "that", "creates", "a", "refcount", "document", ";", "or", "false", "if", "the", "document", "already", "exists", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L52-L59
153,696
juju/juju
state/refcounts_ns.go
StrictCreateOp
func (ns nsRefcounts_) StrictCreateOp(coll mongo.Collection, key string, value int) (txn.Op, error) { if exists, err := ns.exists(coll, key); err != nil { return txn.Op{}, errors.Trace(err) } else if exists { return txn.Op{}, errors.New("refcount already exists") } return ns.JustCreateOp(coll.Name(), key, value), nil }
go
func (ns nsRefcounts_) StrictCreateOp(coll mongo.Collection, key string, value int) (txn.Op, error) { if exists, err := ns.exists(coll, key); err != nil { return txn.Op{}, errors.Trace(err) } else if exists { return txn.Op{}, errors.New("refcount already exists") } return ns.JustCreateOp(coll.Name(), key, value), nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "StrictCreateOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ",", "value", "int", ")", "(", "txn", ".", "Op", ",", "error", ")", "{", "if", "exists", ",", "err", ":=", "ns", ".", "exists", "(", "coll", ",", "key", ")", ";", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "exists", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "ns", ".", "JustCreateOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "value", ")", ",", "nil", "\n", "}" ]
// StrictCreateOp returns a txn.Op that creates a refcount document as // configured, or an error if the document already exists.
[ "StrictCreateOp", "returns", "a", "txn", ".", "Op", "that", "creates", "a", "refcount", "document", "as", "configured", "or", "an", "error", "if", "the", "document", "already", "exists", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L63-L70
153,697
juju/juju
state/refcounts_ns.go
CreateOrIncRefOp
func (ns nsRefcounts_) CreateOrIncRefOp(coll mongo.Collection, key string, n int) (txn.Op, error) { if exists, err := ns.exists(coll, key); err != nil { return txn.Op{}, errors.Trace(err) } else if !exists { return ns.JustCreateOp(coll.Name(), key, n), nil } return ns.JustIncRefOp(coll.Name(), key, n), nil }
go
func (ns nsRefcounts_) CreateOrIncRefOp(coll mongo.Collection, key string, n int) (txn.Op, error) { if exists, err := ns.exists(coll, key); err != nil { return txn.Op{}, errors.Trace(err) } else if !exists { return ns.JustCreateOp(coll.Name(), key, n), nil } return ns.JustIncRefOp(coll.Name(), key, n), nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "CreateOrIncRefOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ",", "n", "int", ")", "(", "txn", ".", "Op", ",", "error", ")", "{", "if", "exists", ",", "err", ":=", "ns", ".", "exists", "(", "coll", ",", "key", ")", ";", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "!", "exists", "{", "return", "ns", ".", "JustCreateOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "n", ")", ",", "nil", "\n", "}", "\n", "return", "ns", ".", "JustIncRefOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "n", ")", ",", "nil", "\n", "}" ]
// CreateOrIncrefOp returns a txn.Op that creates a refcount document as // configured with a specified value; or increments any such refcount doc // that already exists.
[ "CreateOrIncrefOp", "returns", "a", "txn", ".", "Op", "that", "creates", "a", "refcount", "document", "as", "configured", "with", "a", "specified", "value", ";", "or", "increments", "any", "such", "refcount", "doc", "that", "already", "exists", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L75-L82
153,698
juju/juju
state/refcounts_ns.go
AliveDecRefOp
func (ns nsRefcounts_) AliveDecRefOp(coll mongo.Collection, key string) (txn.Op, error) { if refcount, err := ns.read(coll, key); err != nil { return txn.Op{}, errors.Trace(err) } else if refcount < 1 { return txn.Op{}, errors.Annotatef(errRefcountAlreadyZero, "%s(%s)", coll.Name(), key) } return ns.justDecRefOp(coll.Name(), key, 0), nil }
go
func (ns nsRefcounts_) AliveDecRefOp(coll mongo.Collection, key string) (txn.Op, error) { if refcount, err := ns.read(coll, key); err != nil { return txn.Op{}, errors.Trace(err) } else if refcount < 1 { return txn.Op{}, errors.Annotatef(errRefcountAlreadyZero, "%s(%s)", coll.Name(), key) } return ns.justDecRefOp(coll.Name(), key, 0), nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "AliveDecRefOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ")", "(", "txn", ".", "Op", ",", "error", ")", "{", "if", "refcount", ",", "err", ":=", "ns", ".", "read", "(", "coll", ",", "key", ")", ";", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "refcount", "<", "1", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "Annotatef", "(", "errRefcountAlreadyZero", ",", "\"", "\"", ",", "coll", ".", "Name", "(", ")", ",", "key", ")", "\n", "}", "\n", "return", "ns", ".", "justDecRefOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "0", ")", ",", "nil", "\n", "}" ]
// AliveDecRefOp returns a txn.Op that decrements the value of a // refcount doc, or an error if the doc does not exist or the count // would go below 0.
[ "AliveDecRefOp", "returns", "a", "txn", ".", "Op", "that", "decrements", "the", "value", "of", "a", "refcount", "doc", "or", "an", "error", "if", "the", "doc", "does", "not", "exist", "or", "the", "count", "would", "go", "below", "0", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L98-L105
153,699
juju/juju
state/refcounts_ns.go
DyingDecRefOp
func (ns nsRefcounts_) DyingDecRefOp(coll mongo.Collection, key string) (txn.Op, bool, error) { refcount, err := ns.read(coll, key) if err != nil { return txn.Op{}, false, errors.Trace(err) } if refcount < 1 { return txn.Op{}, false, errors.Annotatef(errRefcountAlreadyZero, "%s(%s)", coll.Name(), key) } else if refcount > 1 { return ns.justDecRefOp(coll.Name(), key, 1), false, nil } return ns.JustRemoveOp(coll.Name(), key, 1), true, nil }
go
func (ns nsRefcounts_) DyingDecRefOp(coll mongo.Collection, key string) (txn.Op, bool, error) { refcount, err := ns.read(coll, key) if err != nil { return txn.Op{}, false, errors.Trace(err) } if refcount < 1 { return txn.Op{}, false, errors.Annotatef(errRefcountAlreadyZero, "%s(%s)", coll.Name(), key) } else if refcount > 1 { return ns.justDecRefOp(coll.Name(), key, 1), false, nil } return ns.JustRemoveOp(coll.Name(), key, 1), true, nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "DyingDecRefOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ")", "(", "txn", ".", "Op", ",", "bool", ",", "error", ")", "{", "refcount", ",", "err", ":=", "ns", ".", "read", "(", "coll", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "false", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "refcount", "<", "1", "{", "return", "txn", ".", "Op", "{", "}", ",", "false", ",", "errors", ".", "Annotatef", "(", "errRefcountAlreadyZero", ",", "\"", "\"", ",", "coll", ".", "Name", "(", ")", ",", "key", ")", "\n", "}", "else", "if", "refcount", ">", "1", "{", "return", "ns", ".", "justDecRefOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "1", ")", ",", "false", ",", "nil", "\n", "}", "\n", "return", "ns", ".", "JustRemoveOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "1", ")", ",", "true", ",", "nil", "\n", "}" ]
// DyingDecRefOp returns a txn.Op that decrements the value of a // refcount doc and deletes it if the count reaches 0; if the Op will // cause a delete, the bool result will be true. It will return an error // if the doc does not exist or the count would go below 0.
[ "DyingDecRefOp", "returns", "a", "txn", ".", "Op", "that", "decrements", "the", "value", "of", "a", "refcount", "doc", "and", "deletes", "it", "if", "the", "count", "reaches", "0", ";", "if", "the", "Op", "will", "cause", "a", "delete", "the", "bool", "result", "will", "be", "true", ".", "It", "will", "return", "an", "error", "if", "the", "doc", "does", "not", "exist", "or", "the", "count", "would", "go", "below", "0", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L111-L122