id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
3,300
juju/juju
api/application/client.go
UnsetApplicationConfig
func (c *Client) UnsetApplicationConfig(branchName, application string, options []string) error { if c.BestAPIVersion() < 6 { return errors.NotSupportedf("UnsetApplicationConfig not supported by this version of Juju") } args := params.ApplicationConfigUnsetArgs{ Args: []params.ApplicationUnset{{ ApplicationName: application, BranchName: branchName, Options: options, }}, } var results params.ErrorResults err := c.facade.FacadeCall("UnsetApplicationsConfig", args, &results) if err != nil { return errors.Trace(err) } return results.OneError() }
go
func (c *Client) UnsetApplicationConfig(branchName, application string, options []string) error { if c.BestAPIVersion() < 6 { return errors.NotSupportedf("UnsetApplicationConfig not supported by this version of Juju") } args := params.ApplicationConfigUnsetArgs{ Args: []params.ApplicationUnset{{ ApplicationName: application, BranchName: branchName, Options: options, }}, } var results params.ErrorResults err := c.facade.FacadeCall("UnsetApplicationsConfig", args, &results) if err != nil { return errors.Trace(err) } return results.OneError() }
[ "func", "(", "c", "*", "Client", ")", "UnsetApplicationConfig", "(", "branchName", ",", "application", "string", ",", "options", "[", "]", "string", ")", "error", "{", "if", "c", ".", "BestAPIVersion", "(", ")", "<", "6", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n", "args", ":=", "params", ".", "ApplicationConfigUnsetArgs", "{", "Args", ":", "[", "]", "params", ".", "ApplicationUnset", "{", "{", "ApplicationName", ":", "application", ",", "BranchName", ":", "branchName", ",", "Options", ":", "options", ",", "}", "}", ",", "}", "\n", "var", "results", "params", ".", "ErrorResults", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "results", ".", "OneError", "(", ")", "\n", "}" ]
// UnsetApplicationConfig resets configuration options on an application.
[ "UnsetApplicationConfig", "resets", "configuration", "options", "on", "an", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/application/client.go#L888-L905
3,301
juju/juju
api/application/client.go
ResolveUnitErrors
func (c *Client) ResolveUnitErrors(units []string, all, retry bool) error { if len(units) > 0 && all { return errors.NotSupportedf("specifying units with all=true") } if len(units) != set.NewStrings(units...).Size() { return errors.New("duplicate unit specified") } args := params.UnitsResolved{ All: all, Retry: retry, } if !all { entities := make([]params.Entity, len(units)) for i, unit := range units { if !names.IsValidUnit(unit) { return errors.NotValidf("unit name %q", unit) } entities[i].Tag = names.NewUnitTag(unit).String() } args.Tags = params.Entities{Entities: entities} } results := new(params.ErrorResults) err := c.facade.FacadeCall("ResolveUnitErrors", args, results) if err != nil { return errors.Trace(err) } return errors.Trace(results.Combine()) }
go
func (c *Client) ResolveUnitErrors(units []string, all, retry bool) error { if len(units) > 0 && all { return errors.NotSupportedf("specifying units with all=true") } if len(units) != set.NewStrings(units...).Size() { return errors.New("duplicate unit specified") } args := params.UnitsResolved{ All: all, Retry: retry, } if !all { entities := make([]params.Entity, len(units)) for i, unit := range units { if !names.IsValidUnit(unit) { return errors.NotValidf("unit name %q", unit) } entities[i].Tag = names.NewUnitTag(unit).String() } args.Tags = params.Entities{Entities: entities} } results := new(params.ErrorResults) err := c.facade.FacadeCall("ResolveUnitErrors", args, results) if err != nil { return errors.Trace(err) } return errors.Trace(results.Combine()) }
[ "func", "(", "c", "*", "Client", ")", "ResolveUnitErrors", "(", "units", "[", "]", "string", ",", "all", ",", "retry", "bool", ")", "error", "{", "if", "len", "(", "units", ")", ">", "0", "&&", "all", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "units", ")", "!=", "set", ".", "NewStrings", "(", "units", "...", ")", ".", "Size", "(", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "args", ":=", "params", ".", "UnitsResolved", "{", "All", ":", "all", ",", "Retry", ":", "retry", ",", "}", "\n", "if", "!", "all", "{", "entities", ":=", "make", "(", "[", "]", "params", ".", "Entity", ",", "len", "(", "units", ")", ")", "\n", "for", "i", ",", "unit", ":=", "range", "units", "{", "if", "!", "names", ".", "IsValidUnit", "(", "unit", ")", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "unit", ")", "\n", "}", "\n", "entities", "[", "i", "]", ".", "Tag", "=", "names", ".", "NewUnitTag", "(", "unit", ")", ".", "String", "(", ")", "\n", "}", "\n", "args", ".", "Tags", "=", "params", ".", "Entities", "{", "Entities", ":", "entities", "}", "\n", "}", "\n\n", "results", ":=", "new", "(", "params", ".", "ErrorResults", ")", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "errors", ".", "Trace", "(", "results", ".", "Combine", "(", ")", ")", "\n", "}" ]
// ResolveUnitErrors clears errors on one or more units. // Either specify one or more units, or all.
[ "ResolveUnitErrors", "clears", "errors", "on", "one", "or", "more", "units", ".", "Either", "specify", "one", "or", "more", "units", "or", "all", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/application/client.go#L909-L937
3,302
juju/juju
api/application/client.go
ApplicationsInfo
func (c *Client) ApplicationsInfo(applications []names.ApplicationTag) ([]params.ApplicationInfoResult, error) { if apiVersion := c.BestAPIVersion(); apiVersion < 9 { return nil, errors.NotSupportedf("ApplicationsInfo for Application facade v%v", apiVersion) } all := make([]params.Entity, len(applications)) for i, one := range applications { all[i] = params.Entity{Tag: one.String()} } in := params.Entities{Entities: all} var out params.ApplicationInfoResults err := c.facade.FacadeCall("ApplicationsInfo", in, &out) if err != nil { return nil, errors.Trace(err) } if resultsLen := len(out.Results); resultsLen != len(applications) { return nil, errors.Errorf("expected %d results, got %d", len(applications), resultsLen) } return out.Results, nil }
go
func (c *Client) ApplicationsInfo(applications []names.ApplicationTag) ([]params.ApplicationInfoResult, error) { if apiVersion := c.BestAPIVersion(); apiVersion < 9 { return nil, errors.NotSupportedf("ApplicationsInfo for Application facade v%v", apiVersion) } all := make([]params.Entity, len(applications)) for i, one := range applications { all[i] = params.Entity{Tag: one.String()} } in := params.Entities{Entities: all} var out params.ApplicationInfoResults err := c.facade.FacadeCall("ApplicationsInfo", in, &out) if err != nil { return nil, errors.Trace(err) } if resultsLen := len(out.Results); resultsLen != len(applications) { return nil, errors.Errorf("expected %d results, got %d", len(applications), resultsLen) } return out.Results, nil }
[ "func", "(", "c", "*", "Client", ")", "ApplicationsInfo", "(", "applications", "[", "]", "names", ".", "ApplicationTag", ")", "(", "[", "]", "params", ".", "ApplicationInfoResult", ",", "error", ")", "{", "if", "apiVersion", ":=", "c", ".", "BestAPIVersion", "(", ")", ";", "apiVersion", "<", "9", "{", "return", "nil", ",", "errors", ".", "NotSupportedf", "(", "\"", "\"", ",", "apiVersion", ")", "\n", "}", "\n", "all", ":=", "make", "(", "[", "]", "params", ".", "Entity", ",", "len", "(", "applications", ")", ")", "\n", "for", "i", ",", "one", ":=", "range", "applications", "{", "all", "[", "i", "]", "=", "params", ".", "Entity", "{", "Tag", ":", "one", ".", "String", "(", ")", "}", "\n", "}", "\n", "in", ":=", "params", ".", "Entities", "{", "Entities", ":", "all", "}", "\n", "var", "out", "params", ".", "ApplicationInfoResults", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "in", ",", "&", "out", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "resultsLen", ":=", "len", "(", "out", ".", "Results", ")", ";", "resultsLen", "!=", "len", "(", "applications", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "applications", ")", ",", "resultsLen", ")", "\n", "}", "\n", "return", "out", ".", "Results", ",", "nil", "\n", "}" ]
// ApplicationsInfo retrieves applications information.
[ "ApplicationsInfo", "retrieves", "applications", "information", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/application/client.go#L949-L967
3,303
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
NewFacadeV7
func NewFacadeV7(ctx facade.Context) (*ModelManagerAPI, error) { st := ctx.State() pool := ctx.StatePool() ctlrSt := pool.SystemState() auth := ctx.Auth() var err error model, err := st.Model() if err != nil { return nil, errors.Trace(err) } configGetter := stateenvirons.EnvironConfigGetter{State: st, Model: model} ctrlModel, err := ctlrSt.Model() if err != nil { return nil, err } return NewModelManagerAPI( common.NewModelManagerBackend(model, pool), common.NewModelManagerBackend(ctrlModel, pool), configGetter, caas.New, auth, model, state.CallContext(st), ) }
go
func NewFacadeV7(ctx facade.Context) (*ModelManagerAPI, error) { st := ctx.State() pool := ctx.StatePool() ctlrSt := pool.SystemState() auth := ctx.Auth() var err error model, err := st.Model() if err != nil { return nil, errors.Trace(err) } configGetter := stateenvirons.EnvironConfigGetter{State: st, Model: model} ctrlModel, err := ctlrSt.Model() if err != nil { return nil, err } return NewModelManagerAPI( common.NewModelManagerBackend(model, pool), common.NewModelManagerBackend(ctrlModel, pool), configGetter, caas.New, auth, model, state.CallContext(st), ) }
[ "func", "NewFacadeV7", "(", "ctx", "facade", ".", "Context", ")", "(", "*", "ModelManagerAPI", ",", "error", ")", "{", "st", ":=", "ctx", ".", "State", "(", ")", "\n", "pool", ":=", "ctx", ".", "StatePool", "(", ")", "\n", "ctlrSt", ":=", "pool", ".", "SystemState", "(", ")", "\n", "auth", ":=", "ctx", ".", "Auth", "(", ")", "\n\n", "var", "err", "error", "\n", "model", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "configGetter", ":=", "stateenvirons", ".", "EnvironConfigGetter", "{", "State", ":", "st", ",", "Model", ":", "model", "}", "\n\n", "ctrlModel", ",", "err", ":=", "ctlrSt", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "NewModelManagerAPI", "(", "common", ".", "NewModelManagerBackend", "(", "model", ",", "pool", ")", ",", "common", ".", "NewModelManagerBackend", "(", "ctrlModel", ",", "pool", ")", ",", "configGetter", ",", "caas", ".", "New", ",", "auth", ",", "model", ",", "state", ".", "CallContext", "(", "st", ")", ",", ")", "\n", "}" ]
// NewFacadeV7 is used for API registration.
[ "NewFacadeV7", "is", "used", "for", "API", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L164-L192
3,304
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
NewFacadeV6
func NewFacadeV6(ctx facade.Context) (*ModelManagerAPIV6, error) { v7, err := NewFacadeV7(ctx) if err != nil { return nil, err } return &ModelManagerAPIV6{v7}, nil }
go
func NewFacadeV6(ctx facade.Context) (*ModelManagerAPIV6, error) { v7, err := NewFacadeV7(ctx) if err != nil { return nil, err } return &ModelManagerAPIV6{v7}, nil }
[ "func", "NewFacadeV6", "(", "ctx", "facade", ".", "Context", ")", "(", "*", "ModelManagerAPIV6", ",", "error", ")", "{", "v7", ",", "err", ":=", "NewFacadeV7", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ModelManagerAPIV6", "{", "v7", "}", ",", "nil", "\n", "}" ]
// NewFacadeV6 is used for API registration.
[ "NewFacadeV6", "is", "used", "for", "API", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L195-L201
3,305
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
NewFacadeV4
func NewFacadeV4(ctx facade.Context) (*ModelManagerAPIV4, error) { v5, err := NewFacadeV5(ctx) if err != nil { return nil, err } return &ModelManagerAPIV4{v5}, nil }
go
func NewFacadeV4(ctx facade.Context) (*ModelManagerAPIV4, error) { v5, err := NewFacadeV5(ctx) if err != nil { return nil, err } return &ModelManagerAPIV4{v5}, nil }
[ "func", "NewFacadeV4", "(", "ctx", "facade", ".", "Context", ")", "(", "*", "ModelManagerAPIV4", ",", "error", ")", "{", "v5", ",", "err", ":=", "NewFacadeV5", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ModelManagerAPIV4", "{", "v5", "}", ",", "nil", "\n", "}" ]
// NewFacadeV4 is used for API registration.
[ "NewFacadeV4", "is", "used", "for", "API", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L213-L219
3,306
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
NewModelManagerAPI
func NewModelManagerAPI( st common.ModelManagerBackend, ctlrSt common.ModelManagerBackend, configGetter environs.EnvironConfigGetter, getBroker newCaasBrokerFunc, authorizer facade.Authorizer, m common.Model, callCtx context.ProviderCallContext, ) (*ModelManagerAPI, error) { if !authorizer.AuthClient() { return nil, common.ErrPerm } // Since we know this is a user tag (because AuthClient is true), // we just do the type assertion to the UserTag. apiUser, _ := authorizer.GetAuthTag().(names.UserTag) // Pretty much all of the user manager methods have special casing for admin // users, so look once when we start and remember if the user is an admin. isAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag()) if err != nil { return nil, errors.Trace(err) } urlGetter := common.NewToolsURLGetter(st.ModelUUID(), st) return &ModelManagerAPI{ ModelStatusAPI: common.NewModelStatusAPI(st, authorizer, apiUser), state: st, ctlrState: ctlrSt, getBroker: getBroker, check: common.NewBlockChecker(st), authorizer: authorizer, toolsFinder: common.NewToolsFinder(configGetter, st, urlGetter), apiUser: apiUser, isAdmin: isAdmin, model: m, callContext: callCtx, }, nil }
go
func NewModelManagerAPI( st common.ModelManagerBackend, ctlrSt common.ModelManagerBackend, configGetter environs.EnvironConfigGetter, getBroker newCaasBrokerFunc, authorizer facade.Authorizer, m common.Model, callCtx context.ProviderCallContext, ) (*ModelManagerAPI, error) { if !authorizer.AuthClient() { return nil, common.ErrPerm } // Since we know this is a user tag (because AuthClient is true), // we just do the type assertion to the UserTag. apiUser, _ := authorizer.GetAuthTag().(names.UserTag) // Pretty much all of the user manager methods have special casing for admin // users, so look once when we start and remember if the user is an admin. isAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag()) if err != nil { return nil, errors.Trace(err) } urlGetter := common.NewToolsURLGetter(st.ModelUUID(), st) return &ModelManagerAPI{ ModelStatusAPI: common.NewModelStatusAPI(st, authorizer, apiUser), state: st, ctlrState: ctlrSt, getBroker: getBroker, check: common.NewBlockChecker(st), authorizer: authorizer, toolsFinder: common.NewToolsFinder(configGetter, st, urlGetter), apiUser: apiUser, isAdmin: isAdmin, model: m, callContext: callCtx, }, nil }
[ "func", "NewModelManagerAPI", "(", "st", "common", ".", "ModelManagerBackend", ",", "ctlrSt", "common", ".", "ModelManagerBackend", ",", "configGetter", "environs", ".", "EnvironConfigGetter", ",", "getBroker", "newCaasBrokerFunc", ",", "authorizer", "facade", ".", "Authorizer", ",", "m", "common", ".", "Model", ",", "callCtx", "context", ".", "ProviderCallContext", ",", ")", "(", "*", "ModelManagerAPI", ",", "error", ")", "{", "if", "!", "authorizer", ".", "AuthClient", "(", ")", "{", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "// Since we know this is a user tag (because AuthClient is true),", "// we just do the type assertion to the UserTag.", "apiUser", ",", "_", ":=", "authorizer", ".", "GetAuthTag", "(", ")", ".", "(", "names", ".", "UserTag", ")", "\n", "// Pretty much all of the user manager methods have special casing for admin", "// users, so look once when we start and remember if the user is an admin.", "isAdmin", ",", "err", ":=", "authorizer", ".", "HasPermission", "(", "permission", ".", "SuperuserAccess", ",", "st", ".", "ControllerTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "urlGetter", ":=", "common", ".", "NewToolsURLGetter", "(", "st", ".", "ModelUUID", "(", ")", ",", "st", ")", "\n", "return", "&", "ModelManagerAPI", "{", "ModelStatusAPI", ":", "common", ".", "NewModelStatusAPI", "(", "st", ",", "authorizer", ",", "apiUser", ")", ",", "state", ":", "st", ",", "ctlrState", ":", "ctlrSt", ",", "getBroker", ":", "getBroker", ",", "check", ":", "common", ".", "NewBlockChecker", "(", "st", ")", ",", "authorizer", ":", "authorizer", ",", "toolsFinder", ":", "common", ".", "NewToolsFinder", "(", "configGetter", ",", "st", ",", "urlGetter", ")", ",", "apiUser", ":", "apiUser", ",", "isAdmin", ":", "isAdmin", ",", "model", ":", "m", ",", "callContext", ":", "callCtx", ",", "}", ",", "nil", "\n", "}" ]
// NewModelManagerAPI creates a new api server endpoint for managing // models.
[ "NewModelManagerAPI", "creates", "a", "new", "api", "server", "endpoint", "for", "managing", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L241-L276
3,307
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
authCheck
func (m *ModelManagerAPI) authCheck(user names.UserTag) error { if m.isAdmin { logger.Tracef("%q is a controller admin", m.apiUser.Id()) return nil } // We can't just compare the UserTags themselves as the provider part // may be unset, and gets replaced with 'local'. We must compare against // the Canonical value of the user tag. if m.apiUser == user { return nil } return common.ErrPerm }
go
func (m *ModelManagerAPI) authCheck(user names.UserTag) error { if m.isAdmin { logger.Tracef("%q is a controller admin", m.apiUser.Id()) return nil } // We can't just compare the UserTags themselves as the provider part // may be unset, and gets replaced with 'local'. We must compare against // the Canonical value of the user tag. if m.apiUser == user { return nil } return common.ErrPerm }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "authCheck", "(", "user", "names", ".", "UserTag", ")", "error", "{", "if", "m", ".", "isAdmin", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "m", ".", "apiUser", ".", "Id", "(", ")", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// We can't just compare the UserTags themselves as the provider part", "// may be unset, and gets replaced with 'local'. We must compare against", "// the Canonical value of the user tag.", "if", "m", ".", "apiUser", "==", "user", "{", "return", "nil", "\n", "}", "\n", "return", "common", ".", "ErrPerm", "\n", "}" ]
// authCheck checks if the user is acting on their own behalf, or if they // are an administrator acting on behalf of another user.
[ "authCheck", "checks", "if", "the", "user", "is", "acting", "on", "their", "own", "behalf", "or", "if", "they", "are", "an", "administrator", "acting", "on", "behalf", "of", "another", "user", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L280-L293
3,308
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
DumpModelsDB
func (m *ModelManagerAPI) DumpModelsDB(args params.Entities) params.MapResults { results := params.MapResults{ Results: make([]params.MapResult, len(args.Entities)), } for i, entity := range args.Entities { dumped, err := m.dumpModelDB(entity) if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Result = dumped } return results }
go
func (m *ModelManagerAPI) DumpModelsDB(args params.Entities) params.MapResults { results := params.MapResults{ Results: make([]params.MapResult, len(args.Entities)), } for i, entity := range args.Entities { dumped, err := m.dumpModelDB(entity) if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Result = dumped } return results }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "DumpModelsDB", "(", "args", "params", ".", "Entities", ")", "params", ".", "MapResults", "{", "results", ":=", "params", ".", "MapResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "MapResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "dumped", ",", "err", ":=", "m", ".", "dumpModelDB", "(", "entity", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "results", ".", "Results", "[", "i", "]", ".", "Result", "=", "dumped", "\n", "}", "\n", "return", "results", "\n", "}" ]
// DumpModelsDB will gather all documents from all model collections // for the specified model. The map result contains a map of collection // names to lists of documents represented as maps.
[ "DumpModelsDB", "will", "gather", "all", "documents", "from", "all", "model", "collections", "for", "the", "specified", "model", ".", "The", "map", "result", "contains", "a", "map", "of", "collection", "names", "to", "lists", "of", "documents", "represented", "as", "maps", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L813-L826
3,309
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
DestroyModels
func (m *ModelManagerAPIV3) DestroyModels(args params.Entities) (params.ErrorResults, error) { // v3 DestroyModels is implemented in terms of v4: // storage is unconditionally destroyed, as was the // old behaviour. destroyStorage := true v4Args := params.DestroyModelsParams{ Models: make([]params.DestroyModelParams, len(args.Entities)), } for i, arg := range args.Entities { v4Args.Models[i] = params.DestroyModelParams{ ModelTag: arg.Tag, DestroyStorage: &destroyStorage, } } return m.ModelManagerAPI.DestroyModels(v4Args) }
go
func (m *ModelManagerAPIV3) DestroyModels(args params.Entities) (params.ErrorResults, error) { // v3 DestroyModels is implemented in terms of v4: // storage is unconditionally destroyed, as was the // old behaviour. destroyStorage := true v4Args := params.DestroyModelsParams{ Models: make([]params.DestroyModelParams, len(args.Entities)), } for i, arg := range args.Entities { v4Args.Models[i] = params.DestroyModelParams{ ModelTag: arg.Tag, DestroyStorage: &destroyStorage, } } return m.ModelManagerAPI.DestroyModels(v4Args) }
[ "func", "(", "m", "*", "ModelManagerAPIV3", ")", "DestroyModels", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "// v3 DestroyModels is implemented in terms of v4:", "// storage is unconditionally destroyed, as was the", "// old behaviour.", "destroyStorage", ":=", "true", "\n", "v4Args", ":=", "params", ".", "DestroyModelsParams", "{", "Models", ":", "make", "(", "[", "]", "params", ".", "DestroyModelParams", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Entities", "{", "v4Args", ".", "Models", "[", "i", "]", "=", "params", ".", "DestroyModelParams", "{", "ModelTag", ":", "arg", ".", "Tag", ",", "DestroyStorage", ":", "&", "destroyStorage", ",", "}", "\n", "}", "\n", "return", "m", ".", "ModelManagerAPI", ".", "DestroyModels", "(", "v4Args", ")", "\n", "}" ]
// DestroyModels will try to destroy the specified models. // If there is a block on destruction, this method will return an error.
[ "DestroyModels", "will", "try", "to", "destroy", "the", "specified", "models", ".", "If", "there", "is", "a", "block", "on", "destruction", "this", "method", "will", "return", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L963-L978
3,310
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
DestroyModels
func (m *ModelManagerAPI) DestroyModels(args params.DestroyModelsParams) (params.ErrorResults, error) { results := params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Models)), } destroyModel := func(modelUUID string, destroyStorage, force *bool, maxWait *time.Duration) error { st, releaseSt, err := m.state.GetBackend(modelUUID) if err != nil { return errors.Trace(err) } defer releaseSt() model, err := st.Model() if err != nil { return errors.Trace(err) } if !m.isAdmin { hasAdmin, err := m.authorizer.HasPermission(permission.AdminAccess, model.ModelTag()) if err != nil { return errors.Trace(err) } if !hasAdmin { return errors.Trace(common.ErrPerm) } } return errors.Trace(common.DestroyModel(st, destroyStorage, force, maxWait)) } for i, arg := range args.Models { tag, err := names.ParseModelTag(arg.ModelTag) if err != nil { results.Results[i].Error = common.ServerError(err) continue } if err := destroyModel(tag.Id(), arg.DestroyStorage, arg.Force, arg.MaxWait); err != nil { results.Results[i].Error = common.ServerError(err) continue } } return results, nil }
go
func (m *ModelManagerAPI) DestroyModels(args params.DestroyModelsParams) (params.ErrorResults, error) { results := params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Models)), } destroyModel := func(modelUUID string, destroyStorage, force *bool, maxWait *time.Duration) error { st, releaseSt, err := m.state.GetBackend(modelUUID) if err != nil { return errors.Trace(err) } defer releaseSt() model, err := st.Model() if err != nil { return errors.Trace(err) } if !m.isAdmin { hasAdmin, err := m.authorizer.HasPermission(permission.AdminAccess, model.ModelTag()) if err != nil { return errors.Trace(err) } if !hasAdmin { return errors.Trace(common.ErrPerm) } } return errors.Trace(common.DestroyModel(st, destroyStorage, force, maxWait)) } for i, arg := range args.Models { tag, err := names.ParseModelTag(arg.ModelTag) if err != nil { results.Results[i].Error = common.ServerError(err) continue } if err := destroyModel(tag.Id(), arg.DestroyStorage, arg.Force, arg.MaxWait); err != nil { results.Results[i].Error = common.ServerError(err) continue } } return results, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "DestroyModels", "(", "args", "params", ".", "DestroyModelsParams", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "results", ":=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Models", ")", ")", ",", "}", "\n\n", "destroyModel", ":=", "func", "(", "modelUUID", "string", ",", "destroyStorage", ",", "force", "*", "bool", ",", "maxWait", "*", "time", ".", "Duration", ")", "error", "{", "st", ",", "releaseSt", ",", "err", ":=", "m", ".", "state", ".", "GetBackend", "(", "modelUUID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "defer", "releaseSt", "(", ")", "\n\n", "model", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "m", ".", "isAdmin", "{", "hasAdmin", ",", "err", ":=", "m", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "AdminAccess", ",", "model", ".", "ModelTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "hasAdmin", "{", "return", "errors", ".", "Trace", "(", "common", ".", "ErrPerm", ")", "\n", "}", "\n", "}", "\n\n", "return", "errors", ".", "Trace", "(", "common", ".", "DestroyModel", "(", "st", ",", "destroyStorage", ",", "force", ",", "maxWait", ")", ")", "\n", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Models", "{", "tag", ",", "err", ":=", "names", ".", "ParseModelTag", "(", "arg", ".", "ModelTag", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "err", ":=", "destroyModel", "(", "tag", ".", "Id", "(", ")", ",", "arg", ".", "DestroyStorage", ",", "arg", ".", "Force", ",", "arg", ".", "MaxWait", ")", ";", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// DestroyModels will try to destroy the specified models. // If there is a block on destruction, this method will return an error. // From ModelManager v7 onwards, DestroyModels gains 'force' and 'max-wait' parameters.
[ "DestroyModels", "will", "try", "to", "destroy", "the", "specified", "models", ".", "If", "there", "is", "a", "block", "on", "destruction", "this", "method", "will", "return", "an", "error", ".", "From", "ModelManager", "v7", "onwards", "DestroyModels", "gains", "force", "and", "max", "-", "wait", "parameters", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L983-L1024
3,311
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
ModelInfo
func (m *ModelManagerAPI) ModelInfo(args params.Entities) (params.ModelInfoResults, error) { results := params.ModelInfoResults{ Results: make([]params.ModelInfoResult, len(args.Entities)), } getModelInfo := func(arg params.Entity) (params.ModelInfo, error) { tag, err := names.ParseModelTag(arg.Tag) if err != nil { return params.ModelInfo{}, errors.Trace(err) } return m.getModelInfo(tag) } for i, arg := range args.Entities { modelInfo, err := getModelInfo(arg) if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Result = &modelInfo } return results, nil }
go
func (m *ModelManagerAPI) ModelInfo(args params.Entities) (params.ModelInfoResults, error) { results := params.ModelInfoResults{ Results: make([]params.ModelInfoResult, len(args.Entities)), } getModelInfo := func(arg params.Entity) (params.ModelInfo, error) { tag, err := names.ParseModelTag(arg.Tag) if err != nil { return params.ModelInfo{}, errors.Trace(err) } return m.getModelInfo(tag) } for i, arg := range args.Entities { modelInfo, err := getModelInfo(arg) if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Result = &modelInfo } return results, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "ModelInfo", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "ModelInfoResults", ",", "error", ")", "{", "results", ":=", "params", ".", "ModelInfoResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ModelInfoResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n\n", "getModelInfo", ":=", "func", "(", "arg", "params", ".", "Entity", ")", "(", "params", ".", "ModelInfo", ",", "error", ")", "{", "tag", ",", "err", ":=", "names", ".", "ParseModelTag", "(", "arg", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "ModelInfo", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "m", ".", "getModelInfo", "(", "tag", ")", "\n", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Entities", "{", "modelInfo", ",", "err", ":=", "getModelInfo", "(", "arg", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "results", ".", "Results", "[", "i", "]", ".", "Result", "=", "&", "modelInfo", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// ModelInfo returns information about the specified models.
[ "ModelInfo", "returns", "information", "about", "the", "specified", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1027-L1049
3,312
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
ModifyModelAccess
func (m *ModelManagerAPI) ModifyModelAccess(args params.ModifyModelAccessRequest) (result params.ErrorResults, _ error) { result = params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Changes)), } canModifyController, err := m.authorizer.HasPermission(permission.SuperuserAccess, m.state.ControllerTag()) if err != nil { return result, errors.Trace(err) } if len(args.Changes) == 0 { return result, nil } for i, arg := range args.Changes { modelAccess := permission.Access(arg.Access) if err := permission.ValidateModelAccess(modelAccess); err != nil { err = errors.Annotate(err, "could not modify model access") result.Results[i].Error = common.ServerError(err) continue } modelTag, err := names.ParseModelTag(arg.ModelTag) if err != nil { result.Results[i].Error = common.ServerError(errors.Annotate(err, "could not modify model access")) continue } canModifyModel, err := m.authorizer.HasPermission(permission.AdminAccess, modelTag) if err != nil { return result, errors.Trace(err) } canModify := canModifyController || canModifyModel if !canModify { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } targetUserTag, err := names.ParseUserTag(arg.UserTag) if err != nil { result.Results[i].Error = common.ServerError(errors.Annotate(err, "could not modify model access")) continue } result.Results[i].Error = common.ServerError( changeModelAccess(m.state, modelTag, m.apiUser, targetUserTag, arg.Action, modelAccess, m.isAdmin)) } return result, nil }
go
func (m *ModelManagerAPI) ModifyModelAccess(args params.ModifyModelAccessRequest) (result params.ErrorResults, _ error) { result = params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Changes)), } canModifyController, err := m.authorizer.HasPermission(permission.SuperuserAccess, m.state.ControllerTag()) if err != nil { return result, errors.Trace(err) } if len(args.Changes) == 0 { return result, nil } for i, arg := range args.Changes { modelAccess := permission.Access(arg.Access) if err := permission.ValidateModelAccess(modelAccess); err != nil { err = errors.Annotate(err, "could not modify model access") result.Results[i].Error = common.ServerError(err) continue } modelTag, err := names.ParseModelTag(arg.ModelTag) if err != nil { result.Results[i].Error = common.ServerError(errors.Annotate(err, "could not modify model access")) continue } canModifyModel, err := m.authorizer.HasPermission(permission.AdminAccess, modelTag) if err != nil { return result, errors.Trace(err) } canModify := canModifyController || canModifyModel if !canModify { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } targetUserTag, err := names.ParseUserTag(arg.UserTag) if err != nil { result.Results[i].Error = common.ServerError(errors.Annotate(err, "could not modify model access")) continue } result.Results[i].Error = common.ServerError( changeModelAccess(m.state, modelTag, m.apiUser, targetUserTag, arg.Action, modelAccess, m.isAdmin)) } return result, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "ModifyModelAccess", "(", "args", "params", ".", "ModifyModelAccessRequest", ")", "(", "result", "params", ".", "ErrorResults", ",", "_", "error", ")", "{", "result", "=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Changes", ")", ")", ",", "}", "\n\n", "canModifyController", ",", "err", ":=", "m", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "SuperuserAccess", ",", "m", ".", "state", ".", "ControllerTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "args", ".", "Changes", ")", "==", "0", "{", "return", "result", ",", "nil", "\n", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Changes", "{", "modelAccess", ":=", "permission", ".", "Access", "(", "arg", ".", "Access", ")", "\n", "if", "err", ":=", "permission", ".", "ValidateModelAccess", "(", "modelAccess", ")", ";", "err", "!=", "nil", "{", "err", "=", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n\n", "modelTag", ",", "err", ":=", "names", ".", "ParseModelTag", "(", "arg", ".", "ModelTag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", ")", "\n", "continue", "\n", "}", "\n", "canModifyModel", ",", "err", ":=", "m", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "AdminAccess", ",", "modelTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "canModify", ":=", "canModifyController", "||", "canModifyModel", "\n\n", "if", "!", "canModify", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n\n", "targetUserTag", ",", "err", ":=", "names", ".", "ParseUserTag", "(", "arg", ".", "UserTag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", ")", "\n", "continue", "\n", "}", "\n\n", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "changeModelAccess", "(", "m", ".", "state", ",", "modelTag", ",", "m", ".", "apiUser", ",", "targetUserTag", ",", "arg", ".", "Action", ",", "modelAccess", ",", "m", ".", "isAdmin", ")", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ModifyModelAccess changes the model access granted to users.
[ "ModifyModelAccess", "changes", "the", "model", "access", "granted", "to", "users", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1195-L1242
3,313
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
changeModelAccess
func changeModelAccess(accessor common.ModelManagerBackend, modelTag names.ModelTag, apiUser, targetUserTag names.UserTag, action params.ModelAction, access permission.Access, userIsAdmin bool) error { st, release, err := accessor.GetBackend(modelTag.Id()) if err != nil { return errors.Annotate(err, "could not lookup model") } defer release() if err := userAuthorizedToChangeAccess(st, userIsAdmin, apiUser); err != nil { return errors.Trace(err) } model, err := st.Model() if err != nil { return errors.Trace(err) } switch action { case params.GrantModelAccess: _, err = model.AddUser(state.UserAccessSpec{User: targetUserTag, CreatedBy: apiUser, Access: access}) if errors.IsAlreadyExists(err) { modelUser, err := st.UserAccess(targetUserTag, modelTag) if errors.IsNotFound(err) { // Conflicts with prior check, must be inconsistent state. err = txn.ErrExcessiveContention } if err != nil { return errors.Annotate(err, "could not look up model access for user") } // Only set access if greater access is being granted. if modelUser.Access.EqualOrGreaterModelAccessThan(access) { return errors.Errorf("user already has %q access or greater", access) } if _, err = st.SetUserAccess(modelUser.UserTag, modelUser.Object, access); err != nil { return errors.Annotate(err, "could not set model access for user") } return nil } return errors.Annotate(err, "could not grant model access") case params.RevokeModelAccess: switch access { case permission.ReadAccess: // Revoking read access removes all access. err := st.RemoveUserAccess(targetUserTag, modelTag) return errors.Annotate(err, "could not revoke model access") case permission.WriteAccess: // Revoking write access sets read-only. modelUser, err := st.UserAccess(targetUserTag, modelTag) if err != nil { return errors.Annotate(err, "could not look up model access for user") } _, err = st.SetUserAccess(modelUser.UserTag, modelUser.Object, permission.ReadAccess) return errors.Annotate(err, "could not set model access to read-only") case permission.AdminAccess: // Revoking admin access sets read-write. modelUser, err := st.UserAccess(targetUserTag, modelTag) if err != nil { return errors.Annotate(err, "could not look up model access for user") } _, err = st.SetUserAccess(modelUser.UserTag, modelUser.Object, permission.WriteAccess) return errors.Annotate(err, "could not set model access to read-write") default: return errors.Errorf("don't know how to revoke %q access", access) } default: return errors.Errorf("unknown action %q", action) } }
go
func changeModelAccess(accessor common.ModelManagerBackend, modelTag names.ModelTag, apiUser, targetUserTag names.UserTag, action params.ModelAction, access permission.Access, userIsAdmin bool) error { st, release, err := accessor.GetBackend(modelTag.Id()) if err != nil { return errors.Annotate(err, "could not lookup model") } defer release() if err := userAuthorizedToChangeAccess(st, userIsAdmin, apiUser); err != nil { return errors.Trace(err) } model, err := st.Model() if err != nil { return errors.Trace(err) } switch action { case params.GrantModelAccess: _, err = model.AddUser(state.UserAccessSpec{User: targetUserTag, CreatedBy: apiUser, Access: access}) if errors.IsAlreadyExists(err) { modelUser, err := st.UserAccess(targetUserTag, modelTag) if errors.IsNotFound(err) { // Conflicts with prior check, must be inconsistent state. err = txn.ErrExcessiveContention } if err != nil { return errors.Annotate(err, "could not look up model access for user") } // Only set access if greater access is being granted. if modelUser.Access.EqualOrGreaterModelAccessThan(access) { return errors.Errorf("user already has %q access or greater", access) } if _, err = st.SetUserAccess(modelUser.UserTag, modelUser.Object, access); err != nil { return errors.Annotate(err, "could not set model access for user") } return nil } return errors.Annotate(err, "could not grant model access") case params.RevokeModelAccess: switch access { case permission.ReadAccess: // Revoking read access removes all access. err := st.RemoveUserAccess(targetUserTag, modelTag) return errors.Annotate(err, "could not revoke model access") case permission.WriteAccess: // Revoking write access sets read-only. modelUser, err := st.UserAccess(targetUserTag, modelTag) if err != nil { return errors.Annotate(err, "could not look up model access for user") } _, err = st.SetUserAccess(modelUser.UserTag, modelUser.Object, permission.ReadAccess) return errors.Annotate(err, "could not set model access to read-only") case permission.AdminAccess: // Revoking admin access sets read-write. modelUser, err := st.UserAccess(targetUserTag, modelTag) if err != nil { return errors.Annotate(err, "could not look up model access for user") } _, err = st.SetUserAccess(modelUser.UserTag, modelUser.Object, permission.WriteAccess) return errors.Annotate(err, "could not set model access to read-write") default: return errors.Errorf("don't know how to revoke %q access", access) } default: return errors.Errorf("unknown action %q", action) } }
[ "func", "changeModelAccess", "(", "accessor", "common", ".", "ModelManagerBackend", ",", "modelTag", "names", ".", "ModelTag", ",", "apiUser", ",", "targetUserTag", "names", ".", "UserTag", ",", "action", "params", ".", "ModelAction", ",", "access", "permission", ".", "Access", ",", "userIsAdmin", "bool", ")", "error", "{", "st", ",", "release", ",", "err", ":=", "accessor", ".", "GetBackend", "(", "modelTag", ".", "Id", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "defer", "release", "(", ")", "\n\n", "if", "err", ":=", "userAuthorizedToChangeAccess", "(", "st", ",", "userIsAdmin", ",", "apiUser", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "model", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "switch", "action", "{", "case", "params", ".", "GrantModelAccess", ":", "_", ",", "err", "=", "model", ".", "AddUser", "(", "state", ".", "UserAccessSpec", "{", "User", ":", "targetUserTag", ",", "CreatedBy", ":", "apiUser", ",", "Access", ":", "access", "}", ")", "\n", "if", "errors", ".", "IsAlreadyExists", "(", "err", ")", "{", "modelUser", ",", "err", ":=", "st", ".", "UserAccess", "(", "targetUserTag", ",", "modelTag", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "// Conflicts with prior check, must be inconsistent state.", "err", "=", "txn", ".", "ErrExcessiveContention", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Only set access if greater access is being granted.", "if", "modelUser", ".", "Access", ".", "EqualOrGreaterModelAccessThan", "(", "access", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "access", ")", "\n", "}", "\n", "if", "_", ",", "err", "=", "st", ".", "SetUserAccess", "(", "modelUser", ".", "UserTag", ",", "modelUser", ".", "Object", ",", "access", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n\n", "case", "params", ".", "RevokeModelAccess", ":", "switch", "access", "{", "case", "permission", ".", "ReadAccess", ":", "// Revoking read access removes all access.", "err", ":=", "st", ".", "RemoveUserAccess", "(", "targetUserTag", ",", "modelTag", ")", "\n", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "case", "permission", ".", "WriteAccess", ":", "// Revoking write access sets read-only.", "modelUser", ",", "err", ":=", "st", ".", "UserAccess", "(", "targetUserTag", ",", "modelTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "_", ",", "err", "=", "st", ".", "SetUserAccess", "(", "modelUser", ".", "UserTag", ",", "modelUser", ".", "Object", ",", "permission", ".", "ReadAccess", ")", "\n", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "case", "permission", ".", "AdminAccess", ":", "// Revoking admin access sets read-write.", "modelUser", ",", "err", ":=", "st", ".", "UserAccess", "(", "targetUserTag", ",", "modelTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "_", ",", "err", "=", "st", ".", "SetUserAccess", "(", "modelUser", ".", "UserTag", ",", "modelUser", ".", "Object", ",", "permission", ".", "WriteAccess", ")", "\n", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "access", ")", "\n", "}", "\n\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "action", ")", "\n", "}", "\n", "}" ]
// changeModelAccess performs the requested access grant or revoke action for the // specified user on the specified model.
[ "changeModelAccess", "performs", "the", "requested", "access", "grant", "or", "revoke", "action", "for", "the", "specified", "user", "on", "the", "specified", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1272-L1342
3,314
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
ModelDefaultsForClouds
func (m *ModelManagerAPI) ModelDefaultsForClouds(args params.Entities) (params.ModelDefaultsResults, error) { result := params.ModelDefaultsResults{} if !m.isAdmin { return result, common.ErrPerm } result.Results = make([]params.ModelDefaultsResult, len(args.Entities)) for i, entity := range args.Entities { cloudTag, err := names.ParseCloudTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(err) continue } result.Results[i] = m.modelDefaults(cloudTag.Id()) } return result, nil }
go
func (m *ModelManagerAPI) ModelDefaultsForClouds(args params.Entities) (params.ModelDefaultsResults, error) { result := params.ModelDefaultsResults{} if !m.isAdmin { return result, common.ErrPerm } result.Results = make([]params.ModelDefaultsResult, len(args.Entities)) for i, entity := range args.Entities { cloudTag, err := names.ParseCloudTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(err) continue } result.Results[i] = m.modelDefaults(cloudTag.Id()) } return result, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "ModelDefaultsForClouds", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "ModelDefaultsResults", ",", "error", ")", "{", "result", ":=", "params", ".", "ModelDefaultsResults", "{", "}", "\n", "if", "!", "m", ".", "isAdmin", "{", "return", "result", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "result", ".", "Results", "=", "make", "(", "[", "]", "params", ".", "ModelDefaultsResult", ",", "len", "(", "args", ".", "Entities", ")", ")", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "cloudTag", ",", "err", ":=", "names", ".", "ParseCloudTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "result", ".", "Results", "[", "i", "]", "=", "m", ".", "modelDefaults", "(", "cloudTag", ".", "Id", "(", ")", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ModelDefaults returns the default config values for the specified clouds.
[ "ModelDefaults", "returns", "the", "default", "config", "values", "for", "the", "specified", "clouds", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1345-L1360
3,315
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
ModelDefaults
func (m *ModelManagerAPIV5) ModelDefaults() (params.ModelDefaultsResult, error) { result := params.ModelDefaultsResult{} if !m.isAdmin { return result, common.ErrPerm } return m.modelDefaults(m.model.Cloud()), nil }
go
func (m *ModelManagerAPIV5) ModelDefaults() (params.ModelDefaultsResult, error) { result := params.ModelDefaultsResult{} if !m.isAdmin { return result, common.ErrPerm } return m.modelDefaults(m.model.Cloud()), nil }
[ "func", "(", "m", "*", "ModelManagerAPIV5", ")", "ModelDefaults", "(", ")", "(", "params", ".", "ModelDefaultsResult", ",", "error", ")", "{", "result", ":=", "params", ".", "ModelDefaultsResult", "{", "}", "\n", "if", "!", "m", ".", "isAdmin", "{", "return", "result", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "return", "m", ".", "modelDefaults", "(", "m", ".", "model", ".", "Cloud", "(", ")", ")", ",", "nil", "\n", "}" ]
// ModelDefaults returns the default config values used when creating a new model.
[ "ModelDefaults", "returns", "the", "default", "config", "values", "used", "when", "creating", "a", "new", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1363-L1369
3,316
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
SetModelDefaults
func (m *ModelManagerAPI) SetModelDefaults(args params.SetModelDefaults) (params.ErrorResults, error) { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Config))} if err := m.check.ChangeAllowed(); err != nil { return results, errors.Trace(err) } for i, arg := range args.Config { results.Results[i].Error = common.ServerError( m.setModelDefaults(arg), ) } return results, nil }
go
func (m *ModelManagerAPI) SetModelDefaults(args params.SetModelDefaults) (params.ErrorResults, error) { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Config))} if err := m.check.ChangeAllowed(); err != nil { return results, errors.Trace(err) } for i, arg := range args.Config { results.Results[i].Error = common.ServerError( m.setModelDefaults(arg), ) } return results, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "SetModelDefaults", "(", "args", "params", ".", "SetModelDefaults", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "results", ":=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Config", ")", ")", "}", "\n", "if", "err", ":=", "m", ".", "check", ".", "ChangeAllowed", "(", ")", ";", "err", "!=", "nil", "{", "return", "results", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Config", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "m", ".", "setModelDefaults", "(", "arg", ")", ",", ")", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// SetModelDefaults writes new values for the specified default model settings.
[ "SetModelDefaults", "writes", "new", "values", "for", "the", "specified", "default", "model", "settings", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1396-L1407
3,317
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
UnsetModelDefaults
func (m *ModelManagerAPI) UnsetModelDefaults(args params.UnsetModelDefaults) (params.ErrorResults, error) { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Keys))} if !m.isAdmin { return results, common.ErrPerm } if err := m.check.ChangeAllowed(); err != nil { return results, errors.Trace(err) } for i, arg := range args.Keys { var rspec *environs.CloudRegionSpec if arg.CloudTag != "" { spec, err := m.makeRegionSpec(arg.CloudTag, arg.CloudRegion) if err != nil { results.Results[i].Error = common.ServerError( errors.Trace(err)) continue } rspec = spec } results.Results[i].Error = common.ServerError( m.ctlrState.UpdateModelConfigDefaultValues(nil, arg.Keys, rspec), ) } return results, nil }
go
func (m *ModelManagerAPI) UnsetModelDefaults(args params.UnsetModelDefaults) (params.ErrorResults, error) { results := params.ErrorResults{Results: make([]params.ErrorResult, len(args.Keys))} if !m.isAdmin { return results, common.ErrPerm } if err := m.check.ChangeAllowed(); err != nil { return results, errors.Trace(err) } for i, arg := range args.Keys { var rspec *environs.CloudRegionSpec if arg.CloudTag != "" { spec, err := m.makeRegionSpec(arg.CloudTag, arg.CloudRegion) if err != nil { results.Results[i].Error = common.ServerError( errors.Trace(err)) continue } rspec = spec } results.Results[i].Error = common.ServerError( m.ctlrState.UpdateModelConfigDefaultValues(nil, arg.Keys, rspec), ) } return results, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "UnsetModelDefaults", "(", "args", "params", ".", "UnsetModelDefaults", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "results", ":=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Keys", ")", ")", "}", "\n", "if", "!", "m", ".", "isAdmin", "{", "return", "results", ",", "common", ".", "ErrPerm", "\n", "}", "\n\n", "if", "err", ":=", "m", ".", "check", ".", "ChangeAllowed", "(", ")", ";", "err", "!=", "nil", "{", "return", "results", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Keys", "{", "var", "rspec", "*", "environs", ".", "CloudRegionSpec", "\n", "if", "arg", ".", "CloudTag", "!=", "\"", "\"", "{", "spec", ",", "err", ":=", "m", ".", "makeRegionSpec", "(", "arg", ".", "CloudTag", ",", "arg", ".", "CloudRegion", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "errors", ".", "Trace", "(", "err", ")", ")", "\n", "continue", "\n", "}", "\n", "rspec", "=", "spec", "\n", "}", "\n", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "m", ".", "ctlrState", ".", "UpdateModelConfigDefaultValues", "(", "nil", ",", "arg", ".", "Keys", ",", "rspec", ")", ",", ")", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// UnsetModelDefaults removes the specified default model settings.
[ "UnsetModelDefaults", "removes", "the", "specified", "default", "model", "settings", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1434-L1460
3,318
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
makeRegionSpec
func (m *ModelManagerAPI) makeRegionSpec(cloudTag, r string) (*environs.CloudRegionSpec, error) { cTag, err := names.ParseCloudTag(cloudTag) if err != nil { return nil, errors.Trace(err) } rspec, err := environs.NewCloudRegionSpec(cTag.Id(), r) if err != nil { return nil, errors.Trace(err) } return rspec, nil }
go
func (m *ModelManagerAPI) makeRegionSpec(cloudTag, r string) (*environs.CloudRegionSpec, error) { cTag, err := names.ParseCloudTag(cloudTag) if err != nil { return nil, errors.Trace(err) } rspec, err := environs.NewCloudRegionSpec(cTag.Id(), r) if err != nil { return nil, errors.Trace(err) } return rspec, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "makeRegionSpec", "(", "cloudTag", ",", "r", "string", ")", "(", "*", "environs", ".", "CloudRegionSpec", ",", "error", ")", "{", "cTag", ",", "err", ":=", "names", ".", "ParseCloudTag", "(", "cloudTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "rspec", ",", "err", ":=", "environs", ".", "NewCloudRegionSpec", "(", "cTag", ".", "Id", "(", ")", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "rspec", ",", "nil", "\n", "}" ]
// makeRegionSpec is a helper method for methods that call // state.UpdateModelConfigDefaultValues.
[ "makeRegionSpec", "is", "a", "helper", "method", "for", "methods", "that", "call", "state", ".", "UpdateModelConfigDefaultValues", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1464-L1474
3,319
juju/juju
apiserver/facades/client/modelmanager/modelmanager.go
ChangeModelCredential
func (m *ModelManagerAPI) ChangeModelCredential(args params.ChangeModelCredentialsParams) (params.ErrorResults, error) { if err := m.check.ChangeAllowed(); err != nil { return params.ErrorResults{}, errors.Trace(err) } controllerAdmin, err := m.authorizer.HasPermission(permission.SuperuserAccess, m.state.ControllerTag()) if err != nil { return params.ErrorResults{}, errors.Trace(err) } // Only controller or model admin can change cloud credential on a model. checkModelAccess := func(tag names.ModelTag) error { if controllerAdmin { return nil } modelAdmin, err := m.authorizer.HasPermission(permission.AdminAccess, tag) if err != nil { return errors.Trace(err) } if modelAdmin { return nil } return common.ErrPerm } replaceModelCredential := func(arg params.ChangeModelCredentialParams) error { modelTag, err := names.ParseModelTag(arg.ModelTag) if err != nil { return errors.Trace(err) } if err := checkModelAccess(modelTag); err != nil { return errors.Trace(err) } credentialTag, err := names.ParseCloudCredentialTag(arg.CloudCredentialTag) if err != nil { return errors.Trace(err) } model, releaser, err := m.state.GetModel(modelTag.Id()) if err != nil { return errors.Trace(err) } defer releaser() updated, err := model.SetCloudCredential(credentialTag) if err != nil { return errors.Trace(err) } if !updated { return errors.Errorf("model %v already uses credential %v", modelTag.Id(), credentialTag.Id()) } return nil } results := make([]params.ErrorResult, len(args.Models)) for i, arg := range args.Models { if err := replaceModelCredential(arg); err != nil { results[i].Error = common.ServerError(err) } } return params.ErrorResults{results}, nil }
go
func (m *ModelManagerAPI) ChangeModelCredential(args params.ChangeModelCredentialsParams) (params.ErrorResults, error) { if err := m.check.ChangeAllowed(); err != nil { return params.ErrorResults{}, errors.Trace(err) } controllerAdmin, err := m.authorizer.HasPermission(permission.SuperuserAccess, m.state.ControllerTag()) if err != nil { return params.ErrorResults{}, errors.Trace(err) } // Only controller or model admin can change cloud credential on a model. checkModelAccess := func(tag names.ModelTag) error { if controllerAdmin { return nil } modelAdmin, err := m.authorizer.HasPermission(permission.AdminAccess, tag) if err != nil { return errors.Trace(err) } if modelAdmin { return nil } return common.ErrPerm } replaceModelCredential := func(arg params.ChangeModelCredentialParams) error { modelTag, err := names.ParseModelTag(arg.ModelTag) if err != nil { return errors.Trace(err) } if err := checkModelAccess(modelTag); err != nil { return errors.Trace(err) } credentialTag, err := names.ParseCloudCredentialTag(arg.CloudCredentialTag) if err != nil { return errors.Trace(err) } model, releaser, err := m.state.GetModel(modelTag.Id()) if err != nil { return errors.Trace(err) } defer releaser() updated, err := model.SetCloudCredential(credentialTag) if err != nil { return errors.Trace(err) } if !updated { return errors.Errorf("model %v already uses credential %v", modelTag.Id(), credentialTag.Id()) } return nil } results := make([]params.ErrorResult, len(args.Models)) for i, arg := range args.Models { if err := replaceModelCredential(arg); err != nil { results[i].Error = common.ServerError(err) } } return params.ErrorResults{results}, nil }
[ "func", "(", "m", "*", "ModelManagerAPI", ")", "ChangeModelCredential", "(", "args", "params", ".", "ChangeModelCredentialsParams", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "if", "err", ":=", "m", ".", "check", ".", "ChangeAllowed", "(", ")", ";", "err", "!=", "nil", "{", "return", "params", ".", "ErrorResults", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "controllerAdmin", ",", "err", ":=", "m", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "SuperuserAccess", ",", "m", ".", "state", ".", "ControllerTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "ErrorResults", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// Only controller or model admin can change cloud credential on a model.", "checkModelAccess", ":=", "func", "(", "tag", "names", ".", "ModelTag", ")", "error", "{", "if", "controllerAdmin", "{", "return", "nil", "\n", "}", "\n", "modelAdmin", ",", "err", ":=", "m", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "AdminAccess", ",", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "modelAdmin", "{", "return", "nil", "\n", "}", "\n", "return", "common", ".", "ErrPerm", "\n", "}", "\n\n", "replaceModelCredential", ":=", "func", "(", "arg", "params", ".", "ChangeModelCredentialParams", ")", "error", "{", "modelTag", ",", "err", ":=", "names", ".", "ParseModelTag", "(", "arg", ".", "ModelTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "checkModelAccess", "(", "modelTag", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "credentialTag", ",", "err", ":=", "names", ".", "ParseCloudCredentialTag", "(", "arg", ".", "CloudCredentialTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "model", ",", "releaser", ",", "err", ":=", "m", ".", "state", ".", "GetModel", "(", "modelTag", ".", "Id", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "defer", "releaser", "(", ")", "\n\n", "updated", ",", "err", ":=", "model", ".", "SetCloudCredential", "(", "credentialTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "updated", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "modelTag", ".", "Id", "(", ")", ",", "credentialTag", ".", "Id", "(", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "results", ":=", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Models", ")", ")", "\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Models", "{", "if", "err", ":=", "replaceModelCredential", "(", "arg", ")", ";", "err", "!=", "nil", "{", "results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "params", ".", "ErrorResults", "{", "results", "}", ",", "nil", "\n", "}" ]
// ChangeModelCredentials changes cloud credential reference for models. // These new cloud credentials must already exist on the controller.
[ "ChangeModelCredentials", "changes", "cloud", "credential", "reference", "for", "models", ".", "These", "new", "cloud", "credentials", "must", "already", "exist", "on", "the", "controller", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/modelmanager/modelmanager.go#L1508-L1567
3,320
juju/juju
api/uniter/unit.go
UnitStatus
func (u *Unit) UnitStatus() (params.StatusResult, error) { var results params.StatusResults args := params.Entities{ Entities: []params.Entity{ {Tag: u.tag.String()}, }, } err := u.st.facade.FacadeCall("UnitStatus", args, &results) if err != nil { return params.StatusResult{}, errors.Trace(err) } if len(results.Results) != 1 { return params.StatusResult{}, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return params.StatusResult{}, result.Error } return result, nil }
go
func (u *Unit) UnitStatus() (params.StatusResult, error) { var results params.StatusResults args := params.Entities{ Entities: []params.Entity{ {Tag: u.tag.String()}, }, } err := u.st.facade.FacadeCall("UnitStatus", args, &results) if err != nil { return params.StatusResult{}, errors.Trace(err) } if len(results.Results) != 1 { return params.StatusResult{}, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return params.StatusResult{}, result.Error } return result, nil }
[ "func", "(", "u", "*", "Unit", ")", "UnitStatus", "(", ")", "(", "params", ".", "StatusResult", ",", "error", ")", "{", "var", "results", "params", ".", "StatusResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", "}", ",", "}", ",", "}", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "StatusResult", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "params", ".", "StatusResult", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "params", ".", "StatusResult", "{", "}", ",", "result", ".", "Error", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// UnitStatus gets the status details of the unit.
[ "UnitStatus", "gets", "the", "status", "details", "of", "the", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L96-L115
3,321
juju/juju
api/uniter/unit.go
AddMetrics
func (u *Unit) AddMetrics(metrics []params.Metric) error { var result params.ErrorResults args := params.MetricsParams{ Metrics: []params.MetricsParam{{ Tag: u.tag.String(), Metrics: metrics, }}, } err := u.st.facade.FacadeCall("AddMetrics", args, &result) if err != nil { return errors.Annotate(err, "unable to add metric") } return result.OneError() }
go
func (u *Unit) AddMetrics(metrics []params.Metric) error { var result params.ErrorResults args := params.MetricsParams{ Metrics: []params.MetricsParam{{ Tag: u.tag.String(), Metrics: metrics, }}, } err := u.st.facade.FacadeCall("AddMetrics", args, &result) if err != nil { return errors.Annotate(err, "unable to add metric") } return result.OneError() }
[ "func", "(", "u", "*", "Unit", ")", "AddMetrics", "(", "metrics", "[", "]", "params", ".", "Metric", ")", "error", "{", "var", "result", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "MetricsParams", "{", "Metrics", ":", "[", "]", "params", ".", "MetricsParam", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", ",", "Metrics", ":", "metrics", ",", "}", "}", ",", "}", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "result", ".", "OneError", "(", ")", "\n", "}" ]
// AddMetrics adds the metrics for the unit.
[ "AddMetrics", "adds", "the", "metrics", "for", "the", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L137-L150
3,322
juju/juju
api/uniter/unit.go
AddMetricBatches
func (u *Unit) AddMetricBatches(batches []params.MetricBatch) (map[string]error, error) { p := params.MetricBatchParams{ Batches: make([]params.MetricBatchParam, len(batches)), } batchResults := make(map[string]error, len(batches)) for i, batch := range batches { p.Batches[i].Tag = u.tag.String() p.Batches[i].Batch = batch batchResults[batch.UUID] = nil } results := new(params.ErrorResults) err := u.st.facade.FacadeCall("AddMetricBatches", p, results) if err != nil { return nil, errors.Annotate(err, "failed to send metric batches") } for i, result := range results.Results { batchResults[batches[i].UUID] = result.Error } return batchResults, nil }
go
func (u *Unit) AddMetricBatches(batches []params.MetricBatch) (map[string]error, error) { p := params.MetricBatchParams{ Batches: make([]params.MetricBatchParam, len(batches)), } batchResults := make(map[string]error, len(batches)) for i, batch := range batches { p.Batches[i].Tag = u.tag.String() p.Batches[i].Batch = batch batchResults[batch.UUID] = nil } results := new(params.ErrorResults) err := u.st.facade.FacadeCall("AddMetricBatches", p, results) if err != nil { return nil, errors.Annotate(err, "failed to send metric batches") } for i, result := range results.Results { batchResults[batches[i].UUID] = result.Error } return batchResults, nil }
[ "func", "(", "u", "*", "Unit", ")", "AddMetricBatches", "(", "batches", "[", "]", "params", ".", "MetricBatch", ")", "(", "map", "[", "string", "]", "error", ",", "error", ")", "{", "p", ":=", "params", ".", "MetricBatchParams", "{", "Batches", ":", "make", "(", "[", "]", "params", ".", "MetricBatchParam", ",", "len", "(", "batches", ")", ")", ",", "}", "\n\n", "batchResults", ":=", "make", "(", "map", "[", "string", "]", "error", ",", "len", "(", "batches", ")", ")", "\n\n", "for", "i", ",", "batch", ":=", "range", "batches", "{", "p", ".", "Batches", "[", "i", "]", ".", "Tag", "=", "u", ".", "tag", ".", "String", "(", ")", "\n", "p", ".", "Batches", "[", "i", "]", ".", "Batch", "=", "batch", "\n\n", "batchResults", "[", "batch", ".", "UUID", "]", "=", "nil", "\n", "}", "\n", "results", ":=", "new", "(", "params", ".", "ErrorResults", ")", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "p", ",", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "for", "i", ",", "result", ":=", "range", "results", ".", "Results", "{", "batchResults", "[", "batches", "[", "i", "]", ".", "UUID", "]", "=", "result", ".", "Error", "\n", "}", "\n", "return", "batchResults", ",", "nil", "\n", "}" ]
// AddMetricsBatches makes an api call to the uniter requesting it to store metrics batches in state.
[ "AddMetricsBatches", "makes", "an", "api", "call", "to", "the", "uniter", "requesting", "it", "to", "store", "metrics", "batches", "in", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L153-L175
3,323
juju/juju
api/uniter/unit.go
Watch
func (u *Unit) Watch() (watcher.NotifyWatcher, error) { return common.Watch(u.st.facade, "Watch", u.tag) }
go
func (u *Unit) Watch() (watcher.NotifyWatcher, error) { return common.Watch(u.st.facade, "Watch", u.tag) }
[ "func", "(", "u", "*", "Unit", ")", "Watch", "(", ")", "(", "watcher", ".", "NotifyWatcher", ",", "error", ")", "{", "return", "common", ".", "Watch", "(", "u", ".", "st", ".", "facade", ",", "\"", "\"", ",", "u", ".", "tag", ")", "\n", "}" ]
// Watch returns a watcher for observing changes to the unit.
[ "Watch", "returns", "a", "watcher", "for", "observing", "changes", "to", "the", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L192-L194
3,324
juju/juju
api/uniter/unit.go
Application
func (u *Unit) Application() (*Application, error) { application := &Application{ st: u.st, tag: u.ApplicationTag(), } // Call Refresh() immediately to get the up-to-date // life and other needed locally cached fields. err := application.Refresh() if err != nil { return nil, err } return application, nil }
go
func (u *Unit) Application() (*Application, error) { application := &Application{ st: u.st, tag: u.ApplicationTag(), } // Call Refresh() immediately to get the up-to-date // life and other needed locally cached fields. err := application.Refresh() if err != nil { return nil, err } return application, nil }
[ "func", "(", "u", "*", "Unit", ")", "Application", "(", ")", "(", "*", "Application", ",", "error", ")", "{", "application", ":=", "&", "Application", "{", "st", ":", "u", ".", "st", ",", "tag", ":", "u", ".", "ApplicationTag", "(", ")", ",", "}", "\n", "// Call Refresh() immediately to get the up-to-date", "// life and other needed locally cached fields.", "err", ":=", "application", ".", "Refresh", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "application", ",", "nil", "\n", "}" ]
// Application returns the unit's application.
[ "Application", "returns", "the", "unit", "s", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L219-L231
3,325
juju/juju
api/uniter/unit.go
ApplicationName
func (u *Unit) ApplicationName() string { application, err := names.UnitApplication(u.Name()) if err != nil { panic(err) } return application }
go
func (u *Unit) ApplicationName() string { application, err := names.UnitApplication(u.Name()) if err != nil { panic(err) } return application }
[ "func", "(", "u", "*", "Unit", ")", "ApplicationName", "(", ")", "string", "{", "application", ",", "err", ":=", "names", ".", "UnitApplication", "(", "u", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "application", "\n", "}" ]
// ApplicationName returns the application name.
[ "ApplicationName", "returns", "the", "application", "name", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L257-L263
3,326
juju/juju
api/uniter/unit.go
DestroyAllSubordinates
func (u *Unit) DestroyAllSubordinates() error { var result params.ErrorResults args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } err := u.st.facade.FacadeCall("DestroyAllSubordinates", args, &result) if err != nil { return err } return result.OneError() }
go
func (u *Unit) DestroyAllSubordinates() error { var result params.ErrorResults args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } err := u.st.facade.FacadeCall("DestroyAllSubordinates", args, &result) if err != nil { return err } return result.OneError() }
[ "func", "(", "u", "*", "Unit", ")", "DestroyAllSubordinates", "(", ")", "error", "{", "var", "result", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "result", ".", "OneError", "(", ")", "\n", "}" ]
// DestroyAllSubordinates destroys all subordinates of the unit.
[ "DestroyAllSubordinates", "destroys", "all", "subordinates", "of", "the", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L288-L298
3,327
juju/juju
api/uniter/unit.go
HasSubordinates
func (u *Unit) HasSubordinates() (bool, error) { var results params.BoolResults args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } err := u.st.facade.FacadeCall("HasSubordinates", args, &results) if err != nil { return false, err } if len(results.Results) != 1 { return false, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return false, result.Error } return result.Result, nil }
go
func (u *Unit) HasSubordinates() (bool, error) { var results params.BoolResults args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } err := u.st.facade.FacadeCall("HasSubordinates", args, &results) if err != nil { return false, err } if len(results.Results) != 1 { return false, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return false, result.Error } return result.Result, nil }
[ "func", "(", "u", "*", "Unit", ")", "HasSubordinates", "(", ")", "(", "bool", ",", "error", ")", "{", "var", "results", "params", ".", "BoolResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "false", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "false", ",", "result", ".", "Error", "\n", "}", "\n", "return", "result", ".", "Result", ",", "nil", "\n", "}" ]
// HasSubordinates returns the tags of any subordinate units.
[ "HasSubordinates", "returns", "the", "tags", "of", "any", "subordinate", "units", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L359-L376
3,328
juju/juju
api/uniter/unit.go
ClosePorts
func (u *Unit) ClosePorts(protocol string, fromPort, toPort int) error { var result params.ErrorResults args := params.EntitiesPortRanges{ Entities: []params.EntityPortRange{{ Tag: u.tag.String(), Protocol: protocol, FromPort: fromPort, ToPort: toPort, }}, } err := u.st.facade.FacadeCall("ClosePorts", args, &result) if err != nil { return err } return result.OneError() }
go
func (u *Unit) ClosePorts(protocol string, fromPort, toPort int) error { var result params.ErrorResults args := params.EntitiesPortRanges{ Entities: []params.EntityPortRange{{ Tag: u.tag.String(), Protocol: protocol, FromPort: fromPort, ToPort: toPort, }}, } err := u.st.facade.FacadeCall("ClosePorts", args, &result) if err != nil { return err } return result.OneError() }
[ "func", "(", "u", "*", "Unit", ")", "ClosePorts", "(", "protocol", "string", ",", "fromPort", ",", "toPort", "int", ")", "error", "{", "var", "result", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "EntitiesPortRanges", "{", "Entities", ":", "[", "]", "params", ".", "EntityPortRange", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", ",", "Protocol", ":", "protocol", ",", "FromPort", ":", "fromPort", ",", "ToPort", ":", "toPort", ",", "}", "}", ",", "}", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "result", ".", "OneError", "(", ")", "\n", "}" ]
// ClosePorts sets the policy of the port range with protocol to be // closed.
[ "ClosePorts", "sets", "the", "policy", "of", "the", "port", "range", "with", "protocol", "to", "be", "closed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L472-L487
3,329
juju/juju
api/uniter/unit.go
WatchActionNotifications
func (u *Unit) WatchActionNotifications() (watcher.StringsWatcher, error) { var results params.StringsWatchResults args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } err := u.st.facade.FacadeCall("WatchActionNotifications", args, &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } w := apiwatcher.NewStringsWatcher(u.st.facade.RawAPICaller(), result) return w, nil }
go
func (u *Unit) WatchActionNotifications() (watcher.StringsWatcher, error) { var results params.StringsWatchResults args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } err := u.st.facade.FacadeCall("WatchActionNotifications", args, &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } w := apiwatcher.NewStringsWatcher(u.st.facade.RawAPICaller(), result) return w, nil }
[ "func", "(", "u", "*", "Unit", ")", "WatchActionNotifications", "(", ")", "(", "watcher", ".", "StringsWatcher", ",", "error", ")", "{", "var", "results", "params", ".", "StringsWatchResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "w", ":=", "apiwatcher", ".", "NewStringsWatcher", "(", "u", ".", "st", ".", "facade", ".", "RawAPICaller", "(", ")", ",", "result", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchActionNotifications returns a StringsWatcher for observing the // ids of Actions added to the Unit. The initial event will contain the // ids of any Actions pending at the time the Watcher is made.
[ "WatchActionNotifications", "returns", "a", "StringsWatcher", "for", "observing", "the", "ids", "of", "Actions", "added", "to", "the", "Unit", ".", "The", "initial", "event", "will", "contain", "the", "ids", "of", "any", "Actions", "pending", "at", "the", "time", "the", "Watcher", "is", "made", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L605-L623
3,330
juju/juju
api/uniter/unit.go
UpgradeSeriesStatus
func (u *Unit) UpgradeSeriesStatus() (model.UpgradeSeriesStatus, error) { res, err := u.st.UpgradeSeriesUnitStatus() if err != nil { return "", errors.Trace(err) } if len(res) != 1 { return "", errors.Errorf("expected 1 result, got %d", len(res)) } return res[0], nil }
go
func (u *Unit) UpgradeSeriesStatus() (model.UpgradeSeriesStatus, error) { res, err := u.st.UpgradeSeriesUnitStatus() if err != nil { return "", errors.Trace(err) } if len(res) != 1 { return "", errors.Errorf("expected 1 result, got %d", len(res)) } return res[0], nil }
[ "func", "(", "u", "*", "Unit", ")", "UpgradeSeriesStatus", "(", ")", "(", "model", ".", "UpgradeSeriesStatus", ",", "error", ")", "{", "res", ",", "err", ":=", "u", ".", "st", ".", "UpgradeSeriesUnitStatus", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "res", ")", "!=", "1", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "res", ")", ")", "\n", "}", "\n", "return", "res", "[", "0", "]", ",", "nil", "\n", "}" ]
// UpgradeSeriesStatus returns the upgrade series status of a unit from remote state
[ "UpgradeSeriesStatus", "returns", "the", "upgrade", "series", "status", "of", "a", "unit", "from", "remote", "state" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L632-L641
3,331
juju/juju
api/uniter/unit.go
SetUpgradeSeriesStatus
func (u *Unit) SetUpgradeSeriesStatus(status model.UpgradeSeriesStatus, reason string) error { return u.st.SetUpgradeSeriesUnitStatus(status, reason) }
go
func (u *Unit) SetUpgradeSeriesStatus(status model.UpgradeSeriesStatus, reason string) error { return u.st.SetUpgradeSeriesUnitStatus(status, reason) }
[ "func", "(", "u", "*", "Unit", ")", "SetUpgradeSeriesStatus", "(", "status", "model", ".", "UpgradeSeriesStatus", ",", "reason", "string", ")", "error", "{", "return", "u", ".", "st", ".", "SetUpgradeSeriesUnitStatus", "(", "status", ",", "reason", ")", "\n", "}" ]
// SetUpgradeSeriesStatus sets the upgrade series status of the unit in the remote state
[ "SetUpgradeSeriesStatus", "sets", "the", "upgrade", "series", "status", "of", "the", "unit", "in", "the", "remote", "state" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L644-L646
3,332
juju/juju
api/uniter/unit.go
RequestReboot
func (u *Unit) RequestReboot() error { machineId, err := u.AssignedMachine() if err != nil { return err } var result params.ErrorResults args := params.Entities{ Entities: []params.Entity{{Tag: machineId.String()}}, } err = u.st.facade.FacadeCall("RequestReboot", args, &result) if err != nil { return err } return result.OneError() }
go
func (u *Unit) RequestReboot() error { machineId, err := u.AssignedMachine() if err != nil { return err } var result params.ErrorResults args := params.Entities{ Entities: []params.Entity{{Tag: machineId.String()}}, } err = u.st.facade.FacadeCall("RequestReboot", args, &result) if err != nil { return err } return result.OneError() }
[ "func", "(", "u", "*", "Unit", ")", "RequestReboot", "(", ")", "error", "{", "machineId", ",", "err", ":=", "u", ".", "AssignedMachine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "result", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "machineId", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "err", "=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "result", ".", "OneError", "(", ")", "\n", "}" ]
// RequestReboot sets the reboot flag for its machine agent
[ "RequestReboot", "sets", "the", "reboot", "flag", "for", "its", "machine", "agent" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L649-L663
3,333
juju/juju
api/uniter/unit.go
RelationsStatus
func (u *Unit) RelationsStatus() ([]RelationStatus, error) { args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } var results params.RelationUnitStatusResults err := u.st.facade.FacadeCall("RelationsStatus", args, &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } var statusResult []RelationStatus for _, result := range result.RelationResults { tag, err := names.ParseRelationTag(result.RelationTag) if err != nil { return nil, err } statusResult = append(statusResult, RelationStatus{ Tag: tag, InScope: result.InScope, Suspended: result.Suspended, }) } return statusResult, nil }
go
func (u *Unit) RelationsStatus() ([]RelationStatus, error) { args := params.Entities{ Entities: []params.Entity{{Tag: u.tag.String()}}, } var results params.RelationUnitStatusResults err := u.st.facade.FacadeCall("RelationsStatus", args, &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } var statusResult []RelationStatus for _, result := range result.RelationResults { tag, err := names.ParseRelationTag(result.RelationTag) if err != nil { return nil, err } statusResult = append(statusResult, RelationStatus{ Tag: tag, InScope: result.InScope, Suspended: result.Suspended, }) } return statusResult, nil }
[ "func", "(", "u", "*", "Unit", ")", "RelationsStatus", "(", ")", "(", "[", "]", "RelationStatus", ",", "error", ")", "{", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "u", ".", "tag", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "var", "results", "params", ".", "RelationUnitStatusResults", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "var", "statusResult", "[", "]", "RelationStatus", "\n", "for", "_", ",", "result", ":=", "range", "result", ".", "RelationResults", "{", "tag", ",", "err", ":=", "names", ".", "ParseRelationTag", "(", "result", ".", "RelationTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "statusResult", "=", "append", "(", "statusResult", ",", "RelationStatus", "{", "Tag", ":", "tag", ",", "InScope", ":", "result", ".", "InScope", ",", "Suspended", ":", "result", ".", "Suspended", ",", "}", ")", "\n", "}", "\n", "return", "statusResult", ",", "nil", "\n", "}" ]
// RelationsInScope returns the tags of the relations the unit has joined // and entered scope, or the relation is suspended.
[ "RelationsInScope", "returns", "the", "tags", "of", "the", "relations", "the", "unit", "has", "joined", "and", "entered", "scope", "or", "the", "relation", "is", "suspended", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L679-L708
3,334
juju/juju
api/uniter/unit.go
WatchStorage
func (u *Unit) WatchStorage() (watcher.StringsWatcher, error) { return u.st.WatchUnitStorageAttachments(u.tag) }
go
func (u *Unit) WatchStorage() (watcher.StringsWatcher, error) { return u.st.WatchUnitStorageAttachments(u.tag) }
[ "func", "(", "u", "*", "Unit", ")", "WatchStorage", "(", ")", "(", "watcher", ".", "StringsWatcher", ",", "error", ")", "{", "return", "u", ".", "st", ".", "WatchUnitStorageAttachments", "(", "u", ".", "tag", ")", "\n", "}" ]
// WatchStorage returns a watcher for observing changes to the // unit's storage attachments.
[ "WatchStorage", "returns", "a", "watcher", "for", "observing", "changes", "to", "the", "unit", "s", "storage", "attachments", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L754-L756
3,335
juju/juju
api/uniter/unit.go
AddStorage
func (u *Unit) AddStorage(constraints map[string][]params.StorageConstraints) error { if u.st.facade.BestAPIVersion() < 2 { return errors.NotImplementedf("AddStorage() (need V2+)") } all := make([]params.StorageAddParams, 0, len(constraints)) for storage, cons := range constraints { for _, one := range cons { all = append(all, params.StorageAddParams{ UnitTag: u.Tag().String(), StorageName: storage, Constraints: one, }) } } args := params.StoragesAddParams{Storages: all} var results params.ErrorResults err := u.st.facade.FacadeCall("AddUnitStorage", args, &results) if err != nil { return err } return results.Combine() }
go
func (u *Unit) AddStorage(constraints map[string][]params.StorageConstraints) error { if u.st.facade.BestAPIVersion() < 2 { return errors.NotImplementedf("AddStorage() (need V2+)") } all := make([]params.StorageAddParams, 0, len(constraints)) for storage, cons := range constraints { for _, one := range cons { all = append(all, params.StorageAddParams{ UnitTag: u.Tag().String(), StorageName: storage, Constraints: one, }) } } args := params.StoragesAddParams{Storages: all} var results params.ErrorResults err := u.st.facade.FacadeCall("AddUnitStorage", args, &results) if err != nil { return err } return results.Combine() }
[ "func", "(", "u", "*", "Unit", ")", "AddStorage", "(", "constraints", "map", "[", "string", "]", "[", "]", "params", ".", "StorageConstraints", ")", "error", "{", "if", "u", ".", "st", ".", "facade", ".", "BestAPIVersion", "(", ")", "<", "2", "{", "return", "errors", ".", "NotImplementedf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "all", ":=", "make", "(", "[", "]", "params", ".", "StorageAddParams", ",", "0", ",", "len", "(", "constraints", ")", ")", "\n", "for", "storage", ",", "cons", ":=", "range", "constraints", "{", "for", "_", ",", "one", ":=", "range", "cons", "{", "all", "=", "append", "(", "all", ",", "params", ".", "StorageAddParams", "{", "UnitTag", ":", "u", ".", "Tag", "(", ")", ".", "String", "(", ")", ",", "StorageName", ":", "storage", ",", "Constraints", ":", "one", ",", "}", ")", "\n", "}", "\n", "}", "\n\n", "args", ":=", "params", ".", "StoragesAddParams", "{", "Storages", ":", "all", "}", "\n", "var", "results", "params", ".", "ErrorResults", "\n", "err", ":=", "u", ".", "st", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "results", ".", "Combine", "(", ")", "\n", "}" ]
// AddStorage adds desired storage instances to a unit.
[ "AddStorage", "adds", "desired", "storage", "instances", "to", "a", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/unit.go#L759-L783
3,336
juju/juju
state/backups/backups.go
StoreArchive
func StoreArchive(stor filestorage.FileStorage, meta *Metadata, file io.Reader) error { id, err := stor.Add(meta, file) if err != nil { return errors.Trace(err) } meta.SetID(id) stored, err := stor.Metadata(id) if err != nil { return errors.Trace(err) } meta.SetStored(stored.Stored()) return nil }
go
func StoreArchive(stor filestorage.FileStorage, meta *Metadata, file io.Reader) error { id, err := stor.Add(meta, file) if err != nil { return errors.Trace(err) } meta.SetID(id) stored, err := stor.Metadata(id) if err != nil { return errors.Trace(err) } meta.SetStored(stored.Stored()) return nil }
[ "func", "StoreArchive", "(", "stor", "filestorage", ".", "FileStorage", ",", "meta", "*", "Metadata", ",", "file", "io", ".", "Reader", ")", "error", "{", "id", ",", "err", ":=", "stor", ".", "Add", "(", "meta", ",", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "meta", ".", "SetID", "(", "id", ")", "\n", "stored", ",", "err", ":=", "stor", ".", "Metadata", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "meta", ".", "SetStored", "(", "stored", ".", "Stored", "(", ")", ")", "\n", "return", "nil", "\n", "}" ]
// StoreArchive sends the backup archive and its metadata to storage. // It also sets the metadata's ID and Stored values.
[ "StoreArchive", "sends", "the", "backup", "archive", "and", "its", "metadata", "to", "storage", ".", "It", "also", "sets", "the", "metadata", "s", "ID", "and", "Stored", "values", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/backups.go#L73-L85
3,337
juju/juju
state/backups/backups.go
NewBackups
func NewBackups(stor filestorage.FileStorage) Backups { b := backups{ storage: stor, } return &b }
go
func NewBackups(stor filestorage.FileStorage) Backups { b := backups{ storage: stor, } return &b }
[ "func", "NewBackups", "(", "stor", "filestorage", ".", "FileStorage", ")", "Backups", "{", "b", ":=", "backups", "{", "storage", ":", "stor", ",", "}", "\n", "return", "&", "b", "\n", "}" ]
// NewBackups creates a new Backups value using the FileStorage provided.
[ "NewBackups", "creates", "a", "new", "Backups", "value", "using", "the", "FileStorage", "provided", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/backups.go#L116-L121
3,338
juju/juju
state/backups/backups.go
Add
func (b *backups) Add(archive io.Reader, meta *Metadata) (string, error) { // Store the archive. err := storeArchive(b.storage, meta, archive) if err != nil { return "", errors.Annotate(err, "while storing backup archive") } return meta.ID(), nil }
go
func (b *backups) Add(archive io.Reader, meta *Metadata) (string, error) { // Store the archive. err := storeArchive(b.storage, meta, archive) if err != nil { return "", errors.Annotate(err, "while storing backup archive") } return meta.ID(), nil }
[ "func", "(", "b", "*", "backups", ")", "Add", "(", "archive", "io", ".", "Reader", ",", "meta", "*", "Metadata", ")", "(", "string", ",", "error", ")", "{", "// Store the archive.", "err", ":=", "storeArchive", "(", "b", ".", "storage", ",", "meta", ",", "archive", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "meta", ".", "ID", "(", ")", ",", "nil", "\n", "}" ]
// Add stores the backup archive and returns its new ID.
[ "Add", "stores", "the", "backup", "archive", "and", "returns", "its", "new", "ID", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/backups.go#L175-L183
3,339
juju/juju
state/backups/backups.go
Get
func (b *backups) Get(id string) (*Metadata, io.ReadCloser, error) { if strings.Contains(id, TempFilename) { return b.getArchiveFromFilename(id) } rawmeta, archiveFile, err := b.storage.Get(id) if err != nil { return nil, nil, errors.Trace(err) } meta, ok := rawmeta.(*Metadata) if !ok { return nil, nil, errors.New("did not get a backups.Metadata value from storage") } return meta, archiveFile, nil }
go
func (b *backups) Get(id string) (*Metadata, io.ReadCloser, error) { if strings.Contains(id, TempFilename) { return b.getArchiveFromFilename(id) } rawmeta, archiveFile, err := b.storage.Get(id) if err != nil { return nil, nil, errors.Trace(err) } meta, ok := rawmeta.(*Metadata) if !ok { return nil, nil, errors.New("did not get a backups.Metadata value from storage") } return meta, archiveFile, nil }
[ "func", "(", "b", "*", "backups", ")", "Get", "(", "id", "string", ")", "(", "*", "Metadata", ",", "io", ".", "ReadCloser", ",", "error", ")", "{", "if", "strings", ".", "Contains", "(", "id", ",", "TempFilename", ")", "{", "return", "b", ".", "getArchiveFromFilename", "(", "id", ")", "\n", "}", "\n", "rawmeta", ",", "archiveFile", ",", "err", ":=", "b", ".", "storage", ".", "Get", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "meta", ",", "ok", ":=", "rawmeta", ".", "(", "*", "Metadata", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "meta", ",", "archiveFile", ",", "nil", "\n", "}" ]
// Get retrieves the associated metadata and archive file from model storage. // There are two cases, the archive file can be in the juju database or // a file on the machine.
[ "Get", "retrieves", "the", "associated", "metadata", "and", "archive", "file", "from", "model", "storage", ".", "There", "are", "two", "cases", "the", "archive", "file", "can", "be", "in", "the", "juju", "database", "or", "a", "file", "on", "the", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/backups.go#L188-L203
3,340
juju/juju
state/backups/backups.go
List
func (b *backups) List() ([]*Metadata, error) { metaList, err := b.storage.List() if err != nil { return nil, errors.Trace(err) } result := make([]*Metadata, len(metaList)) for i, meta := range metaList { m, ok := meta.(*Metadata) if !ok { msg := "expected backups.Metadata value from storage for %q, got %T" return nil, errors.Errorf(msg, meta.ID(), meta) } result[i] = m } return result, nil }
go
func (b *backups) List() ([]*Metadata, error) { metaList, err := b.storage.List() if err != nil { return nil, errors.Trace(err) } result := make([]*Metadata, len(metaList)) for i, meta := range metaList { m, ok := meta.(*Metadata) if !ok { msg := "expected backups.Metadata value from storage for %q, got %T" return nil, errors.Errorf(msg, meta.ID(), meta) } result[i] = m } return result, nil }
[ "func", "(", "b", "*", "backups", ")", "List", "(", ")", "(", "[", "]", "*", "Metadata", ",", "error", ")", "{", "metaList", ",", "err", ":=", "b", ".", "storage", ".", "List", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "*", "Metadata", ",", "len", "(", "metaList", ")", ")", "\n", "for", "i", ",", "meta", ":=", "range", "metaList", "{", "m", ",", "ok", ":=", "meta", ".", "(", "*", "Metadata", ")", "\n", "if", "!", "ok", "{", "msg", ":=", "\"", "\"", "\n", "return", "nil", ",", "errors", ".", "Errorf", "(", "msg", ",", "meta", ".", "ID", "(", ")", ",", "meta", ")", "\n", "}", "\n", "result", "[", "i", "]", "=", "m", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// List returns the metadata for all stored backups.
[ "List", "returns", "the", "metadata", "for", "all", "stored", "backups", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/backups.go#L237-L252
3,341
juju/juju
state/backups/backups.go
Remove
func (b *backups) Remove(id string) error { return errors.Trace(b.storage.Remove(id)) }
go
func (b *backups) Remove(id string) error { return errors.Trace(b.storage.Remove(id)) }
[ "func", "(", "b", "*", "backups", ")", "Remove", "(", "id", "string", ")", "error", "{", "return", "errors", ".", "Trace", "(", "b", ".", "storage", ".", "Remove", "(", "id", ")", ")", "\n", "}" ]
// Remove deletes the backup from storage.
[ "Remove", "deletes", "the", "backup", "from", "storage", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/backups.go#L255-L257
3,342
juju/juju
apiserver/logsink/filewriter.go
NewFileWriter
func NewFileWriter(logPath string) (io.WriteCloser, error) { if err := primeLogFile(logPath); err != nil { // This isn't a fatal error so log and continue if priming fails. logger.Warningf("Unable to prime %s (proceeding anyway): %v", logPath, err) } return &lumberjack.Logger{ Filename: logPath, MaxSize: 300, // MB MaxBackups: 2, Compress: true, }, nil }
go
func NewFileWriter(logPath string) (io.WriteCloser, error) { if err := primeLogFile(logPath); err != nil { // This isn't a fatal error so log and continue if priming fails. logger.Warningf("Unable to prime %s (proceeding anyway): %v", logPath, err) } return &lumberjack.Logger{ Filename: logPath, MaxSize: 300, // MB MaxBackups: 2, Compress: true, }, nil }
[ "func", "NewFileWriter", "(", "logPath", "string", ")", "(", "io", ".", "WriteCloser", ",", "error", ")", "{", "if", "err", ":=", "primeLogFile", "(", "logPath", ")", ";", "err", "!=", "nil", "{", "// This isn't a fatal error so log and continue if priming fails.", "logger", ".", "Warningf", "(", "\"", "\"", ",", "logPath", ",", "err", ")", "\n", "}", "\n", "return", "&", "lumberjack", ".", "Logger", "{", "Filename", ":", "logPath", ",", "MaxSize", ":", "300", ",", "// MB", "MaxBackups", ":", "2", ",", "Compress", ":", "true", ",", "}", ",", "nil", "\n", "}" ]
// NewFileWriter returns an io.WriteCloser that will write log messages to disk.
[ "NewFileWriter", "returns", "an", "io", ".", "WriteCloser", "that", "will", "write", "log", "messages", "to", "disk", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/filewriter.go#L16-L27
3,343
juju/juju
apiserver/logsink/filewriter.go
primeLogFile
func primeLogFile(path string) error { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return errors.Trace(err) } f.Close() err = utils.ChownPath(path, "syslog") return errors.Trace(err) }
go
func primeLogFile(path string) error { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { return errors.Trace(err) } f.Close() err = utils.ChownPath(path, "syslog") return errors.Trace(err) }
[ "func", "primeLogFile", "(", "path", "string", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "OpenFile", "(", "path", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_WRONLY", ",", "0600", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "f", ".", "Close", "(", ")", "\n", "err", "=", "utils", ".", "ChownPath", "(", "path", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// primeLogFile ensures the logsink log file is created with the // correct mode and ownership.
[ "primeLogFile", "ensures", "the", "logsink", "log", "file", "is", "created", "with", "the", "correct", "mode", "and", "ownership", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink/filewriter.go#L31-L39
3,344
juju/juju
api/migrationmaster/client.go
NewClient
func NewClient(caller base.APICaller, newWatcher NewWatcherFunc) *Client { return &Client{ caller: base.NewFacadeCaller(caller, "MigrationMaster"), newWatcher: newWatcher, httpClientFactory: caller.HTTPClient, } }
go
func NewClient(caller base.APICaller, newWatcher NewWatcherFunc) *Client { return &Client{ caller: base.NewFacadeCaller(caller, "MigrationMaster"), newWatcher: newWatcher, httpClientFactory: caller.HTTPClient, } }
[ "func", "NewClient", "(", "caller", "base", ".", "APICaller", ",", "newWatcher", "NewWatcherFunc", ")", "*", "Client", "{", "return", "&", "Client", "{", "caller", ":", "base", ".", "NewFacadeCaller", "(", "caller", ",", "\"", "\"", ")", ",", "newWatcher", ":", "newWatcher", ",", "httpClientFactory", ":", "caller", ".", "HTTPClient", ",", "}", "\n", "}" ]
// NewClient returns a new Client based on an existing API connection.
[ "NewClient", "returns", "a", "new", "Client", "based", "on", "an", "existing", "API", "connection", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L32-L38
3,345
juju/juju
api/migrationmaster/client.go
Watch
func (c *Client) Watch() (watcher.NotifyWatcher, error) { var result params.NotifyWatchResult err := c.caller.FacadeCall("Watch", nil, &result) if err != nil { return nil, errors.Trace(err) } if result.Error != nil { return nil, result.Error } return c.newWatcher(c.caller.RawAPICaller(), result), nil }
go
func (c *Client) Watch() (watcher.NotifyWatcher, error) { var result params.NotifyWatchResult err := c.caller.FacadeCall("Watch", nil, &result) if err != nil { return nil, errors.Trace(err) } if result.Error != nil { return nil, result.Error } return c.newWatcher(c.caller.RawAPICaller(), result), nil }
[ "func", "(", "c", "*", "Client", ")", "Watch", "(", ")", "(", "watcher", ".", "NotifyWatcher", ",", "error", ")", "{", "var", "result", "params", ".", "NotifyWatchResult", "\n", "err", ":=", "c", ".", "caller", ".", "FacadeCall", "(", "\"", "\"", ",", "nil", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "return", "c", ".", "newWatcher", "(", "c", ".", "caller", ".", "RawAPICaller", "(", ")", ",", "result", ")", ",", "nil", "\n", "}" ]
// Watch returns a watcher which reports when a migration is active // for the model associated with the API connection.
[ "Watch", "returns", "a", "watcher", "which", "reports", "when", "a", "migration", "is", "active", "for", "the", "model", "associated", "with", "the", "API", "connection", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L50-L60
3,346
juju/juju
api/migrationmaster/client.go
SetPhase
func (c *Client) SetPhase(phase migration.Phase) error { args := params.SetMigrationPhaseArgs{ Phase: phase.String(), } return c.caller.FacadeCall("SetPhase", args, nil) }
go
func (c *Client) SetPhase(phase migration.Phase) error { args := params.SetMigrationPhaseArgs{ Phase: phase.String(), } return c.caller.FacadeCall("SetPhase", args, nil) }
[ "func", "(", "c", "*", "Client", ")", "SetPhase", "(", "phase", "migration", ".", "Phase", ")", "error", "{", "args", ":=", "params", ".", "SetMigrationPhaseArgs", "{", "Phase", ":", "phase", ".", "String", "(", ")", ",", "}", "\n", "return", "c", ".", "caller", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "nil", ")", "\n", "}" ]
// SetPhase updates the phase of the currently active model migration.
[ "SetPhase", "updates", "the", "phase", "of", "the", "currently", "active", "model", "migration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L117-L122
3,347
juju/juju
api/migrationmaster/client.go
SetStatusMessage
func (c *Client) SetStatusMessage(message string) error { args := params.SetMigrationStatusMessageArgs{ Message: message, } return c.caller.FacadeCall("SetStatusMessage", args, nil) }
go
func (c *Client) SetStatusMessage(message string) error { args := params.SetMigrationStatusMessageArgs{ Message: message, } return c.caller.FacadeCall("SetStatusMessage", args, nil) }
[ "func", "(", "c", "*", "Client", ")", "SetStatusMessage", "(", "message", "string", ")", "error", "{", "args", ":=", "params", ".", "SetMigrationStatusMessageArgs", "{", "Message", ":", "message", ",", "}", "\n", "return", "c", ".", "caller", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "nil", ")", "\n", "}" ]
// SetStatusMessage sets a human readable message regarding the // progress of a migration.
[ "SetStatusMessage", "sets", "a", "human", "readable", "message", "regarding", "the", "progress", "of", "a", "migration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L126-L131
3,348
juju/juju
api/migrationmaster/client.go
ModelInfo
func (c *Client) ModelInfo() (migration.ModelInfo, error) { var info params.MigrationModelInfo err := c.caller.FacadeCall("ModelInfo", nil, &info) if err != nil { return migration.ModelInfo{}, errors.Trace(err) } owner, err := names.ParseUserTag(info.OwnerTag) if err != nil { return migration.ModelInfo{}, errors.Trace(err) } return migration.ModelInfo{ UUID: info.UUID, Name: info.Name, Owner: owner, AgentVersion: info.AgentVersion, ControllerAgentVersion: info.ControllerAgentVersion, }, nil }
go
func (c *Client) ModelInfo() (migration.ModelInfo, error) { var info params.MigrationModelInfo err := c.caller.FacadeCall("ModelInfo", nil, &info) if err != nil { return migration.ModelInfo{}, errors.Trace(err) } owner, err := names.ParseUserTag(info.OwnerTag) if err != nil { return migration.ModelInfo{}, errors.Trace(err) } return migration.ModelInfo{ UUID: info.UUID, Name: info.Name, Owner: owner, AgentVersion: info.AgentVersion, ControllerAgentVersion: info.ControllerAgentVersion, }, nil }
[ "func", "(", "c", "*", "Client", ")", "ModelInfo", "(", ")", "(", "migration", ".", "ModelInfo", ",", "error", ")", "{", "var", "info", "params", ".", "MigrationModelInfo", "\n", "err", ":=", "c", ".", "caller", ".", "FacadeCall", "(", "\"", "\"", ",", "nil", ",", "&", "info", ")", "\n", "if", "err", "!=", "nil", "{", "return", "migration", ".", "ModelInfo", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "owner", ",", "err", ":=", "names", ".", "ParseUserTag", "(", "info", ".", "OwnerTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "migration", ".", "ModelInfo", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "migration", ".", "ModelInfo", "{", "UUID", ":", "info", ".", "UUID", ",", "Name", ":", "info", ".", "Name", ",", "Owner", ":", "owner", ",", "AgentVersion", ":", "info", ".", "AgentVersion", ",", "ControllerAgentVersion", ":", "info", ".", "ControllerAgentVersion", ",", "}", ",", "nil", "\n", "}" ]
// ModelInfo return basic information about the model to migrated.
[ "ModelInfo", "return", "basic", "information", "about", "the", "model", "to", "migrated", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L134-L151
3,349
juju/juju
api/migrationmaster/client.go
Export
func (c *Client) Export() (migration.SerializedModel, error) { var empty migration.SerializedModel var serialized params.SerializedModel err := c.caller.FacadeCall("Export", nil, &serialized) if err != nil { return empty, errors.Trace(err) } // Convert tools info to output map. tools := make(map[version.Binary]string) for _, toolsInfo := range serialized.Tools { v, err := version.ParseBinary(toolsInfo.Version) if err != nil { return migration.SerializedModel{}, errors.Annotate(err, "error parsing agent binary version") } tools[v] = toolsInfo.URI } resources, err := convertResources(serialized.Resources) if err != nil { return empty, errors.Trace(err) } return migration.SerializedModel{ Bytes: serialized.Bytes, Charms: serialized.Charms, Tools: tools, Resources: resources, }, nil }
go
func (c *Client) Export() (migration.SerializedModel, error) { var empty migration.SerializedModel var serialized params.SerializedModel err := c.caller.FacadeCall("Export", nil, &serialized) if err != nil { return empty, errors.Trace(err) } // Convert tools info to output map. tools := make(map[version.Binary]string) for _, toolsInfo := range serialized.Tools { v, err := version.ParseBinary(toolsInfo.Version) if err != nil { return migration.SerializedModel{}, errors.Annotate(err, "error parsing agent binary version") } tools[v] = toolsInfo.URI } resources, err := convertResources(serialized.Resources) if err != nil { return empty, errors.Trace(err) } return migration.SerializedModel{ Bytes: serialized.Bytes, Charms: serialized.Charms, Tools: tools, Resources: resources, }, nil }
[ "func", "(", "c", "*", "Client", ")", "Export", "(", ")", "(", "migration", ".", "SerializedModel", ",", "error", ")", "{", "var", "empty", "migration", ".", "SerializedModel", "\n", "var", "serialized", "params", ".", "SerializedModel", "\n", "err", ":=", "c", ".", "caller", ".", "FacadeCall", "(", "\"", "\"", ",", "nil", ",", "&", "serialized", ")", "\n", "if", "err", "!=", "nil", "{", "return", "empty", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Convert tools info to output map.", "tools", ":=", "make", "(", "map", "[", "version", ".", "Binary", "]", "string", ")", "\n", "for", "_", ",", "toolsInfo", ":=", "range", "serialized", ".", "Tools", "{", "v", ",", "err", ":=", "version", ".", "ParseBinary", "(", "toolsInfo", ".", "Version", ")", "\n", "if", "err", "!=", "nil", "{", "return", "migration", ".", "SerializedModel", "{", "}", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "tools", "[", "v", "]", "=", "toolsInfo", ".", "URI", "\n", "}", "\n\n", "resources", ",", "err", ":=", "convertResources", "(", "serialized", ".", "Resources", ")", "\n", "if", "err", "!=", "nil", "{", "return", "empty", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "return", "migration", ".", "SerializedModel", "{", "Bytes", ":", "serialized", ".", "Bytes", ",", "Charms", ":", "serialized", ".", "Charms", ",", "Tools", ":", "tools", ",", "Resources", ":", "resources", ",", "}", ",", "nil", "\n", "}" ]
// Export returns a serialized representation of the model associated // with the API connection. The charms used by the model are also // returned.
[ "Export", "returns", "a", "serialized", "representation", "of", "the", "model", "associated", "with", "the", "API", "connection", ".", "The", "charms", "used", "by", "the", "model", "are", "also", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L162-L191
3,350
juju/juju
api/migrationmaster/client.go
OpenResource
func (c *Client) OpenResource(application, name string) (io.ReadCloser, error) { httpClient, err := c.httpClientFactory() if err != nil { return nil, errors.Annotate(err, "unable to create HTTP client") } uri := fmt.Sprintf("/applications/%s/resources/%s", application, name) var resp *http.Response if err := httpClient.Get(uri, &resp); err != nil { return nil, errors.Annotate(err, "unable to retrieve resource") } return resp.Body, nil }
go
func (c *Client) OpenResource(application, name string) (io.ReadCloser, error) { httpClient, err := c.httpClientFactory() if err != nil { return nil, errors.Annotate(err, "unable to create HTTP client") } uri := fmt.Sprintf("/applications/%s/resources/%s", application, name) var resp *http.Response if err := httpClient.Get(uri, &resp); err != nil { return nil, errors.Annotate(err, "unable to retrieve resource") } return resp.Body, nil }
[ "func", "(", "c", "*", "Client", ")", "OpenResource", "(", "application", ",", "name", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "httpClient", ",", "err", ":=", "c", ".", "httpClientFactory", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "uri", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "application", ",", "name", ")", "\n", "var", "resp", "*", "http", ".", "Response", "\n", "if", "err", ":=", "httpClient", ".", "Get", "(", "uri", ",", "&", "resp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ".", "Body", ",", "nil", "\n", "}" ]
// OpenResource downloads the named resource for an application.
[ "OpenResource", "downloads", "the", "named", "resource", "for", "an", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L194-L206
3,351
juju/juju
api/migrationmaster/client.go
StreamModelLog
func (c *Client) StreamModelLog(start time.Time) (<-chan common.LogMessage, error) { return common.StreamDebugLog(c.caller.RawAPICaller(), common.DebugLogParams{ Replay: true, NoTail: true, StartTime: start, }) }
go
func (c *Client) StreamModelLog(start time.Time) (<-chan common.LogMessage, error) { return common.StreamDebugLog(c.caller.RawAPICaller(), common.DebugLogParams{ Replay: true, NoTail: true, StartTime: start, }) }
[ "func", "(", "c", "*", "Client", ")", "StreamModelLog", "(", "start", "time", ".", "Time", ")", "(", "<-", "chan", "common", ".", "LogMessage", ",", "error", ")", "{", "return", "common", ".", "StreamDebugLog", "(", "c", ".", "caller", ".", "RawAPICaller", "(", ")", ",", "common", ".", "DebugLogParams", "{", "Replay", ":", "true", ",", "NoTail", ":", "true", ",", "StartTime", ":", "start", ",", "}", ")", "\n", "}" ]
// StreamModelLog takes a starting time and returns a channel that // will yield the logs on or after that time - these are the logs that // need to be transferred to the target after the migration is // successful.
[ "StreamModelLog", "takes", "a", "starting", "time", "and", "returns", "a", "channel", "that", "will", "yield", "the", "logs", "on", "or", "after", "that", "time", "-", "these", "are", "the", "logs", "that", "need", "to", "be", "transferred", "to", "the", "target", "after", "the", "migration", "is", "successful", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationmaster/client.go#L267-L273
3,352
juju/juju
apiserver/facades/agent/upgrader/upgrader.go
NewUpgraderFacade
func NewUpgraderFacade(st *state.State, resources facade.Resources, auth facade.Authorizer) (Upgrader, error) { // The type of upgrader we return depends on who is asking. // Machines get an UpgraderAPI, units get a UnitUpgraderAPI. // This is tested in the api/upgrader package since there // are currently no direct srvRoot tests. // TODO(dfc) this is redundant tag, err := names.ParseTag(auth.GetAuthTag().String()) if err != nil { return nil, common.ErrPerm } switch tag.(type) { case names.MachineTag, names.ApplicationTag: return NewUpgraderAPI(st, resources, auth) case names.UnitTag: return NewUnitUpgraderAPI(st, resources, auth) } // Not a machine or unit. return nil, common.ErrPerm }
go
func NewUpgraderFacade(st *state.State, resources facade.Resources, auth facade.Authorizer) (Upgrader, error) { // The type of upgrader we return depends on who is asking. // Machines get an UpgraderAPI, units get a UnitUpgraderAPI. // This is tested in the api/upgrader package since there // are currently no direct srvRoot tests. // TODO(dfc) this is redundant tag, err := names.ParseTag(auth.GetAuthTag().String()) if err != nil { return nil, common.ErrPerm } switch tag.(type) { case names.MachineTag, names.ApplicationTag: return NewUpgraderAPI(st, resources, auth) case names.UnitTag: return NewUnitUpgraderAPI(st, resources, auth) } // Not a machine or unit. return nil, common.ErrPerm }
[ "func", "NewUpgraderFacade", "(", "st", "*", "state", ".", "State", ",", "resources", "facade", ".", "Resources", ",", "auth", "facade", ".", "Authorizer", ")", "(", "Upgrader", ",", "error", ")", "{", "// The type of upgrader we return depends on who is asking.", "// Machines get an UpgraderAPI, units get a UnitUpgraderAPI.", "// This is tested in the api/upgrader package since there", "// are currently no direct srvRoot tests.", "// TODO(dfc) this is redundant", "tag", ",", "err", ":=", "names", ".", "ParseTag", "(", "auth", ".", "GetAuthTag", "(", ")", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "switch", "tag", ".", "(", "type", ")", "{", "case", "names", ".", "MachineTag", ",", "names", ".", "ApplicationTag", ":", "return", "NewUpgraderAPI", "(", "st", ",", "resources", ",", "auth", ")", "\n", "case", "names", ".", "UnitTag", ":", "return", "NewUnitUpgraderAPI", "(", "st", ",", "resources", ",", "auth", ")", "\n", "}", "\n", "// Not a machine or unit.", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}" ]
// The upgrader facade is a bit unique vs the other API Facades, as it // has two implementations that actually expose the same API and which // one gets returned depends on who is calling. Both of them conform // to the exact Upgrader API, so the actual calls that are available // do not depend on who is currently connected. // NewUpgraderFacade provides the signature required for facade registration.
[ "The", "upgrader", "facade", "is", "a", "bit", "unique", "vs", "the", "other", "API", "Facades", "as", "it", "has", "two", "implementations", "that", "actually", "expose", "the", "same", "API", "and", "which", "one", "gets", "returned", "depends", "on", "who", "is", "calling", ".", "Both", "of", "them", "conform", "to", "the", "exact", "Upgrader", "API", "so", "the", "actual", "calls", "that", "are", "available", "do", "not", "depend", "on", "who", "is", "currently", "connected", ".", "NewUpgraderFacade", "provides", "the", "signature", "required", "for", "facade", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/upgrader/upgrader.go#L31-L49
3,353
juju/juju
apiserver/facades/agent/upgrader/upgrader.go
NewUpgraderAPI
func NewUpgraderAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, ) (*UpgraderAPI, error) { if !authorizer.AuthMachineAgent() && !authorizer.AuthApplicationAgent() { return nil, common.ErrPerm } getCanReadWrite := func() (common.AuthFunc, error) { return authorizer.AuthOwner, nil } model, err := st.Model() if err != nil { return nil, err } urlGetter := common.NewToolsURLGetter(model.UUID(), st) configGetter := stateenvirons.EnvironConfigGetter{State: st, Model: model} return &UpgraderAPI{ ToolsGetter: common.NewToolsGetter(st, configGetter, st, urlGetter, getCanReadWrite), ToolsSetter: common.NewToolsSetter(st, getCanReadWrite), st: st, m: model, resources: resources, authorizer: authorizer, }, nil }
go
func NewUpgraderAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, ) (*UpgraderAPI, error) { if !authorizer.AuthMachineAgent() && !authorizer.AuthApplicationAgent() { return nil, common.ErrPerm } getCanReadWrite := func() (common.AuthFunc, error) { return authorizer.AuthOwner, nil } model, err := st.Model() if err != nil { return nil, err } urlGetter := common.NewToolsURLGetter(model.UUID(), st) configGetter := stateenvirons.EnvironConfigGetter{State: st, Model: model} return &UpgraderAPI{ ToolsGetter: common.NewToolsGetter(st, configGetter, st, urlGetter, getCanReadWrite), ToolsSetter: common.NewToolsSetter(st, getCanReadWrite), st: st, m: model, resources: resources, authorizer: authorizer, }, nil }
[ "func", "NewUpgraderAPI", "(", "st", "*", "state", ".", "State", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ",", ")", "(", "*", "UpgraderAPI", ",", "error", ")", "{", "if", "!", "authorizer", ".", "AuthMachineAgent", "(", ")", "&&", "!", "authorizer", ".", "AuthApplicationAgent", "(", ")", "{", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "getCanReadWrite", ":=", "func", "(", ")", "(", "common", ".", "AuthFunc", ",", "error", ")", "{", "return", "authorizer", ".", "AuthOwner", ",", "nil", "\n", "}", "\n", "model", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "urlGetter", ":=", "common", ".", "NewToolsURLGetter", "(", "model", ".", "UUID", "(", ")", ",", "st", ")", "\n", "configGetter", ":=", "stateenvirons", ".", "EnvironConfigGetter", "{", "State", ":", "st", ",", "Model", ":", "model", "}", "\n", "return", "&", "UpgraderAPI", "{", "ToolsGetter", ":", "common", ".", "NewToolsGetter", "(", "st", ",", "configGetter", ",", "st", ",", "urlGetter", ",", "getCanReadWrite", ")", ",", "ToolsSetter", ":", "common", ".", "NewToolsSetter", "(", "st", ",", "getCanReadWrite", ")", ",", "st", ":", "st", ",", "m", ":", "model", ",", "resources", ":", "resources", ",", "authorizer", ":", "authorizer", ",", "}", ",", "nil", "\n", "}" ]
// NewUpgraderAPI creates a new server-side UpgraderAPI facade.
[ "NewUpgraderAPI", "creates", "a", "new", "server", "-", "side", "UpgraderAPI", "facade", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/upgrader/upgrader.go#L70-L95
3,354
juju/juju
apiserver/facades/agent/upgrader/upgrader.go
WatchAPIVersion
func (u *UpgraderAPI) WatchAPIVersion(args params.Entities) (params.NotifyWatchResults, error) { result := params.NotifyWatchResults{ Results: make([]params.NotifyWatchResult, len(args.Entities)), } for i, agent := range args.Entities { tag, err := names.ParseTag(agent.Tag) if err != nil { return params.NotifyWatchResults{}, errors.Trace(err) } err = common.ErrPerm if u.authorizer.AuthOwner(tag) { watch := u.m.WatchForModelConfigChanges() // Consume the initial event. Technically, API // calls to Watch 'transmit' the initial event // in the Watch response. But NotifyWatchers // have no state to transmit. if _, ok := <-watch.Changes(); ok { result.Results[i].NotifyWatcherId = u.resources.Register(watch) err = nil } else { err = watcher.EnsureErr(watch) } } result.Results[i].Error = common.ServerError(err) } return result, nil }
go
func (u *UpgraderAPI) WatchAPIVersion(args params.Entities) (params.NotifyWatchResults, error) { result := params.NotifyWatchResults{ Results: make([]params.NotifyWatchResult, len(args.Entities)), } for i, agent := range args.Entities { tag, err := names.ParseTag(agent.Tag) if err != nil { return params.NotifyWatchResults{}, errors.Trace(err) } err = common.ErrPerm if u.authorizer.AuthOwner(tag) { watch := u.m.WatchForModelConfigChanges() // Consume the initial event. Technically, API // calls to Watch 'transmit' the initial event // in the Watch response. But NotifyWatchers // have no state to transmit. if _, ok := <-watch.Changes(); ok { result.Results[i].NotifyWatcherId = u.resources.Register(watch) err = nil } else { err = watcher.EnsureErr(watch) } } result.Results[i].Error = common.ServerError(err) } return result, nil }
[ "func", "(", "u", "*", "UpgraderAPI", ")", "WatchAPIVersion", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "NotifyWatchResults", ",", "error", ")", "{", "result", ":=", "params", ".", "NotifyWatchResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "NotifyWatchResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "for", "i", ",", "agent", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseTag", "(", "agent", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "NotifyWatchResults", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "err", "=", "common", ".", "ErrPerm", "\n", "if", "u", ".", "authorizer", ".", "AuthOwner", "(", "tag", ")", "{", "watch", ":=", "u", ".", "m", ".", "WatchForModelConfigChanges", "(", ")", "\n", "// Consume the initial event. Technically, API", "// calls to Watch 'transmit' the initial event", "// in the Watch response. But NotifyWatchers", "// have no state to transmit.", "if", "_", ",", "ok", ":=", "<-", "watch", ".", "Changes", "(", ")", ";", "ok", "{", "result", ".", "Results", "[", "i", "]", ".", "NotifyWatcherId", "=", "u", ".", "resources", ".", "Register", "(", "watch", ")", "\n", "err", "=", "nil", "\n", "}", "else", "{", "err", "=", "watcher", ".", "EnsureErr", "(", "watch", ")", "\n", "}", "\n", "}", "\n", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WatchAPIVersion starts a watcher to track if there is a new version // of the API that we want to upgrade to
[ "WatchAPIVersion", "starts", "a", "watcher", "to", "track", "if", "there", "is", "a", "new", "version", "of", "the", "API", "that", "we", "want", "to", "upgrade", "to" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/upgrader/upgrader.go#L99-L125
3,355
juju/juju
apiserver/facades/agent/upgrader/upgrader.go
DesiredVersion
func (u *UpgraderAPI) DesiredVersion(args params.Entities) (params.VersionResults, error) { results := make([]params.VersionResult, len(args.Entities)) if len(args.Entities) == 0 { return params.VersionResults{}, nil } agentVersion, _, err := u.getGlobalAgentVersion() if err != nil { return params.VersionResults{}, common.ServerError(err) } // Is the desired version greater than the current API server version? isNewerVersion := agentVersion.Compare(jujuversion.Current) > 0 for i, entity := range args.Entities { tag, err := names.ParseTag(entity.Tag) if err != nil { results[i].Error = common.ServerError(err) continue } err = common.ErrPerm if u.authorizer.AuthOwner(tag) { // Only return the globally desired agent version if the // asking entity is a machine agent with JobManageModel or // if this API server is running the globally desired agent // version. Otherwise report this API server's current // agent version. // // This ensures that state machine agents will upgrade // first - once they have restarted and are running the // new version other agents will start to see the new // agent version. if !isNewerVersion || u.entityIsManager(tag) { results[i].Version = &agentVersion } else { logger.Debugf("desired version is %s, but current version is %s and agent is not a manager node", agentVersion, jujuversion.Current) results[i].Version = &jujuversion.Current } err = nil } results[i].Error = common.ServerError(err) } return params.VersionResults{Results: results}, nil }
go
func (u *UpgraderAPI) DesiredVersion(args params.Entities) (params.VersionResults, error) { results := make([]params.VersionResult, len(args.Entities)) if len(args.Entities) == 0 { return params.VersionResults{}, nil } agentVersion, _, err := u.getGlobalAgentVersion() if err != nil { return params.VersionResults{}, common.ServerError(err) } // Is the desired version greater than the current API server version? isNewerVersion := agentVersion.Compare(jujuversion.Current) > 0 for i, entity := range args.Entities { tag, err := names.ParseTag(entity.Tag) if err != nil { results[i].Error = common.ServerError(err) continue } err = common.ErrPerm if u.authorizer.AuthOwner(tag) { // Only return the globally desired agent version if the // asking entity is a machine agent with JobManageModel or // if this API server is running the globally desired agent // version. Otherwise report this API server's current // agent version. // // This ensures that state machine agents will upgrade // first - once they have restarted and are running the // new version other agents will start to see the new // agent version. if !isNewerVersion || u.entityIsManager(tag) { results[i].Version = &agentVersion } else { logger.Debugf("desired version is %s, but current version is %s and agent is not a manager node", agentVersion, jujuversion.Current) results[i].Version = &jujuversion.Current } err = nil } results[i].Error = common.ServerError(err) } return params.VersionResults{Results: results}, nil }
[ "func", "(", "u", "*", "UpgraderAPI", ")", "DesiredVersion", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "VersionResults", ",", "error", ")", "{", "results", ":=", "make", "(", "[", "]", "params", ".", "VersionResult", ",", "len", "(", "args", ".", "Entities", ")", ")", "\n", "if", "len", "(", "args", ".", "Entities", ")", "==", "0", "{", "return", "params", ".", "VersionResults", "{", "}", ",", "nil", "\n", "}", "\n", "agentVersion", ",", "_", ",", "err", ":=", "u", ".", "getGlobalAgentVersion", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "VersionResults", "{", "}", ",", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "// Is the desired version greater than the current API server version?", "isNewerVersion", ":=", "agentVersion", ".", "Compare", "(", "jujuversion", ".", "Current", ")", ">", "0", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "err", "=", "common", ".", "ErrPerm", "\n", "if", "u", ".", "authorizer", ".", "AuthOwner", "(", "tag", ")", "{", "// Only return the globally desired agent version if the", "// asking entity is a machine agent with JobManageModel or", "// if this API server is running the globally desired agent", "// version. Otherwise report this API server's current", "// agent version.", "//", "// This ensures that state machine agents will upgrade", "// first - once they have restarted and are running the", "// new version other agents will start to see the new", "// agent version.", "if", "!", "isNewerVersion", "||", "u", ".", "entityIsManager", "(", "tag", ")", "{", "results", "[", "i", "]", ".", "Version", "=", "&", "agentVersion", "\n", "}", "else", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "agentVersion", ",", "jujuversion", ".", "Current", ")", "\n", "results", "[", "i", "]", ".", "Version", "=", "&", "jujuversion", ".", "Current", "\n", "}", "\n", "err", "=", "nil", "\n", "}", "\n", "results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "return", "params", ".", "VersionResults", "{", "Results", ":", "results", "}", ",", "nil", "\n", "}" ]
// DesiredVersion reports the Agent Version that we want that agent to be running
[ "DesiredVersion", "reports", "the", "Agent", "Version", "that", "we", "want", "that", "agent", "to", "be", "running" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/upgrader/upgrader.go#L157-L197
3,356
juju/juju
provider/vsphere/config.go
newValidConfig
func newValidConfig(cfg *config.Config) (*environConfig, error) { // Ensure that the provided config is valid. if err := config.Validate(cfg, nil); err != nil { return nil, errors.Trace(err) } // Apply the defaults and coerce/validate the custom config attrs. validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults) if err != nil { return nil, errors.Trace(err) } validCfg, err := cfg.Apply(validated) if err != nil { return nil, errors.Trace(err) } // Build the config. ecfg := newConfig(validCfg) // Do final validation. if err := ecfg.validate(); err != nil { return nil, errors.Trace(err) } return ecfg, nil }
go
func newValidConfig(cfg *config.Config) (*environConfig, error) { // Ensure that the provided config is valid. if err := config.Validate(cfg, nil); err != nil { return nil, errors.Trace(err) } // Apply the defaults and coerce/validate the custom config attrs. validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults) if err != nil { return nil, errors.Trace(err) } validCfg, err := cfg.Apply(validated) if err != nil { return nil, errors.Trace(err) } // Build the config. ecfg := newConfig(validCfg) // Do final validation. if err := ecfg.validate(); err != nil { return nil, errors.Trace(err) } return ecfg, nil }
[ "func", "newValidConfig", "(", "cfg", "*", "config", ".", "Config", ")", "(", "*", "environConfig", ",", "error", ")", "{", "// Ensure that the provided config is valid.", "if", "err", ":=", "config", ".", "Validate", "(", "cfg", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Apply the defaults and coerce/validate the custom config attrs.", "validated", ",", "err", ":=", "cfg", ".", "ValidateUnknownAttrs", "(", "configFields", ",", "configDefaults", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "validCfg", ",", "err", ":=", "cfg", ".", "Apply", "(", "validated", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Build the config.", "ecfg", ":=", "newConfig", "(", "validCfg", ")", "\n\n", "// Do final validation.", "if", "err", ":=", "ecfg", ".", "validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "return", "ecfg", ",", "nil", "\n", "}" ]
// newValidConfig builds a new environConfig from the provided Config // and returns it. The resulting config values are validated.
[ "newValidConfig", "builds", "a", "new", "environConfig", "from", "the", "provided", "Config", "and", "returns", "it", ".", "The", "resulting", "config", "values", "are", "validated", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/vsphere/config.go#L57-L82
3,357
juju/juju
provider/vsphere/config.go
validate
func (c environConfig) validate() error { // All fields must be populated, even with just the default. for _, field := range configRequiredFields { if c.attrs[field].(string) == "" { return errors.Errorf("%s: must not be empty", field) } } return nil }
go
func (c environConfig) validate() error { // All fields must be populated, even with just the default. for _, field := range configRequiredFields { if c.attrs[field].(string) == "" { return errors.Errorf("%s: must not be empty", field) } } return nil }
[ "func", "(", "c", "environConfig", ")", "validate", "(", ")", "error", "{", "// All fields must be populated, even with just the default.", "for", "_", ",", "field", ":=", "range", "configRequiredFields", "{", "if", "c", ".", "attrs", "[", "field", "]", ".", "(", "string", ")", "==", "\"", "\"", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "field", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// validate checks vmware-specific config values.
[ "validate", "checks", "vmware", "-", "specific", "config", "values", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/vsphere/config.go#L103-L111
3,358
juju/juju
provider/vsphere/config.go
update
func (c *environConfig) update(cfg *config.Config) error { // Validate the updates. newValidConfig does not modify the "known" // config attributes so it is safe to call Validate here first. if err := config.Validate(cfg, c.Config); err != nil { return errors.Trace(err) } updates, err := newValidConfig(cfg) if err != nil { return errors.Trace(err) } // Check that no immutable fields have changed. attrs := updates.UnknownAttrs() for _, field := range configImmutableFields { if attrs[field] != c.attrs[field] { return errors.Errorf("%s: cannot change from %v to %v", field, c.attrs[field], attrs[field]) } } // Apply the updates. c.Config = cfg c.attrs = cfg.UnknownAttrs() return nil }
go
func (c *environConfig) update(cfg *config.Config) error { // Validate the updates. newValidConfig does not modify the "known" // config attributes so it is safe to call Validate here first. if err := config.Validate(cfg, c.Config); err != nil { return errors.Trace(err) } updates, err := newValidConfig(cfg) if err != nil { return errors.Trace(err) } // Check that no immutable fields have changed. attrs := updates.UnknownAttrs() for _, field := range configImmutableFields { if attrs[field] != c.attrs[field] { return errors.Errorf("%s: cannot change from %v to %v", field, c.attrs[field], attrs[field]) } } // Apply the updates. c.Config = cfg c.attrs = cfg.UnknownAttrs() return nil }
[ "func", "(", "c", "*", "environConfig", ")", "update", "(", "cfg", "*", "config", ".", "Config", ")", "error", "{", "// Validate the updates. newValidConfig does not modify the \"known\"", "// config attributes so it is safe to call Validate here first.", "if", "err", ":=", "config", ".", "Validate", "(", "cfg", ",", "c", ".", "Config", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "updates", ",", "err", ":=", "newValidConfig", "(", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Check that no immutable fields have changed.", "attrs", ":=", "updates", ".", "UnknownAttrs", "(", ")", "\n", "for", "_", ",", "field", ":=", "range", "configImmutableFields", "{", "if", "attrs", "[", "field", "]", "!=", "c", ".", "attrs", "[", "field", "]", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "field", ",", "c", ".", "attrs", "[", "field", "]", ",", "attrs", "[", "field", "]", ")", "\n", "}", "\n", "}", "\n\n", "// Apply the updates.", "c", ".", "Config", "=", "cfg", "\n", "c", ".", "attrs", "=", "cfg", ".", "UnknownAttrs", "(", ")", "\n", "return", "nil", "\n", "}" ]
// update applies changes from the provided config to the env config. // Changes to any immutable attributes result in an error.
[ "update", "applies", "changes", "from", "the", "provided", "config", "to", "the", "env", "config", ".", "Changes", "to", "any", "immutable", "attributes", "result", "in", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/vsphere/config.go#L115-L139
3,359
juju/juju
core/crossmodel/externalcontroller.go
Validate
func (info *ControllerInfo) Validate() error { if !names.IsValidController(info.ControllerTag.Id()) { return errors.NotValidf("ControllerTag") } if len(info.Addrs) < 1 { return errors.NotValidf("empty controller api addresses") } for _, addr := range info.Addrs { _, err := network.ParseHostPort(addr) if err != nil { return errors.NotValidf("controller api address %q", addr) } } return nil }
go
func (info *ControllerInfo) Validate() error { if !names.IsValidController(info.ControllerTag.Id()) { return errors.NotValidf("ControllerTag") } if len(info.Addrs) < 1 { return errors.NotValidf("empty controller api addresses") } for _, addr := range info.Addrs { _, err := network.ParseHostPort(addr) if err != nil { return errors.NotValidf("controller api address %q", addr) } } return nil }
[ "func", "(", "info", "*", "ControllerInfo", ")", "Validate", "(", ")", "error", "{", "if", "!", "names", ".", "IsValidController", "(", "info", ".", "ControllerTag", ".", "Id", "(", ")", ")", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "info", ".", "Addrs", ")", "<", "1", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "addr", ":=", "range", "info", ".", "Addrs", "{", "_", ",", "err", ":=", "network", ".", "ParseHostPort", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "addr", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate returns an error if the ControllerInfo contains bad data.
[ "Validate", "returns", "an", "error", "if", "the", "ControllerInfo", "contains", "bad", "data", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/crossmodel/externalcontroller.go#L30-L45
3,360
juju/juju
apiserver/facades/controller/migrationmaster/shim.go
NewFacade
func NewFacade(ctx facade.Context) (*API, error) { controllerState := ctx.StatePool().SystemState() precheckBackend, err := migration.PrecheckShim(ctx.State(), controllerState) if err != nil { return nil, errors.Annotate(err, "creating precheck backend") } return NewAPI( &backendShim{ctx.State()}, precheckBackend, migration.PoolShim(ctx.StatePool()), ctx.Resources(), ctx.Auth(), ctx.Presence(), ) }
go
func NewFacade(ctx facade.Context) (*API, error) { controllerState := ctx.StatePool().SystemState() precheckBackend, err := migration.PrecheckShim(ctx.State(), controllerState) if err != nil { return nil, errors.Annotate(err, "creating precheck backend") } return NewAPI( &backendShim{ctx.State()}, precheckBackend, migration.PoolShim(ctx.StatePool()), ctx.Resources(), ctx.Auth(), ctx.Presence(), ) }
[ "func", "NewFacade", "(", "ctx", "facade", ".", "Context", ")", "(", "*", "API", ",", "error", ")", "{", "controllerState", ":=", "ctx", ".", "StatePool", "(", ")", ".", "SystemState", "(", ")", "\n", "precheckBackend", ",", "err", ":=", "migration", ".", "PrecheckShim", "(", "ctx", ".", "State", "(", ")", ",", "controllerState", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "NewAPI", "(", "&", "backendShim", "{", "ctx", ".", "State", "(", ")", "}", ",", "precheckBackend", ",", "migration", ".", "PoolShim", "(", "ctx", ".", "StatePool", "(", ")", ")", ",", "ctx", ".", "Resources", "(", ")", ",", "ctx", ".", "Auth", "(", ")", ",", "ctx", ".", "Presence", "(", ")", ",", ")", "\n", "}" ]
// NewFacade exists to provide the required signature for API // registration, converting st to backend.
[ "NewFacade", "exists", "to", "provide", "the", "required", "signature", "for", "API", "registration", "converting", "st", "to", "backend", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/shim.go#L18-L32
3,361
juju/juju
apiserver/facades/controller/migrationmaster/shim.go
ModelName
func (s *backendShim) ModelName() (string, error) { model, err := s.Model() if err != nil { return "", errors.Trace(err) } return model.Name(), nil }
go
func (s *backendShim) ModelName() (string, error) { model, err := s.Model() if err != nil { return "", errors.Trace(err) } return model.Name(), nil }
[ "func", "(", "s", "*", "backendShim", ")", "ModelName", "(", ")", "(", "string", ",", "error", ")", "{", "model", ",", "err", ":=", "s", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "model", ".", "Name", "(", ")", ",", "nil", "\n", "}" ]
// ModelName implements Backend.
[ "ModelName", "implements", "Backend", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/shim.go#L41-L47
3,362
juju/juju
apiserver/facades/controller/migrationmaster/shim.go
ModelOwner
func (s *backendShim) ModelOwner() (names.UserTag, error) { model, err := s.Model() if err != nil { return names.UserTag{}, errors.Trace(err) } return model.Owner(), nil }
go
func (s *backendShim) ModelOwner() (names.UserTag, error) { model, err := s.Model() if err != nil { return names.UserTag{}, errors.Trace(err) } return model.Owner(), nil }
[ "func", "(", "s", "*", "backendShim", ")", "ModelOwner", "(", ")", "(", "names", ".", "UserTag", ",", "error", ")", "{", "model", ",", "err", ":=", "s", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "names", ".", "UserTag", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "model", ".", "Owner", "(", ")", ",", "nil", "\n", "}" ]
// ModelOwner implements Backend.
[ "ModelOwner", "implements", "Backend", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/shim.go#L50-L56
3,363
juju/juju
apiserver/facades/controller/migrationmaster/shim.go
AgentVersion
func (s *backendShim) AgentVersion() (version.Number, error) { m, err := s.Model() if err != nil { return version.Zero, errors.Trace(err) } cfg, err := m.ModelConfig() if err != nil { return version.Zero, errors.Trace(err) } vers, ok := cfg.AgentVersion() if !ok { return version.Zero, errors.New("no agent version") } return vers, nil }
go
func (s *backendShim) AgentVersion() (version.Number, error) { m, err := s.Model() if err != nil { return version.Zero, errors.Trace(err) } cfg, err := m.ModelConfig() if err != nil { return version.Zero, errors.Trace(err) } vers, ok := cfg.AgentVersion() if !ok { return version.Zero, errors.New("no agent version") } return vers, nil }
[ "func", "(", "s", "*", "backendShim", ")", "AgentVersion", "(", ")", "(", "version", ".", "Number", ",", "error", ")", "{", "m", ",", "err", ":=", "s", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "version", ".", "Zero", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "cfg", ",", "err", ":=", "m", ".", "ModelConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "version", ".", "Zero", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "vers", ",", "ok", ":=", "cfg", ".", "AgentVersion", "(", ")", "\n", "if", "!", "ok", "{", "return", "version", ".", "Zero", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "vers", ",", "nil", "\n", "}" ]
// AgentVersion implements Backend.
[ "AgentVersion", "implements", "Backend", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/shim.go#L59-L74
3,364
juju/juju
agent/agentbootstrap/bootstrap.go
ensureHostedModel
func ensureHostedModel( isCAAS bool, cloudSpec environs.CloudSpec, provider environs.EnvironProvider, args InitializeStateParams, st *state.State, ctrl *state.Controller, adminUser names.UserTag, cloudCredentialTag names.CloudCredentialTag, ) error { if len(args.HostedModelConfig) == 0 { logger.Debugf("no hosted model configured") return nil } // Create the initial hosted model, with the model config passed to // bootstrap, which contains the UUID, name for the hosted model, // and any user supplied config. We also copy the authorized-keys // from the controller model. attrs := make(map[string]interface{}) for k, v := range args.HostedModelConfig { attrs[k] = v } attrs[config.AuthorizedKeysKey] = args.ControllerModelConfig.AuthorizedKeys() creator := modelmanager.ModelConfigCreator{Provider: args.Provider} hostedModelConfig, err := creator.NewModelConfig( cloudSpec, args.ControllerModelConfig, attrs, ) if err != nil { return errors.Annotate(err, "creating hosted model config") } controllerUUID := args.ControllerConfig.ControllerUUID() hostedModelEnv, err := getEnviron(controllerUUID, cloudSpec, hostedModelConfig, provider) if err != nil { return errors.Annotate(err, "opening hosted model environment") } if err := hostedModelEnv.Create( state.CallContext(st), environs.CreateParams{ ControllerUUID: controllerUUID, }); err != nil { return errors.Annotate(err, "creating hosted model environment") } ctrlModel, err := st.Model() if err != nil { return errors.Trace(err) } model, hostedModelState, err := ctrl.NewModel(state.ModelArgs{ Type: ctrlModel.Type(), Owner: adminUser, Config: hostedModelConfig, Constraints: args.ModelConstraints, CloudName: args.ControllerCloud.Name, CloudRegion: args.ControllerCloudRegion, CloudCredential: cloudCredentialTag, StorageProviderRegistry: args.StorageProviderRegistry, EnvironVersion: provider.Version(), }) if err != nil { return errors.Annotate(err, "creating hosted model") } defer hostedModelState.Close() if err := model.AutoConfigureContainerNetworking(hostedModelEnv); err != nil { return errors.Annotate(err, "autoconfiguring container networking") } // TODO(wpk) 2017-05-24 Copy subnets/spaces from controller model if err = hostedModelState.ReloadSpaces(hostedModelEnv); err != nil { if errors.IsNotSupported(err) { logger.Debugf("Not performing spaces load on a non-networking environment") } else { return errors.Annotate(err, "fetching hosted model spaces") } } return nil }
go
func ensureHostedModel( isCAAS bool, cloudSpec environs.CloudSpec, provider environs.EnvironProvider, args InitializeStateParams, st *state.State, ctrl *state.Controller, adminUser names.UserTag, cloudCredentialTag names.CloudCredentialTag, ) error { if len(args.HostedModelConfig) == 0 { logger.Debugf("no hosted model configured") return nil } // Create the initial hosted model, with the model config passed to // bootstrap, which contains the UUID, name for the hosted model, // and any user supplied config. We also copy the authorized-keys // from the controller model. attrs := make(map[string]interface{}) for k, v := range args.HostedModelConfig { attrs[k] = v } attrs[config.AuthorizedKeysKey] = args.ControllerModelConfig.AuthorizedKeys() creator := modelmanager.ModelConfigCreator{Provider: args.Provider} hostedModelConfig, err := creator.NewModelConfig( cloudSpec, args.ControllerModelConfig, attrs, ) if err != nil { return errors.Annotate(err, "creating hosted model config") } controllerUUID := args.ControllerConfig.ControllerUUID() hostedModelEnv, err := getEnviron(controllerUUID, cloudSpec, hostedModelConfig, provider) if err != nil { return errors.Annotate(err, "opening hosted model environment") } if err := hostedModelEnv.Create( state.CallContext(st), environs.CreateParams{ ControllerUUID: controllerUUID, }); err != nil { return errors.Annotate(err, "creating hosted model environment") } ctrlModel, err := st.Model() if err != nil { return errors.Trace(err) } model, hostedModelState, err := ctrl.NewModel(state.ModelArgs{ Type: ctrlModel.Type(), Owner: adminUser, Config: hostedModelConfig, Constraints: args.ModelConstraints, CloudName: args.ControllerCloud.Name, CloudRegion: args.ControllerCloudRegion, CloudCredential: cloudCredentialTag, StorageProviderRegistry: args.StorageProviderRegistry, EnvironVersion: provider.Version(), }) if err != nil { return errors.Annotate(err, "creating hosted model") } defer hostedModelState.Close() if err := model.AutoConfigureContainerNetworking(hostedModelEnv); err != nil { return errors.Annotate(err, "autoconfiguring container networking") } // TODO(wpk) 2017-05-24 Copy subnets/spaces from controller model if err = hostedModelState.ReloadSpaces(hostedModelEnv); err != nil { if errors.IsNotSupported(err) { logger.Debugf("Not performing spaces load on a non-networking environment") } else { return errors.Annotate(err, "fetching hosted model spaces") } } return nil }
[ "func", "ensureHostedModel", "(", "isCAAS", "bool", ",", "cloudSpec", "environs", ".", "CloudSpec", ",", "provider", "environs", ".", "EnvironProvider", ",", "args", "InitializeStateParams", ",", "st", "*", "state", ".", "State", ",", "ctrl", "*", "state", ".", "Controller", ",", "adminUser", "names", ".", "UserTag", ",", "cloudCredentialTag", "names", ".", "CloudCredentialTag", ",", ")", "error", "{", "if", "len", "(", "args", ".", "HostedModelConfig", ")", "==", "0", "{", "logger", ".", "Debugf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// Create the initial hosted model, with the model config passed to", "// bootstrap, which contains the UUID, name for the hosted model,", "// and any user supplied config. We also copy the authorized-keys", "// from the controller model.", "attrs", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "args", ".", "HostedModelConfig", "{", "attrs", "[", "k", "]", "=", "v", "\n", "}", "\n", "attrs", "[", "config", ".", "AuthorizedKeysKey", "]", "=", "args", ".", "ControllerModelConfig", ".", "AuthorizedKeys", "(", ")", "\n\n", "creator", ":=", "modelmanager", ".", "ModelConfigCreator", "{", "Provider", ":", "args", ".", "Provider", "}", "\n", "hostedModelConfig", ",", "err", ":=", "creator", ".", "NewModelConfig", "(", "cloudSpec", ",", "args", ".", "ControllerModelConfig", ",", "attrs", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "controllerUUID", ":=", "args", ".", "ControllerConfig", ".", "ControllerUUID", "(", ")", "\n\n", "hostedModelEnv", ",", "err", ":=", "getEnviron", "(", "controllerUUID", ",", "cloudSpec", ",", "hostedModelConfig", ",", "provider", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "hostedModelEnv", ".", "Create", "(", "state", ".", "CallContext", "(", "st", ")", ",", "environs", ".", "CreateParams", "{", "ControllerUUID", ":", "controllerUUID", ",", "}", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "ctrlModel", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "model", ",", "hostedModelState", ",", "err", ":=", "ctrl", ".", "NewModel", "(", "state", ".", "ModelArgs", "{", "Type", ":", "ctrlModel", ".", "Type", "(", ")", ",", "Owner", ":", "adminUser", ",", "Config", ":", "hostedModelConfig", ",", "Constraints", ":", "args", ".", "ModelConstraints", ",", "CloudName", ":", "args", ".", "ControllerCloud", ".", "Name", ",", "CloudRegion", ":", "args", ".", "ControllerCloudRegion", ",", "CloudCredential", ":", "cloudCredentialTag", ",", "StorageProviderRegistry", ":", "args", ".", "StorageProviderRegistry", ",", "EnvironVersion", ":", "provider", ".", "Version", "(", ")", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "defer", "hostedModelState", ".", "Close", "(", ")", "\n\n", "if", "err", ":=", "model", ".", "AutoConfigureContainerNetworking", "(", "hostedModelEnv", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// TODO(wpk) 2017-05-24 Copy subnets/spaces from controller model", "if", "err", "=", "hostedModelState", ".", "ReloadSpaces", "(", "hostedModelEnv", ")", ";", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotSupported", "(", "err", ")", "{", "logger", ".", "Debugf", "(", "\"", "\"", ")", "\n", "}", "else", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ensureHostedModel ensures hosted model.
[ "ensureHostedModel", "ensures", "hosted", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agentbootstrap/bootstrap.go#L207-L289
3,365
juju/juju
agent/agentbootstrap/bootstrap.go
initMongo
func initMongo(info mongo.Info, dialOpts mongo.DialOpts, password string) (*mgo.Session, error) { session, err := mongo.DialWithInfo(mongo.MongoInfo{Info: info}, dialOpts) if err != nil { return nil, errors.Trace(err) } if err := mongo.SetAdminMongoPassword(session, mongo.AdminUser, password); err != nil { session.Close() return nil, errors.Trace(err) } if err := mongo.Login(session, mongo.AdminUser, password); err != nil { session.Close() return nil, errors.Trace(err) } return session, nil }
go
func initMongo(info mongo.Info, dialOpts mongo.DialOpts, password string) (*mgo.Session, error) { session, err := mongo.DialWithInfo(mongo.MongoInfo{Info: info}, dialOpts) if err != nil { return nil, errors.Trace(err) } if err := mongo.SetAdminMongoPassword(session, mongo.AdminUser, password); err != nil { session.Close() return nil, errors.Trace(err) } if err := mongo.Login(session, mongo.AdminUser, password); err != nil { session.Close() return nil, errors.Trace(err) } return session, nil }
[ "func", "initMongo", "(", "info", "mongo", ".", "Info", ",", "dialOpts", "mongo", ".", "DialOpts", ",", "password", "string", ")", "(", "*", "mgo", ".", "Session", ",", "error", ")", "{", "session", ",", "err", ":=", "mongo", ".", "DialWithInfo", "(", "mongo", ".", "MongoInfo", "{", "Info", ":", "info", "}", ",", "dialOpts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "mongo", ".", "SetAdminMongoPassword", "(", "session", ",", "mongo", ".", "AdminUser", ",", "password", ")", ";", "err", "!=", "nil", "{", "session", ".", "Close", "(", ")", "\n", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "mongo", ".", "Login", "(", "session", ",", "mongo", ".", "AdminUser", ",", "password", ")", ";", "err", "!=", "nil", "{", "session", ".", "Close", "(", ")", "\n", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "session", ",", "nil", "\n", "}" ]
// initMongo dials the initial MongoDB connection, setting a // password for the admin user, and returning the session.
[ "initMongo", "dials", "the", "initial", "MongoDB", "connection", "setting", "a", "password", "for", "the", "admin", "user", "and", "returning", "the", "session", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agentbootstrap/bootstrap.go#L332-L346
3,366
juju/juju
agent/agentbootstrap/bootstrap.go
initBootstrapMachine
func initBootstrapMachine( c agent.ConfigSetter, st *state.State, args InitializeStateParams, ) (*state.Machine, error) { model, err := st.Model() if err != nil { return nil, errors.Trace(err) } logger.Infof("initialising bootstrap machine for %q model with config: %+v", model.Type(), args) jobs := make([]state.MachineJob, len(args.BootstrapMachineJobs)) for i, job := range args.BootstrapMachineJobs { machineJob, err := machineJobFromParams(job) if err != nil { return nil, errors.Errorf("invalid bootstrap machine job %q: %v", job, err) } jobs[i] = machineJob } var hardware instance.HardwareCharacteristics if args.BootstrapMachineHardwareCharacteristics != nil { hardware = *args.BootstrapMachineHardwareCharacteristics } hostSeries, err := series.HostSeries() if err != nil { return nil, errors.Trace(err) } m, err := st.AddOneMachine(state.MachineTemplate{ Addresses: args.BootstrapMachineAddresses, Series: hostSeries, Nonce: agent.BootstrapNonce, Constraints: args.BootstrapMachineConstraints, InstanceId: args.BootstrapMachineInstanceId, HardwareCharacteristics: hardware, Jobs: jobs, }) if err != nil { return nil, errors.Annotate(err, "cannot create bootstrap machine in state") } if m.Id() != agent.BootstrapMachineId { return nil, errors.Errorf("bootstrap machine expected id 0, got %q", m.Id()) } // Read the machine agent's password and change it to // a new password (other agents will change their password // via the API connection). logger.Debugf("create new random password for machine %v", m.Id()) newPassword, err := utils.RandomPassword() if err != nil { return nil, err } if err := m.SetPassword(newPassword); err != nil { return nil, err } if err := m.SetMongoPassword(newPassword); err != nil { return nil, err } c.SetPassword(newPassword) return m, nil }
go
func initBootstrapMachine( c agent.ConfigSetter, st *state.State, args InitializeStateParams, ) (*state.Machine, error) { model, err := st.Model() if err != nil { return nil, errors.Trace(err) } logger.Infof("initialising bootstrap machine for %q model with config: %+v", model.Type(), args) jobs := make([]state.MachineJob, len(args.BootstrapMachineJobs)) for i, job := range args.BootstrapMachineJobs { machineJob, err := machineJobFromParams(job) if err != nil { return nil, errors.Errorf("invalid bootstrap machine job %q: %v", job, err) } jobs[i] = machineJob } var hardware instance.HardwareCharacteristics if args.BootstrapMachineHardwareCharacteristics != nil { hardware = *args.BootstrapMachineHardwareCharacteristics } hostSeries, err := series.HostSeries() if err != nil { return nil, errors.Trace(err) } m, err := st.AddOneMachine(state.MachineTemplate{ Addresses: args.BootstrapMachineAddresses, Series: hostSeries, Nonce: agent.BootstrapNonce, Constraints: args.BootstrapMachineConstraints, InstanceId: args.BootstrapMachineInstanceId, HardwareCharacteristics: hardware, Jobs: jobs, }) if err != nil { return nil, errors.Annotate(err, "cannot create bootstrap machine in state") } if m.Id() != agent.BootstrapMachineId { return nil, errors.Errorf("bootstrap machine expected id 0, got %q", m.Id()) } // Read the machine agent's password and change it to // a new password (other agents will change their password // via the API connection). logger.Debugf("create new random password for machine %v", m.Id()) newPassword, err := utils.RandomPassword() if err != nil { return nil, err } if err := m.SetPassword(newPassword); err != nil { return nil, err } if err := m.SetMongoPassword(newPassword); err != nil { return nil, err } c.SetPassword(newPassword) return m, nil }
[ "func", "initBootstrapMachine", "(", "c", "agent", ".", "ConfigSetter", ",", "st", "*", "state", ".", "State", ",", "args", "InitializeStateParams", ",", ")", "(", "*", "state", ".", "Machine", ",", "error", ")", "{", "model", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Infof", "(", "\"", "\"", ",", "model", ".", "Type", "(", ")", ",", "args", ")", "\n\n", "jobs", ":=", "make", "(", "[", "]", "state", ".", "MachineJob", ",", "len", "(", "args", ".", "BootstrapMachineJobs", ")", ")", "\n", "for", "i", ",", "job", ":=", "range", "args", ".", "BootstrapMachineJobs", "{", "machineJob", ",", "err", ":=", "machineJobFromParams", "(", "job", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "job", ",", "err", ")", "\n", "}", "\n", "jobs", "[", "i", "]", "=", "machineJob", "\n", "}", "\n", "var", "hardware", "instance", ".", "HardwareCharacteristics", "\n", "if", "args", ".", "BootstrapMachineHardwareCharacteristics", "!=", "nil", "{", "hardware", "=", "*", "args", ".", "BootstrapMachineHardwareCharacteristics", "\n", "}", "\n", "hostSeries", ",", "err", ":=", "series", ".", "HostSeries", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "m", ",", "err", ":=", "st", ".", "AddOneMachine", "(", "state", ".", "MachineTemplate", "{", "Addresses", ":", "args", ".", "BootstrapMachineAddresses", ",", "Series", ":", "hostSeries", ",", "Nonce", ":", "agent", ".", "BootstrapNonce", ",", "Constraints", ":", "args", ".", "BootstrapMachineConstraints", ",", "InstanceId", ":", "args", ".", "BootstrapMachineInstanceId", ",", "HardwareCharacteristics", ":", "hardware", ",", "Jobs", ":", "jobs", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "m", ".", "Id", "(", ")", "!=", "agent", ".", "BootstrapMachineId", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "m", ".", "Id", "(", ")", ")", "\n", "}", "\n", "// Read the machine agent's password and change it to", "// a new password (other agents will change their password", "// via the API connection).", "logger", ".", "Debugf", "(", "\"", "\"", ",", "m", ".", "Id", "(", ")", ")", "\n\n", "newPassword", ",", "err", ":=", "utils", ".", "RandomPassword", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "m", ".", "SetPassword", "(", "newPassword", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "m", ".", "SetMongoPassword", "(", "newPassword", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "SetPassword", "(", "newPassword", ")", "\n", "return", "m", ",", "nil", "\n", "}" ]
// initBootstrapMachine initializes the initial bootstrap machine in state.
[ "initBootstrapMachine", "initializes", "the", "initial", "bootstrap", "machine", "in", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agentbootstrap/bootstrap.go#L349-L408
3,367
juju/juju
agent/agentbootstrap/bootstrap.go
initControllerCloudService
func initControllerCloudService( cloudSpec environs.CloudSpec, provider environs.EnvironProvider, st *state.State, args InitializeStateParams, ) error { controllerUUID := args.ControllerConfig.ControllerUUID() env, err := getEnviron(controllerUUID, cloudSpec, args.ControllerModelConfig, provider) if err != nil { return errors.Annotate(err, "getting environ") } broker, ok := env.(caas.ServiceGetterSetter) if !ok { // this should never happen. return errors.Errorf("environ %T does not implement ServiceGetterSetter interface", env) } svc, err := broker.GetService(k8sprovider.JujuControllerStackName, true) if err != nil { return errors.Trace(err) } if len(svc.Addresses) == 0 { // this should never happen because we have already checked in k8s controller bootstrap stacker. return errors.NotProvisionedf("k8s controller service %q address", svc.Id) } svcId := controllerUUID logger.Infof("creating cloud service for k8s controller %q", svcId) cloudSvc, err := st.SaveCloudService(state.SaveCloudServiceArgs{ Id: svcId, ProviderId: svc.Id, Addresses: svc.Addresses, }) logger.Debugf("created cloud service %v for controller", cloudSvc) return errors.Trace(err) }
go
func initControllerCloudService( cloudSpec environs.CloudSpec, provider environs.EnvironProvider, st *state.State, args InitializeStateParams, ) error { controllerUUID := args.ControllerConfig.ControllerUUID() env, err := getEnviron(controllerUUID, cloudSpec, args.ControllerModelConfig, provider) if err != nil { return errors.Annotate(err, "getting environ") } broker, ok := env.(caas.ServiceGetterSetter) if !ok { // this should never happen. return errors.Errorf("environ %T does not implement ServiceGetterSetter interface", env) } svc, err := broker.GetService(k8sprovider.JujuControllerStackName, true) if err != nil { return errors.Trace(err) } if len(svc.Addresses) == 0 { // this should never happen because we have already checked in k8s controller bootstrap stacker. return errors.NotProvisionedf("k8s controller service %q address", svc.Id) } svcId := controllerUUID logger.Infof("creating cloud service for k8s controller %q", svcId) cloudSvc, err := st.SaveCloudService(state.SaveCloudServiceArgs{ Id: svcId, ProviderId: svc.Id, Addresses: svc.Addresses, }) logger.Debugf("created cloud service %v for controller", cloudSvc) return errors.Trace(err) }
[ "func", "initControllerCloudService", "(", "cloudSpec", "environs", ".", "CloudSpec", ",", "provider", "environs", ".", "EnvironProvider", ",", "st", "*", "state", ".", "State", ",", "args", "InitializeStateParams", ",", ")", "error", "{", "controllerUUID", ":=", "args", ".", "ControllerConfig", ".", "ControllerUUID", "(", ")", "\n", "env", ",", "err", ":=", "getEnviron", "(", "controllerUUID", ",", "cloudSpec", ",", "args", ".", "ControllerModelConfig", ",", "provider", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "broker", ",", "ok", ":=", "env", ".", "(", "caas", ".", "ServiceGetterSetter", ")", "\n", "if", "!", "ok", "{", "// this should never happen.", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "env", ")", "\n", "}", "\n", "svc", ",", "err", ":=", "broker", ".", "GetService", "(", "k8sprovider", ".", "JujuControllerStackName", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "svc", ".", "Addresses", ")", "==", "0", "{", "// this should never happen because we have already checked in k8s controller bootstrap stacker.", "return", "errors", ".", "NotProvisionedf", "(", "\"", "\"", ",", "svc", ".", "Id", ")", "\n", "}", "\n", "svcId", ":=", "controllerUUID", "\n", "logger", ".", "Infof", "(", "\"", "\"", ",", "svcId", ")", "\n", "cloudSvc", ",", "err", ":=", "st", ".", "SaveCloudService", "(", "state", ".", "SaveCloudServiceArgs", "{", "Id", ":", "svcId", ",", "ProviderId", ":", "svc", ".", "Id", ",", "Addresses", ":", "svc", ".", "Addresses", ",", "}", ")", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "cloudSvc", ")", "\n", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// initControllerCloudService creates cloud service for controller service.
[ "initControllerCloudService", "creates", "cloud", "service", "for", "controller", "service", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/agentbootstrap/bootstrap.go#L411-L445
3,368
juju/juju
provider/lxd/userdata.go
Render
func (lxdRenderer) Render(cfg cloudinit.CloudConfig, os jujuos.OSType) ([]byte, error) { switch os { case jujuos.Ubuntu, jujuos.CentOS, jujuos.OpenSUSE: bytes, err := renderers.RenderYAML(cfg) return bytes, errors.Trace(err) default: return nil, errors.Errorf("cannot encode userdata for OS %q", os) } }
go
func (lxdRenderer) Render(cfg cloudinit.CloudConfig, os jujuos.OSType) ([]byte, error) { switch os { case jujuos.Ubuntu, jujuos.CentOS, jujuos.OpenSUSE: bytes, err := renderers.RenderYAML(cfg) return bytes, errors.Trace(err) default: return nil, errors.Errorf("cannot encode userdata for OS %q", os) } }
[ "func", "(", "lxdRenderer", ")", "Render", "(", "cfg", "cloudinit", ".", "CloudConfig", ",", "os", "jujuos", ".", "OSType", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "switch", "os", "{", "case", "jujuos", ".", "Ubuntu", ",", "jujuos", ".", "CentOS", ",", "jujuos", ".", "OpenSUSE", ":", "bytes", ",", "err", ":=", "renderers", ".", "RenderYAML", "(", "cfg", ")", "\n", "return", "bytes", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "default", ":", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "os", ")", "\n", "}", "\n", "}" ]
// EncodeUserdata implements renderers.ProviderRenderer.
[ "EncodeUserdata", "implements", "renderers", ".", "ProviderRenderer", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/userdata.go#L17-L25
3,369
juju/juju
mongo/prealloc.go
preallocOplog
func preallocOplog(dir string, oplogSizeMB int) error { // preallocFiles expects sizes in bytes. sizes := preallocFileSizes(oplogSizeMB * 1024 * 1024) prefix := filepath.Join(dir, "local.") return preallocFiles(prefix, sizes...) }
go
func preallocOplog(dir string, oplogSizeMB int) error { // preallocFiles expects sizes in bytes. sizes := preallocFileSizes(oplogSizeMB * 1024 * 1024) prefix := filepath.Join(dir, "local.") return preallocFiles(prefix, sizes...) }
[ "func", "preallocOplog", "(", "dir", "string", ",", "oplogSizeMB", "int", ")", "error", "{", "// preallocFiles expects sizes in bytes.", "sizes", ":=", "preallocFileSizes", "(", "oplogSizeMB", "*", "1024", "*", "1024", ")", "\n", "prefix", ":=", "filepath", ".", "Join", "(", "dir", ",", "\"", "\"", ")", "\n", "return", "preallocFiles", "(", "prefix", ",", "sizes", "...", ")", "\n", "}" ]
// preallocOplog preallocates the Mongo oplog in the // specified Mongo datadabase directory.
[ "preallocOplog", "preallocates", "the", "Mongo", "oplog", "in", "the", "specified", "Mongo", "datadabase", "directory", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/prealloc.go#L42-L47
3,370
juju/juju
mongo/prealloc.go
defaultOplogSize
func defaultOplogSize(dir string) (int, error) { if hostWordSize == 32 { // "For 32-bit systems, MongoDB allocates about 48 megabytes // of space to the oplog." return 48, nil } // "For 64-bit OS X systems, MongoDB allocates 183 megabytes of // space to the oplog." if runtimeGOOS == "darwin" { return 183, nil } // FIXME calculate disk size on Windows like on Linux below. if runtimeGOOS == "windows" { return smallOplogSizeMB, nil } avail, err := availSpace(dir) if err != nil { return -1, err } if avail < smallOplogBoundary { return smallOplogSizeMB, nil } else { return regularOplogSizeMB, nil } }
go
func defaultOplogSize(dir string) (int, error) { if hostWordSize == 32 { // "For 32-bit systems, MongoDB allocates about 48 megabytes // of space to the oplog." return 48, nil } // "For 64-bit OS X systems, MongoDB allocates 183 megabytes of // space to the oplog." if runtimeGOOS == "darwin" { return 183, nil } // FIXME calculate disk size on Windows like on Linux below. if runtimeGOOS == "windows" { return smallOplogSizeMB, nil } avail, err := availSpace(dir) if err != nil { return -1, err } if avail < smallOplogBoundary { return smallOplogSizeMB, nil } else { return regularOplogSizeMB, nil } }
[ "func", "defaultOplogSize", "(", "dir", "string", ")", "(", "int", ",", "error", ")", "{", "if", "hostWordSize", "==", "32", "{", "// \"For 32-bit systems, MongoDB allocates about 48 megabytes", "// of space to the oplog.\"", "return", "48", ",", "nil", "\n", "}", "\n\n", "// \"For 64-bit OS X systems, MongoDB allocates 183 megabytes of", "// space to the oplog.\"", "if", "runtimeGOOS", "==", "\"", "\"", "{", "return", "183", ",", "nil", "\n", "}", "\n\n", "// FIXME calculate disk size on Windows like on Linux below.", "if", "runtimeGOOS", "==", "\"", "\"", "{", "return", "smallOplogSizeMB", ",", "nil", "\n", "}", "\n\n", "avail", ",", "err", ":=", "availSpace", "(", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "if", "avail", "<", "smallOplogBoundary", "{", "return", "smallOplogSizeMB", ",", "nil", "\n", "}", "else", "{", "return", "regularOplogSizeMB", ",", "nil", "\n", "}", "\n", "}" ]
// defaultOplogSize returns the default size in MB for the // mongo oplog based on the directory of the mongo database. // // Since we limit the maximum oplog size to 1GB and every change // in opLogSize requires mongo restart we are not using the default // MongoDB formula but simply using 512MB for small disks and 1GB // for larger ones.
[ "defaultOplogSize", "returns", "the", "default", "size", "in", "MB", "for", "the", "mongo", "oplog", "based", "on", "the", "directory", "of", "the", "mongo", "database", ".", "Since", "we", "limit", "the", "maximum", "oplog", "size", "to", "1GB", "and", "every", "change", "in", "opLogSize", "requires", "mongo", "restart", "we", "are", "not", "using", "the", "default", "MongoDB", "formula", "but", "simply", "using", "512MB", "for", "small", "disks", "and", "1GB", "for", "larger", "ones", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/prealloc.go#L56-L83
3,371
juju/juju
mongo/prealloc.go
fsAvailSpace
func fsAvailSpace(dir string) (avail float64, err error) { var stderr bytes.Buffer cmd := exec.Command("df", dir) cmd.Stderr = &stderr out, err := cmd.Output() if err != nil { err := fmt.Errorf("df failed: %v", err) if stderr.Len() > 0 { err = fmt.Errorf("%s (%q)", err, stderr.String()) } return -1, err } lines := strings.Split(strings.TrimSpace(string(out)), "\n") if len(lines) < 2 { logger.Errorf("unexpected output: %q", out) return -1, fmt.Errorf("could not determine available space on %q", dir) } fields := strings.Fields(lines[1]) if len(fields) < 4 { logger.Errorf("unexpected output: %q", out) return -1, fmt.Errorf("could not determine available space on %q", dir) } kilobytes, err := strconv.Atoi(fields[3]) if err != nil { return -1, err } return float64(kilobytes) / 1024, err }
go
func fsAvailSpace(dir string) (avail float64, err error) { var stderr bytes.Buffer cmd := exec.Command("df", dir) cmd.Stderr = &stderr out, err := cmd.Output() if err != nil { err := fmt.Errorf("df failed: %v", err) if stderr.Len() > 0 { err = fmt.Errorf("%s (%q)", err, stderr.String()) } return -1, err } lines := strings.Split(strings.TrimSpace(string(out)), "\n") if len(lines) < 2 { logger.Errorf("unexpected output: %q", out) return -1, fmt.Errorf("could not determine available space on %q", dir) } fields := strings.Fields(lines[1]) if len(fields) < 4 { logger.Errorf("unexpected output: %q", out) return -1, fmt.Errorf("could not determine available space on %q", dir) } kilobytes, err := strconv.Atoi(fields[3]) if err != nil { return -1, err } return float64(kilobytes) / 1024, err }
[ "func", "fsAvailSpace", "(", "dir", "string", ")", "(", "avail", "float64", ",", "err", "error", ")", "{", "var", "stderr", "bytes", ".", "Buffer", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "dir", ")", "\n", "cmd", ".", "Stderr", "=", "&", "stderr", "\n", "out", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "if", "stderr", ".", "Len", "(", ")", ">", "0", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "stderr", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "-", "1", ",", "err", "\n", "}", "\n", "lines", ":=", "strings", ".", "Split", "(", "strings", ".", "TrimSpace", "(", "string", "(", "out", ")", ")", ",", "\"", "\\n", "\"", ")", "\n", "if", "len", "(", "lines", ")", "<", "2", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "out", ")", "\n", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ")", "\n", "}", "\n", "fields", ":=", "strings", ".", "Fields", "(", "lines", "[", "1", "]", ")", "\n", "if", "len", "(", "fields", ")", "<", "4", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "out", ")", "\n", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ")", "\n", "}", "\n", "kilobytes", ",", "err", ":=", "strconv", ".", "Atoi", "(", "fields", "[", "3", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "return", "float64", "(", "kilobytes", ")", "/", "1024", ",", "err", "\n", "}" ]
// fsAvailSpace returns the available space in MB on the // filesystem containing the specified directory.
[ "fsAvailSpace", "returns", "the", "available", "space", "in", "MB", "on", "the", "filesystem", "containing", "the", "specified", "directory", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/prealloc.go#L87-L114
3,372
juju/juju
mongo/prealloc.go
preallocFiles
func preallocFiles(prefix string, sizes ...int) error { var err error var createdFiles []string for i, size := range sizes { var created bool filename := fmt.Sprintf("%s%d", prefix, i) created, err = preallocFile(filename, size) if created { createdFiles = append(createdFiles, filename) } if err != nil { break } } if err != nil { logger.Debugf("cleaning up after preallocation failure: %v", err) for _, filename := range createdFiles { if err := os.Remove(filename); err != nil { logger.Errorf("failed to remove %q: %v", filename, err) } } } return err }
go
func preallocFiles(prefix string, sizes ...int) error { var err error var createdFiles []string for i, size := range sizes { var created bool filename := fmt.Sprintf("%s%d", prefix, i) created, err = preallocFile(filename, size) if created { createdFiles = append(createdFiles, filename) } if err != nil { break } } if err != nil { logger.Debugf("cleaning up after preallocation failure: %v", err) for _, filename := range createdFiles { if err := os.Remove(filename); err != nil { logger.Errorf("failed to remove %q: %v", filename, err) } } } return err }
[ "func", "preallocFiles", "(", "prefix", "string", ",", "sizes", "...", "int", ")", "error", "{", "var", "err", "error", "\n", "var", "createdFiles", "[", "]", "string", "\n", "for", "i", ",", "size", ":=", "range", "sizes", "{", "var", "created", "bool", "\n", "filename", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "prefix", ",", "i", ")", "\n", "created", ",", "err", "=", "preallocFile", "(", "filename", ",", "size", ")", "\n", "if", "created", "{", "createdFiles", "=", "append", "(", "createdFiles", ",", "filename", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "for", "_", ",", "filename", ":=", "range", "createdFiles", "{", "if", "err", ":=", "os", ".", "Remove", "(", "filename", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "filename", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// preallocFiles preallocates n data files, zeroed to make // up the specified sizes in bytes. The file sizes must be // multiples of 4096 bytes. // // The filenames are constructed by appending the file index // to the specified prefix.
[ "preallocFiles", "preallocates", "n", "data", "files", "zeroed", "to", "make", "up", "the", "specified", "sizes", "in", "bytes", ".", "The", "file", "sizes", "must", "be", "multiples", "of", "4096", "bytes", ".", "The", "filenames", "are", "constructed", "by", "appending", "the", "file", "index", "to", "the", "specified", "prefix", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/prealloc.go#L122-L145
3,373
juju/juju
mongo/prealloc.go
preallocFileSizes
func preallocFileSizes(totalSize int) []int { // Divide the total size into 512MB chunks, and // then round up the remaining chunk to a multiple // of 4096 bytes. const maxChunkSize = 512 * 1024 * 1024 var sizes []int remainder := totalSize % maxChunkSize if remainder > 0 { aligned := remainder + preallocAlign - 1 aligned = aligned - (aligned % preallocAlign) sizes = []int{aligned} } for i := 0; i < totalSize/maxChunkSize; i++ { sizes = append(sizes, maxChunkSize) } return sizes }
go
func preallocFileSizes(totalSize int) []int { // Divide the total size into 512MB chunks, and // then round up the remaining chunk to a multiple // of 4096 bytes. const maxChunkSize = 512 * 1024 * 1024 var sizes []int remainder := totalSize % maxChunkSize if remainder > 0 { aligned := remainder + preallocAlign - 1 aligned = aligned - (aligned % preallocAlign) sizes = []int{aligned} } for i := 0; i < totalSize/maxChunkSize; i++ { sizes = append(sizes, maxChunkSize) } return sizes }
[ "func", "preallocFileSizes", "(", "totalSize", "int", ")", "[", "]", "int", "{", "// Divide the total size into 512MB chunks, and", "// then round up the remaining chunk to a multiple", "// of 4096 bytes.", "const", "maxChunkSize", "=", "512", "*", "1024", "*", "1024", "\n", "var", "sizes", "[", "]", "int", "\n", "remainder", ":=", "totalSize", "%", "maxChunkSize", "\n", "if", "remainder", ">", "0", "{", "aligned", ":=", "remainder", "+", "preallocAlign", "-", "1", "\n", "aligned", "=", "aligned", "-", "(", "aligned", "%", "preallocAlign", ")", "\n", "sizes", "=", "[", "]", "int", "{", "aligned", "}", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "totalSize", "/", "maxChunkSize", ";", "i", "++", "{", "sizes", "=", "append", "(", "sizes", ",", "maxChunkSize", ")", "\n", "}", "\n", "return", "sizes", "\n", "}" ]
// preallocFileSizes returns a slice of file sizes // that make up the specified total size, exceeding // the specified total as necessary to pad the // remainder to a multiple of 4096 bytes.
[ "preallocFileSizes", "returns", "a", "slice", "of", "file", "sizes", "that", "make", "up", "the", "specified", "total", "size", "exceeding", "the", "specified", "total", "as", "necessary", "to", "pad", "the", "remainder", "to", "a", "multiple", "of", "4096", "bytes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/prealloc.go#L151-L167
3,374
juju/juju
mongo/prealloc.go
doPreallocFile
func doPreallocFile(filename string, size int) (created bool, err error) { if size%preallocAlign != 0 { return false, fmt.Errorf("specified size %v for file %q is not a multiple of %d", size, filename, preallocAlign) } f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0700) if os.IsExist(err) { // already exists, don't overwrite return false, nil } if err != nil { return false, fmt.Errorf("failed to open mongo prealloc file %q: %v", filename, err) } defer f.Close() for written := 0; written < size; { n := len(zeroes) if n > (size - written) { n = size - written } n, err := f.Write(zeroes[:n]) if err != nil { return true, fmt.Errorf("failed to write to mongo prealloc file %q: %v", filename, err) } written += n } return true, nil }
go
func doPreallocFile(filename string, size int) (created bool, err error) { if size%preallocAlign != 0 { return false, fmt.Errorf("specified size %v for file %q is not a multiple of %d", size, filename, preallocAlign) } f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0700) if os.IsExist(err) { // already exists, don't overwrite return false, nil } if err != nil { return false, fmt.Errorf("failed to open mongo prealloc file %q: %v", filename, err) } defer f.Close() for written := 0; written < size; { n := len(zeroes) if n > (size - written) { n = size - written } n, err := f.Write(zeroes[:n]) if err != nil { return true, fmt.Errorf("failed to write to mongo prealloc file %q: %v", filename, err) } written += n } return true, nil }
[ "func", "doPreallocFile", "(", "filename", "string", ",", "size", "int", ")", "(", "created", "bool", ",", "err", "error", ")", "{", "if", "size", "%", "preallocAlign", "!=", "0", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "size", ",", "filename", ",", "preallocAlign", ")", "\n", "}", "\n", "f", ",", "err", ":=", "os", ".", "OpenFile", "(", "filename", ",", "os", ".", "O_WRONLY", "|", "os", ".", "O_CREATE", "|", "os", ".", "O_EXCL", ",", "0700", ")", "\n", "if", "os", ".", "IsExist", "(", "err", ")", "{", "// already exists, don't overwrite", "return", "false", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "filename", ",", "err", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "for", "written", ":=", "0", ";", "written", "<", "size", ";", "{", "n", ":=", "len", "(", "zeroes", ")", "\n", "if", "n", ">", "(", "size", "-", "written", ")", "{", "n", "=", "size", "-", "written", "\n", "}", "\n", "n", ",", "err", ":=", "f", ".", "Write", "(", "zeroes", "[", ":", "n", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "filename", ",", "err", ")", "\n", "}", "\n", "written", "+=", "n", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// doPreallocFile creates a file and writes zeroes up to the specified // extent. If the file exists already, nothing is done and no error // is returned.
[ "doPreallocFile", "creates", "a", "file", "and", "writes", "zeroes", "up", "to", "the", "specified", "extent", ".", "If", "the", "file", "exists", "already", "nothing", "is", "done", "and", "no", "error", "is", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/prealloc.go#L172-L197
3,375
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
NewMockExtensionsV1beta1Interface
func NewMockExtensionsV1beta1Interface(ctrl *gomock.Controller) *MockExtensionsV1beta1Interface { mock := &MockExtensionsV1beta1Interface{ctrl: ctrl} mock.recorder = &MockExtensionsV1beta1InterfaceMockRecorder{mock} return mock }
go
func NewMockExtensionsV1beta1Interface(ctrl *gomock.Controller) *MockExtensionsV1beta1Interface { mock := &MockExtensionsV1beta1Interface{ctrl: ctrl} mock.recorder = &MockExtensionsV1beta1InterfaceMockRecorder{mock} return mock }
[ "func", "NewMockExtensionsV1beta1Interface", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockExtensionsV1beta1Interface", "{", "mock", ":=", "&", "MockExtensionsV1beta1Interface", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockExtensionsV1beta1InterfaceMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockExtensionsV1beta1Interface creates a new mock instance
[ "NewMockExtensionsV1beta1Interface", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L31-L35
3,376
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
DaemonSets
func (mr *MockExtensionsV1beta1InterfaceMockRecorder) DaemonSets(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DaemonSets", reflect.TypeOf((*MockExtensionsV1beta1Interface)(nil).DaemonSets), arg0) }
go
func (mr *MockExtensionsV1beta1InterfaceMockRecorder) DaemonSets(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DaemonSets", reflect.TypeOf((*MockExtensionsV1beta1Interface)(nil).DaemonSets), arg0) }
[ "func", "(", "mr", "*", "MockExtensionsV1beta1InterfaceMockRecorder", ")", "DaemonSets", "(", "arg0", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockExtensionsV1beta1Interface", ")", "(", "nil", ")", ".", "DaemonSets", ")", ",", "arg0", ")", "\n", "}" ]
// DaemonSets indicates an expected call of DaemonSets
[ "DaemonSets", "indicates", "an", "expected", "call", "of", "DaemonSets" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L50-L52
3,377
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
Ingresses
func (m *MockExtensionsV1beta1Interface) Ingresses(arg0 string) v1beta10.IngressInterface { ret := m.ctrl.Call(m, "Ingresses", arg0) ret0, _ := ret[0].(v1beta10.IngressInterface) return ret0 }
go
func (m *MockExtensionsV1beta1Interface) Ingresses(arg0 string) v1beta10.IngressInterface { ret := m.ctrl.Call(m, "Ingresses", arg0) ret0, _ := ret[0].(v1beta10.IngressInterface) return ret0 }
[ "func", "(", "m", "*", "MockExtensionsV1beta1Interface", ")", "Ingresses", "(", "arg0", "string", ")", "v1beta10", ".", "IngressInterface", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "v1beta10", ".", "IngressInterface", ")", "\n", "return", "ret0", "\n", "}" ]
// Ingresses mocks base method
[ "Ingresses", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L67-L71
3,378
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
PodSecurityPolicies
func (m *MockExtensionsV1beta1Interface) PodSecurityPolicies() v1beta10.PodSecurityPolicyInterface { ret := m.ctrl.Call(m, "PodSecurityPolicies") ret0, _ := ret[0].(v1beta10.PodSecurityPolicyInterface) return ret0 }
go
func (m *MockExtensionsV1beta1Interface) PodSecurityPolicies() v1beta10.PodSecurityPolicyInterface { ret := m.ctrl.Call(m, "PodSecurityPolicies") ret0, _ := ret[0].(v1beta10.PodSecurityPolicyInterface) return ret0 }
[ "func", "(", "m", "*", "MockExtensionsV1beta1Interface", ")", "PodSecurityPolicies", "(", ")", "v1beta10", ".", "PodSecurityPolicyInterface", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "v1beta10", ".", "PodSecurityPolicyInterface", ")", "\n", "return", "ret0", "\n", "}" ]
// PodSecurityPolicies mocks base method
[ "PodSecurityPolicies", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L79-L83
3,379
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
PodSecurityPolicies
func (mr *MockExtensionsV1beta1InterfaceMockRecorder) PodSecurityPolicies() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodSecurityPolicies", reflect.TypeOf((*MockExtensionsV1beta1Interface)(nil).PodSecurityPolicies)) }
go
func (mr *MockExtensionsV1beta1InterfaceMockRecorder) PodSecurityPolicies() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodSecurityPolicies", reflect.TypeOf((*MockExtensionsV1beta1Interface)(nil).PodSecurityPolicies)) }
[ "func", "(", "mr", "*", "MockExtensionsV1beta1InterfaceMockRecorder", ")", "PodSecurityPolicies", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockExtensionsV1beta1Interface", ")", "(", "nil", ")", ".", "PodSecurityPolicies", ")", ")", "\n", "}" ]
// PodSecurityPolicies indicates an expected call of PodSecurityPolicies
[ "PodSecurityPolicies", "indicates", "an", "expected", "call", "of", "PodSecurityPolicies" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L86-L88
3,380
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
Scales
func (m *MockExtensionsV1beta1Interface) Scales(arg0 string) v1beta10.ScaleInterface { ret := m.ctrl.Call(m, "Scales", arg0) ret0, _ := ret[0].(v1beta10.ScaleInterface) return ret0 }
go
func (m *MockExtensionsV1beta1Interface) Scales(arg0 string) v1beta10.ScaleInterface { ret := m.ctrl.Call(m, "Scales", arg0) ret0, _ := ret[0].(v1beta10.ScaleInterface) return ret0 }
[ "func", "(", "m", "*", "MockExtensionsV1beta1Interface", ")", "Scales", "(", "arg0", "string", ")", "v1beta10", ".", "ScaleInterface", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "v1beta10", ".", "ScaleInterface", ")", "\n", "return", "ret0", "\n", "}" ]
// Scales mocks base method
[ "Scales", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L115-L119
3,381
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
NewMockIngressInterface
func NewMockIngressInterface(ctrl *gomock.Controller) *MockIngressInterface { mock := &MockIngressInterface{ctrl: ctrl} mock.recorder = &MockIngressInterfaceMockRecorder{mock} return mock }
go
func NewMockIngressInterface(ctrl *gomock.Controller) *MockIngressInterface { mock := &MockIngressInterface{ctrl: ctrl} mock.recorder = &MockIngressInterfaceMockRecorder{mock} return mock }
[ "func", "NewMockIngressInterface", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockIngressInterface", "{", "mock", ":=", "&", "MockIngressInterface", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockIngressInterfaceMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockIngressInterface creates a new mock instance
[ "NewMockIngressInterface", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L138-L142
3,382
juju/juju
caas/kubernetes/provider/mocks/extenstionsv1_mock.go
UpdateStatus
func (mr *MockIngressInterfaceMockRecorder) UpdateStatus(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateStatus", reflect.TypeOf((*MockIngressInterface)(nil).UpdateStatus), arg0) }
go
func (mr *MockIngressInterfaceMockRecorder) UpdateStatus(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateStatus", reflect.TypeOf((*MockIngressInterface)(nil).UpdateStatus), arg0) }
[ "func", "(", "mr", "*", "MockIngressInterfaceMockRecorder", ")", "UpdateStatus", "(", "arg0", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockIngressInterface", ")", "(", "nil", ")", ".", "UpdateStatus", ")", ",", "arg0", ")", "\n", "}" ]
// UpdateStatus indicates an expected call of UpdateStatus
[ "UpdateStatus", "indicates", "an", "expected", "call", "of", "UpdateStatus" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/extenstionsv1_mock.go#L252-L254
3,383
juju/juju
api/machinemanager/machinemanager.go
ConstructClient
func ConstructClient(clientFacade base.ClientFacade, facadeCaller base.FacadeCaller) *Client { return &Client{ClientFacade: clientFacade, facade: facadeCaller} }
go
func ConstructClient(clientFacade base.ClientFacade, facadeCaller base.FacadeCaller) *Client { return &Client{ClientFacade: clientFacade, facade: facadeCaller} }
[ "func", "ConstructClient", "(", "clientFacade", "base", ".", "ClientFacade", ",", "facadeCaller", "base", ".", "FacadeCaller", ")", "*", "Client", "{", "return", "&", "Client", "{", "ClientFacade", ":", "clientFacade", ",", "facade", ":", "facadeCaller", "}", "\n", "}" ]
// ConstructClient is a constructor function for a machine manager client
[ "ConstructClient", "is", "a", "constructor", "function", "for", "a", "machine", "manager", "client" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machinemanager/machinemanager.go#L28-L30
3,384
juju/juju
api/machinemanager/machinemanager.go
NewClient
func NewClient(st base.APICallCloser) *Client { frontend, backend := base.NewClientFacade(st, machineManagerFacade) return ConstructClient(frontend, backend) }
go
func NewClient(st base.APICallCloser) *Client { frontend, backend := base.NewClientFacade(st, machineManagerFacade) return ConstructClient(frontend, backend) }
[ "func", "NewClient", "(", "st", "base", ".", "APICallCloser", ")", "*", "Client", "{", "frontend", ",", "backend", ":=", "base", ".", "NewClientFacade", "(", "st", ",", "machineManagerFacade", ")", "\n", "return", "ConstructClient", "(", "frontend", ",", "backend", ")", "\n", "}" ]
// NewClient returns a new machinemanager client.
[ "NewClient", "returns", "a", "new", "machinemanager", "client", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machinemanager/machinemanager.go#L33-L36
3,385
juju/juju
api/machinemanager/machinemanager.go
AddMachines
func (client *Client) AddMachines(machineParams []params.AddMachineParams) ([]params.AddMachinesResult, error) { args := params.AddMachines{ MachineParams: machineParams, } results := new(params.AddMachinesResults) err := client.facade.FacadeCall("AddMachines", args, results) if len(results.Machines) != len(machineParams) { return nil, errors.Errorf("expected %d result, got %d", len(machineParams), len(results.Machines)) } return results.Machines, err }
go
func (client *Client) AddMachines(machineParams []params.AddMachineParams) ([]params.AddMachinesResult, error) { args := params.AddMachines{ MachineParams: machineParams, } results := new(params.AddMachinesResults) err := client.facade.FacadeCall("AddMachines", args, results) if len(results.Machines) != len(machineParams) { return nil, errors.Errorf("expected %d result, got %d", len(machineParams), len(results.Machines)) } return results.Machines, err }
[ "func", "(", "client", "*", "Client", ")", "AddMachines", "(", "machineParams", "[", "]", "params", ".", "AddMachineParams", ")", "(", "[", "]", "params", ".", "AddMachinesResult", ",", "error", ")", "{", "args", ":=", "params", ".", "AddMachines", "{", "MachineParams", ":", "machineParams", ",", "}", "\n", "results", ":=", "new", "(", "params", ".", "AddMachinesResults", ")", "\n", "err", ":=", "client", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "results", ")", "\n", "if", "len", "(", "results", ".", "Machines", ")", "!=", "len", "(", "machineParams", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "machineParams", ")", ",", "len", "(", "results", ".", "Machines", ")", ")", "\n", "}", "\n", "return", "results", ".", "Machines", ",", "err", "\n", "}" ]
// AddMachines adds new machines with the supplied parameters, creating any requested disks.
[ "AddMachines", "adds", "new", "machines", "with", "the", "supplied", "parameters", "creating", "any", "requested", "disks", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machinemanager/machinemanager.go#L39-L49
3,386
juju/juju
api/machinemanager/machinemanager.go
UpgradeSeriesPrepare
func (client *Client) UpgradeSeriesPrepare(machineName, series string, force bool) error { if client.BestAPIVersion() < 5 { return errors.NotSupportedf("upgrade-series prepare") } args := params.UpdateSeriesArg{ Entity: params.Entity{ Tag: names.NewMachineTag(machineName).String()}, Series: series, Force: force, } result := params.ErrorResult{} if err := client.facade.FacadeCall("UpgradeSeriesPrepare", args, &result); err != nil { return errors.Trace(err) } err := result.Error if err != nil { return common.RestoreError(err) } return nil }
go
func (client *Client) UpgradeSeriesPrepare(machineName, series string, force bool) error { if client.BestAPIVersion() < 5 { return errors.NotSupportedf("upgrade-series prepare") } args := params.UpdateSeriesArg{ Entity: params.Entity{ Tag: names.NewMachineTag(machineName).String()}, Series: series, Force: force, } result := params.ErrorResult{} if err := client.facade.FacadeCall("UpgradeSeriesPrepare", args, &result); err != nil { return errors.Trace(err) } err := result.Error if err != nil { return common.RestoreError(err) } return nil }
[ "func", "(", "client", "*", "Client", ")", "UpgradeSeriesPrepare", "(", "machineName", ",", "series", "string", ",", "force", "bool", ")", "error", "{", "if", "client", ".", "BestAPIVersion", "(", ")", "<", "5", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n", "args", ":=", "params", ".", "UpdateSeriesArg", "{", "Entity", ":", "params", ".", "Entity", "{", "Tag", ":", "names", ".", "NewMachineTag", "(", "machineName", ")", ".", "String", "(", ")", "}", ",", "Series", ":", "series", ",", "Force", ":", "force", ",", "}", "\n", "result", ":=", "params", ".", "ErrorResult", "{", "}", "\n", "if", "err", ":=", "client", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "err", ":=", "result", ".", "Error", "\n", "if", "err", "!=", "nil", "{", "return", "common", ".", "RestoreError", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpgradeSeriesPrepare notifies the controller that a series upgrade is taking // place for a given machine and as such the machine is guarded against // operations that would impede, fail, or interfere with the upgrade process.
[ "UpgradeSeriesPrepare", "notifies", "the", "controller", "that", "a", "series", "upgrade", "is", "taking", "place", "for", "a", "given", "machine", "and", "as", "such", "the", "machine", "is", "guarded", "against", "operations", "that", "would", "impede", "fail", "or", "interfere", "with", "the", "upgrade", "process", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machinemanager/machinemanager.go#L139-L159
3,387
juju/juju
api/machinemanager/machinemanager.go
UpgradeSeriesComplete
func (client *Client) UpgradeSeriesComplete(machineName string) error { if client.BestAPIVersion() < 5 { return errors.NotSupportedf("UpgradeSeriesComplete") } args := params.UpdateSeriesArg{ Entity: params.Entity{Tag: names.NewMachineTag(machineName).String()}, } result := new(params.ErrorResult) err := client.facade.FacadeCall("UpgradeSeriesComplete", args, result) if err != nil { return errors.Trace(err) } if result.Error != nil { return result.Error } return nil }
go
func (client *Client) UpgradeSeriesComplete(machineName string) error { if client.BestAPIVersion() < 5 { return errors.NotSupportedf("UpgradeSeriesComplete") } args := params.UpdateSeriesArg{ Entity: params.Entity{Tag: names.NewMachineTag(machineName).String()}, } result := new(params.ErrorResult) err := client.facade.FacadeCall("UpgradeSeriesComplete", args, result) if err != nil { return errors.Trace(err) } if result.Error != nil { return result.Error } return nil }
[ "func", "(", "client", "*", "Client", ")", "UpgradeSeriesComplete", "(", "machineName", "string", ")", "error", "{", "if", "client", ".", "BestAPIVersion", "(", ")", "<", "5", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n", "args", ":=", "params", ".", "UpdateSeriesArg", "{", "Entity", ":", "params", ".", "Entity", "{", "Tag", ":", "names", ".", "NewMachineTag", "(", "machineName", ")", ".", "String", "(", ")", "}", ",", "}", "\n", "result", ":=", "new", "(", "params", ".", "ErrorResult", ")", "\n", "err", ":=", "client", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "result", ".", "Error", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UpgradeSeriesComplete notifies the controller that a given machine has // successfully completed the managed series upgrade process.
[ "UpgradeSeriesComplete", "notifies", "the", "controller", "that", "a", "given", "machine", "has", "successfully", "completed", "the", "managed", "series", "upgrade", "process", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machinemanager/machinemanager.go#L163-L180
3,388
juju/juju
api/machinemanager/machinemanager.go
GetUpgradeSeriesMessages
func (client *Client) GetUpgradeSeriesMessages(machineName, watcherId string) ([]string, error) { if client.BestAPIVersion() < 5 { return nil, errors.NotSupportedf("GetUpgradeSeriesMessages") } var results params.StringsResults args := params.UpgradeSeriesNotificationParams{ Params: []params.UpgradeSeriesNotificationParam{ { Entity: params.Entity{Tag: names.NewMachineTag(machineName).String()}, WatcherId: watcherId, }, }, } err := client.facade.FacadeCall("GetUpgradeSeriesMessages", args, &results) if err != nil { return nil, errors.Trace(err) } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } return result.Result, nil }
go
func (client *Client) GetUpgradeSeriesMessages(machineName, watcherId string) ([]string, error) { if client.BestAPIVersion() < 5 { return nil, errors.NotSupportedf("GetUpgradeSeriesMessages") } var results params.StringsResults args := params.UpgradeSeriesNotificationParams{ Params: []params.UpgradeSeriesNotificationParam{ { Entity: params.Entity{Tag: names.NewMachineTag(machineName).String()}, WatcherId: watcherId, }, }, } err := client.facade.FacadeCall("GetUpgradeSeriesMessages", args, &results) if err != nil { return nil, errors.Trace(err) } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } return result.Result, nil }
[ "func", "(", "client", "*", "Client", ")", "GetUpgradeSeriesMessages", "(", "machineName", ",", "watcherId", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "client", ".", "BestAPIVersion", "(", ")", "<", "5", "{", "return", "nil", ",", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "results", "params", ".", "StringsResults", "\n", "args", ":=", "params", ".", "UpgradeSeriesNotificationParams", "{", "Params", ":", "[", "]", "params", ".", "UpgradeSeriesNotificationParam", "{", "{", "Entity", ":", "params", ".", "Entity", "{", "Tag", ":", "names", ".", "NewMachineTag", "(", "machineName", ")", ".", "String", "(", ")", "}", ",", "WatcherId", ":", "watcherId", ",", "}", ",", "}", ",", "}", "\n", "err", ":=", "client", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n\n", "return", "result", ".", "Result", ",", "nil", "\n", "}" ]
// GetUpgradeSeriesMessages returns a StringsWatcher for observing the state of // a series upgrade.
[ "GetUpgradeSeriesMessages", "returns", "a", "StringsWatcher", "for", "observing", "the", "state", "of", "a", "series", "upgrade", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/machinemanager/machinemanager.go#L235-L261
3,389
juju/juju
api/caasoperator/client.go
NewClient
func NewClient(caller base.APICaller) *Client { facadeCaller := base.NewFacadeCaller(caller, "CAASOperator") return &Client{ facade: facadeCaller, APIAddresser: common.NewAPIAddresser(facadeCaller), } }
go
func NewClient(caller base.APICaller) *Client { facadeCaller := base.NewFacadeCaller(caller, "CAASOperator") return &Client{ facade: facadeCaller, APIAddresser: common.NewAPIAddresser(facadeCaller), } }
[ "func", "NewClient", "(", "caller", "base", ".", "APICaller", ")", "*", "Client", "{", "facadeCaller", ":=", "base", ".", "NewFacadeCaller", "(", "caller", ",", "\"", "\"", ")", "\n", "return", "&", "Client", "{", "facade", ":", "facadeCaller", ",", "APIAddresser", ":", "common", ".", "NewAPIAddresser", "(", "facadeCaller", ")", ",", "}", "\n", "}" ]
// NewClient returns a client used to access the CAAS Operator API.
[ "NewClient", "returns", "a", "client", "used", "to", "access", "the", "CAAS", "Operator", "API", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperator/client.go#L29-L35
3,390
juju/juju
api/caasoperator/client.go
SetStatus
func (c *Client) SetStatus( application string, status status.Status, info string, data map[string]interface{}, ) error { tag, err := c.appTag(application) if err != nil { return errors.Trace(err) } var result params.ErrorResults args := params.SetStatus{ Entities: []params.EntityStatusArgs{{ Tag: tag.String(), Status: status.String(), Info: info, Data: data, }}, } if err := c.facade.FacadeCall("SetStatus", args, &result); err != nil { return errors.Trace(err) } return result.OneError() }
go
func (c *Client) SetStatus( application string, status status.Status, info string, data map[string]interface{}, ) error { tag, err := c.appTag(application) if err != nil { return errors.Trace(err) } var result params.ErrorResults args := params.SetStatus{ Entities: []params.EntityStatusArgs{{ Tag: tag.String(), Status: status.String(), Info: info, Data: data, }}, } if err := c.facade.FacadeCall("SetStatus", args, &result); err != nil { return errors.Trace(err) } return result.OneError() }
[ "func", "(", "c", "*", "Client", ")", "SetStatus", "(", "application", "string", ",", "status", "status", ".", "Status", ",", "info", "string", ",", "data", "map", "[", "string", "]", "interface", "{", "}", ",", ")", "error", "{", "tag", ",", "err", ":=", "c", ".", "appTag", "(", "application", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "var", "result", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "SetStatus", "{", "Entities", ":", "[", "]", "params", ".", "EntityStatusArgs", "{", "{", "Tag", ":", "tag", ".", "String", "(", ")", ",", "Status", ":", "status", ".", "String", "(", ")", ",", "Info", ":", "info", ",", "Data", ":", "data", ",", "}", "}", ",", "}", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "result", ".", "OneError", "(", ")", "\n", "}" ]
// SetStatus sets the status of the specified application.
[ "SetStatus", "sets", "the", "status", "of", "the", "specified", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperator/client.go#L66-L89
3,391
juju/juju
api/caasoperator/client.go
Charm
func (c *Client) Charm(application string) (_ *charm.URL, forceUpgrade bool, sha256 string, vers int, _ error) { tag, err := c.appTag(application) if err != nil { return nil, false, "", 0, errors.Trace(err) } var results params.ApplicationCharmResults args := params.Entities{ Entities: []params.Entity{{Tag: tag.String()}}, } if err := c.facade.FacadeCall("Charm", args, &results); err != nil { return nil, false, "", 0, errors.Trace(err) } if n := len(results.Results); n != 1 { return nil, false, "", 0, errors.Errorf("expected 1 result, got %d", n) } if err := results.Results[0].Error; err != nil { return nil, false, "", 0, errors.Trace(err) } result := results.Results[0].Result curl, err := charm.ParseURL(result.URL) if err != nil { return nil, false, "", 0, errors.Trace(err) } return curl, result.ForceUpgrade, result.SHA256, result.CharmModifiedVersion, nil }
go
func (c *Client) Charm(application string) (_ *charm.URL, forceUpgrade bool, sha256 string, vers int, _ error) { tag, err := c.appTag(application) if err != nil { return nil, false, "", 0, errors.Trace(err) } var results params.ApplicationCharmResults args := params.Entities{ Entities: []params.Entity{{Tag: tag.String()}}, } if err := c.facade.FacadeCall("Charm", args, &results); err != nil { return nil, false, "", 0, errors.Trace(err) } if n := len(results.Results); n != 1 { return nil, false, "", 0, errors.Errorf("expected 1 result, got %d", n) } if err := results.Results[0].Error; err != nil { return nil, false, "", 0, errors.Trace(err) } result := results.Results[0].Result curl, err := charm.ParseURL(result.URL) if err != nil { return nil, false, "", 0, errors.Trace(err) } return curl, result.ForceUpgrade, result.SHA256, result.CharmModifiedVersion, nil }
[ "func", "(", "c", "*", "Client", ")", "Charm", "(", "application", "string", ")", "(", "_", "*", "charm", ".", "URL", ",", "forceUpgrade", "bool", ",", "sha256", "string", ",", "vers", "int", ",", "_", "error", ")", "{", "tag", ",", "err", ":=", "c", ".", "appTag", "(", "application", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "\"", "\"", ",", "0", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "var", "results", "params", ".", "ApplicationCharmResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "tag", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "\"", "\"", ",", "0", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "n", ":=", "len", "(", "results", ".", "Results", ")", ";", "n", "!=", "1", "{", "return", "nil", ",", "false", ",", "\"", "\"", ",", "0", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "n", ")", "\n", "}", "\n", "if", "err", ":=", "results", ".", "Results", "[", "0", "]", ".", "Error", ";", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "\"", "\"", ",", "0", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", ".", "Result", "\n", "curl", ",", "err", ":=", "charm", ".", "ParseURL", "(", "result", ".", "URL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "\"", "\"", ",", "0", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "curl", ",", "result", ".", "ForceUpgrade", ",", "result", ".", "SHA256", ",", "result", ".", "CharmModifiedVersion", ",", "nil", "\n", "}" ]
// Charm returns information about the charm currently assigned // to the application, including url, force upgrade and sha etc.
[ "Charm", "returns", "information", "about", "the", "charm", "currently", "assigned", "to", "the", "application", "including", "url", "force", "upgrade", "and", "sha", "etc", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperator/client.go#L93-L117
3,392
juju/juju
api/caasoperator/client.go
WatchUnits
func (c *Client) WatchUnits(application string) (watcher.StringsWatcher, error) { applicationTag, err := applicationTag(application) if err != nil { return nil, errors.Trace(err) } args := entities(applicationTag) var results params.StringsWatchResults if err := c.facade.FacadeCall("WatchUnits", args, &results); err != nil { return nil, err } if n := len(results.Results); n != 1 { return nil, errors.Errorf("expected 1 result, got %d", n) } if err := results.Results[0].Error; err != nil { return nil, errors.Trace(err) } w := apiwatcher.NewStringsWatcher(c.facade.RawAPICaller(), results.Results[0]) return w, nil }
go
func (c *Client) WatchUnits(application string) (watcher.StringsWatcher, error) { applicationTag, err := applicationTag(application) if err != nil { return nil, errors.Trace(err) } args := entities(applicationTag) var results params.StringsWatchResults if err := c.facade.FacadeCall("WatchUnits", args, &results); err != nil { return nil, err } if n := len(results.Results); n != 1 { return nil, errors.Errorf("expected 1 result, got %d", n) } if err := results.Results[0].Error; err != nil { return nil, errors.Trace(err) } w := apiwatcher.NewStringsWatcher(c.facade.RawAPICaller(), results.Results[0]) return w, nil }
[ "func", "(", "c", "*", "Client", ")", "WatchUnits", "(", "application", "string", ")", "(", "watcher", ".", "StringsWatcher", ",", "error", ")", "{", "applicationTag", ",", "err", ":=", "applicationTag", "(", "application", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "args", ":=", "entities", "(", "applicationTag", ")", "\n\n", "var", "results", "params", ".", "StringsWatchResults", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "n", ":=", "len", "(", "results", ".", "Results", ")", ";", "n", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "n", ")", "\n", "}", "\n", "if", "err", ":=", "results", ".", "Results", "[", "0", "]", ".", "Error", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "w", ":=", "apiwatcher", ".", "NewStringsWatcher", "(", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ",", "results", ".", "Results", "[", "0", "]", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchUnits returns a StringsWatcher that notifies of // changes to the lifecycles of units of the specified // CAAS application in the current model.
[ "WatchUnits", "returns", "a", "StringsWatcher", "that", "notifies", "of", "changes", "to", "the", "lifecycles", "of", "units", "of", "the", "specified", "CAAS", "application", "in", "the", "current", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperator/client.go#L167-L186
3,393
juju/juju
api/caasoperator/client.go
RemoveUnit
func (c *Client) RemoveUnit(unitName string) error { if !names.IsValidUnit(unitName) { return errors.NotValidf("unit name %q", unitName) } var result params.ErrorResults args := params.Entities{ Entities: []params.Entity{{Tag: names.NewUnitTag(unitName).String()}}, } err := c.facade.FacadeCall("Remove", args, &result) if err != nil { return err } return result.OneError() }
go
func (c *Client) RemoveUnit(unitName string) error { if !names.IsValidUnit(unitName) { return errors.NotValidf("unit name %q", unitName) } var result params.ErrorResults args := params.Entities{ Entities: []params.Entity{{Tag: names.NewUnitTag(unitName).String()}}, } err := c.facade.FacadeCall("Remove", args, &result) if err != nil { return err } return result.OneError() }
[ "func", "(", "c", "*", "Client", ")", "RemoveUnit", "(", "unitName", "string", ")", "error", "{", "if", "!", "names", ".", "IsValidUnit", "(", "unitName", ")", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "unitName", ")", "\n", "}", "\n", "var", "result", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "Entities", "{", "Entities", ":", "[", "]", "params", ".", "Entity", "{", "{", "Tag", ":", "names", ".", "NewUnitTag", "(", "unitName", ")", ".", "String", "(", ")", "}", "}", ",", "}", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "result", ".", "OneError", "(", ")", "\n", "}" ]
// RemoveUnit removes the specified unit from the current model.
[ "RemoveUnit", "removes", "the", "specified", "unit", "from", "the", "current", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperator/client.go#L189-L202
3,394
juju/juju
api/caasoperator/client.go
SetVersion
func (c *Client) SetVersion(appName string, v version.Binary) error { if !names.IsValidApplication(appName) { return errors.NotValidf("application name %q", appName) } var results params.ErrorResults args := params.EntitiesVersion{ AgentTools: []params.EntityVersion{{ Tag: names.NewApplicationTag(appName).String(), Tools: &params.Version{v}, }}, } err := c.facade.FacadeCall("SetTools", args, &results) if err != nil { return errors.Trace(err) } return results.OneError() }
go
func (c *Client) SetVersion(appName string, v version.Binary) error { if !names.IsValidApplication(appName) { return errors.NotValidf("application name %q", appName) } var results params.ErrorResults args := params.EntitiesVersion{ AgentTools: []params.EntityVersion{{ Tag: names.NewApplicationTag(appName).String(), Tools: &params.Version{v}, }}, } err := c.facade.FacadeCall("SetTools", args, &results) if err != nil { return errors.Trace(err) } return results.OneError() }
[ "func", "(", "c", "*", "Client", ")", "SetVersion", "(", "appName", "string", ",", "v", "version", ".", "Binary", ")", "error", "{", "if", "!", "names", ".", "IsValidApplication", "(", "appName", ")", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "appName", ")", "\n", "}", "\n", "var", "results", "params", ".", "ErrorResults", "\n", "args", ":=", "params", ".", "EntitiesVersion", "{", "AgentTools", ":", "[", "]", "params", ".", "EntityVersion", "{", "{", "Tag", ":", "names", ".", "NewApplicationTag", "(", "appName", ")", ".", "String", "(", ")", ",", "Tools", ":", "&", "params", ".", "Version", "{", "v", "}", ",", "}", "}", ",", "}", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "results", ".", "OneError", "(", ")", "\n", "}" ]
// SetVersion sets the tools version associated with // the given application.
[ "SetVersion", "sets", "the", "tools", "version", "associated", "with", "the", "given", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperator/client.go#L242-L258
3,395
juju/juju
state/volume.go
VolumeTag
func (v *volume) VolumeTag() names.VolumeTag { return names.NewVolumeTag(v.doc.Name) }
go
func (v *volume) VolumeTag() names.VolumeTag { return names.NewVolumeTag(v.doc.Name) }
[ "func", "(", "v", "*", "volume", ")", "VolumeTag", "(", ")", "names", ".", "VolumeTag", "{", "return", "names", ".", "NewVolumeTag", "(", "v", ".", "doc", ".", "Name", ")", "\n", "}" ]
// VolumeTag is required to implement Volume.
[ "VolumeTag", "is", "required", "to", "implement", "Volume", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L242-L244
3,396
juju/juju
state/volume.go
StorageInstance
func (v *volume) StorageInstance() (names.StorageTag, error) { if v.doc.StorageId == "" { msg := fmt.Sprintf("volume %q is not assigned to any storage instance", v.Tag().Id()) return names.StorageTag{}, errors.NewNotAssigned(nil, msg) } return names.NewStorageTag(v.doc.StorageId), nil }
go
func (v *volume) StorageInstance() (names.StorageTag, error) { if v.doc.StorageId == "" { msg := fmt.Sprintf("volume %q is not assigned to any storage instance", v.Tag().Id()) return names.StorageTag{}, errors.NewNotAssigned(nil, msg) } return names.NewStorageTag(v.doc.StorageId), nil }
[ "func", "(", "v", "*", "volume", ")", "StorageInstance", "(", ")", "(", "names", ".", "StorageTag", ",", "error", ")", "{", "if", "v", ".", "doc", ".", "StorageId", "==", "\"", "\"", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ".", "Tag", "(", ")", ".", "Id", "(", ")", ")", "\n", "return", "names", ".", "StorageTag", "{", "}", ",", "errors", ".", "NewNotAssigned", "(", "nil", ",", "msg", ")", "\n", "}", "\n", "return", "names", ".", "NewStorageTag", "(", "v", ".", "doc", ".", "StorageId", ")", ",", "nil", "\n", "}" ]
// StorageInstance is required to implement Volume.
[ "StorageInstance", "is", "required", "to", "implement", "Volume", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L252-L258
3,397
juju/juju
state/volume.go
Info
func (v *volume) Info() (VolumeInfo, error) { if v.doc.Info == nil { return VolumeInfo{}, errors.NotProvisionedf("volume %q", v.doc.Name) } return *v.doc.Info, nil }
go
func (v *volume) Info() (VolumeInfo, error) { if v.doc.Info == nil { return VolumeInfo{}, errors.NotProvisionedf("volume %q", v.doc.Name) } return *v.doc.Info, nil }
[ "func", "(", "v", "*", "volume", ")", "Info", "(", ")", "(", "VolumeInfo", ",", "error", ")", "{", "if", "v", ".", "doc", ".", "Info", "==", "nil", "{", "return", "VolumeInfo", "{", "}", ",", "errors", ".", "NotProvisionedf", "(", "\"", "\"", ",", "v", ".", "doc", ".", "Name", ")", "\n", "}", "\n", "return", "*", "v", ".", "doc", ".", "Info", ",", "nil", "\n", "}" ]
// Info is required to implement Volume.
[ "Info", "is", "required", "to", "implement", "Volume", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L261-L266
3,398
juju/juju
state/volume.go
Params
func (v *volume) Params() (VolumeParams, bool) { if v.doc.Params == nil { return VolumeParams{}, false } return *v.doc.Params, true }
go
func (v *volume) Params() (VolumeParams, bool) { if v.doc.Params == nil { return VolumeParams{}, false } return *v.doc.Params, true }
[ "func", "(", "v", "*", "volume", ")", "Params", "(", ")", "(", "VolumeParams", ",", "bool", ")", "{", "if", "v", ".", "doc", ".", "Params", "==", "nil", "{", "return", "VolumeParams", "{", "}", ",", "false", "\n", "}", "\n", "return", "*", "v", ".", "doc", ".", "Params", ",", "true", "\n", "}" ]
// Params is required to implement Volume.
[ "Params", "is", "required", "to", "implement", "Volume", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L269-L274
3,399
juju/juju
state/volume.go
Machine
func (v *volumeAttachmentPlan) Machine() names.MachineTag { return names.NewMachineTag(v.doc.Machine) }
go
func (v *volumeAttachmentPlan) Machine() names.MachineTag { return names.NewMachineTag(v.doc.Machine) }
[ "func", "(", "v", "*", "volumeAttachmentPlan", ")", "Machine", "(", ")", "names", ".", "MachineTag", "{", "return", "names", ".", "NewMachineTag", "(", "v", ".", "doc", ".", "Machine", ")", "\n", "}" ]
// Machine is required to implement VolumeAttachmentPlan.
[ "Machine", "is", "required", "to", "implement", "VolumeAttachmentPlan", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/volume.go#L325-L327