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,400 | juju/juju | state/machine_linklayerdevices.go | addAddressToResult | func addAddressToResult(networkInfos []network.NetworkInfo, address *Address) ([]network.NetworkInfo, error) {
ifaceAddress := network.InterfaceAddress{
Address: address.Value(),
CIDR: address.SubnetCIDR(),
}
for i := range networkInfos {
networkInfo := &networkInfos[i]
if networkInfo.InterfaceName == address.DeviceName() {
networkInfo.Addresses = append(networkInfo.Addresses, ifaceAddress)
return networkInfos, nil
}
}
MAC := ""
device, err := address.Device()
if err == nil {
MAC = device.MACAddress()
} else if !errors.IsNotFound(err) {
return nil, err
}
networkInfo := network.NetworkInfo{
InterfaceName: address.DeviceName(),
MACAddress: MAC,
Addresses: []network.InterfaceAddress{ifaceAddress},
}
return append(networkInfos, networkInfo), nil
} | go | func addAddressToResult(networkInfos []network.NetworkInfo, address *Address) ([]network.NetworkInfo, error) {
ifaceAddress := network.InterfaceAddress{
Address: address.Value(),
CIDR: address.SubnetCIDR(),
}
for i := range networkInfos {
networkInfo := &networkInfos[i]
if networkInfo.InterfaceName == address.DeviceName() {
networkInfo.Addresses = append(networkInfo.Addresses, ifaceAddress)
return networkInfos, nil
}
}
MAC := ""
device, err := address.Device()
if err == nil {
MAC = device.MACAddress()
} else if !errors.IsNotFound(err) {
return nil, err
}
networkInfo := network.NetworkInfo{
InterfaceName: address.DeviceName(),
MACAddress: MAC,
Addresses: []network.InterfaceAddress{ifaceAddress},
}
return append(networkInfos, networkInfo), nil
} | [
"func",
"addAddressToResult",
"(",
"networkInfos",
"[",
"]",
"network",
".",
"NetworkInfo",
",",
"address",
"*",
"Address",
")",
"(",
"[",
"]",
"network",
".",
"NetworkInfo",
",",
"error",
")",
"{",
"ifaceAddress",
":=",
"network",
".",
"InterfaceAddress",
"{",
"Address",
":",
"address",
".",
"Value",
"(",
")",
",",
"CIDR",
":",
"address",
".",
"SubnetCIDR",
"(",
")",
",",
"}",
"\n",
"for",
"i",
":=",
"range",
"networkInfos",
"{",
"networkInfo",
":=",
"&",
"networkInfos",
"[",
"i",
"]",
"\n",
"if",
"networkInfo",
".",
"InterfaceName",
"==",
"address",
".",
"DeviceName",
"(",
")",
"{",
"networkInfo",
".",
"Addresses",
"=",
"append",
"(",
"networkInfo",
".",
"Addresses",
",",
"ifaceAddress",
")",
"\n",
"return",
"networkInfos",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"MAC",
":=",
"\"",
"\"",
"\n",
"device",
",",
"err",
":=",
"address",
".",
"Device",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"MAC",
"=",
"device",
".",
"MACAddress",
"(",
")",
"\n",
"}",
"else",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"networkInfo",
":=",
"network",
".",
"NetworkInfo",
"{",
"InterfaceName",
":",
"address",
".",
"DeviceName",
"(",
")",
",",
"MACAddress",
":",
"MAC",
",",
"Addresses",
":",
"[",
"]",
"network",
".",
"InterfaceAddress",
"{",
"ifaceAddress",
"}",
",",
"}",
"\n",
"return",
"append",
"(",
"networkInfos",
",",
"networkInfo",
")",
",",
"nil",
"\n",
"}"
] | // Add address to a device in list or create a new device with this address. | [
"Add",
"address",
"to",
"a",
"device",
"in",
"list",
"or",
"create",
"a",
"new",
"device",
"with",
"this",
"address",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/machine_linklayerdevices.go#L1097-L1123 |
155,401 | juju/juju | apiserver/facades/agent/migrationflag/shim.go | MigrationPhase | func (shim *backend) MigrationPhase() (migration.Phase, error) {
mig, err := shim.st.LatestMigration()
if errors.IsNotFound(err) {
return migration.NONE, nil
} else if err != nil {
return migration.UNKNOWN, errors.Trace(err)
}
phase, err := mig.Phase()
if err != nil {
return migration.UNKNOWN, errors.Trace(err)
}
return phase, nil
} | go | func (shim *backend) MigrationPhase() (migration.Phase, error) {
mig, err := shim.st.LatestMigration()
if errors.IsNotFound(err) {
return migration.NONE, nil
} else if err != nil {
return migration.UNKNOWN, errors.Trace(err)
}
phase, err := mig.Phase()
if err != nil {
return migration.UNKNOWN, errors.Trace(err)
}
return phase, nil
} | [
"func",
"(",
"shim",
"*",
"backend",
")",
"MigrationPhase",
"(",
")",
"(",
"migration",
".",
"Phase",
",",
"error",
")",
"{",
"mig",
",",
"err",
":=",
"shim",
".",
"st",
".",
"LatestMigration",
"(",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"migration",
".",
"NONE",
",",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"migration",
".",
"UNKNOWN",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"phase",
",",
"err",
":=",
"mig",
".",
"Phase",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"migration",
".",
"UNKNOWN",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"phase",
",",
"nil",
"\n",
"}"
] | // MigrationPhase is part of the Backend interface. | [
"MigrationPhase",
"is",
"part",
"of",
"the",
"Backend",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/migrationflag/shim.go#L39-L51 |
155,402 | juju/juju | state/binarystorage.go | ToolsStorage | func (st *State) ToolsStorage() (binarystorage.StorageCloser, error) {
modelStorage := newBinaryStorageCloser(st.database, toolsmetadataC, st.ModelUUID())
if st.IsController() {
return modelStorage, nil
}
// This is a hosted model. Hosted models have their own tools
// catalogue, which we combine with the controller's.
controllerStorage := newBinaryStorageCloser(
st.database, toolsmetadataC, st.ControllerModelUUID(),
)
storage, err := binarystorage.NewLayeredStorage(modelStorage, controllerStorage)
if err != nil {
modelStorage.Close()
controllerStorage.Close()
return nil, errors.Trace(err)
}
return &storageCloser{storage, func() {
modelStorage.Close()
controllerStorage.Close()
}}, nil
} | go | func (st *State) ToolsStorage() (binarystorage.StorageCloser, error) {
modelStorage := newBinaryStorageCloser(st.database, toolsmetadataC, st.ModelUUID())
if st.IsController() {
return modelStorage, nil
}
// This is a hosted model. Hosted models have their own tools
// catalogue, which we combine with the controller's.
controllerStorage := newBinaryStorageCloser(
st.database, toolsmetadataC, st.ControllerModelUUID(),
)
storage, err := binarystorage.NewLayeredStorage(modelStorage, controllerStorage)
if err != nil {
modelStorage.Close()
controllerStorage.Close()
return nil, errors.Trace(err)
}
return &storageCloser{storage, func() {
modelStorage.Close()
controllerStorage.Close()
}}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ToolsStorage",
"(",
")",
"(",
"binarystorage",
".",
"StorageCloser",
",",
"error",
")",
"{",
"modelStorage",
":=",
"newBinaryStorageCloser",
"(",
"st",
".",
"database",
",",
"toolsmetadataC",
",",
"st",
".",
"ModelUUID",
"(",
")",
")",
"\n",
"if",
"st",
".",
"IsController",
"(",
")",
"{",
"return",
"modelStorage",
",",
"nil",
"\n",
"}",
"\n",
"// This is a hosted model. Hosted models have their own tools",
"// catalogue, which we combine with the controller's.",
"controllerStorage",
":=",
"newBinaryStorageCloser",
"(",
"st",
".",
"database",
",",
"toolsmetadataC",
",",
"st",
".",
"ControllerModelUUID",
"(",
")",
",",
")",
"\n",
"storage",
",",
"err",
":=",
"binarystorage",
".",
"NewLayeredStorage",
"(",
"modelStorage",
",",
"controllerStorage",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"modelStorage",
".",
"Close",
"(",
")",
"\n",
"controllerStorage",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"storageCloser",
"{",
"storage",
",",
"func",
"(",
")",
"{",
"modelStorage",
".",
"Close",
"(",
")",
"\n",
"controllerStorage",
".",
"Close",
"(",
")",
"\n",
"}",
"}",
",",
"nil",
"\n",
"}"
] | // ToolsStorage returns a new binarystorage.StorageCloser that stores tools
// metadata in the "juju" database "toolsmetadata" collection. | [
"ToolsStorage",
"returns",
"a",
"new",
"binarystorage",
".",
"StorageCloser",
"that",
"stores",
"tools",
"metadata",
"in",
"the",
"juju",
"database",
"toolsmetadata",
"collection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage.go#L19-L39 |
155,403 | juju/juju | state/binarystorage.go | GUIStorage | func (st *State) GUIStorage() (binarystorage.StorageCloser, error) {
return newBinaryStorageCloser(st.database, guimetadataC, st.ControllerModelUUID()), nil
} | go | func (st *State) GUIStorage() (binarystorage.StorageCloser, error) {
return newBinaryStorageCloser(st.database, guimetadataC, st.ControllerModelUUID()), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"GUIStorage",
"(",
")",
"(",
"binarystorage",
".",
"StorageCloser",
",",
"error",
")",
"{",
"return",
"newBinaryStorageCloser",
"(",
"st",
".",
"database",
",",
"guimetadataC",
",",
"st",
".",
"ControllerModelUUID",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // GUIStorage returns a new binarystorage.StorageCloser that stores GUI archive
// metadata in the "juju" database "guimetadata" collection. | [
"GUIStorage",
"returns",
"a",
"new",
"binarystorage",
".",
"StorageCloser",
"that",
"stores",
"GUI",
"archive",
"metadata",
"in",
"the",
"juju",
"database",
"guimetadata",
"collection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage.go#L43-L45 |
155,404 | juju/juju | apiserver/facades/client/application/mocks/model_mock.go | NewMockStateModel | func NewMockStateModel(ctrl *gomock.Controller) *MockStateModel {
mock := &MockStateModel{ctrl: ctrl}
mock.recorder = &MockStateModelMockRecorder{mock}
return mock
} | go | func NewMockStateModel(ctrl *gomock.Controller) *MockStateModel {
mock := &MockStateModel{ctrl: ctrl}
mock.recorder = &MockStateModelMockRecorder{mock}
return mock
} | [
"func",
"NewMockStateModel",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockStateModel",
"{",
"mock",
":=",
"&",
"MockStateModel",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockStateModelMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockStateModel creates a new mock instance | [
"NewMockStateModel",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/model_mock.go#L25-L29 |
155,405 | juju/juju | apiserver/facades/client/application/mocks/model_mock.go | ModelConfig | func (m *MockStateModel) ModelConfig() (*config.Config, error) {
ret := m.ctrl.Call(m, "ModelConfig")
ret0, _ := ret[0].(*config.Config)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockStateModel) ModelConfig() (*config.Config, error) {
ret := m.ctrl.Call(m, "ModelConfig")
ret0, _ := ret[0].(*config.Config)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockStateModel",
")",
"ModelConfig",
"(",
")",
"(",
"*",
"config",
".",
"Config",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"config",
".",
"Config",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ModelConfig mocks base method | [
"ModelConfig",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/model_mock.go#L37-L42 |
155,406 | juju/juju | apiserver/facades/client/application/mocks/model_mock.go | ModelConfig | func (mr *MockStateModelMockRecorder) ModelConfig() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelConfig", reflect.TypeOf((*MockStateModel)(nil).ModelConfig))
} | go | func (mr *MockStateModelMockRecorder) ModelConfig() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelConfig", reflect.TypeOf((*MockStateModel)(nil).ModelConfig))
} | [
"func",
"(",
"mr",
"*",
"MockStateModelMockRecorder",
")",
"ModelConfig",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockStateModel",
")",
"(",
"nil",
")",
".",
"ModelConfig",
")",
")",
"\n",
"}"
] | // ModelConfig indicates an expected call of ModelConfig | [
"ModelConfig",
"indicates",
"an",
"expected",
"call",
"of",
"ModelConfig"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/model_mock.go#L45-L47 |
155,407 | juju/juju | worker/lease/bound.go | pinOp | func (b *boundManager) pinOp(leaseName string, entity string, ch chan pin) error {
return errors.Trace(pin{
leaseKey: b.leaseKey(leaseName),
entity: entity,
response: make(chan error),
stop: b.manager.catacomb.Dying(),
}.invoke(ch))
} | go | func (b *boundManager) pinOp(leaseName string, entity string, ch chan pin) error {
return errors.Trace(pin{
leaseKey: b.leaseKey(leaseName),
entity: entity,
response: make(chan error),
stop: b.manager.catacomb.Dying(),
}.invoke(ch))
} | [
"func",
"(",
"b",
"*",
"boundManager",
")",
"pinOp",
"(",
"leaseName",
"string",
",",
"entity",
"string",
",",
"ch",
"chan",
"pin",
")",
"error",
"{",
"return",
"errors",
".",
"Trace",
"(",
"pin",
"{",
"leaseKey",
":",
"b",
".",
"leaseKey",
"(",
"leaseName",
")",
",",
"entity",
":",
"entity",
",",
"response",
":",
"make",
"(",
"chan",
"error",
")",
",",
"stop",
":",
"b",
".",
"manager",
".",
"catacomb",
".",
"Dying",
"(",
")",
",",
"}",
".",
"invoke",
"(",
"ch",
")",
")",
"\n",
"}"
] | // pinOp creates a pin instance from the input lease name,
// then sends it on the input channel. | [
"pinOp",
"creates",
"a",
"pin",
"instance",
"from",
"the",
"input",
"lease",
"name",
"then",
"sends",
"it",
"on",
"the",
"input",
"channel",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/lease/bound.go#L103-L110 |
155,408 | juju/juju | worker/lease/bound.go | leaseKey | func (b *boundManager) leaseKey(leaseName string) lease.Key {
return lease.Key{
Namespace: b.namespace,
ModelUUID: b.modelUUID,
Lease: leaseName,
}
} | go | func (b *boundManager) leaseKey(leaseName string) lease.Key {
return lease.Key{
Namespace: b.namespace,
ModelUUID: b.modelUUID,
Lease: leaseName,
}
} | [
"func",
"(",
"b",
"*",
"boundManager",
")",
"leaseKey",
"(",
"leaseName",
"string",
")",
"lease",
".",
"Key",
"{",
"return",
"lease",
".",
"Key",
"{",
"Namespace",
":",
"b",
".",
"namespace",
",",
"ModelUUID",
":",
"b",
".",
"modelUUID",
",",
"Lease",
":",
"leaseName",
",",
"}",
"\n",
"}"
] | // leaseKey returns a key for the manager's binding and the input lease name. | [
"leaseKey",
"returns",
"a",
"key",
"for",
"the",
"manager",
"s",
"binding",
"and",
"the",
"input",
"lease",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/lease/bound.go#L113-L119 |
155,409 | juju/juju | worker/remoterelations/shim.go | remoteRelationsFacadeForModelFunc | func remoteRelationsFacadeForModelFunc(
connectionFunc apicaller.NewExternalControllerConnectionFunc,
) newRemoteRelationsFacadeFunc {
return func(apiInfo *api.Info) (RemoteModelRelationsFacadeCloser, error) {
apiInfo.Tag = names.NewUserTag(api.AnonymousUsername)
conn, err := connectionFunc(apiInfo)
if err != nil {
return nil, errors.Trace(err)
}
facade, err := NewRemoteModelRelationsFacade(conn)
if err != nil {
conn.Close()
return nil, errors.Trace(err)
}
return &remoteModelRelationsFacadeCloser{facade, conn}, nil
}
} | go | func remoteRelationsFacadeForModelFunc(
connectionFunc apicaller.NewExternalControllerConnectionFunc,
) newRemoteRelationsFacadeFunc {
return func(apiInfo *api.Info) (RemoteModelRelationsFacadeCloser, error) {
apiInfo.Tag = names.NewUserTag(api.AnonymousUsername)
conn, err := connectionFunc(apiInfo)
if err != nil {
return nil, errors.Trace(err)
}
facade, err := NewRemoteModelRelationsFacade(conn)
if err != nil {
conn.Close()
return nil, errors.Trace(err)
}
return &remoteModelRelationsFacadeCloser{facade, conn}, nil
}
} | [
"func",
"remoteRelationsFacadeForModelFunc",
"(",
"connectionFunc",
"apicaller",
".",
"NewExternalControllerConnectionFunc",
",",
")",
"newRemoteRelationsFacadeFunc",
"{",
"return",
"func",
"(",
"apiInfo",
"*",
"api",
".",
"Info",
")",
"(",
"RemoteModelRelationsFacadeCloser",
",",
"error",
")",
"{",
"apiInfo",
".",
"Tag",
"=",
"names",
".",
"NewUserTag",
"(",
"api",
".",
"AnonymousUsername",
")",
"\n",
"conn",
",",
"err",
":=",
"connectionFunc",
"(",
"apiInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"facade",
",",
"err",
":=",
"NewRemoteModelRelationsFacade",
"(",
"conn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"remoteModelRelationsFacadeCloser",
"{",
"facade",
",",
"conn",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // remoteRelationsFacadeForModelFunc returns a function that
// can be used to construct instances which manage remote relation
// changes for a given model.
// For now we use a facade, but in future this may evolve into a REST caller. | [
"remoteRelationsFacadeForModelFunc",
"returns",
"a",
"function",
"that",
"can",
"be",
"used",
"to",
"construct",
"instances",
"which",
"manage",
"remote",
"relation",
"changes",
"for",
"a",
"given",
"model",
".",
"For",
"now",
"we",
"use",
"a",
"facade",
"but",
"in",
"future",
"this",
"may",
"evolve",
"into",
"a",
"REST",
"caller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/remoterelations/shim.go#L43-L59 |
155,410 | juju/juju | provider/gce/google/instance.go | NewInstance | func NewInstance(summary InstanceSummary, spec *InstanceSpec) *Instance {
if spec != nil {
// Make a copy.
val := *spec
spec = &val
}
return &Instance{
InstanceSummary: summary,
spec: spec,
}
} | go | func NewInstance(summary InstanceSummary, spec *InstanceSpec) *Instance {
if spec != nil {
// Make a copy.
val := *spec
spec = &val
}
return &Instance{
InstanceSummary: summary,
spec: spec,
}
} | [
"func",
"NewInstance",
"(",
"summary",
"InstanceSummary",
",",
"spec",
"*",
"InstanceSpec",
")",
"*",
"Instance",
"{",
"if",
"spec",
"!=",
"nil",
"{",
"// Make a copy.",
"val",
":=",
"*",
"spec",
"\n",
"spec",
"=",
"&",
"val",
"\n",
"}",
"\n",
"return",
"&",
"Instance",
"{",
"InstanceSummary",
":",
"summary",
",",
"spec",
":",
"spec",
",",
"}",
"\n",
"}"
] | // NewInstance builds an instance from the provided summary and spec
// and returns it. | [
"NewInstance",
"builds",
"an",
"instance",
"from",
"the",
"provided",
"summary",
"and",
"spec",
"and",
"returns",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/instance.go#L142-L152 |
155,411 | juju/juju | provider/gce/google/instance.go | RootDisk | func (gi Instance) RootDisk() *compute.AttachedDisk {
if gi.spec == nil {
return nil
}
return gi.spec.RootDisk()
} | go | func (gi Instance) RootDisk() *compute.AttachedDisk {
if gi.spec == nil {
return nil
}
return gi.spec.RootDisk()
} | [
"func",
"(",
"gi",
"Instance",
")",
"RootDisk",
"(",
")",
"*",
"compute",
".",
"AttachedDisk",
"{",
"if",
"gi",
".",
"spec",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"gi",
".",
"spec",
".",
"RootDisk",
"(",
")",
"\n",
"}"
] | // RootDisk returns an AttachedDisk | [
"RootDisk",
"returns",
"an",
"AttachedDisk"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/instance.go#L155-L160 |
155,412 | juju/juju | provider/gce/google/instance.go | RootDiskGB | func (gi Instance) RootDiskGB() uint64 {
if gi.spec == nil {
return 0
}
attached := gi.RootDisk()
return uint64(attached.InitializeParams.DiskSizeGb)
} | go | func (gi Instance) RootDiskGB() uint64 {
if gi.spec == nil {
return 0
}
attached := gi.RootDisk()
return uint64(attached.InitializeParams.DiskSizeGb)
} | [
"func",
"(",
"gi",
"Instance",
")",
"RootDiskGB",
"(",
")",
"uint64",
"{",
"if",
"gi",
".",
"spec",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"attached",
":=",
"gi",
".",
"RootDisk",
"(",
")",
"\n",
"return",
"uint64",
"(",
"attached",
".",
"InitializeParams",
".",
"DiskSizeGb",
")",
"\n",
"}"
] | // RootDiskGB returns the size of the instance's root disk. If it
// cannot be determined then 0 is returned. | [
"RootDiskGB",
"returns",
"the",
"size",
"of",
"the",
"instance",
"s",
"root",
"disk",
".",
"If",
"it",
"cannot",
"be",
"determined",
"then",
"0",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/instance.go#L164-L170 |
155,413 | juju/juju | provider/gce/google/instance.go | NetworkInterfaces | func (gi Instance) NetworkInterfaces() []compute.NetworkInterface {
var results []compute.NetworkInterface
// Copy to prevent callers from mutating the source data.
for _, iface := range gi.InstanceSummary.NetworkInterfaces {
results = append(results, *iface)
}
return results
} | go | func (gi Instance) NetworkInterfaces() []compute.NetworkInterface {
var results []compute.NetworkInterface
// Copy to prevent callers from mutating the source data.
for _, iface := range gi.InstanceSummary.NetworkInterfaces {
results = append(results, *iface)
}
return results
} | [
"func",
"(",
"gi",
"Instance",
")",
"NetworkInterfaces",
"(",
")",
"[",
"]",
"compute",
".",
"NetworkInterface",
"{",
"var",
"results",
"[",
"]",
"compute",
".",
"NetworkInterface",
"\n",
"// Copy to prevent callers from mutating the source data.",
"for",
"_",
",",
"iface",
":=",
"range",
"gi",
".",
"InstanceSummary",
".",
"NetworkInterfaces",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"*",
"iface",
")",
"\n",
"}",
"\n",
"return",
"results",
"\n",
"}"
] | // NetworkInterfaces returns the details of the network connection for
// this instance. | [
"NetworkInterfaces",
"returns",
"the",
"details",
"of",
"the",
"network",
"connection",
"for",
"this",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/instance.go#L193-L200 |
155,414 | juju/juju | provider/gce/google/instance.go | packMetadata | func packMetadata(data map[string]string) *compute.Metadata {
var items []*compute.MetadataItems
for key, value := range data {
// Needs to be a new variable so that &localValue is different
// each time round the loop.
localValue := value
item := compute.MetadataItems{
Key: key,
Value: &localValue,
}
items = append(items, &item)
}
return &compute.Metadata{Items: items}
} | go | func packMetadata(data map[string]string) *compute.Metadata {
var items []*compute.MetadataItems
for key, value := range data {
// Needs to be a new variable so that &localValue is different
// each time round the loop.
localValue := value
item := compute.MetadataItems{
Key: key,
Value: &localValue,
}
items = append(items, &item)
}
return &compute.Metadata{Items: items}
} | [
"func",
"packMetadata",
"(",
"data",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"compute",
".",
"Metadata",
"{",
"var",
"items",
"[",
"]",
"*",
"compute",
".",
"MetadataItems",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"data",
"{",
"// Needs to be a new variable so that &localValue is different",
"// each time round the loop.",
"localValue",
":=",
"value",
"\n",
"item",
":=",
"compute",
".",
"MetadataItems",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"&",
"localValue",
",",
"}",
"\n",
"items",
"=",
"append",
"(",
"items",
",",
"&",
"item",
")",
"\n",
"}",
"\n",
"return",
"&",
"compute",
".",
"Metadata",
"{",
"Items",
":",
"items",
"}",
"\n",
"}"
] | // packMetadata composes the provided data into the format required
// by the GCE API. | [
"packMetadata",
"composes",
"the",
"provided",
"data",
"into",
"the",
"format",
"required",
"by",
"the",
"GCE",
"API",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/instance.go#L204-L217 |
155,415 | juju/juju | provider/gce/google/instance.go | unpackMetadata | func unpackMetadata(data *compute.Metadata) map[string]string {
if data == nil {
return nil
}
result := make(map[string]string)
for _, item := range data.Items {
if item == nil {
continue
}
value := ""
if item.Value != nil {
value = *item.Value
}
result[item.Key] = value
}
return result
} | go | func unpackMetadata(data *compute.Metadata) map[string]string {
if data == nil {
return nil
}
result := make(map[string]string)
for _, item := range data.Items {
if item == nil {
continue
}
value := ""
if item.Value != nil {
value = *item.Value
}
result[item.Key] = value
}
return result
} | [
"func",
"unpackMetadata",
"(",
"data",
"*",
"compute",
".",
"Metadata",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"data",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"data",
".",
"Items",
"{",
"if",
"item",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"value",
":=",
"\"",
"\"",
"\n",
"if",
"item",
".",
"Value",
"!=",
"nil",
"{",
"value",
"=",
"*",
"item",
".",
"Value",
"\n",
"}",
"\n",
"result",
"[",
"item",
".",
"Key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // unpackMetadata decomposes the provided data from the format used
// in the GCE API. | [
"unpackMetadata",
"decomposes",
"the",
"provided",
"data",
"from",
"the",
"format",
"used",
"in",
"the",
"GCE",
"API",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/instance.go#L221-L238 |
155,416 | juju/juju | api/sshclient/facade.go | NewFacade | func NewFacade(callCloser base.APICallCloser) *Facade {
clientFacade, caller := base.NewClientFacade(callCloser, "SSHClient")
return &Facade{
ClientFacade: clientFacade,
caller: caller,
}
} | go | func NewFacade(callCloser base.APICallCloser) *Facade {
clientFacade, caller := base.NewClientFacade(callCloser, "SSHClient")
return &Facade{
ClientFacade: clientFacade,
caller: caller,
}
} | [
"func",
"NewFacade",
"(",
"callCloser",
"base",
".",
"APICallCloser",
")",
"*",
"Facade",
"{",
"clientFacade",
",",
"caller",
":=",
"base",
".",
"NewClientFacade",
"(",
"callCloser",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"Facade",
"{",
"ClientFacade",
":",
"clientFacade",
",",
"caller",
":",
"caller",
",",
"}",
"\n",
"}"
] | // NewFacade returns a new Facade based on an existing API connection. | [
"NewFacade",
"returns",
"a",
"new",
"Facade",
"based",
"on",
"an",
"existing",
"API",
"connection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/sshclient/facade.go#L15-L21 |
155,417 | juju/juju | api/sshclient/facade.go | PublicAddress | func (facade *Facade) PublicAddress(target string) (string, error) {
addr, err := facade.addressCall("PublicAddress", target)
return addr, errors.Trace(err)
} | go | func (facade *Facade) PublicAddress(target string) (string, error) {
addr, err := facade.addressCall("PublicAddress", target)
return addr, errors.Trace(err)
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"PublicAddress",
"(",
"target",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"addr",
",",
"err",
":=",
"facade",
".",
"addressCall",
"(",
"\"",
"\"",
",",
"target",
")",
"\n",
"return",
"addr",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // PublicAddress returns the public address for the SSH target
// provided. The target may be provided as a machine ID or unit name. | [
"PublicAddress",
"returns",
"the",
"public",
"address",
"for",
"the",
"SSH",
"target",
"provided",
".",
"The",
"target",
"may",
"be",
"provided",
"as",
"a",
"machine",
"ID",
"or",
"unit",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/sshclient/facade.go#L30-L33 |
155,418 | juju/juju | api/sshclient/facade.go | AllAddresses | func (facade *Facade) AllAddresses(target string) ([]string, error) {
entities, err := targetToEntities(target)
if err != nil {
return nil, errors.Trace(err)
}
var out params.SSHAddressesResults
err = facade.caller.FacadeCall("AllAddresses", entities, &out)
if err != nil {
return nil, errors.Trace(err)
}
if len(out.Results) != 1 {
return nil, countError(len(out.Results))
}
if err := out.Results[0].Error; err != nil {
return nil, errors.Trace(err)
}
return out.Results[0].Addresses, nil
} | go | func (facade *Facade) AllAddresses(target string) ([]string, error) {
entities, err := targetToEntities(target)
if err != nil {
return nil, errors.Trace(err)
}
var out params.SSHAddressesResults
err = facade.caller.FacadeCall("AllAddresses", entities, &out)
if err != nil {
return nil, errors.Trace(err)
}
if len(out.Results) != 1 {
return nil, countError(len(out.Results))
}
if err := out.Results[0].Error; err != nil {
return nil, errors.Trace(err)
}
return out.Results[0].Addresses, nil
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"AllAddresses",
"(",
"target",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"entities",
",",
"err",
":=",
"targetToEntities",
"(",
"target",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"out",
"params",
".",
"SSHAddressesResults",
"\n",
"err",
"=",
"facade",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"entities",
",",
"&",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"out",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"countError",
"(",
"len",
"(",
"out",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"out",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"out",
".",
"Results",
"[",
"0",
"]",
".",
"Addresses",
",",
"nil",
"\n",
"}"
] | // AllAddresses returns all addresses for the SSH target provided. The target
// may be provided as a machine ID or unit name. | [
"AllAddresses",
"returns",
"all",
"addresses",
"for",
"the",
"SSH",
"target",
"provided",
".",
"The",
"target",
"may",
"be",
"provided",
"as",
"a",
"machine",
"ID",
"or",
"unit",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/sshclient/facade.go#L44-L61 |
155,419 | juju/juju | api/sshclient/facade.go | PublicKeys | func (facade *Facade) PublicKeys(target string) ([]string, error) {
entities, err := targetToEntities(target)
if err != nil {
return nil, errors.Trace(err)
}
var out params.SSHPublicKeysResults
err = facade.caller.FacadeCall("PublicKeys", entities, &out)
if err != nil {
return nil, errors.Trace(err)
}
if len(out.Results) != 1 {
return nil, countError(len(out.Results))
}
if err := out.Results[0].Error; err != nil {
return nil, errors.Trace(err)
}
return out.Results[0].PublicKeys, nil
} | go | func (facade *Facade) PublicKeys(target string) ([]string, error) {
entities, err := targetToEntities(target)
if err != nil {
return nil, errors.Trace(err)
}
var out params.SSHPublicKeysResults
err = facade.caller.FacadeCall("PublicKeys", entities, &out)
if err != nil {
return nil, errors.Trace(err)
}
if len(out.Results) != 1 {
return nil, countError(len(out.Results))
}
if err := out.Results[0].Error; err != nil {
return nil, errors.Trace(err)
}
return out.Results[0].PublicKeys, nil
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"PublicKeys",
"(",
"target",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"entities",
",",
"err",
":=",
"targetToEntities",
"(",
"target",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"out",
"params",
".",
"SSHPublicKeysResults",
"\n",
"err",
"=",
"facade",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"entities",
",",
"&",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"out",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"countError",
"(",
"len",
"(",
"out",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"out",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"out",
".",
"Results",
"[",
"0",
"]",
".",
"PublicKeys",
",",
"nil",
"\n",
"}"
] | // PublicKeys returns the SSH public host keys for the SSH target
// provided. The target may be provided as a machine ID or unit name. | [
"PublicKeys",
"returns",
"the",
"SSH",
"public",
"host",
"keys",
"for",
"the",
"SSH",
"target",
"provided",
".",
"The",
"target",
"may",
"be",
"provided",
"as",
"a",
"machine",
"ID",
"or",
"unit",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/sshclient/facade.go#L84-L101 |
155,420 | juju/juju | api/sshclient/facade.go | Proxy | func (facade *Facade) Proxy() (bool, error) {
var out params.SSHProxyResult
err := facade.caller.FacadeCall("Proxy", nil, &out)
if err != nil {
return false, errors.Trace(err)
}
return out.UseProxy, nil
} | go | func (facade *Facade) Proxy() (bool, error) {
var out params.SSHProxyResult
err := facade.caller.FacadeCall("Proxy", nil, &out)
if err != nil {
return false, errors.Trace(err)
}
return out.UseProxy, nil
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"Proxy",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"out",
"params",
".",
"SSHProxyResult",
"\n",
"err",
":=",
"facade",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"nil",
",",
"&",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"out",
".",
"UseProxy",
",",
"nil",
"\n",
"}"
] | // Proxy returns whether SSH connections should be proxied through the
// controller hosts for the associated model. | [
"Proxy",
"returns",
"whether",
"SSH",
"connections",
"should",
"be",
"proxied",
"through",
"the",
"controller",
"hosts",
"for",
"the",
"associated",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/sshclient/facade.go#L105-L112 |
155,421 | juju/juju | api/uniter/leadership.go | NewLeadershipSettingsAccessor | func NewLeadershipSettingsAccessor(
caller FacadeCallFn,
newWatcher NewNotifyWatcherFn,
checkAPIVersion CheckAPIVersionFn,
) *LeadershipSettingsAccessor {
return &LeadershipSettingsAccessor{caller, newWatcher, checkAPIVersion}
} | go | func NewLeadershipSettingsAccessor(
caller FacadeCallFn,
newWatcher NewNotifyWatcherFn,
checkAPIVersion CheckAPIVersionFn,
) *LeadershipSettingsAccessor {
return &LeadershipSettingsAccessor{caller, newWatcher, checkAPIVersion}
} | [
"func",
"NewLeadershipSettingsAccessor",
"(",
"caller",
"FacadeCallFn",
",",
"newWatcher",
"NewNotifyWatcherFn",
",",
"checkAPIVersion",
"CheckAPIVersionFn",
",",
")",
"*",
"LeadershipSettingsAccessor",
"{",
"return",
"&",
"LeadershipSettingsAccessor",
"{",
"caller",
",",
"newWatcher",
",",
"checkAPIVersion",
"}",
"\n",
"}"
] | // NewLeadershipSettingsAccessor returns a new LeadershipSettingsAccessor. | [
"NewLeadershipSettingsAccessor",
"returns",
"a",
"new",
"LeadershipSettingsAccessor",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/leadership.go#L15-L21 |
155,422 | juju/juju | api/uniter/leadership.go | Merge | func (lsa *LeadershipSettingsAccessor) Merge(appId, unitId string, settings map[string]string) error {
if err := lsa.checkAPIVersion("Merge"); err != nil {
return errors.Annotatef(err, "cannot access leadership api")
}
results, err := lsa.bulkMerge(lsa.prepareMerge(appId, unitId, settings))
if err != nil {
return errors.Annotatef(err, "failed to call leadership api")
}
if count := len(results.Results); count != 1 {
return errors.Errorf("expected 1 result from leadership api, got %d", count)
}
if results.Results[0].Error != nil {
return errors.Annotatef(results.Results[0].Error, "failed to merge leadership settings")
}
return nil
} | go | func (lsa *LeadershipSettingsAccessor) Merge(appId, unitId string, settings map[string]string) error {
if err := lsa.checkAPIVersion("Merge"); err != nil {
return errors.Annotatef(err, "cannot access leadership api")
}
results, err := lsa.bulkMerge(lsa.prepareMerge(appId, unitId, settings))
if err != nil {
return errors.Annotatef(err, "failed to call leadership api")
}
if count := len(results.Results); count != 1 {
return errors.Errorf("expected 1 result from leadership api, got %d", count)
}
if results.Results[0].Error != nil {
return errors.Annotatef(results.Results[0].Error, "failed to merge leadership settings")
}
return nil
} | [
"func",
"(",
"lsa",
"*",
"LeadershipSettingsAccessor",
")",
"Merge",
"(",
"appId",
",",
"unitId",
"string",
",",
"settings",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"lsa",
".",
"checkAPIVersion",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"results",
",",
"err",
":=",
"lsa",
".",
"bulkMerge",
"(",
"lsa",
".",
"prepareMerge",
"(",
"appId",
",",
"unitId",
",",
"settings",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"count",
":=",
"len",
"(",
"results",
".",
"Results",
")",
";",
"count",
"!=",
"1",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"count",
")",
"\n",
"}",
"\n",
"if",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Merge merges the provided settings into the leadership settings for
// the given application and unit. Only leaders of a given application may perform
// this operation. | [
"Merge",
"merges",
"the",
"provided",
"settings",
"into",
"the",
"leadership",
"settings",
"for",
"the",
"given",
"application",
"and",
"unit",
".",
"Only",
"leaders",
"of",
"a",
"given",
"application",
"may",
"perform",
"this",
"operation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/leadership.go#L38-L54 |
155,423 | juju/juju | api/uniter/leadership.go | Read | func (lsa *LeadershipSettingsAccessor) Read(appId string) (map[string]string, error) {
if err := lsa.checkAPIVersion("Read"); err != nil {
return nil, errors.Annotatef(err, "cannot access leadership api")
}
results, err := lsa.bulkRead(lsa.prepareRead(appId))
if err != nil {
return nil, errors.Annotatef(err, "failed to call leadership api")
}
if count := len(results.Results); count != 1 {
return nil, errors.Errorf("expected 1 result from leadership api, got %d", count)
}
if results.Results[0].Error != nil {
return nil, errors.Annotatef(results.Results[0].Error, "failed to read leadership settings")
}
return results.Results[0].Settings, nil
} | go | func (lsa *LeadershipSettingsAccessor) Read(appId string) (map[string]string, error) {
if err := lsa.checkAPIVersion("Read"); err != nil {
return nil, errors.Annotatef(err, "cannot access leadership api")
}
results, err := lsa.bulkRead(lsa.prepareRead(appId))
if err != nil {
return nil, errors.Annotatef(err, "failed to call leadership api")
}
if count := len(results.Results); count != 1 {
return nil, errors.Errorf("expected 1 result from leadership api, got %d", count)
}
if results.Results[0].Error != nil {
return nil, errors.Annotatef(results.Results[0].Error, "failed to read leadership settings")
}
return results.Results[0].Settings, nil
} | [
"func",
"(",
"lsa",
"*",
"LeadershipSettingsAccessor",
")",
"Read",
"(",
"appId",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"lsa",
".",
"checkAPIVersion",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"results",
",",
"err",
":=",
"lsa",
".",
"bulkRead",
"(",
"lsa",
".",
"prepareRead",
"(",
"appId",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"count",
":=",
"len",
"(",
"results",
".",
"Results",
")",
";",
"count",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"count",
")",
"\n",
"}",
"\n",
"if",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Settings",
",",
"nil",
"\n",
"}"
] | // Read retrieves the leadership settings for the given application
// ID. Anyone may perform this operation. | [
"Read",
"retrieves",
"the",
"leadership",
"settings",
"for",
"the",
"given",
"application",
"ID",
".",
"Anyone",
"may",
"perform",
"this",
"operation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/leadership.go#L58-L75 |
155,424 | juju/juju | api/uniter/leadership.go | WatchLeadershipSettings | func (lsa *LeadershipSettingsAccessor) WatchLeadershipSettings(appId string) (watcher.NotifyWatcher, error) {
if err := lsa.checkAPIVersion("WatchLeadershipSettings"); err != nil {
return nil, errors.Annotatef(err, "cannot access leadership api")
}
var results params.NotifyWatchResults
if err := lsa.facadeCaller(
"WatchLeadershipSettings",
params.Entities{[]params.Entity{{names.NewApplicationTag(appId).String()}}},
&results,
); err != nil {
return nil, errors.Annotate(err, "failed to call leadership api")
}
if count := len(results.Results); count != 1 {
return nil, errors.Errorf("expected 1 result from leadership api, got %d", count)
}
if results.Results[0].Error != nil {
return nil, errors.Annotatef(results.Results[0].Error, "failed to watch leadership settings")
}
return lsa.newNotifyWatcher(results.Results[0]), nil
} | go | func (lsa *LeadershipSettingsAccessor) WatchLeadershipSettings(appId string) (watcher.NotifyWatcher, error) {
if err := lsa.checkAPIVersion("WatchLeadershipSettings"); err != nil {
return nil, errors.Annotatef(err, "cannot access leadership api")
}
var results params.NotifyWatchResults
if err := lsa.facadeCaller(
"WatchLeadershipSettings",
params.Entities{[]params.Entity{{names.NewApplicationTag(appId).String()}}},
&results,
); err != nil {
return nil, errors.Annotate(err, "failed to call leadership api")
}
if count := len(results.Results); count != 1 {
return nil, errors.Errorf("expected 1 result from leadership api, got %d", count)
}
if results.Results[0].Error != nil {
return nil, errors.Annotatef(results.Results[0].Error, "failed to watch leadership settings")
}
return lsa.newNotifyWatcher(results.Results[0]), nil
} | [
"func",
"(",
"lsa",
"*",
"LeadershipSettingsAccessor",
")",
"WatchLeadershipSettings",
"(",
"appId",
"string",
")",
"(",
"watcher",
".",
"NotifyWatcher",
",",
"error",
")",
"{",
"if",
"err",
":=",
"lsa",
".",
"checkAPIVersion",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"results",
"params",
".",
"NotifyWatchResults",
"\n",
"if",
"err",
":=",
"lsa",
".",
"facadeCaller",
"(",
"\"",
"\"",
",",
"params",
".",
"Entities",
"{",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"names",
".",
"NewApplicationTag",
"(",
"appId",
")",
".",
"String",
"(",
")",
"}",
"}",
"}",
",",
"&",
"results",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"count",
":=",
"len",
"(",
"results",
".",
"Results",
")",
";",
"count",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"count",
")",
"\n",
"}",
"\n",
"if",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"lsa",
".",
"newNotifyWatcher",
"(",
"results",
".",
"Results",
"[",
"0",
"]",
")",
",",
"nil",
"\n",
"}"
] | // WatchLeadershipSettings returns a watcher which can be used to wait
// for leadership settings changes to be made for a given application ID. | [
"WatchLeadershipSettings",
"returns",
"a",
"watcher",
"which",
"can",
"be",
"used",
"to",
"wait",
"for",
"leadership",
"settings",
"changes",
"to",
"be",
"made",
"for",
"a",
"given",
"application",
"ID",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/leadership.go#L79-L99 |
155,425 | juju/juju | api/uniter/leadership.go | prepareMerge | func (lsa *LeadershipSettingsAccessor) prepareMerge(appId, unitId string, settings map[string]string) params.MergeLeadershipSettingsParam {
return params.MergeLeadershipSettingsParam{
ApplicationTag: names.NewApplicationTag(appId).String(),
UnitTag: names.NewUnitTag(unitId).String(),
Settings: settings,
}
} | go | func (lsa *LeadershipSettingsAccessor) prepareMerge(appId, unitId string, settings map[string]string) params.MergeLeadershipSettingsParam {
return params.MergeLeadershipSettingsParam{
ApplicationTag: names.NewApplicationTag(appId).String(),
UnitTag: names.NewUnitTag(unitId).String(),
Settings: settings,
}
} | [
"func",
"(",
"lsa",
"*",
"LeadershipSettingsAccessor",
")",
"prepareMerge",
"(",
"appId",
",",
"unitId",
"string",
",",
"settings",
"map",
"[",
"string",
"]",
"string",
")",
"params",
".",
"MergeLeadershipSettingsParam",
"{",
"return",
"params",
".",
"MergeLeadershipSettingsParam",
"{",
"ApplicationTag",
":",
"names",
".",
"NewApplicationTag",
"(",
"appId",
")",
".",
"String",
"(",
")",
",",
"UnitTag",
":",
"names",
".",
"NewUnitTag",
"(",
"unitId",
")",
".",
"String",
"(",
")",
",",
"Settings",
":",
"settings",
",",
"}",
"\n",
"}"
] | //
// Prepare functions for building bulk-calls.
// | [
"Prepare",
"functions",
"for",
"building",
"bulk",
"-",
"calls",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/leadership.go#L105-L111 |
155,426 | juju/juju | api/storage/client.go | StorageDetails | func (c *Client) StorageDetails(tags []names.StorageTag) ([]params.StorageDetailsResult, error) {
found := params.StorageDetailsResults{}
entities := make([]params.Entity, len(tags))
for i, tag := range tags {
entities[i] = params.Entity{Tag: tag.String()}
}
if err := c.facade.FacadeCall("StorageDetails", params.Entities{Entities: entities}, &found); err != nil {
return nil, errors.Trace(err)
}
return found.Results, nil
} | go | func (c *Client) StorageDetails(tags []names.StorageTag) ([]params.StorageDetailsResult, error) {
found := params.StorageDetailsResults{}
entities := make([]params.Entity, len(tags))
for i, tag := range tags {
entities[i] = params.Entity{Tag: tag.String()}
}
if err := c.facade.FacadeCall("StorageDetails", params.Entities{Entities: entities}, &found); err != nil {
return nil, errors.Trace(err)
}
return found.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"StorageDetails",
"(",
"tags",
"[",
"]",
"names",
".",
"StorageTag",
")",
"(",
"[",
"]",
"params",
".",
"StorageDetailsResult",
",",
"error",
")",
"{",
"found",
":=",
"params",
".",
"StorageDetailsResults",
"{",
"}",
"\n",
"entities",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"Entity",
",",
"len",
"(",
"tags",
")",
")",
"\n",
"for",
"i",
",",
"tag",
":=",
"range",
"tags",
"{",
"entities",
"[",
"i",
"]",
"=",
"params",
".",
"Entity",
"{",
"Tag",
":",
"tag",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"params",
".",
"Entities",
"{",
"Entities",
":",
"entities",
"}",
",",
"&",
"found",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"found",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // StorageDetails retrieves details about desired storage instances. | [
"StorageDetails",
"retrieves",
"details",
"about",
"desired",
"storage",
"instances",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L30-L40 |
155,427 | juju/juju | api/storage/client.go | ListStorageDetails | func (c *Client) ListStorageDetails() ([]params.StorageDetails, error) {
args := params.StorageFilters{
[]params.StorageFilter{{}}, // one empty filter
}
var results params.StorageDetailsListResults
if err := c.facade.FacadeCall("ListStorageDetails", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != 1 {
return nil, errors.Errorf(
"expected 1 result, got %d",
len(results.Results),
)
}
if results.Results[0].Error != nil {
return nil, errors.Trace(results.Results[0].Error)
}
return results.Results[0].Result, nil
} | go | func (c *Client) ListStorageDetails() ([]params.StorageDetails, error) {
args := params.StorageFilters{
[]params.StorageFilter{{}}, // one empty filter
}
var results params.StorageDetailsListResults
if err := c.facade.FacadeCall("ListStorageDetails", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != 1 {
return nil, errors.Errorf(
"expected 1 result, got %d",
len(results.Results),
)
}
if results.Results[0].Error != nil {
return nil, errors.Trace(results.Results[0].Error)
}
return results.Results[0].Result, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListStorageDetails",
"(",
")",
"(",
"[",
"]",
"params",
".",
"StorageDetails",
",",
"error",
")",
"{",
"args",
":=",
"params",
".",
"StorageFilters",
"{",
"[",
"]",
"params",
".",
"StorageFilter",
"{",
"{",
"}",
"}",
",",
"// one empty filter",
"}",
"\n",
"var",
"results",
"params",
".",
"StorageDetailsListResults",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"if",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // ListStorageDetails lists all storage. | [
"ListStorageDetails",
"lists",
"all",
"storage",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L43-L61 |
155,428 | juju/juju | api/storage/client.go | ListPools | func (c *Client) ListPools(providers, names []string) ([]params.StoragePool, error) {
args := params.StoragePoolFilters{
Filters: []params.StoragePoolFilter{{
Names: names,
Providers: providers,
}},
}
var results params.StoragePoolsResults
if err := c.facade.FacadeCall("ListPools", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
if err := results.Results[0].Error; err != nil {
return nil, err
}
return results.Results[0].Result, nil
} | go | func (c *Client) ListPools(providers, names []string) ([]params.StoragePool, error) {
args := params.StoragePoolFilters{
Filters: []params.StoragePoolFilter{{
Names: names,
Providers: providers,
}},
}
var results params.StoragePoolsResults
if err := c.facade.FacadeCall("ListPools", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
if err := results.Results[0].Error; err != nil {
return nil, err
}
return results.Results[0].Result, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListPools",
"(",
"providers",
",",
"names",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"StoragePool",
",",
"error",
")",
"{",
"args",
":=",
"params",
".",
"StoragePoolFilters",
"{",
"Filters",
":",
"[",
"]",
"params",
".",
"StoragePoolFilter",
"{",
"{",
"Names",
":",
"names",
",",
"Providers",
":",
"providers",
",",
"}",
"}",
",",
"}",
"\n",
"var",
"results",
"params",
".",
"StoragePoolsResults",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // ListPools returns a list of pools that matches given filter.
// If no filter was provided, a list of all pools is returned. | [
"ListPools",
"returns",
"a",
"list",
"of",
"pools",
"that",
"matches",
"given",
"filter",
".",
"If",
"no",
"filter",
"was",
"provided",
"a",
"list",
"of",
"all",
"pools",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L65-L83 |
155,429 | juju/juju | api/storage/client.go | CreatePool | func (c *Client) CreatePool(pname, provider string, attrs map[string]interface{}) error {
// Older facade did not support bulk calls.
if c.BestAPIVersion() < 5 {
args := params.StoragePool{
Name: pname,
Provider: provider,
Attrs: attrs,
}
return c.facade.FacadeCall("CreatePool", args, nil)
}
var results params.ErrorResults
args := params.StoragePoolArgs{
Pools: []params.StoragePool{{
Name: pname,
Provider: provider,
Attrs: attrs,
}},
}
if err := c.facade.FacadeCall("CreatePool", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | go | func (c *Client) CreatePool(pname, provider string, attrs map[string]interface{}) error {
// Older facade did not support bulk calls.
if c.BestAPIVersion() < 5 {
args := params.StoragePool{
Name: pname,
Provider: provider,
Attrs: attrs,
}
return c.facade.FacadeCall("CreatePool", args, nil)
}
var results params.ErrorResults
args := params.StoragePoolArgs{
Pools: []params.StoragePool{{
Name: pname,
Provider: provider,
Attrs: attrs,
}},
}
if err := c.facade.FacadeCall("CreatePool", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreatePool",
"(",
"pname",
",",
"provider",
"string",
",",
"attrs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"// Older facade did not support bulk calls.",
"if",
"c",
".",
"BestAPIVersion",
"(",
")",
"<",
"5",
"{",
"args",
":=",
"params",
".",
"StoragePool",
"{",
"Name",
":",
"pname",
",",
"Provider",
":",
"provider",
",",
"Attrs",
":",
"attrs",
",",
"}",
"\n",
"return",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"StoragePoolArgs",
"{",
"Pools",
":",
"[",
"]",
"params",
".",
"StoragePool",
"{",
"{",
"Name",
":",
"pname",
",",
"Provider",
":",
"provider",
",",
"Attrs",
":",
"attrs",
",",
"}",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // CreatePool creates pool with specified parameters. | [
"CreatePool",
"creates",
"pool",
"with",
"specified",
"parameters",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L86-L110 |
155,430 | juju/juju | api/storage/client.go | RemovePool | func (c *Client) RemovePool(pname string) error {
if c.BestAPIVersion() < 5 {
return errors.New("removing storage pools is not supported by this version of Juju")
}
var results params.ErrorResults
args := params.StoragePoolDeleteArgs{
Pools: []params.StoragePoolDeleteArg{{
Name: pname,
}},
}
if err := c.facade.FacadeCall("RemovePool", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | go | func (c *Client) RemovePool(pname string) error {
if c.BestAPIVersion() < 5 {
return errors.New("removing storage pools is not supported by this version of Juju")
}
var results params.ErrorResults
args := params.StoragePoolDeleteArgs{
Pools: []params.StoragePoolDeleteArg{{
Name: pname,
}},
}
if err := c.facade.FacadeCall("RemovePool", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RemovePool",
"(",
"pname",
"string",
")",
"error",
"{",
"if",
"c",
".",
"BestAPIVersion",
"(",
")",
"<",
"5",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"StoragePoolDeleteArgs",
"{",
"Pools",
":",
"[",
"]",
"params",
".",
"StoragePoolDeleteArg",
"{",
"{",
"Name",
":",
"pname",
",",
"}",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // RemovePool removes the named pool | [
"RemovePool",
"removes",
"the",
"named",
"pool"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L113-L127 |
155,431 | juju/juju | api/storage/client.go | UpdatePool | func (c *Client) UpdatePool(pname, provider string, attrs map[string]interface{}) error {
if c.BestAPIVersion() < 5 {
return errors.New("updating storage pools is not supported by this version of Juju")
}
var results params.ErrorResults
args := params.StoragePoolArgs{
Pools: []params.StoragePool{{
Name: pname,
Provider: provider,
Attrs: attrs,
}},
}
if err := c.facade.FacadeCall("UpdatePool", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | go | func (c *Client) UpdatePool(pname, provider string, attrs map[string]interface{}) error {
if c.BestAPIVersion() < 5 {
return errors.New("updating storage pools is not supported by this version of Juju")
}
var results params.ErrorResults
args := params.StoragePoolArgs{
Pools: []params.StoragePool{{
Name: pname,
Provider: provider,
Attrs: attrs,
}},
}
if err := c.facade.FacadeCall("UpdatePool", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdatePool",
"(",
"pname",
",",
"provider",
"string",
",",
"attrs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"c",
".",
"BestAPIVersion",
"(",
")",
"<",
"5",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"StoragePoolArgs",
"{",
"Pools",
":",
"[",
"]",
"params",
".",
"StoragePool",
"{",
"{",
"Name",
":",
"pname",
",",
"Provider",
":",
"provider",
",",
"Attrs",
":",
"attrs",
",",
"}",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // UpdatePool updates a pool with specified parameters. | [
"UpdatePool",
"updates",
"a",
"pool",
"with",
"specified",
"parameters",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L130-L146 |
155,432 | juju/juju | api/storage/client.go | ListVolumes | func (c *Client) ListVolumes(machines []string) ([]params.VolumeDetailsListResult, error) {
filters := make([]params.VolumeFilter, len(machines))
for i, machine := range machines {
filters[i].Machines = []string{names.NewMachineTag(machine).String()}
}
if len(filters) == 0 {
filters = []params.VolumeFilter{{}}
}
args := params.VolumeFilters{filters}
var results params.VolumeDetailsListResults
if err := c.facade.FacadeCall("ListVolumes", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(filters) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(filters), len(results.Results),
)
}
return results.Results, nil
} | go | func (c *Client) ListVolumes(machines []string) ([]params.VolumeDetailsListResult, error) {
filters := make([]params.VolumeFilter, len(machines))
for i, machine := range machines {
filters[i].Machines = []string{names.NewMachineTag(machine).String()}
}
if len(filters) == 0 {
filters = []params.VolumeFilter{{}}
}
args := params.VolumeFilters{filters}
var results params.VolumeDetailsListResults
if err := c.facade.FacadeCall("ListVolumes", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(filters) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(filters), len(results.Results),
)
}
return results.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListVolumes",
"(",
"machines",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"VolumeDetailsListResult",
",",
"error",
")",
"{",
"filters",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"VolumeFilter",
",",
"len",
"(",
"machines",
")",
")",
"\n",
"for",
"i",
",",
"machine",
":=",
"range",
"machines",
"{",
"filters",
"[",
"i",
"]",
".",
"Machines",
"=",
"[",
"]",
"string",
"{",
"names",
".",
"NewMachineTag",
"(",
"machine",
")",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"filters",
")",
"==",
"0",
"{",
"filters",
"=",
"[",
"]",
"params",
".",
"VolumeFilter",
"{",
"{",
"}",
"}",
"\n",
"}",
"\n",
"args",
":=",
"params",
".",
"VolumeFilters",
"{",
"filters",
"}",
"\n",
"var",
"results",
"params",
".",
"VolumeDetailsListResults",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"len",
"(",
"filters",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"filters",
")",
",",
"len",
"(",
"results",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // ListVolumes lists volumes for desired machines.
// If no machines provided, a list of all volumes is returned. | [
"ListVolumes",
"lists",
"volumes",
"for",
"desired",
"machines",
".",
"If",
"no",
"machines",
"provided",
"a",
"list",
"of",
"all",
"volumes",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L150-L170 |
155,433 | juju/juju | api/storage/client.go | ListFilesystems | func (c *Client) ListFilesystems(machines []string) ([]params.FilesystemDetailsListResult, error) {
filters := make([]params.FilesystemFilter, len(machines))
for i, machine := range machines {
filters[i].Machines = []string{names.NewMachineTag(machine).String()}
}
if len(filters) == 0 {
filters = []params.FilesystemFilter{{}}
}
args := params.FilesystemFilters{filters}
var results params.FilesystemDetailsListResults
if err := c.facade.FacadeCall("ListFilesystems", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(filters) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(filters), len(results.Results),
)
}
return results.Results, nil
} | go | func (c *Client) ListFilesystems(machines []string) ([]params.FilesystemDetailsListResult, error) {
filters := make([]params.FilesystemFilter, len(machines))
for i, machine := range machines {
filters[i].Machines = []string{names.NewMachineTag(machine).String()}
}
if len(filters) == 0 {
filters = []params.FilesystemFilter{{}}
}
args := params.FilesystemFilters{filters}
var results params.FilesystemDetailsListResults
if err := c.facade.FacadeCall("ListFilesystems", args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(filters) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(filters), len(results.Results),
)
}
return results.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListFilesystems",
"(",
"machines",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"FilesystemDetailsListResult",
",",
"error",
")",
"{",
"filters",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"FilesystemFilter",
",",
"len",
"(",
"machines",
")",
")",
"\n",
"for",
"i",
",",
"machine",
":=",
"range",
"machines",
"{",
"filters",
"[",
"i",
"]",
".",
"Machines",
"=",
"[",
"]",
"string",
"{",
"names",
".",
"NewMachineTag",
"(",
"machine",
")",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"filters",
")",
"==",
"0",
"{",
"filters",
"=",
"[",
"]",
"params",
".",
"FilesystemFilter",
"{",
"{",
"}",
"}",
"\n",
"}",
"\n",
"args",
":=",
"params",
".",
"FilesystemFilters",
"{",
"filters",
"}",
"\n",
"var",
"results",
"params",
".",
"FilesystemDetailsListResults",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"len",
"(",
"filters",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"filters",
")",
",",
"len",
"(",
"results",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // ListFilesystems lists filesystems for desired machines.
// If no machines provided, a list of all filesystems is returned. | [
"ListFilesystems",
"lists",
"filesystems",
"for",
"desired",
"machines",
".",
"If",
"no",
"machines",
"provided",
"a",
"list",
"of",
"all",
"filesystems",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L174-L194 |
155,434 | juju/juju | api/storage/client.go | Attach | func (c *Client) Attach(unitId string, storageIds []string) ([]params.ErrorResult, error) {
in := params.StorageAttachmentIds{
make([]params.StorageAttachmentId, len(storageIds)),
}
if !names.IsValidUnit(unitId) {
return nil, errors.NotValidf("unit ID %q", unitId)
}
for i, storageId := range storageIds {
if !names.IsValidStorage(storageId) {
return nil, errors.NotValidf("storage ID %q", storageId)
}
in.Ids[i] = params.StorageAttachmentId{
StorageTag: names.NewStorageTag(storageId).String(),
UnitTag: names.NewUnitTag(unitId).String(),
}
}
out := params.ErrorResults{}
if err := c.facade.FacadeCall("Attach", in, &out); err != nil {
return nil, errors.Trace(err)
}
if len(out.Results) != len(storageIds) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(storageIds), len(out.Results),
)
}
return out.Results, nil
} | go | func (c *Client) Attach(unitId string, storageIds []string) ([]params.ErrorResult, error) {
in := params.StorageAttachmentIds{
make([]params.StorageAttachmentId, len(storageIds)),
}
if !names.IsValidUnit(unitId) {
return nil, errors.NotValidf("unit ID %q", unitId)
}
for i, storageId := range storageIds {
if !names.IsValidStorage(storageId) {
return nil, errors.NotValidf("storage ID %q", storageId)
}
in.Ids[i] = params.StorageAttachmentId{
StorageTag: names.NewStorageTag(storageId).String(),
UnitTag: names.NewUnitTag(unitId).String(),
}
}
out := params.ErrorResults{}
if err := c.facade.FacadeCall("Attach", in, &out); err != nil {
return nil, errors.Trace(err)
}
if len(out.Results) != len(storageIds) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(storageIds), len(out.Results),
)
}
return out.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Attach",
"(",
"unitId",
"string",
",",
"storageIds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"error",
")",
"{",
"in",
":=",
"params",
".",
"StorageAttachmentIds",
"{",
"make",
"(",
"[",
"]",
"params",
".",
"StorageAttachmentId",
",",
"len",
"(",
"storageIds",
")",
")",
",",
"}",
"\n",
"if",
"!",
"names",
".",
"IsValidUnit",
"(",
"unitId",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"unitId",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"storageId",
":=",
"range",
"storageIds",
"{",
"if",
"!",
"names",
".",
"IsValidStorage",
"(",
"storageId",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"storageId",
")",
"\n",
"}",
"\n",
"in",
".",
"Ids",
"[",
"i",
"]",
"=",
"params",
".",
"StorageAttachmentId",
"{",
"StorageTag",
":",
"names",
".",
"NewStorageTag",
"(",
"storageId",
")",
".",
"String",
"(",
")",
",",
"UnitTag",
":",
"names",
".",
"NewUnitTag",
"(",
"unitId",
")",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"out",
":=",
"params",
".",
"ErrorResults",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"in",
",",
"&",
"out",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"out",
".",
"Results",
")",
"!=",
"len",
"(",
"storageIds",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"storageIds",
")",
",",
"len",
"(",
"out",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"out",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // Attach attaches existing storage to a unit. | [
"Attach",
"attaches",
"existing",
"storage",
"to",
"a",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L211-L238 |
155,435 | juju/juju | api/storage/client.go | Remove | func (c *Client) Remove(storageIds []string, destroyAttachments, destroyStorage bool, force *bool, maxWait *time.Duration) ([]params.ErrorResult, error) {
for _, id := range storageIds {
if !names.IsValidStorage(id) {
return nil, errors.NotValidf("storage ID %q", id)
}
}
results := params.ErrorResults{}
var args interface{}
var method string
if c.BestAPIVersion() <= 3 {
if !destroyStorage {
return nil, errors.Errorf("this juju controller does not support non-destructive removal of storage")
}
// In version 3, destroyAttached is ignored; removing
// storage always causes detachment.
entities := make([]params.Entity, len(storageIds))
for i, id := range storageIds {
entities[i].Tag = names.NewStorageTag(id).String()
}
args = params.Entities{entities}
method = "Destroy"
} else {
aStorage := make([]params.RemoveStorageInstance, len(storageIds))
for i, id := range storageIds {
aStorage[i] = params.RemoveStorageInstance{
Tag: names.NewStorageTag(id).String(),
DestroyAttachments: destroyAttachments,
DestroyStorage: destroyStorage,
}
if c.BestAPIVersion() > 5 {
aStorage[i].Force = force
aStorage[i].MaxWait = maxWait
}
}
args = params.RemoveStorage{aStorage}
method = "Remove"
}
if err := c.facade.FacadeCall(method, args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(storageIds) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(storageIds), len(results.Results),
)
}
return results.Results, nil
} | go | func (c *Client) Remove(storageIds []string, destroyAttachments, destroyStorage bool, force *bool, maxWait *time.Duration) ([]params.ErrorResult, error) {
for _, id := range storageIds {
if !names.IsValidStorage(id) {
return nil, errors.NotValidf("storage ID %q", id)
}
}
results := params.ErrorResults{}
var args interface{}
var method string
if c.BestAPIVersion() <= 3 {
if !destroyStorage {
return nil, errors.Errorf("this juju controller does not support non-destructive removal of storage")
}
// In version 3, destroyAttached is ignored; removing
// storage always causes detachment.
entities := make([]params.Entity, len(storageIds))
for i, id := range storageIds {
entities[i].Tag = names.NewStorageTag(id).String()
}
args = params.Entities{entities}
method = "Destroy"
} else {
aStorage := make([]params.RemoveStorageInstance, len(storageIds))
for i, id := range storageIds {
aStorage[i] = params.RemoveStorageInstance{
Tag: names.NewStorageTag(id).String(),
DestroyAttachments: destroyAttachments,
DestroyStorage: destroyStorage,
}
if c.BestAPIVersion() > 5 {
aStorage[i].Force = force
aStorage[i].MaxWait = maxWait
}
}
args = params.RemoveStorage{aStorage}
method = "Remove"
}
if err := c.facade.FacadeCall(method, args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(storageIds) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(storageIds), len(results.Results),
)
}
return results.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Remove",
"(",
"storageIds",
"[",
"]",
"string",
",",
"destroyAttachments",
",",
"destroyStorage",
"bool",
",",
"force",
"*",
"bool",
",",
"maxWait",
"*",
"time",
".",
"Duration",
")",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"error",
")",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"storageIds",
"{",
"if",
"!",
"names",
".",
"IsValidStorage",
"(",
"id",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"results",
":=",
"params",
".",
"ErrorResults",
"{",
"}",
"\n",
"var",
"args",
"interface",
"{",
"}",
"\n",
"var",
"method",
"string",
"\n",
"if",
"c",
".",
"BestAPIVersion",
"(",
")",
"<=",
"3",
"{",
"if",
"!",
"destroyStorage",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// In version 3, destroyAttached is ignored; removing",
"// storage always causes detachment.",
"entities",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"Entity",
",",
"len",
"(",
"storageIds",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"storageIds",
"{",
"entities",
"[",
"i",
"]",
".",
"Tag",
"=",
"names",
".",
"NewStorageTag",
"(",
"id",
")",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"args",
"=",
"params",
".",
"Entities",
"{",
"entities",
"}",
"\n",
"method",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"aStorage",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"RemoveStorageInstance",
",",
"len",
"(",
"storageIds",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"storageIds",
"{",
"aStorage",
"[",
"i",
"]",
"=",
"params",
".",
"RemoveStorageInstance",
"{",
"Tag",
":",
"names",
".",
"NewStorageTag",
"(",
"id",
")",
".",
"String",
"(",
")",
",",
"DestroyAttachments",
":",
"destroyAttachments",
",",
"DestroyStorage",
":",
"destroyStorage",
",",
"}",
"\n",
"if",
"c",
".",
"BestAPIVersion",
"(",
")",
">",
"5",
"{",
"aStorage",
"[",
"i",
"]",
".",
"Force",
"=",
"force",
"\n",
"aStorage",
"[",
"i",
"]",
".",
"MaxWait",
"=",
"maxWait",
"\n",
"}",
"\n",
"}",
"\n",
"args",
"=",
"params",
".",
"RemoveStorage",
"{",
"aStorage",
"}",
"\n",
"method",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"method",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"len",
"(",
"storageIds",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"storageIds",
")",
",",
"len",
"(",
"results",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // Remove removes the specified storage entities from the model,
// optionally destroying them. | [
"Remove",
"removes",
"the",
"specified",
"storage",
"entities",
"from",
"the",
"model",
"optionally",
"destroying",
"them",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L242-L289 |
155,436 | juju/juju | api/storage/client.go | Detach | func (c *Client) Detach(storageIds []string, force *bool, maxWait *time.Duration) ([]params.ErrorResult, error) {
results := params.ErrorResults{}
ids := make([]params.StorageAttachmentId, len(storageIds))
for i, id := range storageIds {
if !names.IsValidStorage(id) {
return nil, errors.NotValidf("storage ID %q", id)
}
ids[i] = params.StorageAttachmentId{
StorageTag: names.NewStorageTag(id).String(),
}
}
var args interface{}
var method string
if c.BestAPIVersion() < 6 {
method = "Detach"
args = params.StorageAttachmentIds{ids}
} else {
method = "DetachStorage"
args = params.StorageDetachmentParams{
StorageIds: params.StorageAttachmentIds{ids},
Force: force,
MaxWait: maxWait,
}
}
if err := c.facade.FacadeCall(method, args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(storageIds) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(storageIds), len(results.Results),
)
}
return results.Results, nil
} | go | func (c *Client) Detach(storageIds []string, force *bool, maxWait *time.Duration) ([]params.ErrorResult, error) {
results := params.ErrorResults{}
ids := make([]params.StorageAttachmentId, len(storageIds))
for i, id := range storageIds {
if !names.IsValidStorage(id) {
return nil, errors.NotValidf("storage ID %q", id)
}
ids[i] = params.StorageAttachmentId{
StorageTag: names.NewStorageTag(id).String(),
}
}
var args interface{}
var method string
if c.BestAPIVersion() < 6 {
method = "Detach"
args = params.StorageAttachmentIds{ids}
} else {
method = "DetachStorage"
args = params.StorageDetachmentParams{
StorageIds: params.StorageAttachmentIds{ids},
Force: force,
MaxWait: maxWait,
}
}
if err := c.facade.FacadeCall(method, args, &results); err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != len(storageIds) {
return nil, errors.Errorf(
"expected %d result(s), got %d",
len(storageIds), len(results.Results),
)
}
return results.Results, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Detach",
"(",
"storageIds",
"[",
"]",
"string",
",",
"force",
"*",
"bool",
",",
"maxWait",
"*",
"time",
".",
"Duration",
")",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"error",
")",
"{",
"results",
":=",
"params",
".",
"ErrorResults",
"{",
"}",
"\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"StorageAttachmentId",
",",
"len",
"(",
"storageIds",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"storageIds",
"{",
"if",
"!",
"names",
".",
"IsValidStorage",
"(",
"id",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"ids",
"[",
"i",
"]",
"=",
"params",
".",
"StorageAttachmentId",
"{",
"StorageTag",
":",
"names",
".",
"NewStorageTag",
"(",
"id",
")",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"var",
"args",
"interface",
"{",
"}",
"\n",
"var",
"method",
"string",
"\n",
"if",
"c",
".",
"BestAPIVersion",
"(",
")",
"<",
"6",
"{",
"method",
"=",
"\"",
"\"",
"\n",
"args",
"=",
"params",
".",
"StorageAttachmentIds",
"{",
"ids",
"}",
"\n",
"}",
"else",
"{",
"method",
"=",
"\"",
"\"",
"\n",
"args",
"=",
"params",
".",
"StorageDetachmentParams",
"{",
"StorageIds",
":",
"params",
".",
"StorageAttachmentIds",
"{",
"ids",
"}",
",",
"Force",
":",
"force",
",",
"MaxWait",
":",
"maxWait",
",",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"method",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"len",
"(",
"storageIds",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"storageIds",
")",
",",
"len",
"(",
"results",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"results",
".",
"Results",
",",
"nil",
"\n",
"}"
] | // Detach detaches the specified storage entities. | [
"Detach",
"detaches",
"the",
"specified",
"storage",
"entities",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L292-L326 |
155,437 | juju/juju | api/storage/client.go | Import | func (c *Client) Import(
kind storage.StorageKind,
storagePool string,
storageProviderId string,
storageName string,
) (names.StorageTag, error) {
var results params.ImportStorageResults
args := params.BulkImportStorageParams{
[]params.ImportStorageParams{{
StorageName: storageName,
Kind: params.StorageKind(kind),
Pool: storagePool,
ProviderId: storageProviderId,
}},
}
if err := c.facade.FacadeCall("Import", args, &results); err != nil {
return names.StorageTag{}, errors.Trace(err)
}
if len(results.Results) != 1 {
return names.StorageTag{}, errors.Errorf(
"expected 1 result, got %d",
len(results.Results),
)
}
if err := results.Results[0].Error; err != nil {
return names.StorageTag{}, err
}
return names.ParseStorageTag(results.Results[0].Result.StorageTag)
} | go | func (c *Client) Import(
kind storage.StorageKind,
storagePool string,
storageProviderId string,
storageName string,
) (names.StorageTag, error) {
var results params.ImportStorageResults
args := params.BulkImportStorageParams{
[]params.ImportStorageParams{{
StorageName: storageName,
Kind: params.StorageKind(kind),
Pool: storagePool,
ProviderId: storageProviderId,
}},
}
if err := c.facade.FacadeCall("Import", args, &results); err != nil {
return names.StorageTag{}, errors.Trace(err)
}
if len(results.Results) != 1 {
return names.StorageTag{}, errors.Errorf(
"expected 1 result, got %d",
len(results.Results),
)
}
if err := results.Results[0].Error; err != nil {
return names.StorageTag{}, err
}
return names.ParseStorageTag(results.Results[0].Result.StorageTag)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Import",
"(",
"kind",
"storage",
".",
"StorageKind",
",",
"storagePool",
"string",
",",
"storageProviderId",
"string",
",",
"storageName",
"string",
",",
")",
"(",
"names",
".",
"StorageTag",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"ImportStorageResults",
"\n",
"args",
":=",
"params",
".",
"BulkImportStorageParams",
"{",
"[",
"]",
"params",
".",
"ImportStorageParams",
"{",
"{",
"StorageName",
":",
"storageName",
",",
"Kind",
":",
"params",
".",
"StorageKind",
"(",
"kind",
")",
",",
"Pool",
":",
"storagePool",
",",
"ProviderId",
":",
"storageProviderId",
",",
"}",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"names",
".",
"StorageTag",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"names",
".",
"StorageTag",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
",",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"names",
".",
"StorageTag",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"names",
".",
"ParseStorageTag",
"(",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Result",
".",
"StorageTag",
")",
"\n",
"}"
] | // Import imports storage into the model. | [
"Import",
"imports",
"storage",
"into",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/storage/client.go#L329-L357 |
155,438 | juju/juju | utils/proxy/proxyconfig.go | Set | func (pc *ProxyConfig) Set(newSettings proxyutils.Settings) error {
pc.mu.Lock()
defer pc.mu.Unlock()
httpUrl, err := tolerantParse(newSettings.Http)
if err != nil {
return errors.Annotate(err, "http proxy")
}
httpsUrl, err := tolerantParse(newSettings.Https)
if err != nil {
return errors.Annotate(err, "https proxy")
}
pc.http = httpUrl
pc.https = httpsUrl
pc.noProxy = newSettings.FullNoProxy()
return nil
} | go | func (pc *ProxyConfig) Set(newSettings proxyutils.Settings) error {
pc.mu.Lock()
defer pc.mu.Unlock()
httpUrl, err := tolerantParse(newSettings.Http)
if err != nil {
return errors.Annotate(err, "http proxy")
}
httpsUrl, err := tolerantParse(newSettings.Https)
if err != nil {
return errors.Annotate(err, "https proxy")
}
pc.http = httpUrl
pc.https = httpsUrl
pc.noProxy = newSettings.FullNoProxy()
return nil
} | [
"func",
"(",
"pc",
"*",
"ProxyConfig",
")",
"Set",
"(",
"newSettings",
"proxyutils",
".",
"Settings",
")",
"error",
"{",
"pc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"httpUrl",
",",
"err",
":=",
"tolerantParse",
"(",
"newSettings",
".",
"Http",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"httpsUrl",
",",
"err",
":=",
"tolerantParse",
"(",
"newSettings",
".",
"Https",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pc",
".",
"http",
"=",
"httpUrl",
"\n",
"pc",
".",
"https",
"=",
"httpsUrl",
"\n",
"pc",
".",
"noProxy",
"=",
"newSettings",
".",
"FullNoProxy",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set updates the stored settings to the new ones passed in. | [
"Set",
"updates",
"the",
"stored",
"settings",
"to",
"the",
"new",
"ones",
"passed",
"in",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/utils/proxy/proxyconfig.go#L26-L41 |
155,439 | juju/juju | utils/proxy/proxyconfig.go | InstallInDefaultTransport | func (pc *ProxyConfig) InstallInDefaultTransport() error {
transport, ok := http.DefaultTransport.(*http.Transport)
if !ok {
return errors.Errorf("http.DefaultTransport was %T instead of *http.Transport", http.DefaultTransport)
}
transport.Proxy = pc.GetProxy
return nil
} | go | func (pc *ProxyConfig) InstallInDefaultTransport() error {
transport, ok := http.DefaultTransport.(*http.Transport)
if !ok {
return errors.Errorf("http.DefaultTransport was %T instead of *http.Transport", http.DefaultTransport)
}
transport.Proxy = pc.GetProxy
return nil
} | [
"func",
"(",
"pc",
"*",
"ProxyConfig",
")",
"InstallInDefaultTransport",
"(",
")",
"error",
"{",
"transport",
",",
"ok",
":=",
"http",
".",
"DefaultTransport",
".",
"(",
"*",
"http",
".",
"Transport",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"http",
".",
"DefaultTransport",
")",
"\n",
"}",
"\n",
"transport",
".",
"Proxy",
"=",
"pc",
".",
"GetProxy",
"\n",
"return",
"nil",
"\n",
"}"
] | // InstallInDefaultTransport sets the proxy resolution used by the
// default HTTP transport to use the proxy details stored in this
// ProxyConfig. Requests made without an explicit transport will
// respect these proxy settings. | [
"InstallInDefaultTransport",
"sets",
"the",
"proxy",
"resolution",
"used",
"by",
"the",
"default",
"HTTP",
"transport",
"to",
"use",
"the",
"proxy",
"details",
"stored",
"in",
"this",
"ProxyConfig",
".",
"Requests",
"made",
"without",
"an",
"explicit",
"transport",
"will",
"respect",
"these",
"proxy",
"settings",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/utils/proxy/proxyconfig.go#L128-L135 |
155,440 | juju/juju | cmd/juju/common/controller.go | getBlockAPI | func getBlockAPI(c *modelcmd.ModelCommandBase) (listBlocksAPI, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return block.NewClient(root), nil
} | go | func getBlockAPI(c *modelcmd.ModelCommandBase) (listBlocksAPI, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return block.NewClient(root), nil
} | [
"func",
"getBlockAPI",
"(",
"c",
"*",
"modelcmd",
".",
"ModelCommandBase",
")",
"(",
"listBlocksAPI",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"c",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"block",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // getBlockAPI returns a block api for listing blocks. | [
"getBlockAPI",
"returns",
"a",
"block",
"api",
"for",
"listing",
"blocks",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/controller.go#L41-L47 |
155,441 | juju/juju | cmd/juju/common/controller.go | tryAPI | func tryAPI(c *modelcmd.ModelCommandBase) error {
client, err := blockAPI(c)
if err == nil {
_, err = client.List()
closeErr := client.Close()
if closeErr != nil {
logger.Debugf("Error closing client: %v", closeErr)
}
}
return err
} | go | func tryAPI(c *modelcmd.ModelCommandBase) error {
client, err := blockAPI(c)
if err == nil {
_, err = client.List()
closeErr := client.Close()
if closeErr != nil {
logger.Debugf("Error closing client: %v", closeErr)
}
}
return err
} | [
"func",
"tryAPI",
"(",
"c",
"*",
"modelcmd",
".",
"ModelCommandBase",
")",
"error",
"{",
"client",
",",
"err",
":=",
"blockAPI",
"(",
"c",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"_",
",",
"err",
"=",
"client",
".",
"List",
"(",
")",
"\n",
"closeErr",
":=",
"client",
".",
"Close",
"(",
")",
"\n",
"if",
"closeErr",
"!=",
"nil",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"closeErr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // tryAPI attempts to open the API and makes a trivial call
// to check if the API is available yet. | [
"tryAPI",
"attempts",
"to",
"open",
"the",
"API",
"and",
"makes",
"a",
"trivial",
"call",
"to",
"check",
"if",
"the",
"API",
"is",
"available",
"yet",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/controller.go#L51-L61 |
155,442 | juju/juju | cmd/juju/common/controller.go | BootstrapEndpointAddresses | func BootstrapEndpointAddresses(environ environs.InstanceBroker, callContext context.ProviderCallContext) ([]network.Address, error) {
instances, err := environ.AllInstances(callContext)
if err != nil {
return nil, errors.Trace(err)
}
if n := len(instances); n != 1 {
return nil, errors.Errorf("expected one instance, got %d", n)
}
netAddrs, err := instances[0].Addresses(callContext)
if err != nil {
return nil, errors.Annotate(err, "failed to get bootstrap instance addresses")
}
return netAddrs, nil
} | go | func BootstrapEndpointAddresses(environ environs.InstanceBroker, callContext context.ProviderCallContext) ([]network.Address, error) {
instances, err := environ.AllInstances(callContext)
if err != nil {
return nil, errors.Trace(err)
}
if n := len(instances); n != 1 {
return nil, errors.Errorf("expected one instance, got %d", n)
}
netAddrs, err := instances[0].Addresses(callContext)
if err != nil {
return nil, errors.Annotate(err, "failed to get bootstrap instance addresses")
}
return netAddrs, nil
} | [
"func",
"BootstrapEndpointAddresses",
"(",
"environ",
"environs",
".",
"InstanceBroker",
",",
"callContext",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"error",
")",
"{",
"instances",
",",
"err",
":=",
"environ",
".",
"AllInstances",
"(",
"callContext",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"n",
":=",
"len",
"(",
"instances",
")",
";",
"n",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"}",
"\n",
"netAddrs",
",",
"err",
":=",
"instances",
"[",
"0",
"]",
".",
"Addresses",
"(",
"callContext",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"netAddrs",
",",
"nil",
"\n",
"}"
] | // BootstrapEndpointAddresses returns the addresses of the bootstrapped instance. | [
"BootstrapEndpointAddresses",
"returns",
"the",
"addresses",
"of",
"the",
"bootstrapped",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/controller.go#L132-L145 |
155,443 | juju/juju | cmd/juju/common/controller.go | ValidateIaasController | func ValidateIaasController(c modelcmd.CommandBase, cmdName, controllerName string, store jujuclient.ClientStore) error {
// Ensure controller model is cached.
controllerModel := jujuclient.JoinOwnerModelName(
names.NewUserTag(environs.AdminUser), bootstrap.ControllerModelName)
_, err := c.ModelUUIDs(store, controllerName, []string{controllerModel})
if err != nil {
return errors.Annotatef(err, "cannot get controller model uuid")
}
details, err := store.ModelByName(controllerName, controllerModel)
if err != nil {
return errors.Trace(err)
}
if details.ModelType == model.IAAS {
return nil
}
return errors.Errorf("Juju command %q not supported on kubernetes controllers", cmdName)
} | go | func ValidateIaasController(c modelcmd.CommandBase, cmdName, controllerName string, store jujuclient.ClientStore) error {
// Ensure controller model is cached.
controllerModel := jujuclient.JoinOwnerModelName(
names.NewUserTag(environs.AdminUser), bootstrap.ControllerModelName)
_, err := c.ModelUUIDs(store, controllerName, []string{controllerModel})
if err != nil {
return errors.Annotatef(err, "cannot get controller model uuid")
}
details, err := store.ModelByName(controllerName, controllerModel)
if err != nil {
return errors.Trace(err)
}
if details.ModelType == model.IAAS {
return nil
}
return errors.Errorf("Juju command %q not supported on kubernetes controllers", cmdName)
} | [
"func",
"ValidateIaasController",
"(",
"c",
"modelcmd",
".",
"CommandBase",
",",
"cmdName",
",",
"controllerName",
"string",
",",
"store",
"jujuclient",
".",
"ClientStore",
")",
"error",
"{",
"// Ensure controller model is cached.",
"controllerModel",
":=",
"jujuclient",
".",
"JoinOwnerModelName",
"(",
"names",
".",
"NewUserTag",
"(",
"environs",
".",
"AdminUser",
")",
",",
"bootstrap",
".",
"ControllerModelName",
")",
"\n",
"_",
",",
"err",
":=",
"c",
".",
"ModelUUIDs",
"(",
"store",
",",
"controllerName",
",",
"[",
"]",
"string",
"{",
"controllerModel",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"details",
",",
"err",
":=",
"store",
".",
"ModelByName",
"(",
"controllerName",
",",
"controllerModel",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"details",
".",
"ModelType",
"==",
"model",
".",
"IAAS",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmdName",
")",
"\n",
"}"
] | // ValidateIaasController returns an error if the controller
// is not an IAAS controller. | [
"ValidateIaasController",
"returns",
"an",
"error",
"if",
"the",
"controller",
"is",
"not",
"an",
"IAAS",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/common/controller.go#L149-L166 |
155,444 | juju/juju | cmd/juju/resource/deploy.go | charmStoreResources | func (d deployUploader) charmStoreResources(uploads map[string]string, revisions map[string]int) []charmresource.Resource {
var resources []charmresource.Resource
for name, meta := range d.resources {
if _, ok := uploads[name]; ok {
continue
}
revision := -1
if rev, ok := revisions[name]; ok {
revision = rev
}
resources = append(resources, charmresource.Resource{
Meta: meta,
Origin: charmresource.OriginStore,
Revision: revision,
// Fingerprint and Size will be added server-side in
// the AddPendingResources() API call.
})
}
return resources
} | go | func (d deployUploader) charmStoreResources(uploads map[string]string, revisions map[string]int) []charmresource.Resource {
var resources []charmresource.Resource
for name, meta := range d.resources {
if _, ok := uploads[name]; ok {
continue
}
revision := -1
if rev, ok := revisions[name]; ok {
revision = rev
}
resources = append(resources, charmresource.Resource{
Meta: meta,
Origin: charmresource.OriginStore,
Revision: revision,
// Fingerprint and Size will be added server-side in
// the AddPendingResources() API call.
})
}
return resources
} | [
"func",
"(",
"d",
"deployUploader",
")",
"charmStoreResources",
"(",
"uploads",
"map",
"[",
"string",
"]",
"string",
",",
"revisions",
"map",
"[",
"string",
"]",
"int",
")",
"[",
"]",
"charmresource",
".",
"Resource",
"{",
"var",
"resources",
"[",
"]",
"charmresource",
".",
"Resource",
"\n",
"for",
"name",
",",
"meta",
":=",
"range",
"d",
".",
"resources",
"{",
"if",
"_",
",",
"ok",
":=",
"uploads",
"[",
"name",
"]",
";",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"revision",
":=",
"-",
"1",
"\n",
"if",
"rev",
",",
"ok",
":=",
"revisions",
"[",
"name",
"]",
";",
"ok",
"{",
"revision",
"=",
"rev",
"\n",
"}",
"\n\n",
"resources",
"=",
"append",
"(",
"resources",
",",
"charmresource",
".",
"Resource",
"{",
"Meta",
":",
"meta",
",",
"Origin",
":",
"charmresource",
".",
"OriginStore",
",",
"Revision",
":",
"revision",
",",
"// Fingerprint and Size will be added server-side in",
"// the AddPendingResources() API call.",
"}",
")",
"\n",
"}",
"\n",
"return",
"resources",
"\n",
"}"
] | // charmStoreResources returns which resources revisions will need to be retrieved
// either as they where explicitly requested by the user for that rev or they
// weren't provided by the user. | [
"charmStoreResources",
"returns",
"which",
"resources",
"revisions",
"will",
"need",
"to",
"be",
"retrieved",
"either",
"as",
"they",
"where",
"explicitly",
"requested",
"by",
"the",
"user",
"for",
"that",
"rev",
"or",
"they",
"weren",
"t",
"provided",
"by",
"the",
"user",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/resource/deploy.go#L193-L214 |
155,445 | juju/juju | cmd/juju/resource/deploy.go | getDockerDetailsData | func getDockerDetailsData(path string, osOpen osOpenFunc) (resources.DockerImageDetails, error) {
f, err := osOpen(path)
if err == nil {
defer f.Close()
details, err := unMarshalDockerDetails(f)
if err != nil {
return details, errors.Trace(err)
}
return details, nil
} else if err := resources.ValidateDockerRegistryPath(path); err == nil {
return resources.DockerImageDetails{
RegistryPath: path,
}, nil
}
return resources.DockerImageDetails{}, errors.NotValidf("filepath or registry path: %s", path)
} | go | func getDockerDetailsData(path string, osOpen osOpenFunc) (resources.DockerImageDetails, error) {
f, err := osOpen(path)
if err == nil {
defer f.Close()
details, err := unMarshalDockerDetails(f)
if err != nil {
return details, errors.Trace(err)
}
return details, nil
} else if err := resources.ValidateDockerRegistryPath(path); err == nil {
return resources.DockerImageDetails{
RegistryPath: path,
}, nil
}
return resources.DockerImageDetails{}, errors.NotValidf("filepath or registry path: %s", path)
} | [
"func",
"getDockerDetailsData",
"(",
"path",
"string",
",",
"osOpen",
"osOpenFunc",
")",
"(",
"resources",
".",
"DockerImageDetails",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"osOpen",
"(",
"path",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"details",
",",
"err",
":=",
"unMarshalDockerDetails",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"details",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"details",
",",
"nil",
"\n",
"}",
"else",
"if",
"err",
":=",
"resources",
".",
"ValidateDockerRegistryPath",
"(",
"path",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"resources",
".",
"DockerImageDetails",
"{",
"RegistryPath",
":",
"path",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"resources",
".",
"DockerImageDetails",
"{",
"}",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n\n",
"}"
] | // getDockerDetailsData determines if path is a local file path and extracts the
// details from that otherwise path is considered to be a registry path. | [
"getDockerDetailsData",
"determines",
"if",
"path",
"is",
"a",
"local",
"file",
"path",
"and",
"extracts",
"the",
"details",
"from",
"that",
"otherwise",
"path",
"is",
"considered",
"to",
"be",
"a",
"registry",
"path",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/resource/deploy.go#L248-L264 |
155,446 | juju/juju | apiserver/facades/client/bundle/bundle.go | NewFacadeV1 | func NewFacadeV1(ctx facade.Context) (*APIv1, error) {
api, err := NewFacadeV2(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv1{api}, nil
} | go | func NewFacadeV1(ctx facade.Context) (*APIv1, error) {
api, err := NewFacadeV2(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv1{api}, nil
} | [
"func",
"NewFacadeV1",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv1",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewFacadeV2",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"APIv1",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV1 provides the signature required for facade registration
// version 1. | [
"NewFacadeV1",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"version",
"1",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/bundle/bundle.go#L53-L60 |
155,447 | juju/juju | apiserver/facades/client/bundle/bundle.go | NewFacadeV2 | func NewFacadeV2(ctx facade.Context) (*APIv2, error) {
api, err := newFacade(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv2{api}, nil
} | go | func NewFacadeV2(ctx facade.Context) (*APIv2, error) {
api, err := newFacade(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv2{api}, nil
} | [
"func",
"NewFacadeV2",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv2",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"newFacade",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv2",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV2 provides the signature required for facade registration
// for version 2. | [
"NewFacadeV2",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"for",
"version",
"2",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/bundle/bundle.go#L64-L70 |
155,448 | juju/juju | apiserver/facades/client/bundle/bundle.go | NewBundleAPI | func NewBundleAPI(
st Backend,
auth facade.Authorizer,
tag names.ModelTag,
) (*BundleAPI, error) {
if !auth.AuthClient() {
return nil, common.ErrPerm
}
return &BundleAPI{
backend: st,
authorizer: auth,
modelTag: tag,
}, nil
} | go | func NewBundleAPI(
st Backend,
auth facade.Authorizer,
tag names.ModelTag,
) (*BundleAPI, error) {
if !auth.AuthClient() {
return nil, common.ErrPerm
}
return &BundleAPI{
backend: st,
authorizer: auth,
modelTag: tag,
}, nil
} | [
"func",
"NewBundleAPI",
"(",
"st",
"Backend",
",",
"auth",
"facade",
".",
"Authorizer",
",",
"tag",
"names",
".",
"ModelTag",
",",
")",
"(",
"*",
"BundleAPI",
",",
"error",
")",
"{",
"if",
"!",
"auth",
".",
"AuthClient",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n\n",
"return",
"&",
"BundleAPI",
"{",
"backend",
":",
"st",
",",
"authorizer",
":",
"auth",
",",
"modelTag",
":",
"tag",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewBundleAPI returns the new Bundle API facade. | [
"NewBundleAPI",
"returns",
"the",
"new",
"Bundle",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/bundle/bundle.go#L85-L99 |
155,449 | juju/juju | apiserver/facades/client/bundle/bundle.go | NewBundleAPIv1 | func NewBundleAPIv1(
st Backend,
auth facade.Authorizer,
tag names.ModelTag,
) (*APIv1, error) {
api, err := NewBundleAPI(st, auth, tag)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv1{&APIv2{api}}, nil
} | go | func NewBundleAPIv1(
st Backend,
auth facade.Authorizer,
tag names.ModelTag,
) (*APIv1, error) {
api, err := NewBundleAPI(st, auth, tag)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv1{&APIv2{api}}, nil
} | [
"func",
"NewBundleAPIv1",
"(",
"st",
"Backend",
",",
"auth",
"facade",
".",
"Authorizer",
",",
"tag",
"names",
".",
"ModelTag",
",",
")",
"(",
"*",
"APIv1",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewBundleAPI",
"(",
"st",
",",
"auth",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv1",
"{",
"&",
"APIv2",
"{",
"api",
"}",
"}",
",",
"nil",
"\n",
"}"
] | // NewBundleAPIv1 returns the new Bundle APIv1 facade. | [
"NewBundleAPIv1",
"returns",
"the",
"new",
"Bundle",
"APIv1",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/bundle/bundle.go#L102-L112 |
155,450 | juju/juju | apiserver/facades/client/bundle/bundle.go | GetChanges | func (b *BundleAPI) GetChanges(args params.BundleChangesParams) (params.BundleChangesResults, error) {
vs := validators{
verifyConstraints: func(s string) error {
_, err := constraints.Parse(s)
return err
},
verifyStorage: func(s string) error {
_, err := storage.ParseConstraints(s)
return err
},
verifyDevices: func(s string) error {
_, err := devices.ParseConstraints(s)
return err
},
}
return getChanges(args, vs, func(changes []bundlechanges.Change, results *params.BundleChangesResults) error {
results.Changes = make([]*params.BundleChange, len(changes))
for i, c := range changes {
var guiArgs []interface{}
switch c := c.(type) {
case *bundlechanges.AddApplicationChange:
guiArgs = c.GUIArgsWithDevices()
default:
guiArgs = c.GUIArgs()
}
results.Changes[i] = ¶ms.BundleChange{
Id: c.Id(),
Method: c.Method(),
Args: guiArgs,
Requires: c.Requires(),
}
}
return nil
})
} | go | func (b *BundleAPI) GetChanges(args params.BundleChangesParams) (params.BundleChangesResults, error) {
vs := validators{
verifyConstraints: func(s string) error {
_, err := constraints.Parse(s)
return err
},
verifyStorage: func(s string) error {
_, err := storage.ParseConstraints(s)
return err
},
verifyDevices: func(s string) error {
_, err := devices.ParseConstraints(s)
return err
},
}
return getChanges(args, vs, func(changes []bundlechanges.Change, results *params.BundleChangesResults) error {
results.Changes = make([]*params.BundleChange, len(changes))
for i, c := range changes {
var guiArgs []interface{}
switch c := c.(type) {
case *bundlechanges.AddApplicationChange:
guiArgs = c.GUIArgsWithDevices()
default:
guiArgs = c.GUIArgs()
}
results.Changes[i] = ¶ms.BundleChange{
Id: c.Id(),
Method: c.Method(),
Args: guiArgs,
Requires: c.Requires(),
}
}
return nil
})
} | [
"func",
"(",
"b",
"*",
"BundleAPI",
")",
"GetChanges",
"(",
"args",
"params",
".",
"BundleChangesParams",
")",
"(",
"params",
".",
"BundleChangesResults",
",",
"error",
")",
"{",
"vs",
":=",
"validators",
"{",
"verifyConstraints",
":",
"func",
"(",
"s",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"constraints",
".",
"Parse",
"(",
"s",
")",
"\n",
"return",
"err",
"\n",
"}",
",",
"verifyStorage",
":",
"func",
"(",
"s",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"storage",
".",
"ParseConstraints",
"(",
"s",
")",
"\n",
"return",
"err",
"\n",
"}",
",",
"verifyDevices",
":",
"func",
"(",
"s",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"devices",
".",
"ParseConstraints",
"(",
"s",
")",
"\n",
"return",
"err",
"\n",
"}",
",",
"}",
"\n",
"return",
"getChanges",
"(",
"args",
",",
"vs",
",",
"func",
"(",
"changes",
"[",
"]",
"bundlechanges",
".",
"Change",
",",
"results",
"*",
"params",
".",
"BundleChangesResults",
")",
"error",
"{",
"results",
".",
"Changes",
"=",
"make",
"(",
"[",
"]",
"*",
"params",
".",
"BundleChange",
",",
"len",
"(",
"changes",
")",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"changes",
"{",
"var",
"guiArgs",
"[",
"]",
"interface",
"{",
"}",
"\n",
"switch",
"c",
":=",
"c",
".",
"(",
"type",
")",
"{",
"case",
"*",
"bundlechanges",
".",
"AddApplicationChange",
":",
"guiArgs",
"=",
"c",
".",
"GUIArgsWithDevices",
"(",
")",
"\n",
"default",
":",
"guiArgs",
"=",
"c",
".",
"GUIArgs",
"(",
")",
"\n",
"}",
"\n",
"results",
".",
"Changes",
"[",
"i",
"]",
"=",
"&",
"params",
".",
"BundleChange",
"{",
"Id",
":",
"c",
".",
"Id",
"(",
")",
",",
"Method",
":",
"c",
".",
"Method",
"(",
")",
",",
"Args",
":",
"guiArgs",
",",
"Requires",
":",
"c",
".",
"Requires",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] | // GetChanges returns the list of changes required to deploy the given bundle
// data. The changes are sorted by requirements, so that they can be applied in
// order. | [
"GetChanges",
"returns",
"the",
"list",
"of",
"changes",
"required",
"to",
"deploy",
"the",
"given",
"bundle",
"data",
".",
"The",
"changes",
"are",
"sorted",
"by",
"requirements",
"so",
"that",
"they",
"can",
"be",
"applied",
"in",
"order",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/bundle/bundle.go#L198-L232 |
155,451 | juju/juju | apiserver/facades/client/bundle/bundle.go | ExportBundle | func (b *BundleAPI) ExportBundle() (params.StringResult, error) {
fail := func(failErr error) (params.StringResult, error) {
return params.StringResult{}, common.ServerError(failErr)
}
if err := b.checkCanRead(); err != nil {
return fail(err)
}
exportConfig := b.backend.GetExportConfig()
model, err := b.backend.ExportPartial(exportConfig)
if err != nil {
return fail(err)
}
// Fill it in charm.BundleData data structure.
bundleData, err := b.fillBundleData(model)
if err != nil {
return fail(err)
}
bytes, err := yaml.Marshal(bundleData)
if err != nil {
return fail(err)
}
return params.StringResult{
Result: string(bytes),
}, nil
} | go | func (b *BundleAPI) ExportBundle() (params.StringResult, error) {
fail := func(failErr error) (params.StringResult, error) {
return params.StringResult{}, common.ServerError(failErr)
}
if err := b.checkCanRead(); err != nil {
return fail(err)
}
exportConfig := b.backend.GetExportConfig()
model, err := b.backend.ExportPartial(exportConfig)
if err != nil {
return fail(err)
}
// Fill it in charm.BundleData data structure.
bundleData, err := b.fillBundleData(model)
if err != nil {
return fail(err)
}
bytes, err := yaml.Marshal(bundleData)
if err != nil {
return fail(err)
}
return params.StringResult{
Result: string(bytes),
}, nil
} | [
"func",
"(",
"b",
"*",
"BundleAPI",
")",
"ExportBundle",
"(",
")",
"(",
"params",
".",
"StringResult",
",",
"error",
")",
"{",
"fail",
":=",
"func",
"(",
"failErr",
"error",
")",
"(",
"params",
".",
"StringResult",
",",
"error",
")",
"{",
"return",
"params",
".",
"StringResult",
"{",
"}",
",",
"common",
".",
"ServerError",
"(",
"failErr",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"b",
".",
"checkCanRead",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"exportConfig",
":=",
"b",
".",
"backend",
".",
"GetExportConfig",
"(",
")",
"\n",
"model",
",",
"err",
":=",
"b",
".",
"backend",
".",
"ExportPartial",
"(",
"exportConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Fill it in charm.BundleData data structure.",
"bundleData",
",",
"err",
":=",
"b",
".",
"fillBundleData",
"(",
"model",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"bytes",
",",
"err",
":=",
"yaml",
".",
"Marshal",
"(",
"bundleData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"params",
".",
"StringResult",
"{",
"Result",
":",
"string",
"(",
"bytes",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ExportBundle exports the current model configuration as bundle. | [
"ExportBundle",
"exports",
"the",
"current",
"model",
"configuration",
"as",
"bundle",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/bundle/bundle.go#L235-L264 |
155,452 | juju/juju | container/lxd/image.go | CopyRemoteImage | func (s *Server) CopyRemoteImage(
sourced SourcedImage, aliases []string, callback environs.StatusCallbackFunc,
) error {
logger.Debugf("Copying image from remote server")
newAliases := make([]api.ImageAlias, len(aliases))
for i, a := range aliases {
newAliases[i] = api.ImageAlias{Name: a}
}
req := &lxd.ImageCopyArgs{Aliases: newAliases}
op, err := s.CopyImage(sourced.LXDServer, *sourced.Image, req)
if err != nil {
return errors.Trace(err)
}
// Report progress via callback if supplied.
if callback != nil {
progress := func(op api.Operation) {
if op.Metadata == nil {
return
}
for _, key := range []string{"fs_progress", "download_progress"} {
if value, ok := op.Metadata[key]; ok {
callback(status.Provisioning, fmt.Sprintf("Retrieving image: %s", value.(string)), nil)
return
}
}
}
_, err = op.AddHandler(progress)
if err != nil {
return errors.Trace(err)
}
}
if err := op.Wait(); err != nil {
return errors.Trace(err)
}
opInfo, err := op.GetTarget()
if err != nil {
return errors.Trace(err)
}
if opInfo.StatusCode != api.Success {
return fmt.Errorf("image copy failed: %s", opInfo.Err)
}
return nil
} | go | func (s *Server) CopyRemoteImage(
sourced SourcedImage, aliases []string, callback environs.StatusCallbackFunc,
) error {
logger.Debugf("Copying image from remote server")
newAliases := make([]api.ImageAlias, len(aliases))
for i, a := range aliases {
newAliases[i] = api.ImageAlias{Name: a}
}
req := &lxd.ImageCopyArgs{Aliases: newAliases}
op, err := s.CopyImage(sourced.LXDServer, *sourced.Image, req)
if err != nil {
return errors.Trace(err)
}
// Report progress via callback if supplied.
if callback != nil {
progress := func(op api.Operation) {
if op.Metadata == nil {
return
}
for _, key := range []string{"fs_progress", "download_progress"} {
if value, ok := op.Metadata[key]; ok {
callback(status.Provisioning, fmt.Sprintf("Retrieving image: %s", value.(string)), nil)
return
}
}
}
_, err = op.AddHandler(progress)
if err != nil {
return errors.Trace(err)
}
}
if err := op.Wait(); err != nil {
return errors.Trace(err)
}
opInfo, err := op.GetTarget()
if err != nil {
return errors.Trace(err)
}
if opInfo.StatusCode != api.Success {
return fmt.Errorf("image copy failed: %s", opInfo.Err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"CopyRemoteImage",
"(",
"sourced",
"SourcedImage",
",",
"aliases",
"[",
"]",
"string",
",",
"callback",
"environs",
".",
"StatusCallbackFunc",
",",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n\n",
"newAliases",
":=",
"make",
"(",
"[",
"]",
"api",
".",
"ImageAlias",
",",
"len",
"(",
"aliases",
")",
")",
"\n",
"for",
"i",
",",
"a",
":=",
"range",
"aliases",
"{",
"newAliases",
"[",
"i",
"]",
"=",
"api",
".",
"ImageAlias",
"{",
"Name",
":",
"a",
"}",
"\n",
"}",
"\n\n",
"req",
":=",
"&",
"lxd",
".",
"ImageCopyArgs",
"{",
"Aliases",
":",
"newAliases",
"}",
"\n",
"op",
",",
"err",
":=",
"s",
".",
"CopyImage",
"(",
"sourced",
".",
"LXDServer",
",",
"*",
"sourced",
".",
"Image",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Report progress via callback if supplied.",
"if",
"callback",
"!=",
"nil",
"{",
"progress",
":=",
"func",
"(",
"op",
"api",
".",
"Operation",
")",
"{",
"if",
"op",
".",
"Metadata",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"value",
",",
"ok",
":=",
"op",
".",
"Metadata",
"[",
"key",
"]",
";",
"ok",
"{",
"callback",
"(",
"status",
".",
"Provisioning",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"value",
".",
"(",
"string",
")",
")",
",",
"nil",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"op",
".",
"AddHandler",
"(",
"progress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"op",
".",
"Wait",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"opInfo",
",",
"err",
":=",
"op",
".",
"GetTarget",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"opInfo",
".",
"StatusCode",
"!=",
"api",
".",
"Success",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"opInfo",
".",
"Err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CopyRemoteImage accepts an image sourced from a remote server and copies it
// to the local cache | [
"CopyRemoteImage",
"accepts",
"an",
"image",
"sourced",
"from",
"a",
"remote",
"server",
"and",
"copies",
"it",
"to",
"the",
"local",
"cache"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/image.go#L120-L166 |
155,453 | juju/juju | container/lxd/image.go | seriesRemoteAliases | func seriesRemoteAliases(series, arch string) ([]string, error) {
seriesOS, err := jujuseries.GetOSFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
switch seriesOS {
case jujuos.Ubuntu:
return []string{path.Join(series, arch)}, nil
case jujuos.CentOS:
if series == "centos7" && arch == jujuarch.AMD64 {
return []string{"centos/7/amd64"}, nil
}
case jujuos.OpenSUSE:
if series == "opensuseleap" && arch == jujuarch.AMD64 {
return []string{"opensuse/42.2/amd64"}, nil
}
}
return nil, errors.NotSupportedf("series %q", series)
} | go | func seriesRemoteAliases(series, arch string) ([]string, error) {
seriesOS, err := jujuseries.GetOSFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
switch seriesOS {
case jujuos.Ubuntu:
return []string{path.Join(series, arch)}, nil
case jujuos.CentOS:
if series == "centos7" && arch == jujuarch.AMD64 {
return []string{"centos/7/amd64"}, nil
}
case jujuos.OpenSUSE:
if series == "opensuseleap" && arch == jujuarch.AMD64 {
return []string{"opensuse/42.2/amd64"}, nil
}
}
return nil, errors.NotSupportedf("series %q", series)
} | [
"func",
"seriesRemoteAliases",
"(",
"series",
",",
"arch",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"seriesOS",
",",
"err",
":=",
"jujuseries",
".",
"GetOSFromSeries",
"(",
"series",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"switch",
"seriesOS",
"{",
"case",
"jujuos",
".",
"Ubuntu",
":",
"return",
"[",
"]",
"string",
"{",
"path",
".",
"Join",
"(",
"series",
",",
"arch",
")",
"}",
",",
"nil",
"\n",
"case",
"jujuos",
".",
"CentOS",
":",
"if",
"series",
"==",
"\"",
"\"",
"&&",
"arch",
"==",
"jujuarch",
".",
"AMD64",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
"\n",
"}",
"\n",
"case",
"jujuos",
".",
"OpenSUSE",
":",
"if",
"series",
"==",
"\"",
"\"",
"&&",
"arch",
"==",
"jujuarch",
".",
"AMD64",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"series",
")",
"\n",
"}"
] | // seriesRemoteAliases returns the aliases to look for in remotes. | [
"seriesRemoteAliases",
"returns",
"the",
"aliases",
"to",
"look",
"for",
"in",
"remotes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/image.go#L176-L194 |
155,454 | juju/juju | apiserver/facades/agent/machineactions/machineactions.go | NewFacade | func NewFacade(
backend Backend,
resources facade.Resources,
authorizer facade.Authorizer,
) (*Facade, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
return &Facade{
backend: backend,
resources: resources,
accessMachine: authorizer.AuthOwner,
}, nil
} | go | func NewFacade(
backend Backend,
resources facade.Resources,
authorizer facade.Authorizer,
) (*Facade, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
return &Facade{
backend: backend,
resources: resources,
accessMachine: authorizer.AuthOwner,
}, nil
} | [
"func",
"NewFacade",
"(",
"backend",
"Backend",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
")",
"(",
"*",
"Facade",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthMachineAgent",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"Facade",
"{",
"backend",
":",
"backend",
",",
"resources",
":",
"resources",
",",
"accessMachine",
":",
"authorizer",
".",
"AuthOwner",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacade creates a new server-side machineactions API end point. | [
"NewFacade",
"creates",
"a",
"new",
"server",
"-",
"side",
"machineactions",
"API",
"end",
"point",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machineactions/machineactions.go#L34-L47 |
155,455 | juju/juju | apiserver/facades/agent/machineactions/machineactions.go | Actions | func (f *Facade) Actions(args params.Entities) params.ActionResults {
actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
return common.Actions(args, actionFn)
} | go | func (f *Facade) Actions(args params.Entities) params.ActionResults {
actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
return common.Actions(args, actionFn)
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"Actions",
"(",
"args",
"params",
".",
"Entities",
")",
"params",
".",
"ActionResults",
"{",
"actionFn",
":=",
"common",
".",
"AuthAndActionFromTagFn",
"(",
"f",
".",
"accessMachine",
",",
"f",
".",
"backend",
".",
"ActionByTag",
")",
"\n",
"return",
"common",
".",
"Actions",
"(",
"args",
",",
"actionFn",
")",
"\n",
"}"
] | // Actions returns the Actions by Tags passed and ensures that the machine asking
// for them is the machine that has the actions | [
"Actions",
"returns",
"the",
"Actions",
"by",
"Tags",
"passed",
"and",
"ensures",
"that",
"the",
"machine",
"asking",
"for",
"them",
"is",
"the",
"machine",
"that",
"has",
"the",
"actions"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machineactions/machineactions.go#L51-L54 |
155,456 | juju/juju | apiserver/facades/agent/machineactions/machineactions.go | BeginActions | func (f *Facade) BeginActions(args params.Entities) params.ErrorResults {
actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
return common.BeginActions(args, actionFn)
} | go | func (f *Facade) BeginActions(args params.Entities) params.ErrorResults {
actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
return common.BeginActions(args, actionFn)
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"BeginActions",
"(",
"args",
"params",
".",
"Entities",
")",
"params",
".",
"ErrorResults",
"{",
"actionFn",
":=",
"common",
".",
"AuthAndActionFromTagFn",
"(",
"f",
".",
"accessMachine",
",",
"f",
".",
"backend",
".",
"ActionByTag",
")",
"\n",
"return",
"common",
".",
"BeginActions",
"(",
"args",
",",
"actionFn",
")",
"\n",
"}"
] | // BeginActions marks the actions represented by the passed in Tags as running. | [
"BeginActions",
"marks",
"the",
"actions",
"represented",
"by",
"the",
"passed",
"in",
"Tags",
"as",
"running",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machineactions/machineactions.go#L57-L60 |
155,457 | juju/juju | apiserver/facades/agent/machineactions/machineactions.go | FinishActions | func (f *Facade) FinishActions(args params.ActionExecutionResults) params.ErrorResults {
actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
return common.FinishActions(args, actionFn)
} | go | func (f *Facade) FinishActions(args params.ActionExecutionResults) params.ErrorResults {
actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
return common.FinishActions(args, actionFn)
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"FinishActions",
"(",
"args",
"params",
".",
"ActionExecutionResults",
")",
"params",
".",
"ErrorResults",
"{",
"actionFn",
":=",
"common",
".",
"AuthAndActionFromTagFn",
"(",
"f",
".",
"accessMachine",
",",
"f",
".",
"backend",
".",
"ActionByTag",
")",
"\n",
"return",
"common",
".",
"FinishActions",
"(",
"args",
",",
"actionFn",
")",
"\n",
"}"
] | // FinishActions saves the result of a completed Action | [
"FinishActions",
"saves",
"the",
"result",
"of",
"a",
"completed",
"Action"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machineactions/machineactions.go#L63-L66 |
155,458 | juju/juju | apiserver/facades/agent/machineactions/machineactions.go | WatchActionNotifications | func (f *Facade) WatchActionNotifications(args params.Entities) params.StringsWatchResults {
tagToActionReceiver := f.backend.TagToActionReceiverFn(f.backend.FindEntity)
watchOne := common.WatchOneActionReceiverNotifications(tagToActionReceiver, f.resources.Register)
return common.WatchActionNotifications(args, f.accessMachine, watchOne)
} | go | func (f *Facade) WatchActionNotifications(args params.Entities) params.StringsWatchResults {
tagToActionReceiver := f.backend.TagToActionReceiverFn(f.backend.FindEntity)
watchOne := common.WatchOneActionReceiverNotifications(tagToActionReceiver, f.resources.Register)
return common.WatchActionNotifications(args, f.accessMachine, watchOne)
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"WatchActionNotifications",
"(",
"args",
"params",
".",
"Entities",
")",
"params",
".",
"StringsWatchResults",
"{",
"tagToActionReceiver",
":=",
"f",
".",
"backend",
".",
"TagToActionReceiverFn",
"(",
"f",
".",
"backend",
".",
"FindEntity",
")",
"\n",
"watchOne",
":=",
"common",
".",
"WatchOneActionReceiverNotifications",
"(",
"tagToActionReceiver",
",",
"f",
".",
"resources",
".",
"Register",
")",
"\n",
"return",
"common",
".",
"WatchActionNotifications",
"(",
"args",
",",
"f",
".",
"accessMachine",
",",
"watchOne",
")",
"\n",
"}"
] | // WatchActionNotifications returns a StringsWatcher for observing
// incoming action calls to a machine. | [
"WatchActionNotifications",
"returns",
"a",
"StringsWatcher",
"for",
"observing",
"incoming",
"action",
"calls",
"to",
"a",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machineactions/machineactions.go#L70-L74 |
155,459 | juju/juju | network/containerizer/shim.go | ParentDevice | func (l *linkLayerDevice) ParentDevice() (LinkLayerDevice, error) {
dev, err := l.LinkLayerDevice.ParentDevice()
if err != nil {
return nil, errors.Trace(err)
}
return &linkLayerDevice{dev}, nil
} | go | func (l *linkLayerDevice) ParentDevice() (LinkLayerDevice, error) {
dev, err := l.LinkLayerDevice.ParentDevice()
if err != nil {
return nil, errors.Trace(err)
}
return &linkLayerDevice{dev}, nil
} | [
"func",
"(",
"l",
"*",
"linkLayerDevice",
")",
"ParentDevice",
"(",
")",
"(",
"LinkLayerDevice",
",",
"error",
")",
"{",
"dev",
",",
"err",
":=",
"l",
".",
"LinkLayerDevice",
".",
"ParentDevice",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"linkLayerDevice",
"{",
"dev",
"}",
",",
"nil",
"\n",
"}"
] | // ParentDevice implements LinkLayerDevice by wrapping the response from the
// inner device's call in a new instance of linkLayerDevice. | [
"ParentDevice",
"implements",
"LinkLayerDevice",
"by",
"wrapping",
"the",
"response",
"from",
"the",
"inner",
"device",
"s",
"call",
"in",
"a",
"new",
"instance",
"of",
"linkLayerDevice",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/containerizer/shim.go#L43-L49 |
155,460 | juju/juju | network/containerizer/shim.go | LinkLayerDevicesForSpaces | func (m *MachineShim) LinkLayerDevicesForSpaces(spaces []string) (map[string][]LinkLayerDevice, error) {
spaceDevs, err := m.Machine.LinkLayerDevicesForSpaces(spaces)
if err != nil {
return nil, errors.Trace(err)
}
wrapped := make(map[string][]LinkLayerDevice, len(spaceDevs))
for space, devs := range spaceDevs {
wrappedDevs := make([]LinkLayerDevice, len(devs))
for i, d := range devs {
wrappedDevs[i] = &linkLayerDevice{d}
}
wrapped[space] = wrappedDevs
}
return wrapped, nil
} | go | func (m *MachineShim) LinkLayerDevicesForSpaces(spaces []string) (map[string][]LinkLayerDevice, error) {
spaceDevs, err := m.Machine.LinkLayerDevicesForSpaces(spaces)
if err != nil {
return nil, errors.Trace(err)
}
wrapped := make(map[string][]LinkLayerDevice, len(spaceDevs))
for space, devs := range spaceDevs {
wrappedDevs := make([]LinkLayerDevice, len(devs))
for i, d := range devs {
wrappedDevs[i] = &linkLayerDevice{d}
}
wrapped[space] = wrappedDevs
}
return wrapped, nil
} | [
"func",
"(",
"m",
"*",
"MachineShim",
")",
"LinkLayerDevicesForSpaces",
"(",
"spaces",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"LinkLayerDevice",
",",
"error",
")",
"{",
"spaceDevs",
",",
"err",
":=",
"m",
".",
"Machine",
".",
"LinkLayerDevicesForSpaces",
"(",
"spaces",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"wrapped",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"LinkLayerDevice",
",",
"len",
"(",
"spaceDevs",
")",
")",
"\n",
"for",
"space",
",",
"devs",
":=",
"range",
"spaceDevs",
"{",
"wrappedDevs",
":=",
"make",
"(",
"[",
"]",
"LinkLayerDevice",
",",
"len",
"(",
"devs",
")",
")",
"\n",
"for",
"i",
",",
"d",
":=",
"range",
"devs",
"{",
"wrappedDevs",
"[",
"i",
"]",
"=",
"&",
"linkLayerDevice",
"{",
"d",
"}",
"\n",
"}",
"\n",
"wrapped",
"[",
"space",
"]",
"=",
"wrappedDevs",
"\n",
"}",
"\n",
"return",
"wrapped",
",",
"nil",
"\n",
"}"
] | // LinkLayerDevicesForSpaces implements Machine by unwrapping the inner
// state.Machine call and wrapping the raw state.LinkLayerDevice references
// with the local LinkLayerDevice implementation. | [
"LinkLayerDevicesForSpaces",
"implements",
"Machine",
"by",
"unwrapping",
"the",
"inner",
"state",
".",
"Machine",
"call",
"and",
"wrapping",
"the",
"raw",
"state",
".",
"LinkLayerDevice",
"references",
"with",
"the",
"local",
"LinkLayerDevice",
"implementation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/containerizer/shim.go#L84-L99 |
155,461 | juju/juju | network/containerizer/shim.go | AllLinkLayerDevices | func (m *MachineShim) AllLinkLayerDevices() ([]LinkLayerDevice, error) {
devs, err := m.Machine.AllLinkLayerDevices()
if err != nil {
return nil, errors.Trace(err)
}
wrapped := make([]LinkLayerDevice, len(devs))
for i, d := range devs {
wrapped[i] = &linkLayerDevice{d}
}
return wrapped, nil
} | go | func (m *MachineShim) AllLinkLayerDevices() ([]LinkLayerDevice, error) {
devs, err := m.Machine.AllLinkLayerDevices()
if err != nil {
return nil, errors.Trace(err)
}
wrapped := make([]LinkLayerDevice, len(devs))
for i, d := range devs {
wrapped[i] = &linkLayerDevice{d}
}
return wrapped, nil
} | [
"func",
"(",
"m",
"*",
"MachineShim",
")",
"AllLinkLayerDevices",
"(",
")",
"(",
"[",
"]",
"LinkLayerDevice",
",",
"error",
")",
"{",
"devs",
",",
"err",
":=",
"m",
".",
"Machine",
".",
"AllLinkLayerDevices",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"wrapped",
":=",
"make",
"(",
"[",
"]",
"LinkLayerDevice",
",",
"len",
"(",
"devs",
")",
")",
"\n",
"for",
"i",
",",
"d",
":=",
"range",
"devs",
"{",
"wrapped",
"[",
"i",
"]",
"=",
"&",
"linkLayerDevice",
"{",
"d",
"}",
"\n",
"}",
"\n",
"return",
"wrapped",
",",
"nil",
"\n",
"}"
] | // AllLinkLayerDevices implements Machine by wrapping each
// state.LinkLayerDevice reference in returned collection with the local
// LinkLayerDevice implementation. | [
"AllLinkLayerDevices",
"implements",
"Machine",
"by",
"wrapping",
"each",
"state",
".",
"LinkLayerDevice",
"reference",
"in",
"returned",
"collection",
"with",
"the",
"local",
"LinkLayerDevice",
"implementation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/containerizer/shim.go#L104-L115 |
155,462 | juju/juju | worker/uniter/runner/context/context.go | RegisterComponentFunc | func RegisterComponentFunc(name string, f ComponentFunc) error {
if _, ok := registeredComponentFuncs[name]; ok {
return errors.AlreadyExistsf("%s", name)
}
registeredComponentFuncs[name] = f
return nil
} | go | func RegisterComponentFunc(name string, f ComponentFunc) error {
if _, ok := registeredComponentFuncs[name]; ok {
return errors.AlreadyExistsf("%s", name)
}
registeredComponentFuncs[name] = f
return nil
} | [
"func",
"RegisterComponentFunc",
"(",
"name",
"string",
",",
"f",
"ComponentFunc",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"registeredComponentFuncs",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"errors",
".",
"AlreadyExistsf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"registeredComponentFuncs",
"[",
"name",
"]",
"=",
"f",
"\n",
"return",
"nil",
"\n",
"}"
] | // Add the named component factory func to the registry. | [
"Add",
"the",
"named",
"component",
"factory",
"func",
"to",
"the",
"registry",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L84-L90 |
155,463 | juju/juju | worker/uniter/runner/context/context.go | Component | func (ctx *HookContext) Component(name string) (jujuc.ContextComponent, error) {
compCtxFunc, ok := ctx.componentFuncs[name]
if !ok {
return nil, errors.NotFoundf("context component %q", name)
}
facade := ctx.state.Facade()
config := ComponentConfig{
UnitName: ctx.unit.Name(),
DataDir: ctx.componentDir(name),
APICaller: facade.RawAPICaller(),
}
compCtx, err := compCtxFunc(config)
if err != nil {
return nil, errors.Trace(err)
}
return compCtx, nil
} | go | func (ctx *HookContext) Component(name string) (jujuc.ContextComponent, error) {
compCtxFunc, ok := ctx.componentFuncs[name]
if !ok {
return nil, errors.NotFoundf("context component %q", name)
}
facade := ctx.state.Facade()
config := ComponentConfig{
UnitName: ctx.unit.Name(),
DataDir: ctx.componentDir(name),
APICaller: facade.RawAPICaller(),
}
compCtx, err := compCtxFunc(config)
if err != nil {
return nil, errors.Trace(err)
}
return compCtx, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"Component",
"(",
"name",
"string",
")",
"(",
"jujuc",
".",
"ContextComponent",
",",
"error",
")",
"{",
"compCtxFunc",
",",
"ok",
":=",
"ctx",
".",
"componentFuncs",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"facade",
":=",
"ctx",
".",
"state",
".",
"Facade",
"(",
")",
"\n",
"config",
":=",
"ComponentConfig",
"{",
"UnitName",
":",
"ctx",
".",
"unit",
".",
"Name",
"(",
")",
",",
"DataDir",
":",
"ctx",
".",
"componentDir",
"(",
"name",
")",
",",
"APICaller",
":",
"facade",
".",
"RawAPICaller",
"(",
")",
",",
"}",
"\n",
"compCtx",
",",
"err",
":=",
"compCtxFunc",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"compCtx",
",",
"nil",
"\n",
"}"
] | // Component implements hooks.Context. | [
"Component",
"implements",
"hooks",
".",
"Context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L240-L257 |
155,464 | juju/juju | worker/uniter/runner/context/context.go | UnitStatus | func (ctx *HookContext) UnitStatus() (*jujuc.StatusInfo, error) {
if ctx.status == nil {
var err error
status, err := ctx.unit.UnitStatus()
if err != nil {
return nil, err
}
ctx.status = &jujuc.StatusInfo{
Status: status.Status,
Info: status.Info,
Data: status.Data,
}
}
return ctx.status, nil
} | go | func (ctx *HookContext) UnitStatus() (*jujuc.StatusInfo, error) {
if ctx.status == nil {
var err error
status, err := ctx.unit.UnitStatus()
if err != nil {
return nil, err
}
ctx.status = &jujuc.StatusInfo{
Status: status.Status,
Info: status.Info,
Data: status.Data,
}
}
return ctx.status, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"UnitStatus",
"(",
")",
"(",
"*",
"jujuc",
".",
"StatusInfo",
",",
"error",
")",
"{",
"if",
"ctx",
".",
"status",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n",
"status",
",",
"err",
":=",
"ctx",
".",
"unit",
".",
"UnitStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ctx",
".",
"status",
"=",
"&",
"jujuc",
".",
"StatusInfo",
"{",
"Status",
":",
"status",
".",
"Status",
",",
"Info",
":",
"status",
".",
"Info",
",",
"Data",
":",
"status",
".",
"Data",
",",
"}",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"status",
",",
"nil",
"\n",
"}"
] | // UnitStatus will return the status for the current Unit. | [
"UnitStatus",
"will",
"return",
"the",
"status",
"for",
"the",
"current",
"Unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L313-L327 |
155,465 | juju/juju | worker/uniter/runner/context/context.go | ApplicationStatus | func (ctx *HookContext) ApplicationStatus() (jujuc.ApplicationStatusInfo, error) {
var err error
isLeader, err := ctx.IsLeader()
if err != nil {
return jujuc.ApplicationStatusInfo{}, errors.Annotatef(err, "cannot determine leadership")
}
if !isLeader {
return jujuc.ApplicationStatusInfo{}, ErrIsNotLeader
}
application, err := ctx.unit.Application()
if err != nil {
return jujuc.ApplicationStatusInfo{}, errors.Trace(err)
}
status, err := application.Status(ctx.unit.Name())
if err != nil {
return jujuc.ApplicationStatusInfo{}, errors.Trace(err)
}
us := make([]jujuc.StatusInfo, len(status.Units))
i := 0
for t, s := range status.Units {
us[i] = jujuc.StatusInfo{
Tag: t,
Status: s.Status,
Info: s.Info,
Data: s.Data,
}
i++
}
return jujuc.ApplicationStatusInfo{
Application: jujuc.StatusInfo{
Tag: application.Tag().String(),
Status: status.Application.Status,
Info: status.Application.Info,
Data: status.Application.Data,
},
Units: us,
}, nil
} | go | func (ctx *HookContext) ApplicationStatus() (jujuc.ApplicationStatusInfo, error) {
var err error
isLeader, err := ctx.IsLeader()
if err != nil {
return jujuc.ApplicationStatusInfo{}, errors.Annotatef(err, "cannot determine leadership")
}
if !isLeader {
return jujuc.ApplicationStatusInfo{}, ErrIsNotLeader
}
application, err := ctx.unit.Application()
if err != nil {
return jujuc.ApplicationStatusInfo{}, errors.Trace(err)
}
status, err := application.Status(ctx.unit.Name())
if err != nil {
return jujuc.ApplicationStatusInfo{}, errors.Trace(err)
}
us := make([]jujuc.StatusInfo, len(status.Units))
i := 0
for t, s := range status.Units {
us[i] = jujuc.StatusInfo{
Tag: t,
Status: s.Status,
Info: s.Info,
Data: s.Data,
}
i++
}
return jujuc.ApplicationStatusInfo{
Application: jujuc.StatusInfo{
Tag: application.Tag().String(),
Status: status.Application.Status,
Info: status.Application.Info,
Data: status.Application.Data,
},
Units: us,
}, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"ApplicationStatus",
"(",
")",
"(",
"jujuc",
".",
"ApplicationStatusInfo",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"isLeader",
",",
"err",
":=",
"ctx",
".",
"IsLeader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jujuc",
".",
"ApplicationStatusInfo",
"{",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"isLeader",
"{",
"return",
"jujuc",
".",
"ApplicationStatusInfo",
"{",
"}",
",",
"ErrIsNotLeader",
"\n",
"}",
"\n",
"application",
",",
"err",
":=",
"ctx",
".",
"unit",
".",
"Application",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jujuc",
".",
"ApplicationStatusInfo",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"status",
",",
"err",
":=",
"application",
".",
"Status",
"(",
"ctx",
".",
"unit",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jujuc",
".",
"ApplicationStatusInfo",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"us",
":=",
"make",
"(",
"[",
"]",
"jujuc",
".",
"StatusInfo",
",",
"len",
"(",
"status",
".",
"Units",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"t",
",",
"s",
":=",
"range",
"status",
".",
"Units",
"{",
"us",
"[",
"i",
"]",
"=",
"jujuc",
".",
"StatusInfo",
"{",
"Tag",
":",
"t",
",",
"Status",
":",
"s",
".",
"Status",
",",
"Info",
":",
"s",
".",
"Info",
",",
"Data",
":",
"s",
".",
"Data",
",",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"return",
"jujuc",
".",
"ApplicationStatusInfo",
"{",
"Application",
":",
"jujuc",
".",
"StatusInfo",
"{",
"Tag",
":",
"application",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
",",
"Status",
":",
"status",
".",
"Application",
".",
"Status",
",",
"Info",
":",
"status",
".",
"Application",
".",
"Info",
",",
"Data",
":",
"status",
".",
"Application",
".",
"Data",
",",
"}",
",",
"Units",
":",
"us",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ApplicationStatus returns the status for the application and all the units on
// the application to which this context unit belongs, only if this unit is
// the leader. | [
"ApplicationStatus",
"returns",
"the",
"status",
"for",
"the",
"application",
"and",
"all",
"the",
"units",
"on",
"the",
"application",
"to",
"which",
"this",
"context",
"unit",
"belongs",
"only",
"if",
"this",
"unit",
"is",
"the",
"leader",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L332-L369 |
155,466 | juju/juju | worker/uniter/runner/context/context.go | SetUnitStatus | func (ctx *HookContext) SetUnitStatus(unitStatus jujuc.StatusInfo) error {
ctx.hasRunStatusSet = true
logger.Tracef("[WORKLOAD-STATUS] %s: %s", unitStatus.Status, unitStatus.Info)
return ctx.unit.SetUnitStatus(
status.Status(unitStatus.Status),
unitStatus.Info,
unitStatus.Data,
)
} | go | func (ctx *HookContext) SetUnitStatus(unitStatus jujuc.StatusInfo) error {
ctx.hasRunStatusSet = true
logger.Tracef("[WORKLOAD-STATUS] %s: %s", unitStatus.Status, unitStatus.Info)
return ctx.unit.SetUnitStatus(
status.Status(unitStatus.Status),
unitStatus.Info,
unitStatus.Data,
)
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"SetUnitStatus",
"(",
"unitStatus",
"jujuc",
".",
"StatusInfo",
")",
"error",
"{",
"ctx",
".",
"hasRunStatusSet",
"=",
"true",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"unitStatus",
".",
"Status",
",",
"unitStatus",
".",
"Info",
")",
"\n",
"return",
"ctx",
".",
"unit",
".",
"SetUnitStatus",
"(",
"status",
".",
"Status",
"(",
"unitStatus",
".",
"Status",
")",
",",
"unitStatus",
".",
"Info",
",",
"unitStatus",
".",
"Data",
",",
")",
"\n",
"}"
] | // SetUnitStatus will set the given status for this unit. | [
"SetUnitStatus",
"will",
"set",
"the",
"given",
"status",
"for",
"this",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L372-L380 |
155,467 | juju/juju | worker/uniter/runner/context/context.go | SetApplicationStatus | func (ctx *HookContext) SetApplicationStatus(applicationStatus jujuc.StatusInfo) error {
logger.Tracef("[APPLICATION-STATUS] %s: %s", applicationStatus.Status, applicationStatus.Info)
isLeader, err := ctx.IsLeader()
if err != nil {
return errors.Annotatef(err, "cannot determine leadership")
}
if !isLeader {
return ErrIsNotLeader
}
application, err := ctx.unit.Application()
if err != nil {
return errors.Trace(err)
}
return application.SetStatus(
ctx.unit.Name(),
status.Status(applicationStatus.Status),
applicationStatus.Info,
applicationStatus.Data,
)
} | go | func (ctx *HookContext) SetApplicationStatus(applicationStatus jujuc.StatusInfo) error {
logger.Tracef("[APPLICATION-STATUS] %s: %s", applicationStatus.Status, applicationStatus.Info)
isLeader, err := ctx.IsLeader()
if err != nil {
return errors.Annotatef(err, "cannot determine leadership")
}
if !isLeader {
return ErrIsNotLeader
}
application, err := ctx.unit.Application()
if err != nil {
return errors.Trace(err)
}
return application.SetStatus(
ctx.unit.Name(),
status.Status(applicationStatus.Status),
applicationStatus.Info,
applicationStatus.Data,
)
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"SetApplicationStatus",
"(",
"applicationStatus",
"jujuc",
".",
"StatusInfo",
")",
"error",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"applicationStatus",
".",
"Status",
",",
"applicationStatus",
".",
"Info",
")",
"\n",
"isLeader",
",",
"err",
":=",
"ctx",
".",
"IsLeader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"isLeader",
"{",
"return",
"ErrIsNotLeader",
"\n",
"}",
"\n\n",
"application",
",",
"err",
":=",
"ctx",
".",
"unit",
".",
"Application",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"application",
".",
"SetStatus",
"(",
"ctx",
".",
"unit",
".",
"Name",
"(",
")",
",",
"status",
".",
"Status",
"(",
"applicationStatus",
".",
"Status",
")",
",",
"applicationStatus",
".",
"Info",
",",
"applicationStatus",
".",
"Data",
",",
")",
"\n",
"}"
] | // SetApplicationStatus will set the given status to the application to which this
// unit's belong, only if this unit is the leader. | [
"SetApplicationStatus",
"will",
"set",
"the",
"given",
"status",
"to",
"the",
"application",
"to",
"which",
"this",
"unit",
"s",
"belong",
"only",
"if",
"this",
"unit",
"is",
"the",
"leader",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L384-L404 |
155,468 | juju/juju | worker/uniter/runner/context/context.go | CloudSpec | func (ctx *HookContext) CloudSpec() (*params.CloudSpec, error) {
var err error
ctx.cloudSpec, err = ctx.state.CloudSpec()
if err != nil {
return nil, err
}
return ctx.cloudSpec, nil
} | go | func (ctx *HookContext) CloudSpec() (*params.CloudSpec, error) {
var err error
ctx.cloudSpec, err = ctx.state.CloudSpec()
if err != nil {
return nil, err
}
return ctx.cloudSpec, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"CloudSpec",
"(",
")",
"(",
"*",
"params",
".",
"CloudSpec",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"ctx",
".",
"cloudSpec",
",",
"err",
"=",
"ctx",
".",
"state",
".",
"CloudSpec",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"cloudSpec",
",",
"nil",
"\n",
"}"
] | // CloudSpec return the cloud specification for the running unit's model | [
"CloudSpec",
"return",
"the",
"cloud",
"specification",
"for",
"the",
"running",
"unit",
"s",
"model"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L539-L546 |
155,469 | juju/juju | worker/uniter/runner/context/context.go | ActionName | func (ctx *HookContext) ActionName() (string, error) {
if ctx.actionData == nil {
return "", errors.New("not running an action")
}
return ctx.actionData.Name, nil
} | go | func (ctx *HookContext) ActionName() (string, error) {
if ctx.actionData == nil {
return "", errors.New("not running an action")
}
return ctx.actionData.Name, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"ActionName",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"ctx",
".",
"actionData",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"actionData",
".",
"Name",
",",
"nil",
"\n",
"}"
] | // ActionName returns the name of the action. | [
"ActionName",
"returns",
"the",
"name",
"of",
"the",
"action",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L549-L554 |
155,470 | juju/juju | worker/uniter/runner/context/context.go | ActionParams | func (ctx *HookContext) ActionParams() (map[string]interface{}, error) {
if ctx.actionData == nil {
return nil, errors.New("not running an action")
}
return ctx.actionData.Params, nil
} | go | func (ctx *HookContext) ActionParams() (map[string]interface{}, error) {
if ctx.actionData == nil {
return nil, errors.New("not running an action")
}
return ctx.actionData.Params, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"ActionParams",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"ctx",
".",
"actionData",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"actionData",
".",
"Params",
",",
"nil",
"\n",
"}"
] | // ActionParams simply returns the arguments to the Action. | [
"ActionParams",
"simply",
"returns",
"the",
"arguments",
"to",
"the",
"Action",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L557-L562 |
155,471 | juju/juju | worker/uniter/runner/context/context.go | SetActionMessage | func (ctx *HookContext) SetActionMessage(message string) error {
if ctx.actionData == nil {
return errors.New("not running an action")
}
ctx.actionData.ResultsMessage = message
return nil
} | go | func (ctx *HookContext) SetActionMessage(message string) error {
if ctx.actionData == nil {
return errors.New("not running an action")
}
ctx.actionData.ResultsMessage = message
return nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"SetActionMessage",
"(",
"message",
"string",
")",
"error",
"{",
"if",
"ctx",
".",
"actionData",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
".",
"actionData",
".",
"ResultsMessage",
"=",
"message",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetActionMessage sets a message for the Action, usually an error message. | [
"SetActionMessage",
"sets",
"a",
"message",
"for",
"the",
"Action",
"usually",
"an",
"error",
"message",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L565-L571 |
155,472 | juju/juju | worker/uniter/runner/context/context.go | SetActionFailed | func (ctx *HookContext) SetActionFailed() error {
if ctx.actionData == nil {
return errors.New("not running an action")
}
ctx.actionData.Failed = true
return nil
} | go | func (ctx *HookContext) SetActionFailed() error {
if ctx.actionData == nil {
return errors.New("not running an action")
}
ctx.actionData.Failed = true
return nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"SetActionFailed",
"(",
")",
"error",
"{",
"if",
"ctx",
".",
"actionData",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctx",
".",
"actionData",
".",
"Failed",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetActionFailed sets the fail state of the action. | [
"SetActionFailed",
"sets",
"the",
"fail",
"state",
"of",
"the",
"action",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L574-L580 |
155,473 | juju/juju | worker/uniter/runner/context/context.go | UpdateActionResults | func (ctx *HookContext) UpdateActionResults(keys []string, value string) error {
if ctx.actionData == nil {
return errors.New("not running an action")
}
addValueToMap(keys, value, ctx.actionData.ResultsMap)
return nil
} | go | func (ctx *HookContext) UpdateActionResults(keys []string, value string) error {
if ctx.actionData == nil {
return errors.New("not running an action")
}
addValueToMap(keys, value, ctx.actionData.ResultsMap)
return nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"UpdateActionResults",
"(",
"keys",
"[",
"]",
"string",
",",
"value",
"string",
")",
"error",
"{",
"if",
"ctx",
".",
"actionData",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"addValueToMap",
"(",
"keys",
",",
"value",
",",
"ctx",
".",
"actionData",
".",
"ResultsMap",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UpdateActionResults inserts new values for use with action-set and
// action-fail. The results struct will be delivered to the controller
// upon completion of the Action. It returns an error if not called on an
// Action-containing HookContext. | [
"UpdateActionResults",
"inserts",
"new",
"values",
"for",
"use",
"with",
"action",
"-",
"set",
"and",
"action",
"-",
"fail",
".",
"The",
"results",
"struct",
"will",
"be",
"delivered",
"to",
"the",
"controller",
"upon",
"completion",
"of",
"the",
"Action",
".",
"It",
"returns",
"an",
"error",
"if",
"not",
"called",
"on",
"an",
"Action",
"-",
"containing",
"HookContext",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L586-L592 |
155,474 | juju/juju | worker/uniter/runner/context/context.go | AddMetric | func (ctx *HookContext) AddMetric(key, value string, created time.Time) error {
return errors.New("metrics not allowed in this context")
} | go | func (ctx *HookContext) AddMetric(key, value string, created time.Time) error {
return errors.New("metrics not allowed in this context")
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"AddMetric",
"(",
"key",
",",
"value",
"string",
",",
"created",
"time",
".",
"Time",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // AddMetric adds metrics to the hook context. | [
"AddMetric",
"adds",
"metrics",
"to",
"the",
"hook",
"context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L622-L624 |
155,475 | juju/juju | worker/uniter/runner/context/context.go | AddMetricLabels | func (ctx *HookContext) AddMetricLabels(key, value string, created time.Time, labels map[string]string) error {
return errors.New("metrics not allowed in this context")
} | go | func (ctx *HookContext) AddMetricLabels(key, value string, created time.Time, labels map[string]string) error {
return errors.New("metrics not allowed in this context")
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"AddMetricLabels",
"(",
"key",
",",
"value",
"string",
",",
"created",
"time",
".",
"Time",
",",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // AddMetricLabels adds metrics with labels to the hook context. | [
"AddMetricLabels",
"adds",
"metrics",
"with",
"labels",
"to",
"the",
"hook",
"context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L627-L629 |
155,476 | juju/juju | worker/uniter/runner/context/context.go | ActionData | func (c *HookContext) ActionData() (*ActionData, error) {
if c.actionData == nil {
return nil, errors.New("not running an action")
}
return c.actionData, nil
} | go | func (c *HookContext) ActionData() (*ActionData, error) {
if c.actionData == nil {
return nil, errors.New("not running an action")
}
return c.actionData, nil
} | [
"func",
"(",
"c",
"*",
"HookContext",
")",
"ActionData",
"(",
")",
"(",
"*",
"ActionData",
",",
"error",
")",
"{",
"if",
"c",
".",
"actionData",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"actionData",
",",
"nil",
"\n",
"}"
] | // ActionData returns the context's internal action data. It's meant to be
// transitory; it exists to allow uniter and runner code to keep working as
// it did; it should be considered deprecated, and not used by new clients. | [
"ActionData",
"returns",
"the",
"context",
"s",
"internal",
"action",
"data",
".",
"It",
"s",
"meant",
"to",
"be",
"transitory",
";",
"it",
"exists",
"to",
"allow",
"uniter",
"and",
"runner",
"code",
"to",
"keep",
"working",
"as",
"it",
"did",
";",
"it",
"should",
"be",
"considered",
"deprecated",
"and",
"not",
"used",
"by",
"new",
"clients",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L634-L639 |
155,477 | juju/juju | worker/uniter/runner/context/context.go | HookVars | func (context *HookContext) HookVars(paths Paths) ([]string, error) {
vars := context.legacyProxySettings.AsEnvironmentValues()
// TODO(thumper): as work on proxies progress, there will be additional
// proxy settings to be added.
vars = append(vars,
"CHARM_DIR="+paths.GetCharmDir(), // legacy, embarrassing
"JUJU_CHARM_DIR="+paths.GetCharmDir(),
"JUJU_CONTEXT_ID="+context.id,
"JUJU_AGENT_SOCKET="+paths.GetJujucSocket(),
"JUJU_UNIT_NAME="+context.unitName,
"JUJU_MODEL_UUID="+context.uuid,
"JUJU_MODEL_NAME="+context.modelName,
"JUJU_API_ADDRESSES="+strings.Join(context.apiAddrs, " "),
"JUJU_SLA="+context.slaLevel,
"JUJU_MACHINE_ID="+context.assignedMachineTag.Id(),
"JUJU_PRINCIPAL_UNIT="+context.principal,
"JUJU_AVAILABILITY_ZONE="+context.availabilityzone,
"JUJU_VERSION="+version.Current.String(),
"CLOUD_API_VERSION="+context.cloudAPIVersion,
// Some of these will be empty, but that is fine, better
// to explicitly export them as empty.
"JUJU_CHARM_HTTP_PROXY="+context.jujuProxySettings.Http,
"JUJU_CHARM_HTTPS_PROXY="+context.jujuProxySettings.Https,
"JUJU_CHARM_FTP_PROXY="+context.jujuProxySettings.Ftp,
"JUJU_CHARM_NO_PROXY="+context.jujuProxySettings.NoProxy,
)
if context.meterStatus != nil {
vars = append(vars,
"JUJU_METER_STATUS="+context.meterStatus.code,
"JUJU_METER_INFO="+context.meterStatus.info,
)
}
if r, err := context.HookRelation(); err == nil {
vars = append(vars,
"JUJU_RELATION="+r.Name(),
"JUJU_RELATION_ID="+r.FakeId(),
"JUJU_REMOTE_UNIT="+context.remoteUnitName,
)
} else if !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
if context.actionData != nil {
vars = append(vars,
"JUJU_ACTION_NAME="+context.actionData.Name,
"JUJU_ACTION_UUID="+context.actionData.Tag.Id(),
"JUJU_ACTION_TAG="+context.actionData.Tag.String(),
)
}
return append(vars, OSDependentEnvVars(paths)...), nil
} | go | func (context *HookContext) HookVars(paths Paths) ([]string, error) {
vars := context.legacyProxySettings.AsEnvironmentValues()
// TODO(thumper): as work on proxies progress, there will be additional
// proxy settings to be added.
vars = append(vars,
"CHARM_DIR="+paths.GetCharmDir(), // legacy, embarrassing
"JUJU_CHARM_DIR="+paths.GetCharmDir(),
"JUJU_CONTEXT_ID="+context.id,
"JUJU_AGENT_SOCKET="+paths.GetJujucSocket(),
"JUJU_UNIT_NAME="+context.unitName,
"JUJU_MODEL_UUID="+context.uuid,
"JUJU_MODEL_NAME="+context.modelName,
"JUJU_API_ADDRESSES="+strings.Join(context.apiAddrs, " "),
"JUJU_SLA="+context.slaLevel,
"JUJU_MACHINE_ID="+context.assignedMachineTag.Id(),
"JUJU_PRINCIPAL_UNIT="+context.principal,
"JUJU_AVAILABILITY_ZONE="+context.availabilityzone,
"JUJU_VERSION="+version.Current.String(),
"CLOUD_API_VERSION="+context.cloudAPIVersion,
// Some of these will be empty, but that is fine, better
// to explicitly export them as empty.
"JUJU_CHARM_HTTP_PROXY="+context.jujuProxySettings.Http,
"JUJU_CHARM_HTTPS_PROXY="+context.jujuProxySettings.Https,
"JUJU_CHARM_FTP_PROXY="+context.jujuProxySettings.Ftp,
"JUJU_CHARM_NO_PROXY="+context.jujuProxySettings.NoProxy,
)
if context.meterStatus != nil {
vars = append(vars,
"JUJU_METER_STATUS="+context.meterStatus.code,
"JUJU_METER_INFO="+context.meterStatus.info,
)
}
if r, err := context.HookRelation(); err == nil {
vars = append(vars,
"JUJU_RELATION="+r.Name(),
"JUJU_RELATION_ID="+r.FakeId(),
"JUJU_REMOTE_UNIT="+context.remoteUnitName,
)
} else if !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
if context.actionData != nil {
vars = append(vars,
"JUJU_ACTION_NAME="+context.actionData.Name,
"JUJU_ACTION_UUID="+context.actionData.Tag.Id(),
"JUJU_ACTION_TAG="+context.actionData.Tag.String(),
)
}
return append(vars, OSDependentEnvVars(paths)...), nil
} | [
"func",
"(",
"context",
"*",
"HookContext",
")",
"HookVars",
"(",
"paths",
"Paths",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"vars",
":=",
"context",
".",
"legacyProxySettings",
".",
"AsEnvironmentValues",
"(",
")",
"\n",
"// TODO(thumper): as work on proxies progress, there will be additional",
"// proxy settings to be added.",
"vars",
"=",
"append",
"(",
"vars",
",",
"\"",
"\"",
"+",
"paths",
".",
"GetCharmDir",
"(",
")",
",",
"// legacy, embarrassing",
"\"",
"\"",
"+",
"paths",
".",
"GetCharmDir",
"(",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"id",
",",
"\"",
"\"",
"+",
"paths",
".",
"GetJujucSocket",
"(",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"unitName",
",",
"\"",
"\"",
"+",
"context",
".",
"uuid",
",",
"\"",
"\"",
"+",
"context",
".",
"modelName",
",",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"context",
".",
"apiAddrs",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"slaLevel",
",",
"\"",
"\"",
"+",
"context",
".",
"assignedMachineTag",
".",
"Id",
"(",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"principal",
",",
"\"",
"\"",
"+",
"context",
".",
"availabilityzone",
",",
"\"",
"\"",
"+",
"version",
".",
"Current",
".",
"String",
"(",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"cloudAPIVersion",
",",
"// Some of these will be empty, but that is fine, better",
"// to explicitly export them as empty.",
"\"",
"\"",
"+",
"context",
".",
"jujuProxySettings",
".",
"Http",
",",
"\"",
"\"",
"+",
"context",
".",
"jujuProxySettings",
".",
"Https",
",",
"\"",
"\"",
"+",
"context",
".",
"jujuProxySettings",
".",
"Ftp",
",",
"\"",
"\"",
"+",
"context",
".",
"jujuProxySettings",
".",
"NoProxy",
",",
")",
"\n",
"if",
"context",
".",
"meterStatus",
"!=",
"nil",
"{",
"vars",
"=",
"append",
"(",
"vars",
",",
"\"",
"\"",
"+",
"context",
".",
"meterStatus",
".",
"code",
",",
"\"",
"\"",
"+",
"context",
".",
"meterStatus",
".",
"info",
",",
")",
"\n\n",
"}",
"\n",
"if",
"r",
",",
"err",
":=",
"context",
".",
"HookRelation",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"vars",
"=",
"append",
"(",
"vars",
",",
"\"",
"\"",
"+",
"r",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
"+",
"r",
".",
"FakeId",
"(",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"remoteUnitName",
",",
")",
"\n",
"}",
"else",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"context",
".",
"actionData",
"!=",
"nil",
"{",
"vars",
"=",
"append",
"(",
"vars",
",",
"\"",
"\"",
"+",
"context",
".",
"actionData",
".",
"Name",
",",
"\"",
"\"",
"+",
"context",
".",
"actionData",
".",
"Tag",
".",
"Id",
"(",
")",
",",
"\"",
"\"",
"+",
"context",
".",
"actionData",
".",
"Tag",
".",
"String",
"(",
")",
",",
")",
"\n",
"}",
"\n",
"return",
"append",
"(",
"vars",
",",
"OSDependentEnvVars",
"(",
"paths",
")",
"...",
")",
",",
"nil",
"\n",
"}"
] | // HookVars returns an os.Environ-style list of strings necessary to run a hook
// such that it can know what environment it's operating in, and can call back
// into context. | [
"HookVars",
"returns",
"an",
"os",
".",
"Environ",
"-",
"style",
"list",
"of",
"strings",
"necessary",
"to",
"run",
"a",
"hook",
"such",
"that",
"it",
"can",
"know",
"what",
"environment",
"it",
"s",
"operating",
"in",
"and",
"can",
"call",
"back",
"into",
"context",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L644-L694 |
155,478 | juju/juju | worker/uniter/runner/context/context.go | Prepare | func (ctx *HookContext) Prepare() error {
if ctx.actionData != nil {
err := ctx.state.ActionBegin(ctx.actionData.Tag)
if err != nil {
return errors.Trace(err)
}
}
return nil
} | go | func (ctx *HookContext) Prepare() error {
if ctx.actionData != nil {
err := ctx.state.ActionBegin(ctx.actionData.Tag)
if err != nil {
return errors.Trace(err)
}
}
return nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"Prepare",
"(",
")",
"error",
"{",
"if",
"ctx",
".",
"actionData",
"!=",
"nil",
"{",
"err",
":=",
"ctx",
".",
"state",
".",
"ActionBegin",
"(",
"ctx",
".",
"actionData",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Prepare implements the Context interface. | [
"Prepare",
"implements",
"the",
"Context",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L722-L730 |
155,479 | juju/juju | worker/uniter/runner/context/context.go | Flush | func (ctx *HookContext) Flush(process string, ctxErr error) (err error) {
writeChanges := ctxErr == nil
// In the case of Actions, handle any errors using finalizeAction.
if ctx.actionData != nil {
// If we had an error in err at this point, it's part of the
// normal behavior of an Action. Errors which happen during
// the finalize should be handed back to the uniter. Close
// over the existing err, clear it, and only return errors
// which occur during the finalize, e.g. API call errors.
defer func(ctxErr error) {
err = ctx.finalizeAction(ctxErr, err)
}(ctxErr)
ctxErr = nil
} else {
// TODO(gsamfira): Just for now, reboot will not be supported in actions.
defer ctx.handleReboot(&err)
}
for id, rctx := range ctx.relations {
if writeChanges {
if e := rctx.WriteSettings(); e != nil {
e = errors.Errorf(
"could not write settings from %q to relation %d: %v",
process, id, e,
)
logger.Errorf("%v", e)
if ctxErr == nil {
ctxErr = e
}
}
}
}
for rangeKey, rangeInfo := range ctx.pendingPorts {
if writeChanges {
var e error
var op string
if rangeInfo.ShouldOpen {
e = ctx.unit.OpenPorts(
rangeKey.Ports.Protocol,
rangeKey.Ports.FromPort,
rangeKey.Ports.ToPort,
)
op = "open"
} else {
e = ctx.unit.ClosePorts(
rangeKey.Ports.Protocol,
rangeKey.Ports.FromPort,
rangeKey.Ports.ToPort,
)
op = "close"
}
if e != nil {
e = errors.Annotatef(e, "cannot %s %v", op, rangeKey.Ports)
logger.Errorf("%v", e)
if ctxErr == nil {
ctxErr = e
}
}
}
}
// add storage to unit dynamically
if len(ctx.storageAddConstraints) > 0 && writeChanges {
err := ctx.unit.AddStorage(ctx.storageAddConstraints)
if err != nil {
err = errors.Annotatef(err, "cannot add storage")
logger.Errorf("%v", err)
if ctxErr == nil {
ctxErr = err
}
}
}
// TODO (tasdomas) 2014 09 03: context finalization needs to modified to apply all
// changes in one api call to minimize the risk
// of partial failures.
if !writeChanges {
return ctxErr
}
return ctxErr
} | go | func (ctx *HookContext) Flush(process string, ctxErr error) (err error) {
writeChanges := ctxErr == nil
// In the case of Actions, handle any errors using finalizeAction.
if ctx.actionData != nil {
// If we had an error in err at this point, it's part of the
// normal behavior of an Action. Errors which happen during
// the finalize should be handed back to the uniter. Close
// over the existing err, clear it, and only return errors
// which occur during the finalize, e.g. API call errors.
defer func(ctxErr error) {
err = ctx.finalizeAction(ctxErr, err)
}(ctxErr)
ctxErr = nil
} else {
// TODO(gsamfira): Just for now, reboot will not be supported in actions.
defer ctx.handleReboot(&err)
}
for id, rctx := range ctx.relations {
if writeChanges {
if e := rctx.WriteSettings(); e != nil {
e = errors.Errorf(
"could not write settings from %q to relation %d: %v",
process, id, e,
)
logger.Errorf("%v", e)
if ctxErr == nil {
ctxErr = e
}
}
}
}
for rangeKey, rangeInfo := range ctx.pendingPorts {
if writeChanges {
var e error
var op string
if rangeInfo.ShouldOpen {
e = ctx.unit.OpenPorts(
rangeKey.Ports.Protocol,
rangeKey.Ports.FromPort,
rangeKey.Ports.ToPort,
)
op = "open"
} else {
e = ctx.unit.ClosePorts(
rangeKey.Ports.Protocol,
rangeKey.Ports.FromPort,
rangeKey.Ports.ToPort,
)
op = "close"
}
if e != nil {
e = errors.Annotatef(e, "cannot %s %v", op, rangeKey.Ports)
logger.Errorf("%v", e)
if ctxErr == nil {
ctxErr = e
}
}
}
}
// add storage to unit dynamically
if len(ctx.storageAddConstraints) > 0 && writeChanges {
err := ctx.unit.AddStorage(ctx.storageAddConstraints)
if err != nil {
err = errors.Annotatef(err, "cannot add storage")
logger.Errorf("%v", err)
if ctxErr == nil {
ctxErr = err
}
}
}
// TODO (tasdomas) 2014 09 03: context finalization needs to modified to apply all
// changes in one api call to minimize the risk
// of partial failures.
if !writeChanges {
return ctxErr
}
return ctxErr
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"Flush",
"(",
"process",
"string",
",",
"ctxErr",
"error",
")",
"(",
"err",
"error",
")",
"{",
"writeChanges",
":=",
"ctxErr",
"==",
"nil",
"\n\n",
"// In the case of Actions, handle any errors using finalizeAction.",
"if",
"ctx",
".",
"actionData",
"!=",
"nil",
"{",
"// If we had an error in err at this point, it's part of the",
"// normal behavior of an Action. Errors which happen during",
"// the finalize should be handed back to the uniter. Close",
"// over the existing err, clear it, and only return errors",
"// which occur during the finalize, e.g. API call errors.",
"defer",
"func",
"(",
"ctxErr",
"error",
")",
"{",
"err",
"=",
"ctx",
".",
"finalizeAction",
"(",
"ctxErr",
",",
"err",
")",
"\n",
"}",
"(",
"ctxErr",
")",
"\n",
"ctxErr",
"=",
"nil",
"\n",
"}",
"else",
"{",
"// TODO(gsamfira): Just for now, reboot will not be supported in actions.",
"defer",
"ctx",
".",
"handleReboot",
"(",
"&",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"id",
",",
"rctx",
":=",
"range",
"ctx",
".",
"relations",
"{",
"if",
"writeChanges",
"{",
"if",
"e",
":=",
"rctx",
".",
"WriteSettings",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"e",
"=",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"process",
",",
"id",
",",
"e",
",",
")",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"if",
"ctxErr",
"==",
"nil",
"{",
"ctxErr",
"=",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"rangeKey",
",",
"rangeInfo",
":=",
"range",
"ctx",
".",
"pendingPorts",
"{",
"if",
"writeChanges",
"{",
"var",
"e",
"error",
"\n",
"var",
"op",
"string",
"\n",
"if",
"rangeInfo",
".",
"ShouldOpen",
"{",
"e",
"=",
"ctx",
".",
"unit",
".",
"OpenPorts",
"(",
"rangeKey",
".",
"Ports",
".",
"Protocol",
",",
"rangeKey",
".",
"Ports",
".",
"FromPort",
",",
"rangeKey",
".",
"Ports",
".",
"ToPort",
",",
")",
"\n",
"op",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"e",
"=",
"ctx",
".",
"unit",
".",
"ClosePorts",
"(",
"rangeKey",
".",
"Ports",
".",
"Protocol",
",",
"rangeKey",
".",
"Ports",
".",
"FromPort",
",",
"rangeKey",
".",
"Ports",
".",
"ToPort",
",",
")",
"\n",
"op",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"e",
"=",
"errors",
".",
"Annotatef",
"(",
"e",
",",
"\"",
"\"",
",",
"op",
",",
"rangeKey",
".",
"Ports",
")",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"if",
"ctxErr",
"==",
"nil",
"{",
"ctxErr",
"=",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// add storage to unit dynamically",
"if",
"len",
"(",
"ctx",
".",
"storageAddConstraints",
")",
">",
"0",
"&&",
"writeChanges",
"{",
"err",
":=",
"ctx",
".",
"unit",
".",
"AddStorage",
"(",
"ctx",
".",
"storageAddConstraints",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"if",
"ctxErr",
"==",
"nil",
"{",
"ctxErr",
"=",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// TODO (tasdomas) 2014 09 03: context finalization needs to modified to apply all",
"// changes in one api call to minimize the risk",
"// of partial failures.",
"if",
"!",
"writeChanges",
"{",
"return",
"ctxErr",
"\n",
"}",
"\n\n",
"return",
"ctxErr",
"\n",
"}"
] | // Flush implements the Context interface. | [
"Flush",
"implements",
"the",
"Context",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L733-L817 |
155,480 | juju/juju | worker/uniter/runner/context/context.go | finalizeAction | func (ctx *HookContext) finalizeAction(err, unhandledErr error) error {
// TODO (binary132): synchronize with gsamfira's reboot logic
message := ctx.actionData.ResultsMessage
results := ctx.actionData.ResultsMap
tag := ctx.actionData.Tag
status := params.ActionCompleted
if ctx.actionData.Failed {
status = params.ActionFailed
}
// If we had an action error, we'll simply encapsulate it in the response
// and discard the error state. Actions should not error the uniter.
if err != nil {
message = err.Error()
if charmrunner.IsMissingHookError(err) {
message = fmt.Sprintf("action not implemented on unit %q", ctx.unitName)
}
status = params.ActionFailed
}
callErr := ctx.state.ActionFinish(tag, status, results, message)
if callErr != nil {
unhandledErr = errors.Wrap(unhandledErr, callErr)
}
return unhandledErr
} | go | func (ctx *HookContext) finalizeAction(err, unhandledErr error) error {
// TODO (binary132): synchronize with gsamfira's reboot logic
message := ctx.actionData.ResultsMessage
results := ctx.actionData.ResultsMap
tag := ctx.actionData.Tag
status := params.ActionCompleted
if ctx.actionData.Failed {
status = params.ActionFailed
}
// If we had an action error, we'll simply encapsulate it in the response
// and discard the error state. Actions should not error the uniter.
if err != nil {
message = err.Error()
if charmrunner.IsMissingHookError(err) {
message = fmt.Sprintf("action not implemented on unit %q", ctx.unitName)
}
status = params.ActionFailed
}
callErr := ctx.state.ActionFinish(tag, status, results, message)
if callErr != nil {
unhandledErr = errors.Wrap(unhandledErr, callErr)
}
return unhandledErr
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"finalizeAction",
"(",
"err",
",",
"unhandledErr",
"error",
")",
"error",
"{",
"// TODO (binary132): synchronize with gsamfira's reboot logic",
"message",
":=",
"ctx",
".",
"actionData",
".",
"ResultsMessage",
"\n",
"results",
":=",
"ctx",
".",
"actionData",
".",
"ResultsMap",
"\n",
"tag",
":=",
"ctx",
".",
"actionData",
".",
"Tag",
"\n",
"status",
":=",
"params",
".",
"ActionCompleted",
"\n",
"if",
"ctx",
".",
"actionData",
".",
"Failed",
"{",
"status",
"=",
"params",
".",
"ActionFailed",
"\n",
"}",
"\n\n",
"// If we had an action error, we'll simply encapsulate it in the response",
"// and discard the error state. Actions should not error the uniter.",
"if",
"err",
"!=",
"nil",
"{",
"message",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"if",
"charmrunner",
".",
"IsMissingHookError",
"(",
"err",
")",
"{",
"message",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"unitName",
")",
"\n",
"}",
"\n",
"status",
"=",
"params",
".",
"ActionFailed",
"\n",
"}",
"\n\n",
"callErr",
":=",
"ctx",
".",
"state",
".",
"ActionFinish",
"(",
"tag",
",",
"status",
",",
"results",
",",
"message",
")",
"\n",
"if",
"callErr",
"!=",
"nil",
"{",
"unhandledErr",
"=",
"errors",
".",
"Wrap",
"(",
"unhandledErr",
",",
"callErr",
")",
"\n",
"}",
"\n",
"return",
"unhandledErr",
"\n",
"}"
] | // finalizeAction passes back the final status of an Action hook to state.
// It wraps any errors which occurred in normal behavior of the Action run;
// only errors passed in unhandledErr will be returned. | [
"finalizeAction",
"passes",
"back",
"the",
"final",
"status",
"of",
"an",
"Action",
"hook",
"to",
"state",
".",
"It",
"wraps",
"any",
"errors",
"which",
"occurred",
"in",
"normal",
"behavior",
"of",
"the",
"Action",
"run",
";",
"only",
"errors",
"passed",
"in",
"unhandledErr",
"will",
"be",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L822-L847 |
155,481 | juju/juju | worker/uniter/runner/context/context.go | killCharmHook | func (ctx *HookContext) killCharmHook() error {
proc := ctx.GetProcess()
if proc == nil {
// nothing to kill
return charmrunner.ErrNoProcess
}
logger.Infof("trying to kill context process %v", proc.Pid())
tick := ctx.clock.After(0)
timeout := ctx.clock.After(30 * time.Second)
for {
// We repeatedly try to kill the process until we fail; this is
// because we don't control the *Process, and our clients expect
// to be able to Wait(); so we can't Wait. We could do better,
// but not with a single implementation across all platforms.
// TODO(gsamfira): come up with a better cross-platform approach.
select {
case <-tick:
err := proc.Kill()
if err != nil {
logger.Infof("kill returned: %s", err)
logger.Infof("assuming already killed")
return nil
}
case <-timeout:
return errors.Errorf("failed to kill context process %v", proc.Pid())
}
logger.Infof("waiting for context process %v to die", proc.Pid())
tick = ctx.clock.After(100 * time.Millisecond)
}
} | go | func (ctx *HookContext) killCharmHook() error {
proc := ctx.GetProcess()
if proc == nil {
// nothing to kill
return charmrunner.ErrNoProcess
}
logger.Infof("trying to kill context process %v", proc.Pid())
tick := ctx.clock.After(0)
timeout := ctx.clock.After(30 * time.Second)
for {
// We repeatedly try to kill the process until we fail; this is
// because we don't control the *Process, and our clients expect
// to be able to Wait(); so we can't Wait. We could do better,
// but not with a single implementation across all platforms.
// TODO(gsamfira): come up with a better cross-platform approach.
select {
case <-tick:
err := proc.Kill()
if err != nil {
logger.Infof("kill returned: %s", err)
logger.Infof("assuming already killed")
return nil
}
case <-timeout:
return errors.Errorf("failed to kill context process %v", proc.Pid())
}
logger.Infof("waiting for context process %v to die", proc.Pid())
tick = ctx.clock.After(100 * time.Millisecond)
}
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"killCharmHook",
"(",
")",
"error",
"{",
"proc",
":=",
"ctx",
".",
"GetProcess",
"(",
")",
"\n",
"if",
"proc",
"==",
"nil",
"{",
"// nothing to kill",
"return",
"charmrunner",
".",
"ErrNoProcess",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"proc",
".",
"Pid",
"(",
")",
")",
"\n\n",
"tick",
":=",
"ctx",
".",
"clock",
".",
"After",
"(",
"0",
")",
"\n",
"timeout",
":=",
"ctx",
".",
"clock",
".",
"After",
"(",
"30",
"*",
"time",
".",
"Second",
")",
"\n",
"for",
"{",
"// We repeatedly try to kill the process until we fail; this is",
"// because we don't control the *Process, and our clients expect",
"// to be able to Wait(); so we can't Wait. We could do better,",
"// but not with a single implementation across all platforms.",
"// TODO(gsamfira): come up with a better cross-platform approach.",
"select",
"{",
"case",
"<-",
"tick",
":",
"err",
":=",
"proc",
".",
"Kill",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"<-",
"timeout",
":",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"proc",
".",
"Pid",
"(",
")",
")",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"proc",
".",
"Pid",
"(",
")",
")",
"\n",
"tick",
"=",
"ctx",
".",
"clock",
".",
"After",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}",
"\n",
"}"
] | // killCharmHook tries to kill the current running charm hook. | [
"killCharmHook",
"tries",
"to",
"kill",
"the",
"current",
"running",
"charm",
"hook",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L850-L880 |
155,482 | juju/juju | worker/uniter/runner/context/context.go | UnitWorkloadVersion | func (ctx *HookContext) UnitWorkloadVersion() (string, error) {
var results params.StringResults
args := params.Entities{
Entities: []params.Entity{{Tag: ctx.unit.Tag().String()}},
}
err := ctx.state.Facade().FacadeCall("WorkloadVersion", args, &results)
if err != nil {
return "", err
}
if len(results.Results) != 1 {
return "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return "", result.Error
}
return result.Result, nil
} | go | func (ctx *HookContext) UnitWorkloadVersion() (string, error) {
var results params.StringResults
args := params.Entities{
Entities: []params.Entity{{Tag: ctx.unit.Tag().String()}},
}
err := ctx.state.Facade().FacadeCall("WorkloadVersion", args, &results)
if err != nil {
return "", err
}
if len(results.Results) != 1 {
return "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return "", result.Error
}
return result.Result, nil
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"UnitWorkloadVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StringResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"ctx",
".",
"unit",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"ctx",
".",
"state",
".",
"Facade",
"(",
")",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"result",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // UnitWorkloadVersion returns the version of the workload reported by
// the current unit. | [
"UnitWorkloadVersion",
"returns",
"the",
"version",
"of",
"the",
"workload",
"reported",
"by",
"the",
"current",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L884-L901 |
155,483 | juju/juju | worker/uniter/runner/context/context.go | SetUnitWorkloadVersion | func (ctx *HookContext) SetUnitWorkloadVersion(version string) error {
var result params.ErrorResults
args := params.EntityWorkloadVersions{
Entities: []params.EntityWorkloadVersion{
{Tag: ctx.unit.Tag().String(), WorkloadVersion: version},
},
}
err := ctx.state.Facade().FacadeCall("SetWorkloadVersion", args, &result)
if err != nil {
return err
}
return result.OneError()
} | go | func (ctx *HookContext) SetUnitWorkloadVersion(version string) error {
var result params.ErrorResults
args := params.EntityWorkloadVersions{
Entities: []params.EntityWorkloadVersion{
{Tag: ctx.unit.Tag().String(), WorkloadVersion: version},
},
}
err := ctx.state.Facade().FacadeCall("SetWorkloadVersion", args, &result)
if err != nil {
return err
}
return result.OneError()
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"SetUnitWorkloadVersion",
"(",
"version",
"string",
")",
"error",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"EntityWorkloadVersions",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"EntityWorkloadVersion",
"{",
"{",
"Tag",
":",
"ctx",
".",
"unit",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
",",
"WorkloadVersion",
":",
"version",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"ctx",
".",
"state",
".",
"Facade",
"(",
")",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // SetUnitWorkloadVersion sets the current unit's workload version to
// the specified value. | [
"SetUnitWorkloadVersion",
"sets",
"the",
"current",
"unit",
"s",
"workload",
"version",
"to",
"the",
"specified",
"value",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L905-L917 |
155,484 | juju/juju | worker/uniter/runner/context/context.go | NetworkInfo | func (ctx *HookContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error) {
var relId *int
if relationId != -1 {
relId = &relationId
}
return ctx.unit.NetworkInfo(bindingNames, relId)
} | go | func (ctx *HookContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error) {
var relId *int
if relationId != -1 {
relId = &relationId
}
return ctx.unit.NetworkInfo(bindingNames, relId)
} | [
"func",
"(",
"ctx",
"*",
"HookContext",
")",
"NetworkInfo",
"(",
"bindingNames",
"[",
"]",
"string",
",",
"relationId",
"int",
")",
"(",
"map",
"[",
"string",
"]",
"params",
".",
"NetworkInfoResult",
",",
"error",
")",
"{",
"var",
"relId",
"*",
"int",
"\n",
"if",
"relationId",
"!=",
"-",
"1",
"{",
"relId",
"=",
"&",
"relationId",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"unit",
".",
"NetworkInfo",
"(",
"bindingNames",
",",
"relId",
")",
"\n",
"}"
] | // NetworkInfo returns the network info for the given bindings on the given relation. | [
"NetworkInfo",
"returns",
"the",
"network",
"info",
"for",
"the",
"given",
"bindings",
"on",
"the",
"given",
"relation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/context/context.go#L920-L926 |
155,485 | juju/juju | provider/oci/images.go | ImageMetadata | func (i ImageCache) ImageMetadata(series string, defaultVirtType string) []*imagemetadata.ImageMetadata {
var metadata []*imagemetadata.ImageMetadata
images, ok := i.images[series]
if !ok {
return metadata
}
for _, val := range images {
if val.ImageType == ImageTypeGeneric {
if defaultVirtType != "" {
val.ImageType = ImageType(defaultVirtType)
} else {
val.ImageType = ImageTypeVM
}
}
imgMeta := &imagemetadata.ImageMetadata{
Id: val.Id,
Arch: "amd64",
// TODO(gsamfira): add region name?
// RegionName: region,
Version: val.Series,
VirtType: string(val.ImageType),
}
metadata = append(metadata, imgMeta)
}
return metadata
} | go | func (i ImageCache) ImageMetadata(series string, defaultVirtType string) []*imagemetadata.ImageMetadata {
var metadata []*imagemetadata.ImageMetadata
images, ok := i.images[series]
if !ok {
return metadata
}
for _, val := range images {
if val.ImageType == ImageTypeGeneric {
if defaultVirtType != "" {
val.ImageType = ImageType(defaultVirtType)
} else {
val.ImageType = ImageTypeVM
}
}
imgMeta := &imagemetadata.ImageMetadata{
Id: val.Id,
Arch: "amd64",
// TODO(gsamfira): add region name?
// RegionName: region,
Version: val.Series,
VirtType: string(val.ImageType),
}
metadata = append(metadata, imgMeta)
}
return metadata
} | [
"func",
"(",
"i",
"ImageCache",
")",
"ImageMetadata",
"(",
"series",
"string",
",",
"defaultVirtType",
"string",
")",
"[",
"]",
"*",
"imagemetadata",
".",
"ImageMetadata",
"{",
"var",
"metadata",
"[",
"]",
"*",
"imagemetadata",
".",
"ImageMetadata",
"\n\n",
"images",
",",
"ok",
":=",
"i",
".",
"images",
"[",
"series",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"metadata",
"\n",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"images",
"{",
"if",
"val",
".",
"ImageType",
"==",
"ImageTypeGeneric",
"{",
"if",
"defaultVirtType",
"!=",
"\"",
"\"",
"{",
"val",
".",
"ImageType",
"=",
"ImageType",
"(",
"defaultVirtType",
")",
"\n",
"}",
"else",
"{",
"val",
".",
"ImageType",
"=",
"ImageTypeVM",
"\n",
"}",
"\n",
"}",
"\n",
"imgMeta",
":=",
"&",
"imagemetadata",
".",
"ImageMetadata",
"{",
"Id",
":",
"val",
".",
"Id",
",",
"Arch",
":",
"\"",
"\"",
",",
"// TODO(gsamfira): add region name?",
"// RegionName: region,",
"Version",
":",
"val",
".",
"Series",
",",
"VirtType",
":",
"string",
"(",
"val",
".",
"ImageType",
")",
",",
"}",
"\n",
"metadata",
"=",
"append",
"(",
"metadata",
",",
"imgMeta",
")",
"\n",
"}",
"\n\n",
"return",
"metadata",
"\n",
"}"
] | // ImageMetadata returns an array of imagemetadata.ImageMetadata for
// all images that are currently in cache, matching the provided series
// If defaultVirtType is specified, all generic images will inherit the
// value of defaultVirtType. | [
"ImageMetadata",
"returns",
"an",
"array",
"of",
"imagemetadata",
".",
"ImageMetadata",
"for",
"all",
"images",
"that",
"are",
"currently",
"in",
"cache",
"matching",
"the",
"provided",
"series",
"If",
"defaultVirtType",
"is",
"specified",
"all",
"generic",
"images",
"will",
"inherit",
"the",
"value",
"of",
"defaultVirtType",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/images.go#L178-L205 |
155,486 | juju/juju | provider/oci/images.go | SupportedShapes | func (i ImageCache) SupportedShapes(series string) []instances.InstanceType {
matches := map[string]int{}
ret := []instances.InstanceType{}
// TODO(gsamfira): Find a better way for this.
images, ok := i.images[series]
if !ok {
return ret
}
for _, img := range images {
for _, instType := range img.InstanceTypes {
if _, ok := matches[instType.Name]; !ok {
matches[instType.Name] = 1
ret = append(ret, instType)
}
}
}
return ret
} | go | func (i ImageCache) SupportedShapes(series string) []instances.InstanceType {
matches := map[string]int{}
ret := []instances.InstanceType{}
// TODO(gsamfira): Find a better way for this.
images, ok := i.images[series]
if !ok {
return ret
}
for _, img := range images {
for _, instType := range img.InstanceTypes {
if _, ok := matches[instType.Name]; !ok {
matches[instType.Name] = 1
ret = append(ret, instType)
}
}
}
return ret
} | [
"func",
"(",
"i",
"ImageCache",
")",
"SupportedShapes",
"(",
"series",
"string",
")",
"[",
"]",
"instances",
".",
"InstanceType",
"{",
"matches",
":=",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
"\n",
"ret",
":=",
"[",
"]",
"instances",
".",
"InstanceType",
"{",
"}",
"\n",
"// TODO(gsamfira): Find a better way for this.",
"images",
",",
"ok",
":=",
"i",
".",
"images",
"[",
"series",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ret",
"\n",
"}",
"\n",
"for",
"_",
",",
"img",
":=",
"range",
"images",
"{",
"for",
"_",
",",
"instType",
":=",
"range",
"img",
".",
"InstanceTypes",
"{",
"if",
"_",
",",
"ok",
":=",
"matches",
"[",
"instType",
".",
"Name",
"]",
";",
"!",
"ok",
"{",
"matches",
"[",
"instType",
".",
"Name",
"]",
"=",
"1",
"\n",
"ret",
"=",
"append",
"(",
"ret",
",",
"instType",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] | // SupportedShapes returns the InstanceTypes available for images matching
// the supplied series | [
"SupportedShapes",
"returns",
"the",
"InstanceTypes",
"available",
"for",
"images",
"matching",
"the",
"supplied",
"series"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/images.go#L209-L226 |
155,487 | juju/juju | cmd/juju/commands/switch.go | name | func (c *switchCommand) name(store jujuclient.ModelGetter, controllerName string, machineReadable bool) (string, error) {
if controllerName == "" {
return "", nil
}
modelName, err := store.CurrentModel(controllerName)
if err == nil {
return modelcmd.JoinModelName(controllerName, modelName), nil
}
if !errors.IsNotFound(err) {
return "", errors.Trace(err)
}
// No current account or model.
if machineReadable {
return controllerName, nil
}
return fmt.Sprintf("%s (controller)", controllerName), nil
} | go | func (c *switchCommand) name(store jujuclient.ModelGetter, controllerName string, machineReadable bool) (string, error) {
if controllerName == "" {
return "", nil
}
modelName, err := store.CurrentModel(controllerName)
if err == nil {
return modelcmd.JoinModelName(controllerName, modelName), nil
}
if !errors.IsNotFound(err) {
return "", errors.Trace(err)
}
// No current account or model.
if machineReadable {
return controllerName, nil
}
return fmt.Sprintf("%s (controller)", controllerName), nil
} | [
"func",
"(",
"c",
"*",
"switchCommand",
")",
"name",
"(",
"store",
"jujuclient",
".",
"ModelGetter",
",",
"controllerName",
"string",
",",
"machineReadable",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"controllerName",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"modelName",
",",
"err",
":=",
"store",
".",
"CurrentModel",
"(",
"controllerName",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"modelcmd",
".",
"JoinModelName",
"(",
"controllerName",
",",
"modelName",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// No current account or model.",
"if",
"machineReadable",
"{",
"return",
"controllerName",
",",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"controllerName",
")",
",",
"nil",
"\n",
"}"
] | // name returns the name of the current model for the specified controller
// if one is set, otherwise the controller name with an indicator that it
// is the name of a controller and not a model. | [
"name",
"returns",
"the",
"name",
"of",
"the",
"current",
"model",
"for",
"the",
"specified",
"controller",
"if",
"one",
"is",
"set",
"otherwise",
"the",
"controller",
"name",
"with",
"an",
"indicator",
"that",
"it",
"is",
"the",
"name",
"of",
"a",
"controller",
"and",
"not",
"a",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/switch.go#L206-L222 |
155,488 | juju/juju | state/offerconnections.go | String | func (oc *OfferConnection) String() string {
return fmt.Sprintf("connection to %q by %q for relation %d", oc.doc.OfferUUID, oc.doc.UserName, oc.doc.RelationId)
} | go | func (oc *OfferConnection) String() string {
return fmt.Sprintf("connection to %q by %q for relation %d", oc.doc.OfferUUID, oc.doc.UserName, oc.doc.RelationId)
} | [
"func",
"(",
"oc",
"*",
"OfferConnection",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"oc",
".",
"doc",
".",
"OfferUUID",
",",
"oc",
".",
"doc",
".",
"UserName",
",",
"oc",
".",
"doc",
".",
"RelationId",
")",
"\n",
"}"
] | // String returns the details of the connection. | [
"String",
"returns",
"the",
"details",
"of",
"the",
"connection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/offerconnections.go#L77-L79 |
155,489 | juju/juju | state/offerconnections.go | AddOfferConnection | func (st *State) AddOfferConnection(args AddOfferConnectionParams) (_ *OfferConnection, err error) {
defer errors.DeferredAnnotatef(&err, "cannot add offer record for %q", args.OfferUUID)
if err := validateOfferConnectionParams(args); err != nil {
return nil, errors.Trace(err)
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
} else if model.Life() != Alive {
return nil, errors.Errorf("model is no longer alive")
}
// Create the application addition operations.
offerConnectionDoc := offerConnectionDoc{
SourceModelUUID: args.SourceModelUUID,
OfferUUID: args.OfferUUID,
UserName: args.Username,
RelationId: args.RelationId,
RelationKey: args.RelationKey,
DocID: fmt.Sprintf("%d", args.RelationId),
}
buildTxn := func(attempt int) ([]txn.Op, error) {
// If we've tried once already and failed, check that
// model may have been destroyed.
if attempt > 0 {
if err := checkModelActive(st); err != nil {
return nil, errors.Trace(err)
}
return nil, errors.AlreadyExistsf("offer connection for relation id %d", args.RelationId)
}
ops := []txn.Op{
model.assertActiveOp(),
{
C: offerConnectionsC,
Id: offerConnectionDoc.DocID,
Assert: txn.DocMissing,
Insert: &offerConnectionDoc,
},
}
return ops, nil
}
if err = st.db().Run(buildTxn); err != nil {
return nil, errors.Trace(err)
}
return &OfferConnection{doc: offerConnectionDoc}, nil
} | go | func (st *State) AddOfferConnection(args AddOfferConnectionParams) (_ *OfferConnection, err error) {
defer errors.DeferredAnnotatef(&err, "cannot add offer record for %q", args.OfferUUID)
if err := validateOfferConnectionParams(args); err != nil {
return nil, errors.Trace(err)
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
} else if model.Life() != Alive {
return nil, errors.Errorf("model is no longer alive")
}
// Create the application addition operations.
offerConnectionDoc := offerConnectionDoc{
SourceModelUUID: args.SourceModelUUID,
OfferUUID: args.OfferUUID,
UserName: args.Username,
RelationId: args.RelationId,
RelationKey: args.RelationKey,
DocID: fmt.Sprintf("%d", args.RelationId),
}
buildTxn := func(attempt int) ([]txn.Op, error) {
// If we've tried once already and failed, check that
// model may have been destroyed.
if attempt > 0 {
if err := checkModelActive(st); err != nil {
return nil, errors.Trace(err)
}
return nil, errors.AlreadyExistsf("offer connection for relation id %d", args.RelationId)
}
ops := []txn.Op{
model.assertActiveOp(),
{
C: offerConnectionsC,
Id: offerConnectionDoc.DocID,
Assert: txn.DocMissing,
Insert: &offerConnectionDoc,
},
}
return ops, nil
}
if err = st.db().Run(buildTxn); err != nil {
return nil, errors.Trace(err)
}
return &OfferConnection{doc: offerConnectionDoc}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AddOfferConnection",
"(",
"args",
"AddOfferConnectionParams",
")",
"(",
"_",
"*",
"OfferConnection",
",",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"args",
".",
"OfferUUID",
")",
"\n\n",
"if",
"err",
":=",
"validateOfferConnectionParams",
"(",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"model",
".",
"Life",
"(",
")",
"!=",
"Alive",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Create the application addition operations.",
"offerConnectionDoc",
":=",
"offerConnectionDoc",
"{",
"SourceModelUUID",
":",
"args",
".",
"SourceModelUUID",
",",
"OfferUUID",
":",
"args",
".",
"OfferUUID",
",",
"UserName",
":",
"args",
".",
"Username",
",",
"RelationId",
":",
"args",
".",
"RelationId",
",",
"RelationKey",
":",
"args",
".",
"RelationKey",
",",
"DocID",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"args",
".",
"RelationId",
")",
",",
"}",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"// If we've tried once already and failed, check that",
"// model may have been destroyed.",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"checkModelActive",
"(",
"st",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"AlreadyExistsf",
"(",
"\"",
"\"",
",",
"args",
".",
"RelationId",
")",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"model",
".",
"assertActiveOp",
"(",
")",
",",
"{",
"C",
":",
"offerConnectionsC",
",",
"Id",
":",
"offerConnectionDoc",
".",
"DocID",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"&",
"offerConnectionDoc",
",",
"}",
",",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"=",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"OfferConnection",
"{",
"doc",
":",
"offerConnectionDoc",
"}",
",",
"nil",
"\n",
"}"
] | // AddOfferConnection creates a new offer connection record, which records details about a
// relation made from a remote model to an offer in the local model. | [
"AddOfferConnection",
"creates",
"a",
"new",
"offer",
"connection",
"record",
"which",
"records",
"details",
"about",
"a",
"relation",
"made",
"from",
"a",
"remote",
"model",
"to",
"an",
"offer",
"in",
"the",
"local",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/offerconnections.go#L113-L160 |
155,490 | juju/juju | state/offerconnections.go | OfferConnections | func (st *State) OfferConnections(offerUUID string) (conns []*OfferConnection, err error) {
offerConnectionCollection, closer := st.db().GetCollection(offerConnectionsC)
defer closer()
connDocs := []offerConnectionDoc{}
err = offerConnectionCollection.Find(bson.D{{"offer-uuid", offerUUID}}).All(&connDocs)
if err != nil {
return nil, errors.Errorf("cannot get the offer connections for %v", offerUUID)
}
for _, v := range connDocs {
conns = append(conns, newOfferConnection(st, &v))
}
return conns, nil
} | go | func (st *State) OfferConnections(offerUUID string) (conns []*OfferConnection, err error) {
offerConnectionCollection, closer := st.db().GetCollection(offerConnectionsC)
defer closer()
connDocs := []offerConnectionDoc{}
err = offerConnectionCollection.Find(bson.D{{"offer-uuid", offerUUID}}).All(&connDocs)
if err != nil {
return nil, errors.Errorf("cannot get the offer connections for %v", offerUUID)
}
for _, v := range connDocs {
conns = append(conns, newOfferConnection(st, &v))
}
return conns, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"OfferConnections",
"(",
"offerUUID",
"string",
")",
"(",
"conns",
"[",
"]",
"*",
"OfferConnection",
",",
"err",
"error",
")",
"{",
"offerConnectionCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"offerConnectionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"connDocs",
":=",
"[",
"]",
"offerConnectionDoc",
"{",
"}",
"\n",
"err",
"=",
"offerConnectionCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"offerUUID",
"}",
"}",
")",
".",
"All",
"(",
"&",
"connDocs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"offerUUID",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"connDocs",
"{",
"conns",
"=",
"append",
"(",
"conns",
",",
"newOfferConnection",
"(",
"st",
",",
"&",
"v",
")",
")",
"\n",
"}",
"\n",
"return",
"conns",
",",
"nil",
"\n",
"}"
] | // OfferConnections returns the offer connections for an offer. | [
"OfferConnections",
"returns",
"the",
"offer",
"connections",
"for",
"an",
"offer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/offerconnections.go#L163-L176 |
155,491 | juju/juju | state/offerconnections.go | OfferConnectionForRelation | func (st *State) OfferConnectionForRelation(relationKey string) (*OfferConnection, error) {
offerConnectionCollection, closer := st.db().GetCollection(offerConnectionsC)
defer closer()
var connDoc offerConnectionDoc
err := offerConnectionCollection.Find(bson.D{{"relation-key", relationKey}}).One(&connDoc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("offer connection for relation %q", relationKey)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get offer connection details for relation %q", relationKey)
}
return newOfferConnection(st, &connDoc), nil
} | go | func (st *State) OfferConnectionForRelation(relationKey string) (*OfferConnection, error) {
offerConnectionCollection, closer := st.db().GetCollection(offerConnectionsC)
defer closer()
var connDoc offerConnectionDoc
err := offerConnectionCollection.Find(bson.D{{"relation-key", relationKey}}).One(&connDoc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("offer connection for relation %q", relationKey)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get offer connection details for relation %q", relationKey)
}
return newOfferConnection(st, &connDoc), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"OfferConnectionForRelation",
"(",
"relationKey",
"string",
")",
"(",
"*",
"OfferConnection",
",",
"error",
")",
"{",
"offerConnectionCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"offerConnectionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"connDoc",
"offerConnectionDoc",
"\n",
"err",
":=",
"offerConnectionCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"relationKey",
"}",
"}",
")",
".",
"One",
"(",
"&",
"connDoc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"relationKey",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"relationKey",
")",
"\n",
"}",
"\n",
"return",
"newOfferConnection",
"(",
"st",
",",
"&",
"connDoc",
")",
",",
"nil",
"\n",
"}"
] | // OfferConnectionForRelation returns the offer connection for the specified relation. | [
"OfferConnectionForRelation",
"returns",
"the",
"offer",
"connection",
"for",
"the",
"specified",
"relation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/offerconnections.go#L179-L192 |
155,492 | juju/juju | state/offerconnections.go | OfferConnectionsForUser | func (st *State) OfferConnectionsForUser(username string) ([]*OfferConnection, error) {
offerConnectionCollection, closer := st.db().GetCollection(offerConnectionsC)
defer closer()
var connDocs []offerConnectionDoc
err := offerConnectionCollection.Find(bson.D{{"username", username}}).All(&connDocs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get offer connection details for user %q", username)
}
conns := make([]*OfferConnection, len(connDocs))
for i, oc := range connDocs {
conns[i] = newOfferConnection(st, &oc)
}
return conns, nil
} | go | func (st *State) OfferConnectionsForUser(username string) ([]*OfferConnection, error) {
offerConnectionCollection, closer := st.db().GetCollection(offerConnectionsC)
defer closer()
var connDocs []offerConnectionDoc
err := offerConnectionCollection.Find(bson.D{{"username", username}}).All(&connDocs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get offer connection details for user %q", username)
}
conns := make([]*OfferConnection, len(connDocs))
for i, oc := range connDocs {
conns[i] = newOfferConnection(st, &oc)
}
return conns, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"OfferConnectionsForUser",
"(",
"username",
"string",
")",
"(",
"[",
"]",
"*",
"OfferConnection",
",",
"error",
")",
"{",
"offerConnectionCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"offerConnectionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"connDocs",
"[",
"]",
"offerConnectionDoc",
"\n",
"err",
":=",
"offerConnectionCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"username",
"}",
"}",
")",
".",
"All",
"(",
"&",
"connDocs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"username",
")",
"\n",
"}",
"\n",
"conns",
":=",
"make",
"(",
"[",
"]",
"*",
"OfferConnection",
",",
"len",
"(",
"connDocs",
")",
")",
"\n",
"for",
"i",
",",
"oc",
":=",
"range",
"connDocs",
"{",
"conns",
"[",
"i",
"]",
"=",
"newOfferConnection",
"(",
"st",
",",
"&",
"oc",
")",
"\n",
"}",
"\n",
"return",
"conns",
",",
"nil",
"\n",
"}"
] | // OfferConnectionsForUser returns the offer connections for the specified user. | [
"OfferConnectionsForUser",
"returns",
"the",
"offer",
"connections",
"for",
"the",
"specified",
"user",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/offerconnections.go#L195-L209 |
155,493 | juju/juju | state/offerconnections.go | RemoteConnectionStatus | func (st *State) RemoteConnectionStatus(offerUUID string) (*RemoteConnectionStatus, error) {
conns, err := st.OfferConnections(offerUUID)
if err != nil {
return nil, errors.Trace(err)
}
result := &RemoteConnectionStatus{
totalCount: len(conns),
}
for _, conn := range conns {
rel, err := st.KeyRelation(conn.RelationKey())
if err != nil {
return nil, errors.Trace(err)
}
relStatus, err := rel.Status()
if err != nil {
return nil, errors.Trace(err)
}
if relStatus.Status == status.Joined {
result.activeCount++
}
}
return result, nil
} | go | func (st *State) RemoteConnectionStatus(offerUUID string) (*RemoteConnectionStatus, error) {
conns, err := st.OfferConnections(offerUUID)
if err != nil {
return nil, errors.Trace(err)
}
result := &RemoteConnectionStatus{
totalCount: len(conns),
}
for _, conn := range conns {
rel, err := st.KeyRelation(conn.RelationKey())
if err != nil {
return nil, errors.Trace(err)
}
relStatus, err := rel.Status()
if err != nil {
return nil, errors.Trace(err)
}
if relStatus.Status == status.Joined {
result.activeCount++
}
}
return result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"RemoteConnectionStatus",
"(",
"offerUUID",
"string",
")",
"(",
"*",
"RemoteConnectionStatus",
",",
"error",
")",
"{",
"conns",
",",
"err",
":=",
"st",
".",
"OfferConnections",
"(",
"offerUUID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"result",
":=",
"&",
"RemoteConnectionStatus",
"{",
"totalCount",
":",
"len",
"(",
"conns",
")",
",",
"}",
"\n",
"for",
"_",
",",
"conn",
":=",
"range",
"conns",
"{",
"rel",
",",
"err",
":=",
"st",
".",
"KeyRelation",
"(",
"conn",
".",
"RelationKey",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"relStatus",
",",
"err",
":=",
"rel",
".",
"Status",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"relStatus",
".",
"Status",
"==",
"status",
".",
"Joined",
"{",
"result",
".",
"activeCount",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // RemoteConnectionStatus returns summary information about connections to the specified offer. | [
"RemoteConnectionStatus",
"returns",
"summary",
"information",
"about",
"connections",
"to",
"the",
"specified",
"offer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/offerconnections.go#L212-L234 |
155,494 | juju/juju | state/multiwatcher.go | NewMultiwatcher | func NewMultiwatcher(all *storeManager) *Multiwatcher {
// Note that we want to be clear about the defaults. So we set zero
// values explicitly.
// used: false means that the watcher has not been used yet
// revno: 0 means that *all* transactions prior to the first
// Next() call will be reflected in the deltas.
// stopped: false means that the watcher immediately starts off
// handling changes.
return &Multiwatcher{
all: all,
used: false,
revno: 0,
stopped: false,
}
} | go | func NewMultiwatcher(all *storeManager) *Multiwatcher {
// Note that we want to be clear about the defaults. So we set zero
// values explicitly.
// used: false means that the watcher has not been used yet
// revno: 0 means that *all* transactions prior to the first
// Next() call will be reflected in the deltas.
// stopped: false means that the watcher immediately starts off
// handling changes.
return &Multiwatcher{
all: all,
used: false,
revno: 0,
stopped: false,
}
} | [
"func",
"NewMultiwatcher",
"(",
"all",
"*",
"storeManager",
")",
"*",
"Multiwatcher",
"{",
"// Note that we want to be clear about the defaults. So we set zero",
"// values explicitly.",
"// used: false means that the watcher has not been used yet",
"// revno: 0 means that *all* transactions prior to the first",
"// Next() call will be reflected in the deltas.",
"// stopped: false means that the watcher immediately starts off",
"// handling changes.",
"return",
"&",
"Multiwatcher",
"{",
"all",
":",
"all",
",",
"used",
":",
"false",
",",
"revno",
":",
"0",
",",
"stopped",
":",
"false",
",",
"}",
"\n",
"}"
] | // NewMultiwatcher creates a new watcher that can observe
// changes to an underlying store manager. | [
"NewMultiwatcher",
"creates",
"a",
"new",
"watcher",
"that",
"can",
"observe",
"changes",
"to",
"an",
"underlying",
"store",
"manager",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L34-L48 |
155,495 | juju/juju | state/multiwatcher.go | newStoreManagerNoRun | func newStoreManagerNoRun(backing Backing) *storeManager {
return &storeManager{
backing: backing,
request: make(chan *request),
all: newStore(),
waiting: make(map[*Multiwatcher]*request),
}
} | go | func newStoreManagerNoRun(backing Backing) *storeManager {
return &storeManager{
backing: backing,
request: make(chan *request),
all: newStore(),
waiting: make(map[*Multiwatcher]*request),
}
} | [
"func",
"newStoreManagerNoRun",
"(",
"backing",
"Backing",
")",
"*",
"storeManager",
"{",
"return",
"&",
"storeManager",
"{",
"backing",
":",
"backing",
",",
"request",
":",
"make",
"(",
"chan",
"*",
"request",
")",
",",
"all",
":",
"newStore",
"(",
")",
",",
"waiting",
":",
"make",
"(",
"map",
"[",
"*",
"Multiwatcher",
"]",
"*",
"request",
")",
",",
"}",
"\n",
"}"
] | // newStoreManagerNoRun creates the store manager
// but does not start its run loop. | [
"newStoreManagerNoRun",
"creates",
"the",
"store",
"manager",
"but",
"does",
"not",
"start",
"its",
"run",
"loop",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L178-L185 |
155,496 | juju/juju | state/multiwatcher.go | newDeadStoreManager | func newDeadStoreManager(err error) *storeManager {
var m storeManager
m.tomb.Kill(errors.Trace(err))
return &m
} | go | func newDeadStoreManager(err error) *storeManager {
var m storeManager
m.tomb.Kill(errors.Trace(err))
return &m
} | [
"func",
"newDeadStoreManager",
"(",
"err",
"error",
")",
"*",
"storeManager",
"{",
"var",
"m",
"storeManager",
"\n",
"m",
".",
"tomb",
".",
"Kill",
"(",
"errors",
".",
"Trace",
"(",
"err",
")",
")",
"\n",
"return",
"&",
"m",
"\n",
"}"
] | // newDeadStoreManager returns a store manager instance
// that is already dead and always returns the given error. | [
"newDeadStoreManager",
"returns",
"a",
"store",
"manager",
"instance",
"that",
"is",
"already",
"dead",
"and",
"always",
"returns",
"the",
"given",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L189-L193 |
155,497 | juju/juju | state/multiwatcher.go | newStoreManager | func newStoreManager(backing Backing) *storeManager {
sm := newStoreManagerNoRun(backing)
sm.tomb.Go(func() error {
// TODO(rog) distinguish between temporary and permanent errors:
// if we get an error in loop, this logic kill the state's storeManager
// forever. This currently fits the way we go about things,
// because we reconnect to the state on any error, but
// perhaps there are errors we could recover from.
err := sm.loop()
cause := errors.Cause(err)
// tomb expects ErrDying or ErrStillAlive as
// exact values, so we need to log and unwrap
// the error first.
if err != nil && cause != tomb.ErrDying {
logger.Infof("store manager loop failed: %v", err)
}
return cause
})
return sm
} | go | func newStoreManager(backing Backing) *storeManager {
sm := newStoreManagerNoRun(backing)
sm.tomb.Go(func() error {
// TODO(rog) distinguish between temporary and permanent errors:
// if we get an error in loop, this logic kill the state's storeManager
// forever. This currently fits the way we go about things,
// because we reconnect to the state on any error, but
// perhaps there are errors we could recover from.
err := sm.loop()
cause := errors.Cause(err)
// tomb expects ErrDying or ErrStillAlive as
// exact values, so we need to log and unwrap
// the error first.
if err != nil && cause != tomb.ErrDying {
logger.Infof("store manager loop failed: %v", err)
}
return cause
})
return sm
} | [
"func",
"newStoreManager",
"(",
"backing",
"Backing",
")",
"*",
"storeManager",
"{",
"sm",
":=",
"newStoreManagerNoRun",
"(",
"backing",
")",
"\n",
"sm",
".",
"tomb",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"// TODO(rog) distinguish between temporary and permanent errors:",
"// if we get an error in loop, this logic kill the state's storeManager",
"// forever. This currently fits the way we go about things,",
"// because we reconnect to the state on any error, but",
"// perhaps there are errors we could recover from.",
"err",
":=",
"sm",
".",
"loop",
"(",
")",
"\n",
"cause",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
"\n",
"// tomb expects ErrDying or ErrStillAlive as",
"// exact values, so we need to log and unwrap",
"// the error first.",
"if",
"err",
"!=",
"nil",
"&&",
"cause",
"!=",
"tomb",
".",
"ErrDying",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"cause",
"\n",
"}",
")",
"\n",
"return",
"sm",
"\n",
"}"
] | // newStoreManager returns a new storeManager that retrieves information
// using the given backing. | [
"newStoreManager",
"returns",
"a",
"new",
"storeManager",
"that",
"retrieves",
"information",
"using",
"the",
"given",
"backing",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L197-L217 |
155,498 | juju/juju | state/multiwatcher.go | handle | func (sm *storeManager) handle(req *request) {
if req.w.stopped {
// The watcher has previously been stopped.
if req.reply != nil {
select {
case req.reply <- false:
case <-sm.tomb.Dying():
}
}
return
}
if req.reply == nil {
// This is a request to stop the watcher.
for req := sm.waiting[req.w]; req != nil; req = req.next {
select {
case req.reply <- false:
case <-sm.tomb.Dying():
}
}
delete(sm.waiting, req.w)
req.w.stopped = true
sm.leave(req.w)
return
}
// Add request to head of list.
req.next = sm.waiting[req.w]
sm.waiting[req.w] = req
} | go | func (sm *storeManager) handle(req *request) {
if req.w.stopped {
// The watcher has previously been stopped.
if req.reply != nil {
select {
case req.reply <- false:
case <-sm.tomb.Dying():
}
}
return
}
if req.reply == nil {
// This is a request to stop the watcher.
for req := sm.waiting[req.w]; req != nil; req = req.next {
select {
case req.reply <- false:
case <-sm.tomb.Dying():
}
}
delete(sm.waiting, req.w)
req.w.stopped = true
sm.leave(req.w)
return
}
// Add request to head of list.
req.next = sm.waiting[req.w]
sm.waiting[req.w] = req
} | [
"func",
"(",
"sm",
"*",
"storeManager",
")",
"handle",
"(",
"req",
"*",
"request",
")",
"{",
"if",
"req",
".",
"w",
".",
"stopped",
"{",
"// The watcher has previously been stopped.",
"if",
"req",
".",
"reply",
"!=",
"nil",
"{",
"select",
"{",
"case",
"req",
".",
"reply",
"<-",
"false",
":",
"case",
"<-",
"sm",
".",
"tomb",
".",
"Dying",
"(",
")",
":",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"req",
".",
"reply",
"==",
"nil",
"{",
"// This is a request to stop the watcher.",
"for",
"req",
":=",
"sm",
".",
"waiting",
"[",
"req",
".",
"w",
"]",
";",
"req",
"!=",
"nil",
";",
"req",
"=",
"req",
".",
"next",
"{",
"select",
"{",
"case",
"req",
".",
"reply",
"<-",
"false",
":",
"case",
"<-",
"sm",
".",
"tomb",
".",
"Dying",
"(",
")",
":",
"}",
"\n",
"}",
"\n",
"delete",
"(",
"sm",
".",
"waiting",
",",
"req",
".",
"w",
")",
"\n",
"req",
".",
"w",
".",
"stopped",
"=",
"true",
"\n",
"sm",
".",
"leave",
"(",
"req",
".",
"w",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// Add request to head of list.",
"req",
".",
"next",
"=",
"sm",
".",
"waiting",
"[",
"req",
".",
"w",
"]",
"\n",
"sm",
".",
"waiting",
"[",
"req",
".",
"w",
"]",
"=",
"req",
"\n",
"}"
] | // handle processes a request from a Multiwatcher to the storeManager. | [
"handle",
"processes",
"a",
"request",
"from",
"a",
"Multiwatcher",
"to",
"the",
"storeManager",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L263-L290 |
155,499 | juju/juju | state/multiwatcher.go | respond | func (sm *storeManager) respond() {
for w, req := range sm.waiting {
revno := w.revno
changes := sm.all.ChangesSince(revno)
if len(changes) == 0 {
if req.noChanges != nil {
req.noChanges <- struct{}{}
sm.removeWaitingReq(w, req)
}
continue
}
req.changes = changes
w.revno = sm.all.latestRevno
select {
case req.reply <- true:
case <-sm.tomb.Dying():
}
sm.removeWaitingReq(w, req)
sm.seen(revno)
}
} | go | func (sm *storeManager) respond() {
for w, req := range sm.waiting {
revno := w.revno
changes := sm.all.ChangesSince(revno)
if len(changes) == 0 {
if req.noChanges != nil {
req.noChanges <- struct{}{}
sm.removeWaitingReq(w, req)
}
continue
}
req.changes = changes
w.revno = sm.all.latestRevno
select {
case req.reply <- true:
case <-sm.tomb.Dying():
}
sm.removeWaitingReq(w, req)
sm.seen(revno)
}
} | [
"func",
"(",
"sm",
"*",
"storeManager",
")",
"respond",
"(",
")",
"{",
"for",
"w",
",",
"req",
":=",
"range",
"sm",
".",
"waiting",
"{",
"revno",
":=",
"w",
".",
"revno",
"\n",
"changes",
":=",
"sm",
".",
"all",
".",
"ChangesSince",
"(",
"revno",
")",
"\n",
"if",
"len",
"(",
"changes",
")",
"==",
"0",
"{",
"if",
"req",
".",
"noChanges",
"!=",
"nil",
"{",
"req",
".",
"noChanges",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"sm",
".",
"removeWaitingReq",
"(",
"w",
",",
"req",
")",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n\n",
"req",
".",
"changes",
"=",
"changes",
"\n",
"w",
".",
"revno",
"=",
"sm",
".",
"all",
".",
"latestRevno",
"\n",
"select",
"{",
"case",
"req",
".",
"reply",
"<-",
"true",
":",
"case",
"<-",
"sm",
".",
"tomb",
".",
"Dying",
"(",
")",
":",
"}",
"\n",
"sm",
".",
"removeWaitingReq",
"(",
"w",
",",
"req",
")",
"\n",
"sm",
".",
"seen",
"(",
"revno",
")",
"\n",
"}",
"\n",
"}"
] | // respond responds to all outstanding requests that are satisfiable. | [
"respond",
"responds",
"to",
"all",
"outstanding",
"requests",
"that",
"are",
"satisfiable",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L293-L314 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.