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
155,900
juju/juju
apiserver/facades/agent/uniter/state.go
unitStorageConstraints
func unitStorageConstraints(backend backend, u names.UnitTag) (map[string]state.StorageConstraints, error) { unit, err := backend.Unit(u.Id()) if err != nil { return nil, errors.Trace(err) } cons, err := unit.StorageConstraints() if err != nil { return nil, errors.Trace(err) } return cons, nil }
go
func unitStorageConstraints(backend backend, u names.UnitTag) (map[string]state.StorageConstraints, error) { unit, err := backend.Unit(u.Id()) if err != nil { return nil, errors.Trace(err) } cons, err := unit.StorageConstraints() if err != nil { return nil, errors.Trace(err) } return cons, nil }
[ "func", "unitStorageConstraints", "(", "backend", "backend", ",", "u", "names", ".", "UnitTag", ")", "(", "map", "[", "string", "]", "state", ".", "StorageConstraints", ",", "error", ")", "{", "unit", ",", "err", ":=", "backend", ".", "Unit", "(", "u", ".", "Id", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "cons", ",", "err", ":=", "unit", ".", "StorageConstraints", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "cons", ",", "nil", "\n", "}" ]
// unitStorageConstraints returns storage constraints for this unit, // or an error if the unit or its constraints cannot be obtained.
[ "unitStorageConstraints", "returns", "storage", "constraints", "for", "this", "unit", "or", "an", "error", "if", "the", "unit", "or", "its", "constraints", "cannot", "be", "obtained", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/state.go#L115-L126
155,901
juju/juju
core/leadership/mocks/leadership_mock.go
NewMockPinner
func NewMockPinner(ctrl *gomock.Controller) *MockPinner { mock := &MockPinner{ctrl: ctrl} mock.recorder = &MockPinnerMockRecorder{mock} return mock }
go
func NewMockPinner(ctrl *gomock.Controller) *MockPinner { mock := &MockPinner{ctrl: ctrl} mock.recorder = &MockPinnerMockRecorder{mock} return mock }
[ "func", "NewMockPinner", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockPinner", "{", "mock", ":=", "&", "MockPinner", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockPinnerMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockPinner creates a new mock instance
[ "NewMockPinner", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/leadership/mocks/leadership_mock.go#L25-L29
155,902
juju/juju
core/leadership/mocks/leadership_mock.go
PinLeadership
func (m *MockPinner) PinLeadership(arg0, arg1 string) error { ret := m.ctrl.Call(m, "PinLeadership", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockPinner) PinLeadership(arg0, arg1 string) error { ret := m.ctrl.Call(m, "PinLeadership", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockPinner", ")", "PinLeadership", "(", "arg0", ",", "arg1", "string", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// PinLeadership mocks base method
[ "PinLeadership", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/leadership/mocks/leadership_mock.go#L37-L41
155,903
juju/juju
core/leadership/mocks/leadership_mock.go
PinLeadership
func (mr *MockPinnerMockRecorder) PinLeadership(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PinLeadership", reflect.TypeOf((*MockPinner)(nil).PinLeadership), arg0, arg1) }
go
func (mr *MockPinnerMockRecorder) PinLeadership(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PinLeadership", reflect.TypeOf((*MockPinner)(nil).PinLeadership), arg0, arg1) }
[ "func", "(", "mr", "*", "MockPinnerMockRecorder", ")", "PinLeadership", "(", "arg0", ",", "arg1", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockPinner", ")", "(", "nil", ")", ".", "PinLeadership", ")", ",", "arg0", ",", "arg1", ")", "\n", "}" ]
// PinLeadership indicates an expected call of PinLeadership
[ "PinLeadership", "indicates", "an", "expected", "call", "of", "PinLeadership" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/leadership/mocks/leadership_mock.go#L44-L46
155,904
juju/juju
core/leadership/mocks/leadership_mock.go
PinnedLeadership
func (m *MockPinner) PinnedLeadership() map[string][]string { ret := m.ctrl.Call(m, "PinnedLeadership") ret0, _ := ret[0].(map[string][]string) return ret0 }
go
func (m *MockPinner) PinnedLeadership() map[string][]string { ret := m.ctrl.Call(m, "PinnedLeadership") ret0, _ := ret[0].(map[string][]string) return ret0 }
[ "func", "(", "m", "*", "MockPinner", ")", "PinnedLeadership", "(", ")", "map", "[", "string", "]", "[", "]", "string", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "return", "ret0", "\n", "}" ]
// PinnedLeadership mocks base method
[ "PinnedLeadership", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/leadership/mocks/leadership_mock.go#L49-L53
155,905
juju/juju
core/leadership/mocks/leadership_mock.go
PinnedLeadership
func (mr *MockPinnerMockRecorder) PinnedLeadership() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PinnedLeadership", reflect.TypeOf((*MockPinner)(nil).PinnedLeadership)) }
go
func (mr *MockPinnerMockRecorder) PinnedLeadership() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PinnedLeadership", reflect.TypeOf((*MockPinner)(nil).PinnedLeadership)) }
[ "func", "(", "mr", "*", "MockPinnerMockRecorder", ")", "PinnedLeadership", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockPinner", ")", "(", "nil", ")", ".", "PinnedLeadership", ")", ")", "\n", "}" ]
// PinnedLeadership indicates an expected call of PinnedLeadership
[ "PinnedLeadership", "indicates", "an", "expected", "call", "of", "PinnedLeadership" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/leadership/mocks/leadership_mock.go#L56-L58
155,906
juju/juju
cmd/juju/storage/import.go
NewStorageImporter
func NewStorageImporter(cmd *StorageCommandBase) (StorageImporter, error) { api, err := cmd.NewStorageAPI() return apiStorageImporter{api}, err }
go
func NewStorageImporter(cmd *StorageCommandBase) (StorageImporter, error) { api, err := cmd.NewStorageAPI() return apiStorageImporter{api}, err }
[ "func", "NewStorageImporter", "(", "cmd", "*", "StorageCommandBase", ")", "(", "StorageImporter", ",", "error", ")", "{", "api", ",", "err", ":=", "cmd", ".", "NewStorageAPI", "(", ")", "\n", "return", "apiStorageImporter", "{", "api", "}", ",", "err", "\n", "}" ]
// NewStorageImporter returns a new StorageImporter, // given a StorageCommandBase.
[ "NewStorageImporter", "returns", "a", "new", "StorageImporter", "given", "a", "StorageCommandBase", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/import.go#L47-L50
155,907
juju/juju
apiserver/facades/agent/unitassigner/unitassigner.go
New
func New(st *state.State, res facade.Resources, _ facade.Authorizer) (*API, error) { setter := common.NewStatusSetter(&common.UnitAgentFinder{st}, common.AuthAlways()) return &API{ st: st, res: res, statusSetter: setter, }, nil }
go
func New(st *state.State, res facade.Resources, _ facade.Authorizer) (*API, error) { setter := common.NewStatusSetter(&common.UnitAgentFinder{st}, common.AuthAlways()) return &API{ st: st, res: res, statusSetter: setter, }, nil }
[ "func", "New", "(", "st", "*", "state", ".", "State", ",", "res", "facade", ".", "Resources", ",", "_", "facade", ".", "Authorizer", ")", "(", "*", "API", ",", "error", ")", "{", "setter", ":=", "common", ".", "NewStatusSetter", "(", "&", "common", ".", "UnitAgentFinder", "{", "st", "}", ",", "common", ".", "AuthAlways", "(", ")", ")", "\n", "return", "&", "API", "{", "st", ":", "st", ",", "res", ":", "res", ",", "statusSetter", ":", "setter", ",", "}", ",", "nil", "\n", "}" ]
// New returns a new unitAssigner api instance.
[ "New", "returns", "a", "new", "unitAssigner", "api", "instance", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/unitassigner/unitassigner.go#L36-L43
155,908
juju/juju
apiserver/facades/agent/unitassigner/unitassigner.go
AssignUnits
func (a *API) AssignUnits(args params.Entities) (params.ErrorResults, error) { result := params.ErrorResults{} // state uses ids, but the API uses Tags, so we have to convert back and // forth (whee!). The list of ids is (crucially) in the same order as the // list of tags. This is the same order as the list of errors we return. ids := make([]string, len(args.Entities)) for i, e := range args.Entities { tag, err := names.ParseUnitTag(e.Tag) if err != nil { return result, err } ids[i] = tag.Id() } res, err := a.st.AssignStagedUnits(ids) if err != nil { return result, common.ServerError(err) } // The results come back from state in an undetermined order and do not // include results for units that were not found, so we have to make up for // that here. resultMap := make(map[string]error, len(ids)) for _, r := range res { resultMap[r.Unit] = r.Error } result.Results = make([]params.ErrorResult, len(args.Entities)) for i, id := range ids { if err, ok := resultMap[id]; ok { result.Results[i].Error = common.ServerError(err) } else { result.Results[i].Error = common.ServerError(errors.NotFoundf("unit %q", args.Entities[i].Tag)) } } return result, nil }
go
func (a *API) AssignUnits(args params.Entities) (params.ErrorResults, error) { result := params.ErrorResults{} // state uses ids, but the API uses Tags, so we have to convert back and // forth (whee!). The list of ids is (crucially) in the same order as the // list of tags. This is the same order as the list of errors we return. ids := make([]string, len(args.Entities)) for i, e := range args.Entities { tag, err := names.ParseUnitTag(e.Tag) if err != nil { return result, err } ids[i] = tag.Id() } res, err := a.st.AssignStagedUnits(ids) if err != nil { return result, common.ServerError(err) } // The results come back from state in an undetermined order and do not // include results for units that were not found, so we have to make up for // that here. resultMap := make(map[string]error, len(ids)) for _, r := range res { resultMap[r.Unit] = r.Error } result.Results = make([]params.ErrorResult, len(args.Entities)) for i, id := range ids { if err, ok := resultMap[id]; ok { result.Results[i].Error = common.ServerError(err) } else { result.Results[i].Error = common.ServerError(errors.NotFoundf("unit %q", args.Entities[i].Tag)) } } return result, nil }
[ "func", "(", "a", "*", "API", ")", "AssignUnits", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "result", ":=", "params", ".", "ErrorResults", "{", "}", "\n\n", "// state uses ids, but the API uses Tags, so we have to convert back and", "// forth (whee!). The list of ids is (crucially) in the same order as the", "// list of tags. This is the same order as the list of errors we return.", "ids", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "args", ".", "Entities", ")", ")", "\n", "for", "i", ",", "e", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseUnitTag", "(", "e", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "err", "\n", "}", "\n", "ids", "[", "i", "]", "=", "tag", ".", "Id", "(", ")", "\n", "}", "\n\n", "res", ",", "err", ":=", "a", ".", "st", ".", "AssignStagedUnits", "(", "ids", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n\n", "// The results come back from state in an undetermined order and do not", "// include results for units that were not found, so we have to make up for", "// that here.", "resultMap", ":=", "make", "(", "map", "[", "string", "]", "error", ",", "len", "(", "ids", ")", ")", "\n", "for", "_", ",", "r", ":=", "range", "res", "{", "resultMap", "[", "r", ".", "Unit", "]", "=", "r", ".", "Error", "\n", "}", "\n\n", "result", ".", "Results", "=", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Entities", ")", ")", "\n", "for", "i", ",", "id", ":=", "range", "ids", "{", "if", "err", ",", "ok", ":=", "resultMap", "[", "id", "]", ";", "ok", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "else", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "args", ".", "Entities", "[", "i", "]", ".", "Tag", ")", ")", "\n", "}", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// AssignUnits assigns the units with the given ids to the correct machine. The // error results are returned in the same order as the given entities.
[ "AssignUnits", "assigns", "the", "units", "with", "the", "given", "ids", "to", "the", "correct", "machine", ".", "The", "error", "results", "are", "returned", "in", "the", "same", "order", "as", "the", "given", "entities", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/unitassigner/unitassigner.go#L47-L86
155,909
juju/juju
apiserver/facades/agent/unitassigner/unitassigner.go
WatchUnitAssignments
func (a *API) WatchUnitAssignments() (params.StringsWatchResult, error) { watch := a.st.WatchForUnitAssignment() if changes, ok := <-watch.Changes(); ok { return params.StringsWatchResult{ StringsWatcherId: a.res.Register(watch), Changes: changes, }, nil } return params.StringsWatchResult{}, watcher.EnsureErr(watch) }
go
func (a *API) WatchUnitAssignments() (params.StringsWatchResult, error) { watch := a.st.WatchForUnitAssignment() if changes, ok := <-watch.Changes(); ok { return params.StringsWatchResult{ StringsWatcherId: a.res.Register(watch), Changes: changes, }, nil } return params.StringsWatchResult{}, watcher.EnsureErr(watch) }
[ "func", "(", "a", "*", "API", ")", "WatchUnitAssignments", "(", ")", "(", "params", ".", "StringsWatchResult", ",", "error", ")", "{", "watch", ":=", "a", ".", "st", ".", "WatchForUnitAssignment", "(", ")", "\n", "if", "changes", ",", "ok", ":=", "<-", "watch", ".", "Changes", "(", ")", ";", "ok", "{", "return", "params", ".", "StringsWatchResult", "{", "StringsWatcherId", ":", "a", ".", "res", ".", "Register", "(", "watch", ")", ",", "Changes", ":", "changes", ",", "}", ",", "nil", "\n", "}", "\n", "return", "params", ".", "StringsWatchResult", "{", "}", ",", "watcher", ".", "EnsureErr", "(", "watch", ")", "\n", "}" ]
// WatchUnitAssignments returns a strings watcher that is notified when new unit // assignments are added to the db.
[ "WatchUnitAssignments", "returns", "a", "strings", "watcher", "that", "is", "notified", "when", "new", "unit", "assignments", "are", "added", "to", "the", "db", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/unitassigner/unitassigner.go#L90-L99
155,910
juju/juju
apiserver/facades/agent/unitassigner/unitassigner.go
SetAgentStatus
func (a *API) SetAgentStatus(args params.SetStatus) (params.ErrorResults, error) { return a.statusSetter.SetStatus(args) }
go
func (a *API) SetAgentStatus(args params.SetStatus) (params.ErrorResults, error) { return a.statusSetter.SetStatus(args) }
[ "func", "(", "a", "*", "API", ")", "SetAgentStatus", "(", "args", "params", ".", "SetStatus", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "return", "a", ".", "statusSetter", ".", "SetStatus", "(", "args", ")", "\n", "}" ]
// SetAgentStatus will set status for agents of Units passed in args, if one // of the args is not an Unit it will fail.
[ "SetAgentStatus", "will", "set", "status", "for", "agents", "of", "Units", "passed", "in", "args", "if", "one", "of", "the", "args", "is", "not", "an", "Unit", "it", "will", "fail", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/unitassigner/unitassigner.go#L103-L105
155,911
juju/juju
worker/machineactions/handleactions.go
HandleAction
func HandleAction(name string, params map[string]interface{}) (results map[string]interface{}, err error) { spec, ok := actions.PredefinedActionsSpec[name] if !ok { return nil, errors.Errorf("unexpected action %s", name) } if err := spec.ValidateParams(params); err != nil { return nil, errors.Errorf("invalid action parameters") } switch name { case actions.JujuRunActionName: return handleJujuRunAction(params) default: return nil, errors.Errorf("unexpected action %s", name) } }
go
func HandleAction(name string, params map[string]interface{}) (results map[string]interface{}, err error) { spec, ok := actions.PredefinedActionsSpec[name] if !ok { return nil, errors.Errorf("unexpected action %s", name) } if err := spec.ValidateParams(params); err != nil { return nil, errors.Errorf("invalid action parameters") } switch name { case actions.JujuRunActionName: return handleJujuRunAction(params) default: return nil, errors.Errorf("unexpected action %s", name) } }
[ "func", "HandleAction", "(", "name", "string", ",", "params", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "results", "map", "[", "string", "]", "interface", "{", "}", ",", "err", "error", ")", "{", "spec", ",", "ok", ":=", "actions", ".", "PredefinedActionsSpec", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "if", "err", ":=", "spec", ".", "ValidateParams", "(", "params", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "switch", "name", "{", "case", "actions", ".", "JujuRunActionName", ":", "return", "handleJujuRunAction", "(", "params", ")", "\n", "default", ":", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "}" ]
// HandleAction receives a name and a map of parameters for a given machine action. // It will handle that action in a specific way and return a results map suitable for ActionFinish.
[ "HandleAction", "receives", "a", "name", "and", "a", "map", "of", "parameters", "for", "a", "given", "machine", "action", ".", "It", "will", "handle", "that", "action", "in", "a", "specific", "way", "and", "return", "a", "results", "map", "suitable", "for", "ActionFinish", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/machineactions/handleactions.go#L26-L41
155,912
juju/juju
worker/migrationmaster/worker.go
UploadTools
func (w *uploadWrapper) UploadTools(r io.ReadSeeker, vers version.Binary, additionalSeries ...string) (tools.List, error) { return w.client.UploadTools(w.modelUUID, r, vers, additionalSeries...) }
go
func (w *uploadWrapper) UploadTools(r io.ReadSeeker, vers version.Binary, additionalSeries ...string) (tools.List, error) { return w.client.UploadTools(w.modelUUID, r, vers, additionalSeries...) }
[ "func", "(", "w", "*", "uploadWrapper", ")", "UploadTools", "(", "r", "io", ".", "ReadSeeker", ",", "vers", "version", ".", "Binary", ",", "additionalSeries", "...", "string", ")", "(", "tools", ".", "List", ",", "error", ")", "{", "return", "w", ".", "client", ".", "UploadTools", "(", "w", ".", "modelUUID", ",", "r", ",", "vers", ",", "additionalSeries", "...", ")", "\n", "}" ]
// UploadTools prepends the model UUID to the args passed to the migration client.
[ "UploadTools", "prepends", "the", "model", "UUID", "to", "the", "args", "passed", "to", "the", "migration", "client", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/migrationmaster/worker.go#L369-L371
155,913
juju/juju
worker/migrationmaster/worker.go
UploadCharm
func (w *uploadWrapper) UploadCharm(curl *charm.URL, content io.ReadSeeker) (*charm.URL, error) { return w.client.UploadCharm(w.modelUUID, curl, content) }
go
func (w *uploadWrapper) UploadCharm(curl *charm.URL, content io.ReadSeeker) (*charm.URL, error) { return w.client.UploadCharm(w.modelUUID, curl, content) }
[ "func", "(", "w", "*", "uploadWrapper", ")", "UploadCharm", "(", "curl", "*", "charm", ".", "URL", ",", "content", "io", ".", "ReadSeeker", ")", "(", "*", "charm", ".", "URL", ",", "error", ")", "{", "return", "w", ".", "client", ".", "UploadCharm", "(", "w", ".", "modelUUID", ",", "curl", ",", "content", ")", "\n", "}" ]
// UploadCharm prepends the model UUID to the args passed to the migration client.
[ "UploadCharm", "prepends", "the", "model", "UUID", "to", "the", "args", "passed", "to", "the", "migration", "client", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/migrationmaster/worker.go#L374-L376
155,914
juju/juju
worker/migrationmaster/worker.go
UploadResource
func (w *uploadWrapper) UploadResource(res resource.Resource, content io.ReadSeeker) error { return w.client.UploadResource(w.modelUUID, res, content) }
go
func (w *uploadWrapper) UploadResource(res resource.Resource, content io.ReadSeeker) error { return w.client.UploadResource(w.modelUUID, res, content) }
[ "func", "(", "w", "*", "uploadWrapper", ")", "UploadResource", "(", "res", "resource", ".", "Resource", ",", "content", "io", ".", "ReadSeeker", ")", "error", "{", "return", "w", ".", "client", ".", "UploadResource", "(", "w", ".", "modelUUID", ",", "res", ",", "content", ")", "\n", "}" ]
// UploadResource prepends the model UUID to the args passed to the migration client.
[ "UploadResource", "prepends", "the", "model", "UUID", "to", "the", "args", "passed", "to", "the", "migration", "client", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/migrationmaster/worker.go#L379-L381
155,915
juju/juju
worker/migrationmaster/worker.go
SetPlaceholderResource
func (w *uploadWrapper) SetPlaceholderResource(res resource.Resource) error { return w.client.SetPlaceholderResource(w.modelUUID, res) }
go
func (w *uploadWrapper) SetPlaceholderResource(res resource.Resource) error { return w.client.SetPlaceholderResource(w.modelUUID, res) }
[ "func", "(", "w", "*", "uploadWrapper", ")", "SetPlaceholderResource", "(", "res", "resource", ".", "Resource", ")", "error", "{", "return", "w", ".", "client", ".", "SetPlaceholderResource", "(", "w", ".", "modelUUID", ",", "res", ")", "\n", "}" ]
// SetPlaceholderResource prepends the model UUID to the args passed to the migration client.
[ "SetPlaceholderResource", "prepends", "the", "model", "UUID", "to", "the", "args", "passed", "to", "the", "migration", "client", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/migrationmaster/worker.go#L384-L386
155,916
juju/juju
worker/migrationmaster/worker.go
SetUnitResource
func (w *uploadWrapper) SetUnitResource(unitName string, res resource.Resource) error { return w.client.SetUnitResource(w.modelUUID, unitName, res) }
go
func (w *uploadWrapper) SetUnitResource(unitName string, res resource.Resource) error { return w.client.SetUnitResource(w.modelUUID, unitName, res) }
[ "func", "(", "w", "*", "uploadWrapper", ")", "SetUnitResource", "(", "unitName", "string", ",", "res", "resource", ".", "Resource", ")", "error", "{", "return", "w", ".", "client", ".", "SetUnitResource", "(", "w", ".", "modelUUID", ",", "unitName", ",", "res", ")", "\n", "}" ]
// SetUnitResource prepends the model UUID to the args passed to the migration client.
[ "SetUnitResource", "prepends", "the", "model", "UUID", "to", "the", "args", "passed", "to", "the", "migration", "client", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/migrationmaster/worker.go#L389-L391
155,917
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *MachineInfo) EntityId() EntityId { return EntityId{ Kind: "machine", ModelUUID: i.ModelUUID, Id: i.Id, } }
go
func (i *MachineInfo) EntityId() EntityId { return EntityId{ Kind: "machine", ModelUUID: i.ModelUUID, Id: i.Id, } }
[ "func", "(", "i", "*", "MachineInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Id", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for a machine across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "a", "machine", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L153-L159
155,918
juju/juju
state/multiwatcher/multiwatcher.go
NewStatusInfo
func NewStatusInfo(s status.StatusInfo, err error) StatusInfo { return StatusInfo{ Err: err, Current: s.Status, Message: s.Message, Since: s.Since, Data: s.Data, } }
go
func NewStatusInfo(s status.StatusInfo, err error) StatusInfo { return StatusInfo{ Err: err, Current: s.Status, Message: s.Message, Since: s.Since, Data: s.Data, } }
[ "func", "NewStatusInfo", "(", "s", "status", ".", "StatusInfo", ",", "err", "error", ")", "StatusInfo", "{", "return", "StatusInfo", "{", "Err", ":", "err", ",", "Current", ":", "s", ".", "Status", ",", "Message", ":", "s", ".", "Message", ",", "Since", ":", "s", ".", "Since", ",", "Data", ":", "s", ".", "Data", ",", "}", "\n", "}" ]
// NewStatusInfo return a new multiwatcher StatusInfo from a // status StatusInfo.
[ "NewStatusInfo", "return", "a", "new", "multiwatcher", "StatusInfo", "from", "a", "status", "StatusInfo", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L174-L182
155,919
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *ApplicationInfo) EntityId() EntityId { return EntityId{ Kind: "application", ModelUUID: i.ModelUUID, Id: i.Name, } }
go
func (i *ApplicationInfo) EntityId() EntityId { return EntityId{ Kind: "application", ModelUUID: i.ModelUUID, Id: i.Name, } }
[ "func", "(", "i", "*", "ApplicationInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Name", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for an application across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "an", "application", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L203-L209
155,920
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *CharmInfo) EntityId() EntityId { return EntityId{ Kind: "charm", ModelUUID: i.ModelUUID, Id: i.CharmURL, } }
go
func (i *CharmInfo) EntityId() EntityId { return EntityId{ Kind: "charm", ModelUUID: i.ModelUUID, Id: i.CharmURL, } }
[ "func", "(", "i", "*", "CharmInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "CharmURL", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for an charm across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "an", "charm", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L230-L236
155,921
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *RemoteApplicationInfo) EntityId() EntityId { return EntityId{ Kind: "remoteApplication", ModelUUID: i.ModelUUID, Id: i.Name, } }
go
func (i *RemoteApplicationInfo) EntityId() EntityId { return EntityId{ Kind: "remoteApplication", ModelUUID: i.ModelUUID, Id: i.Name, } }
[ "func", "(", "i", "*", "RemoteApplicationInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Name", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for a remote application across models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "a", "remote", "application", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L250-L256
155,922
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *ApplicationOfferInfo) EntityId() EntityId { return EntityId{ Kind: "applicationOffer", ModelUUID: i.ModelUUID, Id: i.OfferName, } }
go
func (i *ApplicationOfferInfo) EntityId() EntityId { return EntityId{ Kind: "applicationOffer", ModelUUID: i.ModelUUID, Id: i.OfferName, } }
[ "func", "(", "i", "*", "ApplicationOfferInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "OfferName", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for an application offer across models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "an", "application", "offer", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L271-L277
155,923
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *UnitInfo) EntityId() EntityId { return EntityId{ Kind: "unit", ModelUUID: i.ModelUUID, Id: i.Name, } }
go
func (i *UnitInfo) EntityId() EntityId { return EntityId{ Kind: "unit", ModelUUID: i.ModelUUID, Id: i.Name, } }
[ "func", "(", "i", "*", "UnitInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Name", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for a unit across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "a", "unit", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L315-L321
155,924
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *ActionInfo) EntityId() EntityId { return EntityId{ Kind: "action", ModelUUID: i.ModelUUID, Id: i.Id, } }
go
func (i *ActionInfo) EntityId() EntityId { return EntityId{ Kind: "action", ModelUUID: i.ModelUUID, Id: i.Id, } }
[ "func", "(", "i", "*", "ActionInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Id", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for an action across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "an", "action", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L341-L347
155,925
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *RelationInfo) EntityId() EntityId { return EntityId{ Kind: "relation", ModelUUID: i.ModelUUID, Id: i.Key, } }
go
func (i *RelationInfo) EntityId() EntityId { return EntityId{ Kind: "relation", ModelUUID: i.ModelUUID, Id: i.Key, } }
[ "func", "(", "i", "*", "RelationInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Key", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for a relation across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "a", "relation", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L391-L397
155,926
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *AnnotationInfo) EntityId() EntityId { return EntityId{ Kind: "annotation", ModelUUID: i.ModelUUID, Id: i.Tag, } }
go
func (i *AnnotationInfo) EntityId() EntityId { return EntityId{ Kind: "annotation", ModelUUID: i.ModelUUID, Id: i.Tag, } }
[ "func", "(", "i", "*", "AnnotationInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Tag", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for an annotation across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "an", "annotation", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L409-L415
155,927
juju/juju
state/multiwatcher/multiwatcher.go
AnyJobNeedsState
func AnyJobNeedsState(jobs ...MachineJob) bool { for _, j := range jobs { if j.NeedsState() { return true } } return false }
go
func AnyJobNeedsState(jobs ...MachineJob) bool { for _, j := range jobs { if j.NeedsState() { return true } } return false }
[ "func", "AnyJobNeedsState", "(", "jobs", "...", "MachineJob", ")", "bool", "{", "for", "_", ",", "j", ":=", "range", "jobs", "{", "if", "j", ".", "NeedsState", "(", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// AnyJobNeedsState returns true if any of the provided jobs // require a state connection.
[ "AnyJobNeedsState", "returns", "true", "if", "any", "of", "the", "provided", "jobs", "require", "a", "state", "connection", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L433-L440
155,928
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *BlockInfo) EntityId() EntityId { return EntityId{ Kind: "block", ModelUUID: i.ModelUUID, Id: i.Id, } }
go
func (i *BlockInfo) EntityId() EntityId { return EntityId{ Kind: "block", ModelUUID: i.ModelUUID, Id: i.Id, } }
[ "func", "(", "i", "*", "BlockInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "Id", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for a block across // models.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "a", "block", "across", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L454-L460
155,929
juju/juju
state/multiwatcher/multiwatcher.go
EntityId
func (i *ModelInfo) EntityId() EntityId { return EntityId{ Kind: "model", ModelUUID: i.ModelUUID, Id: i.ModelUUID, } }
go
func (i *ModelInfo) EntityId() EntityId { return EntityId{ Kind: "model", ModelUUID: i.ModelUUID, Id: i.ModelUUID, } }
[ "func", "(", "i", "*", "ModelInfo", ")", "EntityId", "(", ")", "EntityId", "{", "return", "EntityId", "{", "Kind", ":", "\"", "\"", ",", "ModelUUID", ":", "i", ".", "ModelUUID", ",", "Id", ":", "i", ".", "ModelUUID", ",", "}", "\n", "}" ]
// EntityId returns a unique identifier for an model.
[ "EntityId", "returns", "a", "unique", "identifier", "for", "an", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher/multiwatcher.go#L499-L505
155,930
juju/juju
cmd/juju/machine/base.go
SetFlags
func (c *baselistMachinesCommand) SetFlags(f *gnuflag.FlagSet) { c.baseMachinesCommand.SetFlags(f) f.BoolVar(&c.isoTime, "utc", false, "Display time as UTC in RFC3339 format") f.BoolVar(&c.color, "color", false, "Force use of ANSI color codes") c.out.AddFlags(f, c.defaultFormat, map[string]cmd.Formatter{ "yaml": cmd.FormatYaml, "json": cmd.FormatJson, "tabular": c.tabular, }) }
go
func (c *baselistMachinesCommand) SetFlags(f *gnuflag.FlagSet) { c.baseMachinesCommand.SetFlags(f) f.BoolVar(&c.isoTime, "utc", false, "Display time as UTC in RFC3339 format") f.BoolVar(&c.color, "color", false, "Force use of ANSI color codes") c.out.AddFlags(f, c.defaultFormat, map[string]cmd.Formatter{ "yaml": cmd.FormatYaml, "json": cmd.FormatJson, "tabular": c.tabular, }) }
[ "func", "(", "c", "*", "baselistMachinesCommand", ")", "SetFlags", "(", "f", "*", "gnuflag", ".", "FlagSet", ")", "{", "c", ".", "baseMachinesCommand", ".", "SetFlags", "(", "f", ")", "\n", "f", ".", "BoolVar", "(", "&", "c", ".", "isoTime", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "f", ".", "BoolVar", "(", "&", "c", ".", "color", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "c", ".", "out", ".", "AddFlags", "(", "f", ",", "c", ".", "defaultFormat", ",", "map", "[", "string", "]", "cmd", ".", "Formatter", "{", "\"", "\"", ":", "cmd", ".", "FormatYaml", ",", "\"", "\"", ":", "cmd", ".", "FormatJson", ",", "\"", "\"", ":", "c", ".", "tabular", ",", "}", ")", "\n", "}" ]
// SetFlags sets utc and format flags based on user specified options.
[ "SetFlags", "sets", "utc", "and", "format", "flags", "based", "on", "user", "specified", "options", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/base.go#L42-L51
155,931
juju/juju
cmd/juju/machine/base.go
Run
func (c *baselistMachinesCommand) Run(ctx *cmd.Context) error { apiclient, err := newAPIClientForMachines(c) if err != nil { return errors.Trace(err) } defer apiclient.Close() fullStatus, err := apiclient.Status(nil) if err != nil { if fullStatus == nil { // Status call completely failed, there is nothing to report return err } // Display any error, but continue to print status if some was returned fmt.Fprintf(ctx.Stderr, "%v\n", err) } else if fullStatus == nil { return errors.Errorf("unable to obtain the current status") } formatter := status.NewStatusFormatter(fullStatus, c.isoTime) formatted := formatter.MachineFormat(c.machineIds) return c.out.Write(ctx, formatted) }
go
func (c *baselistMachinesCommand) Run(ctx *cmd.Context) error { apiclient, err := newAPIClientForMachines(c) if err != nil { return errors.Trace(err) } defer apiclient.Close() fullStatus, err := apiclient.Status(nil) if err != nil { if fullStatus == nil { // Status call completely failed, there is nothing to report return err } // Display any error, but continue to print status if some was returned fmt.Fprintf(ctx.Stderr, "%v\n", err) } else if fullStatus == nil { return errors.Errorf("unable to obtain the current status") } formatter := status.NewStatusFormatter(fullStatus, c.isoTime) formatted := formatter.MachineFormat(c.machineIds) return c.out.Write(ctx, formatted) }
[ "func", "(", "c", "*", "baselistMachinesCommand", ")", "Run", "(", "ctx", "*", "cmd", ".", "Context", ")", "error", "{", "apiclient", ",", "err", ":=", "newAPIClientForMachines", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "defer", "apiclient", ".", "Close", "(", ")", "\n\n", "fullStatus", ",", "err", ":=", "apiclient", ".", "Status", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "if", "fullStatus", "==", "nil", "{", "// Status call completely failed, there is nothing to report", "return", "err", "\n", "}", "\n", "// Display any error, but continue to print status if some was returned", "fmt", ".", "Fprintf", "(", "ctx", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "err", ")", "\n", "}", "else", "if", "fullStatus", "==", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "formatter", ":=", "status", ".", "NewStatusFormatter", "(", "fullStatus", ",", "c", ".", "isoTime", ")", "\n", "formatted", ":=", "formatter", ".", "MachineFormat", "(", "c", ".", "machineIds", ")", "\n", "return", "c", ".", "out", ".", "Write", "(", "ctx", ",", "formatted", ")", "\n", "}" ]
// Run implements Command.Run for baseMachinesCommand.
[ "Run", "implements", "Command", ".", "Run", "for", "baseMachinesCommand", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/base.go#L61-L83
155,932
juju/juju
cmd/juju/storage/volume.go
generateListVolumeOutput
func generateListVolumeOutput(ctx *cmd.Context, api StorageListAPI, ids []string) (map[string]VolumeInfo, error) { results, err := api.ListVolumes(ids) if err != nil { return nil, errors.Trace(err) } // filter out valid output, if any var valid []params.VolumeDetails for _, result := range results { if result.Error == nil { valid = append(valid, result.Result...) continue } // display individual error fmt.Fprintf(ctx.Stderr, "%v\n", result.Error) } if len(valid) == 0 { return nil, nil } return convertToVolumeInfo(valid) }
go
func generateListVolumeOutput(ctx *cmd.Context, api StorageListAPI, ids []string) (map[string]VolumeInfo, error) { results, err := api.ListVolumes(ids) if err != nil { return nil, errors.Trace(err) } // filter out valid output, if any var valid []params.VolumeDetails for _, result := range results { if result.Error == nil { valid = append(valid, result.Result...) continue } // display individual error fmt.Fprintf(ctx.Stderr, "%v\n", result.Error) } if len(valid) == 0 { return nil, nil } return convertToVolumeInfo(valid) }
[ "func", "generateListVolumeOutput", "(", "ctx", "*", "cmd", ".", "Context", ",", "api", "StorageListAPI", ",", "ids", "[", "]", "string", ")", "(", "map", "[", "string", "]", "VolumeInfo", ",", "error", ")", "{", "results", ",", "err", ":=", "api", ".", "ListVolumes", "(", "ids", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// filter out valid output, if any", "var", "valid", "[", "]", "params", ".", "VolumeDetails", "\n", "for", "_", ",", "result", ":=", "range", "results", "{", "if", "result", ".", "Error", "==", "nil", "{", "valid", "=", "append", "(", "valid", ",", "result", ".", "Result", "...", ")", "\n", "continue", "\n", "}", "\n", "// display individual error", "fmt", ".", "Fprintf", "(", "ctx", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "result", ".", "Error", ")", "\n", "}", "\n", "if", "len", "(", "valid", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "convertToVolumeInfo", "(", "valid", ")", "\n", "}" ]
//generateListVolumeOutput returns a map of volume info
[ "generateListVolumeOutput", "returns", "a", "map", "of", "volume", "info" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/volume.go#L74-L94
155,933
juju/juju
cmd/juju/storage/volume.go
convertToVolumeInfo
func convertToVolumeInfo(all []params.VolumeDetails) (map[string]VolumeInfo, error) { result := make(map[string]VolumeInfo) for _, one := range all { volumeTag, info, err := createVolumeInfo(one) if err != nil { return nil, errors.Trace(err) } result[volumeTag.Id()] = info } return result, nil }
go
func convertToVolumeInfo(all []params.VolumeDetails) (map[string]VolumeInfo, error) { result := make(map[string]VolumeInfo) for _, one := range all { volumeTag, info, err := createVolumeInfo(one) if err != nil { return nil, errors.Trace(err) } result[volumeTag.Id()] = info } return result, nil }
[ "func", "convertToVolumeInfo", "(", "all", "[", "]", "params", ".", "VolumeDetails", ")", "(", "map", "[", "string", "]", "VolumeInfo", ",", "error", ")", "{", "result", ":=", "make", "(", "map", "[", "string", "]", "VolumeInfo", ")", "\n", "for", "_", ",", "one", ":=", "range", "all", "{", "volumeTag", ",", "info", ",", "err", ":=", "createVolumeInfo", "(", "one", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", "[", "volumeTag", ".", "Id", "(", ")", "]", "=", "info", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// convertToVolumeInfo returns a map of volume IDs to volume info.
[ "convertToVolumeInfo", "returns", "a", "map", "of", "volume", "IDs", "to", "volume", "info", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/volume.go#L97-L107
155,934
juju/juju
cmd/juju/common/flags.go
ReadAttrs
func (f *ConfigFlag) ReadAttrs(ctx *cmd.Context) (map[string]interface{}, error) { attrs := make(map[string]interface{}) for _, f := range f.files { path, err := utils.NormalizePath(f) if err != nil { return nil, errors.Trace(err) } data, err := ioutil.ReadFile(ctx.AbsPath(path)) if err != nil { return nil, errors.Trace(err) } if err := yaml.Unmarshal(data, &attrs); err != nil { return nil, err } } for k, v := range f.attrs { attrs[k] = v } return attrs, nil }
go
func (f *ConfigFlag) ReadAttrs(ctx *cmd.Context) (map[string]interface{}, error) { attrs := make(map[string]interface{}) for _, f := range f.files { path, err := utils.NormalizePath(f) if err != nil { return nil, errors.Trace(err) } data, err := ioutil.ReadFile(ctx.AbsPath(path)) if err != nil { return nil, errors.Trace(err) } if err := yaml.Unmarshal(data, &attrs); err != nil { return nil, err } } for k, v := range f.attrs { attrs[k] = v } return attrs, nil }
[ "func", "(", "f", "*", "ConfigFlag", ")", "ReadAttrs", "(", "ctx", "*", "cmd", ".", "Context", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "attrs", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "_", ",", "f", ":=", "range", "f", ".", "files", "{", "path", ",", "err", ":=", "utils", ".", "NormalizePath", "(", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "ctx", ".", "AbsPath", "(", "path", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "attrs", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "f", ".", "attrs", "{", "attrs", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "attrs", ",", "nil", "\n", "}" ]
// ReadAttrs reads attributes from the specified files, and then overlays // the results with the k=v attributes.
[ "ReadAttrs", "reads", "attributes", "from", "the", "specified", "files", "and", "then", "overlays", "the", "results", "with", "the", "k", "=", "v", "attributes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/flags.go#L63-L82
155,935
juju/juju
cmd/juju/common/flags.go
ReadConfigPairs
func (f *ConfigFlag) ReadConfigPairs(ctx *cmd.Context) (map[string]interface{}, error) { attrs := make(map[string]interface{}) for k, v := range f.attrs { attrs[k] = v } return attrs, nil }
go
func (f *ConfigFlag) ReadConfigPairs(ctx *cmd.Context) (map[string]interface{}, error) { attrs := make(map[string]interface{}) for k, v := range f.attrs { attrs[k] = v } return attrs, nil }
[ "func", "(", "f", "*", "ConfigFlag", ")", "ReadConfigPairs", "(", "ctx", "*", "cmd", ".", "Context", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "attrs", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "f", ".", "attrs", "{", "attrs", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "attrs", ",", "nil", "\n", "}" ]
// ReadConfigPairs returns just the k=v attributes.
[ "ReadConfigPairs", "returns", "just", "the", "k", "=", "v", "attributes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/flags.go#L85-L91
155,936
juju/juju
cmd/juju/common/flags.go
AbsoluteFileNames
func (f *ConfigFlag) AbsoluteFileNames(ctx *cmd.Context) ([]string, error) { files := make([]string, len(f.files)) for i, f := range f.files { path, err := utils.NormalizePath(f) if err != nil { return nil, errors.Trace(err) } files[i] = ctx.AbsPath(path) } return files, nil }
go
func (f *ConfigFlag) AbsoluteFileNames(ctx *cmd.Context) ([]string, error) { files := make([]string, len(f.files)) for i, f := range f.files { path, err := utils.NormalizePath(f) if err != nil { return nil, errors.Trace(err) } files[i] = ctx.AbsPath(path) } return files, nil }
[ "func", "(", "f", "*", "ConfigFlag", ")", "AbsoluteFileNames", "(", "ctx", "*", "cmd", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "files", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "f", ".", "files", ")", ")", "\n", "for", "i", ",", "f", ":=", "range", "f", ".", "files", "{", "path", ",", "err", ":=", "utils", ".", "NormalizePath", "(", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "files", "[", "i", "]", "=", "ctx", ".", "AbsPath", "(", "path", ")", "\n", "}", "\n", "return", "files", ",", "nil", "\n", "}" ]
// AbsoluteFileNames returns the absolute path of any file names specified.
[ "AbsoluteFileNames", "returns", "the", "absolute", "path", "of", "any", "file", "names", "specified", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/flags.go#L94-L104
155,937
juju/juju
cmd/juju/common/flags.go
WarnConstraintAliases
func WarnConstraintAliases(ctx *cmd.Context, aliases map[string]string) { for alias, canonical := range aliases { ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical) } }
go
func WarnConstraintAliases(ctx *cmd.Context, aliases map[string]string) { for alias, canonical := range aliases { ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical) } }
[ "func", "WarnConstraintAliases", "(", "ctx", "*", "cmd", ".", "Context", ",", "aliases", "map", "[", "string", "]", "string", ")", "{", "for", "alias", ",", "canonical", ":=", "range", "aliases", "{", "ctx", ".", "Infof", "(", "\"", "\\n", "\"", ",", "alias", ",", "canonical", ")", "\n", "}", "\n", "}" ]
// WarnConstraintAliases shows a warning to the user that they have used an // alias for a constraint that might go away sometime.
[ "WarnConstraintAliases", "shows", "a", "warning", "to", "the", "user", "that", "they", "have", "used", "an", "alias", "for", "a", "constraint", "that", "might", "go", "away", "sometime", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/flags.go#L120-L124
155,938
juju/juju
cmd/juju/common/flags.go
ParseConstraints
func ParseConstraints(ctx *cmd.Context, cons string) (constraints.Value, error) { if cons == "" { return constraints.Value{}, nil } constraint, aliases, err := constraints.ParseWithAliases(cons) // we always do these, even on errors, so that the error messages have // context. for alias, canonical := range aliases { ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical) } if err != nil { return constraints.Value{}, err } return constraint, nil }
go
func ParseConstraints(ctx *cmd.Context, cons string) (constraints.Value, error) { if cons == "" { return constraints.Value{}, nil } constraint, aliases, err := constraints.ParseWithAliases(cons) // we always do these, even on errors, so that the error messages have // context. for alias, canonical := range aliases { ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical) } if err != nil { return constraints.Value{}, err } return constraint, nil }
[ "func", "ParseConstraints", "(", "ctx", "*", "cmd", ".", "Context", ",", "cons", "string", ")", "(", "constraints", ".", "Value", ",", "error", ")", "{", "if", "cons", "==", "\"", "\"", "{", "return", "constraints", ".", "Value", "{", "}", ",", "nil", "\n", "}", "\n", "constraint", ",", "aliases", ",", "err", ":=", "constraints", ".", "ParseWithAliases", "(", "cons", ")", "\n", "// we always do these, even on errors, so that the error messages have", "// context.", "for", "alias", ",", "canonical", ":=", "range", "aliases", "{", "ctx", ".", "Infof", "(", "\"", "\\n", "\"", ",", "alias", ",", "canonical", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "constraints", ".", "Value", "{", "}", ",", "err", "\n", "}", "\n", "return", "constraint", ",", "nil", "\n", "}" ]
// ParseConstraints parses the given constraints and uses WarnConstraintAliases // if any aliases were used.
[ "ParseConstraints", "parses", "the", "given", "constraints", "and", "uses", "WarnConstraintAliases", "if", "any", "aliases", "were", "used", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/flags.go#L128-L142
155,939
juju/juju
worker/lease/manifold/manifold.go
Manifold
func Manifold(config ManifoldConfig) dependency.Manifold { s := manifoldState{config: config} return dependency.Manifold{ Inputs: []string{ config.AgentName, config.ClockName, config.CentralHubName, config.StateName, }, Start: s.start, Output: s.output, } }
go
func Manifold(config ManifoldConfig) dependency.Manifold { s := manifoldState{config: config} return dependency.Manifold{ Inputs: []string{ config.AgentName, config.ClockName, config.CentralHubName, config.StateName, }, Start: s.start, Output: s.output, } }
[ "func", "Manifold", "(", "config", "ManifoldConfig", ")", "dependency", ".", "Manifold", "{", "s", ":=", "manifoldState", "{", "config", ":", "config", "}", "\n", "return", "dependency", ".", "Manifold", "{", "Inputs", ":", "[", "]", "string", "{", "config", ".", "AgentName", ",", "config", ".", "ClockName", ",", "config", ".", "CentralHubName", ",", "config", ".", "StateName", ",", "}", ",", "Start", ":", "s", ".", "start", ",", "Output", ":", "s", ".", "output", ",", "}", "\n", "}" ]
// Manifold builds a dependency.Manifold for running a lease manager.
[ "Manifold", "builds", "a", "dependency", ".", "Manifold", "for", "running", "a", "lease", "manager", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/lease/manifold/manifold.go#L191-L203
155,940
juju/juju
worker/lease/manifold/manifold.go
NewWorker
func NewWorker(config lease.ManagerConfig) (worker.Worker, error) { return lease.NewManager(config) }
go
func NewWorker(config lease.ManagerConfig) (worker.Worker, error) { return lease.NewManager(config) }
[ "func", "NewWorker", "(", "config", "lease", ".", "ManagerConfig", ")", "(", "worker", ".", "Worker", ",", "error", ")", "{", "return", "lease", ".", "NewManager", "(", "config", ")", "\n", "}" ]
// NewWorker wraps NewManager to return worker.Worker for testability.
[ "NewWorker", "wraps", "NewManager", "to", "return", "worker", ".", "Worker", "for", "testability", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/lease/manifold/manifold.go#L206-L208
155,941
juju/juju
apiserver/facades/agent/fanconfigurer/fanconfigurer.go
NewFanConfigurerAPI
func NewFanConfigurerAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*FanConfigurerAPI, error) { model, err := st.Model() if err != nil { return nil, err } return NewFanConfigurerAPIForModel(model, resources, authorizer) }
go
func NewFanConfigurerAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*FanConfigurerAPI, error) { model, err := st.Model() if err != nil { return nil, err } return NewFanConfigurerAPIForModel(model, resources, authorizer) }
[ "func", "NewFanConfigurerAPI", "(", "st", "*", "state", ".", "State", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ")", "(", "*", "FanConfigurerAPI", ",", "error", ")", "{", "model", ",", "err", ":=", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "NewFanConfigurerAPIForModel", "(", "model", ",", "resources", ",", "authorizer", ")", "\n", "}" ]
// NewFanConfigurerAPI creates a new FanConfigurer API endpoint on server-side.
[ "NewFanConfigurerAPI", "creates", "a", "new", "FanConfigurer", "API", "endpoint", "on", "server", "-", "side", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/fanconfigurer/fanconfigurer.go#L28-L34
155,942
juju/juju
apiserver/facades/agent/fanconfigurer/fanconfigurer.go
FanConfig
func (m *FanConfigurerAPI) FanConfig() (params.FanConfigResult, error) { result := params.FanConfigResult{} config, err := m.model.ModelConfig() if err != nil { return result, err } fanConfig, err := config.FanConfig() if err != nil { return result, err } return networkingcommon.FanConfigToFanConfigResult(fanConfig), nil }
go
func (m *FanConfigurerAPI) FanConfig() (params.FanConfigResult, error) { result := params.FanConfigResult{} config, err := m.model.ModelConfig() if err != nil { return result, err } fanConfig, err := config.FanConfig() if err != nil { return result, err } return networkingcommon.FanConfigToFanConfigResult(fanConfig), nil }
[ "func", "(", "m", "*", "FanConfigurerAPI", ")", "FanConfig", "(", ")", "(", "params", ".", "FanConfigResult", ",", "error", ")", "{", "result", ":=", "params", ".", "FanConfigResult", "{", "}", "\n", "config", ",", "err", ":=", "m", ".", "model", ".", "ModelConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "err", "\n", "}", "\n", "fanConfig", ",", "err", ":=", "config", ".", "FanConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "err", "\n", "}", "\n", "return", "networkingcommon", ".", "FanConfigToFanConfigResult", "(", "fanConfig", ")", ",", "nil", "\n", "}" ]
// FanConfig returns current FAN configuration.
[ "FanConfig", "returns", "current", "FAN", "configuration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/fanconfigurer/fanconfigurer.go#L68-L79
155,943
juju/juju
state/reboot.go
SetRebootFlag
func (m *Machine) SetRebootFlag(flag bool) error { if flag { return m.setFlag() } return m.clearFlag() }
go
func (m *Machine) SetRebootFlag(flag bool) error { if flag { return m.setFlag() } return m.clearFlag() }
[ "func", "(", "m", "*", "Machine", ")", "SetRebootFlag", "(", "flag", "bool", ")", "error", "{", "if", "flag", "{", "return", "m", ".", "setFlag", "(", ")", "\n", "}", "\n", "return", "m", ".", "clearFlag", "(", ")", "\n", "}" ]
// SetRebootFlag sets the reboot flag of a machine to a boolean value. It will also // do a lazy create of a reboot document if needed; i.e. If a document // does not exist yet for this machine, it will create it.
[ "SetRebootFlag", "sets", "the", "reboot", "flag", "of", "a", "machine", "to", "a", "boolean", "value", ".", "It", "will", "also", "do", "a", "lazy", "create", "of", "a", "reboot", "document", "if", "needed", ";", "i", ".", "e", ".", "If", "a", "document", "does", "not", "exist", "yet", "for", "this", "machine", "it", "will", "create", "it", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/reboot.go#L101-L106
155,944
juju/juju
state/reboot.go
GetRebootFlag
func (m *Machine) GetRebootFlag() (bool, error) { rebootCol, closer := m.st.db().GetCollection(rebootC) defer closer() count, err := rebootCol.FindId(m.doc.DocID).Count() if err != nil { return false, fmt.Errorf("failed to get reboot flag: %v", err) } if count == 0 { return false, nil } return true, nil }
go
func (m *Machine) GetRebootFlag() (bool, error) { rebootCol, closer := m.st.db().GetCollection(rebootC) defer closer() count, err := rebootCol.FindId(m.doc.DocID).Count() if err != nil { return false, fmt.Errorf("failed to get reboot flag: %v", err) } if count == 0 { return false, nil } return true, nil }
[ "func", "(", "m", "*", "Machine", ")", "GetRebootFlag", "(", ")", "(", "bool", ",", "error", ")", "{", "rebootCol", ",", "closer", ":=", "m", ".", "st", ".", "db", "(", ")", ".", "GetCollection", "(", "rebootC", ")", "\n", "defer", "closer", "(", ")", "\n\n", "count", ",", "err", ":=", "rebootCol", ".", "FindId", "(", "m", ".", "doc", ".", "DocID", ")", ".", "Count", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "count", "==", "0", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// GetRebootFlag returns the reboot flag for this machine.
[ "GetRebootFlag", "returns", "the", "reboot", "flag", "for", "this", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/reboot.go#L109-L121
155,945
juju/juju
apiserver/facades/client/spaces/spaces.go
newAPIWithBacking
func newAPIWithBacking(backing networkingcommon.NetworkBacking, ctx context.ProviderCallContext, resources facade.Resources, authorizer facade.Authorizer) (API, error) { // Only clients can access the Spaces facade. if !authorizer.AuthClient() { return nil, common.ErrPerm } return &spacesAPI{ backing: backing, resources: resources, authorizer: authorizer, context: ctx, }, nil }
go
func newAPIWithBacking(backing networkingcommon.NetworkBacking, ctx context.ProviderCallContext, resources facade.Resources, authorizer facade.Authorizer) (API, error) { // Only clients can access the Spaces facade. if !authorizer.AuthClient() { return nil, common.ErrPerm } return &spacesAPI{ backing: backing, resources: resources, authorizer: authorizer, context: ctx, }, nil }
[ "func", "newAPIWithBacking", "(", "backing", "networkingcommon", ".", "NetworkBacking", ",", "ctx", "context", ".", "ProviderCallContext", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ")", "(", "API", ",", "error", ")", "{", "// Only clients can access the Spaces facade.", "if", "!", "authorizer", ".", "AuthClient", "(", ")", "{", "return", "nil", ",", "common", ".", "ErrPerm", "\n", "}", "\n", "return", "&", "spacesAPI", "{", "backing", ":", "backing", ",", "resources", ":", "resources", ",", "authorizer", ":", "authorizer", ",", "context", ":", "ctx", ",", "}", ",", "nil", "\n", "}" ]
// newAPIWithBacking creates a new server-side Spaces API facade with // the given Backing.
[ "newAPIWithBacking", "creates", "a", "new", "server", "-", "side", "Spaces", "API", "facade", "with", "the", "given", "Backing", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/spaces/spaces.go#L52-L63
155,946
juju/juju
apiserver/facades/client/spaces/spaces.go
NewAPIV2
func NewAPIV2(st *state.State, res facade.Resources, auth facade.Authorizer) (APIV2, error) { return NewAPI(st, res, auth) }
go
func NewAPIV2(st *state.State, res facade.Resources, auth facade.Authorizer) (APIV2, error) { return NewAPI(st, res, auth) }
[ "func", "NewAPIV2", "(", "st", "*", "state", ".", "State", ",", "res", "facade", ".", "Resources", ",", "auth", "facade", ".", "Authorizer", ")", "(", "APIV2", ",", "error", ")", "{", "return", "NewAPI", "(", "st", ",", "res", ",", "auth", ")", "\n", "}" ]
// NewAPIV2 is a wrapper that creates a V2 spaces API.
[ "NewAPIV2", "is", "a", "wrapper", "that", "creates", "a", "V2", "spaces", "API", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/spaces/spaces.go#L66-L68
155,947
juju/juju
apiserver/facades/client/spaces/spaces.go
ListSpaces
func (api *spacesAPI) ListSpaces() (results params.ListSpacesResults, err error) { canRead, err := api.authorizer.HasPermission(permission.ReadAccess, api.backing.ModelTag()) if err != nil && !errors.IsNotFound(err) { return results, errors.Trace(err) } if !canRead { return results, common.ServerError(common.ErrPerm) } err = networkingcommon.SupportsSpaces(api.backing, api.context) if err != nil { return results, common.ServerError(errors.Trace(err)) } spaces, err := api.backing.AllSpaces() if err != nil { return results, errors.Trace(err) } results.Results = make([]params.Space, len(spaces)) for i, space := range spaces { result := params.Space{} result.Name = space.Name() subnets, err := space.Subnets() if err != nil { err = errors.Annotatef(err, "fetching subnets") result.Error = common.ServerError(err) results.Results[i] = result continue } result.Subnets = make([]params.Subnet, len(subnets)) for i, subnet := range subnets { result.Subnets[i] = networkingcommon.BackingSubnetToParamsSubnet(subnet) } results.Results[i] = result } return results, nil }
go
func (api *spacesAPI) ListSpaces() (results params.ListSpacesResults, err error) { canRead, err := api.authorizer.HasPermission(permission.ReadAccess, api.backing.ModelTag()) if err != nil && !errors.IsNotFound(err) { return results, errors.Trace(err) } if !canRead { return results, common.ServerError(common.ErrPerm) } err = networkingcommon.SupportsSpaces(api.backing, api.context) if err != nil { return results, common.ServerError(errors.Trace(err)) } spaces, err := api.backing.AllSpaces() if err != nil { return results, errors.Trace(err) } results.Results = make([]params.Space, len(spaces)) for i, space := range spaces { result := params.Space{} result.Name = space.Name() subnets, err := space.Subnets() if err != nil { err = errors.Annotatef(err, "fetching subnets") result.Error = common.ServerError(err) results.Results[i] = result continue } result.Subnets = make([]params.Subnet, len(subnets)) for i, subnet := range subnets { result.Subnets[i] = networkingcommon.BackingSubnetToParamsSubnet(subnet) } results.Results[i] = result } return results, nil }
[ "func", "(", "api", "*", "spacesAPI", ")", "ListSpaces", "(", ")", "(", "results", "params", ".", "ListSpacesResults", ",", "err", "error", ")", "{", "canRead", ",", "err", ":=", "api", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "ReadAccess", ",", "api", ".", "backing", ".", "ModelTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "results", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "canRead", "{", "return", "results", ",", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "}", "\n\n", "err", "=", "networkingcommon", ".", "SupportsSpaces", "(", "api", ".", "backing", ",", "api", ".", "context", ")", "\n", "if", "err", "!=", "nil", "{", "return", "results", ",", "common", ".", "ServerError", "(", "errors", ".", "Trace", "(", "err", ")", ")", "\n", "}", "\n\n", "spaces", ",", "err", ":=", "api", ".", "backing", ".", "AllSpaces", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "results", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "results", ".", "Results", "=", "make", "(", "[", "]", "params", ".", "Space", ",", "len", "(", "spaces", ")", ")", "\n", "for", "i", ",", "space", ":=", "range", "spaces", "{", "result", ":=", "params", ".", "Space", "{", "}", "\n", "result", ".", "Name", "=", "space", ".", "Name", "(", ")", "\n\n", "subnets", ",", "err", ":=", "space", ".", "Subnets", "(", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "result", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "results", ".", "Results", "[", "i", "]", "=", "result", "\n", "continue", "\n", "}", "\n\n", "result", ".", "Subnets", "=", "make", "(", "[", "]", "params", ".", "Subnet", ",", "len", "(", "subnets", ")", ")", "\n", "for", "i", ",", "subnet", ":=", "range", "subnets", "{", "result", ".", "Subnets", "[", "i", "]", "=", "networkingcommon", ".", "BackingSubnetToParamsSubnet", "(", "subnet", ")", "\n", "}", "\n", "results", ".", "Results", "[", "i", "]", "=", "result", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// ListSpaces lists all the available spaces and their associated subnets.
[ "ListSpaces", "lists", "all", "the", "available", "spaces", "and", "their", "associated", "subnets", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/spaces/spaces.go#L85-L124
155,948
juju/juju
apiserver/facades/client/spaces/spaces.go
ReloadSpaces
func (api *spacesAPI) ReloadSpaces() error { canWrite, err := api.authorizer.HasPermission(permission.WriteAccess, api.backing.ModelTag()) if err != nil && !errors.IsNotFound(err) { return errors.Trace(err) } if !canWrite { return common.ServerError(common.ErrPerm) } env, err := environs.GetEnviron(api.backing, environs.New) if err != nil { return errors.Trace(err) } return errors.Trace(api.backing.ReloadSpaces(env)) }
go
func (api *spacesAPI) ReloadSpaces() error { canWrite, err := api.authorizer.HasPermission(permission.WriteAccess, api.backing.ModelTag()) if err != nil && !errors.IsNotFound(err) { return errors.Trace(err) } if !canWrite { return common.ServerError(common.ErrPerm) } env, err := environs.GetEnviron(api.backing, environs.New) if err != nil { return errors.Trace(err) } return errors.Trace(api.backing.ReloadSpaces(env)) }
[ "func", "(", "api", "*", "spacesAPI", ")", "ReloadSpaces", "(", ")", "error", "{", "canWrite", ",", "err", ":=", "api", ".", "authorizer", ".", "HasPermission", "(", "permission", ".", "WriteAccess", ",", "api", ".", "backing", ".", "ModelTag", "(", ")", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "canWrite", "{", "return", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "}", "\n", "env", ",", "err", ":=", "environs", ".", "GetEnviron", "(", "api", ".", "backing", ",", "environs", ".", "New", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "errors", ".", "Trace", "(", "api", ".", "backing", ".", "ReloadSpaces", "(", "env", ")", ")", "\n", "}" ]
// RefreshSpaces refreshes spaces from substrate
[ "RefreshSpaces", "refreshes", "spaces", "from", "substrate" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/spaces/spaces.go#L127-L140
155,949
juju/juju
cmd/juju/model/mocks/checkout_mock.go
NewMockCheckoutCommandAPI
func NewMockCheckoutCommandAPI(ctrl *gomock.Controller) *MockCheckoutCommandAPI { mock := &MockCheckoutCommandAPI{ctrl: ctrl} mock.recorder = &MockCheckoutCommandAPIMockRecorder{mock} return mock }
go
func NewMockCheckoutCommandAPI(ctrl *gomock.Controller) *MockCheckoutCommandAPI { mock := &MockCheckoutCommandAPI{ctrl: ctrl} mock.recorder = &MockCheckoutCommandAPIMockRecorder{mock} return mock }
[ "func", "NewMockCheckoutCommandAPI", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockCheckoutCommandAPI", "{", "mock", ":=", "&", "MockCheckoutCommandAPI", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockCheckoutCommandAPIMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockCheckoutCommandAPI creates a new mock instance
[ "NewMockCheckoutCommandAPI", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/model/mocks/checkout_mock.go#L24-L28
155,950
juju/juju
cmd/juju/model/mocks/checkout_mock.go
HasActiveBranch
func (m *MockCheckoutCommandAPI) HasActiveBranch(arg0 string) (bool, error) { ret := m.ctrl.Call(m, "HasActiveBranch", arg0) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockCheckoutCommandAPI) HasActiveBranch(arg0 string) (bool, error) { ret := m.ctrl.Call(m, "HasActiveBranch", arg0) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockCheckoutCommandAPI", ")", "HasActiveBranch", "(", "arg0", "string", ")", "(", "bool", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "bool", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// HasActiveBranch mocks base method
[ "HasActiveBranch", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/model/mocks/checkout_mock.go#L48-L53
155,951
juju/juju
cmd/juju/model/mocks/checkout_mock.go
HasActiveBranch
func (mr *MockCheckoutCommandAPIMockRecorder) HasActiveBranch(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasActiveBranch", reflect.TypeOf((*MockCheckoutCommandAPI)(nil).HasActiveBranch), arg0) }
go
func (mr *MockCheckoutCommandAPIMockRecorder) HasActiveBranch(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasActiveBranch", reflect.TypeOf((*MockCheckoutCommandAPI)(nil).HasActiveBranch), arg0) }
[ "func", "(", "mr", "*", "MockCheckoutCommandAPIMockRecorder", ")", "HasActiveBranch", "(", "arg0", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockCheckoutCommandAPI", ")", "(", "nil", ")", ".", "HasActiveBranch", ")", ",", "arg0", ")", "\n", "}" ]
// HasActiveBranch indicates an expected call of HasActiveBranch
[ "HasActiveBranch", "indicates", "an", "expected", "call", "of", "HasActiveBranch" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/model/mocks/checkout_mock.go#L56-L58
155,952
juju/juju
worker/apicaller/worker.go
newAPIConnWorker
func newAPIConnWorker(conn api.Connection) worker.Worker { w := &apiConnWorker{conn: conn} w.tomb.Go(w.loop) return w }
go
func newAPIConnWorker(conn api.Connection) worker.Worker { w := &apiConnWorker{conn: conn} w.tomb.Go(w.loop) return w }
[ "func", "newAPIConnWorker", "(", "conn", "api", ".", "Connection", ")", "worker", ".", "Worker", "{", "w", ":=", "&", "apiConnWorker", "{", "conn", ":", "conn", "}", "\n", "w", ".", "tomb", ".", "Go", "(", "w", ".", "loop", ")", "\n", "return", "w", "\n", "}" ]
// newAPIConnWorker returns a worker that exists for as long as the associated // connection, and provides access to a base.APICaller via its manifold's Output // func. If the worker is killed, the connection will be closed; and if the // connection is broken, the worker will be killed. // // The lack of error return is considered and intentional; it signals the // transfer of responsibility for the connection from the caller to the // worker.
[ "newAPIConnWorker", "returns", "a", "worker", "that", "exists", "for", "as", "long", "as", "the", "associated", "connection", "and", "provides", "access", "to", "a", "base", ".", "APICaller", "via", "its", "manifold", "s", "Output", "func", ".", "If", "the", "worker", "is", "killed", "the", "connection", "will", "be", "closed", ";", "and", "if", "the", "connection", "is", "broken", "the", "worker", "will", "be", "killed", ".", "The", "lack", "of", "error", "return", "is", "considered", "and", "intentional", ";", "it", "signals", "the", "transfer", "of", "responsibility", "for", "the", "connection", "from", "the", "caller", "to", "the", "worker", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/apicaller/worker.go#L25-L29
155,953
juju/juju
apiserver/observer/metricobserver/metricobserver.go
Validate
func (cfg Config) Validate() error { if cfg.Clock == nil { return errors.NotValidf("nil Clock") } if cfg.MetricsCollector == nil { return errors.NotValidf("nil MetricsCollector") } return nil }
go
func (cfg Config) Validate() error { if cfg.Clock == nil { return errors.NotValidf("nil Clock") } if cfg.MetricsCollector == nil { return errors.NotValidf("nil MetricsCollector") } return nil }
[ "func", "(", "cfg", "Config", ")", "Validate", "(", ")", "error", "{", "if", "cfg", ".", "Clock", "==", "nil", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "cfg", ".", "MetricsCollector", "==", "nil", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates the observer factory configuration.
[ "Validate", "validates", "the", "observer", "factory", "configuration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/observer/metricobserver/metricobserver.go#L81-L89
155,954
juju/juju
apiserver/observer/metricobserver/metricobserver.go
NewObserverFactory
func NewObserverFactory(config Config) (observer.ObserverFactory, error) { if err := config.Validate(); err != nil { return nil, errors.Annotate(err, "validating config") } // Observer is currently stateless, so we return the same one for each // API connection. Individual RPC requests still get their own RPC // observers. o := &Observer{ clock: config.Clock, metrics: metrics{ apiRequestDuration: config.MetricsCollector.APIRequestDuration(), deprecatedAPIRequestsTotal: config.MetricsCollector.DeprecatedAPIRequestsTotal(), deprecatedAPIRequestDuration: config.MetricsCollector.DeprecatedAPIRequestDuration(), }, } return func() observer.Observer { return o }, nil }
go
func NewObserverFactory(config Config) (observer.ObserverFactory, error) { if err := config.Validate(); err != nil { return nil, errors.Annotate(err, "validating config") } // Observer is currently stateless, so we return the same one for each // API connection. Individual RPC requests still get their own RPC // observers. o := &Observer{ clock: config.Clock, metrics: metrics{ apiRequestDuration: config.MetricsCollector.APIRequestDuration(), deprecatedAPIRequestsTotal: config.MetricsCollector.DeprecatedAPIRequestsTotal(), deprecatedAPIRequestDuration: config.MetricsCollector.DeprecatedAPIRequestDuration(), }, } return func() observer.Observer { return o }, nil }
[ "func", "NewObserverFactory", "(", "config", "Config", ")", "(", "observer", ".", "ObserverFactory", ",", "error", ")", "{", "if", "err", ":=", "config", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Observer is currently stateless, so we return the same one for each", "// API connection. Individual RPC requests still get their own RPC", "// observers.", "o", ":=", "&", "Observer", "{", "clock", ":", "config", ".", "Clock", ",", "metrics", ":", "metrics", "{", "apiRequestDuration", ":", "config", ".", "MetricsCollector", ".", "APIRequestDuration", "(", ")", ",", "deprecatedAPIRequestsTotal", ":", "config", ".", "MetricsCollector", ".", "DeprecatedAPIRequestsTotal", "(", ")", ",", "deprecatedAPIRequestDuration", ":", "config", ".", "MetricsCollector", ".", "DeprecatedAPIRequestDuration", "(", ")", ",", "}", ",", "}", "\n", "return", "func", "(", ")", "observer", ".", "Observer", "{", "return", "o", "\n", "}", ",", "nil", "\n", "}" ]
// NewObserverFactory returns a function that, when called, returns a new // Observer. NewObserverFactory registers the API request metrics, and // each Observer updates those metrics.
[ "NewObserverFactory", "returns", "a", "function", "that", "when", "called", "returns", "a", "new", "Observer", ".", "NewObserverFactory", "registers", "the", "API", "request", "metrics", "and", "each", "Observer", "updates", "those", "metrics", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/observer/metricobserver/metricobserver.go#L94-L113
155,955
juju/juju
apiserver/observer/metricobserver/metricobserver.go
RPCObserver
func (o *Observer) RPCObserver() rpc.Observer { return &rpcObserver{ clock: o.clock, metrics: o.metrics, } }
go
func (o *Observer) RPCObserver() rpc.Observer { return &rpcObserver{ clock: o.clock, metrics: o.metrics, } }
[ "func", "(", "o", "*", "Observer", ")", "RPCObserver", "(", ")", "rpc", ".", "Observer", "{", "return", "&", "rpcObserver", "{", "clock", ":", "o", ".", "clock", ",", "metrics", ":", "o", ".", "metrics", ",", "}", "\n", "}" ]
// RPCObserver is part of the observer.Observer interface.
[ "RPCObserver", "is", "part", "of", "the", "observer", ".", "Observer", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/observer/metricobserver/metricobserver.go#L137-L142
155,956
juju/juju
apiserver/observer/metricobserver/metricobserver.go
ServerRequest
func (o *rpcObserver) ServerRequest(hdr *rpc.Header, body interface{}) { o.requestStart = o.clock.Now() }
go
func (o *rpcObserver) ServerRequest(hdr *rpc.Header, body interface{}) { o.requestStart = o.clock.Now() }
[ "func", "(", "o", "*", "rpcObserver", ")", "ServerRequest", "(", "hdr", "*", "rpc", ".", "Header", ",", "body", "interface", "{", "}", ")", "{", "o", ".", "requestStart", "=", "o", ".", "clock", ".", "Now", "(", ")", "\n", "}" ]
// ServerRequest is part of the rpc.Observer interface.
[ "ServerRequest", "is", "part", "of", "the", "rpc", ".", "Observer", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/observer/metricobserver/metricobserver.go#L151-L153
155,957
juju/juju
apiserver/observer/metricobserver/metricobserver.go
ServerReply
func (o *rpcObserver) ServerReply(req rpc.Request, hdr *rpc.Header, body interface{}) { labels := prometheus.Labels{ MetricLabelFacade: req.Type, MetricLabelVersion: strconv.Itoa(req.Version), MetricLabelMethod: req.Action, MetricLabelErrorCode: hdr.ErrorCode, } duration := o.clock.Now().Sub(o.requestStart) o.metrics.apiRequestDuration.With(labels).Observe(duration.Seconds()) // The following is obsolete and should be removed for 2.6 release o.metrics.deprecatedAPIRequestDuration.With(labels).Observe(duration.Seconds()) o.metrics.deprecatedAPIRequestsTotal.With(labels).Inc() }
go
func (o *rpcObserver) ServerReply(req rpc.Request, hdr *rpc.Header, body interface{}) { labels := prometheus.Labels{ MetricLabelFacade: req.Type, MetricLabelVersion: strconv.Itoa(req.Version), MetricLabelMethod: req.Action, MetricLabelErrorCode: hdr.ErrorCode, } duration := o.clock.Now().Sub(o.requestStart) o.metrics.apiRequestDuration.With(labels).Observe(duration.Seconds()) // The following is obsolete and should be removed for 2.6 release o.metrics.deprecatedAPIRequestDuration.With(labels).Observe(duration.Seconds()) o.metrics.deprecatedAPIRequestsTotal.With(labels).Inc() }
[ "func", "(", "o", "*", "rpcObserver", ")", "ServerReply", "(", "req", "rpc", ".", "Request", ",", "hdr", "*", "rpc", ".", "Header", ",", "body", "interface", "{", "}", ")", "{", "labels", ":=", "prometheus", ".", "Labels", "{", "MetricLabelFacade", ":", "req", ".", "Type", ",", "MetricLabelVersion", ":", "strconv", ".", "Itoa", "(", "req", ".", "Version", ")", ",", "MetricLabelMethod", ":", "req", ".", "Action", ",", "MetricLabelErrorCode", ":", "hdr", ".", "ErrorCode", ",", "}", "\n", "duration", ":=", "o", ".", "clock", ".", "Now", "(", ")", ".", "Sub", "(", "o", ".", "requestStart", ")", "\n", "o", ".", "metrics", ".", "apiRequestDuration", ".", "With", "(", "labels", ")", ".", "Observe", "(", "duration", ".", "Seconds", "(", ")", ")", "\n\n", "// The following is obsolete and should be removed for 2.6 release", "o", ".", "metrics", ".", "deprecatedAPIRequestDuration", ".", "With", "(", "labels", ")", ".", "Observe", "(", "duration", ".", "Seconds", "(", ")", ")", "\n", "o", ".", "metrics", ".", "deprecatedAPIRequestsTotal", ".", "With", "(", "labels", ")", ".", "Inc", "(", ")", "\n", "}" ]
// ServerReply is part of the rpc.Observer interface.
[ "ServerReply", "is", "part", "of", "the", "rpc", ".", "Observer", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/observer/metricobserver/metricobserver.go#L156-L169
155,958
juju/juju
state/blockdevices.go
WatchBlockDevices
func (sb *storageBackend) WatchBlockDevices(machine names.MachineTag) NotifyWatcher { return newBlockDevicesWatcher(sb.mb, machine.Id()) }
go
func (sb *storageBackend) WatchBlockDevices(machine names.MachineTag) NotifyWatcher { return newBlockDevicesWatcher(sb.mb, machine.Id()) }
[ "func", "(", "sb", "*", "storageBackend", ")", "WatchBlockDevices", "(", "machine", "names", ".", "MachineTag", ")", "NotifyWatcher", "{", "return", "newBlockDevicesWatcher", "(", "sb", ".", "mb", ",", "machine", ".", "Id", "(", ")", ")", "\n", "}" ]
// WatchBlockDevices returns a new NotifyWatcher watching for // changes to block devices associated with the specified machine.
[ "WatchBlockDevices", "returns", "a", "new", "NotifyWatcher", "watching", "for", "changes", "to", "block", "devices", "associated", "with", "the", "specified", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/blockdevices.go#L51-L53
155,959
juju/juju
state/blockdevices.go
BlockDevices
func (sb *storageBackend) BlockDevices(machine names.MachineTag) ([]BlockDeviceInfo, error) { return getBlockDevices(sb.mb.db(), machine.Id()) }
go
func (sb *storageBackend) BlockDevices(machine names.MachineTag) ([]BlockDeviceInfo, error) { return getBlockDevices(sb.mb.db(), machine.Id()) }
[ "func", "(", "sb", "*", "storageBackend", ")", "BlockDevices", "(", "machine", "names", ".", "MachineTag", ")", "(", "[", "]", "BlockDeviceInfo", ",", "error", ")", "{", "return", "getBlockDevices", "(", "sb", ".", "mb", ".", "db", "(", ")", ",", "machine", ".", "Id", "(", ")", ")", "\n", "}" ]
// BlockDevices returns the BlockDeviceInfo for the specified machine.
[ "BlockDevices", "returns", "the", "BlockDeviceInfo", "for", "the", "specified", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/blockdevices.go#L56-L58
155,960
juju/juju
state/blockdevices.go
setMachineBlockDevices
func setMachineBlockDevices(st modelBackend, machineId string, newInfo []BlockDeviceInfo) error { db := st.db() buildTxn := func(attempt int) ([]txn.Op, error) { oldInfo, err := getBlockDevices(db, machineId) if err != nil { return nil, errors.Trace(err) } if !blockDevicesChanged(oldInfo, newInfo) { return nil, jujutxn.ErrNoOperations } ops := []txn.Op{{ C: machinesC, Id: machineId, Assert: notDeadDoc, }, { C: blockDevicesC, Id: machineId, Assert: txn.DocExists, Update: bson.D{{"$set", bson.D{{"blockdevices", newInfo}}}}, }} return ops, nil } return db.Run(buildTxn) }
go
func setMachineBlockDevices(st modelBackend, machineId string, newInfo []BlockDeviceInfo) error { db := st.db() buildTxn := func(attempt int) ([]txn.Op, error) { oldInfo, err := getBlockDevices(db, machineId) if err != nil { return nil, errors.Trace(err) } if !blockDevicesChanged(oldInfo, newInfo) { return nil, jujutxn.ErrNoOperations } ops := []txn.Op{{ C: machinesC, Id: machineId, Assert: notDeadDoc, }, { C: blockDevicesC, Id: machineId, Assert: txn.DocExists, Update: bson.D{{"$set", bson.D{{"blockdevices", newInfo}}}}, }} return ops, nil } return db.Run(buildTxn) }
[ "func", "setMachineBlockDevices", "(", "st", "modelBackend", ",", "machineId", "string", ",", "newInfo", "[", "]", "BlockDeviceInfo", ")", "error", "{", "db", ":=", "st", ".", "db", "(", ")", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "oldInfo", ",", "err", ":=", "getBlockDevices", "(", "db", ",", "machineId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "blockDevicesChanged", "(", "oldInfo", ",", "newInfo", ")", "{", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "\n", "ops", ":=", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "machinesC", ",", "Id", ":", "machineId", ",", "Assert", ":", "notDeadDoc", ",", "}", ",", "{", "C", ":", "blockDevicesC", ",", "Id", ":", "machineId", ",", "Assert", ":", "txn", ".", "DocExists", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "newInfo", "}", "}", "}", "}", ",", "}", "}", "\n", "return", "ops", ",", "nil", "\n", "}", "\n", "return", "db", ".", "Run", "(", "buildTxn", ")", "\n", "}" ]
// setMachineBlockDevices updates the blockdevices collection with the // currently attached block devices. Previously recorded block devices // not in the list will be removed.
[ "setMachineBlockDevices", "updates", "the", "blockdevices", "collection", "with", "the", "currently", "attached", "block", "devices", ".", "Previously", "recorded", "block", "devices", "not", "in", "the", "list", "will", "be", "removed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/blockdevices.go#L77-L100
155,961
juju/juju
worker/containerbroker/mocks/machine_lock_mock.go
NewMockLock
func NewMockLock(ctrl *gomock.Controller) *MockLock { mock := &MockLock{ctrl: ctrl} mock.recorder = &MockLockMockRecorder{mock} return mock }
go
func NewMockLock(ctrl *gomock.Controller) *MockLock { mock := &MockLock{ctrl: ctrl} mock.recorder = &MockLockMockRecorder{mock} return mock }
[ "func", "NewMockLock", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockLock", "{", "mock", ":=", "&", "MockLock", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockLockMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockLock creates a new mock instance
[ "NewMockLock", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_lock_mock.go#L25-L29
155,962
juju/juju
worker/containerbroker/mocks/machine_lock_mock.go
Report
func (m *MockLock) Report(arg0 ...machinelock.ReportOption) (string, error) { varargs := []interface{}{} for _, a := range arg0 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "Report", varargs...) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockLock) Report(arg0 ...machinelock.ReportOption) (string, error) { varargs := []interface{}{} for _, a := range arg0 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "Report", varargs...) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockLock", ")", "Report", "(", "arg0", "...", "machinelock", ".", "ReportOption", ")", "(", "string", ",", "error", ")", "{", "varargs", ":=", "[", "]", "interface", "{", "}", "{", "}", "\n", "for", "_", ",", "a", ":=", "range", "arg0", "{", "varargs", "=", "append", "(", "varargs", ",", "a", ")", "\n", "}", "\n", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "varargs", "...", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "string", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// Report mocks base method
[ "Report", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/containerbroker/mocks/machine_lock_mock.go#L50-L59
155,963
juju/juju
api/crossmodelrelations/crossmodelrelations.go
NewClient
func NewClient(caller base.APICallCloser) *Client { return NewClientWithCache(caller, NewMacaroonCache(clock.WallClock)) }
go
func NewClient(caller base.APICallCloser) *Client { return NewClientWithCache(caller, NewMacaroonCache(clock.WallClock)) }
[ "func", "NewClient", "(", "caller", "base", ".", "APICallCloser", ")", "*", "Client", "{", "return", "NewClientWithCache", "(", "caller", ",", "NewMacaroonCache", "(", "clock", ".", "WallClock", ")", ")", "\n", "}" ]
// NewClient creates a new client-side CrossModelRelations facade.
[ "NewClient", "creates", "a", "new", "client", "-", "side", "CrossModelRelations", "facade", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L29-L31
155,964
juju/juju
api/crossmodelrelations/crossmodelrelations.go
NewClientWithCache
func NewClientWithCache(caller base.APICallCloser, cache *MacaroonCache) *Client { frontend, backend := base.NewClientFacade(caller, "CrossModelRelations") return &Client{ ClientFacade: frontend, facade: backend, cache: cache, } }
go
func NewClientWithCache(caller base.APICallCloser, cache *MacaroonCache) *Client { frontend, backend := base.NewClientFacade(caller, "CrossModelRelations") return &Client{ ClientFacade: frontend, facade: backend, cache: cache, } }
[ "func", "NewClientWithCache", "(", "caller", "base", ".", "APICallCloser", ",", "cache", "*", "MacaroonCache", ")", "*", "Client", "{", "frontend", ",", "backend", ":=", "base", ".", "NewClientFacade", "(", "caller", ",", "\"", "\"", ")", "\n", "return", "&", "Client", "{", "ClientFacade", ":", "frontend", ",", "facade", ":", "backend", ",", "cache", ":", "cache", ",", "}", "\n", "}" ]
// NewClientWithCache creates a new client-side CrossModelRelations facade // with the specified cache.
[ "NewClientWithCache", "creates", "a", "new", "client", "-", "side", "CrossModelRelations", "facade", "with", "the", "specified", "cache", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L35-L42
155,965
juju/juju
api/crossmodelrelations/crossmodelrelations.go
handleError
func (c *Client) handleError(apiErr error) (macaroon.Slice, error) { if params.ErrCode(apiErr) != params.CodeDischargeRequired { return nil, apiErr } errResp := errors.Cause(apiErr).(*params.Error) if errResp.Info == nil { return nil, errors.Annotatef(apiErr, "no error info found in discharge-required response error") } logger.Debugf("attempting to discharge macaroon due to error: %v", apiErr) var info params.DischargeRequiredErrorInfo if errUnmarshal := errResp.UnmarshalInfo(&info); errUnmarshal != nil { return nil, errors.Annotatef(apiErr, "unable to extract macaroon details from discharge-required response error") } ms, err := c.facade.RawAPICaller().BakeryClient().DischargeAll(info.Macaroon) if err == nil && logger.IsTraceEnabled() { logger.Tracef("discharge macaroon ids:") for _, m := range ms { logger.Tracef(" - %v", m.Id()) } } if err != nil { return nil, errors.Wrap(apiErr, err) } return ms, err }
go
func (c *Client) handleError(apiErr error) (macaroon.Slice, error) { if params.ErrCode(apiErr) != params.CodeDischargeRequired { return nil, apiErr } errResp := errors.Cause(apiErr).(*params.Error) if errResp.Info == nil { return nil, errors.Annotatef(apiErr, "no error info found in discharge-required response error") } logger.Debugf("attempting to discharge macaroon due to error: %v", apiErr) var info params.DischargeRequiredErrorInfo if errUnmarshal := errResp.UnmarshalInfo(&info); errUnmarshal != nil { return nil, errors.Annotatef(apiErr, "unable to extract macaroon details from discharge-required response error") } ms, err := c.facade.RawAPICaller().BakeryClient().DischargeAll(info.Macaroon) if err == nil && logger.IsTraceEnabled() { logger.Tracef("discharge macaroon ids:") for _, m := range ms { logger.Tracef(" - %v", m.Id()) } } if err != nil { return nil, errors.Wrap(apiErr, err) } return ms, err }
[ "func", "(", "c", "*", "Client", ")", "handleError", "(", "apiErr", "error", ")", "(", "macaroon", ".", "Slice", ",", "error", ")", "{", "if", "params", ".", "ErrCode", "(", "apiErr", ")", "!=", "params", ".", "CodeDischargeRequired", "{", "return", "nil", ",", "apiErr", "\n", "}", "\n", "errResp", ":=", "errors", ".", "Cause", "(", "apiErr", ")", ".", "(", "*", "params", ".", "Error", ")", "\n", "if", "errResp", ".", "Info", "==", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "apiErr", ",", "\"", "\"", ")", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "apiErr", ")", "\n", "var", "info", "params", ".", "DischargeRequiredErrorInfo", "\n", "if", "errUnmarshal", ":=", "errResp", ".", "UnmarshalInfo", "(", "&", "info", ")", ";", "errUnmarshal", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "apiErr", ",", "\"", "\"", ")", "\n", "}", "\n\n", "ms", ",", "err", ":=", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ".", "BakeryClient", "(", ")", ".", "DischargeAll", "(", "info", ".", "Macaroon", ")", "\n", "if", "err", "==", "nil", "&&", "logger", ".", "IsTraceEnabled", "(", ")", "{", "logger", ".", "Tracef", "(", "\"", "\"", ")", "\n", "for", "_", ",", "m", ":=", "range", "ms", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "m", ".", "Id", "(", ")", ")", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "apiErr", ",", "err", ")", "\n", "}", "\n", "return", "ms", ",", "err", "\n", "}" ]
// handleError is used to process an error obtained when making a facade call. // If the error indicates that a macaroon discharge is required, this is done // and the resulting discharge macaroons passed back so the api call can be retried.
[ "handleError", "is", "used", "to", "process", "an", "error", "obtained", "when", "making", "a", "facade", "call", ".", "If", "the", "error", "indicates", "that", "a", "macaroon", "discharge", "is", "required", "this", "is", "done", "and", "the", "resulting", "discharge", "macaroons", "passed", "back", "so", "the", "api", "call", "can", "be", "retried", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L47-L72
155,966
juju/juju
api/crossmodelrelations/crossmodelrelations.go
PublishRelationChange
func (c *Client) PublishRelationChange(change params.RemoteRelationChangeEvent) error { args := params.RemoteRelationsChanges{ Changes: []params.RemoteRelationChangeEvent{change}, } // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("publish relation changed", change.RelationToken); ok { args.Changes[0].Macaroons = ms } apiCall := func() error { var results params.ErrorResults if err := c.facade.FacadeCall("PublishRelationChanges", args, &results); err != nil { return errors.Trace(err) } err := results.OneError() if params.IsCodeNotFound(err) { return errors.NotFoundf("relation for event %v", change) } return err } // Make the api call the first time. err := apiCall() if err == nil || errors.IsNotFound(err) { return errors.Trace(err) } // On error, possibly discharge the macaroon and retry. mac, err2 := c.handleError(err) if err2 != nil { return errors.Trace(err2) } args.Changes[0].Macaroons = mac c.cache.Upsert(args.Changes[0].RelationToken, mac) return apiCall() }
go
func (c *Client) PublishRelationChange(change params.RemoteRelationChangeEvent) error { args := params.RemoteRelationsChanges{ Changes: []params.RemoteRelationChangeEvent{change}, } // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("publish relation changed", change.RelationToken); ok { args.Changes[0].Macaroons = ms } apiCall := func() error { var results params.ErrorResults if err := c.facade.FacadeCall("PublishRelationChanges", args, &results); err != nil { return errors.Trace(err) } err := results.OneError() if params.IsCodeNotFound(err) { return errors.NotFoundf("relation for event %v", change) } return err } // Make the api call the first time. err := apiCall() if err == nil || errors.IsNotFound(err) { return errors.Trace(err) } // On error, possibly discharge the macaroon and retry. mac, err2 := c.handleError(err) if err2 != nil { return errors.Trace(err2) } args.Changes[0].Macaroons = mac c.cache.Upsert(args.Changes[0].RelationToken, mac) return apiCall() }
[ "func", "(", "c", "*", "Client", ")", "PublishRelationChange", "(", "change", "params", ".", "RemoteRelationChangeEvent", ")", "error", "{", "args", ":=", "params", ".", "RemoteRelationsChanges", "{", "Changes", ":", "[", "]", "params", ".", "RemoteRelationChangeEvent", "{", "change", "}", ",", "}", "\n", "// Use any previously cached discharge macaroons.", "if", "ms", ",", "ok", ":=", "c", ".", "getCachedMacaroon", "(", "\"", "\"", ",", "change", ".", "RelationToken", ")", ";", "ok", "{", "args", ".", "Changes", "[", "0", "]", ".", "Macaroons", "=", "ms", "\n", "}", "\n\n", "apiCall", ":=", "func", "(", ")", "error", "{", "var", "results", "params", ".", "ErrorResults", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "err", ":=", "results", ".", "OneError", "(", ")", "\n", "if", "params", ".", "IsCodeNotFound", "(", "err", ")", "{", "return", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "change", ")", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "// Make the api call the first time.", "err", ":=", "apiCall", "(", ")", "\n", "if", "err", "==", "nil", "||", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// On error, possibly discharge the macaroon and retry.", "mac", ",", "err2", ":=", "c", ".", "handleError", "(", "err", ")", "\n", "if", "err2", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err2", ")", "\n", "}", "\n", "args", ".", "Changes", "[", "0", "]", ".", "Macaroons", "=", "mac", "\n", "c", ".", "cache", ".", "Upsert", "(", "args", ".", "Changes", "[", "0", "]", ".", "RelationToken", ",", "mac", ")", "\n", "return", "apiCall", "(", ")", "\n", "}" ]
// PublishRelationChange publishes relation changes to the // model hosting the remote application involved in the relation.
[ "PublishRelationChange", "publishes", "relation", "changes", "to", "the", "model", "hosting", "the", "remote", "application", "involved", "in", "the", "relation", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L89-L123
155,967
juju/juju
api/crossmodelrelations/crossmodelrelations.go
RegisterRemoteRelations
func (c *Client) RegisterRemoteRelations(relations ...params.RegisterRemoteRelationArg) ([]params.RegisterRemoteRelationResult, error) { var ( args params.RegisterRemoteRelationArgs retryIndices []int ) args = params.RegisterRemoteRelationArgs{Relations: relations} // Use any previously cached discharge macaroons. for i, arg := range relations { if ms, ok := c.getCachedMacaroon("register remote relation", arg.RelationToken); ok { newArg := arg newArg.Macaroons = ms args.Relations[i] = newArg } } var results params.RegisterRemoteRelationResults apiCall := func() error { // Reset the results struct before each api call. results = params.RegisterRemoteRelationResults{} err := c.facade.FacadeCall("RegisterRemoteRelations", args, &results) if err != nil { return errors.Trace(err) } if len(results.Results) != len(args.Relations) { return errors.Errorf("expected %d result(s), got %d", len(args.Relations), len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results args = params.RegisterRemoteRelationArgs{} // Separate the successful calls from those needing a retry. for i, res := range results.Results { if res.Error == nil { continue } mac, err := c.handleError(res.Error) if err != nil { resCopy := res resCopy.Error.Message = err.Error() result[i] = resCopy continue } retryArg := relations[i] retryArg.Macaroons = mac args.Relations = append(args.Relations, retryArg) retryIndices = append(retryIndices, i) c.cache.Upsert(retryArg.RelationToken, mac) } // Nothing to retry so return the original result. if len(args.Relations) == 0 { return result, nil } if err := apiCall(); err != nil { return nil, errors.Trace(err) } // After a retry, insert the results into the original result slice. for j, res := range results.Results { resCopy := res result[retryIndices[j]] = resCopy } return result, nil }
go
func (c *Client) RegisterRemoteRelations(relations ...params.RegisterRemoteRelationArg) ([]params.RegisterRemoteRelationResult, error) { var ( args params.RegisterRemoteRelationArgs retryIndices []int ) args = params.RegisterRemoteRelationArgs{Relations: relations} // Use any previously cached discharge macaroons. for i, arg := range relations { if ms, ok := c.getCachedMacaroon("register remote relation", arg.RelationToken); ok { newArg := arg newArg.Macaroons = ms args.Relations[i] = newArg } } var results params.RegisterRemoteRelationResults apiCall := func() error { // Reset the results struct before each api call. results = params.RegisterRemoteRelationResults{} err := c.facade.FacadeCall("RegisterRemoteRelations", args, &results) if err != nil { return errors.Trace(err) } if len(results.Results) != len(args.Relations) { return errors.Errorf("expected %d result(s), got %d", len(args.Relations), len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results args = params.RegisterRemoteRelationArgs{} // Separate the successful calls from those needing a retry. for i, res := range results.Results { if res.Error == nil { continue } mac, err := c.handleError(res.Error) if err != nil { resCopy := res resCopy.Error.Message = err.Error() result[i] = resCopy continue } retryArg := relations[i] retryArg.Macaroons = mac args.Relations = append(args.Relations, retryArg) retryIndices = append(retryIndices, i) c.cache.Upsert(retryArg.RelationToken, mac) } // Nothing to retry so return the original result. if len(args.Relations) == 0 { return result, nil } if err := apiCall(); err != nil { return nil, errors.Trace(err) } // After a retry, insert the results into the original result slice. for j, res := range results.Results { resCopy := res result[retryIndices[j]] = resCopy } return result, nil }
[ "func", "(", "c", "*", "Client", ")", "RegisterRemoteRelations", "(", "relations", "...", "params", ".", "RegisterRemoteRelationArg", ")", "(", "[", "]", "params", ".", "RegisterRemoteRelationResult", ",", "error", ")", "{", "var", "(", "args", "params", ".", "RegisterRemoteRelationArgs", "\n", "retryIndices", "[", "]", "int", "\n", ")", "\n\n", "args", "=", "params", ".", "RegisterRemoteRelationArgs", "{", "Relations", ":", "relations", "}", "\n", "// Use any previously cached discharge macaroons.", "for", "i", ",", "arg", ":=", "range", "relations", "{", "if", "ms", ",", "ok", ":=", "c", ".", "getCachedMacaroon", "(", "\"", "\"", ",", "arg", ".", "RelationToken", ")", ";", "ok", "{", "newArg", ":=", "arg", "\n", "newArg", ".", "Macaroons", "=", "ms", "\n", "args", ".", "Relations", "[", "i", "]", "=", "newArg", "\n", "}", "\n", "}", "\n\n", "var", "results", "params", ".", "RegisterRemoteRelationResults", "\n", "apiCall", ":=", "func", "(", ")", "error", "{", "// Reset the results struct before each api call.", "results", "=", "params", ".", "RegisterRemoteRelationResults", "{", "}", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "len", "(", "args", ".", "Relations", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "args", ".", "Relations", ")", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Make the api call the first time.", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// On error, possibly discharge the macaroon and retry.", "result", ":=", "results", ".", "Results", "\n", "args", "=", "params", ".", "RegisterRemoteRelationArgs", "{", "}", "\n", "// Separate the successful calls from those needing a retry.", "for", "i", ",", "res", ":=", "range", "results", ".", "Results", "{", "if", "res", ".", "Error", "==", "nil", "{", "continue", "\n", "}", "\n", "mac", ",", "err", ":=", "c", ".", "handleError", "(", "res", ".", "Error", ")", "\n", "if", "err", "!=", "nil", "{", "resCopy", ":=", "res", "\n", "resCopy", ".", "Error", ".", "Message", "=", "err", ".", "Error", "(", ")", "\n", "result", "[", "i", "]", "=", "resCopy", "\n", "continue", "\n", "}", "\n", "retryArg", ":=", "relations", "[", "i", "]", "\n", "retryArg", ".", "Macaroons", "=", "mac", "\n", "args", ".", "Relations", "=", "append", "(", "args", ".", "Relations", ",", "retryArg", ")", "\n", "retryIndices", "=", "append", "(", "retryIndices", ",", "i", ")", "\n", "c", ".", "cache", ".", "Upsert", "(", "retryArg", ".", "RelationToken", ",", "mac", ")", "\n", "}", "\n", "// Nothing to retry so return the original result.", "if", "len", "(", "args", ".", "Relations", ")", "==", "0", "{", "return", "result", ",", "nil", "\n", "}", "\n\n", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// After a retry, insert the results into the original result slice.", "for", "j", ",", "res", ":=", "range", "results", ".", "Results", "{", "resCopy", ":=", "res", "\n", "result", "[", "retryIndices", "[", "j", "]", "]", "=", "resCopy", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// RegisterRemoteRelations sets up the remote model to participate // in the specified relations.
[ "RegisterRemoteRelations", "sets", "up", "the", "remote", "model", "to", "participate", "in", "the", "specified", "relations", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L160-L229
155,968
juju/juju
api/crossmodelrelations/crossmodelrelations.go
WatchRelationUnits
func (c *Client) WatchRelationUnits(remoteRelationArg params.RemoteEntityArg) (watcher.RelationUnitsWatcher, error) { args := params.RemoteEntityArgs{Args: []params.RemoteEntityArg{remoteRelationArg}} // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("watch relation units", remoteRelationArg.Token); ok { args.Args[0].Macaroons = ms } var results params.RelationUnitsWatchResults apiCall := func() error { // Reset the results struct before each api call. results = params.RelationUnitsWatchResults{} if err := c.facade.FacadeCall("WatchRelationUnits", args, &results); err != nil { return errors.Trace(err) } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results[0] if result.Error != nil { mac, err := c.handleError(result.Error) if err != nil { result.Error.Message = err.Error() return nil, result.Error } args.Args[0].Macaroons = mac c.cache.Upsert(args.Args[0].Token, mac) if err := apiCall(); err != nil { return nil, errors.Trace(err) } result = results.Results[0] } if result.Error != nil { return nil, result.Error } w := apiwatcher.NewRelationUnitsWatcher(c.facade.RawAPICaller(), result) return w, nil }
go
func (c *Client) WatchRelationUnits(remoteRelationArg params.RemoteEntityArg) (watcher.RelationUnitsWatcher, error) { args := params.RemoteEntityArgs{Args: []params.RemoteEntityArg{remoteRelationArg}} // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("watch relation units", remoteRelationArg.Token); ok { args.Args[0].Macaroons = ms } var results params.RelationUnitsWatchResults apiCall := func() error { // Reset the results struct before each api call. results = params.RelationUnitsWatchResults{} if err := c.facade.FacadeCall("WatchRelationUnits", args, &results); err != nil { return errors.Trace(err) } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results[0] if result.Error != nil { mac, err := c.handleError(result.Error) if err != nil { result.Error.Message = err.Error() return nil, result.Error } args.Args[0].Macaroons = mac c.cache.Upsert(args.Args[0].Token, mac) if err := apiCall(); err != nil { return nil, errors.Trace(err) } result = results.Results[0] } if result.Error != nil { return nil, result.Error } w := apiwatcher.NewRelationUnitsWatcher(c.facade.RawAPICaller(), result) return w, nil }
[ "func", "(", "c", "*", "Client", ")", "WatchRelationUnits", "(", "remoteRelationArg", "params", ".", "RemoteEntityArg", ")", "(", "watcher", ".", "RelationUnitsWatcher", ",", "error", ")", "{", "args", ":=", "params", ".", "RemoteEntityArgs", "{", "Args", ":", "[", "]", "params", ".", "RemoteEntityArg", "{", "remoteRelationArg", "}", "}", "\n", "// Use any previously cached discharge macaroons.", "if", "ms", ",", "ok", ":=", "c", ".", "getCachedMacaroon", "(", "\"", "\"", ",", "remoteRelationArg", ".", "Token", ")", ";", "ok", "{", "args", ".", "Args", "[", "0", "]", ".", "Macaroons", "=", "ms", "\n", "}", "\n\n", "var", "results", "params", ".", "RelationUnitsWatchResults", "\n", "apiCall", ":=", "func", "(", ")", "error", "{", "// Reset the results struct before each api call.", "results", "=", "params", ".", "RelationUnitsWatchResults", "{", "}", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Make the api call the first time.", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// On error, possibly discharge the macaroon and retry.", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "mac", ",", "err", ":=", "c", ".", "handleError", "(", "result", ".", "Error", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Error", ".", "Message", "=", "err", ".", "Error", "(", ")", "\n", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "args", ".", "Args", "[", "0", "]", ".", "Macaroons", "=", "mac", "\n", "c", ".", "cache", ".", "Upsert", "(", "args", ".", "Args", "[", "0", "]", ".", "Token", ",", "mac", ")", "\n\n", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", "=", "results", ".", "Results", "[", "0", "]", "\n", "}", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n\n", "w", ":=", "apiwatcher", ".", "NewRelationUnitsWatcher", "(", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ",", "result", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchRelationUnits returns a watcher that notifies of changes to the // units in the remote model for the relation with the given remote token.
[ "WatchRelationUnits", "returns", "a", "watcher", "that", "notifies", "of", "changes", "to", "the", "units", "in", "the", "remote", "model", "for", "the", "relation", "with", "the", "given", "remote", "token", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L233-L280
155,969
juju/juju
api/crossmodelrelations/crossmodelrelations.go
RelationUnitSettings
func (c *Client) RelationUnitSettings(relationUnits []params.RemoteRelationUnit) ([]params.SettingsResult, error) { var ( args params.RemoteRelationUnits retryIndices []int ) args = params.RemoteRelationUnits{RelationUnits: relationUnits} // Use any previously cached discharge macaroons. for i, arg := range args.RelationUnits { if ms, ok := c.getCachedMacaroon("relation unit settings", arg.RelationToken); ok { newArg := arg newArg.Macaroons = ms args.RelationUnits[i] = newArg } } var results params.SettingsResults apiCall := func() error { // Reset the results struct before each api call. results = params.SettingsResults{} err := c.facade.FacadeCall("RelationUnitSettings", args, &results) if err != nil { return errors.Trace(err) } if len(results.Results) != len(args.RelationUnits) { return errors.Errorf("expected %d result(s), got %d", len(args.RelationUnits), len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results args = params.RemoteRelationUnits{} // Separate the successful calls from those needing a retry. for i, res := range results.Results { if res.Error == nil { continue } mac, err := c.handleError(res.Error) if err != nil { resCopy := res resCopy.Error.Message = err.Error() result[i] = resCopy continue } retryArg := relationUnits[i] retryArg.Macaroons = mac args.RelationUnits = append(args.RelationUnits, retryArg) retryIndices = append(retryIndices, i) c.cache.Upsert(retryArg.RelationToken, mac) } // Nothing to retry so return the original result. if len(args.RelationUnits) == 0 { return result, nil } if err := apiCall(); err != nil { return nil, errors.Trace(err) } // After a retry, insert the results into the original result slice. for j, res := range results.Results { resCopy := res result[retryIndices[j]] = resCopy } return result, nil }
go
func (c *Client) RelationUnitSettings(relationUnits []params.RemoteRelationUnit) ([]params.SettingsResult, error) { var ( args params.RemoteRelationUnits retryIndices []int ) args = params.RemoteRelationUnits{RelationUnits: relationUnits} // Use any previously cached discharge macaroons. for i, arg := range args.RelationUnits { if ms, ok := c.getCachedMacaroon("relation unit settings", arg.RelationToken); ok { newArg := arg newArg.Macaroons = ms args.RelationUnits[i] = newArg } } var results params.SettingsResults apiCall := func() error { // Reset the results struct before each api call. results = params.SettingsResults{} err := c.facade.FacadeCall("RelationUnitSettings", args, &results) if err != nil { return errors.Trace(err) } if len(results.Results) != len(args.RelationUnits) { return errors.Errorf("expected %d result(s), got %d", len(args.RelationUnits), len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results args = params.RemoteRelationUnits{} // Separate the successful calls from those needing a retry. for i, res := range results.Results { if res.Error == nil { continue } mac, err := c.handleError(res.Error) if err != nil { resCopy := res resCopy.Error.Message = err.Error() result[i] = resCopy continue } retryArg := relationUnits[i] retryArg.Macaroons = mac args.RelationUnits = append(args.RelationUnits, retryArg) retryIndices = append(retryIndices, i) c.cache.Upsert(retryArg.RelationToken, mac) } // Nothing to retry so return the original result. if len(args.RelationUnits) == 0 { return result, nil } if err := apiCall(); err != nil { return nil, errors.Trace(err) } // After a retry, insert the results into the original result slice. for j, res := range results.Results { resCopy := res result[retryIndices[j]] = resCopy } return result, nil }
[ "func", "(", "c", "*", "Client", ")", "RelationUnitSettings", "(", "relationUnits", "[", "]", "params", ".", "RemoteRelationUnit", ")", "(", "[", "]", "params", ".", "SettingsResult", ",", "error", ")", "{", "var", "(", "args", "params", ".", "RemoteRelationUnits", "\n", "retryIndices", "[", "]", "int", "\n", ")", "\n\n", "args", "=", "params", ".", "RemoteRelationUnits", "{", "RelationUnits", ":", "relationUnits", "}", "\n", "// Use any previously cached discharge macaroons.", "for", "i", ",", "arg", ":=", "range", "args", ".", "RelationUnits", "{", "if", "ms", ",", "ok", ":=", "c", ".", "getCachedMacaroon", "(", "\"", "\"", ",", "arg", ".", "RelationToken", ")", ";", "ok", "{", "newArg", ":=", "arg", "\n", "newArg", ".", "Macaroons", "=", "ms", "\n", "args", ".", "RelationUnits", "[", "i", "]", "=", "newArg", "\n", "}", "\n", "}", "\n\n", "var", "results", "params", ".", "SettingsResults", "\n", "apiCall", ":=", "func", "(", ")", "error", "{", "// Reset the results struct before each api call.", "results", "=", "params", ".", "SettingsResults", "{", "}", "\n", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "len", "(", "args", ".", "RelationUnits", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "args", ".", "RelationUnits", ")", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Make the api call the first time.", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// On error, possibly discharge the macaroon and retry.", "result", ":=", "results", ".", "Results", "\n", "args", "=", "params", ".", "RemoteRelationUnits", "{", "}", "\n", "// Separate the successful calls from those needing a retry.", "for", "i", ",", "res", ":=", "range", "results", ".", "Results", "{", "if", "res", ".", "Error", "==", "nil", "{", "continue", "\n", "}", "\n", "mac", ",", "err", ":=", "c", ".", "handleError", "(", "res", ".", "Error", ")", "\n", "if", "err", "!=", "nil", "{", "resCopy", ":=", "res", "\n", "resCopy", ".", "Error", ".", "Message", "=", "err", ".", "Error", "(", ")", "\n", "result", "[", "i", "]", "=", "resCopy", "\n", "continue", "\n", "}", "\n", "retryArg", ":=", "relationUnits", "[", "i", "]", "\n", "retryArg", ".", "Macaroons", "=", "mac", "\n", "args", ".", "RelationUnits", "=", "append", "(", "args", ".", "RelationUnits", ",", "retryArg", ")", "\n", "retryIndices", "=", "append", "(", "retryIndices", ",", "i", ")", "\n", "c", ".", "cache", ".", "Upsert", "(", "retryArg", ".", "RelationToken", ",", "mac", ")", "\n", "}", "\n", "// Nothing to retry so return the original result.", "if", "len", "(", "args", ".", "RelationUnits", ")", "==", "0", "{", "return", "result", ",", "nil", "\n", "}", "\n\n", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// After a retry, insert the results into the original result slice.", "for", "j", ",", "res", ":=", "range", "results", ".", "Results", "{", "resCopy", ":=", "res", "\n", "result", "[", "retryIndices", "[", "j", "]", "]", "=", "resCopy", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// RelationUnitSettings returns the relation unit settings for the given relation units in the remote model.
[ "RelationUnitSettings", "returns", "the", "relation", "unit", "settings", "for", "the", "given", "relation", "units", "in", "the", "remote", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L283-L352
155,970
juju/juju
api/crossmodelrelations/crossmodelrelations.go
WatchRelationSuspendedStatus
func (c *Client) WatchRelationSuspendedStatus(arg params.RemoteEntityArg) (watcher.RelationStatusWatcher, error) { args := params.RemoteEntityArgs{Args: []params.RemoteEntityArg{arg}} // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("watch relation status", arg.Token); ok { args.Args[0].Macaroons = ms } var results params.RelationStatusWatchResults apiCall := func() error { // Reset the results struct before each api call. results = params.RelationStatusWatchResults{} if err := c.facade.FacadeCall("WatchRelationsSuspendedStatus", args, &results); err != nil { return errors.Trace(err) } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results[0] if result.Error != nil { mac, err := c.handleError(result.Error) if err != nil { result.Error.Message = err.Error() return nil, result.Error } args.Args[0].Macaroons = mac c.cache.Upsert(args.Args[0].Token, mac) if err := apiCall(); err != nil { return nil, errors.Trace(err) } result = results.Results[0] } if result.Error != nil { return nil, result.Error } w := apiwatcher.NewRelationStatusWatcher(c.facade.RawAPICaller(), result) return w, nil }
go
func (c *Client) WatchRelationSuspendedStatus(arg params.RemoteEntityArg) (watcher.RelationStatusWatcher, error) { args := params.RemoteEntityArgs{Args: []params.RemoteEntityArg{arg}} // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("watch relation status", arg.Token); ok { args.Args[0].Macaroons = ms } var results params.RelationStatusWatchResults apiCall := func() error { // Reset the results struct before each api call. results = params.RelationStatusWatchResults{} if err := c.facade.FacadeCall("WatchRelationsSuspendedStatus", args, &results); err != nil { return errors.Trace(err) } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results[0] if result.Error != nil { mac, err := c.handleError(result.Error) if err != nil { result.Error.Message = err.Error() return nil, result.Error } args.Args[0].Macaroons = mac c.cache.Upsert(args.Args[0].Token, mac) if err := apiCall(); err != nil { return nil, errors.Trace(err) } result = results.Results[0] } if result.Error != nil { return nil, result.Error } w := apiwatcher.NewRelationStatusWatcher(c.facade.RawAPICaller(), result) return w, nil }
[ "func", "(", "c", "*", "Client", ")", "WatchRelationSuspendedStatus", "(", "arg", "params", ".", "RemoteEntityArg", ")", "(", "watcher", ".", "RelationStatusWatcher", ",", "error", ")", "{", "args", ":=", "params", ".", "RemoteEntityArgs", "{", "Args", ":", "[", "]", "params", ".", "RemoteEntityArg", "{", "arg", "}", "}", "\n", "// Use any previously cached discharge macaroons.", "if", "ms", ",", "ok", ":=", "c", ".", "getCachedMacaroon", "(", "\"", "\"", ",", "arg", ".", "Token", ")", ";", "ok", "{", "args", ".", "Args", "[", "0", "]", ".", "Macaroons", "=", "ms", "\n", "}", "\n\n", "var", "results", "params", ".", "RelationStatusWatchResults", "\n", "apiCall", ":=", "func", "(", ")", "error", "{", "// Reset the results struct before each api call.", "results", "=", "params", ".", "RelationStatusWatchResults", "{", "}", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Make the api call the first time.", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// On error, possibly discharge the macaroon and retry.", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "mac", ",", "err", ":=", "c", ".", "handleError", "(", "result", ".", "Error", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Error", ".", "Message", "=", "err", ".", "Error", "(", ")", "\n", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "args", ".", "Args", "[", "0", "]", ".", "Macaroons", "=", "mac", "\n", "c", ".", "cache", ".", "Upsert", "(", "args", ".", "Args", "[", "0", "]", ".", "Token", ",", "mac", ")", "\n\n", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", "=", "results", ".", "Results", "[", "0", "]", "\n", "}", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n\n", "w", ":=", "apiwatcher", ".", "NewRelationStatusWatcher", "(", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ",", "result", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchRelationSuspendedStatus starts a RelationStatusWatcher for watching the life and // suspended status of the specified relation in the remote model.
[ "WatchRelationSuspendedStatus", "starts", "a", "RelationStatusWatcher", "for", "watching", "the", "life", "and", "suspended", "status", "of", "the", "specified", "relation", "in", "the", "remote", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L409-L456
155,971
juju/juju
api/crossmodelrelations/crossmodelrelations.go
WatchOfferStatus
func (c *Client) WatchOfferStatus(arg params.OfferArg) (watcher.OfferStatusWatcher, error) { args := params.OfferArgs{Args: []params.OfferArg{arg}} // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("watch offer status", arg.OfferUUID); ok { args.Args[0].Macaroons = ms } var results params.OfferStatusWatchResults apiCall := func() error { // Reset the results struct before each api call. results = params.OfferStatusWatchResults{} if err := c.facade.FacadeCall("WatchOfferStatus", args, &results); err != nil { return errors.Trace(err) } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results[0] if result.Error != nil { mac, err := c.handleError(result.Error) if err != nil { result.Error.Message = err.Error() return nil, result.Error } args.Args[0].Macaroons = mac c.cache.Upsert(args.Args[0].OfferUUID, mac) if err := apiCall(); err != nil { return nil, errors.Trace(err) } result = results.Results[0] } if result.Error != nil { return nil, result.Error } w := apiwatcher.NewOfferStatusWatcher(c.facade.RawAPICaller(), result) return w, nil }
go
func (c *Client) WatchOfferStatus(arg params.OfferArg) (watcher.OfferStatusWatcher, error) { args := params.OfferArgs{Args: []params.OfferArg{arg}} // Use any previously cached discharge macaroons. if ms, ok := c.getCachedMacaroon("watch offer status", arg.OfferUUID); ok { args.Args[0].Macaroons = ms } var results params.OfferStatusWatchResults apiCall := func() error { // Reset the results struct before each api call. results = params.OfferStatusWatchResults{} if err := c.facade.FacadeCall("WatchOfferStatus", args, &results); err != nil { return errors.Trace(err) } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } return nil } // Make the api call the first time. if err := apiCall(); err != nil { return nil, errors.Trace(err) } // On error, possibly discharge the macaroon and retry. result := results.Results[0] if result.Error != nil { mac, err := c.handleError(result.Error) if err != nil { result.Error.Message = err.Error() return nil, result.Error } args.Args[0].Macaroons = mac c.cache.Upsert(args.Args[0].OfferUUID, mac) if err := apiCall(); err != nil { return nil, errors.Trace(err) } result = results.Results[0] } if result.Error != nil { return nil, result.Error } w := apiwatcher.NewOfferStatusWatcher(c.facade.RawAPICaller(), result) return w, nil }
[ "func", "(", "c", "*", "Client", ")", "WatchOfferStatus", "(", "arg", "params", ".", "OfferArg", ")", "(", "watcher", ".", "OfferStatusWatcher", ",", "error", ")", "{", "args", ":=", "params", ".", "OfferArgs", "{", "Args", ":", "[", "]", "params", ".", "OfferArg", "{", "arg", "}", "}", "\n", "// Use any previously cached discharge macaroons.", "if", "ms", ",", "ok", ":=", "c", ".", "getCachedMacaroon", "(", "\"", "\"", ",", "arg", ".", "OfferUUID", ")", ";", "ok", "{", "args", ".", "Args", "[", "0", "]", ".", "Macaroons", "=", "ms", "\n", "}", "\n\n", "var", "results", "params", ".", "OfferStatusWatchResults", "\n", "apiCall", ":=", "func", "(", ")", "error", "{", "// Reset the results struct before each api call.", "results", "=", "params", ".", "OfferStatusWatchResults", "{", "}", "\n", "if", "err", ":=", "c", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "args", ",", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Make the api call the first time.", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// On error, possibly discharge the macaroon and retry.", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "mac", ",", "err", ":=", "c", ".", "handleError", "(", "result", ".", "Error", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Error", ".", "Message", "=", "err", ".", "Error", "(", ")", "\n", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "args", ".", "Args", "[", "0", "]", ".", "Macaroons", "=", "mac", "\n", "c", ".", "cache", ".", "Upsert", "(", "args", ".", "Args", "[", "0", "]", ".", "OfferUUID", ",", "mac", ")", "\n\n", "if", "err", ":=", "apiCall", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", "=", "results", ".", "Results", "[", "0", "]", "\n", "}", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n\n", "w", ":=", "apiwatcher", ".", "NewOfferStatusWatcher", "(", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ",", "result", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchOfferStatus starts an OfferStatusWatcher for watching the status // of the specified offer in the remote model.
[ "WatchOfferStatus", "starts", "an", "OfferStatusWatcher", "for", "watching", "the", "status", "of", "the", "specified", "offer", "in", "the", "remote", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/crossmodelrelations/crossmodelrelations.go#L460-L507
155,972
juju/juju
cmd/juju/crossmodel/remoteendpoints.go
NewRemoteEndpointsAPI
func (c *RemoteEndpointsCommandBase) NewRemoteEndpointsAPI(controllerName string) (*applicationoffers.Client, error) { root, err := c.CommandBase.NewAPIRoot(c.ClientStore(), controllerName, "") if err != nil { return nil, err } return applicationoffers.NewClient(root), nil }
go
func (c *RemoteEndpointsCommandBase) NewRemoteEndpointsAPI(controllerName string) (*applicationoffers.Client, error) { root, err := c.CommandBase.NewAPIRoot(c.ClientStore(), controllerName, "") if err != nil { return nil, err } return applicationoffers.NewClient(root), nil }
[ "func", "(", "c", "*", "RemoteEndpointsCommandBase", ")", "NewRemoteEndpointsAPI", "(", "controllerName", "string", ")", "(", "*", "applicationoffers", ".", "Client", ",", "error", ")", "{", "root", ",", "err", ":=", "c", ".", "CommandBase", ".", "NewAPIRoot", "(", "c", ".", "ClientStore", "(", ")", ",", "controllerName", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "applicationoffers", ".", "NewClient", "(", "root", ")", ",", "nil", "\n", "}" ]
// NewRemoteEndpointsAPI returns a remote endpoints api for the root api endpoint // that the command returns.
[ "NewRemoteEndpointsAPI", "returns", "a", "remote", "endpoints", "api", "for", "the", "root", "api", "endpoint", "that", "the", "command", "returns", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/crossmodel/remoteendpoints.go#L20-L26
155,973
juju/juju
cmd/juju/crossmodel/remoteendpoints.go
convertRemoteEndpoints
func convertRemoteEndpoints(apiEndpoints ...charm.Relation) map[string]RemoteEndpoint { if len(apiEndpoints) == 0 { return nil } output := make(map[string]RemoteEndpoint, len(apiEndpoints)) for _, one := range apiEndpoints { output[one.Name] = RemoteEndpoint{one.Name, one.Interface, string(one.Role)} } return output }
go
func convertRemoteEndpoints(apiEndpoints ...charm.Relation) map[string]RemoteEndpoint { if len(apiEndpoints) == 0 { return nil } output := make(map[string]RemoteEndpoint, len(apiEndpoints)) for _, one := range apiEndpoints { output[one.Name] = RemoteEndpoint{one.Name, one.Interface, string(one.Role)} } return output }
[ "func", "convertRemoteEndpoints", "(", "apiEndpoints", "...", "charm", ".", "Relation", ")", "map", "[", "string", "]", "RemoteEndpoint", "{", "if", "len", "(", "apiEndpoints", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "output", ":=", "make", "(", "map", "[", "string", "]", "RemoteEndpoint", ",", "len", "(", "apiEndpoints", ")", ")", "\n", "for", "_", ",", "one", ":=", "range", "apiEndpoints", "{", "output", "[", "one", ".", "Name", "]", "=", "RemoteEndpoint", "{", "one", ".", "Name", ",", "one", ".", "Interface", ",", "string", "(", "one", ".", "Role", ")", "}", "\n", "}", "\n", "return", "output", "\n", "}" ]
// convertRemoteEndpoints takes any number of api-formatted remote applications' endpoints and // creates a collection of ui-formatted endpoints.
[ "convertRemoteEndpoints", "takes", "any", "number", "of", "api", "-", "formatted", "remote", "applications", "endpoints", "and", "creates", "a", "collection", "of", "ui", "-", "formatted", "endpoints", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/crossmodel/remoteendpoints.go#L43-L52
155,974
juju/juju
provider/gce/environ_broker.go
finishInstanceConfig
func (env *environ) finishInstanceConfig(args environs.StartInstanceParams, spec *instances.InstanceSpec) error { envTools, err := args.Tools.Match(tools.Filter{Arch: spec.Image.Arch}) if err != nil { return errors.Errorf("chosen architecture %v not present in %v", spec.Image.Arch, arches) } if err := args.InstanceConfig.SetTools(envTools); err != nil { return errors.Trace(err) } return instancecfg.FinishInstanceConfig(args.InstanceConfig, env.Config()) }
go
func (env *environ) finishInstanceConfig(args environs.StartInstanceParams, spec *instances.InstanceSpec) error { envTools, err := args.Tools.Match(tools.Filter{Arch: spec.Image.Arch}) if err != nil { return errors.Errorf("chosen architecture %v not present in %v", spec.Image.Arch, arches) } if err := args.InstanceConfig.SetTools(envTools); err != nil { return errors.Trace(err) } return instancecfg.FinishInstanceConfig(args.InstanceConfig, env.Config()) }
[ "func", "(", "env", "*", "environ", ")", "finishInstanceConfig", "(", "args", "environs", ".", "StartInstanceParams", ",", "spec", "*", "instances", ".", "InstanceSpec", ")", "error", "{", "envTools", ",", "err", ":=", "args", ".", "Tools", ".", "Match", "(", "tools", ".", "Filter", "{", "Arch", ":", "spec", ".", "Image", ".", "Arch", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "spec", ".", "Image", ".", "Arch", ",", "arches", ")", "\n", "}", "\n\n", "if", "err", ":=", "args", ".", "InstanceConfig", ".", "SetTools", "(", "envTools", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "instancecfg", ".", "FinishInstanceConfig", "(", "args", ".", "InstanceConfig", ",", "env", ".", "Config", "(", ")", ")", "\n", "}" ]
// finishInstanceConfig updates args.InstanceConfig in place. Setting up // the API, StateServing, and SSHkeys information.
[ "finishInstanceConfig", "updates", "args", ".", "InstanceConfig", "in", "place", ".", "Setting", "up", "the", "API", "StateServing", "and", "SSHkeys", "information", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/environ_broker.go#L84-L94
155,975
juju/juju
provider/gce/environ_broker.go
buildInstanceSpec
func (env *environ) buildInstanceSpec(args environs.StartInstanceParams) (*instances.InstanceSpec, error) { arches := args.Tools.Arches() series := args.Tools.OneSeries() spec, err := findInstanceSpec( env, &instances.InstanceConstraint{ Region: env.cloud.Region, Series: series, Arches: arches, Constraints: args.Constraints, }, args.ImageMetadata, ) return spec, errors.Trace(err) }
go
func (env *environ) buildInstanceSpec(args environs.StartInstanceParams) (*instances.InstanceSpec, error) { arches := args.Tools.Arches() series := args.Tools.OneSeries() spec, err := findInstanceSpec( env, &instances.InstanceConstraint{ Region: env.cloud.Region, Series: series, Arches: arches, Constraints: args.Constraints, }, args.ImageMetadata, ) return spec, errors.Trace(err) }
[ "func", "(", "env", "*", "environ", ")", "buildInstanceSpec", "(", "args", "environs", ".", "StartInstanceParams", ")", "(", "*", "instances", ".", "InstanceSpec", ",", "error", ")", "{", "arches", ":=", "args", ".", "Tools", ".", "Arches", "(", ")", "\n", "series", ":=", "args", ".", "Tools", ".", "OneSeries", "(", ")", "\n", "spec", ",", "err", ":=", "findInstanceSpec", "(", "env", ",", "&", "instances", ".", "InstanceConstraint", "{", "Region", ":", "env", ".", "cloud", ".", "Region", ",", "Series", ":", "series", ",", "Arches", ":", "arches", ",", "Constraints", ":", "args", ".", "Constraints", ",", "}", ",", "args", ".", "ImageMetadata", ",", ")", "\n", "return", "spec", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// buildInstanceSpec builds an instance spec from the provided args // and returns it. This includes pulling the simplestreams data for the // machine type, region, and other constraints.
[ "buildInstanceSpec", "builds", "an", "instance", "spec", "from", "the", "provided", "args", "and", "returns", "it", ".", "This", "includes", "pulling", "the", "simplestreams", "data", "for", "the", "machine", "type", "region", "and", "other", "constraints", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/environ_broker.go#L99-L112
155,976
juju/juju
provider/gce/environ_broker.go
findInstanceSpec
func (env *environ) findInstanceSpec( ic *instances.InstanceConstraint, imageMetadata []*imagemetadata.ImageMetadata, ) (*instances.InstanceSpec, error) { images := instances.ImageMetadataToImages(imageMetadata) spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes) return spec, errors.Trace(err) }
go
func (env *environ) findInstanceSpec( ic *instances.InstanceConstraint, imageMetadata []*imagemetadata.ImageMetadata, ) (*instances.InstanceSpec, error) { images := instances.ImageMetadataToImages(imageMetadata) spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes) return spec, errors.Trace(err) }
[ "func", "(", "env", "*", "environ", ")", "findInstanceSpec", "(", "ic", "*", "instances", ".", "InstanceConstraint", ",", "imageMetadata", "[", "]", "*", "imagemetadata", ".", "ImageMetadata", ",", ")", "(", "*", "instances", ".", "InstanceSpec", ",", "error", ")", "{", "images", ":=", "instances", ".", "ImageMetadataToImages", "(", "imageMetadata", ")", "\n", "spec", ",", "err", ":=", "instances", ".", "FindInstanceSpec", "(", "images", ",", "ic", ",", "allInstanceTypes", ")", "\n", "return", "spec", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// findInstanceSpec initializes a new instance spec for the given // constraints and returns it. This only covers populating the // initial data for the spec.
[ "findInstanceSpec", "initializes", "a", "new", "instance", "spec", "for", "the", "given", "constraints", "and", "returns", "it", ".", "This", "only", "covers", "populating", "the", "initial", "data", "for", "the", "spec", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/environ_broker.go#L125-L132
155,977
juju/juju
provider/gce/environ_broker.go
getDisks
func getDisks(spec *instances.InstanceSpec, cons constraints.Value, ser, eUUID string, imageURLBase string) ([]google.DiskSpec, error) { size := common.MinRootDiskSizeGiB(ser) if cons.RootDisk != nil && *cons.RootDisk > size { size = common.MiBToGiB(*cons.RootDisk) } if imageURLBase == "" { return nil, errors.NotValidf("imageURLBase must be set") } imageURL := imageURLBase + spec.Image.Id logger.Infof("fetching disk image from %v", imageURL) dSpec := google.DiskSpec{ Series: ser, SizeHintGB: size, ImageURL: imageURL, Boot: true, AutoDelete: true, } if cons.RootDisk != nil && dSpec.TooSmall() { msg := "Ignoring root-disk constraint of %dM because it is smaller than the GCE image size of %dG" logger.Infof(msg, *cons.RootDisk, google.MinDiskSizeGB(ser)) } return []google.DiskSpec{dSpec}, nil }
go
func getDisks(spec *instances.InstanceSpec, cons constraints.Value, ser, eUUID string, imageURLBase string) ([]google.DiskSpec, error) { size := common.MinRootDiskSizeGiB(ser) if cons.RootDisk != nil && *cons.RootDisk > size { size = common.MiBToGiB(*cons.RootDisk) } if imageURLBase == "" { return nil, errors.NotValidf("imageURLBase must be set") } imageURL := imageURLBase + spec.Image.Id logger.Infof("fetching disk image from %v", imageURL) dSpec := google.DiskSpec{ Series: ser, SizeHintGB: size, ImageURL: imageURL, Boot: true, AutoDelete: true, } if cons.RootDisk != nil && dSpec.TooSmall() { msg := "Ignoring root-disk constraint of %dM because it is smaller than the GCE image size of %dG" logger.Infof(msg, *cons.RootDisk, google.MinDiskSizeGB(ser)) } return []google.DiskSpec{dSpec}, nil }
[ "func", "getDisks", "(", "spec", "*", "instances", ".", "InstanceSpec", ",", "cons", "constraints", ".", "Value", ",", "ser", ",", "eUUID", "string", ",", "imageURLBase", "string", ")", "(", "[", "]", "google", ".", "DiskSpec", ",", "error", ")", "{", "size", ":=", "common", ".", "MinRootDiskSizeGiB", "(", "ser", ")", "\n", "if", "cons", ".", "RootDisk", "!=", "nil", "&&", "*", "cons", ".", "RootDisk", ">", "size", "{", "size", "=", "common", ".", "MiBToGiB", "(", "*", "cons", ".", "RootDisk", ")", "\n", "}", "\n", "if", "imageURLBase", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "imageURL", ":=", "imageURLBase", "+", "spec", ".", "Image", ".", "Id", "\n", "logger", ".", "Infof", "(", "\"", "\"", ",", "imageURL", ")", "\n", "dSpec", ":=", "google", ".", "DiskSpec", "{", "Series", ":", "ser", ",", "SizeHintGB", ":", "size", ",", "ImageURL", ":", "imageURL", ",", "Boot", ":", "true", ",", "AutoDelete", ":", "true", ",", "}", "\n", "if", "cons", ".", "RootDisk", "!=", "nil", "&&", "dSpec", ".", "TooSmall", "(", ")", "{", "msg", ":=", "\"", "\"", "\n", "logger", ".", "Infof", "(", "msg", ",", "*", "cons", ".", "RootDisk", ",", "google", ".", "MinDiskSizeGB", "(", "ser", ")", ")", "\n", "}", "\n", "return", "[", "]", "google", ".", "DiskSpec", "{", "dSpec", "}", ",", "nil", "\n", "}" ]
// getDisks builds the raw spec for the disks that should be attached to // the new instances and returns it. This will always include a root // disk with characteristics determined by the provides args and // constraints.
[ "getDisks", "builds", "the", "raw", "spec", "for", "the", "disks", "that", "should", "be", "attached", "to", "the", "new", "instances", "and", "returns", "it", ".", "This", "will", "always", "include", "a", "root", "disk", "with", "characteristics", "determined", "by", "the", "provides", "args", "and", "constraints", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/environ_broker.go#L261-L283
155,978
juju/juju
apiserver/facades/client/backups/remove.go
Remove
func (a *APIv2) Remove(args params.BackupsRemoveArgs) (params.ErrorResults, error) { backups, closer := newBackups(a.backend) defer closer.Close() results := make([]params.ErrorResult, len(args.IDs)) for i, id := range args.IDs { err := backups.Remove(id) results[i].Error = common.ServerError(err) } return params.ErrorResults{results}, nil }
go
func (a *APIv2) Remove(args params.BackupsRemoveArgs) (params.ErrorResults, error) { backups, closer := newBackups(a.backend) defer closer.Close() results := make([]params.ErrorResult, len(args.IDs)) for i, id := range args.IDs { err := backups.Remove(id) results[i].Error = common.ServerError(err) } return params.ErrorResults{results}, nil }
[ "func", "(", "a", "*", "APIv2", ")", "Remove", "(", "args", "params", ".", "BackupsRemoveArgs", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "backups", ",", "closer", ":=", "newBackups", "(", "a", ".", "backend", ")", "\n", "defer", "closer", ".", "Close", "(", ")", "\n", "results", ":=", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "IDs", ")", ")", "\n", "for", "i", ",", "id", ":=", "range", "args", ".", "IDs", "{", "err", ":=", "backups", ".", "Remove", "(", "id", ")", "\n", "results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "return", "params", ".", "ErrorResults", "{", "results", "}", ",", "nil", "\n", "}" ]
// Remove deletes the backups defined by ID from the database.
[ "Remove", "deletes", "the", "backups", "defined", "by", "ID", "from", "the", "database", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/remove.go#L12-L21
155,979
juju/juju
worker/lifeflag/worker.go
New
func New(config Config) (*Worker, error) { if err := config.Validate(); err != nil { return nil, errors.Trace(err) } // Read it before the worker starts, so that we have a value // guaranteed before we return the worker. Because we read this // before we start the internal watcher, we'll need an additional // read triggered by the first change event; this will *probably* // be the same value, but we can't assume it. life, err := config.Facade.Life(config.Entity) if err != nil { return nil, filter(errors.Trace(err)) } w := &Worker{ config: config, life: life, } err = catacomb.Invoke(catacomb.Plan{ Site: &w.catacomb, Work: w.loop, }) if err != nil { return nil, errors.Trace(err) } return w, nil }
go
func New(config Config) (*Worker, error) { if err := config.Validate(); err != nil { return nil, errors.Trace(err) } // Read it before the worker starts, so that we have a value // guaranteed before we return the worker. Because we read this // before we start the internal watcher, we'll need an additional // read triggered by the first change event; this will *probably* // be the same value, but we can't assume it. life, err := config.Facade.Life(config.Entity) if err != nil { return nil, filter(errors.Trace(err)) } w := &Worker{ config: config, life: life, } err = catacomb.Invoke(catacomb.Plan{ Site: &w.catacomb, Work: w.loop, }) if err != nil { return nil, errors.Trace(err) } return w, nil }
[ "func", "New", "(", "config", "Config", ")", "(", "*", "Worker", ",", "error", ")", "{", "if", "err", ":=", "config", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Read it before the worker starts, so that we have a value", "// guaranteed before we return the worker. Because we read this", "// before we start the internal watcher, we'll need an additional", "// read triggered by the first change event; this will *probably*", "// be the same value, but we can't assume it.", "life", ",", "err", ":=", "config", ".", "Facade", ".", "Life", "(", "config", ".", "Entity", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "filter", "(", "errors", ".", "Trace", "(", "err", ")", ")", "\n", "}", "\n\n", "w", ":=", "&", "Worker", "{", "config", ":", "config", ",", "life", ":", "life", ",", "}", "\n", "err", "=", "catacomb", ".", "Invoke", "(", "catacomb", ".", "Plan", "{", "Site", ":", "&", "w", ".", "catacomb", ",", "Work", ":", "w", ".", "loop", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "w", ",", "nil", "\n", "}" ]
// New returns a worker that exposes the result of the configured // predicate when applied to the configured entity's life value, // and fails with ErrValueChanged when the result changes.
[ "New", "returns", "a", "worker", "that", "exposes", "the", "result", "of", "the", "configured", "predicate", "when", "applied", "to", "the", "configured", "entity", "s", "life", "value", "and", "fails", "with", "ErrValueChanged", "when", "the", "result", "changes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/lifeflag/worker.go#L69-L96
155,980
juju/juju
state/stateenvirons/policy.go
GetNewPolicyFunc
func GetNewPolicyFunc() state.NewPolicyFunc { return func(st *state.State) state.Policy { return environStatePolicy{st, GetNewEnvironFunc(environs.New), GetNewCAASBrokerFunc(caas.New)} } }
go
func GetNewPolicyFunc() state.NewPolicyFunc { return func(st *state.State) state.Policy { return environStatePolicy{st, GetNewEnvironFunc(environs.New), GetNewCAASBrokerFunc(caas.New)} } }
[ "func", "GetNewPolicyFunc", "(", ")", "state", ".", "NewPolicyFunc", "{", "return", "func", "(", "st", "*", "state", ".", "State", ")", "state", ".", "Policy", "{", "return", "environStatePolicy", "{", "st", ",", "GetNewEnvironFunc", "(", "environs", ".", "New", ")", ",", "GetNewCAASBrokerFunc", "(", "caas", ".", "New", ")", "}", "\n", "}", "\n", "}" ]
// GetNewPolicyFunc returns a state.NewPolicyFunc that will return // a state.Policy implemented in terms of either environs.Environ // or caas.Broker and related types.
[ "GetNewPolicyFunc", "returns", "a", "state", ".", "NewPolicyFunc", "that", "will", "return", "a", "state", ".", "Policy", "implemented", "in", "terms", "of", "either", "environs", ".", "Environ", "or", "caas", ".", "Broker", "and", "related", "types", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L30-L34
155,981
juju/juju
state/stateenvirons/policy.go
Prechecker
func (p environStatePolicy) Prechecker() (environs.InstancePrechecker, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } if model.Type() == state.ModelTypeIAAS { return p.getEnviron(p.st) } return p.getBroker(p.st) }
go
func (p environStatePolicy) Prechecker() (environs.InstancePrechecker, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } if model.Type() == state.ModelTypeIAAS { return p.getEnviron(p.st) } return p.getBroker(p.st) }
[ "func", "(", "p", "environStatePolicy", ")", "Prechecker", "(", ")", "(", "environs", ".", "InstancePrechecker", ",", "error", ")", "{", "model", ",", "err", ":=", "p", ".", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "model", ".", "Type", "(", ")", "==", "state", ".", "ModelTypeIAAS", "{", "return", "p", ".", "getEnviron", "(", "p", ".", "st", ")", "\n", "}", "\n", "return", "p", ".", "getBroker", "(", "p", ".", "st", ")", "\n", "}" ]
// Prechecker implements state.Policy.
[ "Prechecker", "implements", "state", ".", "Policy", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L37-L46
155,982
juju/juju
state/stateenvirons/policy.go
ConfigValidator
func (p environStatePolicy) ConfigValidator() (config.Validator, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } cloud, err := p.st.Cloud(model.Cloud()) if err != nil { return nil, errors.Annotate(err, "getting cloud") } return environProvider(cloud.Type) }
go
func (p environStatePolicy) ConfigValidator() (config.Validator, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } cloud, err := p.st.Cloud(model.Cloud()) if err != nil { return nil, errors.Annotate(err, "getting cloud") } return environProvider(cloud.Type) }
[ "func", "(", "p", "environStatePolicy", ")", "ConfigValidator", "(", ")", "(", "config", ".", "Validator", ",", "error", ")", "{", "model", ",", "err", ":=", "p", ".", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "cloud", ",", "err", ":=", "p", ".", "st", ".", "Cloud", "(", "model", ".", "Cloud", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "environProvider", "(", "cloud", ".", "Type", ")", "\n", "}" ]
// ConfigValidator implements state.Policy.
[ "ConfigValidator", "implements", "state", ".", "Policy", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L49-L59
155,983
juju/juju
state/stateenvirons/policy.go
ProviderConfigSchemaSource
func (p environStatePolicy) ProviderConfigSchemaSource(cloudName string) (config.ConfigSchemaSource, error) { cloud, err := p.st.Cloud(cloudName) if err != nil { return nil, errors.Trace(err) } provider, err := environProvider(cloud.Type) if err != nil { return nil, errors.Trace(err) } if cs, ok := provider.(config.ConfigSchemaSource); ok { return cs, nil } return nil, errors.NotImplementedf("config.ConfigSource") }
go
func (p environStatePolicy) ProviderConfigSchemaSource(cloudName string) (config.ConfigSchemaSource, error) { cloud, err := p.st.Cloud(cloudName) if err != nil { return nil, errors.Trace(err) } provider, err := environProvider(cloud.Type) if err != nil { return nil, errors.Trace(err) } if cs, ok := provider.(config.ConfigSchemaSource); ok { return cs, nil } return nil, errors.NotImplementedf("config.ConfigSource") }
[ "func", "(", "p", "environStatePolicy", ")", "ProviderConfigSchemaSource", "(", "cloudName", "string", ")", "(", "config", ".", "ConfigSchemaSource", ",", "error", ")", "{", "cloud", ",", "err", ":=", "p", ".", "st", ".", "Cloud", "(", "cloudName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "provider", ",", "err", ":=", "environProvider", "(", "cloud", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "cs", ",", "ok", ":=", "provider", ".", "(", "config", ".", "ConfigSchemaSource", ")", ";", "ok", "{", "return", "cs", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "NotImplementedf", "(", "\"", "\"", ")", "\n", "}" ]
// ProviderConfigSchemaSource implements state.Policy.
[ "ProviderConfigSchemaSource", "implements", "state", ".", "Policy", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L62-L75
155,984
juju/juju
state/stateenvirons/policy.go
ConstraintsValidator
func (p environStatePolicy) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } if model.Type() == state.ModelTypeIAAS { env, err := p.getEnviron(p.st) if err != nil { return nil, err } return env.ConstraintsValidator(ctx) } broker, err := p.getBroker(p.st) if err != nil { return nil, errors.Trace(err) } return broker.ConstraintsValidator(ctx) }
go
func (p environStatePolicy) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } if model.Type() == state.ModelTypeIAAS { env, err := p.getEnviron(p.st) if err != nil { return nil, err } return env.ConstraintsValidator(ctx) } broker, err := p.getBroker(p.st) if err != nil { return nil, errors.Trace(err) } return broker.ConstraintsValidator(ctx) }
[ "func", "(", "p", "environStatePolicy", ")", "ConstraintsValidator", "(", "ctx", "context", ".", "ProviderCallContext", ")", "(", "constraints", ".", "Validator", ",", "error", ")", "{", "model", ",", "err", ":=", "p", ".", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "if", "model", ".", "Type", "(", ")", "==", "state", ".", "ModelTypeIAAS", "{", "env", ",", "err", ":=", "p", ".", "getEnviron", "(", "p", ".", "st", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "env", ".", "ConstraintsValidator", "(", "ctx", ")", "\n", "}", "\n", "broker", ",", "err", ":=", "p", ".", "getBroker", "(", "p", ".", "st", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "broker", ".", "ConstraintsValidator", "(", "ctx", ")", "\n", "}" ]
// ConstraintsValidator implements state.Policy.
[ "ConstraintsValidator", "implements", "state", ".", "Policy", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L78-L96
155,985
juju/juju
state/stateenvirons/policy.go
InstanceDistributor
func (p environStatePolicy) InstanceDistributor() (context.Distributor, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } if model.Type() != state.ModelTypeIAAS { // Only IAAS models support machines, hence distribution. return nil, errors.NotImplementedf("InstanceDistributor") } env, err := p.getEnviron(p.st) if err != nil { return nil, err } if p, ok := env.(context.Distributor); ok { return p, nil } return nil, errors.NotImplementedf("InstanceDistributor") }
go
func (p environStatePolicy) InstanceDistributor() (context.Distributor, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } if model.Type() != state.ModelTypeIAAS { // Only IAAS models support machines, hence distribution. return nil, errors.NotImplementedf("InstanceDistributor") } env, err := p.getEnviron(p.st) if err != nil { return nil, err } if p, ok := env.(context.Distributor); ok { return p, nil } return nil, errors.NotImplementedf("InstanceDistributor") }
[ "func", "(", "p", "environStatePolicy", ")", "InstanceDistributor", "(", ")", "(", "context", ".", "Distributor", ",", "error", ")", "{", "model", ",", "err", ":=", "p", ".", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "model", ".", "Type", "(", ")", "!=", "state", ".", "ModelTypeIAAS", "{", "// Only IAAS models support machines, hence distribution.", "return", "nil", ",", "errors", ".", "NotImplementedf", "(", "\"", "\"", ")", "\n", "}", "\n", "env", ",", "err", ":=", "p", ".", "getEnviron", "(", "p", ".", "st", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "p", ",", "ok", ":=", "env", ".", "(", "context", ".", "Distributor", ")", ";", "ok", "{", "return", "p", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "NotImplementedf", "(", "\"", "\"", ")", "\n", "}" ]
// InstanceDistributor implements state.Policy.
[ "InstanceDistributor", "implements", "state", ".", "Policy", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L99-L116
155,986
juju/juju
state/stateenvirons/policy.go
StorageProviderRegistry
func (p environStatePolicy) StorageProviderRegistry() (storage.ProviderRegistry, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } return NewStorageProviderRegistryForModel(model, p.getEnviron, p.getBroker) }
go
func (p environStatePolicy) StorageProviderRegistry() (storage.ProviderRegistry, error) { model, err := p.st.Model() if err != nil { return nil, errors.Trace(err) } return NewStorageProviderRegistryForModel(model, p.getEnviron, p.getBroker) }
[ "func", "(", "p", "environStatePolicy", ")", "StorageProviderRegistry", "(", ")", "(", "storage", ".", "ProviderRegistry", ",", "error", ")", "{", "model", ",", "err", ":=", "p", ".", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "NewStorageProviderRegistryForModel", "(", "model", ",", "p", ".", "getEnviron", ",", "p", ".", "getBroker", ")", "\n", "}" ]
// StorageProviderRegistry implements state.Policy.
[ "StorageProviderRegistry", "implements", "state", ".", "Policy", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L119-L125
155,987
juju/juju
state/stateenvirons/policy.go
NewStorageProviderRegistryForModel
func NewStorageProviderRegistryForModel( model *state.Model, newEnv NewEnvironFunc, newBroker NewCAASBrokerFunc, ) (_ storage.ProviderRegistry, err error) { var reg storage.ProviderRegistry if model.Type() == state.ModelTypeIAAS { if reg, err = newEnv(model.State()); err != nil { return nil, errors.Trace(err) } } else { if reg, err = newBroker(model.State()); err != nil { return nil, errors.Trace(err) } } return NewStorageProviderRegistry(reg), nil }
go
func NewStorageProviderRegistryForModel( model *state.Model, newEnv NewEnvironFunc, newBroker NewCAASBrokerFunc, ) (_ storage.ProviderRegistry, err error) { var reg storage.ProviderRegistry if model.Type() == state.ModelTypeIAAS { if reg, err = newEnv(model.State()); err != nil { return nil, errors.Trace(err) } } else { if reg, err = newBroker(model.State()); err != nil { return nil, errors.Trace(err) } } return NewStorageProviderRegistry(reg), nil }
[ "func", "NewStorageProviderRegistryForModel", "(", "model", "*", "state", ".", "Model", ",", "newEnv", "NewEnvironFunc", ",", "newBroker", "NewCAASBrokerFunc", ",", ")", "(", "_", "storage", ".", "ProviderRegistry", ",", "err", "error", ")", "{", "var", "reg", "storage", ".", "ProviderRegistry", "\n", "if", "model", ".", "Type", "(", ")", "==", "state", ".", "ModelTypeIAAS", "{", "if", "reg", ",", "err", "=", "newEnv", "(", "model", ".", "State", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "else", "{", "if", "reg", ",", "err", "=", "newBroker", "(", "model", ".", "State", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "NewStorageProviderRegistry", "(", "reg", ")", ",", "nil", "\n", "}" ]
// NewStorageProviderRegistryForModel returns a storage provider registry // for the specified model.
[ "NewStorageProviderRegistryForModel", "returns", "a", "storage", "provider", "registry", "for", "the", "specified", "model", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L129-L145
155,988
juju/juju
state/stateenvirons/policy.go
NewStorageProviderRegistry
func NewStorageProviderRegistry(reg storage.ProviderRegistry) storage.ProviderRegistry { return storage.ChainedProviderRegistry{reg, provider.CommonStorageProviders()} }
go
func NewStorageProviderRegistry(reg storage.ProviderRegistry) storage.ProviderRegistry { return storage.ChainedProviderRegistry{reg, provider.CommonStorageProviders()} }
[ "func", "NewStorageProviderRegistry", "(", "reg", "storage", ".", "ProviderRegistry", ")", "storage", ".", "ProviderRegistry", "{", "return", "storage", ".", "ChainedProviderRegistry", "{", "reg", ",", "provider", ".", "CommonStorageProviders", "(", ")", "}", "\n", "}" ]
// NewStorageProviderRegistry returns a storage.ProviderRegistry that chains // the provided registry with the common storage providers.
[ "NewStorageProviderRegistry", "returns", "a", "storage", ".", "ProviderRegistry", "that", "chains", "the", "provided", "registry", "with", "the", "common", "storage", "providers", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/stateenvirons/policy.go#L149-L151
155,989
juju/juju
environs/bootstrap/config.go
IsBootstrapAttribute
func IsBootstrapAttribute(attr string) bool { for _, a := range BootstrapConfigAttributes { if attr == a { return true } } return false }
go
func IsBootstrapAttribute(attr string) bool { for _, a := range BootstrapConfigAttributes { if attr == a { return true } } return false }
[ "func", "IsBootstrapAttribute", "(", "attr", "string", ")", "bool", "{", "for", "_", ",", "a", ":=", "range", "BootstrapConfigAttributes", "{", "if", "attr", "==", "a", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsBootstrapAttribute reports whether or not the specified // attribute name is only relevant during bootstrap.
[ "IsBootstrapAttribute", "reports", "whether", "or", "not", "the", "specified", "attribute", "name", "is", "only", "relevant", "during", "bootstrap", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/bootstrap/config.go#L78-L85
155,990
juju/juju
environs/bootstrap/config.go
Validate
func (c Config) Validate() error { if c.AdminSecret == "" { return errors.NotValidf("empty " + AdminSecretKey) } if _, err := tls.X509KeyPair([]byte(c.CACert), []byte(c.CAPrivateKey)); err != nil { return errors.Annotatef(err, "validating %s and %s", CACertKey, CAPrivateKeyKey) } if c.BootstrapTimeout <= 0 { return errors.NotValidf("%s of %s", BootstrapTimeoutKey, c.BootstrapTimeout) } if c.BootstrapRetryDelay <= 0 { return errors.NotValidf("%s of %s", BootstrapRetryDelayKey, c.BootstrapRetryDelay) } if c.BootstrapAddressesDelay <= 0 { return errors.NotValidf("%s of %s", BootstrapAddressesDelayKey, c.BootstrapAddressesDelay) } return nil }
go
func (c Config) Validate() error { if c.AdminSecret == "" { return errors.NotValidf("empty " + AdminSecretKey) } if _, err := tls.X509KeyPair([]byte(c.CACert), []byte(c.CAPrivateKey)); err != nil { return errors.Annotatef(err, "validating %s and %s", CACertKey, CAPrivateKeyKey) } if c.BootstrapTimeout <= 0 { return errors.NotValidf("%s of %s", BootstrapTimeoutKey, c.BootstrapTimeout) } if c.BootstrapRetryDelay <= 0 { return errors.NotValidf("%s of %s", BootstrapRetryDelayKey, c.BootstrapRetryDelay) } if c.BootstrapAddressesDelay <= 0 { return errors.NotValidf("%s of %s", BootstrapAddressesDelayKey, c.BootstrapAddressesDelay) } return nil }
[ "func", "(", "c", "Config", ")", "Validate", "(", ")", "error", "{", "if", "c", ".", "AdminSecret", "==", "\"", "\"", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", "+", "AdminSecretKey", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "tls", ".", "X509KeyPair", "(", "[", "]", "byte", "(", "c", ".", "CACert", ")", ",", "[", "]", "byte", "(", "c", ".", "CAPrivateKey", ")", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "CACertKey", ",", "CAPrivateKeyKey", ")", "\n", "}", "\n", "if", "c", ".", "BootstrapTimeout", "<=", "0", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "BootstrapTimeoutKey", ",", "c", ".", "BootstrapTimeout", ")", "\n", "}", "\n", "if", "c", ".", "BootstrapRetryDelay", "<=", "0", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "BootstrapRetryDelayKey", ",", "c", ".", "BootstrapRetryDelay", ")", "\n", "}", "\n", "if", "c", ".", "BootstrapAddressesDelay", "<=", "0", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "BootstrapAddressesDelayKey", ",", "c", ".", "BootstrapAddressesDelay", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates the controller configuration.
[ "Validate", "validates", "the", "controller", "configuration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/bootstrap/config.go#L98-L115
155,991
juju/juju
environs/bootstrap/config.go
readFileAttr
func readFileAttr(attrs map[string]interface{}, key, defaultPath string) (content string, userSpecified bool, _ error) { path, ok := attrs[key+"-path"].(string) if ok { userSpecified = true } else { path = defaultPath } absPath, err := utils.NormalizePath(path) if err != nil { return "", userSpecified, errors.Trace(err) } if !filepath.IsAbs(absPath) { absPath = osenv.JujuXDGDataHomePath(absPath) } data, err := ioutil.ReadFile(absPath) if err != nil { return "", userSpecified, errors.Annotatef(err, "%q not set, and could not read from %q", key, path) } if len(data) == 0 { return "", userSpecified, errors.Errorf("file %q is empty", path) } return string(data), userSpecified, nil }
go
func readFileAttr(attrs map[string]interface{}, key, defaultPath string) (content string, userSpecified bool, _ error) { path, ok := attrs[key+"-path"].(string) if ok { userSpecified = true } else { path = defaultPath } absPath, err := utils.NormalizePath(path) if err != nil { return "", userSpecified, errors.Trace(err) } if !filepath.IsAbs(absPath) { absPath = osenv.JujuXDGDataHomePath(absPath) } data, err := ioutil.ReadFile(absPath) if err != nil { return "", userSpecified, errors.Annotatef(err, "%q not set, and could not read from %q", key, path) } if len(data) == 0 { return "", userSpecified, errors.Errorf("file %q is empty", path) } return string(data), userSpecified, nil }
[ "func", "readFileAttr", "(", "attrs", "map", "[", "string", "]", "interface", "{", "}", ",", "key", ",", "defaultPath", "string", ")", "(", "content", "string", ",", "userSpecified", "bool", ",", "_", "error", ")", "{", "path", ",", "ok", ":=", "attrs", "[", "key", "+", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "ok", "{", "userSpecified", "=", "true", "\n", "}", "else", "{", "path", "=", "defaultPath", "\n", "}", "\n", "absPath", ",", "err", ":=", "utils", ".", "NormalizePath", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "userSpecified", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "!", "filepath", ".", "IsAbs", "(", "absPath", ")", "{", "absPath", "=", "osenv", ".", "JujuXDGDataHomePath", "(", "absPath", ")", "\n", "}", "\n", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "absPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "userSpecified", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "key", ",", "path", ")", "\n", "}", "\n", "if", "len", "(", "data", ")", "==", "0", "{", "return", "\"", "\"", ",", "userSpecified", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "return", "string", "(", "data", ")", ",", "userSpecified", ",", "nil", "\n", "}" ]
// readFileAttr reads the contents of an attribute from a file, if the // corresponding "-path" attribute is set, or otherwise from a default // path.
[ "readFileAttr", "reads", "the", "contents", "of", "an", "attribute", "from", "a", "file", "if", "the", "corresponding", "-", "path", "attribute", "is", "set", "or", "otherwise", "from", "a", "default", "path", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/bootstrap/config.go#L192-L214
155,992
juju/juju
storage/looputil/loop.go
NewLoopDeviceManager
func NewLoopDeviceManager() LoopDeviceManager { run := func(cmd string, args ...string) (string, error) { out, err := exec.Command(cmd, args...).CombinedOutput() out = bytes.TrimSpace(out) if err != nil { if len(out) > 0 { err = errors.Annotatef(err, "failed with %q", out) } return "", err } return string(out), nil } return &loopDeviceManager{run, os.Stat, fileInode} }
go
func NewLoopDeviceManager() LoopDeviceManager { run := func(cmd string, args ...string) (string, error) { out, err := exec.Command(cmd, args...).CombinedOutput() out = bytes.TrimSpace(out) if err != nil { if len(out) > 0 { err = errors.Annotatef(err, "failed with %q", out) } return "", err } return string(out), nil } return &loopDeviceManager{run, os.Stat, fileInode} }
[ "func", "NewLoopDeviceManager", "(", ")", "LoopDeviceManager", "{", "run", ":=", "func", "(", "cmd", "string", ",", "args", "...", "string", ")", "(", "string", ",", "error", ")", "{", "out", ",", "err", ":=", "exec", ".", "Command", "(", "cmd", ",", "args", "...", ")", ".", "CombinedOutput", "(", ")", "\n", "out", "=", "bytes", ".", "TrimSpace", "(", "out", ")", "\n", "if", "err", "!=", "nil", "{", "if", "len", "(", "out", ")", ">", "0", "{", "err", "=", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "out", ")", "\n", "}", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "string", "(", "out", ")", ",", "nil", "\n", "}", "\n", "return", "&", "loopDeviceManager", "{", "run", ",", "os", ".", "Stat", ",", "fileInode", "}", "\n", "}" ]
// NewLoopDeviceManager returns a new LoopDeviceManager for dealing // with storage loop devices on the local machine.
[ "NewLoopDeviceManager", "returns", "a", "new", "LoopDeviceManager", "for", "dealing", "with", "storage", "loop", "devices", "on", "the", "local", "machine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/looputil/loop.go#L38-L51
155,993
juju/juju
storage/looputil/loop.go
DetachLoopDevices
func (m *loopDeviceManager) DetachLoopDevices(rootfs, prefix string) error { logger.Debugf("detaching loop devices inside %q", rootfs) loopDevices, err := loopDevices(m.run) if err != nil { return errors.Annotate(err, "listing loop devices") } for _, info := range loopDevices { logger.Debugf("checking loop device: %v", info) if !strings.HasPrefix(info.backingFile, prefix) { continue } if info.backingInode == 0 { continue } rootedBackingFile := path.Join(rootfs, info.backingFile) st, err := m.stat(rootedBackingFile) if os.IsNotExist(err) { continue } else if err != nil { return errors.Annotate(err, "querying backing file") } if m.inode(st) != info.backingInode { continue } logger.Debugf("detaching loop device %q", info.name) if err := detachLoopDevice(m.run, info.name); err != nil { return errors.Trace(err) } } return nil }
go
func (m *loopDeviceManager) DetachLoopDevices(rootfs, prefix string) error { logger.Debugf("detaching loop devices inside %q", rootfs) loopDevices, err := loopDevices(m.run) if err != nil { return errors.Annotate(err, "listing loop devices") } for _, info := range loopDevices { logger.Debugf("checking loop device: %v", info) if !strings.HasPrefix(info.backingFile, prefix) { continue } if info.backingInode == 0 { continue } rootedBackingFile := path.Join(rootfs, info.backingFile) st, err := m.stat(rootedBackingFile) if os.IsNotExist(err) { continue } else if err != nil { return errors.Annotate(err, "querying backing file") } if m.inode(st) != info.backingInode { continue } logger.Debugf("detaching loop device %q", info.name) if err := detachLoopDevice(m.run, info.name); err != nil { return errors.Trace(err) } } return nil }
[ "func", "(", "m", "*", "loopDeviceManager", ")", "DetachLoopDevices", "(", "rootfs", ",", "prefix", "string", ")", "error", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "rootfs", ")", "\n", "loopDevices", ",", "err", ":=", "loopDevices", "(", "m", ".", "run", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "info", ":=", "range", "loopDevices", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "info", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "info", ".", "backingFile", ",", "prefix", ")", "{", "continue", "\n", "}", "\n", "if", "info", ".", "backingInode", "==", "0", "{", "continue", "\n", "}", "\n", "rootedBackingFile", ":=", "path", ".", "Join", "(", "rootfs", ",", "info", ".", "backingFile", ")", "\n", "st", ",", "err", ":=", "m", ".", "stat", "(", "rootedBackingFile", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "continue", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "m", ".", "inode", "(", "st", ")", "!=", "info", ".", "backingInode", "{", "continue", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "info", ".", "name", ")", "\n", "if", "err", ":=", "detachLoopDevice", "(", "m", ".", "run", ",", "info", ".", "name", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DetachLoopDevices detaches loop devices that are backed by files // inside the given root filesystem with the given prefix.
[ "DetachLoopDevices", "detaches", "loop", "devices", "that", "are", "backed", "by", "files", "inside", "the", "given", "root", "filesystem", "with", "the", "given", "prefix", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/looputil/loop.go#L55-L86
155,994
juju/juju
apiserver/logsink.go
dispose
func (d *dbloggers) dispose() { for _, l := range d.loggers { l.Close() } d.loggers = nil }
go
func (d *dbloggers) dispose() { for _, l := range d.loggers { l.Close() } d.loggers = nil }
[ "func", "(", "d", "*", "dbloggers", ")", "dispose", "(", ")", "{", "for", "_", ",", "l", ":=", "range", "d", ".", "loggers", "{", "l", ".", "Close", "(", ")", "\n", "}", "\n", "d", ".", "loggers", "=", "nil", "\n", "}" ]
// dispose closes all dbloggers in the map, and clears the memory. This // must not be called concurrently with any other dbloggers methods.
[ "dispose", "closes", "all", "dbloggers", "in", "the", "map", "and", "clears", "the", "memory", ".", "This", "must", "not", "be", "called", "concurrently", "with", "any", "other", "dbloggers", "methods", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink.go#L88-L93
155,995
juju/juju
apiserver/logsink.go
logToFile
func logToFile(writer io.Writer, prefix string, m params.LogRecord) error { _, err := writer.Write([]byte(strings.Join([]string{ prefix, m.Entity, m.Time.In(time.UTC).Format("2006-01-02 15:04:05"), m.Level, m.Module, m.Location, m.Message, }, " ") + "\n")) return err }
go
func logToFile(writer io.Writer, prefix string, m params.LogRecord) error { _, err := writer.Write([]byte(strings.Join([]string{ prefix, m.Entity, m.Time.In(time.UTC).Format("2006-01-02 15:04:05"), m.Level, m.Module, m.Location, m.Message, }, " ") + "\n")) return err }
[ "func", "logToFile", "(", "writer", "io", ".", "Writer", ",", "prefix", "string", ",", "m", "params", ".", "LogRecord", ")", "error", "{", "_", ",", "err", ":=", "writer", ".", "Write", "(", "[", "]", "byte", "(", "strings", ".", "Join", "(", "[", "]", "string", "{", "prefix", ",", "m", ".", "Entity", ",", "m", ".", "Time", ".", "In", "(", "time", ".", "UTC", ")", ".", "Format", "(", "\"", "\"", ")", ",", "m", ".", "Level", ",", "m", ".", "Module", ",", "m", ".", "Location", ",", "m", ".", "Message", ",", "}", ",", "\"", "\"", ")", "+", "\"", "\\n", "\"", ")", ")", "\n", "return", "err", "\n", "}" ]
// logToFile writes a single log message to the logsink log file.
[ "logToFile", "writes", "a", "single", "log", "message", "to", "the", "logsink", "log", "file", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logsink.go#L194-L205
155,996
juju/juju
state/initialize.go
Validate
func (p InitializeParams) Validate() error { if p.Clock == nil { return errors.NotValidf("missing clock") } if err := p.ControllerModelArgs.Validate(); err != nil { return errors.Trace(err) } if p.ControllerModelArgs.MigrationMode != MigrationModeNone { return errors.NotValidf("migration mode %q", p.ControllerModelArgs.MigrationMode) } uuid := p.ControllerModelArgs.Config.UUID() controllerUUID := p.ControllerConfig.ControllerUUID() if uuid == controllerUUID { return errors.NotValidf("same controller model uuid (%v) and controller-uuid (%v)", uuid, controllerUUID) } if p.MongoSession == nil { return errors.NotValidf("nil MongoSession") } if p.AdminPassword == "" { return errors.NotValidf("empty AdminPassword") } if err := validateCloud(p.Cloud); err != nil { return errors.Annotate(err, "validating cloud") } if _, err := validateCloudRegion(p.Cloud, p.ControllerModelArgs.CloudRegion); err != nil { return errors.Annotate(err, "validating controller model cloud region") } credentials := make(map[names.CloudCredentialTag]Credential, len(p.CloudCredentials)) for tag, cred := range p.CloudCredentials { credentials[tag] = convertCloudCredentialToState(tag, cred) } if _, err := validateCloudCredentials(p.Cloud, credentials); err != nil { return errors.Trace(err) } creds := make(map[string]Credential, len(credentials)) for tag, cred := range credentials { creds[tag.Id()] = cred } if _, err := validateCloudCredential( p.Cloud, creds, p.ControllerModelArgs.CloudCredential, ); err != nil { return errors.Annotate(err, "validating controller model cloud credential") } return nil }
go
func (p InitializeParams) Validate() error { if p.Clock == nil { return errors.NotValidf("missing clock") } if err := p.ControllerModelArgs.Validate(); err != nil { return errors.Trace(err) } if p.ControllerModelArgs.MigrationMode != MigrationModeNone { return errors.NotValidf("migration mode %q", p.ControllerModelArgs.MigrationMode) } uuid := p.ControllerModelArgs.Config.UUID() controllerUUID := p.ControllerConfig.ControllerUUID() if uuid == controllerUUID { return errors.NotValidf("same controller model uuid (%v) and controller-uuid (%v)", uuid, controllerUUID) } if p.MongoSession == nil { return errors.NotValidf("nil MongoSession") } if p.AdminPassword == "" { return errors.NotValidf("empty AdminPassword") } if err := validateCloud(p.Cloud); err != nil { return errors.Annotate(err, "validating cloud") } if _, err := validateCloudRegion(p.Cloud, p.ControllerModelArgs.CloudRegion); err != nil { return errors.Annotate(err, "validating controller model cloud region") } credentials := make(map[names.CloudCredentialTag]Credential, len(p.CloudCredentials)) for tag, cred := range p.CloudCredentials { credentials[tag] = convertCloudCredentialToState(tag, cred) } if _, err := validateCloudCredentials(p.Cloud, credentials); err != nil { return errors.Trace(err) } creds := make(map[string]Credential, len(credentials)) for tag, cred := range credentials { creds[tag.Id()] = cred } if _, err := validateCloudCredential( p.Cloud, creds, p.ControllerModelArgs.CloudCredential, ); err != nil { return errors.Annotate(err, "validating controller model cloud credential") } return nil }
[ "func", "(", "p", "InitializeParams", ")", "Validate", "(", ")", "error", "{", "if", "p", ".", "Clock", "==", "nil", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "p", ".", "ControllerModelArgs", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "p", ".", "ControllerModelArgs", ".", "MigrationMode", "!=", "MigrationModeNone", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "p", ".", "ControllerModelArgs", ".", "MigrationMode", ")", "\n", "}", "\n", "uuid", ":=", "p", ".", "ControllerModelArgs", ".", "Config", ".", "UUID", "(", ")", "\n", "controllerUUID", ":=", "p", ".", "ControllerConfig", ".", "ControllerUUID", "(", ")", "\n", "if", "uuid", "==", "controllerUUID", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "uuid", ",", "controllerUUID", ")", "\n", "}", "\n", "if", "p", ".", "MongoSession", "==", "nil", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "p", ".", "AdminPassword", "==", "\"", "\"", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "validateCloud", "(", "p", ".", "Cloud", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "validateCloudRegion", "(", "p", ".", "Cloud", ",", "p", ".", "ControllerModelArgs", ".", "CloudRegion", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "credentials", ":=", "make", "(", "map", "[", "names", ".", "CloudCredentialTag", "]", "Credential", ",", "len", "(", "p", ".", "CloudCredentials", ")", ")", "\n", "for", "tag", ",", "cred", ":=", "range", "p", ".", "CloudCredentials", "{", "credentials", "[", "tag", "]", "=", "convertCloudCredentialToState", "(", "tag", ",", "cred", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "validateCloudCredentials", "(", "p", ".", "Cloud", ",", "credentials", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "creds", ":=", "make", "(", "map", "[", "string", "]", "Credential", ",", "len", "(", "credentials", ")", ")", "\n", "for", "tag", ",", "cred", ":=", "range", "credentials", "{", "creds", "[", "tag", ".", "Id", "(", ")", "]", "=", "cred", "\n", "}", "\n", "if", "_", ",", "err", ":=", "validateCloudCredential", "(", "p", ".", "Cloud", ",", "creds", ",", "p", ".", "ControllerModelArgs", ".", "CloudCredential", ",", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate checks that the state initialization parameters are valid.
[ "Validate", "checks", "that", "the", "state", "initialization", "parameters", "are", "valid", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/initialize.go#L68-L115
155,997
juju/juju
state/initialize.go
InitDatabase
func InitDatabase(session *mgo.Session, modelUUID string, settings *controller.Config) error { schema := allCollections() if err := schema.Create(session.DB(jujuDB), settings); err != nil { return errors.Trace(err) } if err := InitDbLogs(session, modelUUID); err != nil { return errors.Trace(err) } return nil }
go
func InitDatabase(session *mgo.Session, modelUUID string, settings *controller.Config) error { schema := allCollections() if err := schema.Create(session.DB(jujuDB), settings); err != nil { return errors.Trace(err) } if err := InitDbLogs(session, modelUUID); err != nil { return errors.Trace(err) } return nil }
[ "func", "InitDatabase", "(", "session", "*", "mgo", ".", "Session", ",", "modelUUID", "string", ",", "settings", "*", "controller", ".", "Config", ")", "error", "{", "schema", ":=", "allCollections", "(", ")", "\n", "if", "err", ":=", "schema", ".", "Create", "(", "session", ".", "DB", "(", "jujuDB", ")", ",", "settings", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "InitDbLogs", "(", "session", ",", "modelUUID", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// InitDatabase creates all the collections and indices in a Juju database.
[ "InitDatabase", "creates", "all", "the", "collections", "and", "indices", "in", "a", "Juju", "database", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/initialize.go#L281-L290
155,998
juju/juju
cmd/service/service_handler_windows.go
Execute
func (s *SystemService) Execute(args []string, changeReq <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown changes <- svc.Status{State: svc.StartPending} errChannel := make(chan int, 1) go func() { err := s.Cmd(s.Args) errChannel <- err }() changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} for { select { case r := <-changeReq: switch r.Cmd { case svc.Interrogate: changes <- r.CurrentStatus case svc.Stop, svc.Shutdown: changes <- svc.Status{State: svc.StopPending} return false, 0 } case err := <-errChannel: return false, uint32(err) } } }
go
func (s *SystemService) Execute(args []string, changeReq <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown changes <- svc.Status{State: svc.StartPending} errChannel := make(chan int, 1) go func() { err := s.Cmd(s.Args) errChannel <- err }() changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} for { select { case r := <-changeReq: switch r.Cmd { case svc.Interrogate: changes <- r.CurrentStatus case svc.Stop, svc.Shutdown: changes <- svc.Status{State: svc.StopPending} return false, 0 } case err := <-errChannel: return false, uint32(err) } } }
[ "func", "(", "s", "*", "SystemService", ")", "Execute", "(", "args", "[", "]", "string", ",", "changeReq", "<-", "chan", "svc", ".", "ChangeRequest", ",", "changes", "chan", "<-", "svc", ".", "Status", ")", "(", "bool", ",", "uint32", ")", "{", "const", "cmdsAccepted", "=", "svc", ".", "AcceptStop", "|", "svc", ".", "AcceptShutdown", "\n", "changes", "<-", "svc", ".", "Status", "{", "State", ":", "svc", ".", "StartPending", "}", "\n\n", "errChannel", ":=", "make", "(", "chan", "int", ",", "1", ")", "\n\n", "go", "func", "(", ")", "{", "err", ":=", "s", ".", "Cmd", "(", "s", ".", "Args", ")", "\n", "errChannel", "<-", "err", "\n", "}", "(", ")", "\n\n", "changes", "<-", "svc", ".", "Status", "{", "State", ":", "svc", ".", "Running", ",", "Accepts", ":", "cmdsAccepted", "}", "\n\n", "for", "{", "select", "{", "case", "r", ":=", "<-", "changeReq", ":", "switch", "r", ".", "Cmd", "{", "case", "svc", ".", "Interrogate", ":", "changes", "<-", "r", ".", "CurrentStatus", "\n", "case", "svc", ".", "Stop", ",", "svc", ".", "Shutdown", ":", "changes", "<-", "svc", ".", "Status", "{", "State", ":", "svc", ".", "StopPending", "}", "\n", "return", "false", ",", "0", "\n", "}", "\n", "case", "err", ":=", "<-", "errChannel", ":", "return", "false", ",", "uint32", "(", "err", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Execute implements the svc.Handler interface
[ "Execute", "implements", "the", "svc", ".", "Handler", "interface" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/service/service_handler_windows.go#L25-L52
155,999
juju/juju
provider/gce/environ_instance.go
checkInstanceType
func checkInstanceType(cons constraints.Value) bool { // Constraint has an instance-type constraint so let's see if it is valid. for _, itype := range allInstanceTypes { if itype.Name == *cons.InstanceType { return true } } return false }
go
func checkInstanceType(cons constraints.Value) bool { // Constraint has an instance-type constraint so let's see if it is valid. for _, itype := range allInstanceTypes { if itype.Name == *cons.InstanceType { return true } } return false }
[ "func", "checkInstanceType", "(", "cons", "constraints", ".", "Value", ")", "bool", "{", "// Constraint has an instance-type constraint so let's see if it is valid.", "for", "_", ",", "itype", ":=", "range", "allInstanceTypes", "{", "if", "itype", ".", "Name", "==", "*", "cons", ".", "InstanceType", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// checkInstanceType is used to ensure the the provided constraints // specify a recognized instance type.
[ "checkInstanceType", "is", "used", "to", "ensure", "the", "the", "provided", "constraints", "specify", "a", "recognized", "instance", "type", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/environ_instance.go#L177-L185