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,800 | juju/juju | api/provisioner/machine.go | InstanceStatus | func (m *Machine) InstanceStatus() (status.Status, string, error) {
var results params.StatusResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.st.facade.FacadeCall("InstanceStatus", args, &results)
if err != nil {
return "", "", err
}
if len(results.Results) != 1 {
return "", "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return "", "", result.Error
}
// TODO(perrito666) add status validation.
return status.Status(result.Status), result.Info, nil
} | go | func (m *Machine) InstanceStatus() (status.Status, string, error) {
var results params.StatusResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.st.facade.FacadeCall("InstanceStatus", args, &results)
if err != nil {
return "", "", err
}
if len(results.Results) != 1 {
return "", "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return "", "", result.Error
}
// TODO(perrito666) add status validation.
return status.Status(result.Status), result.Info, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"InstanceStatus",
"(",
")",
"(",
"status",
".",
"Status",
",",
"string",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StatusResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"}",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"// TODO(perrito666) add status validation.",
"return",
"status",
".",
"Status",
"(",
"result",
".",
"Status",
")",
",",
"result",
".",
"Info",
",",
"nil",
"\n",
"}"
] | // InstanceStatus implements MachineProvisioner.InstanceStatus. | [
"InstanceStatus",
"implements",
"MachineProvisioner",
".",
"InstanceStatus",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L215-L233 |
3,801 | juju/juju | api/provisioner/machine.go | SetModificationStatus | func (m *Machine) SetModificationStatus(status status.Status, info string, data map[string]interface{}) error {
var result params.ErrorResults
args := params.SetStatus{
Entities: []params.EntityStatusArgs{
{Tag: m.tag.String(), Status: status.String(), Info: info, Data: data},
},
}
err := m.st.facade.FacadeCall("SetModificationStatus", args, &result)
if err != nil {
return err
}
return result.OneError()
} | go | func (m *Machine) SetModificationStatus(status status.Status, info string, data map[string]interface{}) error {
var result params.ErrorResults
args := params.SetStatus{
Entities: []params.EntityStatusArgs{
{Tag: m.tag.String(), Status: status.String(), Info: info, Data: data},
},
}
err := m.st.facade.FacadeCall("SetModificationStatus", args, &result)
if err != nil {
return err
}
return result.OneError()
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetModificationStatus",
"(",
"status",
"status",
".",
"Status",
",",
"info",
"string",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"SetStatus",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"EntityStatusArgs",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
",",
"Status",
":",
"status",
".",
"String",
"(",
")",
",",
"Info",
":",
"info",
",",
"Data",
":",
"data",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // SetModificationStatus implements MachineProvisioner.SetModificationStatus. | [
"SetModificationStatus",
"implements",
"MachineProvisioner",
".",
"SetModificationStatus",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L272-L284 |
3,802 | juju/juju | api/provisioner/machine.go | AvailabilityZone | func (m *Machine) AvailabilityZone() (string, error) {
var results params.StringResults
args := params.Entities{
Entities: []params.Entity{{Tag: m.tag.String()}},
}
err := m.st.facade.FacadeCall("AvailabilityZone", args, &results)
if err != nil {
return "", err
}
if len(results.Results) != 1 {
return "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return "", result.Error
}
return result.Result, nil
} | go | func (m *Machine) AvailabilityZone() (string, error) {
var results params.StringResults
args := params.Entities{
Entities: []params.Entity{{Tag: m.tag.String()}},
}
err := m.st.facade.FacadeCall("AvailabilityZone", args, &results)
if err != nil {
return "", err
}
if len(results.Results) != 1 {
return "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return "", result.Error
}
return result.Result, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"AvailabilityZone",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StringResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"result",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // AvailabilityZone implements MachineProvisioner.AvailabilityZone. | [
"AvailabilityZone",
"implements",
"MachineProvisioner",
".",
"AvailabilityZone",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L326-L343 |
3,803 | juju/juju | api/provisioner/machine.go | SetInstanceInfo | func (m *Machine) SetInstanceInfo(
id instance.Id, displayName string, nonce string, characteristics *instance.HardwareCharacteristics,
networkConfig []params.NetworkConfig, volumes []params.Volume,
volumeAttachments map[string]params.VolumeAttachmentInfo, charmProfiles []string,
) error {
var result params.ErrorResults
args := params.InstancesInfo{
Machines: []params.InstanceInfo{{
Tag: m.tag.String(),
InstanceId: id,
DisplayName: displayName,
Nonce: nonce,
Characteristics: characteristics,
Volumes: volumes,
VolumeAttachments: volumeAttachments,
NetworkConfig: networkConfig,
CharmProfiles: charmProfiles,
}},
}
err := m.st.facade.FacadeCall("SetInstanceInfo", args, &result)
if err != nil {
return err
}
return result.OneError()
} | go | func (m *Machine) SetInstanceInfo(
id instance.Id, displayName string, nonce string, characteristics *instance.HardwareCharacteristics,
networkConfig []params.NetworkConfig, volumes []params.Volume,
volumeAttachments map[string]params.VolumeAttachmentInfo, charmProfiles []string,
) error {
var result params.ErrorResults
args := params.InstancesInfo{
Machines: []params.InstanceInfo{{
Tag: m.tag.String(),
InstanceId: id,
DisplayName: displayName,
Nonce: nonce,
Characteristics: characteristics,
Volumes: volumes,
VolumeAttachments: volumeAttachments,
NetworkConfig: networkConfig,
CharmProfiles: charmProfiles,
}},
}
err := m.st.facade.FacadeCall("SetInstanceInfo", args, &result)
if err != nil {
return err
}
return result.OneError()
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetInstanceInfo",
"(",
"id",
"instance",
".",
"Id",
",",
"displayName",
"string",
",",
"nonce",
"string",
",",
"characteristics",
"*",
"instance",
".",
"HardwareCharacteristics",
",",
"networkConfig",
"[",
"]",
"params",
".",
"NetworkConfig",
",",
"volumes",
"[",
"]",
"params",
".",
"Volume",
",",
"volumeAttachments",
"map",
"[",
"string",
"]",
"params",
".",
"VolumeAttachmentInfo",
",",
"charmProfiles",
"[",
"]",
"string",
",",
")",
"error",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"InstancesInfo",
"{",
"Machines",
":",
"[",
"]",
"params",
".",
"InstanceInfo",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
",",
"InstanceId",
":",
"id",
",",
"DisplayName",
":",
"displayName",
",",
"Nonce",
":",
"nonce",
",",
"Characteristics",
":",
"characteristics",
",",
"Volumes",
":",
"volumes",
",",
"VolumeAttachments",
":",
"volumeAttachments",
",",
"NetworkConfig",
":",
"networkConfig",
",",
"CharmProfiles",
":",
"charmProfiles",
",",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // SetInstanceInfo implements MachineProvisioner.SetInstanceInfo. | [
"SetInstanceInfo",
"implements",
"MachineProvisioner",
".",
"SetInstanceInfo",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L366-L390 |
3,804 | juju/juju | api/provisioner/machine.go | WatchContainers | func (m *Machine) WatchContainers(ctype instance.ContainerType) (watcher.StringsWatcher, error) {
if string(ctype) == "" {
return nil, fmt.Errorf("container type must be specified")
}
supported := false
for _, c := range instance.ContainerTypes {
if ctype == c {
supported = true
break
}
}
if !supported {
return nil, fmt.Errorf("unsupported container type %q", ctype)
}
var results params.StringsWatchResults
args := params.WatchContainers{
Params: []params.WatchContainer{
{MachineTag: m.tag.String(), ContainerType: string(ctype)},
},
}
err := m.st.facade.FacadeCall("WatchContainers", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(m.st.facade.RawAPICaller(), result)
return w, nil
} | go | func (m *Machine) WatchContainers(ctype instance.ContainerType) (watcher.StringsWatcher, error) {
if string(ctype) == "" {
return nil, fmt.Errorf("container type must be specified")
}
supported := false
for _, c := range instance.ContainerTypes {
if ctype == c {
supported = true
break
}
}
if !supported {
return nil, fmt.Errorf("unsupported container type %q", ctype)
}
var results params.StringsWatchResults
args := params.WatchContainers{
Params: []params.WatchContainer{
{MachineTag: m.tag.String(), ContainerType: string(ctype)},
},
}
err := m.st.facade.FacadeCall("WatchContainers", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(m.st.facade.RawAPICaller(), result)
return w, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"WatchContainers",
"(",
"ctype",
"instance",
".",
"ContainerType",
")",
"(",
"watcher",
".",
"StringsWatcher",
",",
"error",
")",
"{",
"if",
"string",
"(",
"ctype",
")",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"supported",
":=",
"false",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"instance",
".",
"ContainerTypes",
"{",
"if",
"ctype",
"==",
"c",
"{",
"supported",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"supported",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ctype",
")",
"\n",
"}",
"\n",
"var",
"results",
"params",
".",
"StringsWatchResults",
"\n",
"args",
":=",
"params",
".",
"WatchContainers",
"{",
"Params",
":",
"[",
"]",
"params",
".",
"WatchContainer",
"{",
"{",
"MachineTag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
",",
"ContainerType",
":",
"string",
"(",
"ctype",
")",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"w",
":=",
"apiwatcher",
".",
"NewStringsWatcher",
"(",
"m",
".",
"st",
".",
"facade",
".",
"RawAPICaller",
"(",
")",
",",
"result",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // WatchContainers implements MachineProvisioner.WatchContainers. | [
"WatchContainers",
"implements",
"MachineProvisioner",
".",
"WatchContainers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L451-L484 |
3,805 | juju/juju | api/provisioner/machine.go | WatchAllContainers | func (m *Machine) WatchAllContainers() (watcher.StringsWatcher, error) {
var results params.StringsWatchResults
args := params.WatchContainers{
Params: []params.WatchContainer{
{MachineTag: m.tag.String()},
},
}
err := m.st.facade.FacadeCall("WatchContainers", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(m.st.facade.RawAPICaller(), result)
return w, nil
} | go | func (m *Machine) WatchAllContainers() (watcher.StringsWatcher, error) {
var results params.StringsWatchResults
args := params.WatchContainers{
Params: []params.WatchContainer{
{MachineTag: m.tag.String()},
},
}
err := m.st.facade.FacadeCall("WatchContainers", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(m.st.facade.RawAPICaller(), result)
return w, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"WatchAllContainers",
"(",
")",
"(",
"watcher",
".",
"StringsWatcher",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StringsWatchResults",
"\n",
"args",
":=",
"params",
".",
"WatchContainers",
"{",
"Params",
":",
"[",
"]",
"params",
".",
"WatchContainer",
"{",
"{",
"MachineTag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"w",
":=",
"apiwatcher",
".",
"NewStringsWatcher",
"(",
"m",
".",
"st",
".",
"facade",
".",
"RawAPICaller",
"(",
")",
",",
"result",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // WatchAllContainers implements MachineProvisioner.WatchAllContainers. | [
"WatchAllContainers",
"implements",
"MachineProvisioner",
".",
"WatchAllContainers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L487-L507 |
3,806 | juju/juju | api/provisioner/machine.go | SetSupportedContainers | func (m *Machine) SetSupportedContainers(containerTypes ...instance.ContainerType) error {
var results params.ErrorResults
args := params.MachineContainersParams{
Params: []params.MachineContainers{
{MachineTag: m.tag.String(), ContainerTypes: containerTypes},
},
}
err := m.st.facade.FacadeCall("SetSupportedContainers", args, &results)
if err != nil {
return err
}
if len(results.Results) != 1 {
return fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
apiError := results.Results[0].Error
if apiError != nil {
return apiError
}
return nil
} | go | func (m *Machine) SetSupportedContainers(containerTypes ...instance.ContainerType) error {
var results params.ErrorResults
args := params.MachineContainersParams{
Params: []params.MachineContainers{
{MachineTag: m.tag.String(), ContainerTypes: containerTypes},
},
}
err := m.st.facade.FacadeCall("SetSupportedContainers", args, &results)
if err != nil {
return err
}
if len(results.Results) != 1 {
return fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
apiError := results.Results[0].Error
if apiError != nil {
return apiError
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetSupportedContainers",
"(",
"containerTypes",
"...",
"instance",
".",
"ContainerType",
")",
"error",
"{",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"MachineContainersParams",
"{",
"Params",
":",
"[",
"]",
"params",
".",
"MachineContainers",
"{",
"{",
"MachineTag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
",",
"ContainerTypes",
":",
"containerTypes",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"apiError",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
"\n",
"if",
"apiError",
"!=",
"nil",
"{",
"return",
"apiError",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetSupportedContainers implements MachineProvisioner.SetSupportedContainers. | [
"SetSupportedContainers",
"implements",
"MachineProvisioner",
".",
"SetSupportedContainers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L510-L529 |
3,807 | juju/juju | api/provisioner/machine.go | SupportedContainers | func (m *Machine) SupportedContainers() ([]instance.ContainerType, bool, error) {
var results params.MachineContainerResults
args := params.Entities{
Entities: []params.Entity{
{Tag: m.tag.String()},
},
}
err := m.st.facade.FacadeCall("SupportedContainers", args, &results)
if err != nil {
return nil, false, err
}
if len(results.Results) != 1 {
return nil, false, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
apiError := results.Results[0].Error
if apiError != nil {
return nil, false, apiError
}
result := results.Results[0]
return result.ContainerTypes, result.Determined, nil
} | go | func (m *Machine) SupportedContainers() ([]instance.ContainerType, bool, error) {
var results params.MachineContainerResults
args := params.Entities{
Entities: []params.Entity{
{Tag: m.tag.String()},
},
}
err := m.st.facade.FacadeCall("SupportedContainers", args, &results)
if err != nil {
return nil, false, err
}
if len(results.Results) != 1 {
return nil, false, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
apiError := results.Results[0].Error
if apiError != nil {
return nil, false, apiError
}
result := results.Results[0]
return result.ContainerTypes, result.Determined, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SupportedContainers",
"(",
")",
"(",
"[",
"]",
"instance",
".",
"ContainerType",
",",
"bool",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"MachineContainerResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"false",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"apiError",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
".",
"Error",
"\n",
"if",
"apiError",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"apiError",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"return",
"result",
".",
"ContainerTypes",
",",
"result",
".",
"Determined",
",",
"nil",
"\n",
"}"
] | // SupportedContainers implements MachineProvisioner.SupportedContainers. | [
"SupportedContainers",
"implements",
"MachineProvisioner",
".",
"SupportedContainers",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L537-L557 |
3,808 | juju/juju | api/provisioner/machine.go | SetCharmProfiles | func (m *Machine) SetCharmProfiles(profiles []string) error {
var results params.ErrorResults
args := params.SetProfileArgs{
Args: []params.SetProfileArg{
{
Entity: params.Entity{Tag: m.tag.String()},
Profiles: profiles,
},
},
}
err := m.st.facade.FacadeCall("SetCharmProfiles", args, &results)
if err != nil {
return err
}
if len(results.Results) != 1 {
return fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return result.Error
}
return nil
} | go | func (m *Machine) SetCharmProfiles(profiles []string) error {
var results params.ErrorResults
args := params.SetProfileArgs{
Args: []params.SetProfileArg{
{
Entity: params.Entity{Tag: m.tag.String()},
Profiles: profiles,
},
},
}
err := m.st.facade.FacadeCall("SetCharmProfiles", args, &results)
if err != nil {
return err
}
if len(results.Results) != 1 {
return fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return result.Error
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetCharmProfiles",
"(",
"profiles",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"SetProfileArgs",
"{",
"Args",
":",
"[",
"]",
"params",
".",
"SetProfileArg",
"{",
"{",
"Entity",
":",
"params",
".",
"Entity",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"Profiles",
":",
"profiles",
",",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetCharmProfiles implements MachineProvisioner.SetCharmProfiles. | [
"SetCharmProfiles",
"implements",
"MachineProvisioner",
".",
"SetCharmProfiles",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/provisioner/machine.go#L560-L582 |
3,809 | juju/juju | cmd/juju/romulus/agree/agree.go | Init | func (c *agreeCommand) Init(args []string) error {
if len(args) < 1 {
return errors.New("missing arguments")
}
for _, t := range args {
termId, err := charm.ParseTerm(t)
if err != nil {
return errors.Annotate(err, "invalid term format")
}
if termId.Revision == 0 {
return errors.Errorf("must specify a valid term revision %q", t)
}
c.terms = append(c.terms, term{owner: termId.Owner, name: termId.Name, revision: termId.Revision})
c.termIds = append(c.termIds, t)
}
if len(c.terms) == 0 {
return errors.New("must specify a valid term revision")
}
return c.CommandBase.Init([]string{})
} | go | func (c *agreeCommand) Init(args []string) error {
if len(args) < 1 {
return errors.New("missing arguments")
}
for _, t := range args {
termId, err := charm.ParseTerm(t)
if err != nil {
return errors.Annotate(err, "invalid term format")
}
if termId.Revision == 0 {
return errors.Errorf("must specify a valid term revision %q", t)
}
c.terms = append(c.terms, term{owner: termId.Owner, name: termId.Name, revision: termId.Revision})
c.termIds = append(c.termIds, t)
}
if len(c.terms) == 0 {
return errors.New("must specify a valid term revision")
}
return c.CommandBase.Init([]string{})
} | [
"func",
"(",
"c",
"*",
"agreeCommand",
")",
"Init",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"1",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"t",
":=",
"range",
"args",
"{",
"termId",
",",
"err",
":=",
"charm",
".",
"ParseTerm",
"(",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"termId",
".",
"Revision",
"==",
"0",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"}",
"\n",
"c",
".",
"terms",
"=",
"append",
"(",
"c",
".",
"terms",
",",
"term",
"{",
"owner",
":",
"termId",
".",
"Owner",
",",
"name",
":",
"termId",
".",
"Name",
",",
"revision",
":",
"termId",
".",
"Revision",
"}",
")",
"\n",
"c",
".",
"termIds",
"=",
"append",
"(",
"c",
".",
"termIds",
",",
"t",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"terms",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"CommandBase",
".",
"Init",
"(",
"[",
"]",
"string",
"{",
"}",
")",
"\n",
"}"
] | // Init read and verifies the arguments. | [
"Init",
"read",
"and",
"verifies",
"the",
"arguments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/agree/agree.go#L87-L107 |
3,810 | juju/juju | state/leadership.go | LeadershipClaimer | func (st *State) LeadershipClaimer() leadership.Claimer {
return leadershipClaimer{
lazyLeaseClaimer{func() (lease.Claimer, error) {
manager := st.workers.leadershipManager()
return manager.Claimer(applicationLeadershipNamespace, st.modelUUID())
}},
}
} | go | func (st *State) LeadershipClaimer() leadership.Claimer {
return leadershipClaimer{
lazyLeaseClaimer{func() (lease.Claimer, error) {
manager := st.workers.leadershipManager()
return manager.Claimer(applicationLeadershipNamespace, st.modelUUID())
}},
}
} | [
"func",
"(",
"st",
"*",
"State",
")",
"LeadershipClaimer",
"(",
")",
"leadership",
".",
"Claimer",
"{",
"return",
"leadershipClaimer",
"{",
"lazyLeaseClaimer",
"{",
"func",
"(",
")",
"(",
"lease",
".",
"Claimer",
",",
"error",
")",
"{",
"manager",
":=",
"st",
".",
"workers",
".",
"leadershipManager",
"(",
")",
"\n",
"return",
"manager",
".",
"Claimer",
"(",
"applicationLeadershipNamespace",
",",
"st",
".",
"modelUUID",
"(",
")",
")",
"\n",
"}",
"}",
",",
"}",
"\n",
"}"
] | // LeadershipClaimer returns a leadership.Claimer for units and applications in the
// state's model. | [
"LeadershipClaimer",
"returns",
"a",
"leadership",
".",
"Claimer",
"for",
"units",
"and",
"applications",
"in",
"the",
"state",
"s",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/leadership.go#L28-L35 |
3,811 | juju/juju | state/leadership.go | LeadershipChecker | func (st *State) LeadershipChecker() leadership.Checker {
return leadershipChecker{
lazyLeaseChecker{func() (lease.Checker, error) {
manager := st.workers.leadershipManager()
return manager.Checker(applicationLeadershipNamespace, st.modelUUID())
}},
}
} | go | func (st *State) LeadershipChecker() leadership.Checker {
return leadershipChecker{
lazyLeaseChecker{func() (lease.Checker, error) {
manager := st.workers.leadershipManager()
return manager.Checker(applicationLeadershipNamespace, st.modelUUID())
}},
}
} | [
"func",
"(",
"st",
"*",
"State",
")",
"LeadershipChecker",
"(",
")",
"leadership",
".",
"Checker",
"{",
"return",
"leadershipChecker",
"{",
"lazyLeaseChecker",
"{",
"func",
"(",
")",
"(",
"lease",
".",
"Checker",
",",
"error",
")",
"{",
"manager",
":=",
"st",
".",
"workers",
".",
"leadershipManager",
"(",
")",
"\n",
"return",
"manager",
".",
"Checker",
"(",
"applicationLeadershipNamespace",
",",
"st",
".",
"modelUUID",
"(",
")",
")",
"\n",
"}",
"}",
",",
"}",
"\n",
"}"
] | // LeadershipChecker returns a leadership.Checker for units and applications in the
// state's model. | [
"LeadershipChecker",
"returns",
"a",
"leadership",
".",
"Checker",
"for",
"units",
"and",
"applications",
"in",
"the",
"state",
"s",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/leadership.go#L39-L46 |
3,812 | juju/juju | state/leadership.go | buildTxnWithLeadership | func buildTxnWithLeadership(buildTxn jujutxn.TransactionSource, token leadership.Token) jujutxn.TransactionSource {
return func(attempt int) ([]txn.Op, error) {
var prereqs []txn.Op
if err := token.Check(attempt, &prereqs); err != nil {
return nil, errors.Annotatef(err, "prerequisites failed")
}
ops, err := buildTxn(attempt)
if err == jujutxn.ErrNoOperations {
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
return append(prereqs, ops...), nil
}
} | go | func buildTxnWithLeadership(buildTxn jujutxn.TransactionSource, token leadership.Token) jujutxn.TransactionSource {
return func(attempt int) ([]txn.Op, error) {
var prereqs []txn.Op
if err := token.Check(attempt, &prereqs); err != nil {
return nil, errors.Annotatef(err, "prerequisites failed")
}
ops, err := buildTxn(attempt)
if err == jujutxn.ErrNoOperations {
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
return append(prereqs, ops...), nil
}
} | [
"func",
"buildTxnWithLeadership",
"(",
"buildTxn",
"jujutxn",
".",
"TransactionSource",
",",
"token",
"leadership",
".",
"Token",
")",
"jujutxn",
".",
"TransactionSource",
"{",
"return",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"var",
"prereqs",
"[",
"]",
"txn",
".",
"Op",
"\n",
"if",
"err",
":=",
"token",
".",
"Check",
"(",
"attempt",
",",
"&",
"prereqs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ops",
",",
"err",
":=",
"buildTxn",
"(",
"attempt",
")",
"\n",
"if",
"err",
"==",
"jujutxn",
".",
"ErrNoOperations",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"append",
"(",
"prereqs",
",",
"ops",
"...",
")",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // buildTxnWithLeadership returns a transaction source that combines the supplied source
// with checks and asserts on the supplied token. | [
"buildTxnWithLeadership",
"returns",
"a",
"transaction",
"source",
"that",
"combines",
"the",
"supplied",
"source",
"with",
"checks",
"and",
"asserts",
"on",
"the",
"supplied",
"token",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/leadership.go#L50-L64 |
3,813 | juju/juju | state/logs.go | InitDbLogs | func InitDbLogs(session *mgo.Session, modelUUID string) error {
logsColl := session.DB(logsDB).C(logCollectionName(modelUUID))
for _, key := range logIndexes {
err := logsColl.EnsureIndex(mgo.Index{Key: key})
if err != nil {
return errors.Annotate(err, "cannot create index for logs collection")
}
}
return nil
} | go | func InitDbLogs(session *mgo.Session, modelUUID string) error {
logsColl := session.DB(logsDB).C(logCollectionName(modelUUID))
for _, key := range logIndexes {
err := logsColl.EnsureIndex(mgo.Index{Key: key})
if err != nil {
return errors.Annotate(err, "cannot create index for logs collection")
}
}
return nil
} | [
"func",
"InitDbLogs",
"(",
"session",
"*",
"mgo",
".",
"Session",
",",
"modelUUID",
"string",
")",
"error",
"{",
"logsColl",
":=",
"session",
".",
"DB",
"(",
"logsDB",
")",
".",
"C",
"(",
"logCollectionName",
"(",
"modelUUID",
")",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"logIndexes",
"{",
"err",
":=",
"logsColl",
".",
"EnsureIndex",
"(",
"mgo",
".",
"Index",
"{",
"Key",
":",
"key",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // InitDbLogs sets up the indexes for the logs collection. It should
// be called as state is opened. It is idempotent. | [
"InitDbLogs",
"sets",
"up",
"the",
"indexes",
"for",
"the",
"logs",
"collection",
".",
"It",
"should",
"be",
"called",
"as",
"state",
"is",
"opened",
".",
"It",
"is",
"idempotent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L80-L89 |
3,814 | juju/juju | state/logs.go | NewLastSentLogTracker | func NewLastSentLogTracker(st ModelSessioner, modelUUID, sink string) *LastSentLogTracker {
session := st.MongoSession().Copy()
return &LastSentLogTracker{
id: fmt.Sprintf("%s#%s", modelUUID, sink),
model: modelUUID,
sink: sink,
session: session,
}
} | go | func NewLastSentLogTracker(st ModelSessioner, modelUUID, sink string) *LastSentLogTracker {
session := st.MongoSession().Copy()
return &LastSentLogTracker{
id: fmt.Sprintf("%s#%s", modelUUID, sink),
model: modelUUID,
sink: sink,
session: session,
}
} | [
"func",
"NewLastSentLogTracker",
"(",
"st",
"ModelSessioner",
",",
"modelUUID",
",",
"sink",
"string",
")",
"*",
"LastSentLogTracker",
"{",
"session",
":=",
"st",
".",
"MongoSession",
"(",
")",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"LastSentLogTracker",
"{",
"id",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"modelUUID",
",",
"sink",
")",
",",
"model",
":",
"modelUUID",
",",
"sink",
":",
"sink",
",",
"session",
":",
"session",
",",
"}",
"\n",
"}"
] | // NewLastSentLogTracker returns a new tracker that records and retrieves
// the timestamps of the most recent log records forwarded to the
// identified log sink for the current model. | [
"NewLastSentLogTracker",
"returns",
"a",
"new",
"tracker",
"that",
"records",
"and",
"retrieves",
"the",
"timestamps",
"of",
"the",
"most",
"recent",
"log",
"records",
"forwarded",
"to",
"the",
"identified",
"log",
"sink",
"for",
"the",
"current",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L144-L152 |
3,815 | juju/juju | state/logs.go | Set | func (logger *LastSentLogTracker) Set(recID, recTimestamp int64) error {
collection := logger.session.DB(logsDB).C(forwardedC)
_, err := collection.UpsertId(
logger.id,
lastSentDoc{
ID: logger.id,
ModelUUID: logger.model,
Sink: logger.sink,
RecordID: recID,
RecordTimestamp: recTimestamp,
},
)
return errors.Trace(err)
} | go | func (logger *LastSentLogTracker) Set(recID, recTimestamp int64) error {
collection := logger.session.DB(logsDB).C(forwardedC)
_, err := collection.UpsertId(
logger.id,
lastSentDoc{
ID: logger.id,
ModelUUID: logger.model,
Sink: logger.sink,
RecordID: recID,
RecordTimestamp: recTimestamp,
},
)
return errors.Trace(err)
} | [
"func",
"(",
"logger",
"*",
"LastSentLogTracker",
")",
"Set",
"(",
"recID",
",",
"recTimestamp",
"int64",
")",
"error",
"{",
"collection",
":=",
"logger",
".",
"session",
".",
"DB",
"(",
"logsDB",
")",
".",
"C",
"(",
"forwardedC",
")",
"\n",
"_",
",",
"err",
":=",
"collection",
".",
"UpsertId",
"(",
"logger",
".",
"id",
",",
"lastSentDoc",
"{",
"ID",
":",
"logger",
".",
"id",
",",
"ModelUUID",
":",
"logger",
".",
"model",
",",
"Sink",
":",
"logger",
".",
"sink",
",",
"RecordID",
":",
"recID",
",",
"RecordTimestamp",
":",
"recTimestamp",
",",
"}",
",",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Set records the timestamp. | [
"Set",
"records",
"the",
"timestamp",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L161-L174 |
3,816 | juju/juju | state/logs.go | Get | func (logger *LastSentLogTracker) Get() (int64, int64, error) {
collection := logger.session.DB(logsDB).C(forwardedC)
var doc lastSentDoc
err := collection.FindId(logger.id).One(&doc)
if err != nil {
if err == mgo.ErrNotFound {
return 0, 0, errors.Trace(ErrNeverForwarded)
}
return 0, 0, errors.Trace(err)
}
return doc.RecordID, doc.RecordTimestamp, nil
} | go | func (logger *LastSentLogTracker) Get() (int64, int64, error) {
collection := logger.session.DB(logsDB).C(forwardedC)
var doc lastSentDoc
err := collection.FindId(logger.id).One(&doc)
if err != nil {
if err == mgo.ErrNotFound {
return 0, 0, errors.Trace(ErrNeverForwarded)
}
return 0, 0, errors.Trace(err)
}
return doc.RecordID, doc.RecordTimestamp, nil
} | [
"func",
"(",
"logger",
"*",
"LastSentLogTracker",
")",
"Get",
"(",
")",
"(",
"int64",
",",
"int64",
",",
"error",
")",
"{",
"collection",
":=",
"logger",
".",
"session",
".",
"DB",
"(",
"logsDB",
")",
".",
"C",
"(",
"forwardedC",
")",
"\n",
"var",
"doc",
"lastSentDoc",
"\n",
"err",
":=",
"collection",
".",
"FindId",
"(",
"logger",
".",
"id",
")",
".",
"One",
"(",
"&",
"doc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"0",
",",
"0",
",",
"errors",
".",
"Trace",
"(",
"ErrNeverForwarded",
")",
"\n",
"}",
"\n",
"return",
"0",
",",
"0",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"doc",
".",
"RecordID",
",",
"doc",
".",
"RecordTimestamp",
",",
"nil",
"\n",
"}"
] | // Get retrieves the id and timestamp. | [
"Get",
"retrieves",
"the",
"id",
"and",
"timestamp",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L177-L188 |
3,817 | juju/juju | state/logs.go | Log | func (logger *DbLogger) Log(records []LogRecord) error {
for _, r := range records {
if err := validateInputLogRecord(r); err != nil {
return errors.Annotate(err, "validating input log record")
}
}
bulk := logger.logsColl.Bulk()
for _, r := range records {
var versionString string
if r.Version != version.Zero {
versionString = r.Version.String()
}
bulk.Insert(&logDoc{
// TODO(axw) Use a controller-global int
// sequence for Id, so we can order by
// insertion.
Id: bson.NewObjectId(),
Time: r.Time.UnixNano(),
Entity: r.Entity.String(),
Version: versionString,
Module: r.Module,
Location: r.Location,
Level: int(r.Level),
Message: r.Message,
})
}
_, err := bulk.Run()
return errors.Annotatef(err, "inserting %d log record(s)", len(records))
} | go | func (logger *DbLogger) Log(records []LogRecord) error {
for _, r := range records {
if err := validateInputLogRecord(r); err != nil {
return errors.Annotate(err, "validating input log record")
}
}
bulk := logger.logsColl.Bulk()
for _, r := range records {
var versionString string
if r.Version != version.Zero {
versionString = r.Version.String()
}
bulk.Insert(&logDoc{
// TODO(axw) Use a controller-global int
// sequence for Id, so we can order by
// insertion.
Id: bson.NewObjectId(),
Time: r.Time.UnixNano(),
Entity: r.Entity.String(),
Version: versionString,
Module: r.Module,
Location: r.Location,
Level: int(r.Level),
Message: r.Message,
})
}
_, err := bulk.Run()
return errors.Annotatef(err, "inserting %d log record(s)", len(records))
} | [
"func",
"(",
"logger",
"*",
"DbLogger",
")",
"Log",
"(",
"records",
"[",
"]",
"LogRecord",
")",
"error",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"records",
"{",
"if",
"err",
":=",
"validateInputLogRecord",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"bulk",
":=",
"logger",
".",
"logsColl",
".",
"Bulk",
"(",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"records",
"{",
"var",
"versionString",
"string",
"\n",
"if",
"r",
".",
"Version",
"!=",
"version",
".",
"Zero",
"{",
"versionString",
"=",
"r",
".",
"Version",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"bulk",
".",
"Insert",
"(",
"&",
"logDoc",
"{",
"// TODO(axw) Use a controller-global int",
"// sequence for Id, so we can order by",
"// insertion.",
"Id",
":",
"bson",
".",
"NewObjectId",
"(",
")",
",",
"Time",
":",
"r",
".",
"Time",
".",
"UnixNano",
"(",
")",
",",
"Entity",
":",
"r",
".",
"Entity",
".",
"String",
"(",
")",
",",
"Version",
":",
"versionString",
",",
"Module",
":",
"r",
".",
"Module",
",",
"Location",
":",
"r",
".",
"Location",
",",
"Level",
":",
"int",
"(",
"r",
".",
"Level",
")",
",",
"Message",
":",
"r",
".",
"Message",
",",
"}",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"bulk",
".",
"Run",
"(",
")",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"len",
"(",
"records",
")",
")",
"\n",
"}"
] | // Log writes log messages to the database. Log records
// are written to the database in bulk; callers should
// buffer log records to and call Log with a batch to
// minimise database writes.
//
// The ModelUUID and ID fields of records are ignored;
// DbLogger is scoped to a single model, and ID is
// controlled by the DbLogger code. | [
"Log",
"writes",
"log",
"messages",
"to",
"the",
"database",
".",
"Log",
"records",
"are",
"written",
"to",
"the",
"database",
"in",
"bulk",
";",
"callers",
"should",
"buffer",
"log",
"records",
"to",
"and",
"call",
"Log",
"with",
"a",
"batch",
"to",
"minimise",
"database",
"writes",
".",
"The",
"ModelUUID",
"and",
"ID",
"fields",
"of",
"records",
"are",
"ignored",
";",
"DbLogger",
"is",
"scoped",
"to",
"a",
"single",
"model",
"and",
"ID",
"is",
"controlled",
"by",
"the",
"DbLogger",
"code",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L230-L258 |
3,818 | juju/juju | state/logs.go | Close | func (logger *DbLogger) Close() {
if logger.logsColl != nil {
logger.logsColl.Database.Session.Close()
}
} | go | func (logger *DbLogger) Close() {
if logger.logsColl != nil {
logger.logsColl.Database.Session.Close()
}
} | [
"func",
"(",
"logger",
"*",
"DbLogger",
")",
"Close",
"(",
")",
"{",
"if",
"logger",
".",
"logsColl",
"!=",
"nil",
"{",
"logger",
".",
"logsColl",
".",
"Database",
".",
"Session",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Close cleans up resources used by the DbLogger instance. | [
"Close",
"cleans",
"up",
"resources",
"used",
"by",
"the",
"DbLogger",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L268-L272 |
3,819 | juju/juju | state/logs.go | NewLogTailer | func NewLogTailer(st LogTailerState, params LogTailerParams) (LogTailer, error) {
session := st.MongoSession().Copy()
t := &logTailer{
modelUUID: st.ModelUUID(),
session: session,
logsColl: session.DB(logsDB).C(logCollectionName(st.ModelUUID())).With(session),
params: params,
logCh: make(chan *LogRecord),
recentIds: newRecentIdTracker(maxRecentLogIds),
maxInitialLines: maxInitialLines,
}
t.tomb.Go(func() error {
defer close(t.logCh)
defer session.Close()
err := t.loop()
return errors.Cause(err)
})
return t, nil
} | go | func NewLogTailer(st LogTailerState, params LogTailerParams) (LogTailer, error) {
session := st.MongoSession().Copy()
t := &logTailer{
modelUUID: st.ModelUUID(),
session: session,
logsColl: session.DB(logsDB).C(logCollectionName(st.ModelUUID())).With(session),
params: params,
logCh: make(chan *LogRecord),
recentIds: newRecentIdTracker(maxRecentLogIds),
maxInitialLines: maxInitialLines,
}
t.tomb.Go(func() error {
defer close(t.logCh)
defer session.Close()
err := t.loop()
return errors.Cause(err)
})
return t, nil
} | [
"func",
"NewLogTailer",
"(",
"st",
"LogTailerState",
",",
"params",
"LogTailerParams",
")",
"(",
"LogTailer",
",",
"error",
")",
"{",
"session",
":=",
"st",
".",
"MongoSession",
"(",
")",
".",
"Copy",
"(",
")",
"\n",
"t",
":=",
"&",
"logTailer",
"{",
"modelUUID",
":",
"st",
".",
"ModelUUID",
"(",
")",
",",
"session",
":",
"session",
",",
"logsColl",
":",
"session",
".",
"DB",
"(",
"logsDB",
")",
".",
"C",
"(",
"logCollectionName",
"(",
"st",
".",
"ModelUUID",
"(",
")",
")",
")",
".",
"With",
"(",
"session",
")",
",",
"params",
":",
"params",
",",
"logCh",
":",
"make",
"(",
"chan",
"*",
"LogRecord",
")",
",",
"recentIds",
":",
"newRecentIdTracker",
"(",
"maxRecentLogIds",
")",
",",
"maxInitialLines",
":",
"maxInitialLines",
",",
"}",
"\n",
"t",
".",
"tomb",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"defer",
"close",
"(",
"t",
".",
"logCh",
")",
"\n",
"defer",
"session",
".",
"Close",
"(",
")",
"\n",
"err",
":=",
"t",
".",
"loop",
"(",
")",
"\n",
"return",
"errors",
".",
"Cause",
"(",
"err",
")",
"\n",
"}",
")",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] | // NewLogTailer returns a LogTailer which filters according to the
// parameters given. | [
"NewLogTailer",
"returns",
"a",
"LogTailer",
"which",
"filters",
"according",
"to",
"the",
"parameters",
"given",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L362-L380 |
3,820 | juju/juju | state/logs.go | Stop | func (t *logTailer) Stop() error {
t.tomb.Kill(nil)
return t.tomb.Wait()
} | go | func (t *logTailer) Stop() error {
t.tomb.Kill(nil)
return t.tomb.Wait()
} | [
"func",
"(",
"t",
"*",
"logTailer",
")",
"Stop",
"(",
")",
"error",
"{",
"t",
".",
"tomb",
".",
"Kill",
"(",
"nil",
")",
"\n",
"return",
"t",
".",
"tomb",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Stop implements the LogTailer interface. | [
"Stop",
"implements",
"the",
"LogTailer",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L406-L409 |
3,821 | juju/juju | state/logs.go | initLogsSession | func initLogsSession(st ModelSessioner) (*mgo.Session, *mgo.Collection) {
session, db := initLogsSessionDB(st)
return session, db.C(logCollectionName(st.ModelUUID()))
} | go | func initLogsSession(st ModelSessioner) (*mgo.Session, *mgo.Collection) {
session, db := initLogsSessionDB(st)
return session, db.C(logCollectionName(st.ModelUUID()))
} | [
"func",
"initLogsSession",
"(",
"st",
"ModelSessioner",
")",
"(",
"*",
"mgo",
".",
"Session",
",",
"*",
"mgo",
".",
"Collection",
")",
"{",
"session",
",",
"db",
":=",
"initLogsSessionDB",
"(",
"st",
")",
"\n",
"return",
"session",
",",
"db",
".",
"C",
"(",
"logCollectionName",
"(",
"st",
".",
"ModelUUID",
"(",
")",
")",
")",
"\n",
"}"
] | // initLogsSession creates a new session suitable for logging updates,
// returning the session and a logs mgo.Collection connected to that
// session. | [
"initLogsSession",
"creates",
"a",
"new",
"session",
"suitable",
"for",
"logging",
"updates",
"returning",
"the",
"session",
"and",
"a",
"logs",
"mgo",
".",
"Collection",
"connected",
"to",
"that",
"session",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L881-L884 |
3,822 | juju/juju | state/logs.go | getCollectionTotalMB | func getCollectionTotalMB(colls map[string]*mgo.Collection) (int, error) {
total := 0
for _, coll := range colls {
size, err := getCollectionMB(coll)
if err != nil {
return 0, errors.Trace(err)
}
total += size
}
return total, nil
} | go | func getCollectionTotalMB(colls map[string]*mgo.Collection) (int, error) {
total := 0
for _, coll := range colls {
size, err := getCollectionMB(coll)
if err != nil {
return 0, errors.Trace(err)
}
total += size
}
return total, nil
} | [
"func",
"getCollectionTotalMB",
"(",
"colls",
"map",
"[",
"string",
"]",
"*",
"mgo",
".",
"Collection",
")",
"(",
"int",
",",
"error",
")",
"{",
"total",
":=",
"0",
"\n",
"for",
"_",
",",
"coll",
":=",
"range",
"colls",
"{",
"size",
",",
"err",
":=",
"getCollectionMB",
"(",
"coll",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"total",
"+=",
"size",
"\n",
"}",
"\n",
"return",
"total",
",",
"nil",
"\n",
"}"
] | // getCollectionTotalMB returns the total size of the log collections
// passed. | [
"getCollectionTotalMB",
"returns",
"the",
"total",
"size",
"of",
"the",
"log",
"collections",
"passed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L931-L941 |
3,823 | juju/juju | state/logs.go | getLogCollections | func getLogCollections(db *mgo.Database) (map[string]*mgo.Collection, error) {
result := make(map[string]*mgo.Collection)
names, err := db.CollectionNames()
if err != nil {
return nil, errors.Trace(err)
}
for _, name := range names {
if !strings.HasPrefix(name, logsCPrefix) {
continue
}
uuid := name[len(logsCPrefix):]
result[uuid] = db.C(name)
}
return result, nil
} | go | func getLogCollections(db *mgo.Database) (map[string]*mgo.Collection, error) {
result := make(map[string]*mgo.Collection)
names, err := db.CollectionNames()
if err != nil {
return nil, errors.Trace(err)
}
for _, name := range names {
if !strings.HasPrefix(name, logsCPrefix) {
continue
}
uuid := name[len(logsCPrefix):]
result[uuid] = db.C(name)
}
return result, nil
} | [
"func",
"getLogCollections",
"(",
"db",
"*",
"mgo",
".",
"Database",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"mgo",
".",
"Collection",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"mgo",
".",
"Collection",
")",
"\n",
"names",
",",
"err",
":=",
"db",
".",
"CollectionNames",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"name",
",",
"logsCPrefix",
")",
"{",
"continue",
"\n",
"}",
"\n",
"uuid",
":=",
"name",
"[",
"len",
"(",
"logsCPrefix",
")",
":",
"]",
"\n",
"result",
"[",
"uuid",
"]",
"=",
"db",
".",
"C",
"(",
"name",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // getLogCollections returns all of the log collections in the DB by
// model UUID. | [
"getLogCollections",
"returns",
"all",
"of",
"the",
"log",
"collections",
"in",
"the",
"DB",
"by",
"model",
"UUID",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L945-L959 |
3,824 | juju/juju | state/logs.go | findModelWithMostLogs | func findModelWithMostLogs(colls map[string]*mgo.Collection) (string, int, error) {
var maxModelUUID string
var maxCount int
for modelUUID, coll := range colls {
count, err := getRowCountForCollection(coll)
if err != nil {
return "", -1, errors.Trace(err)
}
if count > maxCount {
maxModelUUID = modelUUID
maxCount = count
}
}
return maxModelUUID, maxCount, nil
} | go | func findModelWithMostLogs(colls map[string]*mgo.Collection) (string, int, error) {
var maxModelUUID string
var maxCount int
for modelUUID, coll := range colls {
count, err := getRowCountForCollection(coll)
if err != nil {
return "", -1, errors.Trace(err)
}
if count > maxCount {
maxModelUUID = modelUUID
maxCount = count
}
}
return maxModelUUID, maxCount, nil
} | [
"func",
"findModelWithMostLogs",
"(",
"colls",
"map",
"[",
"string",
"]",
"*",
"mgo",
".",
"Collection",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"var",
"maxModelUUID",
"string",
"\n",
"var",
"maxCount",
"int",
"\n",
"for",
"modelUUID",
",",
"coll",
":=",
"range",
"colls",
"{",
"count",
",",
"err",
":=",
"getRowCountForCollection",
"(",
"coll",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"-",
"1",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"count",
">",
"maxCount",
"{",
"maxModelUUID",
"=",
"modelUUID",
"\n",
"maxCount",
"=",
"count",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"maxModelUUID",
",",
"maxCount",
",",
"nil",
"\n",
"}"
] | // findModelWithMostLogs returns the modelUUID and row count for the
// collection with the most logs in the logs DB. | [
"findModelWithMostLogs",
"returns",
"the",
"modelUUID",
"and",
"row",
"count",
"for",
"the",
"collection",
"with",
"the",
"most",
"logs",
"in",
"the",
"logs",
"DB",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L963-L977 |
3,825 | juju/juju | state/logs.go | getRowCountForCollection | func getRowCountForCollection(coll *mgo.Collection) (int, error) {
count, err := coll.Count()
if err != nil {
return -1, errors.Annotate(err, "failed to get log count")
}
return count, nil
} | go | func getRowCountForCollection(coll *mgo.Collection) (int, error) {
count, err := coll.Count()
if err != nil {
return -1, errors.Annotate(err, "failed to get log count")
}
return count, nil
} | [
"func",
"getRowCountForCollection",
"(",
"coll",
"*",
"mgo",
".",
"Collection",
")",
"(",
"int",
",",
"error",
")",
"{",
"count",
",",
"err",
":=",
"coll",
".",
"Count",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"count",
",",
"nil",
"\n",
"}"
] | // getRowCountForCollection returns the number of log records stored for a
// given model log collection. | [
"getRowCountForCollection",
"returns",
"the",
"number",
"of",
"log",
"records",
"stored",
"for",
"a",
"given",
"model",
"log",
"collection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/logs.go#L981-L987 |
3,826 | juju/juju | provider/openstack/legacy_firewaller.go | SetUpGroups | func (c *legacyNovaFirewaller) SetUpGroups(ctx context.ProviderCallContext, controllerUUID, machineId string, apiPort int) ([]string, error) {
jujuGroup, err := c.setUpGlobalGroup(ctx, c.jujuGroupName(controllerUUID), apiPort)
if err != nil {
return nil, errors.Trace(err)
}
var machineGroup nova.SecurityGroup
switch c.environ.Config().FirewallMode() {
case config.FwInstance:
machineGroup, err = c.ensureGroup(ctx, c.machineGroupName(controllerUUID, machineId), nil)
case config.FwGlobal:
machineGroup, err = c.ensureGroup(ctx, c.globalGroupName(controllerUUID), nil)
}
if err != nil {
return nil, errors.Trace(err)
}
groupNames := []string{jujuGroup.Name, machineGroup.Name}
if c.environ.ecfg().useDefaultSecurityGroup() {
groupNames = append(groupNames, "default")
}
return groupNames, nil
} | go | func (c *legacyNovaFirewaller) SetUpGroups(ctx context.ProviderCallContext, controllerUUID, machineId string, apiPort int) ([]string, error) {
jujuGroup, err := c.setUpGlobalGroup(ctx, c.jujuGroupName(controllerUUID), apiPort)
if err != nil {
return nil, errors.Trace(err)
}
var machineGroup nova.SecurityGroup
switch c.environ.Config().FirewallMode() {
case config.FwInstance:
machineGroup, err = c.ensureGroup(ctx, c.machineGroupName(controllerUUID, machineId), nil)
case config.FwGlobal:
machineGroup, err = c.ensureGroup(ctx, c.globalGroupName(controllerUUID), nil)
}
if err != nil {
return nil, errors.Trace(err)
}
groupNames := []string{jujuGroup.Name, machineGroup.Name}
if c.environ.ecfg().useDefaultSecurityGroup() {
groupNames = append(groupNames, "default")
}
return groupNames, nil
} | [
"func",
"(",
"c",
"*",
"legacyNovaFirewaller",
")",
"SetUpGroups",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"controllerUUID",
",",
"machineId",
"string",
",",
"apiPort",
"int",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"jujuGroup",
",",
"err",
":=",
"c",
".",
"setUpGlobalGroup",
"(",
"ctx",
",",
"c",
".",
"jujuGroupName",
"(",
"controllerUUID",
")",
",",
"apiPort",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"machineGroup",
"nova",
".",
"SecurityGroup",
"\n",
"switch",
"c",
".",
"environ",
".",
"Config",
"(",
")",
".",
"FirewallMode",
"(",
")",
"{",
"case",
"config",
".",
"FwInstance",
":",
"machineGroup",
",",
"err",
"=",
"c",
".",
"ensureGroup",
"(",
"ctx",
",",
"c",
".",
"machineGroupName",
"(",
"controllerUUID",
",",
"machineId",
")",
",",
"nil",
")",
"\n",
"case",
"config",
".",
"FwGlobal",
":",
"machineGroup",
",",
"err",
"=",
"c",
".",
"ensureGroup",
"(",
"ctx",
",",
"c",
".",
"globalGroupName",
"(",
"controllerUUID",
")",
",",
"nil",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"groupNames",
":=",
"[",
"]",
"string",
"{",
"jujuGroup",
".",
"Name",
",",
"machineGroup",
".",
"Name",
"}",
"\n",
"if",
"c",
".",
"environ",
".",
"ecfg",
"(",
")",
".",
"useDefaultSecurityGroup",
"(",
")",
"{",
"groupNames",
"=",
"append",
"(",
"groupNames",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"groupNames",
",",
"nil",
"\n",
"}"
] | // SetUpGroups creates the security groups for the new machine, and
// returns them.
//
// Instances are tagged with a group so they can be distinguished from
// other instances that might be running on the same OpenStack account.
// In addition, a specific machine security group is created for each
// machine, so that its firewall rules can be configured per machine. | [
"SetUpGroups",
"creates",
"the",
"security",
"groups",
"for",
"the",
"new",
"machine",
"and",
"returns",
"them",
".",
"Instances",
"are",
"tagged",
"with",
"a",
"group",
"so",
"they",
"can",
"be",
"distinguished",
"from",
"other",
"instances",
"that",
"might",
"be",
"running",
"on",
"the",
"same",
"OpenStack",
"account",
".",
"In",
"addition",
"a",
"specific",
"machine",
"security",
"group",
"is",
"created",
"for",
"each",
"machine",
"so",
"that",
"its",
"firewall",
"rules",
"can",
"be",
"configured",
"per",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/legacy_firewaller.go#L35-L55 |
3,827 | juju/juju | provider/openstack/legacy_firewaller.go | ensureGroup | func (c *legacyNovaFirewaller) ensureGroup(ctx context.ProviderCallContext, name string, rules []nova.RuleInfo) (nova.SecurityGroup, error) {
novaClient := c.environ.nova()
// First attempt to look up an existing group by name.
group, err := novaClient.SecurityGroupByName(name)
if err == nil {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
// Group exists, so assume it is correctly set up and return it.
// TODO(jam): 2013-09-18 http://pad.lv/121795
// We really should verify the group is set up correctly,
// because deleting and re-creating environments can get us bad
// groups (especially if they were set up under Python)
return *group, nil
}
// Doesn't exist, so try and create it.
group, err = novaClient.CreateSecurityGroup(name, "juju group")
if err != nil {
if !gooseerrors.IsDuplicateValue(err) {
return legacyZeroGroup, err
} else {
// We just tried to create a duplicate group, so load the existing group.
group, err = novaClient.SecurityGroupByName(name)
if err != nil {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
return legacyZeroGroup, err
}
return *group, nil
}
}
// The new group is created so now add the rules.
group.Rules = make([]nova.SecurityGroupRule, len(rules))
for i, rule := range rules {
rule.ParentGroupId = group.Id
if rule.Cidr == "" {
// http://pad.lv/1226996 Rules that don't have a CIDR
// are meant to apply only to this group. If you don't
// supply CIDR or GroupId then openstack assumes you
// mean CIDR=0.0.0.0/0
rule.GroupId = &group.Id
}
groupRule, err := novaClient.CreateSecurityGroupRule(rule)
if err != nil && !gooseerrors.IsDuplicateValue(err) {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
return legacyZeroGroup, err
}
group.Rules[i] = *groupRule
}
return *group, nil
} | go | func (c *legacyNovaFirewaller) ensureGroup(ctx context.ProviderCallContext, name string, rules []nova.RuleInfo) (nova.SecurityGroup, error) {
novaClient := c.environ.nova()
// First attempt to look up an existing group by name.
group, err := novaClient.SecurityGroupByName(name)
if err == nil {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
// Group exists, so assume it is correctly set up and return it.
// TODO(jam): 2013-09-18 http://pad.lv/121795
// We really should verify the group is set up correctly,
// because deleting and re-creating environments can get us bad
// groups (especially if they were set up under Python)
return *group, nil
}
// Doesn't exist, so try and create it.
group, err = novaClient.CreateSecurityGroup(name, "juju group")
if err != nil {
if !gooseerrors.IsDuplicateValue(err) {
return legacyZeroGroup, err
} else {
// We just tried to create a duplicate group, so load the existing group.
group, err = novaClient.SecurityGroupByName(name)
if err != nil {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
return legacyZeroGroup, err
}
return *group, nil
}
}
// The new group is created so now add the rules.
group.Rules = make([]nova.SecurityGroupRule, len(rules))
for i, rule := range rules {
rule.ParentGroupId = group.Id
if rule.Cidr == "" {
// http://pad.lv/1226996 Rules that don't have a CIDR
// are meant to apply only to this group. If you don't
// supply CIDR or GroupId then openstack assumes you
// mean CIDR=0.0.0.0/0
rule.GroupId = &group.Id
}
groupRule, err := novaClient.CreateSecurityGroupRule(rule)
if err != nil && !gooseerrors.IsDuplicateValue(err) {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
return legacyZeroGroup, err
}
group.Rules[i] = *groupRule
}
return *group, nil
} | [
"func",
"(",
"c",
"*",
"legacyNovaFirewaller",
")",
"ensureGroup",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"name",
"string",
",",
"rules",
"[",
"]",
"nova",
".",
"RuleInfo",
")",
"(",
"nova",
".",
"SecurityGroup",
",",
"error",
")",
"{",
"novaClient",
":=",
"c",
".",
"environ",
".",
"nova",
"(",
")",
"\n",
"// First attempt to look up an existing group by name.",
"group",
",",
"err",
":=",
"novaClient",
".",
"SecurityGroupByName",
"(",
"name",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"// Group exists, so assume it is correctly set up and return it.",
"// TODO(jam): 2013-09-18 http://pad.lv/121795",
"// We really should verify the group is set up correctly,",
"// because deleting and re-creating environments can get us bad",
"// groups (especially if they were set up under Python)",
"return",
"*",
"group",
",",
"nil",
"\n",
"}",
"\n",
"// Doesn't exist, so try and create it.",
"group",
",",
"err",
"=",
"novaClient",
".",
"CreateSecurityGroup",
"(",
"name",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"gooseerrors",
".",
"IsDuplicateValue",
"(",
"err",
")",
"{",
"return",
"legacyZeroGroup",
",",
"err",
"\n",
"}",
"else",
"{",
"// We just tried to create a duplicate group, so load the existing group.",
"group",
",",
"err",
"=",
"novaClient",
".",
"SecurityGroupByName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"return",
"legacyZeroGroup",
",",
"err",
"\n",
"}",
"\n",
"return",
"*",
"group",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"// The new group is created so now add the rules.",
"group",
".",
"Rules",
"=",
"make",
"(",
"[",
"]",
"nova",
".",
"SecurityGroupRule",
",",
"len",
"(",
"rules",
")",
")",
"\n",
"for",
"i",
",",
"rule",
":=",
"range",
"rules",
"{",
"rule",
".",
"ParentGroupId",
"=",
"group",
".",
"Id",
"\n",
"if",
"rule",
".",
"Cidr",
"==",
"\"",
"\"",
"{",
"// http://pad.lv/1226996 Rules that don't have a CIDR",
"// are meant to apply only to this group. If you don't",
"// supply CIDR or GroupId then openstack assumes you",
"// mean CIDR=0.0.0.0/0",
"rule",
".",
"GroupId",
"=",
"&",
"group",
".",
"Id",
"\n",
"}",
"\n",
"groupRule",
",",
"err",
":=",
"novaClient",
".",
"CreateSecurityGroupRule",
"(",
"rule",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"gooseerrors",
".",
"IsDuplicateValue",
"(",
"err",
")",
"{",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"return",
"legacyZeroGroup",
",",
"err",
"\n",
"}",
"\n",
"group",
".",
"Rules",
"[",
"i",
"]",
"=",
"*",
"groupRule",
"\n",
"}",
"\n",
"return",
"*",
"group",
",",
"nil",
"\n",
"}"
] | // ensureGroup returns the security group with name and perms.
// If a group with name does not exist, one will be created.
// If it exists, its permissions are set to perms. | [
"ensureGroup",
"returns",
"the",
"security",
"group",
"with",
"name",
"and",
"perms",
".",
"If",
"a",
"group",
"with",
"name",
"does",
"not",
"exist",
"one",
"will",
"be",
"created",
".",
"If",
"it",
"exists",
"its",
"permissions",
"are",
"set",
"to",
"perms",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/legacy_firewaller.go#L96-L143 |
3,828 | juju/juju | provider/openstack/legacy_firewaller.go | DeleteAllModelGroups | func (c *legacyNovaFirewaller) DeleteAllModelGroups(ctx context.ProviderCallContext) error {
return deleteSecurityGroupsMatchingName(ctx, c.deleteSecurityGroups, c.jujuGroupRegexp())
} | go | func (c *legacyNovaFirewaller) DeleteAllModelGroups(ctx context.ProviderCallContext) error {
return deleteSecurityGroupsMatchingName(ctx, c.deleteSecurityGroups, c.jujuGroupRegexp())
} | [
"func",
"(",
"c",
"*",
"legacyNovaFirewaller",
")",
"DeleteAllModelGroups",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"error",
"{",
"return",
"deleteSecurityGroupsMatchingName",
"(",
"ctx",
",",
"c",
".",
"deleteSecurityGroups",
",",
"c",
".",
"jujuGroupRegexp",
"(",
")",
")",
"\n",
"}"
] | // DeleteAllModelGroups implements Firewaller interface. | [
"DeleteAllModelGroups",
"implements",
"Firewaller",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/legacy_firewaller.go#L171-L173 |
3,829 | juju/juju | provider/openstack/legacy_firewaller.go | DeleteGroups | func (c *legacyNovaFirewaller) DeleteGroups(ctx context.ProviderCallContext, names ...string) error {
return deleteSecurityGroupsOneOfNames(ctx, c.deleteSecurityGroups, names...)
} | go | func (c *legacyNovaFirewaller) DeleteGroups(ctx context.ProviderCallContext, names ...string) error {
return deleteSecurityGroupsOneOfNames(ctx, c.deleteSecurityGroups, names...)
} | [
"func",
"(",
"c",
"*",
"legacyNovaFirewaller",
")",
"DeleteGroups",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"names",
"...",
"string",
")",
"error",
"{",
"return",
"deleteSecurityGroupsOneOfNames",
"(",
"ctx",
",",
"c",
".",
"deleteSecurityGroups",
",",
"names",
"...",
")",
"\n",
"}"
] | // DeleteGroups implements Firewaller interface. | [
"DeleteGroups",
"implements",
"Firewaller",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/legacy_firewaller.go#L176-L178 |
3,830 | juju/juju | provider/openstack/legacy_firewaller.go | legacyRuleMatchesPortRange | func legacyRuleMatchesPortRange(rule nova.SecurityGroupRule, portRange network.IngressRule) bool {
if rule.IPProtocol == nil || rule.FromPort == nil || rule.ToPort == nil {
return false
}
return *rule.IPProtocol == portRange.Protocol &&
*rule.FromPort == portRange.FromPort &&
*rule.ToPort == portRange.ToPort
} | go | func legacyRuleMatchesPortRange(rule nova.SecurityGroupRule, portRange network.IngressRule) bool {
if rule.IPProtocol == nil || rule.FromPort == nil || rule.ToPort == nil {
return false
}
return *rule.IPProtocol == portRange.Protocol &&
*rule.FromPort == portRange.FromPort &&
*rule.ToPort == portRange.ToPort
} | [
"func",
"legacyRuleMatchesPortRange",
"(",
"rule",
"nova",
".",
"SecurityGroupRule",
",",
"portRange",
"network",
".",
"IngressRule",
")",
"bool",
"{",
"if",
"rule",
".",
"IPProtocol",
"==",
"nil",
"||",
"rule",
".",
"FromPort",
"==",
"nil",
"||",
"rule",
".",
"ToPort",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"*",
"rule",
".",
"IPProtocol",
"==",
"portRange",
".",
"Protocol",
"&&",
"*",
"rule",
".",
"FromPort",
"==",
"portRange",
".",
"FromPort",
"&&",
"*",
"rule",
".",
"ToPort",
"==",
"portRange",
".",
"ToPort",
"\n",
"}"
] | // ruleMatchesPortRange checks if supplied nova security group rule matches the port range | [
"ruleMatchesPortRange",
"checks",
"if",
"supplied",
"nova",
"security",
"group",
"rule",
"matches",
"the",
"port",
"range"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/legacy_firewaller.go#L310-L317 |
3,831 | juju/juju | apiserver/facades/client/backups/list.go | List | func (a *API) List(args params.BackupsListArgs) (params.BackupsListResult, error) {
var result params.BackupsListResult
backups, closer := newBackups(a.backend)
defer closer.Close()
metaList, err := backups.List()
if err != nil {
return result, errors.Trace(err)
}
result.List = make([]params.BackupsMetadataResult, len(metaList))
for i, meta := range metaList {
result.List[i] = CreateResult(meta, "")
}
return result, nil
} | go | func (a *API) List(args params.BackupsListArgs) (params.BackupsListResult, error) {
var result params.BackupsListResult
backups, closer := newBackups(a.backend)
defer closer.Close()
metaList, err := backups.List()
if err != nil {
return result, errors.Trace(err)
}
result.List = make([]params.BackupsMetadataResult, len(metaList))
for i, meta := range metaList {
result.List[i] = CreateResult(meta, "")
}
return result, nil
} | [
"func",
"(",
"a",
"*",
"API",
")",
"List",
"(",
"args",
"params",
".",
"BackupsListArgs",
")",
"(",
"params",
".",
"BackupsListResult",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"BackupsListResult",
"\n\n",
"backups",
",",
"closer",
":=",
"newBackups",
"(",
"a",
".",
"backend",
")",
"\n",
"defer",
"closer",
".",
"Close",
"(",
")",
"\n\n",
"metaList",
",",
"err",
":=",
"backups",
".",
"List",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"result",
".",
"List",
"=",
"make",
"(",
"[",
"]",
"params",
".",
"BackupsMetadataResult",
",",
"len",
"(",
"metaList",
")",
")",
"\n",
"for",
"i",
",",
"meta",
":=",
"range",
"metaList",
"{",
"result",
".",
"List",
"[",
"i",
"]",
"=",
"CreateResult",
"(",
"meta",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // List provides the implementation of the API method. | [
"List",
"provides",
"the",
"implementation",
"of",
"the",
"API",
"method",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/list.go#L13-L30 |
3,832 | juju/juju | api/keyupdater/authorisedkeys.go | AuthorisedKeys | func (st *State) AuthorisedKeys(tag names.MachineTag) ([]string, error) {
var results params.StringsResults
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
err := st.facade.FacadeCall("AuthorisedKeys", args, &results)
if err != nil {
// TODO: Not directly tested
return nil, err
}
if len(results.Results) != 1 {
// TODO: Not directly tested
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if err := result.Error; err != nil {
return nil, err
}
return result.Result, nil
} | go | func (st *State) AuthorisedKeys(tag names.MachineTag) ([]string, error) {
var results params.StringsResults
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
err := st.facade.FacadeCall("AuthorisedKeys", args, &results)
if err != nil {
// TODO: Not directly tested
return nil, err
}
if len(results.Results) != 1 {
// TODO: Not directly tested
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if err := result.Error; err != nil {
return nil, err
}
return result.Result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AuthorisedKeys",
"(",
"tag",
"names",
".",
"MachineTag",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StringsResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"tag",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO: Not directly tested",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"// TODO: Not directly tested",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"err",
":=",
"result",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // AuthorisedKeys returns the authorised ssh keys for the machine specified by machineTag. | [
"AuthorisedKeys",
"returns",
"the",
"authorised",
"ssh",
"keys",
"for",
"the",
"machine",
"specified",
"by",
"machineTag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/keyupdater/authorisedkeys.go#L27-L46 |
3,833 | juju/juju | api/keyupdater/authorisedkeys.go | WatchAuthorisedKeys | func (st *State) WatchAuthorisedKeys(tag names.MachineTag) (watcher.NotifyWatcher, error) {
var results params.NotifyWatchResults
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
err := st.facade.FacadeCall("WatchAuthorisedKeys", args, &results)
if err != nil {
// TODO: Not directly tested
return nil, err
}
if len(results.Results) != 1 {
// TODO: Not directly tested
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
// TODO: Not directly tested
return nil, result.Error
}
w := apiwatcher.NewNotifyWatcher(st.facade.RawAPICaller(), result)
return w, nil
} | go | func (st *State) WatchAuthorisedKeys(tag names.MachineTag) (watcher.NotifyWatcher, error) {
var results params.NotifyWatchResults
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
err := st.facade.FacadeCall("WatchAuthorisedKeys", args, &results)
if err != nil {
// TODO: Not directly tested
return nil, err
}
if len(results.Results) != 1 {
// TODO: Not directly tested
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
// TODO: Not directly tested
return nil, result.Error
}
w := apiwatcher.NewNotifyWatcher(st.facade.RawAPICaller(), result)
return w, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"WatchAuthorisedKeys",
"(",
"tag",
"names",
".",
"MachineTag",
")",
"(",
"watcher",
".",
"NotifyWatcher",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"NotifyWatchResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"tag",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO: Not directly tested",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"// TODO: Not directly tested",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"// TODO: Not directly tested",
"return",
"nil",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"w",
":=",
"apiwatcher",
".",
"NewNotifyWatcher",
"(",
"st",
".",
"facade",
".",
"RawAPICaller",
"(",
")",
",",
"result",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // WatchAuthorisedKeys returns a notify watcher that looks for changes in the
// authorised ssh keys for the machine specified by machineTag. | [
"WatchAuthorisedKeys",
"returns",
"a",
"notify",
"watcher",
"that",
"looks",
"for",
"changes",
"in",
"the",
"authorised",
"ssh",
"keys",
"for",
"the",
"machine",
"specified",
"by",
"machineTag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/keyupdater/authorisedkeys.go#L50-L71 |
3,834 | juju/juju | state/policy.go | precheckInstance | func (st *State) precheckInstance(
series string,
cons constraints.Value,
placement string,
volumeAttachments []storage.VolumeAttachmentParams,
) error {
if st.policy == nil {
return nil
}
prechecker, err := st.policy.Prechecker()
if errors.IsNotImplemented(err) {
return nil
} else if err != nil {
return err
}
if prechecker == nil {
return errors.New("policy returned nil prechecker without an error")
}
return prechecker.PrecheckInstance(
CallContext(st),
environs.PrecheckInstanceParams{
Series: series,
Constraints: cons,
Placement: placement,
VolumeAttachments: volumeAttachments,
})
} | go | func (st *State) precheckInstance(
series string,
cons constraints.Value,
placement string,
volumeAttachments []storage.VolumeAttachmentParams,
) error {
if st.policy == nil {
return nil
}
prechecker, err := st.policy.Prechecker()
if errors.IsNotImplemented(err) {
return nil
} else if err != nil {
return err
}
if prechecker == nil {
return errors.New("policy returned nil prechecker without an error")
}
return prechecker.PrecheckInstance(
CallContext(st),
environs.PrecheckInstanceParams{
Series: series,
Constraints: cons,
Placement: placement,
VolumeAttachments: volumeAttachments,
})
} | [
"func",
"(",
"st",
"*",
"State",
")",
"precheckInstance",
"(",
"series",
"string",
",",
"cons",
"constraints",
".",
"Value",
",",
"placement",
"string",
",",
"volumeAttachments",
"[",
"]",
"storage",
".",
"VolumeAttachmentParams",
",",
")",
"error",
"{",
"if",
"st",
".",
"policy",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"prechecker",
",",
"err",
":=",
"st",
".",
"policy",
".",
"Prechecker",
"(",
")",
"\n",
"if",
"errors",
".",
"IsNotImplemented",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"prechecker",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"prechecker",
".",
"PrecheckInstance",
"(",
"CallContext",
"(",
"st",
")",
",",
"environs",
".",
"PrecheckInstanceParams",
"{",
"Series",
":",
"series",
",",
"Constraints",
":",
"cons",
",",
"Placement",
":",
"placement",
",",
"VolumeAttachments",
":",
"volumeAttachments",
",",
"}",
")",
"\n",
"}"
] | // precheckInstance calls the state's assigned policy, if non-nil, to obtain
// a Prechecker, and calls PrecheckInstance if a non-nil Prechecker is returned. | [
"precheckInstance",
"calls",
"the",
"state",
"s",
"assigned",
"policy",
"if",
"non",
"-",
"nil",
"to",
"obtain",
"a",
"Prechecker",
"and",
"calls",
"PrecheckInstance",
"if",
"a",
"non",
"-",
"nil",
"Prechecker",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/policy.go#L53-L79 |
3,835 | juju/juju | state/policy.go | ResolveConstraints | func (st *State) ResolveConstraints(cons constraints.Value) (constraints.Value, error) {
validator, err := st.constraintsValidator()
if err != nil {
return constraints.Value{}, err
}
modelCons, err := st.ModelConstraints()
if err != nil {
return constraints.Value{}, err
}
return validator.Merge(modelCons, cons)
} | go | func (st *State) ResolveConstraints(cons constraints.Value) (constraints.Value, error) {
validator, err := st.constraintsValidator()
if err != nil {
return constraints.Value{}, err
}
modelCons, err := st.ModelConstraints()
if err != nil {
return constraints.Value{}, err
}
return validator.Merge(modelCons, cons)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ResolveConstraints",
"(",
"cons",
"constraints",
".",
"Value",
")",
"(",
"constraints",
".",
"Value",
",",
"error",
")",
"{",
"validator",
",",
"err",
":=",
"st",
".",
"constraintsValidator",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"constraints",
".",
"Value",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"modelCons",
",",
"err",
":=",
"st",
".",
"ModelConstraints",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"constraints",
".",
"Value",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"validator",
".",
"Merge",
"(",
"modelCons",
",",
"cons",
")",
"\n",
"}"
] | // ResolveConstraints combines the given constraints with the environ constraints to get
// a constraints which will be used to create a new instance. | [
"ResolveConstraints",
"combines",
"the",
"given",
"constraints",
"with",
"the",
"environ",
"constraints",
"to",
"get",
"a",
"constraints",
"which",
"will",
"be",
"used",
"to",
"create",
"a",
"new",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/policy.go#L133-L143 |
3,836 | juju/juju | state/policy.go | validateConstraints | func (st *State) validateConstraints(cons constraints.Value) ([]string, error) {
validator, err := st.constraintsValidator()
if err != nil {
return nil, err
}
return validator.Validate(cons)
} | go | func (st *State) validateConstraints(cons constraints.Value) ([]string, error) {
validator, err := st.constraintsValidator()
if err != nil {
return nil, err
}
return validator.Validate(cons)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"validateConstraints",
"(",
"cons",
"constraints",
".",
"Value",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"validator",
",",
"err",
":=",
"st",
".",
"constraintsValidator",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"validator",
".",
"Validate",
"(",
"cons",
")",
"\n",
"}"
] | // validateConstraints returns an error if the given constraints are not valid for the
// current model, and also any unsupported attributes. | [
"validateConstraints",
"returns",
"an",
"error",
"if",
"the",
"given",
"constraints",
"are",
"not",
"valid",
"for",
"the",
"current",
"model",
"and",
"also",
"any",
"unsupported",
"attributes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/policy.go#L147-L153 |
3,837 | juju/juju | state/policy.go | validate | func (st *State) validate(cfg, old *config.Config) (valid *config.Config, err error) {
if st.policy == nil {
return cfg, nil
}
configValidator, err := st.policy.ConfigValidator()
if errors.IsNotImplemented(err) {
return cfg, nil
} else if err != nil {
return nil, err
}
if configValidator == nil {
return nil, errors.New("policy returned nil configValidator without an error")
}
return configValidator.Validate(cfg, old)
} | go | func (st *State) validate(cfg, old *config.Config) (valid *config.Config, err error) {
if st.policy == nil {
return cfg, nil
}
configValidator, err := st.policy.ConfigValidator()
if errors.IsNotImplemented(err) {
return cfg, nil
} else if err != nil {
return nil, err
}
if configValidator == nil {
return nil, errors.New("policy returned nil configValidator without an error")
}
return configValidator.Validate(cfg, old)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"validate",
"(",
"cfg",
",",
"old",
"*",
"config",
".",
"Config",
")",
"(",
"valid",
"*",
"config",
".",
"Config",
",",
"err",
"error",
")",
"{",
"if",
"st",
".",
"policy",
"==",
"nil",
"{",
"return",
"cfg",
",",
"nil",
"\n",
"}",
"\n",
"configValidator",
",",
"err",
":=",
"st",
".",
"policy",
".",
"ConfigValidator",
"(",
")",
"\n",
"if",
"errors",
".",
"IsNotImplemented",
"(",
"err",
")",
"{",
"return",
"cfg",
",",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"configValidator",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"configValidator",
".",
"Validate",
"(",
"cfg",
",",
"old",
")",
"\n",
"}"
] | // validate calls the state's assigned policy, if non-nil, to obtain
// a config.Validator, and calls Validate if a non-nil config.Validator is
// returned. | [
"validate",
"calls",
"the",
"state",
"s",
"assigned",
"policy",
"if",
"non",
"-",
"nil",
"to",
"obtain",
"a",
"config",
".",
"Validator",
"and",
"calls",
"Validate",
"if",
"a",
"non",
"-",
"nil",
"config",
".",
"Validator",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/policy.go#L158-L172 |
3,838 | juju/juju | core/cache/machine.go | Id | func (m *Machine) Id() string {
m.mu.Lock()
defer m.mu.Unlock()
return m.details.Id
} | go | func (m *Machine) Id() string {
m.mu.Lock()
defer m.mu.Unlock()
return m.details.Id
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Id",
"(",
")",
"string",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"details",
".",
"Id",
"\n",
"}"
] | // Id returns the id string of this machine. | [
"Id",
"returns",
"the",
"id",
"string",
"of",
"this",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/machine.go#L44-L48 |
3,839 | juju/juju | core/cache/machine.go | InstanceId | func (m *Machine) InstanceId() (instance.Id, error) {
m.mu.Lock()
defer m.mu.Unlock()
if m.details.InstanceId == "" {
return "", errors.NotProvisionedf("machine %v", m.details.Id)
}
return instance.Id(m.details.InstanceId), nil
} | go | func (m *Machine) InstanceId() (instance.Id, error) {
m.mu.Lock()
defer m.mu.Unlock()
if m.details.InstanceId == "" {
return "", errors.NotProvisionedf("machine %v", m.details.Id)
}
return instance.Id(m.details.InstanceId), nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"InstanceId",
"(",
")",
"(",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"m",
".",
"details",
".",
"InstanceId",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"NotProvisionedf",
"(",
"\"",
"\"",
",",
"m",
".",
"details",
".",
"Id",
")",
"\n",
"}",
"\n",
"return",
"instance",
".",
"Id",
"(",
"m",
".",
"details",
".",
"InstanceId",
")",
",",
"nil",
"\n",
"}"
] | // InstanceId returns the provider specific instance id for this machine and
// returns not provisioned if instance id is empty | [
"InstanceId",
"returns",
"the",
"provider",
"specific",
"instance",
"id",
"for",
"this",
"machine",
"and",
"returns",
"not",
"provisioned",
"if",
"instance",
"id",
"is",
"empty"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/machine.go#L52-L60 |
3,840 | juju/juju | core/cache/machine.go | CharmProfiles | func (m *Machine) CharmProfiles() []string {
m.mu.Lock()
defer m.mu.Unlock()
return m.details.CharmProfiles
} | go | func (m *Machine) CharmProfiles() []string {
m.mu.Lock()
defer m.mu.Unlock()
return m.details.CharmProfiles
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"CharmProfiles",
"(",
")",
"[",
"]",
"string",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"details",
".",
"CharmProfiles",
"\n",
"}"
] | // CharmProfiles returns the cached list of charm profiles for the machine | [
"CharmProfiles",
"returns",
"the",
"cached",
"list",
"of",
"charm",
"profiles",
"for",
"the",
"machine"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/machine.go#L63-L67 |
3,841 | juju/juju | core/cache/machine.go | Units | func (m *Machine) Units() ([]*Unit, error) {
m.mu.Lock()
defer m.mu.Unlock()
result := make([]*Unit, 0)
for unitName, unit := range m.model.units {
if unit.details.MachineId == m.details.Id {
result = append(result, unit)
}
if unit.details.Subordinate {
principalUnit, found := m.model.units[unit.details.Principal]
if !found {
return result, errors.NotFoundf("principal unit %q for subordinate %s", unit.details.Principal, unitName)
}
if principalUnit.details.MachineId == m.details.Id {
result = append(result, unit)
}
}
}
return result, nil
} | go | func (m *Machine) Units() ([]*Unit, error) {
m.mu.Lock()
defer m.mu.Unlock()
result := make([]*Unit, 0)
for unitName, unit := range m.model.units {
if unit.details.MachineId == m.details.Id {
result = append(result, unit)
}
if unit.details.Subordinate {
principalUnit, found := m.model.units[unit.details.Principal]
if !found {
return result, errors.NotFoundf("principal unit %q for subordinate %s", unit.details.Principal, unitName)
}
if principalUnit.details.MachineId == m.details.Id {
result = append(result, unit)
}
}
}
return result, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Units",
"(",
")",
"(",
"[",
"]",
"*",
"Unit",
",",
"error",
")",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"result",
":=",
"make",
"(",
"[",
"]",
"*",
"Unit",
",",
"0",
")",
"\n",
"for",
"unitName",
",",
"unit",
":=",
"range",
"m",
".",
"model",
".",
"units",
"{",
"if",
"unit",
".",
"details",
".",
"MachineId",
"==",
"m",
".",
"details",
".",
"Id",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"unit",
")",
"\n",
"}",
"\n",
"if",
"unit",
".",
"details",
".",
"Subordinate",
"{",
"principalUnit",
",",
"found",
":=",
"m",
".",
"model",
".",
"units",
"[",
"unit",
".",
"details",
".",
"Principal",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"result",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"unit",
".",
"details",
".",
"Principal",
",",
"unitName",
")",
"\n",
"}",
"\n",
"if",
"principalUnit",
".",
"details",
".",
"MachineId",
"==",
"m",
".",
"details",
".",
"Id",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"unit",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Units returns all the units that have been assigned to the machine
// including subordinates. | [
"Units",
"returns",
"all",
"the",
"units",
"that",
"have",
"been",
"assigned",
"to",
"the",
"machine",
"including",
"subordinates",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/cache/machine.go#L71-L91 |
3,842 | juju/juju | provider/azure/instancetype.go | newInstanceType | func newInstanceType(size compute.VirtualMachineSize) instances.InstanceType {
// We're not doing real costs for now; just made-up, relative
// costs, to ensure we choose the right VMs given matching
// constraints. This was based on the pricing for West US,
// and assumes that all regions have the same relative costs.
//
// DS is the same price as D, but is targeted at Premium Storage.
// Likewise for GS and G. We put the premium storage variants
// directly after their non-premium counterparts.
machineSizeCost := []string{
"Standard_A0",
"Standard_A1",
"Standard_D1",
"Standard_DS1",
"Standard_D1_v2",
"Standard_A2",
"Standard_D2",
"Standard_DS2",
"Standard_D2_v2",
"Standard_D11",
"Standard_DS11",
"Standard_D11_v2",
"Standard_A3",
"Standard_D3",
"Standard_DS3",
"Standard_D3_v2",
"Standard_D12",
"Standard_DS12",
"Standard_D12_v2",
"Standard_A5", // Yes, A5 is cheaper than A4.
"Standard_A4",
"Standard_A6",
"Standard_G1",
"Standard_GS1",
"Standard_D4",
"Standard_DS4",
"Standard_D4_v2",
"Standard_D13",
"Standard_DS13",
"Standard_D13_v2",
"Standard_A7",
"Standard_A10",
"Standard_G2",
"Standard_GS2",
"Standard_D5_v2",
"Standard_D14",
"Standard_DS14",
"Standard_D14_v2",
"Standard_A8",
"Standard_A11",
"Standard_G3",
"Standard_GS3",
"Standard_A9",
"Standard_G4",
"Standard_GS4",
"Standard_GS5",
"Standard_G5",
// Basic instances are less capable than standard
// ones, so we don't want to be providing them as
// a default. This is achieved by costing them at
// a higher price, even though they are cheaper
// in reality.
"Basic_A0",
"Basic_A1",
"Basic_A2",
"Basic_A3",
"Basic_A4",
}
// Anything not in the list is more expensive that is in the list.
cost := len(machineSizeCost)
sizeName := to.String(size.Name)
for i, name := range machineSizeCost {
if sizeName == name {
cost = i
break
}
}
if cost == len(machineSizeCost) {
logger.Debugf("found unknown VM size %q", sizeName)
}
vtype := "Hyper-V"
return instances.InstanceType{
Id: sizeName,
Name: sizeName,
Arches: []string{arch.AMD64},
CpuCores: uint64(to.Int32(size.NumberOfCores)),
Mem: uint64(to.Int32(size.MemoryInMB)),
// NOTE(axw) size.OsDiskSizeInMB is the *maximum*
// OS-disk size. When we create a VM, we can create
// one that is smaller.
RootDisk: mbToMib(uint64(to.Int32(size.OsDiskSizeInMB))),
Cost: uint64(cost),
VirtType: &vtype,
// tags are not currently supported by azure
}
} | go | func newInstanceType(size compute.VirtualMachineSize) instances.InstanceType {
// We're not doing real costs for now; just made-up, relative
// costs, to ensure we choose the right VMs given matching
// constraints. This was based on the pricing for West US,
// and assumes that all regions have the same relative costs.
//
// DS is the same price as D, but is targeted at Premium Storage.
// Likewise for GS and G. We put the premium storage variants
// directly after their non-premium counterparts.
machineSizeCost := []string{
"Standard_A0",
"Standard_A1",
"Standard_D1",
"Standard_DS1",
"Standard_D1_v2",
"Standard_A2",
"Standard_D2",
"Standard_DS2",
"Standard_D2_v2",
"Standard_D11",
"Standard_DS11",
"Standard_D11_v2",
"Standard_A3",
"Standard_D3",
"Standard_DS3",
"Standard_D3_v2",
"Standard_D12",
"Standard_DS12",
"Standard_D12_v2",
"Standard_A5", // Yes, A5 is cheaper than A4.
"Standard_A4",
"Standard_A6",
"Standard_G1",
"Standard_GS1",
"Standard_D4",
"Standard_DS4",
"Standard_D4_v2",
"Standard_D13",
"Standard_DS13",
"Standard_D13_v2",
"Standard_A7",
"Standard_A10",
"Standard_G2",
"Standard_GS2",
"Standard_D5_v2",
"Standard_D14",
"Standard_DS14",
"Standard_D14_v2",
"Standard_A8",
"Standard_A11",
"Standard_G3",
"Standard_GS3",
"Standard_A9",
"Standard_G4",
"Standard_GS4",
"Standard_GS5",
"Standard_G5",
// Basic instances are less capable than standard
// ones, so we don't want to be providing them as
// a default. This is achieved by costing them at
// a higher price, even though they are cheaper
// in reality.
"Basic_A0",
"Basic_A1",
"Basic_A2",
"Basic_A3",
"Basic_A4",
}
// Anything not in the list is more expensive that is in the list.
cost := len(machineSizeCost)
sizeName := to.String(size.Name)
for i, name := range machineSizeCost {
if sizeName == name {
cost = i
break
}
}
if cost == len(machineSizeCost) {
logger.Debugf("found unknown VM size %q", sizeName)
}
vtype := "Hyper-V"
return instances.InstanceType{
Id: sizeName,
Name: sizeName,
Arches: []string{arch.AMD64},
CpuCores: uint64(to.Int32(size.NumberOfCores)),
Mem: uint64(to.Int32(size.MemoryInMB)),
// NOTE(axw) size.OsDiskSizeInMB is the *maximum*
// OS-disk size. When we create a VM, we can create
// one that is smaller.
RootDisk: mbToMib(uint64(to.Int32(size.OsDiskSizeInMB))),
Cost: uint64(cost),
VirtType: &vtype,
// tags are not currently supported by azure
}
} | [
"func",
"newInstanceType",
"(",
"size",
"compute",
".",
"VirtualMachineSize",
")",
"instances",
".",
"InstanceType",
"{",
"// We're not doing real costs for now; just made-up, relative",
"// costs, to ensure we choose the right VMs given matching",
"// constraints. This was based on the pricing for West US,",
"// and assumes that all regions have the same relative costs.",
"//",
"// DS is the same price as D, but is targeted at Premium Storage.",
"// Likewise for GS and G. We put the premium storage variants",
"// directly after their non-premium counterparts.",
"machineSizeCost",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"// Yes, A5 is cheaper than A4.",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"// Basic instances are less capable than standard",
"// ones, so we don't want to be providing them as",
"// a default. This is achieved by costing them at",
"// a higher price, even though they are cheaper",
"// in reality.",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"}",
"\n\n",
"// Anything not in the list is more expensive that is in the list.",
"cost",
":=",
"len",
"(",
"machineSizeCost",
")",
"\n",
"sizeName",
":=",
"to",
".",
"String",
"(",
"size",
".",
"Name",
")",
"\n",
"for",
"i",
",",
"name",
":=",
"range",
"machineSizeCost",
"{",
"if",
"sizeName",
"==",
"name",
"{",
"cost",
"=",
"i",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cost",
"==",
"len",
"(",
"machineSizeCost",
")",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"sizeName",
")",
"\n",
"}",
"\n\n",
"vtype",
":=",
"\"",
"\"",
"\n",
"return",
"instances",
".",
"InstanceType",
"{",
"Id",
":",
"sizeName",
",",
"Name",
":",
"sizeName",
",",
"Arches",
":",
"[",
"]",
"string",
"{",
"arch",
".",
"AMD64",
"}",
",",
"CpuCores",
":",
"uint64",
"(",
"to",
".",
"Int32",
"(",
"size",
".",
"NumberOfCores",
")",
")",
",",
"Mem",
":",
"uint64",
"(",
"to",
".",
"Int32",
"(",
"size",
".",
"MemoryInMB",
")",
")",
",",
"// NOTE(axw) size.OsDiskSizeInMB is the *maximum*",
"// OS-disk size. When we create a VM, we can create",
"// one that is smaller.",
"RootDisk",
":",
"mbToMib",
"(",
"uint64",
"(",
"to",
".",
"Int32",
"(",
"size",
".",
"OsDiskSizeInMB",
")",
")",
")",
",",
"Cost",
":",
"uint64",
"(",
"cost",
")",
",",
"VirtType",
":",
"&",
"vtype",
",",
"// tags are not currently supported by azure",
"}",
"\n",
"}"
] | // newInstanceType creates an InstanceType based on a VirtualMachineSize. | [
"newInstanceType",
"creates",
"an",
"InstanceType",
"based",
"on",
"a",
"VirtualMachineSize",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/instancetype.go#L21-L119 |
3,843 | juju/juju | provider/azure/instancetype.go | defaultToBaselineSpec | func defaultToBaselineSpec(constraint constraints.Value) constraints.Value {
result := constraint
if !result.HasInstanceType() && result.Mem == nil {
var value uint64 = defaultMem
result.Mem = &value
}
return result
} | go | func defaultToBaselineSpec(constraint constraints.Value) constraints.Value {
result := constraint
if !result.HasInstanceType() && result.Mem == nil {
var value uint64 = defaultMem
result.Mem = &value
}
return result
} | [
"func",
"defaultToBaselineSpec",
"(",
"constraint",
"constraints",
".",
"Value",
")",
"constraints",
".",
"Value",
"{",
"result",
":=",
"constraint",
"\n",
"if",
"!",
"result",
".",
"HasInstanceType",
"(",
")",
"&&",
"result",
".",
"Mem",
"==",
"nil",
"{",
"var",
"value",
"uint64",
"=",
"defaultMem",
"\n",
"result",
".",
"Mem",
"=",
"&",
"value",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // If you specify no constraints at all, you're going to get the smallest
// instance type available. In practice that one's a bit small, so unless
// the constraints are deliberately set lower, this gives you a set of
// baseline constraints that are just slightly more ambitious than that. | [
"If",
"you",
"specify",
"no",
"constraints",
"at",
"all",
"you",
"re",
"going",
"to",
"get",
"the",
"smallest",
"instance",
"type",
"available",
".",
"In",
"practice",
"that",
"one",
"s",
"a",
"bit",
"small",
"so",
"unless",
"the",
"constraints",
"are",
"deliberately",
"set",
"lower",
"this",
"gives",
"you",
"a",
"set",
"of",
"baseline",
"constraints",
"that",
"are",
"just",
"slightly",
"more",
"ambitious",
"than",
"that",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/instancetype.go#L171-L178 |
3,844 | juju/juju | worker/firewaller/shim.go | NewFirewallerFacade | func NewFirewallerFacade(apiCaller base.APICaller) (FirewallerAPI, error) {
facade, err := firewaller.NewClient(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
return facade, nil
} | go | func NewFirewallerFacade(apiCaller base.APICaller) (FirewallerAPI, error) {
facade, err := firewaller.NewClient(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
return facade, nil
} | [
"func",
"NewFirewallerFacade",
"(",
"apiCaller",
"base",
".",
"APICaller",
")",
"(",
"FirewallerAPI",
",",
"error",
")",
"{",
"facade",
",",
"err",
":=",
"firewaller",
".",
"NewClient",
"(",
"apiCaller",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"facade",
",",
"nil",
"\n",
"}"
] | // NewFirewallerFacade creates a firewaller API facade. | [
"NewFirewallerFacade",
"creates",
"a",
"firewaller",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/firewaller/shim.go#L28-L34 |
3,845 | juju/juju | worker/firewaller/shim.go | NewWorker | func NewWorker(cfg Config) (worker.Worker, error) {
w, err := NewFirewaller(cfg)
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
} | go | func NewWorker(cfg Config) (worker.Worker, error) {
w, err := NewFirewaller(cfg)
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
} | [
"func",
"NewWorker",
"(",
"cfg",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"w",
",",
"err",
":=",
"NewFirewaller",
"(",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // NewWorker creates a firewaller worker. | [
"NewWorker",
"creates",
"a",
"firewaller",
"worker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/firewaller/shim.go#L37-L43 |
3,846 | juju/juju | worker/firewaller/shim.go | crossmodelFirewallerFacadeFunc | func crossmodelFirewallerFacadeFunc(
connectionFunc apicaller.NewExternalControllerConnectionFunc,
) newCrossModelFacadeFunc {
return func(apiInfo *api.Info) (CrossModelFirewallerFacadeCloser, error) {
apiInfo.Tag = names.NewUserTag(api.AnonymousUsername)
conn, err := connectionFunc(apiInfo)
if err != nil {
return nil, errors.Trace(err)
}
facade := crossmodelrelations.NewClient(conn)
return &crossModelFirewallerFacadeCloser{facade, conn}, nil
}
} | go | func crossmodelFirewallerFacadeFunc(
connectionFunc apicaller.NewExternalControllerConnectionFunc,
) newCrossModelFacadeFunc {
return func(apiInfo *api.Info) (CrossModelFirewallerFacadeCloser, error) {
apiInfo.Tag = names.NewUserTag(api.AnonymousUsername)
conn, err := connectionFunc(apiInfo)
if err != nil {
return nil, errors.Trace(err)
}
facade := crossmodelrelations.NewClient(conn)
return &crossModelFirewallerFacadeCloser{facade, conn}, nil
}
} | [
"func",
"crossmodelFirewallerFacadeFunc",
"(",
"connectionFunc",
"apicaller",
".",
"NewExternalControllerConnectionFunc",
",",
")",
"newCrossModelFacadeFunc",
"{",
"return",
"func",
"(",
"apiInfo",
"*",
"api",
".",
"Info",
")",
"(",
"CrossModelFirewallerFacadeCloser",
",",
"error",
")",
"{",
"apiInfo",
".",
"Tag",
"=",
"names",
".",
"NewUserTag",
"(",
"api",
".",
"AnonymousUsername",
")",
"\n",
"conn",
",",
"err",
":=",
"connectionFunc",
"(",
"apiInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"facade",
":=",
"crossmodelrelations",
".",
"NewClient",
"(",
"conn",
")",
"\n",
"return",
"&",
"crossModelFirewallerFacadeCloser",
"{",
"facade",
",",
"conn",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // crossmodelFirewallerFacadeFunc returns a function that
// can be used to construct instances which manage remote relation
// firewall changes for a given model.
// For now we use a facade, but in future this may evolve into a REST caller. | [
"crossmodelFirewallerFacadeFunc",
"returns",
"a",
"function",
"that",
"can",
"be",
"used",
"to",
"construct",
"instances",
"which",
"manage",
"remote",
"relation",
"firewall",
"changes",
"for",
"a",
"given",
"model",
".",
"For",
"now",
"we",
"use",
"a",
"facade",
"but",
"in",
"future",
"this",
"may",
"evolve",
"into",
"a",
"REST",
"caller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/firewaller/shim.go#L50-L62 |
3,847 | juju/juju | worker/globalclockupdater/worker.go | NewWorker | func NewWorker(config Config) (worker.Worker, error) {
if err := config.Validate(); err != nil {
return nil, errors.Annotate(err, "validating config")
}
updater, err := config.NewUpdater()
if err != nil {
return nil, errors.Annotate(err, "getting new updater")
}
w := &updaterWorker{
config: config,
updater: updater,
}
w.tomb.Go(w.loop)
return w, nil
} | go | func NewWorker(config Config) (worker.Worker, error) {
if err := config.Validate(); err != nil {
return nil, errors.Annotate(err, "validating config")
}
updater, err := config.NewUpdater()
if err != nil {
return nil, errors.Annotate(err, "getting new updater")
}
w := &updaterWorker{
config: config,
updater: updater,
}
w.tomb.Go(w.loop)
return w, nil
} | [
"func",
"NewWorker",
"(",
"config",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"updater",
",",
"err",
":=",
"config",
".",
"NewUpdater",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
":=",
"&",
"updaterWorker",
"{",
"config",
":",
"config",
",",
"updater",
":",
"updater",
",",
"}",
"\n",
"w",
".",
"tomb",
".",
"Go",
"(",
"w",
".",
"loop",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // NewWorker returns a new global clock updater worker, using the given
// configuration. | [
"NewWorker",
"returns",
"a",
"new",
"global",
"clock",
"updater",
"worker",
"using",
"the",
"given",
"configuration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/globalclockupdater/worker.go#L65-L79 |
3,848 | juju/juju | api/uniter/relation.go | SetStatus | func (r *Relation) SetStatus(status relation.Status) error {
return r.st.setRelationStatus(r.id, status)
} | go | func (r *Relation) SetStatus(status relation.Status) error {
return r.st.setRelationStatus(r.id, status)
} | [
"func",
"(",
"r",
"*",
"Relation",
")",
"SetStatus",
"(",
"status",
"relation",
".",
"Status",
")",
"error",
"{",
"return",
"r",
".",
"st",
".",
"setRelationStatus",
"(",
"r",
".",
"id",
",",
"status",
")",
"\n",
"}"
] | // SetStatus updates the status of the relation. | [
"SetStatus",
"updates",
"the",
"status",
"of",
"the",
"relation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/relation.go#L89-L91 |
3,849 | juju/juju | api/uniter/relation.go | Endpoint | func (r *Relation) Endpoint() (*Endpoint, error) {
// NOTE: This differs from state.Relation.Endpoint(), because when
// talking to the API, there's already an authenticated entity - the
// unit, and we can find out its application name.
result, err := r.st.relation(r.tag, r.st.unitTag)
if err != nil {
return nil, err
}
return &Endpoint{r.toCharmRelation(result.Endpoint.Relation)}, nil
} | go | func (r *Relation) Endpoint() (*Endpoint, error) {
// NOTE: This differs from state.Relation.Endpoint(), because when
// talking to the API, there's already an authenticated entity - the
// unit, and we can find out its application name.
result, err := r.st.relation(r.tag, r.st.unitTag)
if err != nil {
return nil, err
}
return &Endpoint{r.toCharmRelation(result.Endpoint.Relation)}, nil
} | [
"func",
"(",
"r",
"*",
"Relation",
")",
"Endpoint",
"(",
")",
"(",
"*",
"Endpoint",
",",
"error",
")",
"{",
"// NOTE: This differs from state.Relation.Endpoint(), because when",
"// talking to the API, there's already an authenticated entity - the",
"// unit, and we can find out its application name.",
"result",
",",
"err",
":=",
"r",
".",
"st",
".",
"relation",
"(",
"r",
".",
"tag",
",",
"r",
".",
"st",
".",
"unitTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Endpoint",
"{",
"r",
".",
"toCharmRelation",
"(",
"result",
".",
"Endpoint",
".",
"Relation",
")",
"}",
",",
"nil",
"\n",
"}"
] | // Endpoint returns the endpoint of the relation for the application the
// uniter's managed unit belongs to. | [
"Endpoint",
"returns",
"the",
"endpoint",
"of",
"the",
"relation",
"for",
"the",
"application",
"the",
"uniter",
"s",
"managed",
"unit",
"belongs",
"to",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/uniter/relation.go#L106-L115 |
3,850 | juju/juju | cmd/juju/resource/list.go | NewListCommand | func NewListCommand(deps ListDeps) modelcmd.ModelCommand {
return modelcmd.Wrap(&ListCommand{deps: deps})
} | go | func NewListCommand(deps ListDeps) modelcmd.ModelCommand {
return modelcmd.Wrap(&ListCommand{deps: deps})
} | [
"func",
"NewListCommand",
"(",
"deps",
"ListDeps",
")",
"modelcmd",
".",
"ModelCommand",
"{",
"return",
"modelcmd",
".",
"Wrap",
"(",
"&",
"ListCommand",
"{",
"deps",
":",
"deps",
"}",
")",
"\n",
"}"
] | // NewListCommand returns a new command that lists resources defined
// by a charm. | [
"NewListCommand",
"returns",
"a",
"new",
"command",
"that",
"lists",
"resources",
"defined",
"by",
"a",
"charm",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/resource/list.go#L46-L48 |
3,851 | juju/juju | apiserver/facades/agent/machine/machiner.go | NewMachinerAPI | func NewMachinerAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*MachinerAPI, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
getCanModify := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
getCanRead := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
return &MachinerAPI{
LifeGetter: common.NewLifeGetter(st, getCanRead),
StatusSetter: common.NewStatusSetter(st, getCanModify),
DeadEnsurer: common.NewDeadEnsurer(st, getCanModify),
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, getCanRead),
APIAddresser: common.NewAPIAddresser(st, resources),
NetworkConfigAPI: networkingcommon.NewNetworkConfigAPI(st, state.CallContext(st), getCanModify),
st: st,
auth: authorizer,
getCanModify: getCanModify,
getCanRead: getCanRead,
}, nil
} | go | func NewMachinerAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*MachinerAPI, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
getCanModify := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
getCanRead := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
return &MachinerAPI{
LifeGetter: common.NewLifeGetter(st, getCanRead),
StatusSetter: common.NewStatusSetter(st, getCanModify),
DeadEnsurer: common.NewDeadEnsurer(st, getCanModify),
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, getCanRead),
APIAddresser: common.NewAPIAddresser(st, resources),
NetworkConfigAPI: networkingcommon.NewNetworkConfigAPI(st, state.CallContext(st), getCanModify),
st: st,
auth: authorizer,
getCanModify: getCanModify,
getCanRead: getCanRead,
}, nil
} | [
"func",
"NewMachinerAPI",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"MachinerAPI",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthMachineAgent",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"getCanModify",
":=",
"func",
"(",
")",
"(",
"common",
".",
"AuthFunc",
",",
"error",
")",
"{",
"return",
"authorizer",
".",
"AuthOwner",
",",
"nil",
"\n",
"}",
"\n",
"getCanRead",
":=",
"func",
"(",
")",
"(",
"common",
".",
"AuthFunc",
",",
"error",
")",
"{",
"return",
"authorizer",
".",
"AuthOwner",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"MachinerAPI",
"{",
"LifeGetter",
":",
"common",
".",
"NewLifeGetter",
"(",
"st",
",",
"getCanRead",
")",
",",
"StatusSetter",
":",
"common",
".",
"NewStatusSetter",
"(",
"st",
",",
"getCanModify",
")",
",",
"DeadEnsurer",
":",
"common",
".",
"NewDeadEnsurer",
"(",
"st",
",",
"getCanModify",
")",
",",
"AgentEntityWatcher",
":",
"common",
".",
"NewAgentEntityWatcher",
"(",
"st",
",",
"resources",
",",
"getCanRead",
")",
",",
"APIAddresser",
":",
"common",
".",
"NewAPIAddresser",
"(",
"st",
",",
"resources",
")",
",",
"NetworkConfigAPI",
":",
"networkingcommon",
".",
"NewNetworkConfigAPI",
"(",
"st",
",",
"state",
".",
"CallContext",
"(",
"st",
")",
",",
"getCanModify",
")",
",",
"st",
":",
"st",
",",
"auth",
":",
"authorizer",
",",
"getCanModify",
":",
"getCanModify",
",",
"getCanRead",
":",
"getCanRead",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewMachinerAPI creates a new instance of the Machiner API. | [
"NewMachinerAPI",
"creates",
"a",
"new",
"instance",
"of",
"the",
"Machiner",
"API",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machine/machiner.go#L39-L61 |
3,852 | juju/juju | apiserver/facades/agent/machine/machiner.go | Jobs | func (api *MachinerAPI) Jobs(args params.Entities) (params.JobsResults, error) {
result := params.JobsResults{
Results: make([]params.JobsResult, len(args.Entities)),
}
canRead, err := api.getCanRead()
if err != nil {
return result, err
}
for i, agent := range args.Entities {
tag, err := names.ParseMachineTag(agent.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if !canRead(tag) {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := api.getMachine(tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
machineJobs := machine.Jobs()
jobs := make([]multiwatcher.MachineJob, len(machineJobs))
for i, job := range machineJobs {
jobs[i] = job.ToParams()
}
result.Results[i].Jobs = jobs
}
return result, nil
} | go | func (api *MachinerAPI) Jobs(args params.Entities) (params.JobsResults, error) {
result := params.JobsResults{
Results: make([]params.JobsResult, len(args.Entities)),
}
canRead, err := api.getCanRead()
if err != nil {
return result, err
}
for i, agent := range args.Entities {
tag, err := names.ParseMachineTag(agent.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if !canRead(tag) {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := api.getMachine(tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
machineJobs := machine.Jobs()
jobs := make([]multiwatcher.MachineJob, len(machineJobs))
for i, job := range machineJobs {
jobs[i] = job.ToParams()
}
result.Results[i].Jobs = jobs
}
return result, nil
} | [
"func",
"(",
"api",
"*",
"MachinerAPI",
")",
"Jobs",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"JobsResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"JobsResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"JobsResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n\n",
"canRead",
",",
"err",
":=",
"api",
".",
"getCanRead",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"agent",
":=",
"range",
"args",
".",
"Entities",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseMachineTag",
"(",
"agent",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"if",
"!",
"canRead",
"(",
"tag",
")",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"machine",
",",
"err",
":=",
"api",
".",
"getMachine",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"machineJobs",
":=",
"machine",
".",
"Jobs",
"(",
")",
"\n",
"jobs",
":=",
"make",
"(",
"[",
"]",
"multiwatcher",
".",
"MachineJob",
",",
"len",
"(",
"machineJobs",
")",
")",
"\n",
"for",
"i",
",",
"job",
":=",
"range",
"machineJobs",
"{",
"jobs",
"[",
"i",
"]",
"=",
"job",
".",
"ToParams",
"(",
")",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Jobs",
"=",
"jobs",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Jobs returns the jobs assigned to the given entities. | [
"Jobs",
"returns",
"the",
"jobs",
"assigned",
"to",
"the",
"given",
"entities",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/machine/machiner.go#L102-L137 |
3,853 | juju/juju | state/mongo.go | GetCollection | func (m *environMongo) GetCollection(name string) (mongo.Collection, func()) {
return m.state.db().GetCollection(name)
} | go | func (m *environMongo) GetCollection(name string) (mongo.Collection, func()) {
return m.state.db().GetCollection(name)
} | [
"func",
"(",
"m",
"*",
"environMongo",
")",
"GetCollection",
"(",
"name",
"string",
")",
"(",
"mongo",
".",
"Collection",
",",
"func",
"(",
")",
")",
"{",
"return",
"m",
".",
"state",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"name",
")",
"\n",
"}"
] | // GetCollection is part of the lease.Mongo interface. | [
"GetCollection",
"is",
"part",
"of",
"the",
"lease",
".",
"Mongo",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mongo.go#L23-L25 |
3,854 | juju/juju | state/mongo.go | RunTransaction | func (m *environMongo) RunTransaction(buildTxn jujutxn.TransactionSource) error {
return m.state.db().Run(buildTxn)
} | go | func (m *environMongo) RunTransaction(buildTxn jujutxn.TransactionSource) error {
return m.state.db().Run(buildTxn)
} | [
"func",
"(",
"m",
"*",
"environMongo",
")",
"RunTransaction",
"(",
"buildTxn",
"jujutxn",
".",
"TransactionSource",
")",
"error",
"{",
"return",
"m",
".",
"state",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // RunTransaction is part of the lease.Mongo interface. | [
"RunTransaction",
"is",
"part",
"of",
"the",
"lease",
".",
"Mongo",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mongo.go#L28-L30 |
3,855 | juju/juju | state/mongo.go | SetUpgradeMongoMode | func (st *State) SetUpgradeMongoMode(v mongo.Version) (UpgradeMongoParams, error) {
currentInfo, err := st.ControllerInfo()
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "could not obtain current controller information")
}
result := UpgradeMongoParams{}
machines := []*Machine{}
for _, mID := range currentInfo.MachineIds {
m, err := st.Machine(mID)
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot change all the replicas")
}
isMaster, err := mongo.IsMaster(st.session, m)
if err != nil {
return UpgradeMongoParams{}, errors.Annotatef(err, "cannot determine if machine %q is master", mID)
}
paddr, err := m.PublicAddress()
if err != nil {
return UpgradeMongoParams{}, errors.Annotatef(err, "cannot obtain public address for machine: %v", m)
}
tag := m.Tag()
mtag := tag.(names.MachineTag)
member := HAMember{
Tag: mtag.Id(),
PublicAddress: paddr,
Series: m.Series(),
}
if isMaster {
result.Master = member
} else {
result.Members = append(result.Members, member)
}
machines = append(machines, m)
}
rsMembers, err := replicaset.CurrentMembers(st.session)
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot obtain current replicaset members")
}
masterRs, err := replicaset.MasterHostPort(st.session)
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot determine master on replicaset members")
}
for _, m := range rsMembers {
if m.Address != masterRs {
result.RsMembers = append(result.RsMembers, m)
}
}
for _, m := range machines {
if err := m.SetStopMongoUntilVersion(v); err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot trigger replica shutdown")
}
}
return result, nil
} | go | func (st *State) SetUpgradeMongoMode(v mongo.Version) (UpgradeMongoParams, error) {
currentInfo, err := st.ControllerInfo()
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "could not obtain current controller information")
}
result := UpgradeMongoParams{}
machines := []*Machine{}
for _, mID := range currentInfo.MachineIds {
m, err := st.Machine(mID)
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot change all the replicas")
}
isMaster, err := mongo.IsMaster(st.session, m)
if err != nil {
return UpgradeMongoParams{}, errors.Annotatef(err, "cannot determine if machine %q is master", mID)
}
paddr, err := m.PublicAddress()
if err != nil {
return UpgradeMongoParams{}, errors.Annotatef(err, "cannot obtain public address for machine: %v", m)
}
tag := m.Tag()
mtag := tag.(names.MachineTag)
member := HAMember{
Tag: mtag.Id(),
PublicAddress: paddr,
Series: m.Series(),
}
if isMaster {
result.Master = member
} else {
result.Members = append(result.Members, member)
}
machines = append(machines, m)
}
rsMembers, err := replicaset.CurrentMembers(st.session)
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot obtain current replicaset members")
}
masterRs, err := replicaset.MasterHostPort(st.session)
if err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot determine master on replicaset members")
}
for _, m := range rsMembers {
if m.Address != masterRs {
result.RsMembers = append(result.RsMembers, m)
}
}
for _, m := range machines {
if err := m.SetStopMongoUntilVersion(v); err != nil {
return UpgradeMongoParams{}, errors.Annotate(err, "cannot trigger replica shutdown")
}
}
return result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SetUpgradeMongoMode",
"(",
"v",
"mongo",
".",
"Version",
")",
"(",
"UpgradeMongoParams",
",",
"error",
")",
"{",
"currentInfo",
",",
"err",
":=",
"st",
".",
"ControllerInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"result",
":=",
"UpgradeMongoParams",
"{",
"}",
"\n",
"machines",
":=",
"[",
"]",
"*",
"Machine",
"{",
"}",
"\n",
"for",
"_",
",",
"mID",
":=",
"range",
"currentInfo",
".",
"MachineIds",
"{",
"m",
",",
"err",
":=",
"st",
".",
"Machine",
"(",
"mID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"isMaster",
",",
"err",
":=",
"mongo",
".",
"IsMaster",
"(",
"st",
".",
"session",
",",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"mID",
")",
"\n",
"}",
"\n",
"paddr",
",",
"err",
":=",
"m",
".",
"PublicAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"tag",
":=",
"m",
".",
"Tag",
"(",
")",
"\n",
"mtag",
":=",
"tag",
".",
"(",
"names",
".",
"MachineTag",
")",
"\n",
"member",
":=",
"HAMember",
"{",
"Tag",
":",
"mtag",
".",
"Id",
"(",
")",
",",
"PublicAddress",
":",
"paddr",
",",
"Series",
":",
"m",
".",
"Series",
"(",
")",
",",
"}",
"\n",
"if",
"isMaster",
"{",
"result",
".",
"Master",
"=",
"member",
"\n",
"}",
"else",
"{",
"result",
".",
"Members",
"=",
"append",
"(",
"result",
".",
"Members",
",",
"member",
")",
"\n",
"}",
"\n",
"machines",
"=",
"append",
"(",
"machines",
",",
"m",
")",
"\n",
"}",
"\n",
"rsMembers",
",",
"err",
":=",
"replicaset",
".",
"CurrentMembers",
"(",
"st",
".",
"session",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"masterRs",
",",
"err",
":=",
"replicaset",
".",
"MasterHostPort",
"(",
"st",
".",
"session",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"rsMembers",
"{",
"if",
"m",
".",
"Address",
"!=",
"masterRs",
"{",
"result",
".",
"RsMembers",
"=",
"append",
"(",
"result",
".",
"RsMembers",
",",
"m",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"machines",
"{",
"if",
"err",
":=",
"m",
".",
"SetStopMongoUntilVersion",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"UpgradeMongoParams",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetUpgradeMongoMode writes a value in the state server to be picked up
// by api servers to know that there is an upgrade ready to happen. | [
"SetUpgradeMongoMode",
"writes",
"a",
"value",
"in",
"the",
"state",
"server",
"to",
"be",
"picked",
"up",
"by",
"api",
"servers",
"to",
"know",
"that",
"there",
"is",
"an",
"upgrade",
"ready",
"to",
"happen",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mongo.go#L53-L106 |
3,856 | juju/juju | state/mongo.go | ResumeReplication | func (st *State) ResumeReplication(members []replicaset.Member) error {
return replicaset.Add(st.session, members...)
} | go | func (st *State) ResumeReplication(members []replicaset.Member) error {
return replicaset.Add(st.session, members...)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ResumeReplication",
"(",
"members",
"[",
"]",
"replicaset",
".",
"Member",
")",
"error",
"{",
"return",
"replicaset",
".",
"Add",
"(",
"st",
".",
"session",
",",
"members",
"...",
")",
"\n",
"}"
] | // ResumeReplication will add all passed members to replicaset. | [
"ResumeReplication",
"will",
"add",
"all",
"passed",
"members",
"to",
"replicaset",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mongo.go#L109-L111 |
3,857 | juju/juju | apiserver/facades/controller/cleaner/cleaner.go | NewCleanerAPI | func NewCleanerAPI(
st *state.State,
res facade.Resources,
authorizer facade.Authorizer,
) (*CleanerAPI, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &CleanerAPI{
st: getState(st),
resources: res,
}, nil
} | go | func NewCleanerAPI(
st *state.State,
res facade.Resources,
authorizer facade.Authorizer,
) (*CleanerAPI, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &CleanerAPI{
st: getState(st),
resources: res,
}, nil
} | [
"func",
"NewCleanerAPI",
"(",
"st",
"*",
"state",
".",
"State",
",",
"res",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
")",
"(",
"*",
"CleanerAPI",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthController",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"CleanerAPI",
"{",
"st",
":",
"getState",
"(",
"st",
")",
",",
"resources",
":",
"res",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewCleanerAPI creates a new instance of the Cleaner API. | [
"NewCleanerAPI",
"creates",
"a",
"new",
"instance",
"of",
"the",
"Cleaner",
"API",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/cleaner/cleaner.go#L24-L36 |
3,858 | juju/juju | apiserver/facades/controller/cleaner/cleaner.go | WatchCleanups | func (api *CleanerAPI) WatchCleanups() (params.NotifyWatchResult, error) {
watch := api.st.WatchCleanups()
if _, ok := <-watch.Changes(); ok {
return params.NotifyWatchResult{
NotifyWatcherId: api.resources.Register(watch),
}, nil
}
return params.NotifyWatchResult{
Error: common.ServerError(watcher.EnsureErr(watch)),
}, nil
} | go | func (api *CleanerAPI) WatchCleanups() (params.NotifyWatchResult, error) {
watch := api.st.WatchCleanups()
if _, ok := <-watch.Changes(); ok {
return params.NotifyWatchResult{
NotifyWatcherId: api.resources.Register(watch),
}, nil
}
return params.NotifyWatchResult{
Error: common.ServerError(watcher.EnsureErr(watch)),
}, nil
} | [
"func",
"(",
"api",
"*",
"CleanerAPI",
")",
"WatchCleanups",
"(",
")",
"(",
"params",
".",
"NotifyWatchResult",
",",
"error",
")",
"{",
"watch",
":=",
"api",
".",
"st",
".",
"WatchCleanups",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"<-",
"watch",
".",
"Changes",
"(",
")",
";",
"ok",
"{",
"return",
"params",
".",
"NotifyWatchResult",
"{",
"NotifyWatcherId",
":",
"api",
".",
"resources",
".",
"Register",
"(",
"watch",
")",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"params",
".",
"NotifyWatchResult",
"{",
"Error",
":",
"common",
".",
"ServerError",
"(",
"watcher",
".",
"EnsureErr",
"(",
"watch",
")",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // WatchChanges watches for cleanups to be perfomed in state | [
"WatchChanges",
"watches",
"for",
"cleanups",
"to",
"be",
"perfomed",
"in",
"state"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/cleaner/cleaner.go#L44-L54 |
3,859 | juju/juju | worker/upgrader/error.go | ChangeAgentTools | func (e *UpgradeReadyError) ChangeAgentTools() error {
agentTools, err := tools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools)
if err != nil {
return err
}
logger.Infof("upgraded from %v to %v (%q)", e.OldTools, agentTools.Version, agentTools.URL)
return nil
} | go | func (e *UpgradeReadyError) ChangeAgentTools() error {
agentTools, err := tools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools)
if err != nil {
return err
}
logger.Infof("upgraded from %v to %v (%q)", e.OldTools, agentTools.Version, agentTools.URL)
return nil
} | [
"func",
"(",
"e",
"*",
"UpgradeReadyError",
")",
"ChangeAgentTools",
"(",
")",
"error",
"{",
"agentTools",
",",
"err",
":=",
"tools",
".",
"ChangeAgentTools",
"(",
"e",
".",
"DataDir",
",",
"e",
".",
"AgentName",
",",
"e",
".",
"NewTools",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"e",
".",
"OldTools",
",",
"agentTools",
".",
"Version",
",",
"agentTools",
".",
"URL",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ChangeAgentTools does the actual agent upgrade.
// It should be called just before an agent exits, so that
// it will restart running the new tools. | [
"ChangeAgentTools",
"does",
"the",
"actual",
"agent",
"upgrade",
".",
"It",
"should",
"be",
"called",
"just",
"before",
"an",
"agent",
"exits",
"so",
"that",
"it",
"will",
"restart",
"running",
"the",
"new",
"tools",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgrader/error.go#L28-L35 |
3,860 | juju/juju | provider/oci/common/errors.go | IsAuthorisationFailure | func IsAuthorisationFailure(err error) bool {
if err == nil {
return false
}
serviceError, ok := err.(ociCommon.ServiceError)
if !ok {
// Just to double check, also try the SDK's
// implementation. This isn't checked first, because
// it is hard to test.
serviceError, ok = ociCommon.IsServiceError(err)
}
if ok && authErrorCodes.Contains(serviceError.GetCode()) {
return true
}
return false
} | go | func IsAuthorisationFailure(err error) bool {
if err == nil {
return false
}
serviceError, ok := err.(ociCommon.ServiceError)
if !ok {
// Just to double check, also try the SDK's
// implementation. This isn't checked first, because
// it is hard to test.
serviceError, ok = ociCommon.IsServiceError(err)
}
if ok && authErrorCodes.Contains(serviceError.GetCode()) {
return true
}
return false
} | [
"func",
"IsAuthorisationFailure",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"serviceError",
",",
"ok",
":=",
"err",
".",
"(",
"ociCommon",
".",
"ServiceError",
")",
"\n",
"if",
"!",
"ok",
"{",
"// Just to double check, also try the SDK's",
"// implementation. This isn't checked first, because",
"// it is hard to test.",
"serviceError",
",",
"ok",
"=",
"ociCommon",
".",
"IsServiceError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"ok",
"&&",
"authErrorCodes",
".",
"Contains",
"(",
"serviceError",
".",
"GetCode",
"(",
")",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IsAuthorisationFailure reports whether the error is related to
// attempting to access the provider with invalid or expired credentials. | [
"IsAuthorisationFailure",
"reports",
"whether",
"the",
"error",
"is",
"related",
"to",
"attempting",
"to",
"access",
"the",
"provider",
"with",
"invalid",
"or",
"expired",
"credentials",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/common/errors.go#L37-L55 |
3,861 | juju/juju | provider/oci/common/errors.go | HandleCredentialError | func HandleCredentialError(err error, ctx context.ProviderCallContext) {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
} | go | func HandleCredentialError(err error, ctx context.ProviderCallContext) {
common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
} | [
"func",
"HandleCredentialError",
"(",
"err",
"error",
",",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"{",
"common",
".",
"HandleCredentialError",
"(",
"IsAuthorisationFailure",
",",
"err",
",",
"ctx",
")",
"\n",
"}"
] | // HandleCredentialError marks the current credentials as invalid internally
// if Oracle believes that they are expired | [
"HandleCredentialError",
"marks",
"the",
"current",
"credentials",
"as",
"invalid",
"internally",
"if",
"Oracle",
"believes",
"that",
"they",
"are",
"expired"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/common/errors.go#L59-L61 |
3,862 | juju/juju | worker/logforwarder/manifold.go | Manifold | func Manifold(config ManifoldConfig) dependency.Manifold {
openLogStream := config.OpenLogStream
if openLogStream == nil {
openLogStream = func(caller base.APICaller, cfg params.LogStreamConfig, controllerUUID string) (LogStream, error) {
return logstream.Open(caller, cfg, controllerUUID)
}
}
openForwarder := config.OpenLogForwarder
if openForwarder == nil {
openForwarder = NewLogForwarder
}
return dependency.Manifold{
Inputs: []string{
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, errors.Trace(err)
}
agentFacade, err := apiagent.NewState(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
controllerCfg, err := agentFacade.ControllerConfig()
if err != nil {
return nil, errors.Annotate(err, "cannot read controller config")
}
orchestrator, err := newOrchestratorForController(OrchestratorArgs{
ControllerUUID: controllerCfg.ControllerUUID(),
LogForwardConfig: agentFacade,
Caller: apiCaller,
Sinks: config.Sinks,
OpenLogStream: openLogStream,
OpenLogForwarder: openForwarder,
})
return orchestrator, errors.Annotate(err, "creating log forwarding orchestrator")
},
}
} | go | func Manifold(config ManifoldConfig) dependency.Manifold {
openLogStream := config.OpenLogStream
if openLogStream == nil {
openLogStream = func(caller base.APICaller, cfg params.LogStreamConfig, controllerUUID string) (LogStream, error) {
return logstream.Open(caller, cfg, controllerUUID)
}
}
openForwarder := config.OpenLogForwarder
if openForwarder == nil {
openForwarder = NewLogForwarder
}
return dependency.Manifold{
Inputs: []string{
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, errors.Trace(err)
}
agentFacade, err := apiagent.NewState(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
controllerCfg, err := agentFacade.ControllerConfig()
if err != nil {
return nil, errors.Annotate(err, "cannot read controller config")
}
orchestrator, err := newOrchestratorForController(OrchestratorArgs{
ControllerUUID: controllerCfg.ControllerUUID(),
LogForwardConfig: agentFacade,
Caller: apiCaller,
Sinks: config.Sinks,
OpenLogStream: openLogStream,
OpenLogForwarder: openForwarder,
})
return orchestrator, errors.Annotate(err, "creating log forwarding orchestrator")
},
}
} | [
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"openLogStream",
":=",
"config",
".",
"OpenLogStream",
"\n",
"if",
"openLogStream",
"==",
"nil",
"{",
"openLogStream",
"=",
"func",
"(",
"caller",
"base",
".",
"APICaller",
",",
"cfg",
"params",
".",
"LogStreamConfig",
",",
"controllerUUID",
"string",
")",
"(",
"LogStream",
",",
"error",
")",
"{",
"return",
"logstream",
".",
"Open",
"(",
"caller",
",",
"cfg",
",",
"controllerUUID",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"openForwarder",
":=",
"config",
".",
"OpenLogForwarder",
"\n",
"if",
"openForwarder",
"==",
"nil",
"{",
"openForwarder",
"=",
"NewLogForwarder",
"\n",
"}",
"\n\n",
"return",
"dependency",
".",
"Manifold",
"{",
"Inputs",
":",
"[",
"]",
"string",
"{",
"config",
".",
"APICallerName",
",",
"}",
",",
"Start",
":",
"func",
"(",
"context",
"dependency",
".",
"Context",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"var",
"apiCaller",
"base",
".",
"APICaller",
"\n",
"if",
"err",
":=",
"context",
".",
"Get",
"(",
"config",
".",
"APICallerName",
",",
"&",
"apiCaller",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"agentFacade",
",",
"err",
":=",
"apiagent",
".",
"NewState",
"(",
"apiCaller",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"controllerCfg",
",",
"err",
":=",
"agentFacade",
".",
"ControllerConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"orchestrator",
",",
"err",
":=",
"newOrchestratorForController",
"(",
"OrchestratorArgs",
"{",
"ControllerUUID",
":",
"controllerCfg",
".",
"ControllerUUID",
"(",
")",
",",
"LogForwardConfig",
":",
"agentFacade",
",",
"Caller",
":",
"apiCaller",
",",
"Sinks",
":",
"config",
".",
"Sinks",
",",
"OpenLogStream",
":",
"openLogStream",
",",
"OpenLogForwarder",
":",
"openForwarder",
",",
"}",
")",
"\n",
"return",
"orchestrator",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // Manifold returns a dependency manifold that runs a log forwarding
// worker, using the resource names defined in the supplied config. | [
"Manifold",
"returns",
"a",
"dependency",
"manifold",
"that",
"runs",
"a",
"log",
"forwarding",
"worker",
"using",
"the",
"resource",
"names",
"defined",
"in",
"the",
"supplied",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/logforwarder/manifold.go#L37-L80 |
3,863 | juju/juju | provider/oci/provider.go | Open | func (e *EnvironProvider) Open(params environs.OpenParams) (environs.Environ, error) {
logger.Infof("opening model %q", params.Config.Name())
if err := validateCloudSpec(params.Cloud); err != nil {
return nil, errors.Trace(err)
}
creds := params.Cloud.Credential.Attributes()
jujuConfig := common.JujuConfigProvider{
Key: []byte(creds["key"]),
Fingerprint: creds["fingerprint"],
Passphrase: creds["pass-phrase"],
Tenancy: creds["tenancy"],
User: creds["user"],
OCIRegion: creds["region"],
}
provider, err := jujuConfig.Config()
if err != nil {
return nil, errors.Trace(err)
}
compute, err := ociCore.NewComputeClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
networking, err := ociCore.NewVirtualNetworkClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
storage, err := ociCore.NewBlockstorageClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
identity, err := ociIdentity.NewIdentityClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
env := &Environ{
Compute: compute,
Networking: networking,
Storage: storage,
Firewall: networking,
Identity: identity,
ociConfig: provider,
clock: clock.WallClock,
p: e,
}
if err := env.SetConfig(params.Config); err != nil {
return nil, err
}
env.namespace, err = instance.NewNamespace(env.Config().UUID())
cfg := env.ecfg()
if cfg.compartmentID() == nil {
return nil, errors.New("compartment-id may not be empty")
}
addressSpace := cfg.addressSpace()
if _, ipNET, err := net.ParseCIDR(*addressSpace); err == nil {
size, _ := ipNET.Mask.Size()
if size > 16 {
return nil, errors.Errorf("configured subnet (%q) is not large enough. Please use a prefix length in the range /8 to /16. Current prefix length is /%d", *addressSpace, size)
}
} else {
return nil, errors.Trace(err)
}
return env, nil
} | go | func (e *EnvironProvider) Open(params environs.OpenParams) (environs.Environ, error) {
logger.Infof("opening model %q", params.Config.Name())
if err := validateCloudSpec(params.Cloud); err != nil {
return nil, errors.Trace(err)
}
creds := params.Cloud.Credential.Attributes()
jujuConfig := common.JujuConfigProvider{
Key: []byte(creds["key"]),
Fingerprint: creds["fingerprint"],
Passphrase: creds["pass-phrase"],
Tenancy: creds["tenancy"],
User: creds["user"],
OCIRegion: creds["region"],
}
provider, err := jujuConfig.Config()
if err != nil {
return nil, errors.Trace(err)
}
compute, err := ociCore.NewComputeClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
networking, err := ociCore.NewVirtualNetworkClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
storage, err := ociCore.NewBlockstorageClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
identity, err := ociIdentity.NewIdentityClientWithConfigurationProvider(provider)
if err != nil {
return nil, errors.Trace(err)
}
env := &Environ{
Compute: compute,
Networking: networking,
Storage: storage,
Firewall: networking,
Identity: identity,
ociConfig: provider,
clock: clock.WallClock,
p: e,
}
if err := env.SetConfig(params.Config); err != nil {
return nil, err
}
env.namespace, err = instance.NewNamespace(env.Config().UUID())
cfg := env.ecfg()
if cfg.compartmentID() == nil {
return nil, errors.New("compartment-id may not be empty")
}
addressSpace := cfg.addressSpace()
if _, ipNET, err := net.ParseCIDR(*addressSpace); err == nil {
size, _ := ipNET.Mask.Size()
if size > 16 {
return nil, errors.Errorf("configured subnet (%q) is not large enough. Please use a prefix length in the range /8 to /16. Current prefix length is /%d", *addressSpace, size)
}
} else {
return nil, errors.Trace(err)
}
return env, nil
} | [
"func",
"(",
"e",
"*",
"EnvironProvider",
")",
"Open",
"(",
"params",
"environs",
".",
"OpenParams",
")",
"(",
"environs",
".",
"Environ",
",",
"error",
")",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"params",
".",
"Config",
".",
"Name",
"(",
")",
")",
"\n\n",
"if",
"err",
":=",
"validateCloudSpec",
"(",
"params",
".",
"Cloud",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"creds",
":=",
"params",
".",
"Cloud",
".",
"Credential",
".",
"Attributes",
"(",
")",
"\n",
"jujuConfig",
":=",
"common",
".",
"JujuConfigProvider",
"{",
"Key",
":",
"[",
"]",
"byte",
"(",
"creds",
"[",
"\"",
"\"",
"]",
")",
",",
"Fingerprint",
":",
"creds",
"[",
"\"",
"\"",
"]",
",",
"Passphrase",
":",
"creds",
"[",
"\"",
"\"",
"]",
",",
"Tenancy",
":",
"creds",
"[",
"\"",
"\"",
"]",
",",
"User",
":",
"creds",
"[",
"\"",
"\"",
"]",
",",
"OCIRegion",
":",
"creds",
"[",
"\"",
"\"",
"]",
",",
"}",
"\n",
"provider",
",",
"err",
":=",
"jujuConfig",
".",
"Config",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"compute",
",",
"err",
":=",
"ociCore",
".",
"NewComputeClientWithConfigurationProvider",
"(",
"provider",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"networking",
",",
"err",
":=",
"ociCore",
".",
"NewVirtualNetworkClientWithConfigurationProvider",
"(",
"provider",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"storage",
",",
"err",
":=",
"ociCore",
".",
"NewBlockstorageClientWithConfigurationProvider",
"(",
"provider",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"identity",
",",
"err",
":=",
"ociIdentity",
".",
"NewIdentityClientWithConfigurationProvider",
"(",
"provider",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"env",
":=",
"&",
"Environ",
"{",
"Compute",
":",
"compute",
",",
"Networking",
":",
"networking",
",",
"Storage",
":",
"storage",
",",
"Firewall",
":",
"networking",
",",
"Identity",
":",
"identity",
",",
"ociConfig",
":",
"provider",
",",
"clock",
":",
"clock",
".",
"WallClock",
",",
"p",
":",
"e",
",",
"}",
"\n\n",
"if",
"err",
":=",
"env",
".",
"SetConfig",
"(",
"params",
".",
"Config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"env",
".",
"namespace",
",",
"err",
"=",
"instance",
".",
"NewNamespace",
"(",
"env",
".",
"Config",
"(",
")",
".",
"UUID",
"(",
")",
")",
"\n\n",
"cfg",
":=",
"env",
".",
"ecfg",
"(",
")",
"\n",
"if",
"cfg",
".",
"compartmentID",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"addressSpace",
":=",
"cfg",
".",
"addressSpace",
"(",
")",
"\n",
"if",
"_",
",",
"ipNET",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"*",
"addressSpace",
")",
";",
"err",
"==",
"nil",
"{",
"size",
",",
"_",
":=",
"ipNET",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"if",
"size",
">",
"16",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"addressSpace",
",",
"size",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"env",
",",
"nil",
"\n",
"}"
] | // Open implements environs.EnvironProvider. | [
"Open",
"implements",
"environs",
".",
"EnvironProvider",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/provider.go#L222-L295 |
3,864 | juju/juju | provider/oci/provider.go | Validate | func (e EnvironProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
newAttrs, err := cfg.ValidateUnknownAttrs(
configFields, configDefaults,
)
if err != nil {
return nil, err
}
return cfg.Apply(newAttrs)
} | go | func (e EnvironProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
newAttrs, err := cfg.ValidateUnknownAttrs(
configFields, configDefaults,
)
if err != nil {
return nil, err
}
return cfg.Apply(newAttrs)
} | [
"func",
"(",
"e",
"EnvironProvider",
")",
"Validate",
"(",
"cfg",
",",
"old",
"*",
"config",
".",
"Config",
")",
"(",
"valid",
"*",
"config",
".",
"Config",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"Validate",
"(",
"cfg",
",",
"old",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newAttrs",
",",
"err",
":=",
"cfg",
".",
"ValidateUnknownAttrs",
"(",
"configFields",
",",
"configDefaults",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"cfg",
".",
"Apply",
"(",
"newAttrs",
")",
"\n",
"}"
] | // Validate implements config.Validator. | [
"Validate",
"implements",
"config",
".",
"Validator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/provider.go#L398-L410 |
3,865 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | NewMockLinkLayerDevice | func NewMockLinkLayerDevice(ctrl *gomock.Controller) *MockLinkLayerDevice {
mock := &MockLinkLayerDevice{ctrl: ctrl}
mock.recorder = &MockLinkLayerDeviceMockRecorder{mock}
return mock
} | go | func NewMockLinkLayerDevice(ctrl *gomock.Controller) *MockLinkLayerDevice {
mock := &MockLinkLayerDevice{ctrl: ctrl}
mock.recorder = &MockLinkLayerDeviceMockRecorder{mock}
return mock
} | [
"func",
"NewMockLinkLayerDevice",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockLinkLayerDevice",
"{",
"mock",
":=",
"&",
"MockLinkLayerDevice",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockLinkLayerDeviceMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockLinkLayerDevice creates a new mock instance | [
"NewMockLinkLayerDevice",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L28-L32 |
3,866 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | Addresses | func (m *MockLinkLayerDevice) Addresses() ([]*state.Address, error) {
ret := m.ctrl.Call(m, "Addresses")
ret0, _ := ret[0].([]*state.Address)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockLinkLayerDevice) Addresses() ([]*state.Address, error) {
ret := m.ctrl.Call(m, "Addresses")
ret0, _ := ret[0].([]*state.Address)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockLinkLayerDevice",
")",
"Addresses",
"(",
")",
"(",
"[",
"]",
"*",
"state",
".",
"Address",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"*",
"state",
".",
"Address",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // Addresses mocks base method | [
"Addresses",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L40-L45 |
3,867 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | Addresses | func (mr *MockLinkLayerDeviceMockRecorder) Addresses() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Addresses", reflect.TypeOf((*MockLinkLayerDevice)(nil).Addresses))
} | go | func (mr *MockLinkLayerDeviceMockRecorder) Addresses() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Addresses", reflect.TypeOf((*MockLinkLayerDevice)(nil).Addresses))
} | [
"func",
"(",
"mr",
"*",
"MockLinkLayerDeviceMockRecorder",
")",
"Addresses",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockLinkLayerDevice",
")",
"(",
"nil",
")",
".",
"Addresses",
")",
")",
"\n",
"}"
] | // Addresses indicates an expected call of Addresses | [
"Addresses",
"indicates",
"an",
"expected",
"call",
"of",
"Addresses"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L48-L50 |
3,868 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | EthernetDeviceForBridge | func (m *MockLinkLayerDevice) EthernetDeviceForBridge(arg0 string) (state.LinkLayerDeviceArgs, error) {
ret := m.ctrl.Call(m, "EthernetDeviceForBridge", arg0)
ret0, _ := ret[0].(state.LinkLayerDeviceArgs)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockLinkLayerDevice) EthernetDeviceForBridge(arg0 string) (state.LinkLayerDeviceArgs, error) {
ret := m.ctrl.Call(m, "EthernetDeviceForBridge", arg0)
ret0, _ := ret[0].(state.LinkLayerDeviceArgs)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockLinkLayerDevice",
")",
"EthernetDeviceForBridge",
"(",
"arg0",
"string",
")",
"(",
"state",
".",
"LinkLayerDeviceArgs",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"state",
".",
"LinkLayerDeviceArgs",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // EthernetDeviceForBridge mocks base method | [
"EthernetDeviceForBridge",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L53-L58 |
3,869 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | EthernetDeviceForBridge | func (mr *MockLinkLayerDeviceMockRecorder) EthernetDeviceForBridge(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EthernetDeviceForBridge", reflect.TypeOf((*MockLinkLayerDevice)(nil).EthernetDeviceForBridge), arg0)
} | go | func (mr *MockLinkLayerDeviceMockRecorder) EthernetDeviceForBridge(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EthernetDeviceForBridge", reflect.TypeOf((*MockLinkLayerDevice)(nil).EthernetDeviceForBridge), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockLinkLayerDeviceMockRecorder",
")",
"EthernetDeviceForBridge",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockLinkLayerDevice",
")",
"(",
"nil",
")",
".",
"EthernetDeviceForBridge",
")",
",",
"arg0",
")",
"\n",
"}"
] | // EthernetDeviceForBridge indicates an expected call of EthernetDeviceForBridge | [
"EthernetDeviceForBridge",
"indicates",
"an",
"expected",
"call",
"of",
"EthernetDeviceForBridge"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L61-L63 |
3,870 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | IsUp | func (m *MockLinkLayerDevice) IsUp() bool {
ret := m.ctrl.Call(m, "IsUp")
ret0, _ := ret[0].(bool)
return ret0
} | go | func (m *MockLinkLayerDevice) IsUp() bool {
ret := m.ctrl.Call(m, "IsUp")
ret0, _ := ret[0].(bool)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockLinkLayerDevice",
")",
"IsUp",
"(",
")",
"bool",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // IsUp mocks base method | [
"IsUp",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L78-L82 |
3,871 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | MTU | func (m *MockLinkLayerDevice) MTU() uint {
ret := m.ctrl.Call(m, "MTU")
ret0, _ := ret[0].(uint)
return ret0
} | go | func (m *MockLinkLayerDevice) MTU() uint {
ret := m.ctrl.Call(m, "MTU")
ret0, _ := ret[0].(uint)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockLinkLayerDevice",
")",
"MTU",
"(",
")",
"uint",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"uint",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // MTU mocks base method | [
"MTU",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L102-L106 |
3,872 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | ParentDevice | func (m *MockLinkLayerDevice) ParentDevice() (containerizer.LinkLayerDevice, error) {
ret := m.ctrl.Call(m, "ParentDevice")
ret0, _ := ret[0].(containerizer.LinkLayerDevice)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockLinkLayerDevice) ParentDevice() (containerizer.LinkLayerDevice, error) {
ret := m.ctrl.Call(m, "ParentDevice")
ret0, _ := ret[0].(containerizer.LinkLayerDevice)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockLinkLayerDevice",
")",
"ParentDevice",
"(",
")",
"(",
"containerizer",
".",
"LinkLayerDevice",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"containerizer",
".",
"LinkLayerDevice",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ParentDevice mocks base method | [
"ParentDevice",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L126-L131 |
3,873 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | NewMockUnit | func NewMockUnit(ctrl *gomock.Controller) *MockUnit {
mock := &MockUnit{ctrl: ctrl}
mock.recorder = &MockUnitMockRecorder{mock}
return mock
} | go | func NewMockUnit(ctrl *gomock.Controller) *MockUnit {
mock := &MockUnit{ctrl: ctrl}
mock.recorder = &MockUnitMockRecorder{mock}
return mock
} | [
"func",
"NewMockUnit",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockUnit",
"{",
"mock",
":=",
"&",
"MockUnit",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockUnitMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockUnit creates a new mock instance | [
"NewMockUnit",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L174-L178 |
3,874 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | NewMockApplication | func NewMockApplication(ctrl *gomock.Controller) *MockApplication {
mock := &MockApplication{ctrl: ctrl}
mock.recorder = &MockApplicationMockRecorder{mock}
return mock
} | go | func NewMockApplication(ctrl *gomock.Controller) *MockApplication {
mock := &MockApplication{ctrl: ctrl}
mock.recorder = &MockApplicationMockRecorder{mock}
return mock
} | [
"func",
"NewMockApplication",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockApplication",
"{",
"mock",
":=",
"&",
"MockApplication",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockApplicationMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockApplication creates a new mock instance | [
"NewMockApplication",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L222-L226 |
3,875 | juju/juju | apiserver/facades/agent/provisioner/mocks/containerizer_mock.go | NewMockCharm | func NewMockCharm(ctrl *gomock.Controller) *MockCharm {
mock := &MockCharm{ctrl: ctrl}
mock.recorder = &MockCharmMockRecorder{mock}
return mock
} | go | func NewMockCharm(ctrl *gomock.Controller) *MockCharm {
mock := &MockCharm{ctrl: ctrl}
mock.recorder = &MockCharmMockRecorder{mock}
return mock
} | [
"func",
"NewMockCharm",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockCharm",
"{",
"mock",
":=",
"&",
"MockCharm",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockCharmMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockCharm creates a new mock instance | [
"NewMockCharm",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/provisioner/mocks/containerizer_mock.go#L271-L275 |
3,876 | juju/juju | cmd/jujud/agent/agent.go | AddFlags | func (c *agentConf) AddFlags(f *gnuflag.FlagSet) {
// TODO(dimitern) 2014-02-19 bug 1282025
// We need to pass a config location here instead and
// use it to locate the conf and the infer the data-dir
// from there instead of passing it like that.
f.StringVar(&c.dataDir, "data-dir", util.DataDir, "directory for juju data")
} | go | func (c *agentConf) AddFlags(f *gnuflag.FlagSet) {
// TODO(dimitern) 2014-02-19 bug 1282025
// We need to pass a config location here instead and
// use it to locate the conf and the infer the data-dir
// from there instead of passing it like that.
f.StringVar(&c.dataDir, "data-dir", util.DataDir, "directory for juju data")
} | [
"func",
"(",
"c",
"*",
"agentConf",
")",
"AddFlags",
"(",
"f",
"*",
"gnuflag",
".",
"FlagSet",
")",
"{",
"// TODO(dimitern) 2014-02-19 bug 1282025",
"// We need to pass a config location here instead and",
"// use it to locate the conf and the infer the data-dir",
"// from there instead of passing it like that.",
"f",
".",
"StringVar",
"(",
"&",
"c",
".",
"dataDir",
",",
"\"",
"\"",
",",
"util",
".",
"DataDir",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // AddFlags injects common agent flags into f. | [
"AddFlags",
"injects",
"common",
"agent",
"flags",
"into",
"f",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/agent.go#L66-L72 |
3,877 | juju/juju | cmd/jujud/agent/agent.go | CheckArgs | func (c *agentConf) CheckArgs(args []string) error {
if c.dataDir == "" {
return util.RequiredError("data-dir")
}
return cmd.CheckEmpty(args)
} | go | func (c *agentConf) CheckArgs(args []string) error {
if c.dataDir == "" {
return util.RequiredError("data-dir")
}
return cmd.CheckEmpty(args)
} | [
"func",
"(",
"c",
"*",
"agentConf",
")",
"CheckArgs",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"c",
".",
"dataDir",
"==",
"\"",
"\"",
"{",
"return",
"util",
".",
"RequiredError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"cmd",
".",
"CheckEmpty",
"(",
"args",
")",
"\n",
"}"
] | // CheckArgs reports whether the given args are valid for this agent. | [
"CheckArgs",
"reports",
"whether",
"the",
"given",
"args",
"are",
"valid",
"for",
"this",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/agent.go#L75-L80 |
3,878 | juju/juju | cmd/jujud/agent/agent.go | ReadConfig | func (c *agentConf) ReadConfig(tag string) error {
t, err := names.ParseTag(tag)
if err != nil {
return errors.Trace(err)
}
c.mu.Lock()
defer c.mu.Unlock()
conf, err := agent.ReadConfig(agent.ConfigPath(c.dataDir, t))
if err != nil {
return errors.Trace(err)
}
c._config = conf
return nil
} | go | func (c *agentConf) ReadConfig(tag string) error {
t, err := names.ParseTag(tag)
if err != nil {
return errors.Trace(err)
}
c.mu.Lock()
defer c.mu.Unlock()
conf, err := agent.ReadConfig(agent.ConfigPath(c.dataDir, t))
if err != nil {
return errors.Trace(err)
}
c._config = conf
return nil
} | [
"func",
"(",
"c",
"*",
"agentConf",
")",
"ReadConfig",
"(",
"tag",
"string",
")",
"error",
"{",
"t",
",",
"err",
":=",
"names",
".",
"ParseTag",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"conf",
",",
"err",
":=",
"agent",
".",
"ReadConfig",
"(",
"agent",
".",
"ConfigPath",
"(",
"c",
".",
"dataDir",
",",
"t",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"c",
".",
"_config",
"=",
"conf",
"\n",
"return",
"nil",
"\n",
"}"
] | // ReadConfig reads the agent's config from its config file. | [
"ReadConfig",
"reads",
"the",
"agent",
"s",
"config",
"from",
"its",
"config",
"file",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/agent.go#L88-L101 |
3,879 | juju/juju | cmd/jujud/agent/agent.go | ChangeConfig | func (c *agentConf) ChangeConfig(change agent.ConfigMutator) error {
c.mu.Lock()
defer c.mu.Unlock()
if err := change(c._config); err != nil {
return errors.Trace(err)
}
if err := c._config.Write(); err != nil {
return errors.Annotate(err, "cannot write agent configuration")
}
return nil
} | go | func (c *agentConf) ChangeConfig(change agent.ConfigMutator) error {
c.mu.Lock()
defer c.mu.Unlock()
if err := change(c._config); err != nil {
return errors.Trace(err)
}
if err := c._config.Write(); err != nil {
return errors.Annotate(err, "cannot write agent configuration")
}
return nil
} | [
"func",
"(",
"c",
"*",
"agentConf",
")",
"ChangeConfig",
"(",
"change",
"agent",
".",
"ConfigMutator",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"change",
"(",
"c",
".",
"_config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"_config",
".",
"Write",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ChangeConfig modifies this configuration using the given mutator. | [
"ChangeConfig",
"modifies",
"this",
"configuration",
"using",
"the",
"given",
"mutator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/agent.go#L104-L114 |
3,880 | juju/juju | cmd/jujud/agent/agent.go | CurrentConfig | func (c *agentConf) CurrentConfig() agent.Config {
c.mu.Lock()
defer c.mu.Unlock()
return c._config.Clone()
} | go | func (c *agentConf) CurrentConfig() agent.Config {
c.mu.Lock()
defer c.mu.Unlock()
return c._config.Clone()
} | [
"func",
"(",
"c",
"*",
"agentConf",
")",
"CurrentConfig",
"(",
")",
"agent",
".",
"Config",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"_config",
".",
"Clone",
"(",
")",
"\n",
"}"
] | // CurrentConfig returns the agent config for this agent. | [
"CurrentConfig",
"returns",
"the",
"agent",
"config",
"for",
"this",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/agent.go#L117-L121 |
3,881 | juju/juju | cmd/jujud/agent/agent.go | GetJujuVersion | func GetJujuVersion(machineAgent string, dataDir string) (version.Number, error) {
agentConf := NewAgentConf(dataDir)
if err := agentConf.ReadConfig(machineAgent); err != nil {
err = errors.Annotate(err, "failed to read agent config file.")
return version.Number{}, err
}
config := agentConf.CurrentConfig()
if config == nil {
return version.Number{}, errors.Errorf("%s agent conf is not found", machineAgent)
}
return config.UpgradedToVersion(), nil
} | go | func GetJujuVersion(machineAgent string, dataDir string) (version.Number, error) {
agentConf := NewAgentConf(dataDir)
if err := agentConf.ReadConfig(machineAgent); err != nil {
err = errors.Annotate(err, "failed to read agent config file.")
return version.Number{}, err
}
config := agentConf.CurrentConfig()
if config == nil {
return version.Number{}, errors.Errorf("%s agent conf is not found", machineAgent)
}
return config.UpgradedToVersion(), nil
} | [
"func",
"GetJujuVersion",
"(",
"machineAgent",
"string",
",",
"dataDir",
"string",
")",
"(",
"version",
".",
"Number",
",",
"error",
")",
"{",
"agentConf",
":=",
"NewAgentConf",
"(",
"dataDir",
")",
"\n",
"if",
"err",
":=",
"agentConf",
".",
"ReadConfig",
"(",
"machineAgent",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"return",
"version",
".",
"Number",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"config",
":=",
"agentConf",
".",
"CurrentConfig",
"(",
")",
"\n",
"if",
"config",
"==",
"nil",
"{",
"return",
"version",
".",
"Number",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"machineAgent",
")",
"\n",
"}",
"\n",
"return",
"config",
".",
"UpgradedToVersion",
"(",
")",
",",
"nil",
"\n",
"}"
] | // GetJujuVersion gets the version of the agent from agent's config file | [
"GetJujuVersion",
"gets",
"the",
"version",
"of",
"the",
"agent",
"from",
"agent",
"s",
"config",
"file"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/agent.go#L149-L160 |
3,882 | juju/juju | state/mocks/txn_mock.go | NewMockRunner | func NewMockRunner(ctrl *gomock.Controller) *MockRunner {
mock := &MockRunner{ctrl: ctrl}
mock.recorder = &MockRunnerMockRecorder{mock}
return mock
} | go | func NewMockRunner(ctrl *gomock.Controller) *MockRunner {
mock := &MockRunner{ctrl: ctrl}
mock.recorder = &MockRunnerMockRecorder{mock}
return mock
} | [
"func",
"NewMockRunner",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockRunner",
"{",
"mock",
":=",
"&",
"MockRunner",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockRunnerMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockRunner creates a new mock instance | [
"NewMockRunner",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/txn_mock.go#L25-L29 |
3,883 | juju/juju | state/mocks/txn_mock.go | MaybePruneTransactions | func (m *MockRunner) MaybePruneTransactions(arg0 txn.PruneOptions) error {
ret := m.ctrl.Call(m, "MaybePruneTransactions", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockRunner) MaybePruneTransactions(arg0 txn.PruneOptions) error {
ret := m.ctrl.Call(m, "MaybePruneTransactions", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockRunner",
")",
"MaybePruneTransactions",
"(",
"arg0",
"txn",
".",
"PruneOptions",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // MaybePruneTransactions mocks base method | [
"MaybePruneTransactions",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/txn_mock.go#L37-L41 |
3,884 | juju/juju | state/mocks/txn_mock.go | ResumeTransactions | func (m *MockRunner) ResumeTransactions() error {
ret := m.ctrl.Call(m, "ResumeTransactions")
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockRunner) ResumeTransactions() error {
ret := m.ctrl.Call(m, "ResumeTransactions")
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockRunner",
")",
"ResumeTransactions",
"(",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ResumeTransactions mocks base method | [
"ResumeTransactions",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/txn_mock.go#L49-L53 |
3,885 | juju/juju | state/mocks/txn_mock.go | ResumeTransactions | func (mr *MockRunnerMockRecorder) ResumeTransactions() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResumeTransactions", reflect.TypeOf((*MockRunner)(nil).ResumeTransactions))
} | go | func (mr *MockRunnerMockRecorder) ResumeTransactions() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResumeTransactions", reflect.TypeOf((*MockRunner)(nil).ResumeTransactions))
} | [
"func",
"(",
"mr",
"*",
"MockRunnerMockRecorder",
")",
"ResumeTransactions",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockRunner",
")",
"(",
"nil",
")",
".",
"ResumeTransactions",
")",
")",
"\n",
"}"
] | // ResumeTransactions indicates an expected call of ResumeTransactions | [
"ResumeTransactions",
"indicates",
"an",
"expected",
"call",
"of",
"ResumeTransactions"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/txn_mock.go#L56-L58 |
3,886 | juju/juju | state/mocks/txn_mock.go | Run | func (m *MockRunner) Run(arg0 txn.TransactionSource) error {
ret := m.ctrl.Call(m, "Run", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockRunner) Run(arg0 txn.TransactionSource) error {
ret := m.ctrl.Call(m, "Run", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockRunner",
")",
"Run",
"(",
"arg0",
"txn",
".",
"TransactionSource",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Run mocks base method | [
"Run",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/txn_mock.go#L61-L65 |
3,887 | juju/juju | state/mocks/txn_mock.go | Run | func (mr *MockRunnerMockRecorder) Run(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockRunner)(nil).Run), arg0)
} | go | func (mr *MockRunnerMockRecorder) Run(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockRunner)(nil).Run), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockRunnerMockRecorder",
")",
"Run",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockRunner",
")",
"(",
"nil",
")",
".",
"Run",
")",
",",
"arg0",
")",
"\n",
"}"
] | // Run indicates an expected call of Run | [
"Run",
"indicates",
"an",
"expected",
"call",
"of",
"Run"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/mocks/txn_mock.go#L68-L70 |
3,888 | juju/juju | worker/instancemutater/mocks/environs_mock.go | NewMockEnviron | func NewMockEnviron(ctrl *gomock.Controller) *MockEnviron {
mock := &MockEnviron{ctrl: ctrl}
mock.recorder = &MockEnvironMockRecorder{mock}
return mock
} | go | func NewMockEnviron(ctrl *gomock.Controller) *MockEnviron {
mock := &MockEnviron{ctrl: ctrl}
mock.recorder = &MockEnvironMockRecorder{mock}
return mock
} | [
"func",
"NewMockEnviron",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockEnviron",
"{",
"mock",
":=",
"&",
"MockEnviron",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockEnvironMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockEnviron creates a new mock instance | [
"NewMockEnviron",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/mocks/environs_mock.go#L34-L38 |
3,889 | juju/juju | worker/instancemutater/mocks/environs_mock.go | AllInstances | func (m *MockEnviron) AllInstances(arg0 context.ProviderCallContext) ([]instances.Instance, error) {
ret := m.ctrl.Call(m, "AllInstances", arg0)
ret0, _ := ret[0].([]instances.Instance)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockEnviron) AllInstances(arg0 context.ProviderCallContext) ([]instances.Instance, error) {
ret := m.ctrl.Call(m, "AllInstances", arg0)
ret0, _ := ret[0].([]instances.Instance)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockEnviron",
")",
"AllInstances",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"instances",
".",
"Instance",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // AllInstances mocks base method | [
"AllInstances",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/mocks/environs_mock.go#L58-L63 |
3,890 | juju/juju | worker/instancemutater/mocks/environs_mock.go | Bootstrap | func (m *MockEnviron) Bootstrap(arg0 environs.BootstrapContext, arg1 context.ProviderCallContext, arg2 environs.BootstrapParams) (*environs.BootstrapResult, error) {
ret := m.ctrl.Call(m, "Bootstrap", arg0, arg1, arg2)
ret0, _ := ret[0].(*environs.BootstrapResult)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockEnviron) Bootstrap(arg0 environs.BootstrapContext, arg1 context.ProviderCallContext, arg2 environs.BootstrapParams) (*environs.BootstrapResult, error) {
ret := m.ctrl.Call(m, "Bootstrap", arg0, arg1, arg2)
ret0, _ := ret[0].(*environs.BootstrapResult)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockEnviron",
")",
"Bootstrap",
"(",
"arg0",
"environs",
".",
"BootstrapContext",
",",
"arg1",
"context",
".",
"ProviderCallContext",
",",
"arg2",
"environs",
".",
"BootstrapParams",
")",
"(",
"*",
"environs",
".",
"BootstrapResult",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"environs",
".",
"BootstrapResult",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // Bootstrap mocks base method | [
"Bootstrap",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/mocks/environs_mock.go#L71-L76 |
3,891 | juju/juju | worker/instancemutater/mocks/environs_mock.go | ControllerInstances | func (m *MockEnviron) ControllerInstances(arg0 context.ProviderCallContext, arg1 string) ([]instance.Id, error) {
ret := m.ctrl.Call(m, "ControllerInstances", arg0, arg1)
ret0, _ := ret[0].([]instance.Id)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockEnviron) ControllerInstances(arg0 context.ProviderCallContext, arg1 string) ([]instance.Id, error) {
ret := m.ctrl.Call(m, "ControllerInstances", arg0, arg1)
ret0, _ := ret[0].([]instance.Id)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockEnviron",
")",
"ControllerInstances",
"(",
"arg0",
"context",
".",
"ProviderCallContext",
",",
"arg1",
"string",
")",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"instance",
".",
"Id",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ControllerInstances mocks base method | [
"ControllerInstances",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/mocks/environs_mock.go#L109-L114 |
3,892 | juju/juju | worker/instancemutater/mocks/environs_mock.go | DestroyController | func (mr *MockEnvironMockRecorder) DestroyController(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DestroyController", reflect.TypeOf((*MockEnviron)(nil).DestroyController), arg0, arg1)
} | go | func (mr *MockEnvironMockRecorder) DestroyController(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DestroyController", reflect.TypeOf((*MockEnviron)(nil).DestroyController), arg0, arg1)
} | [
"func",
"(",
"mr",
"*",
"MockEnvironMockRecorder",
")",
"DestroyController",
"(",
"arg0",
",",
"arg1",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockEnviron",
")",
"(",
"nil",
")",
".",
"DestroyController",
")",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // DestroyController indicates an expected call of DestroyController | [
"DestroyController",
"indicates",
"an",
"expected",
"call",
"of",
"DestroyController"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/mocks/environs_mock.go#L153-L155 |
3,893 | juju/juju | worker/instancemutater/mocks/environs_mock.go | Provider | func (mr *MockEnvironMockRecorder) Provider() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Provider", reflect.TypeOf((*MockEnviron)(nil).Provider))
} | go | func (mr *MockEnvironMockRecorder) Provider() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Provider", reflect.TypeOf((*MockEnviron)(nil).Provider))
} | [
"func",
"(",
"mr",
"*",
"MockEnvironMockRecorder",
")",
"Provider",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockEnviron",
")",
"(",
"nil",
")",
".",
"Provider",
")",
")",
"\n",
"}"
] | // Provider indicates an expected call of Provider | [
"Provider",
"indicates",
"an",
"expected",
"call",
"of",
"Provider"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/mocks/environs_mock.go#L227-L229 |
3,894 | juju/juju | caas/kubernetes/provider/k8s.go | NewK8sBroker | func NewK8sBroker(
controllerUUID string,
k8sRestConfig *rest.Config,
cfg *config.Config,
newClient NewK8sClientFunc,
newWatcher NewK8sWatcherFunc,
clock jujuclock.Clock,
) (*kubernetesClient, error) {
k8sClient, apiextensionsClient, err := newClient(k8sRestConfig)
if err != nil {
return nil, errors.Trace(err)
}
newCfg, err := providerInstance.newConfig(cfg)
if err != nil {
return nil, errors.Trace(err)
}
modelUUID := newCfg.UUID()
if modelUUID == "" {
return nil, errors.NotValidf("modelUUID is required")
}
client := &kubernetesClient{
clock: clock,
clientUnlocked: k8sClient,
apiextensionsClientUnlocked: apiextensionsClient,
envCfgUnlocked: newCfg.Config,
namespace: newCfg.Name(),
modelUUID: modelUUID,
newWatcher: newWatcher,
newClient: newClient,
annotations: k8sannotations.New(nil).
Add(annotationModelUUIDKey, modelUUID),
}
if controllerUUID != "" {
// controllerUUID could be empty in add-k8s without -c because there might be no controller yet.
client.annotations.Add(annotationControllerUUIDKey, controllerUUID)
}
return client, nil
} | go | func NewK8sBroker(
controllerUUID string,
k8sRestConfig *rest.Config,
cfg *config.Config,
newClient NewK8sClientFunc,
newWatcher NewK8sWatcherFunc,
clock jujuclock.Clock,
) (*kubernetesClient, error) {
k8sClient, apiextensionsClient, err := newClient(k8sRestConfig)
if err != nil {
return nil, errors.Trace(err)
}
newCfg, err := providerInstance.newConfig(cfg)
if err != nil {
return nil, errors.Trace(err)
}
modelUUID := newCfg.UUID()
if modelUUID == "" {
return nil, errors.NotValidf("modelUUID is required")
}
client := &kubernetesClient{
clock: clock,
clientUnlocked: k8sClient,
apiextensionsClientUnlocked: apiextensionsClient,
envCfgUnlocked: newCfg.Config,
namespace: newCfg.Name(),
modelUUID: modelUUID,
newWatcher: newWatcher,
newClient: newClient,
annotations: k8sannotations.New(nil).
Add(annotationModelUUIDKey, modelUUID),
}
if controllerUUID != "" {
// controllerUUID could be empty in add-k8s without -c because there might be no controller yet.
client.annotations.Add(annotationControllerUUIDKey, controllerUUID)
}
return client, nil
} | [
"func",
"NewK8sBroker",
"(",
"controllerUUID",
"string",
",",
"k8sRestConfig",
"*",
"rest",
".",
"Config",
",",
"cfg",
"*",
"config",
".",
"Config",
",",
"newClient",
"NewK8sClientFunc",
",",
"newWatcher",
"NewK8sWatcherFunc",
",",
"clock",
"jujuclock",
".",
"Clock",
",",
")",
"(",
"*",
"kubernetesClient",
",",
"error",
")",
"{",
"k8sClient",
",",
"apiextensionsClient",
",",
"err",
":=",
"newClient",
"(",
"k8sRestConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"newCfg",
",",
"err",
":=",
"providerInstance",
".",
"newConfig",
"(",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"modelUUID",
":=",
"newCfg",
".",
"UUID",
"(",
")",
"\n",
"if",
"modelUUID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"client",
":=",
"&",
"kubernetesClient",
"{",
"clock",
":",
"clock",
",",
"clientUnlocked",
":",
"k8sClient",
",",
"apiextensionsClientUnlocked",
":",
"apiextensionsClient",
",",
"envCfgUnlocked",
":",
"newCfg",
".",
"Config",
",",
"namespace",
":",
"newCfg",
".",
"Name",
"(",
")",
",",
"modelUUID",
":",
"modelUUID",
",",
"newWatcher",
":",
"newWatcher",
",",
"newClient",
":",
"newClient",
",",
"annotations",
":",
"k8sannotations",
".",
"New",
"(",
"nil",
")",
".",
"Add",
"(",
"annotationModelUUIDKey",
",",
"modelUUID",
")",
",",
"}",
"\n\n",
"if",
"controllerUUID",
"!=",
"\"",
"\"",
"{",
"// controllerUUID could be empty in add-k8s without -c because there might be no controller yet.",
"client",
".",
"annotations",
".",
"Add",
"(",
"annotationControllerUUIDKey",
",",
"controllerUUID",
")",
"\n",
"}",
"\n",
"return",
"client",
",",
"nil",
"\n",
"}"
] | // NewK8sBroker returns a kubernetes client for the specified k8s cluster. | [
"NewK8sBroker",
"returns",
"a",
"kubernetes",
"client",
"for",
"the",
"specified",
"k8s",
"cluster",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8s.go#L123-L163 |
3,895 | juju/juju | caas/kubernetes/provider/k8s.go | addAnnotations | func (k *kubernetesClient) addAnnotations(key, value string) k8sannotations.Annotation {
return k.annotations.Add(key, value)
} | go | func (k *kubernetesClient) addAnnotations(key, value string) k8sannotations.Annotation {
return k.annotations.Add(key, value)
} | [
"func",
"(",
"k",
"*",
"kubernetesClient",
")",
"addAnnotations",
"(",
"key",
",",
"value",
"string",
")",
"k8sannotations",
".",
"Annotation",
"{",
"return",
"k",
".",
"annotations",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"}"
] | // addAnnotations set an annotation to current namespace's annotations. | [
"addAnnotations",
"set",
"an",
"annotation",
"to",
"current",
"namespace",
"s",
"annotations",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8s.go#L171-L173 |
3,896 | juju/juju | caas/kubernetes/provider/k8s.go | Config | func (k *kubernetesClient) Config() *config.Config {
k.lock.Lock()
defer k.lock.Unlock()
cfg := k.envCfgUnlocked
return cfg
} | go | func (k *kubernetesClient) Config() *config.Config {
k.lock.Lock()
defer k.lock.Unlock()
cfg := k.envCfgUnlocked
return cfg
} | [
"func",
"(",
"k",
"*",
"kubernetesClient",
")",
"Config",
"(",
")",
"*",
"config",
".",
"Config",
"{",
"k",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"k",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"cfg",
":=",
"k",
".",
"envCfgUnlocked",
"\n",
"return",
"cfg",
"\n",
"}"
] | // Config returns environ config. | [
"Config",
"returns",
"environ",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8s.go#L190-L195 |
3,897 | juju/juju | caas/kubernetes/provider/k8s.go | PrepareForBootstrap | func (k *kubernetesClient) PrepareForBootstrap(ctx environs.BootstrapContext, controllerName string) error {
alreadyExistErr := errors.NewAlreadyExists(nil,
fmt.Sprintf(`a controller called %q already exists on this k8s cluster.
Please bootstrap again and choose a different controller name.`, controllerName),
)
k.namespace = DecideControllerNamespace(controllerName)
// ensure no existing namespace has the same name.
_, err := k.getNamespaceByName(k.namespace)
if err == nil {
return alreadyExistErr
}
if !errors.IsNotFound(err) {
return errors.Trace(err)
}
// Good, no existing namespace has the same name.
// Now, try to find if there is any existing controller running in this cluster.
// Note: we have to do this check before we are confident to support multi controllers running in same k8s cluster.
_, err = k.listNamespacesByAnnotations(k.annotations)
if err == nil {
return alreadyExistErr
}
if !errors.IsNotFound(err) {
return errors.Trace(err)
}
// All good, no existing controller found on the cluster.
// The namespace will be set to controller-name in newcontrollerStack.
// do validation on storage class.
_, err = k.validateOperatorStorage()
return errors.Trace(err)
} | go | func (k *kubernetesClient) PrepareForBootstrap(ctx environs.BootstrapContext, controllerName string) error {
alreadyExistErr := errors.NewAlreadyExists(nil,
fmt.Sprintf(`a controller called %q already exists on this k8s cluster.
Please bootstrap again and choose a different controller name.`, controllerName),
)
k.namespace = DecideControllerNamespace(controllerName)
// ensure no existing namespace has the same name.
_, err := k.getNamespaceByName(k.namespace)
if err == nil {
return alreadyExistErr
}
if !errors.IsNotFound(err) {
return errors.Trace(err)
}
// Good, no existing namespace has the same name.
// Now, try to find if there is any existing controller running in this cluster.
// Note: we have to do this check before we are confident to support multi controllers running in same k8s cluster.
_, err = k.listNamespacesByAnnotations(k.annotations)
if err == nil {
return alreadyExistErr
}
if !errors.IsNotFound(err) {
return errors.Trace(err)
}
// All good, no existing controller found on the cluster.
// The namespace will be set to controller-name in newcontrollerStack.
// do validation on storage class.
_, err = k.validateOperatorStorage()
return errors.Trace(err)
} | [
"func",
"(",
"k",
"*",
"kubernetesClient",
")",
"PrepareForBootstrap",
"(",
"ctx",
"environs",
".",
"BootstrapContext",
",",
"controllerName",
"string",
")",
"error",
"{",
"alreadyExistErr",
":=",
"errors",
".",
"NewAlreadyExists",
"(",
"nil",
",",
"fmt",
".",
"Sprintf",
"(",
"`a controller called %q already exists on this k8s cluster.\nPlease bootstrap again and choose a different controller name.`",
",",
"controllerName",
")",
",",
")",
"\n\n",
"k",
".",
"namespace",
"=",
"DecideControllerNamespace",
"(",
"controllerName",
")",
"\n\n",
"// ensure no existing namespace has the same name.",
"_",
",",
"err",
":=",
"k",
".",
"getNamespaceByName",
"(",
"k",
".",
"namespace",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"alreadyExistErr",
"\n",
"}",
"\n",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Good, no existing namespace has the same name.",
"// Now, try to find if there is any existing controller running in this cluster.",
"// Note: we have to do this check before we are confident to support multi controllers running in same k8s cluster.",
"_",
",",
"err",
"=",
"k",
".",
"listNamespacesByAnnotations",
"(",
"k",
".",
"annotations",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"alreadyExistErr",
"\n",
"}",
"\n",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// All good, no existing controller found on the cluster.",
"// The namespace will be set to controller-name in newcontrollerStack.",
"// do validation on storage class.",
"_",
",",
"err",
"=",
"k",
".",
"validateOperatorStorage",
"(",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // PrepareForBootstrap prepares for bootstraping a controller. | [
"PrepareForBootstrap",
"prepares",
"for",
"bootstraping",
"a",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8s.go#L236-L269 |
3,898 | juju/juju | caas/kubernetes/provider/k8s.go | Create | func (k *kubernetesClient) Create(context.ProviderCallContext, environs.CreateParams) error {
// must raise errors.AlreadyExistsf if it's already exist.
return k.createNamespace(k.namespace)
} | go | func (k *kubernetesClient) Create(context.ProviderCallContext, environs.CreateParams) error {
// must raise errors.AlreadyExistsf if it's already exist.
return k.createNamespace(k.namespace)
} | [
"func",
"(",
"k",
"*",
"kubernetesClient",
")",
"Create",
"(",
"context",
".",
"ProviderCallContext",
",",
"environs",
".",
"CreateParams",
")",
"error",
"{",
"// must raise errors.AlreadyExistsf if it's already exist.",
"return",
"k",
".",
"createNamespace",
"(",
"k",
".",
"namespace",
")",
"\n",
"}"
] | // Create implements environs.BootstrapEnviron. | [
"Create",
"implements",
"environs",
".",
"BootstrapEnviron",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8s.go#L272-L275 |
3,899 | juju/juju | caas/kubernetes/provider/k8s.go | Bootstrap | func (k *kubernetesClient) Bootstrap(
ctx environs.BootstrapContext,
callCtx context.ProviderCallContext,
args environs.BootstrapParams,
) (*environs.BootstrapResult, error) {
if args.BootstrapSeries != "" {
return nil, errors.NotSupportedf("set series for bootstrapping to kubernetes")
}
storageClass, err := k.validateOperatorStorage()
if err != nil {
return nil, errors.Trace(err)
}
finalizer := func(ctx environs.BootstrapContext, pcfg *podcfg.ControllerPodConfig, opts environs.BootstrapDialOpts) (err error) {
if err = podcfg.FinishControllerPodConfig(pcfg, k.Config()); err != nil {
return errors.Trace(err)
}
if err = pcfg.VerifyConfig(); err != nil {
return errors.Trace(err)
}
logger.Debugf("controller pod config: \n%+v", pcfg)
// validate hosted model name if we need to create it.
if hostedModelName, has := pcfg.GetHostedModel(); has {
_, err := k.getNamespaceByName(hostedModelName)
if err == nil {
return errors.NewAlreadyExists(nil,
fmt.Sprintf(`
namespace %q already exists in the cluster,
please choose a different hosted model name then try again.`, hostedModelName),
)
}
if !errors.IsNotFound(err) {
return errors.Trace(err)
}
// hosted model is all good.
}
// we use controller name to name controller namespace in bootstrap time.
setControllerNamespace := func(controllerName string, broker *kubernetesClient) error {
nsName := DecideControllerNamespace(controllerName)
_, err := broker.GetNamespace(nsName)
if errors.IsNotFound(err) {
// all good.
broker.SetNamespace(nsName)
// ensure controller specific annotations.
_ = broker.addAnnotations(annotationControllerIsControllerKey, "true")
return nil
}
if err == nil {
// this should never happen because we avoid it in broker.PrepareForBootstrap before reaching here.
return errors.NotValidf("existing namespace %q found", broker.namespace)
}
return errors.Trace(err)
}
if err := setControllerNamespace(pcfg.ControllerName, k); err != nil {
return errors.Trace(err)
}
// create configmap, secret, volume, statefulset, etc resources for controller stack.
controllerStack, err := newcontrollerStack(ctx, JujuControllerStackName, storageClass, k, pcfg)
if err != nil {
return errors.Trace(err)
}
return errors.Annotate(
controllerStack.Deploy(),
"creating controller stack for controller",
)
}
return &environs.BootstrapResult{
// TODO(bootstrap): review this default arch and series(required for determining DataDir etc.) later.
Arch: arch.AMD64,
Series: jujuversion.SupportedLTS(),
CaasBootstrapFinalizer: finalizer,
}, nil
} | go | func (k *kubernetesClient) Bootstrap(
ctx environs.BootstrapContext,
callCtx context.ProviderCallContext,
args environs.BootstrapParams,
) (*environs.BootstrapResult, error) {
if args.BootstrapSeries != "" {
return nil, errors.NotSupportedf("set series for bootstrapping to kubernetes")
}
storageClass, err := k.validateOperatorStorage()
if err != nil {
return nil, errors.Trace(err)
}
finalizer := func(ctx environs.BootstrapContext, pcfg *podcfg.ControllerPodConfig, opts environs.BootstrapDialOpts) (err error) {
if err = podcfg.FinishControllerPodConfig(pcfg, k.Config()); err != nil {
return errors.Trace(err)
}
if err = pcfg.VerifyConfig(); err != nil {
return errors.Trace(err)
}
logger.Debugf("controller pod config: \n%+v", pcfg)
// validate hosted model name if we need to create it.
if hostedModelName, has := pcfg.GetHostedModel(); has {
_, err := k.getNamespaceByName(hostedModelName)
if err == nil {
return errors.NewAlreadyExists(nil,
fmt.Sprintf(`
namespace %q already exists in the cluster,
please choose a different hosted model name then try again.`, hostedModelName),
)
}
if !errors.IsNotFound(err) {
return errors.Trace(err)
}
// hosted model is all good.
}
// we use controller name to name controller namespace in bootstrap time.
setControllerNamespace := func(controllerName string, broker *kubernetesClient) error {
nsName := DecideControllerNamespace(controllerName)
_, err := broker.GetNamespace(nsName)
if errors.IsNotFound(err) {
// all good.
broker.SetNamespace(nsName)
// ensure controller specific annotations.
_ = broker.addAnnotations(annotationControllerIsControllerKey, "true")
return nil
}
if err == nil {
// this should never happen because we avoid it in broker.PrepareForBootstrap before reaching here.
return errors.NotValidf("existing namespace %q found", broker.namespace)
}
return errors.Trace(err)
}
if err := setControllerNamespace(pcfg.ControllerName, k); err != nil {
return errors.Trace(err)
}
// create configmap, secret, volume, statefulset, etc resources for controller stack.
controllerStack, err := newcontrollerStack(ctx, JujuControllerStackName, storageClass, k, pcfg)
if err != nil {
return errors.Trace(err)
}
return errors.Annotate(
controllerStack.Deploy(),
"creating controller stack for controller",
)
}
return &environs.BootstrapResult{
// TODO(bootstrap): review this default arch and series(required for determining DataDir etc.) later.
Arch: arch.AMD64,
Series: jujuversion.SupportedLTS(),
CaasBootstrapFinalizer: finalizer,
}, nil
} | [
"func",
"(",
"k",
"*",
"kubernetesClient",
")",
"Bootstrap",
"(",
"ctx",
"environs",
".",
"BootstrapContext",
",",
"callCtx",
"context",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"BootstrapParams",
",",
")",
"(",
"*",
"environs",
".",
"BootstrapResult",
",",
"error",
")",
"{",
"if",
"args",
".",
"BootstrapSeries",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"storageClass",
",",
"err",
":=",
"k",
".",
"validateOperatorStorage",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"finalizer",
":=",
"func",
"(",
"ctx",
"environs",
".",
"BootstrapContext",
",",
"pcfg",
"*",
"podcfg",
".",
"ControllerPodConfig",
",",
"opts",
"environs",
".",
"BootstrapDialOpts",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"podcfg",
".",
"FinishControllerPodConfig",
"(",
"pcfg",
",",
"k",
".",
"Config",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"pcfg",
".",
"VerifyConfig",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"pcfg",
")",
"\n\n",
"// validate hosted model name if we need to create it.",
"if",
"hostedModelName",
",",
"has",
":=",
"pcfg",
".",
"GetHostedModel",
"(",
")",
";",
"has",
"{",
"_",
",",
"err",
":=",
"k",
".",
"getNamespaceByName",
"(",
"hostedModelName",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"errors",
".",
"NewAlreadyExists",
"(",
"nil",
",",
"fmt",
".",
"Sprintf",
"(",
"`\nnamespace %q already exists in the cluster,\nplease choose a different hosted model name then try again.`",
",",
"hostedModelName",
")",
",",
")",
"\n",
"}",
"\n",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// hosted model is all good.",
"}",
"\n\n",
"// we use controller name to name controller namespace in bootstrap time.",
"setControllerNamespace",
":=",
"func",
"(",
"controllerName",
"string",
",",
"broker",
"*",
"kubernetesClient",
")",
"error",
"{",
"nsName",
":=",
"DecideControllerNamespace",
"(",
"controllerName",
")",
"\n\n",
"_",
",",
"err",
":=",
"broker",
".",
"GetNamespace",
"(",
"nsName",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"// all good.",
"broker",
".",
"SetNamespace",
"(",
"nsName",
")",
"\n",
"// ensure controller specific annotations.",
"_",
"=",
"broker",
".",
"addAnnotations",
"(",
"annotationControllerIsControllerKey",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// this should never happen because we avoid it in broker.PrepareForBootstrap before reaching here.",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"broker",
".",
"namespace",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"setControllerNamespace",
"(",
"pcfg",
".",
"ControllerName",
",",
"k",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// create configmap, secret, volume, statefulset, etc resources for controller stack.",
"controllerStack",
",",
"err",
":=",
"newcontrollerStack",
"(",
"ctx",
",",
"JujuControllerStackName",
",",
"storageClass",
",",
"k",
",",
"pcfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotate",
"(",
"controllerStack",
".",
"Deploy",
"(",
")",
",",
"\"",
"\"",
",",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"environs",
".",
"BootstrapResult",
"{",
"// TODO(bootstrap): review this default arch and series(required for determining DataDir etc.) later.",
"Arch",
":",
"arch",
".",
"AMD64",
",",
"Series",
":",
"jujuversion",
".",
"SupportedLTS",
"(",
")",
",",
"CaasBootstrapFinalizer",
":",
"finalizer",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Bootstrap deploys controller with mongoDB together into k8s cluster. | [
"Bootstrap",
"deploys",
"controller",
"with",
"mongoDB",
"together",
"into",
"k8s",
"cluster",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8s.go#L278-L360 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.