id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
3,500
juju/juju
provider/common/mocks/zoned_environ.go
DestroyController
func (m *MockZonedEnviron) DestroyController(arg0 context.ProviderCallContext, arg1 string) error { ret := m.ctrl.Call(m, "DestroyController", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockZonedEnviron) DestroyController(arg0 context.ProviderCallContext, arg1 string) error { ret := m.ctrl.Call(m, "DestroyController", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "DestroyController", "(", "arg0", "context", ".", "ProviderCallContext", ",", "arg1", "string", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// DestroyController mocks base method
[ "DestroyController", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L171-L175
3,501
juju/juju
provider/common/mocks/zoned_environ.go
InstanceTypes
func (m *MockZonedEnviron) InstanceTypes(arg0 context.ProviderCallContext, arg1 constraints.Value) (instances.InstanceTypesWithCostMetadata, error) { ret := m.ctrl.Call(m, "InstanceTypes", arg0, arg1) ret0, _ := ret[0].(instances.InstanceTypesWithCostMetadata) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockZonedEnviron) InstanceTypes(arg0 context.ProviderCallContext, arg1 constraints.Value) (instances.InstanceTypesWithCostMetadata, error) { ret := m.ctrl.Call(m, "InstanceTypes", arg0, arg1) ret0, _ := ret[0].(instances.InstanceTypesWithCostMetadata) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "InstanceTypes", "(", "arg0", "context", ".", "ProviderCallContext", ",", "arg1", "constraints", ".", "Value", ")", "(", "instances", ".", "InstanceTypesWithCostMetadata", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "instances", ".", "InstanceTypesWithCostMetadata", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// InstanceTypes mocks base method
[ "InstanceTypes", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L196-L201
3,502
juju/juju
provider/common/mocks/zoned_environ.go
Instances
func (m *MockZonedEnviron) Instances(arg0 context.ProviderCallContext, arg1 []instance.Id) ([]instances.Instance, error) { ret := m.ctrl.Call(m, "Instances", arg0, arg1) ret0, _ := ret[0].([]instances.Instance) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockZonedEnviron) Instances(arg0 context.ProviderCallContext, arg1 []instance.Id) ([]instances.Instance, error) { ret := m.ctrl.Call(m, "Instances", arg0, arg1) ret0, _ := ret[0].([]instances.Instance) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "Instances", "(", "arg0", "context", ".", "ProviderCallContext", ",", "arg1", "[", "]", "instance", ".", "Id", ")", "(", "[", "]", "instances", ".", "Instance", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "[", "]", "instances", ".", "Instance", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// Instances mocks base method
[ "Instances", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L209-L214
3,503
juju/juju
provider/common/mocks/zoned_environ.go
MaintainInstance
func (m *MockZonedEnviron) MaintainInstance(arg0 context.ProviderCallContext, arg1 environs.StartInstanceParams) error { ret := m.ctrl.Call(m, "MaintainInstance", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockZonedEnviron) MaintainInstance(arg0 context.ProviderCallContext, arg1 environs.StartInstanceParams) error { ret := m.ctrl.Call(m, "MaintainInstance", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "MaintainInstance", "(", "arg0", "context", ".", "ProviderCallContext", ",", "arg1", "environs", ".", "StartInstanceParams", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// MaintainInstance mocks base method
[ "MaintainInstance", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L222-L226
3,504
juju/juju
provider/common/mocks/zoned_environ.go
PrecheckInstance
func (m *MockZonedEnviron) PrecheckInstance(arg0 context.ProviderCallContext, arg1 environs.PrecheckInstanceParams) error { ret := m.ctrl.Call(m, "PrecheckInstance", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockZonedEnviron) PrecheckInstance(arg0 context.ProviderCallContext, arg1 environs.PrecheckInstanceParams) error { ret := m.ctrl.Call(m, "PrecheckInstance", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "PrecheckInstance", "(", "arg0", "context", ".", "ProviderCallContext", ",", "arg1", "environs", ".", "PrecheckInstanceParams", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// PrecheckInstance mocks base method
[ "PrecheckInstance", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L234-L238
3,505
juju/juju
provider/common/mocks/zoned_environ.go
PrepareForBootstrap
func (m *MockZonedEnviron) PrepareForBootstrap(arg0 environs.BootstrapContext, arg1 string) error { ret := m.ctrl.Call(m, "PrepareForBootstrap", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockZonedEnviron) PrepareForBootstrap(arg0 environs.BootstrapContext, arg1 string) error { ret := m.ctrl.Call(m, "PrepareForBootstrap", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "PrepareForBootstrap", "(", "arg0", "environs", ".", "BootstrapContext", ",", "arg1", "string", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// PrepareForBootstrap mocks base method
[ "PrepareForBootstrap", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L246-L250
3,506
juju/juju
provider/common/mocks/zoned_environ.go
Provider
func (m *MockZonedEnviron) Provider() environs.EnvironProvider { ret := m.ctrl.Call(m, "Provider") ret0, _ := ret[0].(environs.EnvironProvider) return ret0 }
go
func (m *MockZonedEnviron) Provider() environs.EnvironProvider { ret := m.ctrl.Call(m, "Provider") ret0, _ := ret[0].(environs.EnvironProvider) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "Provider", "(", ")", "environs", ".", "EnvironProvider", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "environs", ".", "EnvironProvider", ")", "\n", "return", "ret0", "\n", "}" ]
// Provider mocks base method
[ "Provider", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L258-L262
3,507
juju/juju
provider/common/mocks/zoned_environ.go
SetConfig
func (m *MockZonedEnviron) SetConfig(arg0 *config.Config) error { ret := m.ctrl.Call(m, "SetConfig", arg0) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockZonedEnviron) SetConfig(arg0 *config.Config) error { ret := m.ctrl.Call(m, "SetConfig", arg0) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "SetConfig", "(", "arg0", "*", "config", ".", "Config", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// SetConfig mocks base method
[ "SetConfig", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L270-L274
3,508
juju/juju
provider/common/mocks/zoned_environ.go
StopInstances
func (m *MockZonedEnviron) StopInstances(arg0 context.ProviderCallContext, arg1 ...instance.Id) error { varargs := []interface{}{arg0} for _, a := range arg1 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "StopInstances", varargs...) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockZonedEnviron) StopInstances(arg0 context.ProviderCallContext, arg1 ...instance.Id) error { varargs := []interface{}{arg0} for _, a := range arg1 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "StopInstances", varargs...) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "StopInstances", "(", "arg0", "context", ".", "ProviderCallContext", ",", "arg1", "...", "instance", ".", "Id", ")", "error", "{", "varargs", ":=", "[", "]", "interface", "{", "}", "{", "arg0", "}", "\n", "for", "_", ",", "a", ":=", "range", "arg1", "{", "varargs", "=", "append", "(", "varargs", ",", "a", ")", "\n", "}", "\n", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "varargs", "...", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// StopInstances mocks base method
[ "StopInstances", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L295-L303
3,509
juju/juju
provider/common/mocks/zoned_environ.go
StorageProvider
func (m *MockZonedEnviron) StorageProvider(arg0 storage.ProviderType) (storage.Provider, error) { ret := m.ctrl.Call(m, "StorageProvider", arg0) ret0, _ := ret[0].(storage.Provider) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockZonedEnviron) StorageProvider(arg0 storage.ProviderType) (storage.Provider, error) { ret := m.ctrl.Call(m, "StorageProvider", arg0) ret0, _ := ret[0].(storage.Provider) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "StorageProvider", "(", "arg0", "storage", ".", "ProviderType", ")", "(", "storage", ".", "Provider", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "storage", ".", "Provider", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// StorageProvider mocks base method
[ "StorageProvider", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L312-L317
3,510
juju/juju
provider/common/mocks/zoned_environ.go
StorageProvider
func (mr *MockZonedEnvironMockRecorder) StorageProvider(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StorageProvider", reflect.TypeOf((*MockZonedEnviron)(nil).StorageProvider), arg0) }
go
func (mr *MockZonedEnvironMockRecorder) StorageProvider(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StorageProvider", reflect.TypeOf((*MockZonedEnviron)(nil).StorageProvider), arg0) }
[ "func", "(", "mr", "*", "MockZonedEnvironMockRecorder", ")", "StorageProvider", "(", "arg0", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockZonedEnviron", ")", "(", "nil", ")", ".", "StorageProvider", ")", ",", "arg0", ")", "\n", "}" ]
// StorageProvider indicates an expected call of StorageProvider
[ "StorageProvider", "indicates", "an", "expected", "call", "of", "StorageProvider" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L320-L322
3,511
juju/juju
provider/common/mocks/zoned_environ.go
StorageProviderTypes
func (m *MockZonedEnviron) StorageProviderTypes() ([]storage.ProviderType, error) { ret := m.ctrl.Call(m, "StorageProviderTypes") ret0, _ := ret[0].([]storage.ProviderType) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockZonedEnviron) StorageProviderTypes() ([]storage.ProviderType, error) { ret := m.ctrl.Call(m, "StorageProviderTypes") ret0, _ := ret[0].([]storage.ProviderType) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockZonedEnviron", ")", "StorageProviderTypes", "(", ")", "(", "[", "]", "storage", ".", "ProviderType", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "[", "]", "storage", ".", "ProviderType", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// StorageProviderTypes mocks base method
[ "StorageProviderTypes", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/mocks/zoned_environ.go#L325-L330
3,512
juju/juju
worker/uniter/runner/jujuc/storage-add.go
NewStorageAddCommand
func NewStorageAddCommand(ctx Context) (cmd.Command, error) { return &StorageAddCommand{ctx: ctx}, nil }
go
func NewStorageAddCommand(ctx Context) (cmd.Command, error) { return &StorageAddCommand{ctx: ctx}, nil }
[ "func", "NewStorageAddCommand", "(", "ctx", "Context", ")", "(", "cmd", ".", "Command", ",", "error", ")", "{", "return", "&", "StorageAddCommand", "{", "ctx", ":", "ctx", "}", ",", "nil", "\n", "}" ]
// NewStorageAddCommand makes a jujuc storage-add command.
[ "NewStorageAddCommand", "makes", "a", "jujuc", "storage", "-", "add", "command", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/jujuc/storage-add.go#L23-L25
3,513
juju/juju
cmd/jujud/agent/machine/manifolds.go
IAASManifolds
func IAASManifolds(config ManifoldsConfig) dependency.Manifolds { var externalUpdateProxyFunc func(proxy.Settings) error if runtime.GOOS == "linux" { externalUpdateProxyFunc = lxd.ConfigureLXDProxies } manifolds := dependency.Manifolds{ toolsVersionCheckerName: ifNotMigrating(toolsversionchecker.Manifold(toolsversionchecker.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, })), authenticationWorkerName: ifNotMigrating(authenticationworker.Manifold(authenticationworker.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, })), // The proxy config updater is a leaf worker that sets http/https/apt/etc // proxy settings. proxyConfigUpdater: ifNotMigrating(proxyupdater.Manifold(proxyupdater.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, Logger: loggo.GetLogger("juju.worker.proxyupdater"), WorkerFunc: proxyupdater.NewWorker, ExternalUpdate: externalUpdateProxyFunc, InProcessUpdate: proxyconfig.DefaultConfig.Set, RunFunc: proxyupdater.RunWithStdIn, })), hostKeyReporterName: ifNotMigrating(hostkeyreporter.Manifold(hostkeyreporter.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, RootDir: config.RootDir, NewFacade: hostkeyreporter.NewFacade, NewWorker: hostkeyreporter.NewWorker, })), // The upgrader is a leaf worker that returns a specific error // type recognised by the machine agent, causing other workers // to be stopped and the agent to be restarted running the new // tools. We should only need one of these in a consolidated // agent, but we'll need to be careful about behavioural // differences, and interactions with the upgrade-steps // worker. upgraderName: upgrader.Manifold(upgrader.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, UpgradeStepsGateName: upgradeStepsGateName, UpgradeCheckGateName: upgradeCheckGateName, PreviousAgentVersion: config.PreviousAgentVersion, }), upgradeSeriesWorkerName: ifNotMigrating(upgradeseries.Manifold(upgradeseries.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, Logger: loggo.GetLogger("juju.worker.upgradeseries"), NewFacade: upgradeseries.NewFacade, NewWorker: upgradeseries.NewWorker, })), // The deployer worker is primary for deploying and recalling unit // agents, according to changes in a set of state units; and for the // final removal of its agents' units from state when they are no // longer needed. deployerName: ifNotMigrating(deployer.Manifold(deployer.ManifoldConfig{ NewDeployContext: config.NewDeployContext, AgentName: agentName, APICallerName: apiCallerName, })), // The reboot manifold manages a worker which will reboot the // machine when requested. It needs an API connection and // waits for upgrades to be complete. rebootName: ifNotMigrating(reboot.Manifold(reboot.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, MachineLock: config.MachineLock, Clock: config.Clock, })), // The storageProvisioner worker manages provisioning // (deprovisioning), and attachment (detachment) of first-class // volumes and filesystems. storageProvisionerName: ifNotMigrating(ifCredentialValid(storageprovisioner.MachineManifold(storageprovisioner.MachineManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, Clock: config.Clock, NewCredentialValidatorFacade: common.NewCredentialInvalidatorFacade, }))), brokerTrackerName: ifNotMigrating(lxdbroker.Manifold(lxdbroker.ManifoldConfig{ APICallerName: apiCallerName, AgentName: agentName, MachineLock: config.MachineLock, NewBrokerFunc: config.NewBrokerFunc, NewTracker: lxdbroker.NewWorkerTracker, })), instanceMutaterName: ifNotMigrating(instancemutater.MachineManifold(instancemutater.MachineManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, BrokerName: brokerTrackerName, Logger: loggo.GetLogger("juju.worker.instancemutater"), NewClient: instancemutater.NewClient, NewWorker: instancemutater.NewContainerWorker, })), } return mergeManifolds(config, manifolds) }
go
func IAASManifolds(config ManifoldsConfig) dependency.Manifolds { var externalUpdateProxyFunc func(proxy.Settings) error if runtime.GOOS == "linux" { externalUpdateProxyFunc = lxd.ConfigureLXDProxies } manifolds := dependency.Manifolds{ toolsVersionCheckerName: ifNotMigrating(toolsversionchecker.Manifold(toolsversionchecker.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, })), authenticationWorkerName: ifNotMigrating(authenticationworker.Manifold(authenticationworker.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, })), // The proxy config updater is a leaf worker that sets http/https/apt/etc // proxy settings. proxyConfigUpdater: ifNotMigrating(proxyupdater.Manifold(proxyupdater.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, Logger: loggo.GetLogger("juju.worker.proxyupdater"), WorkerFunc: proxyupdater.NewWorker, ExternalUpdate: externalUpdateProxyFunc, InProcessUpdate: proxyconfig.DefaultConfig.Set, RunFunc: proxyupdater.RunWithStdIn, })), hostKeyReporterName: ifNotMigrating(hostkeyreporter.Manifold(hostkeyreporter.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, RootDir: config.RootDir, NewFacade: hostkeyreporter.NewFacade, NewWorker: hostkeyreporter.NewWorker, })), // The upgrader is a leaf worker that returns a specific error // type recognised by the machine agent, causing other workers // to be stopped and the agent to be restarted running the new // tools. We should only need one of these in a consolidated // agent, but we'll need to be careful about behavioural // differences, and interactions with the upgrade-steps // worker. upgraderName: upgrader.Manifold(upgrader.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, UpgradeStepsGateName: upgradeStepsGateName, UpgradeCheckGateName: upgradeCheckGateName, PreviousAgentVersion: config.PreviousAgentVersion, }), upgradeSeriesWorkerName: ifNotMigrating(upgradeseries.Manifold(upgradeseries.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, Logger: loggo.GetLogger("juju.worker.upgradeseries"), NewFacade: upgradeseries.NewFacade, NewWorker: upgradeseries.NewWorker, })), // The deployer worker is primary for deploying and recalling unit // agents, according to changes in a set of state units; and for the // final removal of its agents' units from state when they are no // longer needed. deployerName: ifNotMigrating(deployer.Manifold(deployer.ManifoldConfig{ NewDeployContext: config.NewDeployContext, AgentName: agentName, APICallerName: apiCallerName, })), // The reboot manifold manages a worker which will reboot the // machine when requested. It needs an API connection and // waits for upgrades to be complete. rebootName: ifNotMigrating(reboot.Manifold(reboot.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, MachineLock: config.MachineLock, Clock: config.Clock, })), // The storageProvisioner worker manages provisioning // (deprovisioning), and attachment (detachment) of first-class // volumes and filesystems. storageProvisionerName: ifNotMigrating(ifCredentialValid(storageprovisioner.MachineManifold(storageprovisioner.MachineManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, Clock: config.Clock, NewCredentialValidatorFacade: common.NewCredentialInvalidatorFacade, }))), brokerTrackerName: ifNotMigrating(lxdbroker.Manifold(lxdbroker.ManifoldConfig{ APICallerName: apiCallerName, AgentName: agentName, MachineLock: config.MachineLock, NewBrokerFunc: config.NewBrokerFunc, NewTracker: lxdbroker.NewWorkerTracker, })), instanceMutaterName: ifNotMigrating(instancemutater.MachineManifold(instancemutater.MachineManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, BrokerName: brokerTrackerName, Logger: loggo.GetLogger("juju.worker.instancemutater"), NewClient: instancemutater.NewClient, NewWorker: instancemutater.NewContainerWorker, })), } return mergeManifolds(config, manifolds) }
[ "func", "IAASManifolds", "(", "config", "ManifoldsConfig", ")", "dependency", ".", "Manifolds", "{", "var", "externalUpdateProxyFunc", "func", "(", "proxy", ".", "Settings", ")", "error", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "externalUpdateProxyFunc", "=", "lxd", ".", "ConfigureLXDProxies", "\n", "}", "\n", "manifolds", ":=", "dependency", ".", "Manifolds", "{", "toolsVersionCheckerName", ":", "ifNotMigrating", "(", "toolsversionchecker", ".", "Manifold", "(", "toolsversionchecker", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "}", ")", ")", ",", "authenticationWorkerName", ":", "ifNotMigrating", "(", "authenticationworker", ".", "Manifold", "(", "authenticationworker", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "}", ")", ")", ",", "// The proxy config updater is a leaf worker that sets http/https/apt/etc", "// proxy settings.", "proxyConfigUpdater", ":", "ifNotMigrating", "(", "proxyupdater", ".", "Manifold", "(", "proxyupdater", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "Logger", ":", "loggo", ".", "GetLogger", "(", "\"", "\"", ")", ",", "WorkerFunc", ":", "proxyupdater", ".", "NewWorker", ",", "ExternalUpdate", ":", "externalUpdateProxyFunc", ",", "InProcessUpdate", ":", "proxyconfig", ".", "DefaultConfig", ".", "Set", ",", "RunFunc", ":", "proxyupdater", ".", "RunWithStdIn", ",", "}", ")", ")", ",", "hostKeyReporterName", ":", "ifNotMigrating", "(", "hostkeyreporter", ".", "Manifold", "(", "hostkeyreporter", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "RootDir", ":", "config", ".", "RootDir", ",", "NewFacade", ":", "hostkeyreporter", ".", "NewFacade", ",", "NewWorker", ":", "hostkeyreporter", ".", "NewWorker", ",", "}", ")", ")", ",", "// The upgrader is a leaf worker that returns a specific error", "// type recognised by the machine agent, causing other workers", "// to be stopped and the agent to be restarted running the new", "// tools. We should only need one of these in a consolidated", "// agent, but we'll need to be careful about behavioural", "// differences, and interactions with the upgrade-steps", "// worker.", "upgraderName", ":", "upgrader", ".", "Manifold", "(", "upgrader", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "UpgradeStepsGateName", ":", "upgradeStepsGateName", ",", "UpgradeCheckGateName", ":", "upgradeCheckGateName", ",", "PreviousAgentVersion", ":", "config", ".", "PreviousAgentVersion", ",", "}", ")", ",", "upgradeSeriesWorkerName", ":", "ifNotMigrating", "(", "upgradeseries", ".", "Manifold", "(", "upgradeseries", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "Logger", ":", "loggo", ".", "GetLogger", "(", "\"", "\"", ")", ",", "NewFacade", ":", "upgradeseries", ".", "NewFacade", ",", "NewWorker", ":", "upgradeseries", ".", "NewWorker", ",", "}", ")", ")", ",", "// The deployer worker is primary for deploying and recalling unit", "// agents, according to changes in a set of state units; and for the", "// final removal of its agents' units from state when they are no", "// longer needed.", "deployerName", ":", "ifNotMigrating", "(", "deployer", ".", "Manifold", "(", "deployer", ".", "ManifoldConfig", "{", "NewDeployContext", ":", "config", ".", "NewDeployContext", ",", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "}", ")", ")", ",", "// The reboot manifold manages a worker which will reboot the", "// machine when requested. It needs an API connection and", "// waits for upgrades to be complete.", "rebootName", ":", "ifNotMigrating", "(", "reboot", ".", "Manifold", "(", "reboot", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "MachineLock", ":", "config", ".", "MachineLock", ",", "Clock", ":", "config", ".", "Clock", ",", "}", ")", ")", ",", "// The storageProvisioner worker manages provisioning", "// (deprovisioning), and attachment (detachment) of first-class", "// volumes and filesystems.", "storageProvisionerName", ":", "ifNotMigrating", "(", "ifCredentialValid", "(", "storageprovisioner", ".", "MachineManifold", "(", "storageprovisioner", ".", "MachineManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "Clock", ":", "config", ".", "Clock", ",", "NewCredentialValidatorFacade", ":", "common", ".", "NewCredentialInvalidatorFacade", ",", "}", ")", ")", ")", ",", "brokerTrackerName", ":", "ifNotMigrating", "(", "lxdbroker", ".", "Manifold", "(", "lxdbroker", ".", "ManifoldConfig", "{", "APICallerName", ":", "apiCallerName", ",", "AgentName", ":", "agentName", ",", "MachineLock", ":", "config", ".", "MachineLock", ",", "NewBrokerFunc", ":", "config", ".", "NewBrokerFunc", ",", "NewTracker", ":", "lxdbroker", ".", "NewWorkerTracker", ",", "}", ")", ")", ",", "instanceMutaterName", ":", "ifNotMigrating", "(", "instancemutater", ".", "MachineManifold", "(", "instancemutater", ".", "MachineManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "BrokerName", ":", "brokerTrackerName", ",", "Logger", ":", "loggo", ".", "GetLogger", "(", "\"", "\"", ")", ",", "NewClient", ":", "instancemutater", ".", "NewClient", ",", "NewWorker", ":", "instancemutater", ".", "NewContainerWorker", ",", "}", ")", ")", ",", "}", "\n\n", "return", "mergeManifolds", "(", "config", ",", "manifolds", ")", "\n", "}" ]
// IAASManifolds returns a set of co-configured manifolds covering the // various responsibilities of a IAAS machine agent.
[ "IAASManifolds", "returns", "a", "set", "of", "co", "-", "configured", "manifolds", "covering", "the", "various", "responsibilities", "of", "a", "IAAS", "machine", "agent", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/machine/manifolds.go#L847-L953
3,514
juju/juju
cmd/jujud/agent/machine/manifolds.go
CAASManifolds
func CAASManifolds(config ManifoldsConfig) dependency.Manifolds { return mergeManifolds(config, dependency.Manifolds{ // TODO(caas) - when we support HA, only want this on primary upgraderName: caasupgrader.Manifold(caasupgrader.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, UpgradeStepsGateName: upgradeStepsGateName, UpgradeCheckGateName: upgradeCheckGateName, PreviousAgentVersion: config.PreviousAgentVersion, }), }) }
go
func CAASManifolds(config ManifoldsConfig) dependency.Manifolds { return mergeManifolds(config, dependency.Manifolds{ // TODO(caas) - when we support HA, only want this on primary upgraderName: caasupgrader.Manifold(caasupgrader.ManifoldConfig{ AgentName: agentName, APICallerName: apiCallerName, UpgradeStepsGateName: upgradeStepsGateName, UpgradeCheckGateName: upgradeCheckGateName, PreviousAgentVersion: config.PreviousAgentVersion, }), }) }
[ "func", "CAASManifolds", "(", "config", "ManifoldsConfig", ")", "dependency", ".", "Manifolds", "{", "return", "mergeManifolds", "(", "config", ",", "dependency", ".", "Manifolds", "{", "// TODO(caas) - when we support HA, only want this on primary", "upgraderName", ":", "caasupgrader", ".", "Manifold", "(", "caasupgrader", ".", "ManifoldConfig", "{", "AgentName", ":", "agentName", ",", "APICallerName", ":", "apiCallerName", ",", "UpgradeStepsGateName", ":", "upgradeStepsGateName", ",", "UpgradeCheckGateName", ":", "upgradeCheckGateName", ",", "PreviousAgentVersion", ":", "config", ".", "PreviousAgentVersion", ",", "}", ")", ",", "}", ")", "\n", "}" ]
// CAASManifolds returns a set of co-configured manifolds covering the // various responsibilities of a CAAS machine agent.
[ "CAASManifolds", "returns", "a", "set", "of", "co", "-", "configured", "manifolds", "covering", "the", "various", "responsibilities", "of", "a", "CAAS", "machine", "agent", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/machine/manifolds.go#L957-L968
3,515
juju/juju
provider/rackspace/firewaller.go
OpenPorts
func (c *rackspaceFirewaller) OpenPorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { return errors.NotSupportedf("OpenPorts") }
go
func (c *rackspaceFirewaller) OpenPorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { return errors.NotSupportedf("OpenPorts") }
[ "func", "(", "c", "*", "rackspaceFirewaller", ")", "OpenPorts", "(", "ctx", "context", ".", "ProviderCallContext", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}" ]
// OpenPorts is not supported.
[ "OpenPorts", "is", "not", "supported", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/rackspace/firewaller.go#L33-L35
3,516
juju/juju
provider/rackspace/firewaller.go
IngressRules
func (c *rackspaceFirewaller) IngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) { return nil, errors.NotSupportedf("Ports") }
go
func (c *rackspaceFirewaller) IngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) { return nil, errors.NotSupportedf("Ports") }
[ "func", "(", "c", "*", "rackspaceFirewaller", ")", "IngressRules", "(", "ctx", "context", ".", "ProviderCallContext", ")", "(", "[", "]", "network", ".", "IngressRule", ",", "error", ")", "{", "return", "nil", ",", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}" ]
// IngressRules returns the port ranges opened for the whole environment. // Must only be used if the environment was setup with the // FwGlobal firewall mode.
[ "IngressRules", "returns", "the", "port", "ranges", "opened", "for", "the", "whole", "environment", ".", "Must", "only", "be", "used", "if", "the", "environment", "was", "setup", "with", "the", "FwGlobal", "firewall", "mode", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/rackspace/firewaller.go#L45-L47
3,517
juju/juju
provider/rackspace/firewaller.go
DeleteGroups
func (c *rackspaceFirewaller) DeleteGroups(ctx context.ProviderCallContext, names ...string) error { return nil }
go
func (c *rackspaceFirewaller) DeleteGroups(ctx context.ProviderCallContext, names ...string) error { return nil }
[ "func", "(", "c", "*", "rackspaceFirewaller", ")", "DeleteGroups", "(", "ctx", "context", ".", "ProviderCallContext", ",", "names", "...", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// DeleteGroups implements OpenstackFirewaller interface.
[ "DeleteGroups", "implements", "OpenstackFirewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/rackspace/firewaller.go#L50-L52
3,518
juju/juju
provider/rackspace/firewaller.go
DeleteAllControllerGroups
func (c *rackspaceFirewaller) DeleteAllControllerGroups(ctx context.ProviderCallContext, controllerUUID string) error { return nil }
go
func (c *rackspaceFirewaller) DeleteAllControllerGroups(ctx context.ProviderCallContext, controllerUUID string) error { return nil }
[ "func", "(", "c", "*", "rackspaceFirewaller", ")", "DeleteAllControllerGroups", "(", "ctx", "context", ".", "ProviderCallContext", ",", "controllerUUID", "string", ")", "error", "{", "return", "nil", "\n", "}" ]
// DeleteAllControllerGroups implements OpenstackFirewaller interface.
[ "DeleteAllControllerGroups", "implements", "OpenstackFirewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/rackspace/firewaller.go#L60-L62
3,519
juju/juju
provider/rackspace/firewaller.go
GetSecurityGroups
func (c *rackspaceFirewaller) GetSecurityGroups(ctx context.ProviderCallContext, ids ...instance.Id) ([]string, error) { return nil, nil }
go
func (c *rackspaceFirewaller) GetSecurityGroups(ctx context.ProviderCallContext, ids ...instance.Id) ([]string, error) { return nil, nil }
[ "func", "(", "c", "*", "rackspaceFirewaller", ")", "GetSecurityGroups", "(", "ctx", "context", ".", "ProviderCallContext", ",", "ids", "...", "instance", ".", "Id", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// GetSecurityGroups implements OpenstackFirewaller interface.
[ "GetSecurityGroups", "implements", "OpenstackFirewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/rackspace/firewaller.go#L69-L71
3,520
juju/juju
provider/rackspace/firewaller.go
SetUpGroups
func (c *rackspaceFirewaller) SetUpGroups(ctx context.ProviderCallContext, controllerUUID, machineId string, apiPort int) ([]string, error) { return nil, nil }
go
func (c *rackspaceFirewaller) SetUpGroups(ctx context.ProviderCallContext, controllerUUID, machineId string, apiPort int) ([]string, error) { return nil, nil }
[ "func", "(", "c", "*", "rackspaceFirewaller", ")", "SetUpGroups", "(", "ctx", "context", ".", "ProviderCallContext", ",", "controllerUUID", ",", "machineId", "string", ",", "apiPort", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// SetUpGroups implements OpenstackFirewaller interface.
[ "SetUpGroups", "implements", "OpenstackFirewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/rackspace/firewaller.go#L74-L76
3,521
juju/juju
worker/storageprovisioner/filesystem_events.go
filesystemsChanged
func filesystemsChanged(ctx *context, changes []string) error { tags := make([]names.Tag, len(changes)) for i, change := range changes { tags[i] = names.NewFilesystemTag(change) } alive, dying, dead, err := storageEntityLife(ctx, tags) if err != nil { return errors.Trace(err) } logger.Debugf("filesystems alive: %v, dying: %v, dead: %v", alive, dying, dead) if len(alive)+len(dying)+len(dead) == 0 { return nil } // Get filesystem information for filesystems, so we can provision, // deprovision, attach and detach. filesystemTags := make([]names.FilesystemTag, 0, len(alive)+len(dying)+len(dead)) for _, tag := range alive { filesystemTags = append(filesystemTags, tag.(names.FilesystemTag)) } for _, tag := range dying { filesystemTags = append(filesystemTags, tag.(names.FilesystemTag)) } for _, tag := range dead { filesystemTags = append(filesystemTags, tag.(names.FilesystemTag)) } filesystemResults, err := ctx.config.Filesystems.Filesystems(filesystemTags) if err != nil { return errors.Annotatef(err, "getting filesystem information") } aliveFilesystemTags := filesystemTags[:len(alive)] dyingFilesystemTags := filesystemTags[len(alive) : len(alive)+len(dying)] deadFilesystemTags := filesystemTags[len(alive)+len(dying):] aliveFilesystemResults := filesystemResults[:len(alive)] dyingFilesystemResults := filesystemResults[len(alive) : len(alive)+len(dying)] deadFilesystemResults := filesystemResults[len(alive)+len(dying):] if err := processDeadFilesystems(ctx, deadFilesystemTags, deadFilesystemResults); err != nil { return errors.Annotate(err, "deprovisioning filesystems") } if err := processDyingFilesystems(ctx, dyingFilesystemTags, dyingFilesystemResults); err != nil { return errors.Annotate(err, "processing dying filesystems") } if err := processAliveFilesystems(ctx, aliveFilesystemTags, aliveFilesystemResults); err != nil { return errors.Annotate(err, "provisioning filesystems") } return nil }
go
func filesystemsChanged(ctx *context, changes []string) error { tags := make([]names.Tag, len(changes)) for i, change := range changes { tags[i] = names.NewFilesystemTag(change) } alive, dying, dead, err := storageEntityLife(ctx, tags) if err != nil { return errors.Trace(err) } logger.Debugf("filesystems alive: %v, dying: %v, dead: %v", alive, dying, dead) if len(alive)+len(dying)+len(dead) == 0 { return nil } // Get filesystem information for filesystems, so we can provision, // deprovision, attach and detach. filesystemTags := make([]names.FilesystemTag, 0, len(alive)+len(dying)+len(dead)) for _, tag := range alive { filesystemTags = append(filesystemTags, tag.(names.FilesystemTag)) } for _, tag := range dying { filesystemTags = append(filesystemTags, tag.(names.FilesystemTag)) } for _, tag := range dead { filesystemTags = append(filesystemTags, tag.(names.FilesystemTag)) } filesystemResults, err := ctx.config.Filesystems.Filesystems(filesystemTags) if err != nil { return errors.Annotatef(err, "getting filesystem information") } aliveFilesystemTags := filesystemTags[:len(alive)] dyingFilesystemTags := filesystemTags[len(alive) : len(alive)+len(dying)] deadFilesystemTags := filesystemTags[len(alive)+len(dying):] aliveFilesystemResults := filesystemResults[:len(alive)] dyingFilesystemResults := filesystemResults[len(alive) : len(alive)+len(dying)] deadFilesystemResults := filesystemResults[len(alive)+len(dying):] if err := processDeadFilesystems(ctx, deadFilesystemTags, deadFilesystemResults); err != nil { return errors.Annotate(err, "deprovisioning filesystems") } if err := processDyingFilesystems(ctx, dyingFilesystemTags, dyingFilesystemResults); err != nil { return errors.Annotate(err, "processing dying filesystems") } if err := processAliveFilesystems(ctx, aliveFilesystemTags, aliveFilesystemResults); err != nil { return errors.Annotate(err, "provisioning filesystems") } return nil }
[ "func", "filesystemsChanged", "(", "ctx", "*", "context", ",", "changes", "[", "]", "string", ")", "error", "{", "tags", ":=", "make", "(", "[", "]", "names", ".", "Tag", ",", "len", "(", "changes", ")", ")", "\n", "for", "i", ",", "change", ":=", "range", "changes", "{", "tags", "[", "i", "]", "=", "names", ".", "NewFilesystemTag", "(", "change", ")", "\n", "}", "\n", "alive", ",", "dying", ",", "dead", ",", "err", ":=", "storageEntityLife", "(", "ctx", ",", "tags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "alive", ",", "dying", ",", "dead", ")", "\n", "if", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", "+", "len", "(", "dead", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "// Get filesystem information for filesystems, so we can provision,", "// deprovision, attach and detach.", "filesystemTags", ":=", "make", "(", "[", "]", "names", ".", "FilesystemTag", ",", "0", ",", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", "+", "len", "(", "dead", ")", ")", "\n", "for", "_", ",", "tag", ":=", "range", "alive", "{", "filesystemTags", "=", "append", "(", "filesystemTags", ",", "tag", ".", "(", "names", ".", "FilesystemTag", ")", ")", "\n", "}", "\n", "for", "_", ",", "tag", ":=", "range", "dying", "{", "filesystemTags", "=", "append", "(", "filesystemTags", ",", "tag", ".", "(", "names", ".", "FilesystemTag", ")", ")", "\n", "}", "\n", "for", "_", ",", "tag", ":=", "range", "dead", "{", "filesystemTags", "=", "append", "(", "filesystemTags", ",", "tag", ".", "(", "names", ".", "FilesystemTag", ")", ")", "\n", "}", "\n", "filesystemResults", ",", "err", ":=", "ctx", ".", "config", ".", "Filesystems", ".", "Filesystems", "(", "filesystemTags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "aliveFilesystemTags", ":=", "filesystemTags", "[", ":", "len", "(", "alive", ")", "]", "\n", "dyingFilesystemTags", ":=", "filesystemTags", "[", "len", "(", "alive", ")", ":", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", "]", "\n", "deadFilesystemTags", ":=", "filesystemTags", "[", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", ":", "]", "\n", "aliveFilesystemResults", ":=", "filesystemResults", "[", ":", "len", "(", "alive", ")", "]", "\n", "dyingFilesystemResults", ":=", "filesystemResults", "[", "len", "(", "alive", ")", ":", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", "]", "\n", "deadFilesystemResults", ":=", "filesystemResults", "[", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", ":", "]", "\n\n", "if", "err", ":=", "processDeadFilesystems", "(", "ctx", ",", "deadFilesystemTags", ",", "deadFilesystemResults", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "processDyingFilesystems", "(", "ctx", ",", "dyingFilesystemTags", ",", "dyingFilesystemResults", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "processAliveFilesystems", "(", "ctx", ",", "aliveFilesystemTags", ",", "aliveFilesystemResults", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// filesystemsChanged is called when the lifecycle states of the filesystems // with the provided IDs have been seen to have changed.
[ "filesystemsChanged", "is", "called", "when", "the", "lifecycle", "states", "of", "the", "filesystems", "with", "the", "provided", "IDs", "have", "been", "seen", "to", "have", "changed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L18-L66
3,522
juju/juju
worker/storageprovisioner/filesystem_events.go
filesystemAttachmentsChanged
func filesystemAttachmentsChanged(ctx *context, watcherIds []watcher.MachineStorageId) error { ids := copyMachineStorageIds(watcherIds) alive, dying, dead, err := attachmentLife(ctx, ids) if err != nil { return errors.Trace(err) } logger.Debugf("filesystem attachment alive: %v, dying: %v, dead: %v", alive, dying, dead) if len(dead) != 0 { // We should not see dead filesystem attachments; // attachments go directly from Dying to removed. logger.Warningf("unexpected dead filesystem attachments: %v", dead) } if len(alive)+len(dying) == 0 { return nil } // Get filesystem information for alive and dying filesystem attachments, so // we can attach/detach. ids = append(alive, dying...) filesystemAttachmentResults, err := ctx.config.Filesystems.FilesystemAttachments(ids) if err != nil { return errors.Annotatef(err, "getting filesystem attachment information") } // Deprovision Dying filesystem attachments. dyingFilesystemAttachmentResults := filesystemAttachmentResults[len(alive):] if err := processDyingFilesystemAttachments(ctx, dying, dyingFilesystemAttachmentResults); err != nil { return errors.Annotate(err, "destroying filesystem attachments") } // Provision Alive filesystem attachments. aliveFilesystemAttachmentResults := filesystemAttachmentResults[:len(alive)] if err := processAliveFilesystemAttachments(ctx, alive, aliveFilesystemAttachmentResults); err != nil { return errors.Annotate(err, "creating filesystem attachments") } return nil }
go
func filesystemAttachmentsChanged(ctx *context, watcherIds []watcher.MachineStorageId) error { ids := copyMachineStorageIds(watcherIds) alive, dying, dead, err := attachmentLife(ctx, ids) if err != nil { return errors.Trace(err) } logger.Debugf("filesystem attachment alive: %v, dying: %v, dead: %v", alive, dying, dead) if len(dead) != 0 { // We should not see dead filesystem attachments; // attachments go directly from Dying to removed. logger.Warningf("unexpected dead filesystem attachments: %v", dead) } if len(alive)+len(dying) == 0 { return nil } // Get filesystem information for alive and dying filesystem attachments, so // we can attach/detach. ids = append(alive, dying...) filesystemAttachmentResults, err := ctx.config.Filesystems.FilesystemAttachments(ids) if err != nil { return errors.Annotatef(err, "getting filesystem attachment information") } // Deprovision Dying filesystem attachments. dyingFilesystemAttachmentResults := filesystemAttachmentResults[len(alive):] if err := processDyingFilesystemAttachments(ctx, dying, dyingFilesystemAttachmentResults); err != nil { return errors.Annotate(err, "destroying filesystem attachments") } // Provision Alive filesystem attachments. aliveFilesystemAttachmentResults := filesystemAttachmentResults[:len(alive)] if err := processAliveFilesystemAttachments(ctx, alive, aliveFilesystemAttachmentResults); err != nil { return errors.Annotate(err, "creating filesystem attachments") } return nil }
[ "func", "filesystemAttachmentsChanged", "(", "ctx", "*", "context", ",", "watcherIds", "[", "]", "watcher", ".", "MachineStorageId", ")", "error", "{", "ids", ":=", "copyMachineStorageIds", "(", "watcherIds", ")", "\n", "alive", ",", "dying", ",", "dead", ",", "err", ":=", "attachmentLife", "(", "ctx", ",", "ids", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "alive", ",", "dying", ",", "dead", ")", "\n", "if", "len", "(", "dead", ")", "!=", "0", "{", "// We should not see dead filesystem attachments;", "// attachments go directly from Dying to removed.", "logger", ".", "Warningf", "(", "\"", "\"", ",", "dead", ")", "\n", "}", "\n", "if", "len", "(", "alive", ")", "+", "len", "(", "dying", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "// Get filesystem information for alive and dying filesystem attachments, so", "// we can attach/detach.", "ids", "=", "append", "(", "alive", ",", "dying", "...", ")", "\n", "filesystemAttachmentResults", ",", "err", ":=", "ctx", ".", "config", ".", "Filesystems", ".", "FilesystemAttachments", "(", "ids", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Deprovision Dying filesystem attachments.", "dyingFilesystemAttachmentResults", ":=", "filesystemAttachmentResults", "[", "len", "(", "alive", ")", ":", "]", "\n", "if", "err", ":=", "processDyingFilesystemAttachments", "(", "ctx", ",", "dying", ",", "dyingFilesystemAttachmentResults", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Provision Alive filesystem attachments.", "aliveFilesystemAttachmentResults", ":=", "filesystemAttachmentResults", "[", ":", "len", "(", "alive", ")", "]", "\n", "if", "err", ":=", "processAliveFilesystemAttachments", "(", "ctx", ",", "alive", ",", "aliveFilesystemAttachmentResults", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// filesystemAttachmentsChanged is called when the lifecycle states of the filesystem // attachments with the provided IDs have been seen to have changed.
[ "filesystemAttachmentsChanged", "is", "called", "when", "the", "lifecycle", "states", "of", "the", "filesystem", "attachments", "with", "the", "provided", "IDs", "have", "been", "seen", "to", "have", "changed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L70-L107
3,523
juju/juju
worker/storageprovisioner/filesystem_events.go
processDyingFilesystems
func processDyingFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error { for _, tag := range tags { removePendingFilesystem(ctx, tag) } return nil }
go
func processDyingFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error { for _, tag := range tags { removePendingFilesystem(ctx, tag) } return nil }
[ "func", "processDyingFilesystems", "(", "ctx", "*", "context", ",", "tags", "[", "]", "names", ".", "FilesystemTag", ",", "filesystemResults", "[", "]", "params", ".", "FilesystemResult", ")", "error", "{", "for", "_", ",", "tag", ":=", "range", "tags", "{", "removePendingFilesystem", "(", "ctx", ",", "tag", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// processDyingFilesystems processes the FilesystemResults for Dying filesystems, // removing them from provisioning-pending as necessary.
[ "processDyingFilesystems", "processes", "the", "FilesystemResults", "for", "Dying", "filesystems", "removing", "them", "from", "provisioning", "-", "pending", "as", "necessary", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L111-L116
3,524
juju/juju
worker/storageprovisioner/filesystem_events.go
updatePendingFilesystemAttachment
func updatePendingFilesystemAttachment( ctx *context, id params.MachineStorageId, params storage.FilesystemAttachmentParams, ) { var incomplete bool filesystem, ok := ctx.filesystems[params.Filesystem] if !ok { incomplete = true } else { params.FilesystemId = filesystem.FilesystemId if filesystem.Volume != (names.VolumeTag{}) { // The filesystem is volume-backed: if the filesystem // was created in another session, then the block device // may not have been seen yet. We must wait for the block // device watcher to trigger. if _, ok := ctx.volumeBlockDevices[filesystem.Volume]; !ok { incomplete = true } } } if params.InstanceId == "" { watchMachine(ctx, params.Machine.(names.MachineTag)) incomplete = true } if params.FilesystemId == "" { incomplete = true } if incomplete { ctx.incompleteFilesystemAttachmentParams[id] = params return } delete(ctx.incompleteFilesystemAttachmentParams, id) scheduleOperations(ctx, &attachFilesystemOp{args: params}) }
go
func updatePendingFilesystemAttachment( ctx *context, id params.MachineStorageId, params storage.FilesystemAttachmentParams, ) { var incomplete bool filesystem, ok := ctx.filesystems[params.Filesystem] if !ok { incomplete = true } else { params.FilesystemId = filesystem.FilesystemId if filesystem.Volume != (names.VolumeTag{}) { // The filesystem is volume-backed: if the filesystem // was created in another session, then the block device // may not have been seen yet. We must wait for the block // device watcher to trigger. if _, ok := ctx.volumeBlockDevices[filesystem.Volume]; !ok { incomplete = true } } } if params.InstanceId == "" { watchMachine(ctx, params.Machine.(names.MachineTag)) incomplete = true } if params.FilesystemId == "" { incomplete = true } if incomplete { ctx.incompleteFilesystemAttachmentParams[id] = params return } delete(ctx.incompleteFilesystemAttachmentParams, id) scheduleOperations(ctx, &attachFilesystemOp{args: params}) }
[ "func", "updatePendingFilesystemAttachment", "(", "ctx", "*", "context", ",", "id", "params", ".", "MachineStorageId", ",", "params", "storage", ".", "FilesystemAttachmentParams", ",", ")", "{", "var", "incomplete", "bool", "\n", "filesystem", ",", "ok", ":=", "ctx", ".", "filesystems", "[", "params", ".", "Filesystem", "]", "\n", "if", "!", "ok", "{", "incomplete", "=", "true", "\n", "}", "else", "{", "params", ".", "FilesystemId", "=", "filesystem", ".", "FilesystemId", "\n", "if", "filesystem", ".", "Volume", "!=", "(", "names", ".", "VolumeTag", "{", "}", ")", "{", "// The filesystem is volume-backed: if the filesystem", "// was created in another session, then the block device", "// may not have been seen yet. We must wait for the block", "// device watcher to trigger.", "if", "_", ",", "ok", ":=", "ctx", ".", "volumeBlockDevices", "[", "filesystem", ".", "Volume", "]", ";", "!", "ok", "{", "incomplete", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "params", ".", "InstanceId", "==", "\"", "\"", "{", "watchMachine", "(", "ctx", ",", "params", ".", "Machine", ".", "(", "names", ".", "MachineTag", ")", ")", "\n", "incomplete", "=", "true", "\n", "}", "\n", "if", "params", ".", "FilesystemId", "==", "\"", "\"", "{", "incomplete", "=", "true", "\n", "}", "\n", "if", "incomplete", "{", "ctx", ".", "incompleteFilesystemAttachmentParams", "[", "id", "]", "=", "params", "\n", "return", "\n", "}", "\n", "delete", "(", "ctx", ".", "incompleteFilesystemAttachmentParams", ",", "id", ")", "\n", "scheduleOperations", "(", "ctx", ",", "&", "attachFilesystemOp", "{", "args", ":", "params", "}", ")", "\n", "}" ]
// updatePendingFilesystemAttachment adds the given filesystem attachment params to // either the incomplete set or the schedule. If the params are incomplete // due to a missing instance ID, updatePendingFilesystemAttachment will request // that the machine be watched so its instance ID can be learned.
[ "updatePendingFilesystemAttachment", "adds", "the", "given", "filesystem", "attachment", "params", "to", "either", "the", "incomplete", "set", "or", "the", "schedule", ".", "If", "the", "params", "are", "incomplete", "due", "to", "a", "missing", "instance", "ID", "updatePendingFilesystemAttachment", "will", "request", "that", "the", "machine", "be", "watched", "so", "its", "instance", "ID", "can", "be", "learned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L155-L189
3,525
juju/juju
worker/storageprovisioner/filesystem_events.go
processDeadFilesystems
func processDeadFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error { for _, tag := range tags { removePendingFilesystem(ctx, tag) } var destroy []names.FilesystemTag var remove []names.Tag for i, result := range filesystemResults { tag := tags[i] if result.Error == nil { logger.Debugf("filesystem %s is provisioned, queuing for deprovisioning", tag.Id()) filesystem, err := filesystemFromParams(result.Result) if err != nil { return errors.Annotate(err, "getting filesystem info") } updateFilesystem(ctx, filesystem) destroy = append(destroy, tag) continue } if params.IsCodeNotProvisioned(result.Error) { logger.Debugf("filesystem %s is not provisioned, queuing for removal", tag.Id()) remove = append(remove, tag) continue } return errors.Annotatef(result.Error, "getting filesystem information for filesystem %s", tag.Id()) } if len(destroy) > 0 { ops := make([]scheduleOp, len(destroy)) for i, tag := range destroy { ops[i] = &removeFilesystemOp{tag: tag} } scheduleOperations(ctx, ops...) } if err := removeEntities(ctx, remove); err != nil { return errors.Annotate(err, "removing filesystems from state") } return nil }
go
func processDeadFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error { for _, tag := range tags { removePendingFilesystem(ctx, tag) } var destroy []names.FilesystemTag var remove []names.Tag for i, result := range filesystemResults { tag := tags[i] if result.Error == nil { logger.Debugf("filesystem %s is provisioned, queuing for deprovisioning", tag.Id()) filesystem, err := filesystemFromParams(result.Result) if err != nil { return errors.Annotate(err, "getting filesystem info") } updateFilesystem(ctx, filesystem) destroy = append(destroy, tag) continue } if params.IsCodeNotProvisioned(result.Error) { logger.Debugf("filesystem %s is not provisioned, queuing for removal", tag.Id()) remove = append(remove, tag) continue } return errors.Annotatef(result.Error, "getting filesystem information for filesystem %s", tag.Id()) } if len(destroy) > 0 { ops := make([]scheduleOp, len(destroy)) for i, tag := range destroy { ops[i] = &removeFilesystemOp{tag: tag} } scheduleOperations(ctx, ops...) } if err := removeEntities(ctx, remove); err != nil { return errors.Annotate(err, "removing filesystems from state") } return nil }
[ "func", "processDeadFilesystems", "(", "ctx", "*", "context", ",", "tags", "[", "]", "names", ".", "FilesystemTag", ",", "filesystemResults", "[", "]", "params", ".", "FilesystemResult", ")", "error", "{", "for", "_", ",", "tag", ":=", "range", "tags", "{", "removePendingFilesystem", "(", "ctx", ",", "tag", ")", "\n", "}", "\n", "var", "destroy", "[", "]", "names", ".", "FilesystemTag", "\n", "var", "remove", "[", "]", "names", ".", "Tag", "\n", "for", "i", ",", "result", ":=", "range", "filesystemResults", "{", "tag", ":=", "tags", "[", "i", "]", "\n", "if", "result", ".", "Error", "==", "nil", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n", "filesystem", ",", "err", ":=", "filesystemFromParams", "(", "result", ".", "Result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "updateFilesystem", "(", "ctx", ",", "filesystem", ")", "\n", "destroy", "=", "append", "(", "destroy", ",", "tag", ")", "\n", "continue", "\n", "}", "\n", "if", "params", ".", "IsCodeNotProvisioned", "(", "result", ".", "Error", ")", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n", "remove", "=", "append", "(", "remove", ",", "tag", ")", "\n", "continue", "\n", "}", "\n", "return", "errors", ".", "Annotatef", "(", "result", ".", "Error", ",", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n", "}", "\n", "if", "len", "(", "destroy", ")", ">", "0", "{", "ops", ":=", "make", "(", "[", "]", "scheduleOp", ",", "len", "(", "destroy", ")", ")", "\n", "for", "i", ",", "tag", ":=", "range", "destroy", "{", "ops", "[", "i", "]", "=", "&", "removeFilesystemOp", "{", "tag", ":", "tag", "}", "\n", "}", "\n", "scheduleOperations", "(", "ctx", ",", "ops", "...", ")", "\n", "}", "\n", "if", "err", ":=", "removeEntities", "(", "ctx", ",", "remove", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// processDeadFilesystems processes the FilesystemResults for Dead filesystems, // deprovisioning filesystems and removing from state as necessary.
[ "processDeadFilesystems", "processes", "the", "FilesystemResults", "for", "Dead", "filesystems", "deprovisioning", "filesystems", "and", "removing", "from", "state", "as", "necessary", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L201-L237
3,526
juju/juju
worker/storageprovisioner/filesystem_events.go
processDyingFilesystemAttachments
func processDyingFilesystemAttachments( ctx *context, ids []params.MachineStorageId, filesystemAttachmentResults []params.FilesystemAttachmentResult, ) error { for _, id := range ids { removePendingFilesystemAttachment(ctx, id) } detach := make([]params.MachineStorageId, 0, len(ids)) remove := make([]params.MachineStorageId, 0, len(ids)) for i, result := range filesystemAttachmentResults { id := ids[i] if result.Error == nil { detach = append(detach, id) continue } if params.IsCodeNotProvisioned(result.Error) { remove = append(remove, id) continue } return errors.Annotatef(result.Error, "getting information for filesystem attachment %v", id) } if len(detach) > 0 { attachmentParams, err := filesystemAttachmentParams(ctx, detach) if err != nil { return errors.Trace(err) } ops := make([]scheduleOp, len(attachmentParams)) for i, p := range attachmentParams { ops[i] = &detachFilesystemOp{args: p} } scheduleOperations(ctx, ops...) } if err := removeAttachments(ctx, remove); err != nil { return errors.Annotate(err, "removing attachments from state") } return nil }
go
func processDyingFilesystemAttachments( ctx *context, ids []params.MachineStorageId, filesystemAttachmentResults []params.FilesystemAttachmentResult, ) error { for _, id := range ids { removePendingFilesystemAttachment(ctx, id) } detach := make([]params.MachineStorageId, 0, len(ids)) remove := make([]params.MachineStorageId, 0, len(ids)) for i, result := range filesystemAttachmentResults { id := ids[i] if result.Error == nil { detach = append(detach, id) continue } if params.IsCodeNotProvisioned(result.Error) { remove = append(remove, id) continue } return errors.Annotatef(result.Error, "getting information for filesystem attachment %v", id) } if len(detach) > 0 { attachmentParams, err := filesystemAttachmentParams(ctx, detach) if err != nil { return errors.Trace(err) } ops := make([]scheduleOp, len(attachmentParams)) for i, p := range attachmentParams { ops[i] = &detachFilesystemOp{args: p} } scheduleOperations(ctx, ops...) } if err := removeAttachments(ctx, remove); err != nil { return errors.Annotate(err, "removing attachments from state") } return nil }
[ "func", "processDyingFilesystemAttachments", "(", "ctx", "*", "context", ",", "ids", "[", "]", "params", ".", "MachineStorageId", ",", "filesystemAttachmentResults", "[", "]", "params", ".", "FilesystemAttachmentResult", ",", ")", "error", "{", "for", "_", ",", "id", ":=", "range", "ids", "{", "removePendingFilesystemAttachment", "(", "ctx", ",", "id", ")", "\n", "}", "\n", "detach", ":=", "make", "(", "[", "]", "params", ".", "MachineStorageId", ",", "0", ",", "len", "(", "ids", ")", ")", "\n", "remove", ":=", "make", "(", "[", "]", "params", ".", "MachineStorageId", ",", "0", ",", "len", "(", "ids", ")", ")", "\n", "for", "i", ",", "result", ":=", "range", "filesystemAttachmentResults", "{", "id", ":=", "ids", "[", "i", "]", "\n", "if", "result", ".", "Error", "==", "nil", "{", "detach", "=", "append", "(", "detach", ",", "id", ")", "\n", "continue", "\n", "}", "\n", "if", "params", ".", "IsCodeNotProvisioned", "(", "result", ".", "Error", ")", "{", "remove", "=", "append", "(", "remove", ",", "id", ")", "\n", "continue", "\n", "}", "\n", "return", "errors", ".", "Annotatef", "(", "result", ".", "Error", ",", "\"", "\"", ",", "id", ")", "\n", "}", "\n", "if", "len", "(", "detach", ")", ">", "0", "{", "attachmentParams", ",", "err", ":=", "filesystemAttachmentParams", "(", "ctx", ",", "detach", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "ops", ":=", "make", "(", "[", "]", "scheduleOp", ",", "len", "(", "attachmentParams", ")", ")", "\n", "for", "i", ",", "p", ":=", "range", "attachmentParams", "{", "ops", "[", "i", "]", "=", "&", "detachFilesystemOp", "{", "args", ":", "p", "}", "\n", "}", "\n", "scheduleOperations", "(", "ctx", ",", "ops", "...", ")", "\n", "}", "\n", "if", "err", ":=", "removeAttachments", "(", "ctx", ",", "remove", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// processDyingFilesystemAttachments processes the FilesystemAttachmentResults for // Dying filesystem attachments, detaching filesystems and updating state as necessary.
[ "processDyingFilesystemAttachments", "processes", "the", "FilesystemAttachmentResults", "for", "Dying", "filesystem", "attachments", "detaching", "filesystems", "and", "updating", "state", "as", "necessary", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L241-L278
3,527
juju/juju
worker/storageprovisioner/filesystem_events.go
processAliveFilesystems
func processAliveFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error { // Filter out the already-provisioned filesystems. pending := make([]names.FilesystemTag, 0, len(tags)) for i, result := range filesystemResults { tag := tags[i] if result.Error == nil { // Filesystem is already provisioned: skip. logger.Debugf("filesystem %q is already provisioned, nothing to do", tag.Id()) filesystem, err := filesystemFromParams(result.Result) if err != nil { return errors.Annotate(err, "getting filesystem info") } updateFilesystem(ctx, filesystem) if !ctx.isApplicationKind() { if filesystem.Volume != (names.VolumeTag{}) { // Ensure that volume-backed filesystems' block // devices are present even after creating the // filesystem, so that attachments can be made. maybeAddPendingVolumeBlockDevice(ctx, filesystem.Volume) } } continue } if !params.IsCodeNotProvisioned(result.Error) { return errors.Annotatef( result.Error, "getting filesystem information for filesystem %q", tag.Id(), ) } // The filesystem has not yet been provisioned, so record its tag // to enquire about parameters below. pending = append(pending, tag) } if len(pending) == 0 { return nil } params, err := filesystemParams(ctx, pending) if err != nil { return errors.Annotate(err, "getting filesystem params") } for _, params := range params { if ctx.isApplicationKind() { logger.Debugf("not queuing filesystem for %v unit", ctx.config.Scope.Id()) continue } updatePendingFilesystem(ctx, params) } return nil }
go
func processAliveFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error { // Filter out the already-provisioned filesystems. pending := make([]names.FilesystemTag, 0, len(tags)) for i, result := range filesystemResults { tag := tags[i] if result.Error == nil { // Filesystem is already provisioned: skip. logger.Debugf("filesystem %q is already provisioned, nothing to do", tag.Id()) filesystem, err := filesystemFromParams(result.Result) if err != nil { return errors.Annotate(err, "getting filesystem info") } updateFilesystem(ctx, filesystem) if !ctx.isApplicationKind() { if filesystem.Volume != (names.VolumeTag{}) { // Ensure that volume-backed filesystems' block // devices are present even after creating the // filesystem, so that attachments can be made. maybeAddPendingVolumeBlockDevice(ctx, filesystem.Volume) } } continue } if !params.IsCodeNotProvisioned(result.Error) { return errors.Annotatef( result.Error, "getting filesystem information for filesystem %q", tag.Id(), ) } // The filesystem has not yet been provisioned, so record its tag // to enquire about parameters below. pending = append(pending, tag) } if len(pending) == 0 { return nil } params, err := filesystemParams(ctx, pending) if err != nil { return errors.Annotate(err, "getting filesystem params") } for _, params := range params { if ctx.isApplicationKind() { logger.Debugf("not queuing filesystem for %v unit", ctx.config.Scope.Id()) continue } updatePendingFilesystem(ctx, params) } return nil }
[ "func", "processAliveFilesystems", "(", "ctx", "*", "context", ",", "tags", "[", "]", "names", ".", "FilesystemTag", ",", "filesystemResults", "[", "]", "params", ".", "FilesystemResult", ")", "error", "{", "// Filter out the already-provisioned filesystems.", "pending", ":=", "make", "(", "[", "]", "names", ".", "FilesystemTag", ",", "0", ",", "len", "(", "tags", ")", ")", "\n", "for", "i", ",", "result", ":=", "range", "filesystemResults", "{", "tag", ":=", "tags", "[", "i", "]", "\n", "if", "result", ".", "Error", "==", "nil", "{", "// Filesystem is already provisioned: skip.", "logger", ".", "Debugf", "(", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ")", "\n", "filesystem", ",", "err", ":=", "filesystemFromParams", "(", "result", ".", "Result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "updateFilesystem", "(", "ctx", ",", "filesystem", ")", "\n", "if", "!", "ctx", ".", "isApplicationKind", "(", ")", "{", "if", "filesystem", ".", "Volume", "!=", "(", "names", ".", "VolumeTag", "{", "}", ")", "{", "// Ensure that volume-backed filesystems' block", "// devices are present even after creating the", "// filesystem, so that attachments can be made.", "maybeAddPendingVolumeBlockDevice", "(", "ctx", ",", "filesystem", ".", "Volume", ")", "\n", "}", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "!", "params", ".", "IsCodeNotProvisioned", "(", "result", ".", "Error", ")", "{", "return", "errors", ".", "Annotatef", "(", "result", ".", "Error", ",", "\"", "\"", ",", "tag", ".", "Id", "(", ")", ",", ")", "\n", "}", "\n", "// The filesystem has not yet been provisioned, so record its tag", "// to enquire about parameters below.", "pending", "=", "append", "(", "pending", ",", "tag", ")", "\n", "}", "\n", "if", "len", "(", "pending", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "params", ",", "err", ":=", "filesystemParams", "(", "ctx", ",", "pending", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "params", ":=", "range", "params", "{", "if", "ctx", ".", "isApplicationKind", "(", ")", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "ctx", ".", "config", ".", "Scope", ".", "Id", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "updatePendingFilesystem", "(", "ctx", ",", "params", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// processAliveFilesystems processes the FilesystemResults for Alive filesystems, // provisioning filesystems and setting the info in state as necessary.
[ "processAliveFilesystems", "processes", "the", "FilesystemResults", "for", "Alive", "filesystems", "provisioning", "filesystems", "and", "setting", "the", "info", "in", "state", "as", "necessary", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L282-L329
3,528
juju/juju
worker/storageprovisioner/filesystem_events.go
processAliveFilesystemAttachments
func processAliveFilesystemAttachments( ctx *context, ids []params.MachineStorageId, filesystemAttachmentResults []params.FilesystemAttachmentResult, ) error { // Filter out the already-attached. pending := make([]params.MachineStorageId, 0, len(ids)) for i, result := range filesystemAttachmentResults { if result.Error == nil { // Filesystem attachment is already provisioned: if we // didn't (re)attach in this session, then we must do // so now. action := "nothing to do" if _, ok := ctx.filesystemAttachments[ids[i]]; !ok { // Not yet (re)attached in this session. pending = append(pending, ids[i]) action = "will reattach" } logger.Debugf( "%s is already attached to %s, %s", ids[i].AttachmentTag, ids[i].MachineTag, action, ) removePendingFilesystemAttachment(ctx, ids[i]) continue } if !params.IsCodeNotProvisioned(result.Error) { return errors.Annotatef( result.Error, "getting information for attachment %v", ids[i], ) } // The filesystem has not yet been attached, so // record its tag to enquire about parameters below. pending = append(pending, ids[i]) } if len(pending) == 0 { return nil } params, err := filesystemAttachmentParams(ctx, pending) if err != nil { return errors.Trace(err) } for i, params := range params { if params.Machine != nil && params.Machine.Kind() != names.MachineTagKind { logger.Debugf("not queuing filesystem attachment for non-machine %v", params.Machine) continue } updatePendingFilesystemAttachment(ctx, pending[i], params) } return nil }
go
func processAliveFilesystemAttachments( ctx *context, ids []params.MachineStorageId, filesystemAttachmentResults []params.FilesystemAttachmentResult, ) error { // Filter out the already-attached. pending := make([]params.MachineStorageId, 0, len(ids)) for i, result := range filesystemAttachmentResults { if result.Error == nil { // Filesystem attachment is already provisioned: if we // didn't (re)attach in this session, then we must do // so now. action := "nothing to do" if _, ok := ctx.filesystemAttachments[ids[i]]; !ok { // Not yet (re)attached in this session. pending = append(pending, ids[i]) action = "will reattach" } logger.Debugf( "%s is already attached to %s, %s", ids[i].AttachmentTag, ids[i].MachineTag, action, ) removePendingFilesystemAttachment(ctx, ids[i]) continue } if !params.IsCodeNotProvisioned(result.Error) { return errors.Annotatef( result.Error, "getting information for attachment %v", ids[i], ) } // The filesystem has not yet been attached, so // record its tag to enquire about parameters below. pending = append(pending, ids[i]) } if len(pending) == 0 { return nil } params, err := filesystemAttachmentParams(ctx, pending) if err != nil { return errors.Trace(err) } for i, params := range params { if params.Machine != nil && params.Machine.Kind() != names.MachineTagKind { logger.Debugf("not queuing filesystem attachment for non-machine %v", params.Machine) continue } updatePendingFilesystemAttachment(ctx, pending[i], params) } return nil }
[ "func", "processAliveFilesystemAttachments", "(", "ctx", "*", "context", ",", "ids", "[", "]", "params", ".", "MachineStorageId", ",", "filesystemAttachmentResults", "[", "]", "params", ".", "FilesystemAttachmentResult", ",", ")", "error", "{", "// Filter out the already-attached.", "pending", ":=", "make", "(", "[", "]", "params", ".", "MachineStorageId", ",", "0", ",", "len", "(", "ids", ")", ")", "\n", "for", "i", ",", "result", ":=", "range", "filesystemAttachmentResults", "{", "if", "result", ".", "Error", "==", "nil", "{", "// Filesystem attachment is already provisioned: if we", "// didn't (re)attach in this session, then we must do", "// so now.", "action", ":=", "\"", "\"", "\n", "if", "_", ",", "ok", ":=", "ctx", ".", "filesystemAttachments", "[", "ids", "[", "i", "]", "]", ";", "!", "ok", "{", "// Not yet (re)attached in this session.", "pending", "=", "append", "(", "pending", ",", "ids", "[", "i", "]", ")", "\n", "action", "=", "\"", "\"", "\n", "}", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "ids", "[", "i", "]", ".", "AttachmentTag", ",", "ids", "[", "i", "]", ".", "MachineTag", ",", "action", ",", ")", "\n", "removePendingFilesystemAttachment", "(", "ctx", ",", "ids", "[", "i", "]", ")", "\n", "continue", "\n", "}", "\n", "if", "!", "params", ".", "IsCodeNotProvisioned", "(", "result", ".", "Error", ")", "{", "return", "errors", ".", "Annotatef", "(", "result", ".", "Error", ",", "\"", "\"", ",", "ids", "[", "i", "]", ",", ")", "\n", "}", "\n", "// The filesystem has not yet been attached, so", "// record its tag to enquire about parameters below.", "pending", "=", "append", "(", "pending", ",", "ids", "[", "i", "]", ")", "\n", "}", "\n", "if", "len", "(", "pending", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "params", ",", "err", ":=", "filesystemAttachmentParams", "(", "ctx", ",", "pending", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "for", "i", ",", "params", ":=", "range", "params", "{", "if", "params", ".", "Machine", "!=", "nil", "&&", "params", ".", "Machine", ".", "Kind", "(", ")", "!=", "names", ".", "MachineTagKind", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "params", ".", "Machine", ")", "\n", "continue", "\n", "}", "\n", "updatePendingFilesystemAttachment", "(", "ctx", ",", "pending", "[", "i", "]", ",", "params", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// processAliveFilesystemAttachments processes the FilesystemAttachmentResults // for Alive filesystem attachments, attaching filesystems and setting the info // in state as necessary.
[ "processAliveFilesystemAttachments", "processes", "the", "FilesystemAttachmentResults", "for", "Alive", "filesystem", "attachments", "attaching", "filesystems", "and", "setting", "the", "info", "in", "state", "as", "necessary", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L340-L389
3,529
juju/juju
worker/storageprovisioner/filesystem_events.go
filesystemAttachmentParams
func filesystemAttachmentParams( ctx *context, ids []params.MachineStorageId, ) ([]storage.FilesystemAttachmentParams, error) { paramsResults, err := ctx.config.Filesystems.FilesystemAttachmentParams(ids) if err != nil { return nil, errors.Annotate(err, "getting filesystem attachment params") } attachmentParams := make([]storage.FilesystemAttachmentParams, len(ids)) for i, result := range paramsResults { if result.Error != nil { return nil, errors.Annotate(result.Error, "getting filesystem attachment parameters") } params, err := filesystemAttachmentParamsFromParams(result.Result) if err != nil { return nil, errors.Annotate(err, "getting filesystem attachment parameters") } attachmentParams[i] = params } return attachmentParams, nil }
go
func filesystemAttachmentParams( ctx *context, ids []params.MachineStorageId, ) ([]storage.FilesystemAttachmentParams, error) { paramsResults, err := ctx.config.Filesystems.FilesystemAttachmentParams(ids) if err != nil { return nil, errors.Annotate(err, "getting filesystem attachment params") } attachmentParams := make([]storage.FilesystemAttachmentParams, len(ids)) for i, result := range paramsResults { if result.Error != nil { return nil, errors.Annotate(result.Error, "getting filesystem attachment parameters") } params, err := filesystemAttachmentParamsFromParams(result.Result) if err != nil { return nil, errors.Annotate(err, "getting filesystem attachment parameters") } attachmentParams[i] = params } return attachmentParams, nil }
[ "func", "filesystemAttachmentParams", "(", "ctx", "*", "context", ",", "ids", "[", "]", "params", ".", "MachineStorageId", ",", ")", "(", "[", "]", "storage", ".", "FilesystemAttachmentParams", ",", "error", ")", "{", "paramsResults", ",", "err", ":=", "ctx", ".", "config", ".", "Filesystems", ".", "FilesystemAttachmentParams", "(", "ids", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "attachmentParams", ":=", "make", "(", "[", "]", "storage", ".", "FilesystemAttachmentParams", ",", "len", "(", "ids", ")", ")", "\n", "for", "i", ",", "result", ":=", "range", "paramsResults", "{", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "result", ".", "Error", ",", "\"", "\"", ")", "\n", "}", "\n", "params", ",", "err", ":=", "filesystemAttachmentParamsFromParams", "(", "result", ".", "Result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "attachmentParams", "[", "i", "]", "=", "params", "\n", "}", "\n", "return", "attachmentParams", ",", "nil", "\n", "}" ]
// filesystemAttachmentParams obtains the specified attachments' parameters.
[ "filesystemAttachmentParams", "obtains", "the", "specified", "attachments", "parameters", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L392-L411
3,530
juju/juju
worker/storageprovisioner/filesystem_events.go
filesystemParams
func filesystemParams(ctx *context, tags []names.FilesystemTag) ([]storage.FilesystemParams, error) { paramsResults, err := ctx.config.Filesystems.FilesystemParams(tags) if err != nil { return nil, errors.Annotate(err, "getting filesystem params") } allParams := make([]storage.FilesystemParams, len(tags)) for i, result := range paramsResults { if result.Error != nil { return nil, errors.Annotate(result.Error, "getting filesystem parameters") } params, err := filesystemParamsFromParams(result.Result) if err != nil { return nil, errors.Annotate(err, "getting filesystem parameters") } allParams[i] = params } return allParams, nil }
go
func filesystemParams(ctx *context, tags []names.FilesystemTag) ([]storage.FilesystemParams, error) { paramsResults, err := ctx.config.Filesystems.FilesystemParams(tags) if err != nil { return nil, errors.Annotate(err, "getting filesystem params") } allParams := make([]storage.FilesystemParams, len(tags)) for i, result := range paramsResults { if result.Error != nil { return nil, errors.Annotate(result.Error, "getting filesystem parameters") } params, err := filesystemParamsFromParams(result.Result) if err != nil { return nil, errors.Annotate(err, "getting filesystem parameters") } allParams[i] = params } return allParams, nil }
[ "func", "filesystemParams", "(", "ctx", "*", "context", ",", "tags", "[", "]", "names", ".", "FilesystemTag", ")", "(", "[", "]", "storage", ".", "FilesystemParams", ",", "error", ")", "{", "paramsResults", ",", "err", ":=", "ctx", ".", "config", ".", "Filesystems", ".", "FilesystemParams", "(", "tags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "allParams", ":=", "make", "(", "[", "]", "storage", ".", "FilesystemParams", ",", "len", "(", "tags", ")", ")", "\n", "for", "i", ",", "result", ":=", "range", "paramsResults", "{", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "result", ".", "Error", ",", "\"", "\"", ")", "\n", "}", "\n", "params", ",", "err", ":=", "filesystemParamsFromParams", "(", "result", ".", "Result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "allParams", "[", "i", "]", "=", "params", "\n", "}", "\n", "return", "allParams", ",", "nil", "\n", "}" ]
// filesystemParams obtains the specified filesystems' parameters.
[ "filesystemParams", "obtains", "the", "specified", "filesystems", "parameters", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L414-L431
3,531
juju/juju
worker/storageprovisioner/filesystem_events.go
removeFilesystemParams
func removeFilesystemParams(ctx *context, tags []names.FilesystemTag) ([]params.RemoveFilesystemParams, error) { paramsResults, err := ctx.config.Filesystems.RemoveFilesystemParams(tags) if err != nil { return nil, errors.Annotate(err, "getting filesystem params") } allParams := make([]params.RemoveFilesystemParams, len(tags)) for i, result := range paramsResults { if result.Error != nil { return nil, errors.Annotate(result.Error, "getting filesystem removal parameters") } allParams[i] = result.Result } return allParams, nil }
go
func removeFilesystemParams(ctx *context, tags []names.FilesystemTag) ([]params.RemoveFilesystemParams, error) { paramsResults, err := ctx.config.Filesystems.RemoveFilesystemParams(tags) if err != nil { return nil, errors.Annotate(err, "getting filesystem params") } allParams := make([]params.RemoveFilesystemParams, len(tags)) for i, result := range paramsResults { if result.Error != nil { return nil, errors.Annotate(result.Error, "getting filesystem removal parameters") } allParams[i] = result.Result } return allParams, nil }
[ "func", "removeFilesystemParams", "(", "ctx", "*", "context", ",", "tags", "[", "]", "names", ".", "FilesystemTag", ")", "(", "[", "]", "params", ".", "RemoveFilesystemParams", ",", "error", ")", "{", "paramsResults", ",", "err", ":=", "ctx", ".", "config", ".", "Filesystems", ".", "RemoveFilesystemParams", "(", "tags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "allParams", ":=", "make", "(", "[", "]", "params", ".", "RemoveFilesystemParams", ",", "len", "(", "tags", ")", ")", "\n", "for", "i", ",", "result", ":=", "range", "paramsResults", "{", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "result", ".", "Error", ",", "\"", "\"", ")", "\n", "}", "\n", "allParams", "[", "i", "]", "=", "result", ".", "Result", "\n", "}", "\n", "return", "allParams", ",", "nil", "\n", "}" ]
// removeFilesystemParams obtains the specified filesystems' destruction parameters.
[ "removeFilesystemParams", "obtains", "the", "specified", "filesystems", "destruction", "parameters", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/filesystem_events.go#L434-L447
3,532
juju/juju
environs/simplestreams/simplestreams.go
extractCatalogsForProducts
func (metadata *CloudMetadata) extractCatalogsForProducts(productIds []string) []MetadataCatalog { result := []MetadataCatalog{} for _, id := range productIds { if catalog, ok := metadata.Products[id]; ok { result = append(result, catalog) } } return result }
go
func (metadata *CloudMetadata) extractCatalogsForProducts(productIds []string) []MetadataCatalog { result := []MetadataCatalog{} for _, id := range productIds { if catalog, ok := metadata.Products[id]; ok { result = append(result, catalog) } } return result }
[ "func", "(", "metadata", "*", "CloudMetadata", ")", "extractCatalogsForProducts", "(", "productIds", "[", "]", "string", ")", "[", "]", "MetadataCatalog", "{", "result", ":=", "[", "]", "MetadataCatalog", "{", "}", "\n", "for", "_", ",", "id", ":=", "range", "productIds", "{", "if", "catalog", ",", "ok", ":=", "metadata", ".", "Products", "[", "id", "]", ";", "ok", "{", "result", "=", "append", "(", "result", ",", "catalog", ")", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// extractCatalogsForProducts gives you just those catalogs from a // cloudImageMetadata that are for the given product IDs. They are kept in // the order of the parameter.
[ "extractCatalogsForProducts", "gives", "you", "just", "those", "catalogs", "from", "a", "cloudImageMetadata", "that", "are", "for", "the", "given", "product", "IDs", ".", "They", "are", "kept", "in", "the", "order", "of", "the", "parameter", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L239-L247
3,533
juju/juju
environs/simplestreams/simplestreams.go
extractIndexes
func (ind *Indices) extractIndexes(indexIds []string) IndexMetadataSlice { result := make(IndexMetadataSlice, 0, len(ind.Indexes)) if len(indexIds) == 0 { // No ids specified so return everything. for _, metadata := range ind.Indexes { result = append(result, metadata) } } else { // Return metadata for just the specified ids. for _, id := range indexIds { if metadata, ok := ind.Indexes[id]; ok { result = append(result, metadata) } } } return result }
go
func (ind *Indices) extractIndexes(indexIds []string) IndexMetadataSlice { result := make(IndexMetadataSlice, 0, len(ind.Indexes)) if len(indexIds) == 0 { // No ids specified so return everything. for _, metadata := range ind.Indexes { result = append(result, metadata) } } else { // Return metadata for just the specified ids. for _, id := range indexIds { if metadata, ok := ind.Indexes[id]; ok { result = append(result, metadata) } } } return result }
[ "func", "(", "ind", "*", "Indices", ")", "extractIndexes", "(", "indexIds", "[", "]", "string", ")", "IndexMetadataSlice", "{", "result", ":=", "make", "(", "IndexMetadataSlice", ",", "0", ",", "len", "(", "ind", ".", "Indexes", ")", ")", "\n", "if", "len", "(", "indexIds", ")", "==", "0", "{", "// No ids specified so return everything.", "for", "_", ",", "metadata", ":=", "range", "ind", ".", "Indexes", "{", "result", "=", "append", "(", "result", ",", "metadata", ")", "\n", "}", "\n", "}", "else", "{", "// Return metadata for just the specified ids.", "for", "_", ",", "id", ":=", "range", "indexIds", "{", "if", "metadata", ",", "ok", ":=", "ind", ".", "Indexes", "[", "id", "]", ";", "ok", "{", "result", "=", "append", "(", "result", ",", "metadata", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// extractIndexes returns just the array of indexes, in arbitrary order.
[ "extractIndexes", "returns", "just", "the", "array", "of", "indexes", "in", "arbitrary", "order", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L250-L266
3,534
juju/juju
environs/simplestreams/simplestreams.go
hasCloud
func (metadata *IndexMetadata) hasCloud(cloud CloudSpec) bool { for _, metadataCloud := range metadata.Clouds { if metadataCloud.equals(&cloud) { return true } } return len(metadata.Clouds) == 0 }
go
func (metadata *IndexMetadata) hasCloud(cloud CloudSpec) bool { for _, metadataCloud := range metadata.Clouds { if metadataCloud.equals(&cloud) { return true } } return len(metadata.Clouds) == 0 }
[ "func", "(", "metadata", "*", "IndexMetadata", ")", "hasCloud", "(", "cloud", "CloudSpec", ")", "bool", "{", "for", "_", ",", "metadataCloud", ":=", "range", "metadata", ".", "Clouds", "{", "if", "metadataCloud", ".", "equals", "(", "&", "cloud", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "len", "(", "metadata", ".", "Clouds", ")", "==", "0", "\n", "}" ]
// hasCloud tells you whether an IndexMetadata has the given cloud in its // Clouds list. If IndexMetadata has no clouds defined, then hasCloud // returns true regardless so that the corresponding product records // are searched.
[ "hasCloud", "tells", "you", "whether", "an", "IndexMetadata", "has", "the", "given", "cloud", "in", "its", "Clouds", "list", ".", "If", "IndexMetadata", "has", "no", "clouds", "defined", "then", "hasCloud", "returns", "true", "regardless", "so", "that", "the", "corresponding", "product", "records", "are", "searched", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L276-L283
3,535
juju/juju
environs/simplestreams/simplestreams.go
hasProduct
func (metadata *IndexMetadata) hasProduct(prodIds []string) bool { for _, pid := range metadata.ProductIds { if containsString(prodIds, pid) { return true } } return false }
go
func (metadata *IndexMetadata) hasProduct(prodIds []string) bool { for _, pid := range metadata.ProductIds { if containsString(prodIds, pid) { return true } } return false }
[ "func", "(", "metadata", "*", "IndexMetadata", ")", "hasProduct", "(", "prodIds", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "pid", ":=", "range", "metadata", ".", "ProductIds", "{", "if", "containsString", "(", "prodIds", ",", "pid", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// hasProduct tells you whether an IndexMetadata provides any of the given // product IDs.
[ "hasProduct", "tells", "you", "whether", "an", "IndexMetadata", "provides", "any", "of", "the", "given", "product", "IDs", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L287-L294
3,536
juju/juju
environs/simplestreams/simplestreams.go
filter
func (entries IndexMetadataSlice) filter(match func(*IndexMetadata) bool) IndexMetadataSlice { result := IndexMetadataSlice{} for _, metadata := range entries { if match(metadata) { result = append(result, metadata) } } return result }
go
func (entries IndexMetadataSlice) filter(match func(*IndexMetadata) bool) IndexMetadataSlice { result := IndexMetadataSlice{} for _, metadata := range entries { if match(metadata) { result = append(result, metadata) } } return result }
[ "func", "(", "entries", "IndexMetadataSlice", ")", "filter", "(", "match", "func", "(", "*", "IndexMetadata", ")", "bool", ")", "IndexMetadataSlice", "{", "result", ":=", "IndexMetadataSlice", "{", "}", "\n", "for", "_", ",", "metadata", ":=", "range", "entries", "{", "if", "match", "(", "metadata", ")", "{", "result", "=", "append", "(", "result", ",", "metadata", ")", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// filter returns those entries from an IndexMetadata array for which the given // match function returns true. It preserves order.
[ "filter", "returns", "those", "entries", "from", "an", "IndexMetadata", "array", "for", "which", "the", "given", "match", "function", "returns", "true", ".", "It", "preserves", "order", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L300-L308
3,537
juju/juju
environs/simplestreams/simplestreams.go
UnsignedIndex
func UnsignedIndex(streamsVersion string, indexFileVersion int) string { indexFileSuffix := "" if indexFileVersion > 1 { indexFileSuffix = fmt.Sprintf("%d", indexFileVersion) } return fmt.Sprintf(unsignedIndex, streamsVersion, indexFileSuffix) }
go
func UnsignedIndex(streamsVersion string, indexFileVersion int) string { indexFileSuffix := "" if indexFileVersion > 1 { indexFileSuffix = fmt.Sprintf("%d", indexFileVersion) } return fmt.Sprintf(unsignedIndex, streamsVersion, indexFileSuffix) }
[ "func", "UnsignedIndex", "(", "streamsVersion", "string", ",", "indexFileVersion", "int", ")", "string", "{", "indexFileSuffix", ":=", "\"", "\"", "\n", "if", "indexFileVersion", ">", "1", "{", "indexFileSuffix", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "indexFileVersion", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "unsignedIndex", ",", "streamsVersion", ",", "indexFileSuffix", ")", "\n", "}" ]
// UnsignedIndex returns an unsigned index file name for streamsVersion.
[ "UnsignedIndex", "returns", "an", "unsigned", "index", "file", "name", "for", "streamsVersion", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L369-L375
3,538
juju/juju
environs/simplestreams/simplestreams.go
getMaybeSignedMetadata
func getMaybeSignedMetadata(source DataSource, params GetMetadataParams, signed bool) ([]interface{}, *ResolveInfo, error) { makeIndexPath := func(basePath string) string { pathNoSuffix := fmt.Sprintf(basePath, params.StreamsVersion) indexPath := pathNoSuffix + UnsignedSuffix if signed { indexPath = pathNoSuffix + SignedSuffix } return indexPath } resolveInfo := &ResolveInfo{} resolveInfo.Source = source.Description() resolveInfo.Signed = signed indexPath := makeIndexPath(defaultIndexPath) logger.Tracef("looking for data index using path %s", indexPath) mirrorsPath := fmt.Sprintf(defaultMirrorsPath, params.StreamsVersion) cons := params.LookupConstraint indexRef, indexURL, err := fetchIndex( source, indexPath, mirrorsPath, cons.Params().CloudSpec, signed, params.ValueParams, ) logger.Tracef("looking for data index using URL %s", indexURL) if errors.IsNotFound(err) || errors.IsUnauthorized(err) { legacyIndexPath := makeIndexPath(defaultLegacyIndexPath) logger.Tracef("%s not accessed, actual error: %v", indexPath, err) logger.Tracef("%s not accessed, trying legacy index path: %s", indexPath, legacyIndexPath) indexPath = legacyIndexPath indexRef, indexURL, err = fetchIndex( source, indexPath, mirrorsPath, cons.Params().CloudSpec, signed, params.ValueParams, ) } resolveInfo.IndexURL = indexURL if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { logger.Tracef("cannot load index %q: %v", indexURL, err) } return nil, resolveInfo, err } logger.Tracef("read metadata index at %q", indexURL) items, err := indexRef.getLatestMetadataWithFormat(cons, ProductFormat, signed) if err != nil { if errors.IsNotFound(err) { logger.Debugf("skipping index %q because of missing information: %v", indexURL, err) return nil, resolveInfo, err } if _, ok := err.(*noMatchingProductsError); !ok { logger.Debugf("%v", err) } } if indexRef.Source.Description() == "mirror" { resolveInfo.MirrorURL = indexRef.Source.(*urlDataSource).baseURL } return items, resolveInfo, err }
go
func getMaybeSignedMetadata(source DataSource, params GetMetadataParams, signed bool) ([]interface{}, *ResolveInfo, error) { makeIndexPath := func(basePath string) string { pathNoSuffix := fmt.Sprintf(basePath, params.StreamsVersion) indexPath := pathNoSuffix + UnsignedSuffix if signed { indexPath = pathNoSuffix + SignedSuffix } return indexPath } resolveInfo := &ResolveInfo{} resolveInfo.Source = source.Description() resolveInfo.Signed = signed indexPath := makeIndexPath(defaultIndexPath) logger.Tracef("looking for data index using path %s", indexPath) mirrorsPath := fmt.Sprintf(defaultMirrorsPath, params.StreamsVersion) cons := params.LookupConstraint indexRef, indexURL, err := fetchIndex( source, indexPath, mirrorsPath, cons.Params().CloudSpec, signed, params.ValueParams, ) logger.Tracef("looking for data index using URL %s", indexURL) if errors.IsNotFound(err) || errors.IsUnauthorized(err) { legacyIndexPath := makeIndexPath(defaultLegacyIndexPath) logger.Tracef("%s not accessed, actual error: %v", indexPath, err) logger.Tracef("%s not accessed, trying legacy index path: %s", indexPath, legacyIndexPath) indexPath = legacyIndexPath indexRef, indexURL, err = fetchIndex( source, indexPath, mirrorsPath, cons.Params().CloudSpec, signed, params.ValueParams, ) } resolveInfo.IndexURL = indexURL if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { logger.Tracef("cannot load index %q: %v", indexURL, err) } return nil, resolveInfo, err } logger.Tracef("read metadata index at %q", indexURL) items, err := indexRef.getLatestMetadataWithFormat(cons, ProductFormat, signed) if err != nil { if errors.IsNotFound(err) { logger.Debugf("skipping index %q because of missing information: %v", indexURL, err) return nil, resolveInfo, err } if _, ok := err.(*noMatchingProductsError); !ok { logger.Debugf("%v", err) } } if indexRef.Source.Description() == "mirror" { resolveInfo.MirrorURL = indexRef.Source.(*urlDataSource).baseURL } return items, resolveInfo, err }
[ "func", "getMaybeSignedMetadata", "(", "source", "DataSource", ",", "params", "GetMetadataParams", ",", "signed", "bool", ")", "(", "[", "]", "interface", "{", "}", ",", "*", "ResolveInfo", ",", "error", ")", "{", "makeIndexPath", ":=", "func", "(", "basePath", "string", ")", "string", "{", "pathNoSuffix", ":=", "fmt", ".", "Sprintf", "(", "basePath", ",", "params", ".", "StreamsVersion", ")", "\n", "indexPath", ":=", "pathNoSuffix", "+", "UnsignedSuffix", "\n", "if", "signed", "{", "indexPath", "=", "pathNoSuffix", "+", "SignedSuffix", "\n", "}", "\n", "return", "indexPath", "\n", "}", "\n\n", "resolveInfo", ":=", "&", "ResolveInfo", "{", "}", "\n", "resolveInfo", ".", "Source", "=", "source", ".", "Description", "(", ")", "\n", "resolveInfo", ".", "Signed", "=", "signed", "\n", "indexPath", ":=", "makeIndexPath", "(", "defaultIndexPath", ")", "\n\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "indexPath", ")", "\n", "mirrorsPath", ":=", "fmt", ".", "Sprintf", "(", "defaultMirrorsPath", ",", "params", ".", "StreamsVersion", ")", "\n", "cons", ":=", "params", ".", "LookupConstraint", "\n\n", "indexRef", ",", "indexURL", ",", "err", ":=", "fetchIndex", "(", "source", ",", "indexPath", ",", "mirrorsPath", ",", "cons", ".", "Params", "(", ")", ".", "CloudSpec", ",", "signed", ",", "params", ".", "ValueParams", ",", ")", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "indexURL", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "||", "errors", ".", "IsUnauthorized", "(", "err", ")", "{", "legacyIndexPath", ":=", "makeIndexPath", "(", "defaultLegacyIndexPath", ")", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "indexPath", ",", "err", ")", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "indexPath", ",", "legacyIndexPath", ")", "\n", "indexPath", "=", "legacyIndexPath", "\n", "indexRef", ",", "indexURL", ",", "err", "=", "fetchIndex", "(", "source", ",", "indexPath", ",", "mirrorsPath", ",", "cons", ".", "Params", "(", ")", ".", "CloudSpec", ",", "signed", ",", "params", ".", "ValueParams", ",", ")", "\n", "}", "\n", "resolveInfo", ".", "IndexURL", "=", "indexURL", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotFound", "(", "err", ")", "||", "errors", ".", "IsUnauthorized", "(", "err", ")", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "indexURL", ",", "err", ")", "\n", "}", "\n", "return", "nil", ",", "resolveInfo", ",", "err", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "indexURL", ")", "\n", "items", ",", "err", ":=", "indexRef", ".", "getLatestMetadataWithFormat", "(", "cons", ",", "ProductFormat", ",", "signed", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "indexURL", ",", "err", ")", "\n", "return", "nil", ",", "resolveInfo", ",", "err", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "noMatchingProductsError", ")", ";", "!", "ok", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "indexRef", ".", "Source", ".", "Description", "(", ")", "==", "\"", "\"", "{", "resolveInfo", ".", "MirrorURL", "=", "indexRef", ".", "Source", ".", "(", "*", "urlDataSource", ")", ".", "baseURL", "\n", "}", "\n", "return", "items", ",", "resolveInfo", ",", "err", "\n", "}" ]
// getMaybeSignedMetadata returns metadata records matching the specified constraint in params.
[ "getMaybeSignedMetadata", "returns", "metadata", "records", "matching", "the", "specified", "constraint", "in", "params", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L413-L468
3,539
juju/juju
environs/simplestreams/simplestreams.go
fetchIndex
func fetchIndex(source DataSource, indexPath string, mirrorsPath string, cloudSpec CloudSpec, signed bool, params ValueParams) (indexRef *IndexReference, indexURL string, _ error) { indexURL, err := source.URL(indexPath) if err != nil { // Some providers return an error if asked for the URL of a non-existent file. // So the best we can do is use the relative path for the URL when logging messages. indexURL = indexPath } indexRef, err = GetIndexWithFormat( source, indexPath, IndexFormat, mirrorsPath, signed, cloudSpec, params, ) return indexRef, indexURL, err }
go
func fetchIndex(source DataSource, indexPath string, mirrorsPath string, cloudSpec CloudSpec, signed bool, params ValueParams) (indexRef *IndexReference, indexURL string, _ error) { indexURL, err := source.URL(indexPath) if err != nil { // Some providers return an error if asked for the URL of a non-existent file. // So the best we can do is use the relative path for the URL when logging messages. indexURL = indexPath } indexRef, err = GetIndexWithFormat( source, indexPath, IndexFormat, mirrorsPath, signed, cloudSpec, params, ) return indexRef, indexURL, err }
[ "func", "fetchIndex", "(", "source", "DataSource", ",", "indexPath", "string", ",", "mirrorsPath", "string", ",", "cloudSpec", "CloudSpec", ",", "signed", "bool", ",", "params", "ValueParams", ")", "(", "indexRef", "*", "IndexReference", ",", "indexURL", "string", ",", "_", "error", ")", "{", "indexURL", ",", "err", ":=", "source", ".", "URL", "(", "indexPath", ")", "\n", "if", "err", "!=", "nil", "{", "// Some providers return an error if asked for the URL of a non-existent file.", "// So the best we can do is use the relative path for the URL when logging messages.", "indexURL", "=", "indexPath", "\n", "}", "\n", "indexRef", ",", "err", "=", "GetIndexWithFormat", "(", "source", ",", "indexPath", ",", "IndexFormat", ",", "mirrorsPath", ",", "signed", ",", "cloudSpec", ",", "params", ",", ")", "\n", "return", "indexRef", ",", "indexURL", ",", "err", "\n", "}" ]
// fetchIndex attempts to load the index file at indexPath in source.
[ "fetchIndex", "attempts", "to", "load", "the", "index", "file", "at", "indexPath", "in", "source", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L471-L483
3,540
juju/juju
environs/simplestreams/simplestreams.go
fetchData
func fetchData(source DataSource, path string, requireSigned bool) (data []byte, dataURL string, err error) { rc, dataURL, err := source.Fetch(path) if err != nil { logger.Tracef("fetchData failed for %q: %v", dataURL, err) return nil, dataURL, errors.NotFoundf("invalid URL %q", dataURL) } defer rc.Close() if requireSigned { data, err = DecodeCheckSignature(rc, source.PublicSigningKey()) } else { data, err = ioutil.ReadAll(rc) } if err != nil { return nil, dataURL, errors.Annotatef(err, "cannot read data for source %q at URL %v", source.Description(), dataURL) } return data, dataURL, nil }
go
func fetchData(source DataSource, path string, requireSigned bool) (data []byte, dataURL string, err error) { rc, dataURL, err := source.Fetch(path) if err != nil { logger.Tracef("fetchData failed for %q: %v", dataURL, err) return nil, dataURL, errors.NotFoundf("invalid URL %q", dataURL) } defer rc.Close() if requireSigned { data, err = DecodeCheckSignature(rc, source.PublicSigningKey()) } else { data, err = ioutil.ReadAll(rc) } if err != nil { return nil, dataURL, errors.Annotatef(err, "cannot read data for source %q at URL %v", source.Description(), dataURL) } return data, dataURL, nil }
[ "func", "fetchData", "(", "source", "DataSource", ",", "path", "string", ",", "requireSigned", "bool", ")", "(", "data", "[", "]", "byte", ",", "dataURL", "string", ",", "err", "error", ")", "{", "rc", ",", "dataURL", ",", "err", ":=", "source", ".", "Fetch", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "dataURL", ",", "err", ")", "\n", "return", "nil", ",", "dataURL", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "dataURL", ")", "\n", "}", "\n", "defer", "rc", ".", "Close", "(", ")", "\n", "if", "requireSigned", "{", "data", ",", "err", "=", "DecodeCheckSignature", "(", "rc", ",", "source", ".", "PublicSigningKey", "(", ")", ")", "\n", "}", "else", "{", "data", ",", "err", "=", "ioutil", ".", "ReadAll", "(", "rc", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "dataURL", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "source", ".", "Description", "(", ")", ",", "dataURL", ")", "\n", "}", "\n", "return", "data", ",", "dataURL", ",", "nil", "\n", "}" ]
// fetchData gets all the data from the given source located at the specified path. // It returns the data found and the full URL used.
[ "fetchData", "gets", "all", "the", "data", "from", "the", "given", "source", "located", "at", "the", "specified", "path", ".", "It", "returns", "the", "data", "found", "and", "the", "full", "URL", "used", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L487-L503
3,541
juju/juju
environs/simplestreams/simplestreams.go
GetIndexWithFormat
func GetIndexWithFormat(source DataSource, indexPath, indexFormat, mirrorsPath string, requireSigned bool, cloudSpec CloudSpec, params ValueParams) (*IndexReference, error) { data, url, err := fetchData(source, indexPath, requireSigned) if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { return nil, err } return nil, fmt.Errorf("cannot read index data, %v", err) } var indices Indices err = json.Unmarshal(data, &indices) if err != nil { logger.Errorf("bad JSON index data at URL %q: %v", url, string(data)) return nil, fmt.Errorf("cannot unmarshal JSON index metadata at URL %q: %v", url, err) } if indices.Format != indexFormat { return nil, fmt.Errorf( "unexpected index file format %q, expected %q at URL %q", indices.Format, indexFormat, url) } mirrors, url, err := getMirrorRefs(source, mirrorsPath, requireSigned, params) if err != nil && !errors.IsNotFound(err) && !errors.IsUnauthorized(err) { return nil, fmt.Errorf("cannot load mirror metadata at URL %q: %v", url, err) } indexRef := &IndexReference{ Source: source, Indices: indices, valueParams: params, } // Apply any mirror information to the source. if params.MirrorContentId != "" { mirrorInfo, err := getMirror( source, mirrors, params.DataType, params.MirrorContentId, cloudSpec, requireSigned) if err == nil { logger.Debugf("using mirrored products path: %s", path.Join(mirrorInfo.MirrorURL, mirrorInfo.Path)) indexRef.Source = NewURLSignedDataSource("mirror", mirrorInfo.MirrorURL, source.PublicSigningKey(), utils.VerifySSLHostnames, source.Priority(), requireSigned) indexRef.MirroredProductsPath = mirrorInfo.Path } else { logger.Tracef("no mirror information available for %s: %v", cloudSpec, err) } } return indexRef, nil }
go
func GetIndexWithFormat(source DataSource, indexPath, indexFormat, mirrorsPath string, requireSigned bool, cloudSpec CloudSpec, params ValueParams) (*IndexReference, error) { data, url, err := fetchData(source, indexPath, requireSigned) if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { return nil, err } return nil, fmt.Errorf("cannot read index data, %v", err) } var indices Indices err = json.Unmarshal(data, &indices) if err != nil { logger.Errorf("bad JSON index data at URL %q: %v", url, string(data)) return nil, fmt.Errorf("cannot unmarshal JSON index metadata at URL %q: %v", url, err) } if indices.Format != indexFormat { return nil, fmt.Errorf( "unexpected index file format %q, expected %q at URL %q", indices.Format, indexFormat, url) } mirrors, url, err := getMirrorRefs(source, mirrorsPath, requireSigned, params) if err != nil && !errors.IsNotFound(err) && !errors.IsUnauthorized(err) { return nil, fmt.Errorf("cannot load mirror metadata at URL %q: %v", url, err) } indexRef := &IndexReference{ Source: source, Indices: indices, valueParams: params, } // Apply any mirror information to the source. if params.MirrorContentId != "" { mirrorInfo, err := getMirror( source, mirrors, params.DataType, params.MirrorContentId, cloudSpec, requireSigned) if err == nil { logger.Debugf("using mirrored products path: %s", path.Join(mirrorInfo.MirrorURL, mirrorInfo.Path)) indexRef.Source = NewURLSignedDataSource("mirror", mirrorInfo.MirrorURL, source.PublicSigningKey(), utils.VerifySSLHostnames, source.Priority(), requireSigned) indexRef.MirroredProductsPath = mirrorInfo.Path } else { logger.Tracef("no mirror information available for %s: %v", cloudSpec, err) } } return indexRef, nil }
[ "func", "GetIndexWithFormat", "(", "source", "DataSource", ",", "indexPath", ",", "indexFormat", ",", "mirrorsPath", "string", ",", "requireSigned", "bool", ",", "cloudSpec", "CloudSpec", ",", "params", "ValueParams", ")", "(", "*", "IndexReference", ",", "error", ")", "{", "data", ",", "url", ",", "err", ":=", "fetchData", "(", "source", ",", "indexPath", ",", "requireSigned", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotFound", "(", "err", ")", "||", "errors", ".", "IsUnauthorized", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "var", "indices", "Indices", "\n", "err", "=", "json", ".", "Unmarshal", "(", "data", ",", "&", "indices", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "string", "(", "data", ")", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "err", ")", "\n", "}", "\n", "if", "indices", ".", "Format", "!=", "indexFormat", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "indices", ".", "Format", ",", "indexFormat", ",", "url", ")", "\n", "}", "\n\n", "mirrors", ",", "url", ",", "err", ":=", "getMirrorRefs", "(", "source", ",", "mirrorsPath", ",", "requireSigned", ",", "params", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "errors", ".", "IsNotFound", "(", "err", ")", "&&", "!", "errors", ".", "IsUnauthorized", "(", "err", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "err", ")", "\n", "}", "\n\n", "indexRef", ":=", "&", "IndexReference", "{", "Source", ":", "source", ",", "Indices", ":", "indices", ",", "valueParams", ":", "params", ",", "}", "\n\n", "// Apply any mirror information to the source.", "if", "params", ".", "MirrorContentId", "!=", "\"", "\"", "{", "mirrorInfo", ",", "err", ":=", "getMirror", "(", "source", ",", "mirrors", ",", "params", ".", "DataType", ",", "params", ".", "MirrorContentId", ",", "cloudSpec", ",", "requireSigned", ")", "\n", "if", "err", "==", "nil", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "path", ".", "Join", "(", "mirrorInfo", ".", "MirrorURL", ",", "mirrorInfo", ".", "Path", ")", ")", "\n", "indexRef", ".", "Source", "=", "NewURLSignedDataSource", "(", "\"", "\"", ",", "mirrorInfo", ".", "MirrorURL", ",", "source", ".", "PublicSigningKey", "(", ")", ",", "utils", ".", "VerifySSLHostnames", ",", "source", ".", "Priority", "(", ")", ",", "requireSigned", ")", "\n", "indexRef", ".", "MirroredProductsPath", "=", "mirrorInfo", ".", "Path", "\n", "}", "else", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "cloudSpec", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "indexRef", ",", "nil", "\n", "}" ]
// GetIndexWithFormat returns a simplestreams index of the specified format. // Exported for testing.
[ "GetIndexWithFormat", "returns", "a", "simplestreams", "index", "of", "the", "specified", "format", ".", "Exported", "for", "testing", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L507-L553
3,542
juju/juju
environs/simplestreams/simplestreams.go
getMirrorRefs
func getMirrorRefs(source DataSource, baseMirrorsPath string, requireSigned bool, params ValueParams) (MirrorRefs, string, error) { mirrorsPath := baseMirrorsPath + UnsignedSuffix if requireSigned { mirrorsPath = baseMirrorsPath + SignedSuffix } var mirrors MirrorRefs data, url, err := fetchData(source, mirrorsPath, requireSigned) if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { return mirrors, url, err } return mirrors, url, fmt.Errorf("cannot read mirrors data, %v", err) } err = json.Unmarshal(data, &mirrors) if err != nil { return mirrors, url, fmt.Errorf("cannot unmarshal JSON mirror metadata at URL %q: %v", url, err) } return mirrors, url, err }
go
func getMirrorRefs(source DataSource, baseMirrorsPath string, requireSigned bool, params ValueParams) (MirrorRefs, string, error) { mirrorsPath := baseMirrorsPath + UnsignedSuffix if requireSigned { mirrorsPath = baseMirrorsPath + SignedSuffix } var mirrors MirrorRefs data, url, err := fetchData(source, mirrorsPath, requireSigned) if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { return mirrors, url, err } return mirrors, url, fmt.Errorf("cannot read mirrors data, %v", err) } err = json.Unmarshal(data, &mirrors) if err != nil { return mirrors, url, fmt.Errorf("cannot unmarshal JSON mirror metadata at URL %q: %v", url, err) } return mirrors, url, err }
[ "func", "getMirrorRefs", "(", "source", "DataSource", ",", "baseMirrorsPath", "string", ",", "requireSigned", "bool", ",", "params", "ValueParams", ")", "(", "MirrorRefs", ",", "string", ",", "error", ")", "{", "mirrorsPath", ":=", "baseMirrorsPath", "+", "UnsignedSuffix", "\n", "if", "requireSigned", "{", "mirrorsPath", "=", "baseMirrorsPath", "+", "SignedSuffix", "\n", "}", "\n", "var", "mirrors", "MirrorRefs", "\n", "data", ",", "url", ",", "err", ":=", "fetchData", "(", "source", ",", "mirrorsPath", ",", "requireSigned", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotFound", "(", "err", ")", "||", "errors", ".", "IsUnauthorized", "(", "err", ")", "{", "return", "mirrors", ",", "url", ",", "err", "\n", "}", "\n", "return", "mirrors", ",", "url", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "data", ",", "&", "mirrors", ")", "\n", "if", "err", "!=", "nil", "{", "return", "mirrors", ",", "url", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "err", ")", "\n", "}", "\n", "return", "mirrors", ",", "url", ",", "err", "\n", "}" ]
// getMirrorRefs parses and returns a simplestreams mirror reference.
[ "getMirrorRefs", "parses", "and", "returns", "a", "simplestreams", "mirror", "reference", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L556-L576
3,543
juju/juju
environs/simplestreams/simplestreams.go
getMirror
func getMirror(source DataSource, mirrors MirrorRefs, datatype, contentId string, cloudSpec CloudSpec, requireSigned bool) (*MirrorInfo, error) { mirrorRef, err := mirrors.getMirrorReference(datatype, contentId, cloudSpec) if err != nil { return nil, err } mirrorInfo, err := mirrorRef.getMirrorInfo(source, contentId, cloudSpec, MirrorFormat, requireSigned) if err != nil { return nil, err } if mirrorInfo == nil { return nil, errors.NotFoundf("mirror metadata for %q and cloud %v", contentId, cloudSpec) } return mirrorInfo, nil }
go
func getMirror(source DataSource, mirrors MirrorRefs, datatype, contentId string, cloudSpec CloudSpec, requireSigned bool) (*MirrorInfo, error) { mirrorRef, err := mirrors.getMirrorReference(datatype, contentId, cloudSpec) if err != nil { return nil, err } mirrorInfo, err := mirrorRef.getMirrorInfo(source, contentId, cloudSpec, MirrorFormat, requireSigned) if err != nil { return nil, err } if mirrorInfo == nil { return nil, errors.NotFoundf("mirror metadata for %q and cloud %v", contentId, cloudSpec) } return mirrorInfo, nil }
[ "func", "getMirror", "(", "source", "DataSource", ",", "mirrors", "MirrorRefs", ",", "datatype", ",", "contentId", "string", ",", "cloudSpec", "CloudSpec", ",", "requireSigned", "bool", ")", "(", "*", "MirrorInfo", ",", "error", ")", "{", "mirrorRef", ",", "err", ":=", "mirrors", ".", "getMirrorReference", "(", "datatype", ",", "contentId", ",", "cloudSpec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "mirrorInfo", ",", "err", ":=", "mirrorRef", ".", "getMirrorInfo", "(", "source", ",", "contentId", ",", "cloudSpec", ",", "MirrorFormat", ",", "requireSigned", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "mirrorInfo", "==", "nil", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "contentId", ",", "cloudSpec", ")", "\n", "}", "\n", "return", "mirrorInfo", ",", "nil", "\n", "}" ]
// getMirror returns a mirror info struct matching the specified content and cloud.
[ "getMirror", "returns", "a", "mirror", "info", "struct", "matching", "the", "specified", "content", "and", "cloud", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L579-L594
3,544
juju/juju
environs/simplestreams/simplestreams.go
GetProductsPath
func (indexRef *IndexReference) GetProductsPath(cons LookupConstraint) (string, error) { if indexRef.MirroredProductsPath != "" { return indexRef.MirroredProductsPath, nil } prodIds, err := cons.ProductIds() if err != nil { return "", err } candidates := indexRef.extractIndexes(cons.IndexIds()) // Restrict to the relevant data type entries. dataTypeMatches := func(metadata *IndexMetadata) bool { return metadata.DataType == indexRef.valueParams.DataType } candidates = candidates.filter(dataTypeMatches) if len(candidates) == 0 { // TODO: jam 2015-04-01 This isn't a great error to use, // because it is generally reserved for file-not-found // semantics. // This was formatted as: index file missing "content-download" data not found // It now formats as: "content-download" data not found // which at least reads better. // Shouldn't we be using noMatchingProductsError instead? return "", errors.NotFoundf("%q data", indexRef.valueParams.DataType) } // Restrict by cloud spec, if required. if cons.Params().CloudSpec != EmptyCloudSpec { hasRightCloud := func(metadata *IndexMetadata) bool { return metadata.hasCloud(cons.Params().CloudSpec) } candidates = candidates.filter(hasRightCloud) if len(candidates) == 0 { return "", errors.NotFoundf("index file has no data for cloud %v", cons.Params().CloudSpec) } } // Restrict by product IDs. hasProduct := func(metadata *IndexMetadata) bool { return metadata.hasProduct(prodIds) } candidates = candidates.filter(hasProduct) if len(candidates) == 0 { return "", newNoMatchingProductsError("index file has no data for product name(s) %q", prodIds) } logger.Tracef("candidate matches for products %q are %v", prodIds, candidates) // Pick arbitrary match. return candidates[0].ProductsFilePath, nil }
go
func (indexRef *IndexReference) GetProductsPath(cons LookupConstraint) (string, error) { if indexRef.MirroredProductsPath != "" { return indexRef.MirroredProductsPath, nil } prodIds, err := cons.ProductIds() if err != nil { return "", err } candidates := indexRef.extractIndexes(cons.IndexIds()) // Restrict to the relevant data type entries. dataTypeMatches := func(metadata *IndexMetadata) bool { return metadata.DataType == indexRef.valueParams.DataType } candidates = candidates.filter(dataTypeMatches) if len(candidates) == 0 { // TODO: jam 2015-04-01 This isn't a great error to use, // because it is generally reserved for file-not-found // semantics. // This was formatted as: index file missing "content-download" data not found // It now formats as: "content-download" data not found // which at least reads better. // Shouldn't we be using noMatchingProductsError instead? return "", errors.NotFoundf("%q data", indexRef.valueParams.DataType) } // Restrict by cloud spec, if required. if cons.Params().CloudSpec != EmptyCloudSpec { hasRightCloud := func(metadata *IndexMetadata) bool { return metadata.hasCloud(cons.Params().CloudSpec) } candidates = candidates.filter(hasRightCloud) if len(candidates) == 0 { return "", errors.NotFoundf("index file has no data for cloud %v", cons.Params().CloudSpec) } } // Restrict by product IDs. hasProduct := func(metadata *IndexMetadata) bool { return metadata.hasProduct(prodIds) } candidates = candidates.filter(hasProduct) if len(candidates) == 0 { return "", newNoMatchingProductsError("index file has no data for product name(s) %q", prodIds) } logger.Tracef("candidate matches for products %q are %v", prodIds, candidates) // Pick arbitrary match. return candidates[0].ProductsFilePath, nil }
[ "func", "(", "indexRef", "*", "IndexReference", ")", "GetProductsPath", "(", "cons", "LookupConstraint", ")", "(", "string", ",", "error", ")", "{", "if", "indexRef", ".", "MirroredProductsPath", "!=", "\"", "\"", "{", "return", "indexRef", ".", "MirroredProductsPath", ",", "nil", "\n", "}", "\n", "prodIds", ",", "err", ":=", "cons", ".", "ProductIds", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "candidates", ":=", "indexRef", ".", "extractIndexes", "(", "cons", ".", "IndexIds", "(", ")", ")", "\n", "// Restrict to the relevant data type entries.", "dataTypeMatches", ":=", "func", "(", "metadata", "*", "IndexMetadata", ")", "bool", "{", "return", "metadata", ".", "DataType", "==", "indexRef", ".", "valueParams", ".", "DataType", "\n", "}", "\n", "candidates", "=", "candidates", ".", "filter", "(", "dataTypeMatches", ")", "\n", "if", "len", "(", "candidates", ")", "==", "0", "{", "// TODO: jam 2015-04-01 This isn't a great error to use,", "// because it is generally reserved for file-not-found", "// semantics.", "// This was formatted as: index file missing \"content-download\" data not found", "// It now formats as: \"content-download\" data not found", "// which at least reads better.", "// Shouldn't we be using noMatchingProductsError instead?", "return", "\"", "\"", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "indexRef", ".", "valueParams", ".", "DataType", ")", "\n", "}", "\n", "// Restrict by cloud spec, if required.", "if", "cons", ".", "Params", "(", ")", ".", "CloudSpec", "!=", "EmptyCloudSpec", "{", "hasRightCloud", ":=", "func", "(", "metadata", "*", "IndexMetadata", ")", "bool", "{", "return", "metadata", ".", "hasCloud", "(", "cons", ".", "Params", "(", ")", ".", "CloudSpec", ")", "\n", "}", "\n", "candidates", "=", "candidates", ".", "filter", "(", "hasRightCloud", ")", "\n", "if", "len", "(", "candidates", ")", "==", "0", "{", "return", "\"", "\"", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "cons", ".", "Params", "(", ")", ".", "CloudSpec", ")", "\n", "}", "\n", "}", "\n", "// Restrict by product IDs.", "hasProduct", ":=", "func", "(", "metadata", "*", "IndexMetadata", ")", "bool", "{", "return", "metadata", ".", "hasProduct", "(", "prodIds", ")", "\n", "}", "\n", "candidates", "=", "candidates", ".", "filter", "(", "hasProduct", ")", "\n", "if", "len", "(", "candidates", ")", "==", "0", "{", "return", "\"", "\"", ",", "newNoMatchingProductsError", "(", "\"", "\"", ",", "prodIds", ")", "\n", "}", "\n\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "prodIds", ",", "candidates", ")", "\n\n", "// Pick arbitrary match.", "return", "candidates", "[", "0", "]", ".", "ProductsFilePath", ",", "nil", "\n", "}" ]
// GetProductsPath returns the path to the metadata file containing products for the specified constraint. // Exported for testing.
[ "GetProductsPath", "returns", "the", "path", "to", "the", "metadata", "file", "containing", "products", "for", "the", "specified", "constraint", ".", "Exported", "for", "testing", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L598-L645
3,545
juju/juju
environs/simplestreams/simplestreams.go
extractMirrorRefs
func (mirrorRefs *MirrorRefs) extractMirrorRefs(contentId string) MirrorRefSlice { for id, refs := range mirrorRefs.Mirrors { if id == contentId { return refs } } return nil }
go
func (mirrorRefs *MirrorRefs) extractMirrorRefs(contentId string) MirrorRefSlice { for id, refs := range mirrorRefs.Mirrors { if id == contentId { return refs } } return nil }
[ "func", "(", "mirrorRefs", "*", "MirrorRefs", ")", "extractMirrorRefs", "(", "contentId", "string", ")", "MirrorRefSlice", "{", "for", "id", ",", "refs", ":=", "range", "mirrorRefs", ".", "Mirrors", "{", "if", "id", "==", "contentId", "{", "return", "refs", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// extractMirrorRefs returns just the array of MirrorRef structs for the contentId, in arbitrary order.
[ "extractMirrorRefs", "returns", "just", "the", "array", "of", "MirrorRef", "structs", "for", "the", "contentId", "in", "arbitrary", "order", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L648-L655
3,546
juju/juju
environs/simplestreams/simplestreams.go
hasCloud
func (mirrorRef *MirrorReference) hasCloud(cloud CloudSpec) bool { for _, refCloud := range mirrorRef.Clouds { if refCloud.equals(&cloud) { return true } } return false }
go
func (mirrorRef *MirrorReference) hasCloud(cloud CloudSpec) bool { for _, refCloud := range mirrorRef.Clouds { if refCloud.equals(&cloud) { return true } } return false }
[ "func", "(", "mirrorRef", "*", "MirrorReference", ")", "hasCloud", "(", "cloud", "CloudSpec", ")", "bool", "{", "for", "_", ",", "refCloud", ":=", "range", "mirrorRef", ".", "Clouds", "{", "if", "refCloud", ".", "equals", "(", "&", "cloud", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// hasCloud tells you whether a MirrorReference has the given cloud in its // Clouds list.
[ "hasCloud", "tells", "you", "whether", "a", "MirrorReference", "has", "the", "given", "cloud", "in", "its", "Clouds", "list", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L659-L666
3,547
juju/juju
environs/simplestreams/simplestreams.go
getMirrorReference
func (mirrorRefs *MirrorRefs) getMirrorReference(datatype, contentId string, cloud CloudSpec) (*MirrorReference, error) { candidates := mirrorRefs.extractMirrorRefs(contentId) if len(candidates) == 0 { return nil, errors.NotFoundf("mirror data for %q", contentId) } // Restrict by cloud spec and datatype. hasRightCloud := func(mirrorRef *MirrorReference) bool { return mirrorRef.hasCloud(cloud) && mirrorRef.DataType == datatype } matchingCandidates := candidates.filter(hasRightCloud) if len(matchingCandidates) == 0 { // No cloud specific mirrors found so look for a non cloud specific mirror. for _, candidate := range candidates { if len(candidate.Clouds) == 0 { logger.Debugf("using default candidate for content id %q are %v", contentId, candidate) return &candidate, nil } } return nil, errors.NotFoundf("index file with cloud %v", cloud) } logger.Debugf("candidate matches for content id %q are %v", contentId, candidates) // Pick arbitrary match. return &matchingCandidates[0], nil }
go
func (mirrorRefs *MirrorRefs) getMirrorReference(datatype, contentId string, cloud CloudSpec) (*MirrorReference, error) { candidates := mirrorRefs.extractMirrorRefs(contentId) if len(candidates) == 0 { return nil, errors.NotFoundf("mirror data for %q", contentId) } // Restrict by cloud spec and datatype. hasRightCloud := func(mirrorRef *MirrorReference) bool { return mirrorRef.hasCloud(cloud) && mirrorRef.DataType == datatype } matchingCandidates := candidates.filter(hasRightCloud) if len(matchingCandidates) == 0 { // No cloud specific mirrors found so look for a non cloud specific mirror. for _, candidate := range candidates { if len(candidate.Clouds) == 0 { logger.Debugf("using default candidate for content id %q are %v", contentId, candidate) return &candidate, nil } } return nil, errors.NotFoundf("index file with cloud %v", cloud) } logger.Debugf("candidate matches for content id %q are %v", contentId, candidates) // Pick arbitrary match. return &matchingCandidates[0], nil }
[ "func", "(", "mirrorRefs", "*", "MirrorRefs", ")", "getMirrorReference", "(", "datatype", ",", "contentId", "string", ",", "cloud", "CloudSpec", ")", "(", "*", "MirrorReference", ",", "error", ")", "{", "candidates", ":=", "mirrorRefs", ".", "extractMirrorRefs", "(", "contentId", ")", "\n", "if", "len", "(", "candidates", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "contentId", ")", "\n", "}", "\n", "// Restrict by cloud spec and datatype.", "hasRightCloud", ":=", "func", "(", "mirrorRef", "*", "MirrorReference", ")", "bool", "{", "return", "mirrorRef", ".", "hasCloud", "(", "cloud", ")", "&&", "mirrorRef", ".", "DataType", "==", "datatype", "\n", "}", "\n", "matchingCandidates", ":=", "candidates", ".", "filter", "(", "hasRightCloud", ")", "\n", "if", "len", "(", "matchingCandidates", ")", "==", "0", "{", "// No cloud specific mirrors found so look for a non cloud specific mirror.", "for", "_", ",", "candidate", ":=", "range", "candidates", "{", "if", "len", "(", "candidate", ".", "Clouds", ")", "==", "0", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "contentId", ",", "candidate", ")", "\n", "return", "&", "candidate", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "cloud", ")", "\n", "}", "\n\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "contentId", ",", "candidates", ")", "\n\n", "// Pick arbitrary match.", "return", "&", "matchingCandidates", "[", "0", "]", ",", "nil", "\n", "}" ]
// getMirrorReference returns the reference to the metadata file containing mirrors for the specified content and cloud.
[ "getMirrorReference", "returns", "the", "reference", "to", "the", "metadata", "file", "containing", "mirrors", "for", "the", "specified", "content", "and", "cloud", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L669-L694
3,548
juju/juju
environs/simplestreams/simplestreams.go
getMirrorInfo
func (mirrorRef *MirrorReference) getMirrorInfo(source DataSource, contentId string, cloud CloudSpec, format string, requireSigned bool) (*MirrorInfo, error) { metadata, err := GetMirrorMetadataWithFormat(source, mirrorRef.Path, format, requireSigned) if err != nil { return nil, err } mirrorInfo, err := metadata.getMirrorInfo(contentId, cloud) if err != nil { return nil, err } return mirrorInfo, nil }
go
func (mirrorRef *MirrorReference) getMirrorInfo(source DataSource, contentId string, cloud CloudSpec, format string, requireSigned bool) (*MirrorInfo, error) { metadata, err := GetMirrorMetadataWithFormat(source, mirrorRef.Path, format, requireSigned) if err != nil { return nil, err } mirrorInfo, err := metadata.getMirrorInfo(contentId, cloud) if err != nil { return nil, err } return mirrorInfo, nil }
[ "func", "(", "mirrorRef", "*", "MirrorReference", ")", "getMirrorInfo", "(", "source", "DataSource", ",", "contentId", "string", ",", "cloud", "CloudSpec", ",", "format", "string", ",", "requireSigned", "bool", ")", "(", "*", "MirrorInfo", ",", "error", ")", "{", "metadata", ",", "err", ":=", "GetMirrorMetadataWithFormat", "(", "source", ",", "mirrorRef", ".", "Path", ",", "format", ",", "requireSigned", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "mirrorInfo", ",", "err", ":=", "metadata", ".", "getMirrorInfo", "(", "contentId", ",", "cloud", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "mirrorInfo", ",", "nil", "\n", "}" ]
// getMirrorInfo returns mirror information from the mirror file at the given path for the specified content and cloud.
[ "getMirrorInfo", "returns", "mirror", "information", "from", "the", "mirror", "file", "at", "the", "given", "path", "for", "the", "specified", "content", "and", "cloud", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L697-L709
3,549
juju/juju
environs/simplestreams/simplestreams.go
GetMirrorMetadataWithFormat
func GetMirrorMetadataWithFormat(source DataSource, mirrorPath, format string, requireSigned bool) (*MirrorMetadata, error) { data, url, err := fetchData(source, mirrorPath, requireSigned) if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { return nil, err } return nil, fmt.Errorf("cannot read mirror data, %v", err) } var mirrors MirrorMetadata err = json.Unmarshal(data, &mirrors) if err != nil { return nil, fmt.Errorf("cannot unmarshal JSON mirror metadata at URL %q: %v", url, err) } if mirrors.Format != format { return nil, fmt.Errorf("unexpected mirror file format %q, expected %q at URL %q", mirrors.Format, format, url) } return &mirrors, nil }
go
func GetMirrorMetadataWithFormat(source DataSource, mirrorPath, format string, requireSigned bool) (*MirrorMetadata, error) { data, url, err := fetchData(source, mirrorPath, requireSigned) if err != nil { if errors.IsNotFound(err) || errors.IsUnauthorized(err) { return nil, err } return nil, fmt.Errorf("cannot read mirror data, %v", err) } var mirrors MirrorMetadata err = json.Unmarshal(data, &mirrors) if err != nil { return nil, fmt.Errorf("cannot unmarshal JSON mirror metadata at URL %q: %v", url, err) } if mirrors.Format != format { return nil, fmt.Errorf("unexpected mirror file format %q, expected %q at URL %q", mirrors.Format, format, url) } return &mirrors, nil }
[ "func", "GetMirrorMetadataWithFormat", "(", "source", "DataSource", ",", "mirrorPath", ",", "format", "string", ",", "requireSigned", "bool", ")", "(", "*", "MirrorMetadata", ",", "error", ")", "{", "data", ",", "url", ",", "err", ":=", "fetchData", "(", "source", ",", "mirrorPath", ",", "requireSigned", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotFound", "(", "err", ")", "||", "errors", ".", "IsUnauthorized", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "var", "mirrors", "MirrorMetadata", "\n", "err", "=", "json", ".", "Unmarshal", "(", "data", ",", "&", "mirrors", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "err", ")", "\n", "}", "\n", "if", "mirrors", ".", "Format", "!=", "format", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "mirrors", ".", "Format", ",", "format", ",", "url", ")", "\n", "}", "\n", "return", "&", "mirrors", ",", "nil", "\n", "}" ]
// GetMirrorMetadataWithFormat returns simplestreams mirror data of the specified format. // Exported for testing.
[ "GetMirrorMetadataWithFormat", "returns", "simplestreams", "mirror", "data", "of", "the", "specified", "format", ".", "Exported", "for", "testing", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L713-L732
3,550
juju/juju
environs/simplestreams/simplestreams.go
hasCloud
func (mirrorInfo *MirrorInfo) hasCloud(cloud CloudSpec) bool { for _, metadataCloud := range mirrorInfo.Clouds { if metadataCloud.equals(&cloud) { return true } } return false }
go
func (mirrorInfo *MirrorInfo) hasCloud(cloud CloudSpec) bool { for _, metadataCloud := range mirrorInfo.Clouds { if metadataCloud.equals(&cloud) { return true } } return false }
[ "func", "(", "mirrorInfo", "*", "MirrorInfo", ")", "hasCloud", "(", "cloud", "CloudSpec", ")", "bool", "{", "for", "_", ",", "metadataCloud", ":=", "range", "mirrorInfo", ".", "Clouds", "{", "if", "metadataCloud", ".", "equals", "(", "&", "cloud", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// hasCloud tells you whether an MirrorInfo has the given cloud in its // Clouds list.
[ "hasCloud", "tells", "you", "whether", "an", "MirrorInfo", "has", "the", "given", "cloud", "in", "its", "Clouds", "list", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L736-L743
3,551
juju/juju
environs/simplestreams/simplestreams.go
getMirrorInfo
func (mirrorMetadata *MirrorMetadata) getMirrorInfo(contentId string, cloud CloudSpec) (*MirrorInfo, error) { var candidates MirrorInfoSlice for id, m := range mirrorMetadata.Mirrors { if id == contentId { candidates = m break } } if len(candidates) == 0 { return nil, errors.NotFoundf("mirror info for %q", contentId) } // Restrict by cloud spec. hasRightCloud := func(mirrorInfo *MirrorInfo) bool { return mirrorInfo.hasCloud(cloud) } candidates = candidates.filter(hasRightCloud) if len(candidates) == 0 { return nil, errors.NotFoundf("mirror info with cloud %v", cloud) } // Pick arbitrary match. return &candidates[0], nil }
go
func (mirrorMetadata *MirrorMetadata) getMirrorInfo(contentId string, cloud CloudSpec) (*MirrorInfo, error) { var candidates MirrorInfoSlice for id, m := range mirrorMetadata.Mirrors { if id == contentId { candidates = m break } } if len(candidates) == 0 { return nil, errors.NotFoundf("mirror info for %q", contentId) } // Restrict by cloud spec. hasRightCloud := func(mirrorInfo *MirrorInfo) bool { return mirrorInfo.hasCloud(cloud) } candidates = candidates.filter(hasRightCloud) if len(candidates) == 0 { return nil, errors.NotFoundf("mirror info with cloud %v", cloud) } // Pick arbitrary match. return &candidates[0], nil }
[ "func", "(", "mirrorMetadata", "*", "MirrorMetadata", ")", "getMirrorInfo", "(", "contentId", "string", ",", "cloud", "CloudSpec", ")", "(", "*", "MirrorInfo", ",", "error", ")", "{", "var", "candidates", "MirrorInfoSlice", "\n", "for", "id", ",", "m", ":=", "range", "mirrorMetadata", ".", "Mirrors", "{", "if", "id", "==", "contentId", "{", "candidates", "=", "m", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "len", "(", "candidates", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "contentId", ")", "\n", "}", "\n\n", "// Restrict by cloud spec.", "hasRightCloud", ":=", "func", "(", "mirrorInfo", "*", "MirrorInfo", ")", "bool", "{", "return", "mirrorInfo", ".", "hasCloud", "(", "cloud", ")", "\n", "}", "\n", "candidates", "=", "candidates", ".", "filter", "(", "hasRightCloud", ")", "\n", "if", "len", "(", "candidates", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "cloud", ")", "\n", "}", "\n\n", "// Pick arbitrary match.", "return", "&", "candidates", "[", "0", "]", ",", "nil", "\n", "}" ]
// getMirrorInfo returns the mirror metadata for the specified content and cloud.
[ "getMirrorInfo", "returns", "the", "mirror", "metadata", "for", "the", "specified", "content", "and", "cloud", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L746-L769
3,552
juju/juju
environs/simplestreams/simplestreams.go
containsString
func containsString(values []string, element string) bool { for _, value := range values { if value == element { return true } } return false }
go
func containsString(values []string, element string) bool { for _, value := range values { if value == element { return true } } return false }
[ "func", "containsString", "(", "values", "[", "]", "string", ",", "element", "string", ")", "bool", "{", "for", "_", ",", "value", ":=", "range", "values", "{", "if", "value", "==", "element", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// utility function to see if element exists in values slice.
[ "utility", "function", "to", "see", "if", "element", "exists", "in", "values", "slice", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L772-L779
3,553
juju/juju
environs/simplestreams/simplestreams.go
processAliases
func (metadata *CloudMetadata) processAliases(item interface{}) { for tag := range tags(item) { aliases, ok := metadata.Aliases[tag] if !ok { continue } // We have found a set of aliases for one of the fields in the metadata struct. // Now check to see if the field matches one of the defined aliases. fields, ok := aliases[fieldByTag(item, tag)] if !ok { continue } // The alias matches - set all the aliased fields in the struct. for attr, val := range fields { setFieldByTag(item, attr, val, true) } } }
go
func (metadata *CloudMetadata) processAliases(item interface{}) { for tag := range tags(item) { aliases, ok := metadata.Aliases[tag] if !ok { continue } // We have found a set of aliases for one of the fields in the metadata struct. // Now check to see if the field matches one of the defined aliases. fields, ok := aliases[fieldByTag(item, tag)] if !ok { continue } // The alias matches - set all the aliased fields in the struct. for attr, val := range fields { setFieldByTag(item, attr, val, true) } } }
[ "func", "(", "metadata", "*", "CloudMetadata", ")", "processAliases", "(", "item", "interface", "{", "}", ")", "{", "for", "tag", ":=", "range", "tags", "(", "item", ")", "{", "aliases", ",", "ok", ":=", "metadata", ".", "Aliases", "[", "tag", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "// We have found a set of aliases for one of the fields in the metadata struct.", "// Now check to see if the field matches one of the defined aliases.", "fields", ",", "ok", ":=", "aliases", "[", "fieldByTag", "(", "item", ",", "tag", ")", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "// The alias matches - set all the aliased fields in the struct.", "for", "attr", ",", "val", ":=", "range", "fields", "{", "setFieldByTag", "(", "item", ",", "attr", ",", "val", ",", "true", ")", "\n", "}", "\n", "}", "\n", "}" ]
// processAliases looks through the struct fields to see if // any aliases apply, and sets attributes appropriately if so.
[ "processAliases", "looks", "through", "the", "struct", "fields", "to", "see", "if", "any", "aliases", "apply", "and", "sets", "attributes", "appropriately", "if", "so", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L807-L824
3,554
juju/juju
environs/simplestreams/simplestreams.go
applyAliases
func (metadata *CloudMetadata) applyAliases() { for _, metadataCatalog := range metadata.Products { for _, ItemCollection := range metadataCatalog.Items { for _, item := range ItemCollection.Items { metadata.processAliases(item) } } } }
go
func (metadata *CloudMetadata) applyAliases() { for _, metadataCatalog := range metadata.Products { for _, ItemCollection := range metadataCatalog.Items { for _, item := range ItemCollection.Items { metadata.processAliases(item) } } } }
[ "func", "(", "metadata", "*", "CloudMetadata", ")", "applyAliases", "(", ")", "{", "for", "_", ",", "metadataCatalog", ":=", "range", "metadata", ".", "Products", "{", "for", "_", ",", "ItemCollection", ":=", "range", "metadataCatalog", ".", "Items", "{", "for", "_", ",", "item", ":=", "range", "ItemCollection", ".", "Items", "{", "metadata", ".", "processAliases", "(", "item", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Apply any attribute aliases to the metadata records.
[ "Apply", "any", "attribute", "aliases", "to", "the", "metadata", "records", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L827-L835
3,555
juju/juju
environs/simplestreams/simplestreams.go
construct
func (metadata *CloudMetadata) construct(valueType reflect.Type) error { for _, metadataCatalog := range metadata.Products { for _, ItemCollection := range metadataCatalog.Items { if err := ItemCollection.construct(valueType); err != nil { return err } } } return nil }
go
func (metadata *CloudMetadata) construct(valueType reflect.Type) error { for _, metadataCatalog := range metadata.Products { for _, ItemCollection := range metadataCatalog.Items { if err := ItemCollection.construct(valueType); err != nil { return err } } } return nil }
[ "func", "(", "metadata", "*", "CloudMetadata", ")", "construct", "(", "valueType", "reflect", ".", "Type", ")", "error", "{", "for", "_", ",", "metadataCatalog", ":=", "range", "metadata", ".", "Products", "{", "for", "_", ",", "ItemCollection", ":=", "range", "metadataCatalog", ".", "Items", "{", "if", "err", ":=", "ItemCollection", ".", "construct", "(", "valueType", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// construct iterates over the metadata records and replaces the generic maps of values // with structs of the required type.
[ "construct", "iterates", "over", "the", "metadata", "records", "and", "replaces", "the", "generic", "maps", "of", "values", "with", "structs", "of", "the", "required", "type", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L839-L848
3,556
juju/juju
environs/simplestreams/simplestreams.go
GetCloudMetadataWithFormat
func (indexRef *IndexReference) GetCloudMetadataWithFormat(cons LookupConstraint, format string, requireSigned bool) (*CloudMetadata, error) { productFilesPath, err := indexRef.GetProductsPath(cons) if err != nil { return nil, err } logger.Tracef("finding products at path %q", productFilesPath) data, url, err := fetchData(indexRef.Source, productFilesPath, requireSigned) if err != nil { logger.Tracef("can't read product data: %v", err) return nil, fmt.Errorf("cannot read product data, %v", err) } return ParseCloudMetadata(data, format, url, indexRef.valueParams.ValueTemplate) }
go
func (indexRef *IndexReference) GetCloudMetadataWithFormat(cons LookupConstraint, format string, requireSigned bool) (*CloudMetadata, error) { productFilesPath, err := indexRef.GetProductsPath(cons) if err != nil { return nil, err } logger.Tracef("finding products at path %q", productFilesPath) data, url, err := fetchData(indexRef.Source, productFilesPath, requireSigned) if err != nil { logger.Tracef("can't read product data: %v", err) return nil, fmt.Errorf("cannot read product data, %v", err) } return ParseCloudMetadata(data, format, url, indexRef.valueParams.ValueTemplate) }
[ "func", "(", "indexRef", "*", "IndexReference", ")", "GetCloudMetadataWithFormat", "(", "cons", "LookupConstraint", ",", "format", "string", ",", "requireSigned", "bool", ")", "(", "*", "CloudMetadata", ",", "error", ")", "{", "productFilesPath", ",", "err", ":=", "indexRef", ".", "GetProductsPath", "(", "cons", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "productFilesPath", ")", "\n", "data", ",", "url", ",", "err", ":=", "fetchData", "(", "indexRef", ".", "Source", ",", "productFilesPath", ",", "requireSigned", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "ParseCloudMetadata", "(", "data", ",", "format", ",", "url", ",", "indexRef", ".", "valueParams", ".", "ValueTemplate", ")", "\n", "}" ]
// GetCloudMetadataWithFormat loads the entire cloud metadata encoded using the specified format. // Exported for testing.
[ "GetCloudMetadataWithFormat", "loads", "the", "entire", "cloud", "metadata", "encoded", "using", "the", "specified", "format", ".", "Exported", "for", "testing", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L949-L961
3,557
juju/juju
environs/simplestreams/simplestreams.go
ParseCloudMetadata
func ParseCloudMetadata(data []byte, format, url string, valueTemplate interface{}) (*CloudMetadata, error) { var metadata CloudMetadata err := json.Unmarshal(data, &metadata) if err != nil { return nil, fmt.Errorf("cannot unmarshal JSON metadata at URL %q: %v", url, err) } if metadata.Format != format { return nil, fmt.Errorf("unexpected index file format %q, expected %q at URL %q", metadata.Format, format, url) } if valueTemplate != nil { err = metadata.construct(reflect.TypeOf(valueTemplate)) } if err != nil { logger.Errorf("bad JSON product data at URL %q: %v", url, string(data)) return nil, fmt.Errorf("cannot unmarshal JSON metadata at URL %q: %v", url, err) } metadata.applyAliases() metadata.denormaliseMetadata() return &metadata, nil }
go
func ParseCloudMetadata(data []byte, format, url string, valueTemplate interface{}) (*CloudMetadata, error) { var metadata CloudMetadata err := json.Unmarshal(data, &metadata) if err != nil { return nil, fmt.Errorf("cannot unmarshal JSON metadata at URL %q: %v", url, err) } if metadata.Format != format { return nil, fmt.Errorf("unexpected index file format %q, expected %q at URL %q", metadata.Format, format, url) } if valueTemplate != nil { err = metadata.construct(reflect.TypeOf(valueTemplate)) } if err != nil { logger.Errorf("bad JSON product data at URL %q: %v", url, string(data)) return nil, fmt.Errorf("cannot unmarshal JSON metadata at URL %q: %v", url, err) } metadata.applyAliases() metadata.denormaliseMetadata() return &metadata, nil }
[ "func", "ParseCloudMetadata", "(", "data", "[", "]", "byte", ",", "format", ",", "url", "string", ",", "valueTemplate", "interface", "{", "}", ")", "(", "*", "CloudMetadata", ",", "error", ")", "{", "var", "metadata", "CloudMetadata", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "metadata", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "err", ")", "\n", "}", "\n", "if", "metadata", ".", "Format", "!=", "format", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "metadata", ".", "Format", ",", "format", ",", "url", ")", "\n", "}", "\n", "if", "valueTemplate", "!=", "nil", "{", "err", "=", "metadata", ".", "construct", "(", "reflect", ".", "TypeOf", "(", "valueTemplate", ")", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "string", "(", "data", ")", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ",", "err", ")", "\n", "}", "\n", "metadata", ".", "applyAliases", "(", ")", "\n", "metadata", ".", "denormaliseMetadata", "(", ")", "\n", "return", "&", "metadata", ",", "nil", "\n", "}" ]
// ParseCloudMetadata parses the given bytes into simplestreams metadata.
[ "ParseCloudMetadata", "parses", "the", "given", "bytes", "into", "simplestreams", "metadata", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/simplestreams/simplestreams.go#L964-L983
3,558
juju/juju
apiserver/facades/client/applicationoffers/conversions.go
paramsFromProviderSpaceInfo
func paramsFromProviderSpaceInfo(info *environs.ProviderSpaceInfo) params.RemoteSpace { result := params.RemoteSpace{ CloudType: info.CloudType, Name: info.Name, ProviderId: string(info.ProviderId), ProviderAttributes: info.ProviderAttributes, } for _, subnet := range info.Subnets { resultSubnet := params.Subnet{ CIDR: subnet.CIDR, ProviderId: string(subnet.ProviderId), ProviderNetworkId: string(subnet.ProviderNetworkId), ProviderSpaceId: string(subnet.SpaceProviderId), VLANTag: subnet.VLANTag, Zones: subnet.AvailabilityZones, } result.Subnets = append(result.Subnets, resultSubnet) } return result }
go
func paramsFromProviderSpaceInfo(info *environs.ProviderSpaceInfo) params.RemoteSpace { result := params.RemoteSpace{ CloudType: info.CloudType, Name: info.Name, ProviderId: string(info.ProviderId), ProviderAttributes: info.ProviderAttributes, } for _, subnet := range info.Subnets { resultSubnet := params.Subnet{ CIDR: subnet.CIDR, ProviderId: string(subnet.ProviderId), ProviderNetworkId: string(subnet.ProviderNetworkId), ProviderSpaceId: string(subnet.SpaceProviderId), VLANTag: subnet.VLANTag, Zones: subnet.AvailabilityZones, } result.Subnets = append(result.Subnets, resultSubnet) } return result }
[ "func", "paramsFromProviderSpaceInfo", "(", "info", "*", "environs", ".", "ProviderSpaceInfo", ")", "params", ".", "RemoteSpace", "{", "result", ":=", "params", ".", "RemoteSpace", "{", "CloudType", ":", "info", ".", "CloudType", ",", "Name", ":", "info", ".", "Name", ",", "ProviderId", ":", "string", "(", "info", ".", "ProviderId", ")", ",", "ProviderAttributes", ":", "info", ".", "ProviderAttributes", ",", "}", "\n", "for", "_", ",", "subnet", ":=", "range", "info", ".", "Subnets", "{", "resultSubnet", ":=", "params", ".", "Subnet", "{", "CIDR", ":", "subnet", ".", "CIDR", ",", "ProviderId", ":", "string", "(", "subnet", ".", "ProviderId", ")", ",", "ProviderNetworkId", ":", "string", "(", "subnet", ".", "ProviderNetworkId", ")", ",", "ProviderSpaceId", ":", "string", "(", "subnet", ".", "SpaceProviderId", ")", ",", "VLANTag", ":", "subnet", ".", "VLANTag", ",", "Zones", ":", "subnet", ".", "AvailabilityZones", ",", "}", "\n", "result", ".", "Subnets", "=", "append", "(", "result", ".", "Subnets", ",", "resultSubnet", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// paramsFromProviderSpaceInfo converts a ProviderSpaceInfo into the // equivalent params.RemoteSpace.
[ "paramsFromProviderSpaceInfo", "converts", "a", "ProviderSpaceInfo", "into", "the", "equivalent", "params", ".", "RemoteSpace", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/conversions.go#L16-L35
3,559
juju/juju
apiserver/facades/client/applicationoffers/conversions.go
spaceInfoFromState
func spaceInfoFromState(space Space) (*network.SpaceInfo, error) { result := &network.SpaceInfo{ Name: space.Name(), ProviderId: space.ProviderId(), } subnets, err := space.Subnets() if err != nil { return nil, errors.Trace(err) } for _, subnet := range subnets { resultSubnet := network.SubnetInfo{ CIDR: subnet.CIDR(), ProviderId: subnet.ProviderId(), ProviderNetworkId: subnet.ProviderNetworkId(), VLANTag: subnet.VLANTag(), AvailabilityZones: subnet.AvailabilityZones(), } result.Subnets = append(result.Subnets, resultSubnet) } return result, nil }
go
func spaceInfoFromState(space Space) (*network.SpaceInfo, error) { result := &network.SpaceInfo{ Name: space.Name(), ProviderId: space.ProviderId(), } subnets, err := space.Subnets() if err != nil { return nil, errors.Trace(err) } for _, subnet := range subnets { resultSubnet := network.SubnetInfo{ CIDR: subnet.CIDR(), ProviderId: subnet.ProviderId(), ProviderNetworkId: subnet.ProviderNetworkId(), VLANTag: subnet.VLANTag(), AvailabilityZones: subnet.AvailabilityZones(), } result.Subnets = append(result.Subnets, resultSubnet) } return result, nil }
[ "func", "spaceInfoFromState", "(", "space", "Space", ")", "(", "*", "network", ".", "SpaceInfo", ",", "error", ")", "{", "result", ":=", "&", "network", ".", "SpaceInfo", "{", "Name", ":", "space", ".", "Name", "(", ")", ",", "ProviderId", ":", "space", ".", "ProviderId", "(", ")", ",", "}", "\n", "subnets", ",", "err", ":=", "space", ".", "Subnets", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "for", "_", ",", "subnet", ":=", "range", "subnets", "{", "resultSubnet", ":=", "network", ".", "SubnetInfo", "{", "CIDR", ":", "subnet", ".", "CIDR", "(", ")", ",", "ProviderId", ":", "subnet", ".", "ProviderId", "(", ")", ",", "ProviderNetworkId", ":", "subnet", ".", "ProviderNetworkId", "(", ")", ",", "VLANTag", ":", "subnet", ".", "VLANTag", "(", ")", ",", "AvailabilityZones", ":", "subnet", ".", "AvailabilityZones", "(", ")", ",", "}", "\n", "result", ".", "Subnets", "=", "append", "(", "result", ".", "Subnets", ",", "resultSubnet", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// spaceInfoFromState converts a state.Space into the equivalent // network.SpaceInfo.
[ "spaceInfoFromState", "converts", "a", "state", ".", "Space", "into", "the", "equivalent", "network", ".", "SpaceInfo", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/applicationoffers/conversions.go#L64-L84
3,560
juju/juju
provider/openstack/image.go
findInstanceSpec
func findInstanceSpec( e *Environ, ic *instances.InstanceConstraint, imageMetadata []*imagemetadata.ImageMetadata, ) (*instances.InstanceSpec, error) { // First construct all available instance types from the supported flavors. nova := e.nova() flavors, err := nova.ListFlavorsDetail() if err != nil { return nil, err } // Not all needed information is available in flavors, // for e.g. architectures or virtualisation types. // For these properties, we assume that all instance types support // all values. allInstanceTypes := []instances.InstanceType{} for _, flavor := range flavors { if !e.flavorFilter.AcceptFlavor(flavor) { continue } instanceType := instances.InstanceType{ Id: flavor.Id, Name: flavor.Name, Arches: ic.Arches, Mem: uint64(flavor.RAM), CpuCores: uint64(flavor.VCPUs), RootDisk: uint64(flavor.Disk * 1024), // tags not currently supported on openstack } if ic.Constraints.HasVirtType() { // Instance Type virtual type depends on the virtual type of the selected image, i.e. // picking an image with a virt type gives a machine with this virt type. instanceType.VirtType = ic.Constraints.VirtType } allInstanceTypes = append(allInstanceTypes, instanceType) } images := instances.ImageMetadataToImages(imageMetadata) spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes) if err != nil { return nil, err } // If instance constraints did not have a virtualisation type, // but image metadata did, we will have an instance type // with virtualisation type of an image. if !ic.Constraints.HasVirtType() && spec.Image.VirtType != "" { spec.InstanceType.VirtType = &spec.Image.VirtType } return spec, nil }
go
func findInstanceSpec( e *Environ, ic *instances.InstanceConstraint, imageMetadata []*imagemetadata.ImageMetadata, ) (*instances.InstanceSpec, error) { // First construct all available instance types from the supported flavors. nova := e.nova() flavors, err := nova.ListFlavorsDetail() if err != nil { return nil, err } // Not all needed information is available in flavors, // for e.g. architectures or virtualisation types. // For these properties, we assume that all instance types support // all values. allInstanceTypes := []instances.InstanceType{} for _, flavor := range flavors { if !e.flavorFilter.AcceptFlavor(flavor) { continue } instanceType := instances.InstanceType{ Id: flavor.Id, Name: flavor.Name, Arches: ic.Arches, Mem: uint64(flavor.RAM), CpuCores: uint64(flavor.VCPUs), RootDisk: uint64(flavor.Disk * 1024), // tags not currently supported on openstack } if ic.Constraints.HasVirtType() { // Instance Type virtual type depends on the virtual type of the selected image, i.e. // picking an image with a virt type gives a machine with this virt type. instanceType.VirtType = ic.Constraints.VirtType } allInstanceTypes = append(allInstanceTypes, instanceType) } images := instances.ImageMetadataToImages(imageMetadata) spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes) if err != nil { return nil, err } // If instance constraints did not have a virtualisation type, // but image metadata did, we will have an instance type // with virtualisation type of an image. if !ic.Constraints.HasVirtType() && spec.Image.VirtType != "" { spec.InstanceType.VirtType = &spec.Image.VirtType } return spec, nil }
[ "func", "findInstanceSpec", "(", "e", "*", "Environ", ",", "ic", "*", "instances", ".", "InstanceConstraint", ",", "imageMetadata", "[", "]", "*", "imagemetadata", ".", "ImageMetadata", ",", ")", "(", "*", "instances", ".", "InstanceSpec", ",", "error", ")", "{", "// First construct all available instance types from the supported flavors.", "nova", ":=", "e", ".", "nova", "(", ")", "\n", "flavors", ",", "err", ":=", "nova", ".", "ListFlavorsDetail", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Not all needed information is available in flavors,", "// for e.g. architectures or virtualisation types.", "// For these properties, we assume that all instance types support", "// all values.", "allInstanceTypes", ":=", "[", "]", "instances", ".", "InstanceType", "{", "}", "\n", "for", "_", ",", "flavor", ":=", "range", "flavors", "{", "if", "!", "e", ".", "flavorFilter", ".", "AcceptFlavor", "(", "flavor", ")", "{", "continue", "\n", "}", "\n", "instanceType", ":=", "instances", ".", "InstanceType", "{", "Id", ":", "flavor", ".", "Id", ",", "Name", ":", "flavor", ".", "Name", ",", "Arches", ":", "ic", ".", "Arches", ",", "Mem", ":", "uint64", "(", "flavor", ".", "RAM", ")", ",", "CpuCores", ":", "uint64", "(", "flavor", ".", "VCPUs", ")", ",", "RootDisk", ":", "uint64", "(", "flavor", ".", "Disk", "*", "1024", ")", ",", "// tags not currently supported on openstack", "}", "\n", "if", "ic", ".", "Constraints", ".", "HasVirtType", "(", ")", "{", "// Instance Type virtual type depends on the virtual type of the selected image, i.e.", "// picking an image with a virt type gives a machine with this virt type.", "instanceType", ".", "VirtType", "=", "ic", ".", "Constraints", ".", "VirtType", "\n", "}", "\n", "allInstanceTypes", "=", "append", "(", "allInstanceTypes", ",", "instanceType", ")", "\n", "}", "\n\n", "images", ":=", "instances", ".", "ImageMetadataToImages", "(", "imageMetadata", ")", "\n", "spec", ",", "err", ":=", "instances", ".", "FindInstanceSpec", "(", "images", ",", "ic", ",", "allInstanceTypes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// If instance constraints did not have a virtualisation type,", "// but image metadata did, we will have an instance type", "// with virtualisation type of an image.", "if", "!", "ic", ".", "Constraints", ".", "HasVirtType", "(", ")", "&&", "spec", ".", "Image", ".", "VirtType", "!=", "\"", "\"", "{", "spec", ".", "InstanceType", ".", "VirtType", "=", "&", "spec", ".", "Image", ".", "VirtType", "\n", "}", "\n", "return", "spec", ",", "nil", "\n", "}" ]
// findInstanceSpec returns an image and instance type satisfying the constraint. // The instance type comes from querying the flavors supported by the deployment.
[ "findInstanceSpec", "returns", "an", "image", "and", "instance", "type", "satisfying", "the", "constraint", ".", "The", "instance", "type", "comes", "from", "querying", "the", "flavors", "supported", "by", "the", "deployment", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/image.go#L36-L86
3,561
juju/juju
api/undertaker/undertaker.go
NewClient
func NewClient(caller base.APICaller, newWatcher NewWatcherFunc) (*Client, error) { modelTag, ok := caller.ModelTag() if !ok { return nil, errors.New("undertaker client is not appropriate for controller-only API") } return &Client{ modelTag: modelTag, caller: base.NewFacadeCaller(caller, "Undertaker"), newWatcher: newWatcher, }, nil }
go
func NewClient(caller base.APICaller, newWatcher NewWatcherFunc) (*Client, error) { modelTag, ok := caller.ModelTag() if !ok { return nil, errors.New("undertaker client is not appropriate for controller-only API") } return &Client{ modelTag: modelTag, caller: base.NewFacadeCaller(caller, "Undertaker"), newWatcher: newWatcher, }, nil }
[ "func", "NewClient", "(", "caller", "base", ".", "APICaller", ",", "newWatcher", "NewWatcherFunc", ")", "(", "*", "Client", ",", "error", ")", "{", "modelTag", ",", "ok", ":=", "caller", ".", "ModelTag", "(", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "&", "Client", "{", "modelTag", ":", "modelTag", ",", "caller", ":", "base", ".", "NewFacadeCaller", "(", "caller", ",", "\"", "\"", ")", ",", "newWatcher", ":", "newWatcher", ",", "}", ",", "nil", "\n", "}" ]
// NewClient creates a new client for accessing the undertaker API.
[ "NewClient", "creates", "a", "new", "client", "for", "accessing", "the", "undertaker", "API", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/undertaker/undertaker.go#L27-L37
3,562
juju/juju
api/undertaker/undertaker.go
WatchModelResources
func (c *Client) WatchModelResources() (watcher.NotifyWatcher, error) { var results params.NotifyWatchResults err := c.entityFacadeCall("WatchModelResources", &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } w := c.newWatcher(c.caller.RawAPICaller(), result) return w, nil }
go
func (c *Client) WatchModelResources() (watcher.NotifyWatcher, error) { var results params.NotifyWatchResults err := c.entityFacadeCall("WatchModelResources", &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } w := c.newWatcher(c.caller.RawAPICaller(), result) return w, nil }
[ "func", "(", "c", "*", "Client", ")", "WatchModelResources", "(", ")", "(", "watcher", ".", "NotifyWatcher", ",", "error", ")", "{", "var", "results", "params", ".", "NotifyWatchResults", "\n", "err", ":=", "c", ".", "entityFacadeCall", "(", "\"", "\"", ",", "&", "results", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "results", ".", "Results", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "results", ".", "Results", ")", ")", "\n", "}", "\n", "result", ":=", "results", ".", "Results", "[", "0", "]", "\n", "if", "result", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "w", ":=", "c", ".", "newWatcher", "(", "c", ".", "caller", ".", "RawAPICaller", "(", ")", ",", "result", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchModelResources starts a watcher for changes to the model's // machines and applications.
[ "WatchModelResources", "starts", "a", "watcher", "for", "changes", "to", "the", "model", "s", "machines", "and", "applications", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/undertaker/undertaker.go#L86-L102
3,563
juju/juju
provider/oracle/network/firewall.go
NewFirewall
func NewFirewall(cfg environs.ConfigGetter, client FirewallerAPI, c clock.Clock) *Firewall { return &Firewall{ environ: cfg, client: client, clock: c, } }
go
func NewFirewall(cfg environs.ConfigGetter, client FirewallerAPI, c clock.Clock) *Firewall { return &Firewall{ environ: cfg, client: client, clock: c, } }
[ "func", "NewFirewall", "(", "cfg", "environs", ".", "ConfigGetter", ",", "client", "FirewallerAPI", ",", "c", "clock", ".", "Clock", ")", "*", "Firewall", "{", "return", "&", "Firewall", "{", "environ", ":", "cfg", ",", "client", ":", "client", ",", "clock", ":", "c", ",", "}", "\n", "}" ]
// NewFirewall returns a new Firewall
[ "NewFirewall", "returns", "a", "new", "Firewall" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L92-L98
3,564
juju/juju
provider/oracle/network/firewall.go
OpenPorts
func (f Firewall) OpenPorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { mode := f.environ.Config().FirewallMode() if mode != config.FwGlobal { return fmt.Errorf( "invalid firewall mode %q for opening ports on model", mode, ) } globalGroupName := f.globalGroupName() seclist, err := f.ensureSecList(f.client.ComposeName(globalGroupName)) if err != nil { return errors.Trace(err) } err = f.ensureSecRules(seclist, rules) if err != nil { return errors.Trace(err) } return nil }
go
func (f Firewall) OpenPorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { mode := f.environ.Config().FirewallMode() if mode != config.FwGlobal { return fmt.Errorf( "invalid firewall mode %q for opening ports on model", mode, ) } globalGroupName := f.globalGroupName() seclist, err := f.ensureSecList(f.client.ComposeName(globalGroupName)) if err != nil { return errors.Trace(err) } err = f.ensureSecRules(seclist, rules) if err != nil { return errors.Trace(err) } return nil }
[ "func", "(", "f", "Firewall", ")", "OpenPorts", "(", "ctx", "context", ".", "ProviderCallContext", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "mode", ":=", "f", ".", "environ", ".", "Config", "(", ")", ".", "FirewallMode", "(", ")", "\n", "if", "mode", "!=", "config", ".", "FwGlobal", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "mode", ",", ")", "\n", "}", "\n\n", "globalGroupName", ":=", "f", ".", "globalGroupName", "(", ")", "\n", "seclist", ",", "err", ":=", "f", ".", "ensureSecList", "(", "f", ".", "client", ".", "ComposeName", "(", "globalGroupName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "err", "=", "f", ".", "ensureSecRules", "(", "seclist", ",", "rules", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// OpenPorts is specified on the environ.Firewaller interface.
[ "OpenPorts", "is", "specified", "on", "the", "environ", ".", "Firewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L101-L120
3,565
juju/juju
provider/oracle/network/firewall.go
ClosePorts
func (f Firewall) ClosePorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { groupName := f.globalGroupName() return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules) }
go
func (f Firewall) ClosePorts(ctx context.ProviderCallContext, rules []network.IngressRule) error { groupName := f.globalGroupName() return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules) }
[ "func", "(", "f", "Firewall", ")", "ClosePorts", "(", "ctx", "context", ".", "ProviderCallContext", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "groupName", ":=", "f", ".", "globalGroupName", "(", ")", "\n", "return", "f", ".", "closePortsOnList", "(", "ctx", ",", "f", ".", "client", ".", "ComposeName", "(", "groupName", ")", ",", "rules", ")", "\n", "}" ]
// ClosePorts is specified on the environ.Firewaller interface.
[ "ClosePorts", "is", "specified", "on", "the", "environ", ".", "Firewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L123-L126
3,566
juju/juju
provider/oracle/network/firewall.go
IngressRules
func (f Firewall) IngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) { return f.GlobalIngressRules(ctx) }
go
func (f Firewall) IngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) { return f.GlobalIngressRules(ctx) }
[ "func", "(", "f", "Firewall", ")", "IngressRules", "(", "ctx", "context", ".", "ProviderCallContext", ")", "(", "[", "]", "network", ".", "IngressRule", ",", "error", ")", "{", "return", "f", ".", "GlobalIngressRules", "(", "ctx", ")", "\n", "}" ]
// IngressRules is specified on the environ.Firewaller interface.
[ "IngressRules", "is", "specified", "on", "the", "environ", ".", "Firewaller", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L129-L131
3,567
juju/juju
provider/oracle/network/firewall.go
MachineIngressRules
func (f Firewall) MachineIngressRules(ctx context.ProviderCallContext, machineId string) ([]network.IngressRule, error) { seclist := f.machineGroupName(machineId) return f.getIngressRules(ctx, f.client.ComposeName(seclist)) }
go
func (f Firewall) MachineIngressRules(ctx context.ProviderCallContext, machineId string) ([]network.IngressRule, error) { seclist := f.machineGroupName(machineId) return f.getIngressRules(ctx, f.client.ComposeName(seclist)) }
[ "func", "(", "f", "Firewall", ")", "MachineIngressRules", "(", "ctx", "context", ".", "ProviderCallContext", ",", "machineId", "string", ")", "(", "[", "]", "network", ".", "IngressRule", ",", "error", ")", "{", "seclist", ":=", "f", ".", "machineGroupName", "(", "machineId", ")", "\n", "return", "f", ".", "getIngressRules", "(", "ctx", ",", "f", ".", "client", ".", "ComposeName", "(", "seclist", ")", ")", "\n", "}" ]
// MachineIngressRules returns all ingress rules from the machine specific sec list
[ "MachineIngressRules", "returns", "all", "ingress", "rules", "from", "the", "machine", "specific", "sec", "list" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L134-L137
3,568
juju/juju
provider/oracle/network/firewall.go
OpenPortsOnInstance
func (f Firewall) OpenPortsOnInstance(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error { machineGroup := f.machineGroupName(machineId) seclist, err := f.ensureSecList(f.client.ComposeName(machineGroup)) if err != nil { return errors.Trace(err) } err = f.ensureSecRules(seclist, rules) if err != nil { return errors.Trace(err) } return nil }
go
func (f Firewall) OpenPortsOnInstance(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error { machineGroup := f.machineGroupName(machineId) seclist, err := f.ensureSecList(f.client.ComposeName(machineGroup)) if err != nil { return errors.Trace(err) } err = f.ensureSecRules(seclist, rules) if err != nil { return errors.Trace(err) } return nil }
[ "func", "(", "f", "Firewall", ")", "OpenPortsOnInstance", "(", "ctx", "context", ".", "ProviderCallContext", ",", "machineId", "string", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "machineGroup", ":=", "f", ".", "machineGroupName", "(", "machineId", ")", "\n", "seclist", ",", "err", ":=", "f", ".", "ensureSecList", "(", "f", ".", "client", ".", "ComposeName", "(", "machineGroup", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "err", "=", "f", ".", "ensureSecRules", "(", "seclist", ",", "rules", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// OpenPortsOnInstance will open ports corresponding to the supplied rules // on the given instance
[ "OpenPortsOnInstance", "will", "open", "ports", "corresponding", "to", "the", "supplied", "rules", "on", "the", "given", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L141-L152
3,569
juju/juju
provider/oracle/network/firewall.go
ClosePortsOnInstance
func (f Firewall) ClosePortsOnInstance(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error { // fetch the group name based on the machine id provided groupName := f.machineGroupName(machineId) return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules) }
go
func (f Firewall) ClosePortsOnInstance(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error { // fetch the group name based on the machine id provided groupName := f.machineGroupName(machineId) return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules) }
[ "func", "(", "f", "Firewall", ")", "ClosePortsOnInstance", "(", "ctx", "context", ".", "ProviderCallContext", ",", "machineId", "string", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "// fetch the group name based on the machine id provided", "groupName", ":=", "f", ".", "machineGroupName", "(", "machineId", ")", "\n", "return", "f", ".", "closePortsOnList", "(", "ctx", ",", "f", ".", "client", ".", "ComposeName", "(", "groupName", ")", ",", "rules", ")", "\n", "}" ]
// ClosePortsOnInstnace will close ports corresponding to the supplied rules // for a given instance.
[ "ClosePortsOnInstnace", "will", "close", "ports", "corresponding", "to", "the", "supplied", "rules", "for", "a", "given", "instance", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L156-L160
3,570
juju/juju
provider/oracle/network/firewall.go
CreateMachineSecLists
func (f Firewall) CreateMachineSecLists(machineId string, apiPort int) ([]string, error) { defaultSecList, err := f.createDefaultGroupAndRules(apiPort) if err != nil { return nil, errors.Trace(err) } name := f.machineGroupName(machineId) resourceName := f.client.ComposeName(name) secList, err := f.ensureSecList(resourceName) if err != nil { return nil, errors.Trace(err) } return []string{ defaultSecList.Name, secList.Name, }, nil }
go
func (f Firewall) CreateMachineSecLists(machineId string, apiPort int) ([]string, error) { defaultSecList, err := f.createDefaultGroupAndRules(apiPort) if err != nil { return nil, errors.Trace(err) } name := f.machineGroupName(machineId) resourceName := f.client.ComposeName(name) secList, err := f.ensureSecList(resourceName) if err != nil { return nil, errors.Trace(err) } return []string{ defaultSecList.Name, secList.Name, }, nil }
[ "func", "(", "f", "Firewall", ")", "CreateMachineSecLists", "(", "machineId", "string", ",", "apiPort", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "defaultSecList", ",", "err", ":=", "f", ".", "createDefaultGroupAndRules", "(", "apiPort", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "name", ":=", "f", ".", "machineGroupName", "(", "machineId", ")", "\n", "resourceName", ":=", "f", ".", "client", ".", "ComposeName", "(", "name", ")", "\n", "secList", ",", "err", ":=", "f", ".", "ensureSecList", "(", "resourceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "[", "]", "string", "{", "defaultSecList", ".", "Name", ",", "secList", ".", "Name", ",", "}", ",", "nil", "\n", "}" ]
// CreateMachineSecLists creates a security list for the given instance. // It's worth noting that this function also ensures that the default environment // sec list is also present, and has the appropriate default rules. // The port parameter is the API port for the state machine, for which we need // to create rules.
[ "CreateMachineSecLists", "creates", "a", "security", "list", "for", "the", "given", "instance", ".", "It", "s", "worth", "noting", "that", "this", "function", "also", "ensures", "that", "the", "default", "environment", "sec", "list", "is", "also", "present", "and", "has", "the", "appropriate", "default", "rules", ".", "The", "port", "parameter", "is", "the", "API", "port", "for", "the", "state", "machine", "for", "which", "we", "need", "to", "create", "rules", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L167-L182
3,571
juju/juju
provider/oracle/network/firewall.go
DeleteMachineSecList
func (f Firewall) DeleteMachineSecList(machineId string) error { listName := f.machineGroupName(machineId) globalListName := f.globalGroupName() err := f.maybeDeleteList(f.client.ComposeName(listName)) if err != nil { return errors.Trace(err) } // check if we can delete the global list as well err = f.maybeDeleteList(f.client.ComposeName(globalListName)) if err != nil { return errors.Trace(err) } return nil }
go
func (f Firewall) DeleteMachineSecList(machineId string) error { listName := f.machineGroupName(machineId) globalListName := f.globalGroupName() err := f.maybeDeleteList(f.client.ComposeName(listName)) if err != nil { return errors.Trace(err) } // check if we can delete the global list as well err = f.maybeDeleteList(f.client.ComposeName(globalListName)) if err != nil { return errors.Trace(err) } return nil }
[ "func", "(", "f", "Firewall", ")", "DeleteMachineSecList", "(", "machineId", "string", ")", "error", "{", "listName", ":=", "f", ".", "machineGroupName", "(", "machineId", ")", "\n", "globalListName", ":=", "f", ".", "globalGroupName", "(", ")", "\n", "err", ":=", "f", ".", "maybeDeleteList", "(", "f", ".", "client", ".", "ComposeName", "(", "listName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// check if we can delete the global list as well", "err", "=", "f", ".", "maybeDeleteList", "(", "f", ".", "client", ".", "ComposeName", "(", "globalListName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteMachineSecList will delete the security list on the given machine
[ "DeleteMachineSecList", "will", "delete", "the", "security", "list", "on", "the", "given", "machine" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L185-L198
3,572
juju/juju
provider/oracle/network/firewall.go
RemoveACLAndRules
func (f Firewall) RemoveACLAndRules(machineId string) error { groupName := f.machineGroupName(machineId) resourceName := f.client.ComposeName(groupName) secRules, err := f.getAllSecurityRules(resourceName) if err != nil { return err } for _, val := range secRules { err := f.client.DeleteSecurityRule(val.Name) if err != nil { if !api.IsNotFound(err) { return err } } } err = f.client.DeleteAcl(resourceName) if err != nil { if !api.IsNotFound(err) { return err } } return nil }
go
func (f Firewall) RemoveACLAndRules(machineId string) error { groupName := f.machineGroupName(machineId) resourceName := f.client.ComposeName(groupName) secRules, err := f.getAllSecurityRules(resourceName) if err != nil { return err } for _, val := range secRules { err := f.client.DeleteSecurityRule(val.Name) if err != nil { if !api.IsNotFound(err) { return err } } } err = f.client.DeleteAcl(resourceName) if err != nil { if !api.IsNotFound(err) { return err } } return nil }
[ "func", "(", "f", "Firewall", ")", "RemoveACLAndRules", "(", "machineId", "string", ")", "error", "{", "groupName", ":=", "f", ".", "machineGroupName", "(", "machineId", ")", "\n", "resourceName", ":=", "f", ".", "client", ".", "ComposeName", "(", "groupName", ")", "\n", "secRules", ",", "err", ":=", "f", ".", "getAllSecurityRules", "(", "resourceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "val", ":=", "range", "secRules", "{", "err", ":=", "f", ".", "client", ".", "DeleteSecurityRule", "(", "val", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "api", ".", "IsNotFound", "(", "err", ")", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "err", "=", "f", ".", "client", ".", "DeleteAcl", "(", "resourceName", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "api", ".", "IsNotFound", "(", "err", ")", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveACLAndRules will remove the ACL and any associated rules.
[ "RemoveACLAndRules", "will", "remove", "the", "ACL", "and", "any", "associated", "rules", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L280-L302
3,573
juju/juju
provider/oracle/network/firewall.go
GlobalIngressRules
func (f Firewall) GlobalIngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) { seclist := f.globalGroupName() return f.getIngressRules(ctx, f.client.ComposeName(seclist)) }
go
func (f Firewall) GlobalIngressRules(ctx context.ProviderCallContext) ([]network.IngressRule, error) { seclist := f.globalGroupName() return f.getIngressRules(ctx, f.client.ComposeName(seclist)) }
[ "func", "(", "f", "Firewall", ")", "GlobalIngressRules", "(", "ctx", "context", ".", "ProviderCallContext", ")", "(", "[", "]", "network", ".", "IngressRule", ",", "error", ")", "{", "seclist", ":=", "f", ".", "globalGroupName", "(", ")", "\n", "return", "f", ".", "getIngressRules", "(", "ctx", ",", "f", ".", "client", ".", "ComposeName", "(", "seclist", ")", ")", "\n", "}" ]
// GlobalIngressRules returns the ingress rules applied to the whole environment.
[ "GlobalIngressRules", "returns", "the", "ingress", "rules", "applied", "to", "the", "whole", "environment", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L305-L308
3,574
juju/juju
provider/oracle/network/firewall.go
getDefaultIngressRules
func (f Firewall) getDefaultIngressRules(apiPort int) []network.IngressRule { return []network.IngressRule{ { PortRange: corenetwork.PortRange{ FromPort: 22, ToPort: 22, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, { PortRange: corenetwork.PortRange{ FromPort: 3389, ToPort: 3389, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, { PortRange: corenetwork.PortRange{ FromPort: apiPort, ToPort: apiPort, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, { PortRange: corenetwork.PortRange{ FromPort: controller.DefaultStatePort, ToPort: controller.DefaultStatePort, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, } }
go
func (f Firewall) getDefaultIngressRules(apiPort int) []network.IngressRule { return []network.IngressRule{ { PortRange: corenetwork.PortRange{ FromPort: 22, ToPort: 22, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, { PortRange: corenetwork.PortRange{ FromPort: 3389, ToPort: 3389, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, { PortRange: corenetwork.PortRange{ FromPort: apiPort, ToPort: apiPort, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, { PortRange: corenetwork.PortRange{ FromPort: controller.DefaultStatePort, ToPort: controller.DefaultStatePort, Protocol: "tcp", }, SourceCIDRs: []string{ "0.0.0.0/0", }, }, } }
[ "func", "(", "f", "Firewall", ")", "getDefaultIngressRules", "(", "apiPort", "int", ")", "[", "]", "network", ".", "IngressRule", "{", "return", "[", "]", "network", ".", "IngressRule", "{", "{", "PortRange", ":", "corenetwork", ".", "PortRange", "{", "FromPort", ":", "22", ",", "ToPort", ":", "22", ",", "Protocol", ":", "\"", "\"", ",", "}", ",", "SourceCIDRs", ":", "[", "]", "string", "{", "\"", "\"", ",", "}", ",", "}", ",", "{", "PortRange", ":", "corenetwork", ".", "PortRange", "{", "FromPort", ":", "3389", ",", "ToPort", ":", "3389", ",", "Protocol", ":", "\"", "\"", ",", "}", ",", "SourceCIDRs", ":", "[", "]", "string", "{", "\"", "\"", ",", "}", ",", "}", ",", "{", "PortRange", ":", "corenetwork", ".", "PortRange", "{", "FromPort", ":", "apiPort", ",", "ToPort", ":", "apiPort", ",", "Protocol", ":", "\"", "\"", ",", "}", ",", "SourceCIDRs", ":", "[", "]", "string", "{", "\"", "\"", ",", "}", ",", "}", ",", "{", "PortRange", ":", "corenetwork", ".", "PortRange", "{", "FromPort", ":", "controller", ".", "DefaultStatePort", ",", "ToPort", ":", "controller", ".", "DefaultStatePort", ",", "Protocol", ":", "\"", "\"", ",", "}", ",", "SourceCIDRs", ":", "[", "]", "string", "{", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// getDefaultIngressRules will create the default ingressRules given an api port
[ "getDefaultIngressRules", "will", "create", "the", "default", "ingressRules", "given", "an", "api", "port" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L311-L354
3,575
juju/juju
provider/oracle/network/firewall.go
closePortsOnList
func (f Firewall) closePortsOnList(ctx context.ProviderCallContext, list string, rules []network.IngressRule) error { // get all security rules based on the dst_list=list secrules, err := f.getSecRules(list) if err != nil { return errors.Trace(err) } // converts all security rules into a map of ingress rules mapping, err := f.secRuleToIngresRule(secrules...) if err != nil { return errors.Trace(err) } //TODO (gsamfira): optimize this for name, rule := range mapping { sort.Strings(rule.SourceCIDRs) for _, ingressRule := range rules { sort.Strings(ingressRule.SourceCIDRs) if reflect.DeepEqual(rule, ingressRule) { err := f.client.DeleteSecRule(name) if err != nil { return errors.Trace(err) } } } } return nil }
go
func (f Firewall) closePortsOnList(ctx context.ProviderCallContext, list string, rules []network.IngressRule) error { // get all security rules based on the dst_list=list secrules, err := f.getSecRules(list) if err != nil { return errors.Trace(err) } // converts all security rules into a map of ingress rules mapping, err := f.secRuleToIngresRule(secrules...) if err != nil { return errors.Trace(err) } //TODO (gsamfira): optimize this for name, rule := range mapping { sort.Strings(rule.SourceCIDRs) for _, ingressRule := range rules { sort.Strings(ingressRule.SourceCIDRs) if reflect.DeepEqual(rule, ingressRule) { err := f.client.DeleteSecRule(name) if err != nil { return errors.Trace(err) } } } } return nil }
[ "func", "(", "f", "Firewall", ")", "closePortsOnList", "(", "ctx", "context", ".", "ProviderCallContext", ",", "list", "string", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "// get all security rules based on the dst_list=list", "secrules", ",", "err", ":=", "f", ".", "getSecRules", "(", "list", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// converts all security rules into a map of ingress rules", "mapping", ",", "err", ":=", "f", ".", "secRuleToIngresRule", "(", "secrules", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "//TODO (gsamfira): optimize this", "for", "name", ",", "rule", ":=", "range", "mapping", "{", "sort", ".", "Strings", "(", "rule", ".", "SourceCIDRs", ")", "\n", "for", "_", ",", "ingressRule", ":=", "range", "rules", "{", "sort", ".", "Strings", "(", "ingressRule", ".", "SourceCIDRs", ")", "\n", "if", "reflect", ".", "DeepEqual", "(", "rule", ",", "ingressRule", ")", "{", "err", ":=", "f", ".", "client", ".", "DeleteSecRule", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// closePortsOnList on list will close all ports corresponding to the supplied ingress rules // on a particular list
[ "closePortsOnList", "on", "list", "will", "close", "all", "ports", "corresponding", "to", "the", "supplied", "ingress", "rules", "on", "a", "particular", "list" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L391-L417
3,576
juju/juju
provider/oracle/network/firewall.go
deleteAllSecRulesOnList
func (f Firewall) deleteAllSecRulesOnList(list string) error { // get all security rules associated with this list secrules, err := f.getSecRules(list) if err != nil { return errors.Trace(err) } // delete everything for _, rule := range secrules { err := f.client.DeleteSecRule(rule.Name) if err != nil { if api.IsNotFound(err) { continue } return errors.Trace(err) } } return nil }
go
func (f Firewall) deleteAllSecRulesOnList(list string) error { // get all security rules associated with this list secrules, err := f.getSecRules(list) if err != nil { return errors.Trace(err) } // delete everything for _, rule := range secrules { err := f.client.DeleteSecRule(rule.Name) if err != nil { if api.IsNotFound(err) { continue } return errors.Trace(err) } } return nil }
[ "func", "(", "f", "Firewall", ")", "deleteAllSecRulesOnList", "(", "list", "string", ")", "error", "{", "// get all security rules associated with this list", "secrules", ",", "err", ":=", "f", ".", "getSecRules", "(", "list", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// delete everything", "for", "_", ",", "rule", ":=", "range", "secrules", "{", "err", ":=", "f", ".", "client", ".", "DeleteSecRule", "(", "rule", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "if", "api", ".", "IsNotFound", "(", "err", ")", "{", "continue", "\n", "}", "\n", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// deleteAllSecRulesOnList will delete all security rules from a give // security list
[ "deleteAllSecRulesOnList", "will", "delete", "all", "security", "rules", "from", "a", "give", "security", "list" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L421-L438
3,577
juju/juju
provider/oracle/network/firewall.go
maybeDeleteList
func (f *Firewall) maybeDeleteList(list string) error { filter := []api.Filter{ { Arg: "seclist", Value: list, }, } iter := 0 found := true var assoc response.AllSecAssociations for { if iter >= 10 { break } assoc, err := f.client.AllSecAssociations(filter) if err != nil { return errors.Trace(err) } if len(assoc.Result) > 0 { <-f.clock.After(1 * time.Second) iter++ continue } found = false break } if found { logger.Warningf( "seclist %s is still has some associations to instance(s): %v. Will not delete", list, assoc.Result, ) return nil } err := f.deleteAllSecRulesOnList(list) if err != nil { return errors.Trace(err) } logger.Tracef("deleting seclist %v", list) err = f.client.DeleteSecList(list) if err != nil { if api.IsNotFound(err) { return nil } return errors.Trace(err) } return nil }
go
func (f *Firewall) maybeDeleteList(list string) error { filter := []api.Filter{ { Arg: "seclist", Value: list, }, } iter := 0 found := true var assoc response.AllSecAssociations for { if iter >= 10 { break } assoc, err := f.client.AllSecAssociations(filter) if err != nil { return errors.Trace(err) } if len(assoc.Result) > 0 { <-f.clock.After(1 * time.Second) iter++ continue } found = false break } if found { logger.Warningf( "seclist %s is still has some associations to instance(s): %v. Will not delete", list, assoc.Result, ) return nil } err := f.deleteAllSecRulesOnList(list) if err != nil { return errors.Trace(err) } logger.Tracef("deleting seclist %v", list) err = f.client.DeleteSecList(list) if err != nil { if api.IsNotFound(err) { return nil } return errors.Trace(err) } return nil }
[ "func", "(", "f", "*", "Firewall", ")", "maybeDeleteList", "(", "list", "string", ")", "error", "{", "filter", ":=", "[", "]", "api", ".", "Filter", "{", "{", "Arg", ":", "\"", "\"", ",", "Value", ":", "list", ",", "}", ",", "}", "\n", "iter", ":=", "0", "\n", "found", ":=", "true", "\n", "var", "assoc", "response", ".", "AllSecAssociations", "\n", "for", "{", "if", "iter", ">=", "10", "{", "break", "\n", "}", "\n", "assoc", ",", "err", ":=", "f", ".", "client", ".", "AllSecAssociations", "(", "filter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "assoc", ".", "Result", ")", ">", "0", "{", "<-", "f", ".", "clock", ".", "After", "(", "1", "*", "time", ".", "Second", ")", "\n", "iter", "++", "\n", "continue", "\n", "}", "\n", "found", "=", "false", "\n", "break", "\n", "}", "\n", "if", "found", "{", "logger", ".", "Warningf", "(", "\"", "\"", ",", "list", ",", "assoc", ".", "Result", ",", ")", "\n", "return", "nil", "\n", "}", "\n", "err", ":=", "f", ".", "deleteAllSecRulesOnList", "(", "list", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "list", ")", "\n", "err", "=", "f", ".", "client", ".", "DeleteSecList", "(", "list", ")", "\n", "if", "err", "!=", "nil", "{", "if", "api", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// maybeDeleteList tries to delete a security list. Lists that are still in use // may not be deleted. When deleting an environment, we want to also cleanup the // environment level sec list. This function attempts to delete a sec list. If the // sec list still has some associations to any instance, we simply return and assume // the last VM to get killed as part of the tear-down, will also remove the global // list as well
[ "maybeDeleteList", "tries", "to", "delete", "a", "security", "list", ".", "Lists", "that", "are", "still", "in", "use", "may", "not", "be", "deleted", ".", "When", "deleting", "an", "environment", "we", "want", "to", "also", "cleanup", "the", "environment", "level", "sec", "list", ".", "This", "function", "attempts", "to", "delete", "a", "sec", "list", ".", "If", "the", "sec", "list", "still", "has", "some", "associations", "to", "any", "instance", "we", "simply", "return", "and", "assume", "the", "last", "VM", "to", "get", "killed", "as", "part", "of", "the", "tear", "-", "down", "will", "also", "remove", "the", "global", "list", "as", "well" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L446-L492
3,578
juju/juju
provider/oracle/network/firewall.go
getAllApplications
func (f Firewall) getAllApplications() ([]response.SecApplication, error) { // get all user defined sec applications applications, err := f.client.AllSecApplications(nil) if err != nil { return nil, errors.Trace(err) } // get also default ones defined in the provider defaultApps, err := f.client.DefaultSecApplications(nil) if err != nil { return nil, errors.Trace(err) } allApps := []response.SecApplication{} for _, val := range applications.Result { if val.PortProtocolPair() == "" { // (gsamfira):this should not really happen, // but I get paranoid when I run out of coffee continue } allApps = append(allApps, val) } for _, val := range defaultApps.Result { if val.PortProtocolPair() == "" { continue } allApps = append(allApps, val) } return allApps, nil }
go
func (f Firewall) getAllApplications() ([]response.SecApplication, error) { // get all user defined sec applications applications, err := f.client.AllSecApplications(nil) if err != nil { return nil, errors.Trace(err) } // get also default ones defined in the provider defaultApps, err := f.client.DefaultSecApplications(nil) if err != nil { return nil, errors.Trace(err) } allApps := []response.SecApplication{} for _, val := range applications.Result { if val.PortProtocolPair() == "" { // (gsamfira):this should not really happen, // but I get paranoid when I run out of coffee continue } allApps = append(allApps, val) } for _, val := range defaultApps.Result { if val.PortProtocolPair() == "" { continue } allApps = append(allApps, val) } return allApps, nil }
[ "func", "(", "f", "Firewall", ")", "getAllApplications", "(", ")", "(", "[", "]", "response", ".", "SecApplication", ",", "error", ")", "{", "// get all user defined sec applications", "applications", ",", "err", ":=", "f", ".", "client", ".", "AllSecApplications", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// get also default ones defined in the provider", "defaultApps", ",", "err", ":=", "f", ".", "client", ".", "DefaultSecApplications", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "allApps", ":=", "[", "]", "response", ".", "SecApplication", "{", "}", "\n", "for", "_", ",", "val", ":=", "range", "applications", ".", "Result", "{", "if", "val", ".", "PortProtocolPair", "(", ")", "==", "\"", "\"", "{", "// (gsamfira):this should not really happen,", "// but I get paranoid when I run out of coffee", "continue", "\n", "}", "\n", "allApps", "=", "append", "(", "allApps", ",", "val", ")", "\n", "}", "\n", "for", "_", ",", "val", ":=", "range", "defaultApps", ".", "Result", "{", "if", "val", ".", "PortProtocolPair", "(", ")", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "allApps", "=", "append", "(", "allApps", ",", "val", ")", "\n", "}", "\n", "return", "allApps", ",", "nil", "\n", "}" ]
// getAllApplications returns all security applications known to the // oracle compute cloud. These are used as part of security rules
[ "getAllApplications", "returns", "all", "security", "applications", "known", "to", "the", "oracle", "compute", "cloud", ".", "These", "are", "used", "as", "part", "of", "security", "rules" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L515-L542
3,579
juju/juju
provider/oracle/network/firewall.go
getAllApplicationsAsMap
func (f Firewall) getAllApplicationsAsMap() (map[string]response.SecApplication, error) { // get all defined protocols // from the current identity and default ones apps, err := f.getAllApplications() if err != nil { return nil, errors.Trace(err) } // copy all of them into this map allApps := map[string]response.SecApplication{} for _, val := range apps { if val.String() == "" { continue } if _, ok := allApps[val.String()]; !ok { allApps[val.String()] = val } } return allApps, nil }
go
func (f Firewall) getAllApplicationsAsMap() (map[string]response.SecApplication, error) { // get all defined protocols // from the current identity and default ones apps, err := f.getAllApplications() if err != nil { return nil, errors.Trace(err) } // copy all of them into this map allApps := map[string]response.SecApplication{} for _, val := range apps { if val.String() == "" { continue } if _, ok := allApps[val.String()]; !ok { allApps[val.String()] = val } } return allApps, nil }
[ "func", "(", "f", "Firewall", ")", "getAllApplicationsAsMap", "(", ")", "(", "map", "[", "string", "]", "response", ".", "SecApplication", ",", "error", ")", "{", "// get all defined protocols", "// from the current identity and default ones", "apps", ",", "err", ":=", "f", ".", "getAllApplications", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// copy all of them into this map", "allApps", ":=", "map", "[", "string", "]", "response", ".", "SecApplication", "{", "}", "\n", "for", "_", ",", "val", ":=", "range", "apps", "{", "if", "val", ".", "String", "(", ")", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "allApps", "[", "val", ".", "String", "(", ")", "]", ";", "!", "ok", "{", "allApps", "[", "val", ".", "String", "(", ")", "]", "=", "val", "\n", "}", "\n", "}", "\n", "return", "allApps", ",", "nil", "\n", "}" ]
// getAllApplicationsAsMap returns all sec applications as a map
[ "getAllApplicationsAsMap", "returns", "all", "sec", "applications", "as", "a", "map" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L545-L563
3,580
juju/juju
provider/oracle/network/firewall.go
convertToSecRules
func (f Firewall) convertToSecRules(seclist response.SecList, rules []network.IngressRule) ([]api.SecRuleParams, error) { applications, err := f.getAllApplications() if err != nil { return nil, errors.Trace(err) } iplists, err := f.getAllIPLists() if err != nil { return nil, errors.Trace(err) } ret := make([]api.SecRuleParams, 0, len(rules)) // for every rule we need to ensure that the there is a relationship // between security applications and security IP lists // and from every one of them create a slice of security rule parameters for _, val := range rules { app, err := f.ensureApplication(val.PortRange, &applications) if err != nil { return nil, errors.Trace(err) } ipList, err := f.ensureSecIpList(val.SourceCIDRs, &iplists) if err != nil { return nil, errors.Trace(err) } uuid, err := utils.NewUUID() if err != nil { return nil, errors.Trace(err) } name := f.newResourceName(uuid.String()) resourceName := f.client.ComposeName(name) dstList := fmt.Sprintf("seclist:%s", seclist.Name) srcList := fmt.Sprintf("seciplist:%s", ipList) // create the new security rule parameters rule := api.SecRuleParams{ Action: common.SecRulePermit, Application: app, Description: "Juju created security rule", Disabled: false, Dst_list: dstList, Name: resourceName, Src_list: srcList, } // append the new parameters rule ret = append(ret, rule) } return ret, nil }
go
func (f Firewall) convertToSecRules(seclist response.SecList, rules []network.IngressRule) ([]api.SecRuleParams, error) { applications, err := f.getAllApplications() if err != nil { return nil, errors.Trace(err) } iplists, err := f.getAllIPLists() if err != nil { return nil, errors.Trace(err) } ret := make([]api.SecRuleParams, 0, len(rules)) // for every rule we need to ensure that the there is a relationship // between security applications and security IP lists // and from every one of them create a slice of security rule parameters for _, val := range rules { app, err := f.ensureApplication(val.PortRange, &applications) if err != nil { return nil, errors.Trace(err) } ipList, err := f.ensureSecIpList(val.SourceCIDRs, &iplists) if err != nil { return nil, errors.Trace(err) } uuid, err := utils.NewUUID() if err != nil { return nil, errors.Trace(err) } name := f.newResourceName(uuid.String()) resourceName := f.client.ComposeName(name) dstList := fmt.Sprintf("seclist:%s", seclist.Name) srcList := fmt.Sprintf("seciplist:%s", ipList) // create the new security rule parameters rule := api.SecRuleParams{ Action: common.SecRulePermit, Application: app, Description: "Juju created security rule", Disabled: false, Dst_list: dstList, Name: resourceName, Src_list: srcList, } // append the new parameters rule ret = append(ret, rule) } return ret, nil }
[ "func", "(", "f", "Firewall", ")", "convertToSecRules", "(", "seclist", "response", ".", "SecList", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "(", "[", "]", "api", ".", "SecRuleParams", ",", "error", ")", "{", "applications", ",", "err", ":=", "f", ".", "getAllApplications", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "iplists", ",", "err", ":=", "f", ".", "getAllIPLists", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "ret", ":=", "make", "(", "[", "]", "api", ".", "SecRuleParams", ",", "0", ",", "len", "(", "rules", ")", ")", "\n", "// for every rule we need to ensure that the there is a relationship", "// between security applications and security IP lists", "// and from every one of them create a slice of security rule parameters", "for", "_", ",", "val", ":=", "range", "rules", "{", "app", ",", "err", ":=", "f", ".", "ensureApplication", "(", "val", ".", "PortRange", ",", "&", "applications", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "ipList", ",", "err", ":=", "f", ".", "ensureSecIpList", "(", "val", ".", "SourceCIDRs", ",", "&", "iplists", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "uuid", ",", "err", ":=", "utils", ".", "NewUUID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "name", ":=", "f", ".", "newResourceName", "(", "uuid", ".", "String", "(", ")", ")", "\n", "resourceName", ":=", "f", ".", "client", ".", "ComposeName", "(", "name", ")", "\n", "dstList", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "seclist", ".", "Name", ")", "\n", "srcList", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ipList", ")", "\n", "// create the new security rule parameters", "rule", ":=", "api", ".", "SecRuleParams", "{", "Action", ":", "common", ".", "SecRulePermit", ",", "Application", ":", "app", ",", "Description", ":", "\"", "\"", ",", "Disabled", ":", "false", ",", "Dst_list", ":", "dstList", ",", "Name", ":", "resourceName", ",", "Src_list", ":", "srcList", ",", "}", "\n", "// append the new parameters rule", "ret", "=", "append", "(", "ret", ",", "rule", ")", "\n", "}", "\n", "return", "ret", ",", "nil", "\n", "}" ]
// convertToSecRules converts network.IngressRules to api.SecRuleParams
[ "convertToSecRules", "converts", "network", ".", "IngressRules", "to", "api", ".", "SecRuleParams" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L611-L656
3,581
juju/juju
provider/oracle/network/firewall.go
convertApplicationToPortRange
func (f Firewall) convertApplicationToPortRange(app response.SecApplication) corenetwork.PortRange { appCopy := app if appCopy.Value2 == -1 { appCopy.Value2 = appCopy.Value1 } return corenetwork.PortRange{ FromPort: appCopy.Value1, ToPort: appCopy.Value2, Protocol: string(appCopy.Protocol), } }
go
func (f Firewall) convertApplicationToPortRange(app response.SecApplication) corenetwork.PortRange { appCopy := app if appCopy.Value2 == -1 { appCopy.Value2 = appCopy.Value1 } return corenetwork.PortRange{ FromPort: appCopy.Value1, ToPort: appCopy.Value2, Protocol: string(appCopy.Protocol), } }
[ "func", "(", "f", "Firewall", ")", "convertApplicationToPortRange", "(", "app", "response", ".", "SecApplication", ")", "corenetwork", ".", "PortRange", "{", "appCopy", ":=", "app", "\n", "if", "appCopy", ".", "Value2", "==", "-", "1", "{", "appCopy", ".", "Value2", "=", "appCopy", ".", "Value1", "\n", "}", "\n", "return", "corenetwork", ".", "PortRange", "{", "FromPort", ":", "appCopy", ".", "Value1", ",", "ToPort", ":", "appCopy", ".", "Value2", ",", "Protocol", ":", "string", "(", "appCopy", ".", "Protocol", ")", ",", "}", "\n", "}" ]
// convertApplicationToPortRange takes a SecApplication and // converts it to a network.PortRange type
[ "convertApplicationToPortRange", "takes", "a", "SecApplication", "and", "converts", "it", "to", "a", "network", ".", "PortRange", "type" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L660-L670
3,582
juju/juju
provider/oracle/network/firewall.go
convertFromSecRules
func (f Firewall) convertFromSecRules(rules ...response.SecRule) (map[string][]network.IngressRule, error) { applications, err := f.getAllApplicationsAsMap() if err != nil { return nil, errors.Trace(err) } iplists, err := f.getAllIPListsAsMap() if err != nil { return nil, errors.Trace(err) } ret := map[string][]network.IngressRule{} for _, val := range rules { app := val.Application srcList := strings.TrimPrefix(val.Src_list, "seciplist:") dstList := strings.TrimPrefix(val.Dst_list, "seclist:") portRange := f.convertApplicationToPortRange(applications[app]) if _, ok := ret[dstList]; !ok { ret[dstList] = []network.IngressRule{ { PortRange: portRange, SourceCIDRs: iplists[srcList].Secipentries, }, } } else { toAdd := network.IngressRule{ PortRange: portRange, SourceCIDRs: iplists[srcList].Secipentries, } ret[dstList] = append(ret[dstList], toAdd) } } return ret, nil }
go
func (f Firewall) convertFromSecRules(rules ...response.SecRule) (map[string][]network.IngressRule, error) { applications, err := f.getAllApplicationsAsMap() if err != nil { return nil, errors.Trace(err) } iplists, err := f.getAllIPListsAsMap() if err != nil { return nil, errors.Trace(err) } ret := map[string][]network.IngressRule{} for _, val := range rules { app := val.Application srcList := strings.TrimPrefix(val.Src_list, "seciplist:") dstList := strings.TrimPrefix(val.Dst_list, "seclist:") portRange := f.convertApplicationToPortRange(applications[app]) if _, ok := ret[dstList]; !ok { ret[dstList] = []network.IngressRule{ { PortRange: portRange, SourceCIDRs: iplists[srcList].Secipentries, }, } } else { toAdd := network.IngressRule{ PortRange: portRange, SourceCIDRs: iplists[srcList].Secipentries, } ret[dstList] = append(ret[dstList], toAdd) } } return ret, nil }
[ "func", "(", "f", "Firewall", ")", "convertFromSecRules", "(", "rules", "...", "response", ".", "SecRule", ")", "(", "map", "[", "string", "]", "[", "]", "network", ".", "IngressRule", ",", "error", ")", "{", "applications", ",", "err", ":=", "f", ".", "getAllApplicationsAsMap", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "iplists", ",", "err", ":=", "f", ".", "getAllIPListsAsMap", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "ret", ":=", "map", "[", "string", "]", "[", "]", "network", ".", "IngressRule", "{", "}", "\n", "for", "_", ",", "val", ":=", "range", "rules", "{", "app", ":=", "val", ".", "Application", "\n", "srcList", ":=", "strings", ".", "TrimPrefix", "(", "val", ".", "Src_list", ",", "\"", "\"", ")", "\n", "dstList", ":=", "strings", ".", "TrimPrefix", "(", "val", ".", "Dst_list", ",", "\"", "\"", ")", "\n", "portRange", ":=", "f", ".", "convertApplicationToPortRange", "(", "applications", "[", "app", "]", ")", "\n", "if", "_", ",", "ok", ":=", "ret", "[", "dstList", "]", ";", "!", "ok", "{", "ret", "[", "dstList", "]", "=", "[", "]", "network", ".", "IngressRule", "{", "{", "PortRange", ":", "portRange", ",", "SourceCIDRs", ":", "iplists", "[", "srcList", "]", ".", "Secipentries", ",", "}", ",", "}", "\n", "}", "else", "{", "toAdd", ":=", "network", ".", "IngressRule", "{", "PortRange", ":", "portRange", ",", "SourceCIDRs", ":", "iplists", "[", "srcList", "]", ".", "Secipentries", ",", "}", "\n", "ret", "[", "dstList", "]", "=", "append", "(", "ret", "[", "dstList", "]", ",", "toAdd", ")", "\n", "}", "\n", "}", "\n", "return", "ret", ",", "nil", "\n", "}" ]
// convertFromSecRules takes a slice of security rules and creates a map of them
[ "convertFromSecRules", "takes", "a", "slice", "of", "security", "rules", "and", "creates", "a", "map", "of", "them" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L673-L706
3,583
juju/juju
provider/oracle/network/firewall.go
globalGroupName
func (f Firewall) globalGroupName() string { return fmt.Sprintf("juju-%s-global", f.environ.Config().UUID()) }
go
func (f Firewall) globalGroupName() string { return fmt.Sprintf("juju-%s-global", f.environ.Config().UUID()) }
[ "func", "(", "f", "Firewall", ")", "globalGroupName", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "environ", ".", "Config", "(", ")", ".", "UUID", "(", ")", ")", "\n", "}" ]
// globalGroupName returns the global group name // derived from the model UUID
[ "globalGroupName", "returns", "the", "global", "group", "name", "derived", "from", "the", "model", "UUID" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L763-L765
3,584
juju/juju
provider/oracle/network/firewall.go
machineGroupName
func (f Firewall) machineGroupName(machineId string) string { return fmt.Sprintf("juju-%s-%s", f.environ.Config().UUID(), machineId) }
go
func (f Firewall) machineGroupName(machineId string) string { return fmt.Sprintf("juju-%s-%s", f.environ.Config().UUID(), machineId) }
[ "func", "(", "f", "Firewall", ")", "machineGroupName", "(", "machineId", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "environ", ".", "Config", "(", ")", ".", "UUID", "(", ")", ",", "machineId", ")", "\n", "}" ]
// machineGroupName returns the machine group name // derived from the model UUID and the machine ID
[ "machineGroupName", "returns", "the", "machine", "group", "name", "derived", "from", "the", "model", "UUID", "and", "the", "machine", "ID" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L769-L771
3,585
juju/juju
provider/oracle/network/firewall.go
newResourceName
func (f Firewall) newResourceName(appName string) string { return fmt.Sprintf("juju-%s-%s", f.environ.Config().UUID(), appName) }
go
func (f Firewall) newResourceName(appName string) string { return fmt.Sprintf("juju-%s-%s", f.environ.Config().UUID(), appName) }
[ "func", "(", "f", "Firewall", ")", "newResourceName", "(", "appName", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "environ", ".", "Config", "(", ")", ".", "UUID", "(", ")", ",", "appName", ")", "\n", "}" ]
// resourceName returns the resource name // derived from the model UUID and the name of the resource
[ "resourceName", "returns", "the", "resource", "name", "derived", "from", "the", "model", "UUID", "and", "the", "name", "of", "the", "resource" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L775-L777
3,586
juju/juju
provider/oracle/network/firewall.go
getAllSecurityRules
func (f Firewall) getAllSecurityRules(aclName string) ([]response.SecurityRule, error) { rules, err := f.client.AllSecurityRules(nil) if err != nil { return nil, err } if aclName == "" { return rules.Result, nil } var ret []response.SecurityRule for _, val := range rules.Result { if val.Acl == aclName { ret = append(ret, val) } } return ret, nil }
go
func (f Firewall) getAllSecurityRules(aclName string) ([]response.SecurityRule, error) { rules, err := f.client.AllSecurityRules(nil) if err != nil { return nil, err } if aclName == "" { return rules.Result, nil } var ret []response.SecurityRule for _, val := range rules.Result { if val.Acl == aclName { ret = append(ret, val) } } return ret, nil }
[ "func", "(", "f", "Firewall", ")", "getAllSecurityRules", "(", "aclName", "string", ")", "(", "[", "]", "response", ".", "SecurityRule", ",", "error", ")", "{", "rules", ",", "err", ":=", "f", ".", "client", ".", "AllSecurityRules", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "aclName", "==", "\"", "\"", "{", "return", "rules", ".", "Result", ",", "nil", "\n", "}", "\n", "var", "ret", "[", "]", "response", ".", "SecurityRule", "\n", "for", "_", ",", "val", ":=", "range", "rules", ".", "Result", "{", "if", "val", ".", "Acl", "==", "aclName", "{", "ret", "=", "append", "(", "ret", ",", "val", ")", "\n", "}", "\n", "}", "\n", "return", "ret", ",", "nil", "\n", "}" ]
// get all security rules associated with an ACL
[ "get", "all", "security", "rules", "associated", "with", "an", "ACL" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L780-L795
3,587
juju/juju
provider/oracle/network/firewall.go
getSecRules
func (f Firewall) getSecRules(seclist string) ([]response.SecRule, error) { // we only care about ingress rules name := fmt.Sprintf("seclist:%s", seclist) rulesFilter := []api.Filter{ { Arg: "dst_list", Value: name, }, } rules, err := f.client.AllSecRules(rulesFilter) if err != nil { return nil, errors.Trace(err) } // gsamfira: the oracle compute API does not allow filtering by action ret := []response.SecRule{} for _, val := range rules.Result { // gsamfira: We set a default policy of DENY. No use in worrying about // DENY rules (if by any chance someone add one manually for some reason) if val.Action != common.SecRulePermit { continue } // We only care about rules that have a destination set // to a security list. Those lists get attached to VMs // NOTE: someone decided, when writing the oracle API // that some fields should be bool, some should be string. // never mind they both are boolean values...but hey. // I swear...some people like to watch the world burn if val.Dst_is_ip == "true" { continue } // We only care about rules that have an IP list as source if val.Src_is_ip == "false" { continue } ret = append(ret, val) } return ret, nil }
go
func (f Firewall) getSecRules(seclist string) ([]response.SecRule, error) { // we only care about ingress rules name := fmt.Sprintf("seclist:%s", seclist) rulesFilter := []api.Filter{ { Arg: "dst_list", Value: name, }, } rules, err := f.client.AllSecRules(rulesFilter) if err != nil { return nil, errors.Trace(err) } // gsamfira: the oracle compute API does not allow filtering by action ret := []response.SecRule{} for _, val := range rules.Result { // gsamfira: We set a default policy of DENY. No use in worrying about // DENY rules (if by any chance someone add one manually for some reason) if val.Action != common.SecRulePermit { continue } // We only care about rules that have a destination set // to a security list. Those lists get attached to VMs // NOTE: someone decided, when writing the oracle API // that some fields should be bool, some should be string. // never mind they both are boolean values...but hey. // I swear...some people like to watch the world burn if val.Dst_is_ip == "true" { continue } // We only care about rules that have an IP list as source if val.Src_is_ip == "false" { continue } ret = append(ret, val) } return ret, nil }
[ "func", "(", "f", "Firewall", ")", "getSecRules", "(", "seclist", "string", ")", "(", "[", "]", "response", ".", "SecRule", ",", "error", ")", "{", "// we only care about ingress rules", "name", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "seclist", ")", "\n", "rulesFilter", ":=", "[", "]", "api", ".", "Filter", "{", "{", "Arg", ":", "\"", "\"", ",", "Value", ":", "name", ",", "}", ",", "}", "\n", "rules", ",", "err", ":=", "f", ".", "client", ".", "AllSecRules", "(", "rulesFilter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// gsamfira: the oracle compute API does not allow filtering by action", "ret", ":=", "[", "]", "response", ".", "SecRule", "{", "}", "\n", "for", "_", ",", "val", ":=", "range", "rules", ".", "Result", "{", "// gsamfira: We set a default policy of DENY. No use in worrying about", "// DENY rules (if by any chance someone add one manually for some reason)", "if", "val", ".", "Action", "!=", "common", ".", "SecRulePermit", "{", "continue", "\n", "}", "\n", "// We only care about rules that have a destination set", "// to a security list. Those lists get attached to VMs", "// NOTE: someone decided, when writing the oracle API", "// that some fields should be bool, some should be string.", "// never mind they both are boolean values...but hey.", "// I swear...some people like to watch the world burn", "if", "val", ".", "Dst_is_ip", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "// We only care about rules that have an IP list as source", "if", "val", ".", "Src_is_ip", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "val", ")", "\n", "}", "\n", "return", "ret", ",", "nil", "\n", "}" ]
// getSecRules retrieves the security rules associated with a particular security list
[ "getSecRules", "retrieves", "the", "security", "rules", "associated", "with", "a", "particular", "security", "list" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L798-L835
3,588
juju/juju
provider/oracle/network/firewall.go
ensureSecRules
func (f Firewall) ensureSecRules(seclist response.SecList, rules []network.IngressRule) error { // get all security rules associated with the seclist secRules, err := f.getSecRules(seclist.Name) if err != nil { return errors.Trace(err) } logger.Tracef("list %v has sec rules: %v", seclist.Name, secRules) converted, err := f.convertFromSecRules(secRules...) if err != nil { return errors.Trace(err) } logger.Tracef("converted rules are: %v", converted) asIngressRules := converted[seclist.Name] missing := []network.IngressRule{} // search through all rules and find the missing ones for _, toAdd := range rules { found := false for _, exists := range asIngressRules { sort.Strings(toAdd.SourceCIDRs) sort.Strings(exists.SourceCIDRs) logger.Tracef("comparing %v to %v", toAdd.SourceCIDRs, exists.SourceCIDRs) if reflect.DeepEqual(toAdd, exists) { found = true break } } if found { continue } missing = append(missing, toAdd) } if len(missing) == 0 { return nil } logger.Tracef("Found missing rules: %v", missing) // convert the missing rules back to sec rules asSecRule, err := f.convertToSecRules(seclist, missing) if err != nil { return errors.Trace(err) } for _, val := range asSecRule { _, err = f.client.CreateSecRule(val) if err != nil { return errors.Trace(err) } } return nil }
go
func (f Firewall) ensureSecRules(seclist response.SecList, rules []network.IngressRule) error { // get all security rules associated with the seclist secRules, err := f.getSecRules(seclist.Name) if err != nil { return errors.Trace(err) } logger.Tracef("list %v has sec rules: %v", seclist.Name, secRules) converted, err := f.convertFromSecRules(secRules...) if err != nil { return errors.Trace(err) } logger.Tracef("converted rules are: %v", converted) asIngressRules := converted[seclist.Name] missing := []network.IngressRule{} // search through all rules and find the missing ones for _, toAdd := range rules { found := false for _, exists := range asIngressRules { sort.Strings(toAdd.SourceCIDRs) sort.Strings(exists.SourceCIDRs) logger.Tracef("comparing %v to %v", toAdd.SourceCIDRs, exists.SourceCIDRs) if reflect.DeepEqual(toAdd, exists) { found = true break } } if found { continue } missing = append(missing, toAdd) } if len(missing) == 0 { return nil } logger.Tracef("Found missing rules: %v", missing) // convert the missing rules back to sec rules asSecRule, err := f.convertToSecRules(seclist, missing) if err != nil { return errors.Trace(err) } for _, val := range asSecRule { _, err = f.client.CreateSecRule(val) if err != nil { return errors.Trace(err) } } return nil }
[ "func", "(", "f", "Firewall", ")", "ensureSecRules", "(", "seclist", "response", ".", "SecList", ",", "rules", "[", "]", "network", ".", "IngressRule", ")", "error", "{", "// get all security rules associated with the seclist", "secRules", ",", "err", ":=", "f", ".", "getSecRules", "(", "seclist", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "seclist", ".", "Name", ",", "secRules", ")", "\n\n", "converted", ",", "err", ":=", "f", ".", "convertFromSecRules", "(", "secRules", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "converted", ")", "\n", "asIngressRules", ":=", "converted", "[", "seclist", ".", "Name", "]", "\n", "missing", ":=", "[", "]", "network", ".", "IngressRule", "{", "}", "\n\n", "// search through all rules and find the missing ones", "for", "_", ",", "toAdd", ":=", "range", "rules", "{", "found", ":=", "false", "\n", "for", "_", ",", "exists", ":=", "range", "asIngressRules", "{", "sort", ".", "Strings", "(", "toAdd", ".", "SourceCIDRs", ")", "\n", "sort", ".", "Strings", "(", "exists", ".", "SourceCIDRs", ")", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "toAdd", ".", "SourceCIDRs", ",", "exists", ".", "SourceCIDRs", ")", "\n", "if", "reflect", ".", "DeepEqual", "(", "toAdd", ",", "exists", ")", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "found", "{", "continue", "\n", "}", "\n", "missing", "=", "append", "(", "missing", ",", "toAdd", ")", "\n", "}", "\n", "if", "len", "(", "missing", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "missing", ")", "\n", "// convert the missing rules back to sec rules", "asSecRule", ",", "err", ":=", "f", ".", "convertToSecRules", "(", "seclist", ",", "missing", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "val", ":=", "range", "asSecRule", "{", "_", ",", "err", "=", "f", ".", "client", ".", "CreateSecRule", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ensureSecRules ensures that the list passed has all the rules // that it needs, if one is missing it will create it inside the oracle // cloud environment and it will return nil // if none rule is missing then it will return nil
[ "ensureSecRules", "ensures", "that", "the", "list", "passed", "has", "all", "the", "rules", "that", "it", "needs", "if", "one", "is", "missing", "it", "will", "create", "it", "inside", "the", "oracle", "cloud", "environment", "and", "it", "will", "return", "nil", "if", "none", "rule", "is", "missing", "then", "it", "will", "return", "nil" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L841-L891
3,589
juju/juju
provider/oracle/network/firewall.go
ensureSecList
func (f Firewall) ensureSecList(name string) (response.SecList, error) { logger.Infof("Fetching details for list: %s", name) // check if the security list is already there details, err := f.client.SecListDetails(name) if err != nil { logger.Infof("Got error fetching details for %s: %v", name, err) if api.IsNotFound(err) { logger.Infof("Creating new seclist: %s", name) details, err := f.client.CreateSecList( "Juju created security list", name, common.SecRulePermit, common.SecRuleDeny) if err != nil { return response.SecList{}, err } return details, nil } return response.SecList{}, err } return details, nil }
go
func (f Firewall) ensureSecList(name string) (response.SecList, error) { logger.Infof("Fetching details for list: %s", name) // check if the security list is already there details, err := f.client.SecListDetails(name) if err != nil { logger.Infof("Got error fetching details for %s: %v", name, err) if api.IsNotFound(err) { logger.Infof("Creating new seclist: %s", name) details, err := f.client.CreateSecList( "Juju created security list", name, common.SecRulePermit, common.SecRuleDeny) if err != nil { return response.SecList{}, err } return details, nil } return response.SecList{}, err } return details, nil }
[ "func", "(", "f", "Firewall", ")", "ensureSecList", "(", "name", "string", ")", "(", "response", ".", "SecList", ",", "error", ")", "{", "logger", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "// check if the security list is already there", "details", ",", "err", ":=", "f", ".", "client", ".", "SecListDetails", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Infof", "(", "\"", "\"", ",", "name", ",", "err", ")", "\n", "if", "api", ".", "IsNotFound", "(", "err", ")", "{", "logger", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "details", ",", "err", ":=", "f", ".", "client", ".", "CreateSecList", "(", "\"", "\"", ",", "name", ",", "common", ".", "SecRulePermit", ",", "common", ".", "SecRuleDeny", ")", "\n", "if", "err", "!=", "nil", "{", "return", "response", ".", "SecList", "{", "}", ",", "err", "\n", "}", "\n", "return", "details", ",", "nil", "\n", "}", "\n", "return", "response", ".", "SecList", "{", "}", ",", "err", "\n", "}", "\n", "return", "details", ",", "nil", "\n", "}" ]
// ensureSecList creates a new seclist if one does not already exist. // this function is idempotent
[ "ensureSecList", "creates", "a", "new", "seclist", "if", "one", "does", "not", "already", "exist", ".", "this", "function", "is", "idempotent" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L895-L916
3,590
juju/juju
provider/oracle/network/firewall.go
getAllIPListsAsMap
func (f Firewall) getAllIPListsAsMap() (map[string]response.SecIpList, error) { allIps, err := f.getAllIPLists() if err != nil { return nil, errors.Trace(err) } allIpLists := map[string]response.SecIpList{} for _, val := range allIps { allIpLists[val.Name] = val } return allIpLists, nil }
go
func (f Firewall) getAllIPListsAsMap() (map[string]response.SecIpList, error) { allIps, err := f.getAllIPLists() if err != nil { return nil, errors.Trace(err) } allIpLists := map[string]response.SecIpList{} for _, val := range allIps { allIpLists[val.Name] = val } return allIpLists, nil }
[ "func", "(", "f", "Firewall", ")", "getAllIPListsAsMap", "(", ")", "(", "map", "[", "string", "]", "response", ".", "SecIpList", ",", "error", ")", "{", "allIps", ",", "err", ":=", "f", ".", "getAllIPLists", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "allIpLists", ":=", "map", "[", "string", "]", "response", ".", "SecIpList", "{", "}", "\n", "for", "_", ",", "val", ":=", "range", "allIps", "{", "allIpLists", "[", "val", ".", "Name", "]", "=", "val", "\n", "}", "\n", "return", "allIpLists", ",", "nil", "\n", "}" ]
// getAllIPListsAsMap returns all IP lists as a map, with the key being // the resource name
[ "getAllIPListsAsMap", "returns", "all", "IP", "lists", "as", "a", "map", "with", "the", "key", "being", "the", "resource", "name" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L940-L950
3,591
juju/juju
provider/oracle/network/firewall.go
ensureSecIpList
func (f Firewall) ensureSecIpList(cidr []string, cache *[]response.SecIpList) (string, error) { sort.Strings(cidr) for _, val := range *cache { sort.Strings(val.Secipentries) if reflect.DeepEqual(val.Secipentries, cidr) { return val.Name, nil } } uuid, err := utils.NewUUID() if err != nil { return "", errors.Trace(err) } name := f.newResourceName(uuid.String()) resource := f.client.ComposeName(name) secList, err := f.client.CreateSecIpList( "Juju created security IP list", resource, cidr) if err != nil { return "", errors.Trace(err) } *cache = append(*cache, secList) return secList.Name, nil }
go
func (f Firewall) ensureSecIpList(cidr []string, cache *[]response.SecIpList) (string, error) { sort.Strings(cidr) for _, val := range *cache { sort.Strings(val.Secipentries) if reflect.DeepEqual(val.Secipentries, cidr) { return val.Name, nil } } uuid, err := utils.NewUUID() if err != nil { return "", errors.Trace(err) } name := f.newResourceName(uuid.String()) resource := f.client.ComposeName(name) secList, err := f.client.CreateSecIpList( "Juju created security IP list", resource, cidr) if err != nil { return "", errors.Trace(err) } *cache = append(*cache, secList) return secList.Name, nil }
[ "func", "(", "f", "Firewall", ")", "ensureSecIpList", "(", "cidr", "[", "]", "string", ",", "cache", "*", "[", "]", "response", ".", "SecIpList", ")", "(", "string", ",", "error", ")", "{", "sort", ".", "Strings", "(", "cidr", ")", "\n", "for", "_", ",", "val", ":=", "range", "*", "cache", "{", "sort", ".", "Strings", "(", "val", ".", "Secipentries", ")", "\n", "if", "reflect", ".", "DeepEqual", "(", "val", ".", "Secipentries", ",", "cidr", ")", "{", "return", "val", ".", "Name", ",", "nil", "\n", "}", "\n", "}", "\n", "uuid", ",", "err", ":=", "utils", ".", "NewUUID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "name", ":=", "f", ".", "newResourceName", "(", "uuid", ".", "String", "(", ")", ")", "\n", "resource", ":=", "f", ".", "client", ".", "ComposeName", "(", "name", ")", "\n", "secList", ",", "err", ":=", "f", ".", "client", ".", "CreateSecIpList", "(", "\"", "\"", ",", "resource", ",", "cidr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "*", "cache", "=", "append", "(", "*", "cache", ",", "secList", ")", "\n", "return", "secList", ".", "Name", ",", "nil", "\n", "}" ]
// ensureSecIpList ensures that a sec ip list with the provided cidr list // exists. If one does not, it gets created. This function is idempotent.
[ "ensureSecIpList", "ensures", "that", "a", "sec", "ip", "list", "with", "the", "provided", "cidr", "list", "exists", ".", "If", "one", "does", "not", "it", "gets", "created", ".", "This", "function", "is", "idempotent", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/network/firewall.go#L954-L976
3,592
juju/juju
apiserver/backup.go
sendError
func (h *backupHandler) sendError(w http.ResponseWriter, err error) { err, status := common.ServerErrorAndStatus(err) if err := sendStatusAndJSON(w, status, err); err != nil { logger.Errorf("%v", err) } }
go
func (h *backupHandler) sendError(w http.ResponseWriter, err error) { err, status := common.ServerErrorAndStatus(err) if err := sendStatusAndJSON(w, status, err); err != nil { logger.Errorf("%v", err) } }
[ "func", "(", "h", "*", "backupHandler", ")", "sendError", "(", "w", "http", ".", "ResponseWriter", ",", "err", "error", ")", "{", "err", ",", "status", ":=", "common", ".", "ServerErrorAndStatus", "(", "err", ")", "\n", "if", "err", ":=", "sendStatusAndJSON", "(", "w", ",", "status", ",", "err", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// sendError sends a JSON-encoded error response. // Note the difference from the error response sent by // the sendError function - the error is encoded directly // rather than in the Error field.
[ "sendError", "sends", "a", "JSON", "-", "encoded", "error", "response", ".", "Note", "the", "difference", "from", "the", "error", "response", "sent", "by", "the", "sendError", "function", "-", "the", "error", "is", "encoded", "directly", "rather", "than", "in", "the", "Error", "field", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/backup.go#L181-L186
3,593
juju/juju
apiserver/common/resource.go
Get
func (rs *Resources) Get(id string) facade.Resource { rs.mu.Lock() defer rs.mu.Unlock() return rs.resources[id] }
go
func (rs *Resources) Get(id string) facade.Resource { rs.mu.Lock() defer rs.mu.Unlock() return rs.resources[id] }
[ "func", "(", "rs", "*", "Resources", ")", "Get", "(", "id", "string", ")", "facade", ".", "Resource", "{", "rs", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "rs", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "rs", ".", "resources", "[", "id", "]", "\n", "}" ]
// Get returns the resource for the given id, or // nil if there is no such resource.
[ "Get", "returns", "the", "resource", "for", "the", "given", "id", "or", "nil", "if", "there", "is", "no", "such", "resource", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/resource.go#L38-L42
3,594
juju/juju
apiserver/common/resource.go
Register
func (rs *Resources) Register(r facade.Resource) string { rs.mu.Lock() defer rs.mu.Unlock() rs.maxId++ id := strconv.FormatUint(rs.maxId, 10) rs.resources[id] = r rs.stack = append(rs.stack, id) logger.Tracef("registered unnamed resource: %s", id) return id }
go
func (rs *Resources) Register(r facade.Resource) string { rs.mu.Lock() defer rs.mu.Unlock() rs.maxId++ id := strconv.FormatUint(rs.maxId, 10) rs.resources[id] = r rs.stack = append(rs.stack, id) logger.Tracef("registered unnamed resource: %s", id) return id }
[ "func", "(", "rs", "*", "Resources", ")", "Register", "(", "r", "facade", ".", "Resource", ")", "string", "{", "rs", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "rs", ".", "mu", ".", "Unlock", "(", ")", "\n", "rs", ".", "maxId", "++", "\n", "id", ":=", "strconv", ".", "FormatUint", "(", "rs", ".", "maxId", ",", "10", ")", "\n", "rs", ".", "resources", "[", "id", "]", "=", "r", "\n", "rs", ".", "stack", "=", "append", "(", "rs", ".", "stack", ",", "id", ")", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "id", ")", "\n", "return", "id", "\n", "}" ]
// Register registers the given resource. It returns a unique // identifier for the resource which can then be used in // subsequent API requests to refer to the resource.
[ "Register", "registers", "the", "given", "resource", ".", "It", "returns", "a", "unique", "identifier", "for", "the", "resource", "which", "can", "then", "be", "used", "in", "subsequent", "API", "requests", "to", "refer", "to", "the", "resource", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/resource.go#L47-L56
3,595
juju/juju
apiserver/common/resource.go
Stop
func (rs *Resources) Stop(id string) error { // We don't hold the mutex while calling Stop, because // that might take a while and we don't want to // stop all other resource manipulation while we do so. // If resources.Stop is called concurrently, we'll get // two concurrent calls to Stop, but that should fit // well with the way we invariably implement Stop. logger.Tracef("stopping resource: %s", id) r := rs.Get(id) if r == nil { return nil } err := r.Stop() rs.mu.Lock() defer rs.mu.Unlock() delete(rs.resources, id) for pos := 0; pos < len(rs.stack); pos++ { if rs.stack[pos] == id { rs.stack = append(rs.stack[0:pos], rs.stack[pos+1:]...) break } } return err }
go
func (rs *Resources) Stop(id string) error { // We don't hold the mutex while calling Stop, because // that might take a while and we don't want to // stop all other resource manipulation while we do so. // If resources.Stop is called concurrently, we'll get // two concurrent calls to Stop, but that should fit // well with the way we invariably implement Stop. logger.Tracef("stopping resource: %s", id) r := rs.Get(id) if r == nil { return nil } err := r.Stop() rs.mu.Lock() defer rs.mu.Unlock() delete(rs.resources, id) for pos := 0; pos < len(rs.stack); pos++ { if rs.stack[pos] == id { rs.stack = append(rs.stack[0:pos], rs.stack[pos+1:]...) break } } return err }
[ "func", "(", "rs", "*", "Resources", ")", "Stop", "(", "id", "string", ")", "error", "{", "// We don't hold the mutex while calling Stop, because", "// that might take a while and we don't want to", "// stop all other resource manipulation while we do so.", "// If resources.Stop is called concurrently, we'll get", "// two concurrent calls to Stop, but that should fit", "// well with the way we invariably implement Stop.", "logger", ".", "Tracef", "(", "\"", "\"", ",", "id", ")", "\n", "r", ":=", "rs", ".", "Get", "(", "id", ")", "\n", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "err", ":=", "r", ".", "Stop", "(", ")", "\n", "rs", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "rs", ".", "mu", ".", "Unlock", "(", ")", "\n", "delete", "(", "rs", ".", "resources", ",", "id", ")", "\n", "for", "pos", ":=", "0", ";", "pos", "<", "len", "(", "rs", ".", "stack", ")", ";", "pos", "++", "{", "if", "rs", ".", "stack", "[", "pos", "]", "==", "id", "{", "rs", ".", "stack", "=", "append", "(", "rs", ".", "stack", "[", "0", ":", "pos", "]", ",", "rs", ".", "stack", "[", "pos", "+", "1", ":", "]", "...", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Stop stops the resource with the given id and unregisters it. // It returns any error from the underlying Stop call. // It does not return an error if the resource has already // been unregistered.
[ "Stop", "stops", "the", "resource", "with", "the", "given", "id", "and", "unregisters", "it", ".", "It", "returns", "any", "error", "from", "the", "underlying", "Stop", "call", ".", "It", "does", "not", "return", "an", "error", "if", "the", "resource", "has", "already", "been", "unregistered", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/resource.go#L84-L107
3,596
juju/juju
apiserver/common/resource.go
StopAll
func (rs *Resources) StopAll() { rs.mu.Lock() defer rs.mu.Unlock() for i := len(rs.stack); i > 0; i-- { id := rs.stack[i-1] r := rs.resources[id] logger.Tracef("stopping resource: %s", id) if err := r.Stop(); err != nil { logger.Errorf("error stopping %T resource: %v", r, err) } } rs.resources = make(map[string]facade.Resource) rs.stack = nil }
go
func (rs *Resources) StopAll() { rs.mu.Lock() defer rs.mu.Unlock() for i := len(rs.stack); i > 0; i-- { id := rs.stack[i-1] r := rs.resources[id] logger.Tracef("stopping resource: %s", id) if err := r.Stop(); err != nil { logger.Errorf("error stopping %T resource: %v", r, err) } } rs.resources = make(map[string]facade.Resource) rs.stack = nil }
[ "func", "(", "rs", "*", "Resources", ")", "StopAll", "(", ")", "{", "rs", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "rs", ".", "mu", ".", "Unlock", "(", ")", "\n", "for", "i", ":=", "len", "(", "rs", ".", "stack", ")", ";", "i", ">", "0", ";", "i", "--", "{", "id", ":=", "rs", ".", "stack", "[", "i", "-", "1", "]", "\n", "r", ":=", "rs", ".", "resources", "[", "id", "]", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "id", ")", "\n", "if", "err", ":=", "r", ".", "Stop", "(", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Errorf", "(", "\"", "\"", ",", "r", ",", "err", ")", "\n", "}", "\n", "}", "\n", "rs", ".", "resources", "=", "make", "(", "map", "[", "string", "]", "facade", ".", "Resource", ")", "\n", "rs", ".", "stack", "=", "nil", "\n", "}" ]
// StopAll stops all the resources.
[ "StopAll", "stops", "all", "the", "resources", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/resource.go#L110-L123
3,597
juju/juju
apiserver/common/resource.go
Count
func (rs *Resources) Count() int { rs.mu.Lock() defer rs.mu.Unlock() return len(rs.resources) }
go
func (rs *Resources) Count() int { rs.mu.Lock() defer rs.mu.Unlock() return len(rs.resources) }
[ "func", "(", "rs", "*", "Resources", ")", "Count", "(", ")", "int", "{", "rs", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "rs", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "len", "(", "rs", ".", "resources", ")", "\n", "}" ]
// Count returns the number of resources currently held.
[ "Count", "returns", "the", "number", "of", "resources", "currently", "held", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/resource.go#L126-L130
3,598
juju/juju
state/spaces.go
ProviderId
func (s *Space) ProviderId() network.Id { return network.Id(s.doc.ProviderId) }
go
func (s *Space) ProviderId() network.Id { return network.Id(s.doc.ProviderId) }
[ "func", "(", "s", "*", "Space", ")", "ProviderId", "(", ")", "network", ".", "Id", "{", "return", "network", ".", "Id", "(", "s", ".", "doc", ".", "ProviderId", ")", "\n", "}" ]
// ProviderId returns the provider id of the space. This will be the empty // string except on substrates that directly support spaces.
[ "ProviderId", "returns", "the", "provider", "id", "of", "the", "space", ".", "This", "will", "be", "the", "empty", "string", "except", "on", "substrates", "that", "directly", "support", "spaces", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L51-L53
3,599
juju/juju
state/spaces.go
Subnets
func (s *Space) Subnets() (results []*Subnet, err error) { defer errors.DeferredAnnotatef(&err, "cannot fetch subnets") name := s.Name() subnetsCollection, closer := s.st.db().GetCollection(subnetsC) defer closer() var doc subnetDoc // We ignore space-name field for FAN subnets... iter := subnetsCollection.Find(bson.D{{"space-name", name}, bson.DocElem{"fan-local-underlay", bson.D{{"$exists", false}}}}).Iter() defer iter.Close() for iter.Next(&doc) { subnet := &Subnet{s.st, doc, name} results = append(results, subnet) // ...and then add them explicitly as descendants of underlay network. childIter := subnetsCollection.Find(bson.D{{"fan-local-underlay", doc.CIDR}}).Iter() for childIter.Next(&doc) { subnet := &Subnet{s.st, doc, name} results = append(results, subnet) } } if err := iter.Close(); err != nil { return nil, err } return results, nil }
go
func (s *Space) Subnets() (results []*Subnet, err error) { defer errors.DeferredAnnotatef(&err, "cannot fetch subnets") name := s.Name() subnetsCollection, closer := s.st.db().GetCollection(subnetsC) defer closer() var doc subnetDoc // We ignore space-name field for FAN subnets... iter := subnetsCollection.Find(bson.D{{"space-name", name}, bson.DocElem{"fan-local-underlay", bson.D{{"$exists", false}}}}).Iter() defer iter.Close() for iter.Next(&doc) { subnet := &Subnet{s.st, doc, name} results = append(results, subnet) // ...and then add them explicitly as descendants of underlay network. childIter := subnetsCollection.Find(bson.D{{"fan-local-underlay", doc.CIDR}}).Iter() for childIter.Next(&doc) { subnet := &Subnet{s.st, doc, name} results = append(results, subnet) } } if err := iter.Close(); err != nil { return nil, err } return results, nil }
[ "func", "(", "s", "*", "Space", ")", "Subnets", "(", ")", "(", "results", "[", "]", "*", "Subnet", ",", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ")", "\n", "name", ":=", "s", ".", "Name", "(", ")", "\n\n", "subnetsCollection", ",", "closer", ":=", "s", ".", "st", ".", "db", "(", ")", ".", "GetCollection", "(", "subnetsC", ")", "\n", "defer", "closer", "(", ")", "\n\n", "var", "doc", "subnetDoc", "\n", "// We ignore space-name field for FAN subnets...", "iter", ":=", "subnetsCollection", ".", "Find", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "name", "}", ",", "bson", ".", "DocElem", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "false", "}", "}", "}", "}", ")", ".", "Iter", "(", ")", "\n", "defer", "iter", ".", "Close", "(", ")", "\n", "for", "iter", ".", "Next", "(", "&", "doc", ")", "{", "subnet", ":=", "&", "Subnet", "{", "s", ".", "st", ",", "doc", ",", "name", "}", "\n", "results", "=", "append", "(", "results", ",", "subnet", ")", "\n", "// ...and then add them explicitly as descendants of underlay network.", "childIter", ":=", "subnetsCollection", ".", "Find", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "doc", ".", "CIDR", "}", "}", ")", ".", "Iter", "(", ")", "\n", "for", "childIter", ".", "Next", "(", "&", "doc", ")", "{", "subnet", ":=", "&", "Subnet", "{", "s", ".", "st", ",", "doc", ",", "name", "}", "\n", "results", "=", "append", "(", "results", ",", "subnet", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "iter", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// Subnets returns all the subnets associated with the Space.
[ "Subnets", "returns", "all", "the", "subnets", "associated", "with", "the", "Space", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L56-L81