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
|
---|---|---|---|---|---|---|---|---|---|---|---|
156,600 | juju/juju | container/lxd/network.go | ensureDefaultNetworking | func (s *Server) ensureDefaultNetworking(profile *api.Profile, eTag string) error {
net, _, err := s.GetNetwork(network.DefaultLXDBridge)
if err != nil {
if !IsLXDNotFound(err) {
return errors.Trace(err)
}
req := api.NetworksPost{
Name: network.DefaultLXDBridge,
Type: "bridge",
Managed: true,
NetworkPut: api.NetworkPut{Config: map[string]string{
"ipv4.address": "auto",
"ipv4.nat": "true",
"ipv6.address": "none",
"ipv6.nat": "false",
}},
}
err := s.CreateNetwork(req)
if err != nil {
return errors.Trace(err)
}
net, _, err = s.GetNetwork(network.DefaultLXDBridge)
if err != nil {
return errors.Trace(err)
}
} else {
if err := verifyNoIPv6(net); err != nil {
return errors.Trace(err)
}
}
s.localBridgeName = network.DefaultLXDBridge
nicName := generateNICDeviceName(profile)
if nicName == "" {
return errors.Errorf("failed to generate a unique device name for profile %q", profile.Name)
}
// Add the new device with the bridge as its parent.
nicType := nicTypeMACVLAN
if net.Type == "bridge" {
nicType = nicTypeBridged
}
profile.Devices[nicName] = device{
"type": nic,
"nictype": nicType,
"parent": network.DefaultLXDBridge,
}
if err := s.UpdateProfile(profile.Name, profile.Writable(), eTag); err != nil {
return errors.Trace(err)
}
logger.Debugf("created new nic device %q in profile %q", nicName, profile.Name)
return nil
} | go | func (s *Server) ensureDefaultNetworking(profile *api.Profile, eTag string) error {
net, _, err := s.GetNetwork(network.DefaultLXDBridge)
if err != nil {
if !IsLXDNotFound(err) {
return errors.Trace(err)
}
req := api.NetworksPost{
Name: network.DefaultLXDBridge,
Type: "bridge",
Managed: true,
NetworkPut: api.NetworkPut{Config: map[string]string{
"ipv4.address": "auto",
"ipv4.nat": "true",
"ipv6.address": "none",
"ipv6.nat": "false",
}},
}
err := s.CreateNetwork(req)
if err != nil {
return errors.Trace(err)
}
net, _, err = s.GetNetwork(network.DefaultLXDBridge)
if err != nil {
return errors.Trace(err)
}
} else {
if err := verifyNoIPv6(net); err != nil {
return errors.Trace(err)
}
}
s.localBridgeName = network.DefaultLXDBridge
nicName := generateNICDeviceName(profile)
if nicName == "" {
return errors.Errorf("failed to generate a unique device name for profile %q", profile.Name)
}
// Add the new device with the bridge as its parent.
nicType := nicTypeMACVLAN
if net.Type == "bridge" {
nicType = nicTypeBridged
}
profile.Devices[nicName] = device{
"type": nic,
"nictype": nicType,
"parent": network.DefaultLXDBridge,
}
if err := s.UpdateProfile(profile.Name, profile.Writable(), eTag); err != nil {
return errors.Trace(err)
}
logger.Debugf("created new nic device %q in profile %q", nicName, profile.Name)
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"ensureDefaultNetworking",
"(",
"profile",
"*",
"api",
".",
"Profile",
",",
"eTag",
"string",
")",
"error",
"{",
"net",
",",
"_",
",",
"err",
":=",
"s",
".",
"GetNetwork",
"(",
"network",
".",
"DefaultLXDBridge",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"IsLXDNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"req",
":=",
"api",
".",
"NetworksPost",
"{",
"Name",
":",
"network",
".",
"DefaultLXDBridge",
",",
"Type",
":",
"\"",
"\"",
",",
"Managed",
":",
"true",
",",
"NetworkPut",
":",
"api",
".",
"NetworkPut",
"{",
"Config",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"s",
".",
"CreateNetwork",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"net",
",",
"_",
",",
"err",
"=",
"s",
".",
"GetNetwork",
"(",
"network",
".",
"DefaultLXDBridge",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"verifyNoIPv6",
"(",
"net",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"s",
".",
"localBridgeName",
"=",
"network",
".",
"DefaultLXDBridge",
"\n\n",
"nicName",
":=",
"generateNICDeviceName",
"(",
"profile",
")",
"\n",
"if",
"nicName",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"profile",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"// Add the new device with the bridge as its parent.",
"nicType",
":=",
"nicTypeMACVLAN",
"\n",
"if",
"net",
".",
"Type",
"==",
"\"",
"\"",
"{",
"nicType",
"=",
"nicTypeBridged",
"\n",
"}",
"\n",
"profile",
".",
"Devices",
"[",
"nicName",
"]",
"=",
"device",
"{",
"\"",
"\"",
":",
"nic",
",",
"\"",
"\"",
":",
"nicType",
",",
"\"",
"\"",
":",
"network",
".",
"DefaultLXDBridge",
",",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"UpdateProfile",
"(",
"profile",
".",
"Name",
",",
"profile",
".",
"Writable",
"(",
")",
",",
"eTag",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"nicName",
",",
"profile",
".",
"Name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ensureDefaultNetworking ensures that the default LXD bridge exists,
// that it is not configured to use IPv6, and that a NIC device exists in
// the input profile.
// An error is returned if the bridge exists with IPv6 configuration.
// If the bridge does not exist, it is created. | [
"ensureDefaultNetworking",
"ensures",
"that",
"the",
"default",
"LXD",
"bridge",
"exists",
"that",
"it",
"is",
"not",
"configured",
"to",
"use",
"IPv6",
"and",
"that",
"a",
"NIC",
"device",
"exists",
"in",
"the",
"input",
"profile",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"bridge",
"exists",
"with",
"IPv6",
"configuration",
".",
"If",
"the",
"bridge",
"does",
"not",
"exist",
"it",
"is",
"created",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/network.go#L132-L186 |
156,601 | juju/juju | container/lxd/network.go | verifyNICsWithAPI | func (s *Server) verifyNICsWithAPI(nics map[string]device) error {
checked := make([]string, 0, len(nics))
var ipV6ErrMsg error
for name, nic := range nics {
checked = append(checked, name)
if !isValidNICType(nic) {
continue
}
netName := nic["parent"]
if netName == "" {
continue
}
net, _, err := s.GetNetwork(netName)
if err != nil {
return errors.Annotatef(err, "retrieving network %q", netName)
}
if err := verifyNoIPv6(net); err != nil {
ipV6ErrMsg = err
continue
}
logger.Tracef("found usable network device %q with parent %q", name, netName)
s.localBridgeName = netName
return nil
}
// A nic with valid type found, but the network configures IPv6.
if ipV6ErrMsg != nil {
return ipV6ErrMsg
}
// No nics with a nictype of nicTypeBridged, nicTypeMACVLAN was found.
return errors.Errorf(fmt.Sprintf(
"no network device found with nictype %q or %q"+
"\n\tthe following devices were checked: %s"+
"\nNote: juju does not support IPv6."+
"\nReconfigure lxd to use a network of type %q or %q, disabling IPv6.",
nicTypeBridged, nicTypeMACVLAN, strings.Join(checked, ", "), nicTypeBridged, nicTypeMACVLAN))
} | go | func (s *Server) verifyNICsWithAPI(nics map[string]device) error {
checked := make([]string, 0, len(nics))
var ipV6ErrMsg error
for name, nic := range nics {
checked = append(checked, name)
if !isValidNICType(nic) {
continue
}
netName := nic["parent"]
if netName == "" {
continue
}
net, _, err := s.GetNetwork(netName)
if err != nil {
return errors.Annotatef(err, "retrieving network %q", netName)
}
if err := verifyNoIPv6(net); err != nil {
ipV6ErrMsg = err
continue
}
logger.Tracef("found usable network device %q with parent %q", name, netName)
s.localBridgeName = netName
return nil
}
// A nic with valid type found, but the network configures IPv6.
if ipV6ErrMsg != nil {
return ipV6ErrMsg
}
// No nics with a nictype of nicTypeBridged, nicTypeMACVLAN was found.
return errors.Errorf(fmt.Sprintf(
"no network device found with nictype %q or %q"+
"\n\tthe following devices were checked: %s"+
"\nNote: juju does not support IPv6."+
"\nReconfigure lxd to use a network of type %q or %q, disabling IPv6.",
nicTypeBridged, nicTypeMACVLAN, strings.Join(checked, ", "), nicTypeBridged, nicTypeMACVLAN))
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"verifyNICsWithAPI",
"(",
"nics",
"map",
"[",
"string",
"]",
"device",
")",
"error",
"{",
"checked",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"nics",
")",
")",
"\n",
"var",
"ipV6ErrMsg",
"error",
"\n",
"for",
"name",
",",
"nic",
":=",
"range",
"nics",
"{",
"checked",
"=",
"append",
"(",
"checked",
",",
"name",
")",
"\n\n",
"if",
"!",
"isValidNICType",
"(",
"nic",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"netName",
":=",
"nic",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"netName",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"net",
",",
"_",
",",
"err",
":=",
"s",
".",
"GetNetwork",
"(",
"netName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"netName",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"verifyNoIPv6",
"(",
"net",
")",
";",
"err",
"!=",
"nil",
"{",
"ipV6ErrMsg",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"name",
",",
"netName",
")",
"\n",
"s",
".",
"localBridgeName",
"=",
"netName",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// A nic with valid type found, but the network configures IPv6.",
"if",
"ipV6ErrMsg",
"!=",
"nil",
"{",
"return",
"ipV6ErrMsg",
"\n",
"}",
"\n\n",
"// No nics with a nictype of nicTypeBridged, nicTypeMACVLAN was found.",
"return",
"errors",
".",
"Errorf",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"\"",
"\\n",
"\\t",
"\"",
"+",
"\"",
"\\n",
"\"",
"+",
"\"",
"\\n",
"\"",
",",
"nicTypeBridged",
",",
"nicTypeMACVLAN",
",",
"strings",
".",
"Join",
"(",
"checked",
",",
"\"",
"\"",
")",
",",
"nicTypeBridged",
",",
"nicTypeMACVLAN",
")",
")",
"\n",
"}"
] | // verifyNICsWithAPI uses the LXD network API to check if one of the input NIC
// devices is suitable for LXD to work with Juju. | [
"verifyNICsWithAPI",
"uses",
"the",
"LXD",
"network",
"API",
"to",
"check",
"if",
"one",
"of",
"the",
"input",
"NIC",
"devices",
"is",
"suitable",
"for",
"LXD",
"to",
"work",
"with",
"Juju",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/network.go#L190-L231 |
156,602 | juju/juju | container/lxd/network.go | verifyNICsWithConfigFile | func (s *Server) verifyNICsWithConfigFile(nics map[string]device, reader func(string) ([]byte, error)) error {
netName, err := checkBridgeConfigFile(reader)
if err != nil {
return errors.Trace(err)
}
checked := make([]string, 0, len(nics))
for name, nic := range nics {
checked = append(checked, name)
if nic["parent"] != netName {
continue
}
if !isValidNICType(nic) {
continue
}
logger.Tracef("found usable network device %q with parent %q", name, netName)
s.localBridgeName = netName
return nil
}
return errors.Errorf("no network device found with nictype %q or %q that uses the configured bridge in %s"+
"\n\tthe following devices were checked: %v", nicTypeBridged, nicTypeMACVLAN, BridgeConfigFile, checked)
} | go | func (s *Server) verifyNICsWithConfigFile(nics map[string]device, reader func(string) ([]byte, error)) error {
netName, err := checkBridgeConfigFile(reader)
if err != nil {
return errors.Trace(err)
}
checked := make([]string, 0, len(nics))
for name, nic := range nics {
checked = append(checked, name)
if nic["parent"] != netName {
continue
}
if !isValidNICType(nic) {
continue
}
logger.Tracef("found usable network device %q with parent %q", name, netName)
s.localBridgeName = netName
return nil
}
return errors.Errorf("no network device found with nictype %q or %q that uses the configured bridge in %s"+
"\n\tthe following devices were checked: %v", nicTypeBridged, nicTypeMACVLAN, BridgeConfigFile, checked)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"verifyNICsWithConfigFile",
"(",
"nics",
"map",
"[",
"string",
"]",
"device",
",",
"reader",
"func",
"(",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
")",
"error",
"{",
"netName",
",",
"err",
":=",
"checkBridgeConfigFile",
"(",
"reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"checked",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"nics",
")",
")",
"\n",
"for",
"name",
",",
"nic",
":=",
"range",
"nics",
"{",
"checked",
"=",
"append",
"(",
"checked",
",",
"name",
")",
"\n\n",
"if",
"nic",
"[",
"\"",
"\"",
"]",
"!=",
"netName",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"isValidNICType",
"(",
"nic",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"name",
",",
"netName",
")",
"\n",
"s",
".",
"localBridgeName",
"=",
"netName",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\\n",
"\\t",
"\"",
",",
"nicTypeBridged",
",",
"nicTypeMACVLAN",
",",
"BridgeConfigFile",
",",
"checked",
")",
"\n",
"}"
] | // verifyNICsWithConfigFile is recruited for legacy LXD installations.
// It checks the LXD bridge configuration file and ensure that one of the input
// devices is suitable for LXD to work with Juju. | [
"verifyNICsWithConfigFile",
"is",
"recruited",
"for",
"legacy",
"LXD",
"installations",
".",
"It",
"checks",
"the",
"LXD",
"bridge",
"configuration",
"file",
"and",
"ensure",
"that",
"one",
"of",
"the",
"input",
"devices",
"is",
"suitable",
"for",
"LXD",
"to",
"work",
"with",
"Juju",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/network.go#L236-L260 |
156,603 | juju/juju | container/lxd/network.go | getProfileNICs | func getProfileNICs(profile *api.Profile) map[string]device {
nics := make(map[string]device, len(profile.Devices))
for k, v := range profile.Devices {
if v["type"] == nic {
nics[k] = v
}
}
return nics
} | go | func getProfileNICs(profile *api.Profile) map[string]device {
nics := make(map[string]device, len(profile.Devices))
for k, v := range profile.Devices {
if v["type"] == nic {
nics[k] = v
}
}
return nics
} | [
"func",
"getProfileNICs",
"(",
"profile",
"*",
"api",
".",
"Profile",
")",
"map",
"[",
"string",
"]",
"device",
"{",
"nics",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"device",
",",
"len",
"(",
"profile",
".",
"Devices",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"profile",
".",
"Devices",
"{",
"if",
"v",
"[",
"\"",
"\"",
"]",
"==",
"nic",
"{",
"nics",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nics",
"\n",
"}"
] | // getProfileNICs iterates over the devices in the input profile and returns
// any that are of type "nic". | [
"getProfileNICs",
"iterates",
"over",
"the",
"devices",
"in",
"the",
"input",
"profile",
"and",
"returns",
"any",
"that",
"are",
"of",
"type",
"nic",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/network.go#L286-L294 |
156,604 | juju/juju | container/lxd/network.go | InterfaceInfoFromDevices | func InterfaceInfoFromDevices(nics map[string]device) ([]network.InterfaceInfo, error) {
interfaces := make([]network.InterfaceInfo, len(nics))
var i int
for name, device := range nics {
iInfo := network.InterfaceInfo{
InterfaceName: name,
ParentInterfaceName: device["parent"],
MACAddress: device["hwaddr"],
ConfigType: network.ConfigDHCP,
}
if device["mtu"] != "" {
mtu, err := strconv.Atoi(device["mtu"])
if err != nil {
return nil, errors.Annotate(err, "parsing device MTU")
}
iInfo.MTU = mtu
}
interfaces[i] = iInfo
i++
}
sortInterfacesByName(interfaces)
return interfaces, nil
} | go | func InterfaceInfoFromDevices(nics map[string]device) ([]network.InterfaceInfo, error) {
interfaces := make([]network.InterfaceInfo, len(nics))
var i int
for name, device := range nics {
iInfo := network.InterfaceInfo{
InterfaceName: name,
ParentInterfaceName: device["parent"],
MACAddress: device["hwaddr"],
ConfigType: network.ConfigDHCP,
}
if device["mtu"] != "" {
mtu, err := strconv.Atoi(device["mtu"])
if err != nil {
return nil, errors.Annotate(err, "parsing device MTU")
}
iInfo.MTU = mtu
}
interfaces[i] = iInfo
i++
}
sortInterfacesByName(interfaces)
return interfaces, nil
} | [
"func",
"InterfaceInfoFromDevices",
"(",
"nics",
"map",
"[",
"string",
"]",
"device",
")",
"(",
"[",
"]",
"network",
".",
"InterfaceInfo",
",",
"error",
")",
"{",
"interfaces",
":=",
"make",
"(",
"[",
"]",
"network",
".",
"InterfaceInfo",
",",
"len",
"(",
"nics",
")",
")",
"\n",
"var",
"i",
"int",
"\n",
"for",
"name",
",",
"device",
":=",
"range",
"nics",
"{",
"iInfo",
":=",
"network",
".",
"InterfaceInfo",
"{",
"InterfaceName",
":",
"name",
",",
"ParentInterfaceName",
":",
"device",
"[",
"\"",
"\"",
"]",
",",
"MACAddress",
":",
"device",
"[",
"\"",
"\"",
"]",
",",
"ConfigType",
":",
"network",
".",
"ConfigDHCP",
",",
"}",
"\n",
"if",
"device",
"[",
"\"",
"\"",
"]",
"!=",
"\"",
"\"",
"{",
"mtu",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"device",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"iInfo",
".",
"MTU",
"=",
"mtu",
"\n",
"}",
"\n\n",
"interfaces",
"[",
"i",
"]",
"=",
"iInfo",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"sortInterfacesByName",
"(",
"interfaces",
")",
"\n",
"return",
"interfaces",
",",
"nil",
"\n",
"}"
] | // InterfaceInfoFromDevices returns a slice of interface info congruent with the
// input LXD NIC devices.
// The output is used to generate cloud-init user-data congruent with the NICs
// that end up in the container. | [
"InterfaceInfoFromDevices",
"returns",
"a",
"slice",
"of",
"interface",
"info",
"congruent",
"with",
"the",
"input",
"LXD",
"NIC",
"devices",
".",
"The",
"output",
"is",
"used",
"to",
"generate",
"cloud",
"-",
"init",
"user",
"-",
"data",
"congruent",
"with",
"the",
"NICs",
"that",
"end",
"up",
"in",
"the",
"container",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/network.go#L410-L434 |
156,605 | juju/juju | container/lxd/network.go | DevicesFromInterfaceInfo | func DevicesFromInterfaceInfo(interfaces []network.InterfaceInfo) (map[string]device, []string, error) {
nics := make(map[string]device, len(interfaces))
var unknown []string
for _, v := range interfaces {
if v.InterfaceType == network.LoopbackInterface {
continue
}
if v.InterfaceType != network.EthernetInterface {
return nil, nil, errors.Errorf("interface type %q not supported", v.InterfaceType)
}
if v.ParentInterfaceName == "" {
return nil, nil, errors.Errorf("parent interface name is empty")
}
if v.CIDR == "" {
unknown = append(unknown, v.ParentInterfaceName)
}
nics[v.InterfaceName] = newNICDevice(v.InterfaceName, v.ParentInterfaceName, v.MACAddress, v.MTU)
}
return nics, unknown, nil
} | go | func DevicesFromInterfaceInfo(interfaces []network.InterfaceInfo) (map[string]device, []string, error) {
nics := make(map[string]device, len(interfaces))
var unknown []string
for _, v := range interfaces {
if v.InterfaceType == network.LoopbackInterface {
continue
}
if v.InterfaceType != network.EthernetInterface {
return nil, nil, errors.Errorf("interface type %q not supported", v.InterfaceType)
}
if v.ParentInterfaceName == "" {
return nil, nil, errors.Errorf("parent interface name is empty")
}
if v.CIDR == "" {
unknown = append(unknown, v.ParentInterfaceName)
}
nics[v.InterfaceName] = newNICDevice(v.InterfaceName, v.ParentInterfaceName, v.MACAddress, v.MTU)
}
return nics, unknown, nil
} | [
"func",
"DevicesFromInterfaceInfo",
"(",
"interfaces",
"[",
"]",
"network",
".",
"InterfaceInfo",
")",
"(",
"map",
"[",
"string",
"]",
"device",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"nics",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"device",
",",
"len",
"(",
"interfaces",
")",
")",
"\n",
"var",
"unknown",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"interfaces",
"{",
"if",
"v",
".",
"InterfaceType",
"==",
"network",
".",
"LoopbackInterface",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"v",
".",
"InterfaceType",
"!=",
"network",
".",
"EthernetInterface",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
".",
"InterfaceType",
")",
"\n",
"}",
"\n",
"if",
"v",
".",
"ParentInterfaceName",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"v",
".",
"CIDR",
"==",
"\"",
"\"",
"{",
"unknown",
"=",
"append",
"(",
"unknown",
",",
"v",
".",
"ParentInterfaceName",
")",
"\n",
"}",
"\n",
"nics",
"[",
"v",
".",
"InterfaceName",
"]",
"=",
"newNICDevice",
"(",
"v",
".",
"InterfaceName",
",",
"v",
".",
"ParentInterfaceName",
",",
"v",
".",
"MACAddress",
",",
"v",
".",
"MTU",
")",
"\n",
"}",
"\n\n",
"return",
"nics",
",",
"unknown",
",",
"nil",
"\n",
"}"
] | // DevicesFromInterfaceInfo uses the input interface info collection to create a
// map of network device configuration in the LXD format.
// Names for any networks without a known CIDR are returned in a slice. | [
"DevicesFromInterfaceInfo",
"uses",
"the",
"input",
"interface",
"info",
"collection",
"to",
"create",
"a",
"map",
"of",
"network",
"device",
"configuration",
"in",
"the",
"LXD",
"format",
".",
"Names",
"for",
"any",
"networks",
"without",
"a",
"known",
"CIDR",
"are",
"returned",
"in",
"a",
"slice",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/network.go#L455-L476 |
156,606 | juju/juju | apiserver/common/setstatus.go | NewApplicationStatusSetter | func NewApplicationStatusSetter(st *state.State, getCanModify GetAuthFunc, leadershipChecker leadership.Checker) *ApplicationStatusSetter {
return &ApplicationStatusSetter{
leadershipChecker: leadershipChecker,
st: st,
getCanModify: getCanModify,
}
} | go | func NewApplicationStatusSetter(st *state.State, getCanModify GetAuthFunc, leadershipChecker leadership.Checker) *ApplicationStatusSetter {
return &ApplicationStatusSetter{
leadershipChecker: leadershipChecker,
st: st,
getCanModify: getCanModify,
}
} | [
"func",
"NewApplicationStatusSetter",
"(",
"st",
"*",
"state",
".",
"State",
",",
"getCanModify",
"GetAuthFunc",
",",
"leadershipChecker",
"leadership",
".",
"Checker",
")",
"*",
"ApplicationStatusSetter",
"{",
"return",
"&",
"ApplicationStatusSetter",
"{",
"leadershipChecker",
":",
"leadershipChecker",
",",
"st",
":",
"st",
",",
"getCanModify",
":",
"getCanModify",
",",
"}",
"\n",
"}"
] | // NewApplicationStatusSetter returns a ServiceStatusSetter. | [
"NewApplicationStatusSetter",
"returns",
"a",
"ServiceStatusSetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/setstatus.go#L31-L37 |
156,607 | juju/juju | apiserver/common/setstatus.go | SetStatus | func (s *ApplicationStatusSetter) SetStatus(args params.SetStatus) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
canModify, err := s.getCanModify()
if err != nil {
return params.ErrorResults{}, err
}
for i, arg := range args.Entities {
// TODO(fwereade): the auth is basically nonsense, and basically only
// works by coincidence. Read carefully.
// We "know" that arg.Tag is either the calling unit or its service
// (because getCanModify is authUnitOrService, and we'll fail out if
// it isn't); and, in practice, it's always going to be the calling
// unit (because, /sigh, we don't actually use service tags to refer
// to services in this method).
tag, err := names.ParseTag(arg.Tag)
if err != nil {
result.Results[i].Error = ServerError(err)
continue
}
if !canModify(tag) {
result.Results[i].Error = ServerError(ErrPerm)
continue
}
unitTag, ok := tag.(names.UnitTag)
if !ok {
// No matter what the canModify says, if this entity is not
// a unit, we say "NO".
result.Results[i].Error = ServerError(ErrPerm)
continue
}
unitId := unitTag.Id()
// Now we have the unit, we can get the service that should have been
// specified in the first place...
serviceId, err := names.UnitApplication(unitId)
if err != nil {
result.Results[i].Error = ServerError(err)
continue
}
service, err := s.st.Application(serviceId)
if err != nil {
result.Results[i].Error = ServerError(err)
continue
}
// ...and set the status, conditional on the unit being (and remaining)
// service leader.
token := s.leadershipChecker.LeadershipCheck(serviceId, unitId)
// TODO(fwereade) pass token into SetStatus instead of checking here.
if err := token.Check(0, nil); err != nil {
// TODO(fwereade) this should probably be ErrPerm is certain cases,
// but I don't think I implemented an exported ErrNotLeader. I
// should have done, though.
result.Results[i].Error = ServerError(err)
continue
}
// TODO(perrito666) 2016-05-02 lp:1558657
now := time.Now()
sInfo := status.StatusInfo{
Status: status.Status(arg.Status),
Message: arg.Info,
Data: arg.Data,
Since: &now,
}
if err := service.SetStatus(sInfo); err != nil {
result.Results[i].Error = ServerError(err)
}
}
return result, nil
} | go | func (s *ApplicationStatusSetter) SetStatus(args params.SetStatus) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
canModify, err := s.getCanModify()
if err != nil {
return params.ErrorResults{}, err
}
for i, arg := range args.Entities {
// TODO(fwereade): the auth is basically nonsense, and basically only
// works by coincidence. Read carefully.
// We "know" that arg.Tag is either the calling unit or its service
// (because getCanModify is authUnitOrService, and we'll fail out if
// it isn't); and, in practice, it's always going to be the calling
// unit (because, /sigh, we don't actually use service tags to refer
// to services in this method).
tag, err := names.ParseTag(arg.Tag)
if err != nil {
result.Results[i].Error = ServerError(err)
continue
}
if !canModify(tag) {
result.Results[i].Error = ServerError(ErrPerm)
continue
}
unitTag, ok := tag.(names.UnitTag)
if !ok {
// No matter what the canModify says, if this entity is not
// a unit, we say "NO".
result.Results[i].Error = ServerError(ErrPerm)
continue
}
unitId := unitTag.Id()
// Now we have the unit, we can get the service that should have been
// specified in the first place...
serviceId, err := names.UnitApplication(unitId)
if err != nil {
result.Results[i].Error = ServerError(err)
continue
}
service, err := s.st.Application(serviceId)
if err != nil {
result.Results[i].Error = ServerError(err)
continue
}
// ...and set the status, conditional on the unit being (and remaining)
// service leader.
token := s.leadershipChecker.LeadershipCheck(serviceId, unitId)
// TODO(fwereade) pass token into SetStatus instead of checking here.
if err := token.Check(0, nil); err != nil {
// TODO(fwereade) this should probably be ErrPerm is certain cases,
// but I don't think I implemented an exported ErrNotLeader. I
// should have done, though.
result.Results[i].Error = ServerError(err)
continue
}
// TODO(perrito666) 2016-05-02 lp:1558657
now := time.Now()
sInfo := status.StatusInfo{
Status: status.Status(arg.Status),
Message: arg.Info,
Data: arg.Data,
Since: &now,
}
if err := service.SetStatus(sInfo); err != nil {
result.Results[i].Error = ServerError(err)
}
}
return result, nil
} | [
"func",
"(",
"s",
"*",
"ApplicationStatusSetter",
")",
"SetStatus",
"(",
"args",
"params",
".",
"SetStatus",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"if",
"len",
"(",
"args",
".",
"Entities",
")",
"==",
"0",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n\n",
"canModify",
",",
"err",
":=",
"s",
".",
"getCanModify",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"// TODO(fwereade): the auth is basically nonsense, and basically only",
"// works by coincidence. Read carefully.",
"// We \"know\" that arg.Tag is either the calling unit or its service",
"// (because getCanModify is authUnitOrService, and we'll fail out if",
"// it isn't); and, in practice, it's always going to be the calling",
"// unit (because, /sigh, we don't actually use service tags to refer",
"// to services in this method).",
"tag",
",",
"err",
":=",
"names",
".",
"ParseTag",
"(",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"canModify",
"(",
"tag",
")",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"unitTag",
",",
"ok",
":=",
"tag",
".",
"(",
"names",
".",
"UnitTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"// No matter what the canModify says, if this entity is not",
"// a unit, we say \"NO\".",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"ErrPerm",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"unitId",
":=",
"unitTag",
".",
"Id",
"(",
")",
"\n\n",
"// Now we have the unit, we can get the service that should have been",
"// specified in the first place...",
"serviceId",
",",
"err",
":=",
"names",
".",
"UnitApplication",
"(",
"unitId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"service",
",",
"err",
":=",
"s",
".",
"st",
".",
"Application",
"(",
"serviceId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// ...and set the status, conditional on the unit being (and remaining)",
"// service leader.",
"token",
":=",
"s",
".",
"leadershipChecker",
".",
"LeadershipCheck",
"(",
"serviceId",
",",
"unitId",
")",
"\n\n",
"// TODO(fwereade) pass token into SetStatus instead of checking here.",
"if",
"err",
":=",
"token",
".",
"Check",
"(",
"0",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"// TODO(fwereade) this should probably be ErrPerm is certain cases,",
"// but I don't think I implemented an exported ErrNotLeader. I",
"// should have done, though.",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"// TODO(perrito666) 2016-05-02 lp:1558657",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"sInfo",
":=",
"status",
".",
"StatusInfo",
"{",
"Status",
":",
"status",
".",
"Status",
"(",
"arg",
".",
"Status",
")",
",",
"Message",
":",
"arg",
".",
"Info",
",",
"Data",
":",
"arg",
".",
"Data",
",",
"Since",
":",
"&",
"now",
",",
"}",
"\n",
"if",
"err",
":=",
"service",
".",
"SetStatus",
"(",
"sInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetStatus sets the status on the service given by the unit in args if the unit is the leader. | [
"SetStatus",
"sets",
"the",
"status",
"on",
"the",
"service",
"given",
"by",
"the",
"unit",
"in",
"args",
"if",
"the",
"unit",
"is",
"the",
"leader",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/setstatus.go#L40-L120 |
156,608 | juju/juju | apiserver/common/setstatus.go | NewStatusSetter | func NewStatusSetter(st state.EntityFinder, getCanModify GetAuthFunc) *StatusSetter {
return &StatusSetter{
st: st,
getCanModify: getCanModify,
}
} | go | func NewStatusSetter(st state.EntityFinder, getCanModify GetAuthFunc) *StatusSetter {
return &StatusSetter{
st: st,
getCanModify: getCanModify,
}
} | [
"func",
"NewStatusSetter",
"(",
"st",
"state",
".",
"EntityFinder",
",",
"getCanModify",
"GetAuthFunc",
")",
"*",
"StatusSetter",
"{",
"return",
"&",
"StatusSetter",
"{",
"st",
":",
"st",
",",
"getCanModify",
":",
"getCanModify",
",",
"}",
"\n",
"}"
] | // NewStatusSetter returns a new StatusSetter. The GetAuthFunc will be
// used on each invocation of SetStatus to determine current
// permissions. | [
"NewStatusSetter",
"returns",
"a",
"new",
"StatusSetter",
".",
"The",
"GetAuthFunc",
"will",
"be",
"used",
"on",
"each",
"invocation",
"of",
"SetStatus",
"to",
"determine",
"current",
"permissions",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/setstatus.go#L132-L137 |
156,609 | juju/juju | apiserver/common/setstatus.go | FindEntity | func (ua *UnitAgentFinder) FindEntity(tag names.Tag) (state.Entity, error) {
_, ok := tag.(names.UnitTag)
if !ok {
return nil, errors.Errorf("unsupported tag %T", tag)
}
entity, err := ua.EntityFinder.FindEntity(tag)
if err != nil {
return nil, errors.Trace(err)
}
// this returns a state.Unit, but for testing we just cast to the minimal
// interface we need.
return entity.(hasAgent).Agent(), nil
} | go | func (ua *UnitAgentFinder) FindEntity(tag names.Tag) (state.Entity, error) {
_, ok := tag.(names.UnitTag)
if !ok {
return nil, errors.Errorf("unsupported tag %T", tag)
}
entity, err := ua.EntityFinder.FindEntity(tag)
if err != nil {
return nil, errors.Trace(err)
}
// this returns a state.Unit, but for testing we just cast to the minimal
// interface we need.
return entity.(hasAgent).Agent(), nil
} | [
"func",
"(",
"ua",
"*",
"UnitAgentFinder",
")",
"FindEntity",
"(",
"tag",
"names",
".",
"Tag",
")",
"(",
"state",
".",
"Entity",
",",
"error",
")",
"{",
"_",
",",
"ok",
":=",
"tag",
".",
"(",
"names",
".",
"UnitTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"entity",
",",
"err",
":=",
"ua",
".",
"EntityFinder",
".",
"FindEntity",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// this returns a state.Unit, but for testing we just cast to the minimal",
"// interface we need.",
"return",
"entity",
".",
"(",
"hasAgent",
")",
".",
"Agent",
"(",
")",
",",
"nil",
"\n",
"}"
] | // FindEntity implements state.EntityFinder and returns unit agents. | [
"FindEntity",
"implements",
"state",
".",
"EntityFinder",
"and",
"returns",
"unit",
"agents",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/setstatus.go#L264-L276 |
156,610 | juju/juju | provider/maas/storage.go | addressFileObject | func (stor *maas1Storage) addressFileObject(name string) gomaasapi.MAASObject {
return stor.maasClient.GetSubObject(name)
} | go | func (stor *maas1Storage) addressFileObject(name string) gomaasapi.MAASObject {
return stor.maasClient.GetSubObject(name)
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"addressFileObject",
"(",
"name",
"string",
")",
"gomaasapi",
".",
"MAASObject",
"{",
"return",
"stor",
".",
"maasClient",
".",
"GetSubObject",
"(",
"name",
")",
"\n",
"}"
] | // addressFileObject creates a MAASObject pointing to a given file.
// Takes out a lock on the storage object to get a consistent view. | [
"addressFileObject",
"creates",
"a",
"MAASObject",
"pointing",
"to",
"a",
"given",
"file",
".",
"Takes",
"out",
"a",
"lock",
"on",
"the",
"storage",
"object",
"to",
"get",
"a",
"consistent",
"view",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L50-L52 |
156,611 | juju/juju | provider/maas/storage.go | retrieveFileObject | func (stor *maas1Storage) retrieveFileObject(name string) (gomaasapi.MAASObject, error) {
obj, err := stor.addressFileObject(name).Get()
if err != nil {
noObj := gomaasapi.MAASObject{}
serverErr, ok := errors.Cause(err).(gomaasapi.ServerError)
if ok && serverErr.StatusCode == 404 {
return noObj, errors.NotFoundf("file '%s' not found", name)
}
msg := fmt.Errorf("could not access file '%s': %v", name, err)
return noObj, msg
}
return obj, nil
} | go | func (stor *maas1Storage) retrieveFileObject(name string) (gomaasapi.MAASObject, error) {
obj, err := stor.addressFileObject(name).Get()
if err != nil {
noObj := gomaasapi.MAASObject{}
serverErr, ok := errors.Cause(err).(gomaasapi.ServerError)
if ok && serverErr.StatusCode == 404 {
return noObj, errors.NotFoundf("file '%s' not found", name)
}
msg := fmt.Errorf("could not access file '%s': %v", name, err)
return noObj, msg
}
return obj, nil
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"retrieveFileObject",
"(",
"name",
"string",
")",
"(",
"gomaasapi",
".",
"MAASObject",
",",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"stor",
".",
"addressFileObject",
"(",
"name",
")",
".",
"Get",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"noObj",
":=",
"gomaasapi",
".",
"MAASObject",
"{",
"}",
"\n",
"serverErr",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"gomaasapi",
".",
"ServerError",
")",
"\n",
"if",
"ok",
"&&",
"serverErr",
".",
"StatusCode",
"==",
"404",
"{",
"return",
"noObj",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"return",
"noObj",
",",
"msg",
"\n",
"}",
"\n",
"return",
"obj",
",",
"nil",
"\n",
"}"
] | // retrieveFileObject retrieves the information of the named file,
// including its download URL and its contents, as a MAASObject.
//
// This may return many different errors, but specifically, it returns
// an error that satisfies errors.IsNotFound if the file did not
// exist.
//
// The function takes out a lock on the storage object. | [
"retrieveFileObject",
"retrieves",
"the",
"information",
"of",
"the",
"named",
"file",
"including",
"its",
"download",
"URL",
"and",
"its",
"contents",
"as",
"a",
"MAASObject",
".",
"This",
"may",
"return",
"many",
"different",
"errors",
"but",
"specifically",
"it",
"returns",
"an",
"error",
"that",
"satisfies",
"errors",
".",
"IsNotFound",
"if",
"the",
"file",
"did",
"not",
"exist",
".",
"The",
"function",
"takes",
"out",
"a",
"lock",
"on",
"the",
"storage",
"object",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L73-L85 |
156,612 | juju/juju | provider/maas/storage.go | Get | func (stor *maas1Storage) Get(name string) (io.ReadCloser, error) {
name = stor.prefixWithPrivateNamespace(name)
fileObj, err := stor.retrieveFileObject(name)
if err != nil {
return nil, err
}
data, err := fileObj.GetField("content")
if err != nil {
return nil, fmt.Errorf("could not extract file content for %s: %v", name, err)
}
buf, err := base64.StdEncoding.DecodeString(data)
if err != nil {
return nil, fmt.Errorf("bad data in file '%s': %v", name, err)
}
return ioutil.NopCloser(bytes.NewReader(buf)), nil
} | go | func (stor *maas1Storage) Get(name string) (io.ReadCloser, error) {
name = stor.prefixWithPrivateNamespace(name)
fileObj, err := stor.retrieveFileObject(name)
if err != nil {
return nil, err
}
data, err := fileObj.GetField("content")
if err != nil {
return nil, fmt.Errorf("could not extract file content for %s: %v", name, err)
}
buf, err := base64.StdEncoding.DecodeString(data)
if err != nil {
return nil, fmt.Errorf("bad data in file '%s': %v", name, err)
}
return ioutil.NopCloser(bytes.NewReader(buf)), nil
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"name",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"name",
")",
"\n",
"fileObj",
",",
"err",
":=",
"stor",
".",
"retrieveFileObject",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"data",
",",
"err",
":=",
"fileObj",
".",
"GetField",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"buf",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewReader",
"(",
"buf",
")",
")",
",",
"nil",
"\n",
"}"
] | // Get is specified in the StorageReader interface. | [
"Get",
"is",
"specified",
"in",
"the",
"StorageReader",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L88-L103 |
156,613 | juju/juju | provider/maas/storage.go | extractFilenames | func (stor *maas1Storage) extractFilenames(listResult gomaasapi.JSONObject) ([]string, error) {
privatePrefix := stor.prefixWithPrivateNamespace("")
list, err := listResult.GetArray()
if err != nil {
return nil, err
}
result := make([]string, len(list))
for index, entry := range list {
file, err := entry.GetMap()
if err != nil {
return nil, err
}
filename, err := file["filename"].GetString()
if err != nil {
return nil, err
}
// When listing files we need to return them without our special prefix.
result[index] = strings.TrimPrefix(filename, privatePrefix)
}
sort.Strings(result)
return result, nil
} | go | func (stor *maas1Storage) extractFilenames(listResult gomaasapi.JSONObject) ([]string, error) {
privatePrefix := stor.prefixWithPrivateNamespace("")
list, err := listResult.GetArray()
if err != nil {
return nil, err
}
result := make([]string, len(list))
for index, entry := range list {
file, err := entry.GetMap()
if err != nil {
return nil, err
}
filename, err := file["filename"].GetString()
if err != nil {
return nil, err
}
// When listing files we need to return them without our special prefix.
result[index] = strings.TrimPrefix(filename, privatePrefix)
}
sort.Strings(result)
return result, nil
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"extractFilenames",
"(",
"listResult",
"gomaasapi",
".",
"JSONObject",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"privatePrefix",
":=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"\"",
"\"",
")",
"\n",
"list",
",",
"err",
":=",
"listResult",
".",
"GetArray",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"list",
")",
")",
"\n",
"for",
"index",
",",
"entry",
":=",
"range",
"list",
"{",
"file",
",",
"err",
":=",
"entry",
".",
"GetMap",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"filename",
",",
"err",
":=",
"file",
"[",
"\"",
"\"",
"]",
".",
"GetString",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// When listing files we need to return them without our special prefix.",
"result",
"[",
"index",
"]",
"=",
"strings",
".",
"TrimPrefix",
"(",
"filename",
",",
"privatePrefix",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"result",
")",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // extractFilenames returns the filenames from a "list" operation on the
// MAAS API, sorted by name. | [
"extractFilenames",
"returns",
"the",
"filenames",
"from",
"a",
"list",
"operation",
"on",
"the",
"MAAS",
"API",
"sorted",
"by",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L107-L128 |
156,614 | juju/juju | provider/maas/storage.go | List | func (stor *maas1Storage) List(prefix string) ([]string, error) {
prefix = stor.prefixWithPrivateNamespace(prefix)
params := make(url.Values)
params.Add("prefix", prefix)
obj, err := stor.maasClient.CallGet("list", params)
if err != nil {
return nil, err
}
return stor.extractFilenames(obj)
} | go | func (stor *maas1Storage) List(prefix string) ([]string, error) {
prefix = stor.prefixWithPrivateNamespace(prefix)
params := make(url.Values)
params.Add("prefix", prefix)
obj, err := stor.maasClient.CallGet("list", params)
if err != nil {
return nil, err
}
return stor.extractFilenames(obj)
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"List",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"prefix",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"prefix",
")",
"\n",
"params",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
"prefix",
")",
"\n",
"obj",
",",
"err",
":=",
"stor",
".",
"maasClient",
".",
"CallGet",
"(",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"stor",
".",
"extractFilenames",
"(",
"obj",
")",
"\n",
"}"
] | // List is specified in the StorageReader interface. | [
"List",
"is",
"specified",
"in",
"the",
"StorageReader",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L131-L140 |
156,615 | juju/juju | provider/maas/storage.go | URL | func (stor *maas1Storage) URL(name string) (string, error) {
name = stor.prefixWithPrivateNamespace(name)
fileObj, err := stor.retrieveFileObject(name)
if err != nil {
return "", err
}
uri, err := fileObj.GetField("anon_resource_uri")
if err != nil {
msg := fmt.Errorf("could not get file's download URL (may be an outdated MAAS): %s", err)
return "", msg
}
partialURL, err := url.Parse(uri)
if err != nil {
return "", err
}
fullURL := fileObj.URL().ResolveReference(partialURL)
return fullURL.String(), nil
} | go | func (stor *maas1Storage) URL(name string) (string, error) {
name = stor.prefixWithPrivateNamespace(name)
fileObj, err := stor.retrieveFileObject(name)
if err != nil {
return "", err
}
uri, err := fileObj.GetField("anon_resource_uri")
if err != nil {
msg := fmt.Errorf("could not get file's download URL (may be an outdated MAAS): %s", err)
return "", msg
}
partialURL, err := url.Parse(uri)
if err != nil {
return "", err
}
fullURL := fileObj.URL().ResolveReference(partialURL)
return fullURL.String(), nil
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"URL",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"name",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"name",
")",
"\n",
"fileObj",
",",
"err",
":=",
"stor",
".",
"retrieveFileObject",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"uri",
",",
"err",
":=",
"fileObj",
".",
"GetField",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"msg",
"\n",
"}",
"\n\n",
"partialURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"fullURL",
":=",
"fileObj",
".",
"URL",
"(",
")",
".",
"ResolveReference",
"(",
"partialURL",
")",
"\n",
"return",
"fullURL",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // URL is specified in the StorageReader interface. | [
"URL",
"is",
"specified",
"in",
"the",
"StorageReader",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L143-L161 |
156,616 | juju/juju | provider/maas/storage.go | Put | func (stor *maas1Storage) Put(name string, r io.Reader, length int64) error {
name = stor.prefixWithPrivateNamespace(name)
data, err := ioutil.ReadAll(io.LimitReader(r, length))
if err != nil {
return err
}
params := url.Values{"filename": {name}}
files := map[string][]byte{"file": data}
_, err = stor.maasClient.CallPostFiles("add", params, files)
return err
} | go | func (stor *maas1Storage) Put(name string, r io.Reader, length int64) error {
name = stor.prefixWithPrivateNamespace(name)
data, err := ioutil.ReadAll(io.LimitReader(r, length))
if err != nil {
return err
}
params := url.Values{"filename": {name}}
files := map[string][]byte{"file": data}
_, err = stor.maasClient.CallPostFiles("add", params, files)
return err
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"Put",
"(",
"name",
"string",
",",
"r",
"io",
".",
"Reader",
",",
"length",
"int64",
")",
"error",
"{",
"name",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"name",
")",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"io",
".",
"LimitReader",
"(",
"r",
",",
"length",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"params",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"name",
"}",
"}",
"\n",
"files",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
"{",
"\"",
"\"",
":",
"data",
"}",
"\n",
"_",
",",
"err",
"=",
"stor",
".",
"maasClient",
".",
"CallPostFiles",
"(",
"\"",
"\"",
",",
"params",
",",
"files",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Put is specified in the StorageWriter interface. | [
"Put",
"is",
"specified",
"in",
"the",
"StorageWriter",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L176-L186 |
156,617 | juju/juju | provider/maas/storage.go | Remove | func (stor *maas1Storage) Remove(name string) error {
name = stor.prefixWithPrivateNamespace(name)
// The only thing that can go wrong here, really, is that the file
// does not exist. But deletion is idempotent: deleting a file that
// is no longer there anyway is success, not failure.
stor.maasClient.GetSubObject(name).Delete()
return nil
} | go | func (stor *maas1Storage) Remove(name string) error {
name = stor.prefixWithPrivateNamespace(name)
// The only thing that can go wrong here, really, is that the file
// does not exist. But deletion is idempotent: deleting a file that
// is no longer there anyway is success, not failure.
stor.maasClient.GetSubObject(name).Delete()
return nil
} | [
"func",
"(",
"stor",
"*",
"maas1Storage",
")",
"Remove",
"(",
"name",
"string",
")",
"error",
"{",
"name",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"name",
")",
"\n",
"// The only thing that can go wrong here, really, is that the file",
"// does not exist. But deletion is idempotent: deleting a file that",
"// is no longer there anyway is success, not failure.",
"stor",
".",
"maasClient",
".",
"GetSubObject",
"(",
"name",
")",
".",
"Delete",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Remove is specified in the StorageWriter interface. | [
"Remove",
"is",
"specified",
"in",
"the",
"StorageWriter",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/storage.go#L189-L196 |
156,618 | juju/juju | apiserver/common/errors.go | IsUpgradeInProgressError | func IsUpgradeInProgressError(err error) bool {
if state.IsUpgradeInProgressError(err) {
return true
}
return errors.Cause(err) == params.UpgradeInProgressError
} | go | func IsUpgradeInProgressError(err error) bool {
if state.IsUpgradeInProgressError(err) {
return true
}
return errors.Cause(err) == params.UpgradeInProgressError
} | [
"func",
"IsUpgradeInProgressError",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"state",
".",
"IsUpgradeInProgressError",
"(",
"err",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"params",
".",
"UpgradeInProgressError",
"\n",
"}"
] | // IsUpgradeInProgress returns true if this error is caused
// by an upgrade in progress. | [
"IsUpgradeInProgress",
"returns",
"true",
"if",
"this",
"error",
"is",
"caused",
"by",
"an",
"upgrade",
"in",
"progress",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/errors.go#L83-L88 |
156,619 | juju/juju | apiserver/common/errors.go | IsRedirectError | func IsRedirectError(err error) bool {
_, ok := errors.Cause(err).(*RedirectError)
return ok
} | go | func IsRedirectError(err error) bool {
_, ok := errors.Cause(err).(*RedirectError)
return ok
} | [
"func",
"IsRedirectError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"RedirectError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsRedirectError returns true if err is caused by a RedirectError. | [
"IsRedirectError",
"returns",
"true",
"if",
"err",
"is",
"caused",
"by",
"a",
"RedirectError",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/errors.go#L109-L112 |
156,620 | juju/juju | apiserver/common/errors.go | OperationBlockedError | func OperationBlockedError(msg string) error {
if msg == "" {
msg = "the operation has been blocked"
}
return ¶ms.Error{
Message: msg,
Code: params.CodeOperationBlocked,
}
} | go | func OperationBlockedError(msg string) error {
if msg == "" {
msg = "the operation has been blocked"
}
return ¶ms.Error{
Message: msg,
Code: params.CodeOperationBlocked,
}
} | [
"func",
"OperationBlockedError",
"(",
"msg",
"string",
")",
"error",
"{",
"if",
"msg",
"==",
"\"",
"\"",
"{",
"msg",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"&",
"params",
".",
"Error",
"{",
"Message",
":",
"msg",
",",
"Code",
":",
"params",
".",
"CodeOperationBlocked",
",",
"}",
"\n",
"}"
] | // OperationBlockedError returns an error which signifies that
// an operation has been blocked; the message should describe
// what has been blocked. | [
"OperationBlockedError",
"returns",
"an",
"error",
"which",
"signifies",
"that",
"an",
"operation",
"has",
"been",
"blocked",
";",
"the",
"message",
"should",
"describe",
"what",
"has",
"been",
"blocked",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/errors.go#L131-L139 |
156,621 | juju/juju | apiserver/common/errors.go | ServerErrorAndStatus | func ServerErrorAndStatus(err error) (*params.Error, int) {
err1 := ServerError(err)
if err1 == nil {
return nil, http.StatusOK
}
status := http.StatusInternalServerError
switch err1.Code {
case params.CodeUnauthorized:
status = http.StatusUnauthorized
case params.CodeNotFound,
params.CodeUserNotFound,
params.CodeModelNotFound:
status = http.StatusNotFound
case params.CodeBadRequest:
status = http.StatusBadRequest
case params.CodeMethodNotAllowed:
status = http.StatusMethodNotAllowed
case params.CodeOperationBlocked:
// This should really be http.StatusForbidden but earlier versions
// of juju clients rely on the 400 status, so we leave it like that.
status = http.StatusBadRequest
case params.CodeForbidden:
status = http.StatusForbidden
case params.CodeDischargeRequired:
status = http.StatusUnauthorized
case params.CodeRetry:
status = http.StatusServiceUnavailable
case params.CodeRedirect:
status = http.StatusMovedPermanently
}
return err1, status
} | go | func ServerErrorAndStatus(err error) (*params.Error, int) {
err1 := ServerError(err)
if err1 == nil {
return nil, http.StatusOK
}
status := http.StatusInternalServerError
switch err1.Code {
case params.CodeUnauthorized:
status = http.StatusUnauthorized
case params.CodeNotFound,
params.CodeUserNotFound,
params.CodeModelNotFound:
status = http.StatusNotFound
case params.CodeBadRequest:
status = http.StatusBadRequest
case params.CodeMethodNotAllowed:
status = http.StatusMethodNotAllowed
case params.CodeOperationBlocked:
// This should really be http.StatusForbidden but earlier versions
// of juju clients rely on the 400 status, so we leave it like that.
status = http.StatusBadRequest
case params.CodeForbidden:
status = http.StatusForbidden
case params.CodeDischargeRequired:
status = http.StatusUnauthorized
case params.CodeRetry:
status = http.StatusServiceUnavailable
case params.CodeRedirect:
status = http.StatusMovedPermanently
}
return err1, status
} | [
"func",
"ServerErrorAndStatus",
"(",
"err",
"error",
")",
"(",
"*",
"params",
".",
"Error",
",",
"int",
")",
"{",
"err1",
":=",
"ServerError",
"(",
"err",
")",
"\n",
"if",
"err1",
"==",
"nil",
"{",
"return",
"nil",
",",
"http",
".",
"StatusOK",
"\n",
"}",
"\n",
"status",
":=",
"http",
".",
"StatusInternalServerError",
"\n",
"switch",
"err1",
".",
"Code",
"{",
"case",
"params",
".",
"CodeUnauthorized",
":",
"status",
"=",
"http",
".",
"StatusUnauthorized",
"\n",
"case",
"params",
".",
"CodeNotFound",
",",
"params",
".",
"CodeUserNotFound",
",",
"params",
".",
"CodeModelNotFound",
":",
"status",
"=",
"http",
".",
"StatusNotFound",
"\n",
"case",
"params",
".",
"CodeBadRequest",
":",
"status",
"=",
"http",
".",
"StatusBadRequest",
"\n",
"case",
"params",
".",
"CodeMethodNotAllowed",
":",
"status",
"=",
"http",
".",
"StatusMethodNotAllowed",
"\n",
"case",
"params",
".",
"CodeOperationBlocked",
":",
"// This should really be http.StatusForbidden but earlier versions",
"// of juju clients rely on the 400 status, so we leave it like that.",
"status",
"=",
"http",
".",
"StatusBadRequest",
"\n",
"case",
"params",
".",
"CodeForbidden",
":",
"status",
"=",
"http",
".",
"StatusForbidden",
"\n",
"case",
"params",
".",
"CodeDischargeRequired",
":",
"status",
"=",
"http",
".",
"StatusUnauthorized",
"\n",
"case",
"params",
".",
"CodeRetry",
":",
"status",
"=",
"http",
".",
"StatusServiceUnavailable",
"\n",
"case",
"params",
".",
"CodeRedirect",
":",
"status",
"=",
"http",
".",
"StatusMovedPermanently",
"\n",
"}",
"\n",
"return",
"err1",
",",
"status",
"\n",
"}"
] | // ServerErrorAndStatus is like ServerError but also
// returns an HTTP status code appropriate for using
// in a response holding the given error. | [
"ServerErrorAndStatus",
"is",
"like",
"ServerError",
"but",
"also",
"returns",
"an",
"HTTP",
"status",
"code",
"appropriate",
"for",
"using",
"in",
"a",
"response",
"holding",
"the",
"given",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/errors.go#L185-L216 |
156,622 | juju/juju | apiserver/common/errors.go | ServerError | func ServerError(err error) *params.Error {
if err == nil {
return nil
}
logger.Tracef("server RPC error %v", errors.Details(err))
var (
info map[string]interface{}
msg = err.Error()
)
// Skip past annotations when looking for the code.
err = errors.Cause(err)
code, ok := singletonCode(err)
switch {
case ok:
case errors.IsUnauthorized(err):
code = params.CodeUnauthorized
case errors.IsNotFound(err):
code = params.CodeNotFound
case errors.IsUserNotFound(err):
code = params.CodeUserNotFound
case errors.IsAlreadyExists(err):
code = params.CodeAlreadyExists
case errors.IsNotAssigned(err):
code = params.CodeNotAssigned
case state.IsHasAssignedUnitsError(err):
code = params.CodeHasAssignedUnits
case state.IsHasHostedModelsError(err):
code = params.CodeHasHostedModels
case state.IsHasPersistentStorageError(err):
code = params.CodeHasPersistentStorage
case state.IsModelNotEmptyError(err):
code = params.CodeModelNotEmpty
case isNoAddressSetError(err):
code = params.CodeNoAddressSet
case errors.IsNotProvisioned(err):
code = params.CodeNotProvisioned
case IsUpgradeInProgressError(err):
code = params.CodeUpgradeInProgress
case state.IsHasAttachmentsError(err):
code = params.CodeMachineHasAttachedStorage
case state.IsStorageAttachedError(err):
code = params.CodeStorageAttached
case isUnknownModelError(err):
code = params.CodeModelNotFound
case errors.IsNotSupported(err):
code = params.CodeNotSupported
case errors.IsBadRequest(err):
code = params.CodeBadRequest
case errors.IsMethodNotAllowed(err):
code = params.CodeMethodNotAllowed
case errors.IsNotImplemented(err):
code = params.CodeNotImplemented
case state.IsIncompatibleSeriesError(err):
code = params.CodeIncompatibleSeries
case IsDischargeRequiredError(err):
dischErr := errors.Cause(err).(*DischargeRequiredError)
code = params.CodeDischargeRequired
info = params.DischargeRequiredErrorInfo{
Macaroon: dischErr.Macaroon,
// One macaroon fits all.
MacaroonPath: "/",
}.AsMap()
case IsRedirectError(err):
redirErr := errors.Cause(err).(*RedirectError)
code = params.CodeRedirect
info = params.RedirectErrorInfo{
Servers: params.FromNetworkHostsPorts(redirErr.Servers),
CACert: redirErr.CACert,
ControllerAlias: redirErr.ControllerAlias,
}.AsMap()
default:
code = params.ErrCode(err)
}
return ¶ms.Error{
Message: msg,
Code: code,
Info: info,
}
} | go | func ServerError(err error) *params.Error {
if err == nil {
return nil
}
logger.Tracef("server RPC error %v", errors.Details(err))
var (
info map[string]interface{}
msg = err.Error()
)
// Skip past annotations when looking for the code.
err = errors.Cause(err)
code, ok := singletonCode(err)
switch {
case ok:
case errors.IsUnauthorized(err):
code = params.CodeUnauthorized
case errors.IsNotFound(err):
code = params.CodeNotFound
case errors.IsUserNotFound(err):
code = params.CodeUserNotFound
case errors.IsAlreadyExists(err):
code = params.CodeAlreadyExists
case errors.IsNotAssigned(err):
code = params.CodeNotAssigned
case state.IsHasAssignedUnitsError(err):
code = params.CodeHasAssignedUnits
case state.IsHasHostedModelsError(err):
code = params.CodeHasHostedModels
case state.IsHasPersistentStorageError(err):
code = params.CodeHasPersistentStorage
case state.IsModelNotEmptyError(err):
code = params.CodeModelNotEmpty
case isNoAddressSetError(err):
code = params.CodeNoAddressSet
case errors.IsNotProvisioned(err):
code = params.CodeNotProvisioned
case IsUpgradeInProgressError(err):
code = params.CodeUpgradeInProgress
case state.IsHasAttachmentsError(err):
code = params.CodeMachineHasAttachedStorage
case state.IsStorageAttachedError(err):
code = params.CodeStorageAttached
case isUnknownModelError(err):
code = params.CodeModelNotFound
case errors.IsNotSupported(err):
code = params.CodeNotSupported
case errors.IsBadRequest(err):
code = params.CodeBadRequest
case errors.IsMethodNotAllowed(err):
code = params.CodeMethodNotAllowed
case errors.IsNotImplemented(err):
code = params.CodeNotImplemented
case state.IsIncompatibleSeriesError(err):
code = params.CodeIncompatibleSeries
case IsDischargeRequiredError(err):
dischErr := errors.Cause(err).(*DischargeRequiredError)
code = params.CodeDischargeRequired
info = params.DischargeRequiredErrorInfo{
Macaroon: dischErr.Macaroon,
// One macaroon fits all.
MacaroonPath: "/",
}.AsMap()
case IsRedirectError(err):
redirErr := errors.Cause(err).(*RedirectError)
code = params.CodeRedirect
info = params.RedirectErrorInfo{
Servers: params.FromNetworkHostsPorts(redirErr.Servers),
CACert: redirErr.CACert,
ControllerAlias: redirErr.ControllerAlias,
}.AsMap()
default:
code = params.ErrCode(err)
}
return ¶ms.Error{
Message: msg,
Code: code,
Info: info,
}
} | [
"func",
"ServerError",
"(",
"err",
"error",
")",
"*",
"params",
".",
"Error",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"errors",
".",
"Details",
"(",
"err",
")",
")",
"\n\n",
"var",
"(",
"info",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"msg",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
")",
"\n\n",
"// Skip past annotations when looking for the code.",
"err",
"=",
"errors",
".",
"Cause",
"(",
"err",
")",
"\n",
"code",
",",
"ok",
":=",
"singletonCode",
"(",
"err",
")",
"\n",
"switch",
"{",
"case",
"ok",
":",
"case",
"errors",
".",
"IsUnauthorized",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeUnauthorized",
"\n",
"case",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeNotFound",
"\n",
"case",
"errors",
".",
"IsUserNotFound",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeUserNotFound",
"\n",
"case",
"errors",
".",
"IsAlreadyExists",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeAlreadyExists",
"\n",
"case",
"errors",
".",
"IsNotAssigned",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeNotAssigned",
"\n",
"case",
"state",
".",
"IsHasAssignedUnitsError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeHasAssignedUnits",
"\n",
"case",
"state",
".",
"IsHasHostedModelsError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeHasHostedModels",
"\n",
"case",
"state",
".",
"IsHasPersistentStorageError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeHasPersistentStorage",
"\n",
"case",
"state",
".",
"IsModelNotEmptyError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeModelNotEmpty",
"\n",
"case",
"isNoAddressSetError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeNoAddressSet",
"\n",
"case",
"errors",
".",
"IsNotProvisioned",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeNotProvisioned",
"\n",
"case",
"IsUpgradeInProgressError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeUpgradeInProgress",
"\n",
"case",
"state",
".",
"IsHasAttachmentsError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeMachineHasAttachedStorage",
"\n",
"case",
"state",
".",
"IsStorageAttachedError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeStorageAttached",
"\n",
"case",
"isUnknownModelError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeModelNotFound",
"\n",
"case",
"errors",
".",
"IsNotSupported",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeNotSupported",
"\n",
"case",
"errors",
".",
"IsBadRequest",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeBadRequest",
"\n",
"case",
"errors",
".",
"IsMethodNotAllowed",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeMethodNotAllowed",
"\n",
"case",
"errors",
".",
"IsNotImplemented",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeNotImplemented",
"\n",
"case",
"state",
".",
"IsIncompatibleSeriesError",
"(",
"err",
")",
":",
"code",
"=",
"params",
".",
"CodeIncompatibleSeries",
"\n",
"case",
"IsDischargeRequiredError",
"(",
"err",
")",
":",
"dischErr",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"DischargeRequiredError",
")",
"\n",
"code",
"=",
"params",
".",
"CodeDischargeRequired",
"\n",
"info",
"=",
"params",
".",
"DischargeRequiredErrorInfo",
"{",
"Macaroon",
":",
"dischErr",
".",
"Macaroon",
",",
"// One macaroon fits all.",
"MacaroonPath",
":",
"\"",
"\"",
",",
"}",
".",
"AsMap",
"(",
")",
"\n",
"case",
"IsRedirectError",
"(",
"err",
")",
":",
"redirErr",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"RedirectError",
")",
"\n",
"code",
"=",
"params",
".",
"CodeRedirect",
"\n",
"info",
"=",
"params",
".",
"RedirectErrorInfo",
"{",
"Servers",
":",
"params",
".",
"FromNetworkHostsPorts",
"(",
"redirErr",
".",
"Servers",
")",
",",
"CACert",
":",
"redirErr",
".",
"CACert",
",",
"ControllerAlias",
":",
"redirErr",
".",
"ControllerAlias",
",",
"}",
".",
"AsMap",
"(",
")",
"\n",
"default",
":",
"code",
"=",
"params",
".",
"ErrCode",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"params",
".",
"Error",
"{",
"Message",
":",
"msg",
",",
"Code",
":",
"code",
",",
"Info",
":",
"info",
",",
"}",
"\n",
"}"
] | // ServerError returns an error suitable for returning to an API
// client, with an error code suitable for various kinds of errors
// generated in packages outside the API. | [
"ServerError",
"returns",
"an",
"error",
"suitable",
"for",
"returning",
"to",
"an",
"API",
"client",
"with",
"an",
"error",
"code",
"suitable",
"for",
"various",
"kinds",
"of",
"errors",
"generated",
"in",
"packages",
"outside",
"the",
"API",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/errors.go#L221-L302 |
156,623 | juju/juju | service/windows/service.go | NewService | func NewService(name string, conf common.Conf) (*Service, error) {
m, err := NewServiceManager()
if err != nil {
return nil, errors.Trace(err)
}
return newService(name, conf, m), nil
} | go | func NewService(name string, conf common.Conf) (*Service, error) {
m, err := NewServiceManager()
if err != nil {
return nil, errors.Trace(err)
}
return newService(name, conf, m), nil
} | [
"func",
"NewService",
"(",
"name",
"string",
",",
"conf",
"common",
".",
"Conf",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"NewServiceManager",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"newService",
"(",
"name",
",",
"conf",
",",
"m",
")",
",",
"nil",
"\n",
"}"
] | // NewService returns a new Service type | [
"NewService",
"returns",
"a",
"new",
"Service",
"type"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/windows/service.go#L98-L104 |
156,624 | juju/juju | service/windows/service.go | Validate | func (s *Service) Validate() error {
if err := s.Service.Validate(renderer); err != nil {
return errors.Trace(err)
}
if s.Service.Conf.Transient {
return errors.NotSupportedf("transient services")
}
if s.Service.Conf.AfterStopped != "" {
return errors.NotSupportedf("Conf.AfterStopped")
}
return nil
} | go | func (s *Service) Validate() error {
if err := s.Service.Validate(renderer); err != nil {
return errors.Trace(err)
}
if s.Service.Conf.Transient {
return errors.NotSupportedf("transient services")
}
if s.Service.Conf.AfterStopped != "" {
return errors.NotSupportedf("Conf.AfterStopped")
}
return nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"Service",
".",
"Validate",
"(",
"renderer",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"Transient",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"AfterStopped",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks the service for invalid values. | [
"Validate",
"checks",
"the",
"service",
"for",
"invalid",
"values",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/windows/service.go#L117-L131 |
156,625 | juju/juju | service/windows/service.go | Installed | func (s *Service) Installed() (bool, error) {
services, err := ListServices()
if err != nil {
return false, errors.Trace(err)
}
for _, val := range services {
if s.Name() == val {
return true, nil
}
}
return false, nil
} | go | func (s *Service) Installed() (bool, error) {
services, err := ListServices()
if err != nil {
return false, errors.Trace(err)
}
for _, val := range services {
if s.Name() == val {
return true, nil
}
}
return false, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Installed",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"services",
",",
"err",
":=",
"ListServices",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"services",
"{",
"if",
"s",
".",
"Name",
"(",
")",
"==",
"val",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // Installed returns whether the service is installed | [
"Installed",
"returns",
"whether",
"the",
"service",
"is",
"installed"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/windows/service.go#L143-L154 |
156,626 | juju/juju | service/windows/service.go | Exists | func (s *Service) Exists() (bool, error) {
return s.manager.Exists(s.Name(), s.Conf())
} | go | func (s *Service) Exists() (bool, error) {
return s.manager.Exists(s.Name(), s.Conf())
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Exists",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"s",
".",
"manager",
".",
"Exists",
"(",
"s",
".",
"Name",
"(",
")",
",",
"s",
".",
"Conf",
"(",
")",
")",
"\n",
"}"
] | // Exists returns whether the service configuration reflects the
// desired state | [
"Exists",
"returns",
"whether",
"the",
"service",
"configuration",
"reflects",
"the",
"desired",
"state"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/windows/service.go#L158-L160 |
156,627 | juju/juju | service/windows/service.go | Stop | func (s *Service) Stop() error {
running, err := s.Running()
if err != nil {
return errors.Trace(err)
}
if !running {
return nil
}
err = s.manager.Stop(s.Name())
return err
} | go | func (s *Service) Stop() error {
running, err := s.Running()
if err != nil {
return errors.Trace(err)
}
if !running {
return nil
}
err = s.manager.Stop(s.Name())
return err
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Stop",
"(",
")",
"error",
"{",
"running",
",",
"err",
":=",
"s",
".",
"Running",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"running",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"manager",
".",
"Stop",
"(",
"s",
".",
"Name",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Stop stops the service. | [
"Stop",
"stops",
"the",
"service",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/windows/service.go#L178-L188 |
156,628 | juju/juju | service/windows/service.go | Remove | func (s *Service) Remove() error {
installed, err := s.Installed()
if err != nil {
return err
}
if !installed {
return nil
}
err = s.Stop()
if err != nil {
return errors.Trace(err)
}
err = s.manager.Delete(s.Name())
return err
} | go | func (s *Service) Remove() error {
installed, err := s.Installed()
if err != nil {
return err
}
if !installed {
return nil
}
err = s.Stop()
if err != nil {
return errors.Trace(err)
}
err = s.manager.Delete(s.Name())
return err
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Remove",
"(",
")",
"error",
"{",
"installed",
",",
"err",
":=",
"s",
".",
"Installed",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"installed",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"err",
"=",
"s",
".",
"Stop",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"manager",
".",
"Delete",
"(",
"s",
".",
"Name",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Remove deletes the service. | [
"Remove",
"deletes",
"the",
"service",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/windows/service.go#L191-L206 |
156,629 | juju/juju | juju/api.go | usableHostPorts | func usableHostPorts(hps [][]network.HostPort) []network.HostPort {
collapsed := network.CollapseHostPorts(hps)
usable := network.FilterUnusableHostPorts(collapsed)
unique := network.UniqueHostPorts(usable)
return unique
} | go | func usableHostPorts(hps [][]network.HostPort) []network.HostPort {
collapsed := network.CollapseHostPorts(hps)
usable := network.FilterUnusableHostPorts(collapsed)
unique := network.UniqueHostPorts(usable)
return unique
} | [
"func",
"usableHostPorts",
"(",
"hps",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
")",
"[",
"]",
"network",
".",
"HostPort",
"{",
"collapsed",
":=",
"network",
".",
"CollapseHostPorts",
"(",
"hps",
")",
"\n",
"usable",
":=",
"network",
".",
"FilterUnusableHostPorts",
"(",
"collapsed",
")",
"\n",
"unique",
":=",
"network",
".",
"UniqueHostPorts",
"(",
"usable",
")",
"\n",
"return",
"unique",
"\n",
"}"
] | // usableHostPorts returns hps with unusable and non-unique
// host-ports filtered out. | [
"usableHostPorts",
"returns",
"hps",
"with",
"unusable",
"and",
"non",
"-",
"unique",
"host",
"-",
"ports",
"filtered",
"out",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/juju/api.go#L200-L205 |
156,630 | juju/juju | juju/api.go | UpdateControllerDetailsFromLogin | func UpdateControllerDetailsFromLogin(
store jujuclient.ControllerStore, controllerName string,
params UpdateControllerParams,
) error {
controllerDetails, err := store.ControllerByName(controllerName)
if err != nil {
return errors.Trace(err)
}
return updateControllerDetailsFromLogin(store, controllerName, controllerDetails, params)
} | go | func UpdateControllerDetailsFromLogin(
store jujuclient.ControllerStore, controllerName string,
params UpdateControllerParams,
) error {
controllerDetails, err := store.ControllerByName(controllerName)
if err != nil {
return errors.Trace(err)
}
return updateControllerDetailsFromLogin(store, controllerName, controllerDetails, params)
} | [
"func",
"UpdateControllerDetailsFromLogin",
"(",
"store",
"jujuclient",
".",
"ControllerStore",
",",
"controllerName",
"string",
",",
"params",
"UpdateControllerParams",
",",
")",
"error",
"{",
"controllerDetails",
",",
"err",
":=",
"store",
".",
"ControllerByName",
"(",
"controllerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"updateControllerDetailsFromLogin",
"(",
"store",
",",
"controllerName",
",",
"controllerDetails",
",",
"params",
")",
"\n",
"}"
] | // UpdateControllerDetailsFromLogin writes any new api addresses and other relevant details
// to the client controller file.
// Controller may be specified by a UUID or name, and must already exist. | [
"UpdateControllerDetailsFromLogin",
"writes",
"any",
"new",
"api",
"addresses",
"and",
"other",
"relevant",
"details",
"to",
"the",
"client",
"controller",
"file",
".",
"Controller",
"may",
"be",
"specified",
"by",
"a",
"UUID",
"or",
"name",
"and",
"must",
"already",
"exist",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/juju/api.go#L254-L263 |
156,631 | juju/juju | apiserver/facades/client/credentialmanager/client.go | NewCredentialManagerAPI | func NewCredentialManagerAPI(ctx facade.Context) (*CredentialManagerAPI, error) {
return internalNewCredentialManagerAPI(newStateShim(ctx.State()), ctx.Resources(), ctx.Auth())
} | go | func NewCredentialManagerAPI(ctx facade.Context) (*CredentialManagerAPI, error) {
return internalNewCredentialManagerAPI(newStateShim(ctx.State()), ctx.Resources(), ctx.Auth())
} | [
"func",
"NewCredentialManagerAPI",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"CredentialManagerAPI",
",",
"error",
")",
"{",
"return",
"internalNewCredentialManagerAPI",
"(",
"newStateShim",
"(",
"ctx",
".",
"State",
"(",
")",
")",
",",
"ctx",
".",
"Resources",
"(",
")",
",",
"ctx",
".",
"Auth",
"(",
")",
")",
"\n",
"}"
] | // NewCredentialManagerAPI creates a new CredentialManager API endpoint on server-side. | [
"NewCredentialManagerAPI",
"creates",
"a",
"new",
"CredentialManager",
"API",
"endpoint",
"on",
"server",
"-",
"side",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/credentialmanager/client.go#L31-L33 |
156,632 | juju/juju | state/resources.go | Resources | func (st *State) Resources() (Resources, error) {
persist := st.newPersistence()
resources := NewResourceState(persist, st)
return resources, nil
} | go | func (st *State) Resources() (Resources, error) {
persist := st.newPersistence()
resources := NewResourceState(persist, st)
return resources, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Resources",
"(",
")",
"(",
"Resources",
",",
"error",
")",
"{",
"persist",
":=",
"st",
".",
"newPersistence",
"(",
")",
"\n",
"resources",
":=",
"NewResourceState",
"(",
"persist",
",",
"st",
")",
"\n",
"return",
"resources",
",",
"nil",
"\n",
"}"
] | // Resources returns the resources functionality for the current state. | [
"Resources",
"returns",
"the",
"resources",
"functionality",
"for",
"the",
"current",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/resources.go#L69-L73 |
156,633 | juju/juju | state/resources.go | ResourcesPersistence | func (st *State) ResourcesPersistence() (ResourcesPersistence, error) {
base := st.newPersistence()
persist := NewResourcePersistence(base)
return persist, nil
} | go | func (st *State) ResourcesPersistence() (ResourcesPersistence, error) {
base := st.newPersistence()
persist := NewResourcePersistence(base)
return persist, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ResourcesPersistence",
"(",
")",
"(",
"ResourcesPersistence",
",",
"error",
")",
"{",
"base",
":=",
"st",
".",
"newPersistence",
"(",
")",
"\n",
"persist",
":=",
"NewResourcePersistence",
"(",
"base",
")",
"\n",
"return",
"persist",
",",
"nil",
"\n",
"}"
] | // ResourcesPersistence returns the resources persistence functionality
// for the current state. | [
"ResourcesPersistence",
"returns",
"the",
"resources",
"persistence",
"functionality",
"for",
"the",
"current",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/resources.go#L89-L93 |
156,634 | juju/juju | apiserver/restrict_controller.go | IsControllerFacade | func IsControllerFacade(facadeName string) bool {
return controllerFacadeNames.Contains(facadeName) || commonFacadeNames.Contains(facadeName)
} | go | func IsControllerFacade(facadeName string) bool {
return controllerFacadeNames.Contains(facadeName) || commonFacadeNames.Contains(facadeName)
} | [
"func",
"IsControllerFacade",
"(",
"facadeName",
"string",
")",
"bool",
"{",
"return",
"controllerFacadeNames",
".",
"Contains",
"(",
"facadeName",
")",
"||",
"commonFacadeNames",
".",
"Contains",
"(",
"facadeName",
")",
"\n",
"}"
] | // IsControllerFacade reports whether the given facade name can be accessed
// using a controller connection. | [
"IsControllerFacade",
"reports",
"whether",
"the",
"given",
"facade",
"name",
"can",
"be",
"accessed",
"using",
"a",
"controller",
"connection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/restrict_controller.go#L55-L57 |
156,635 | juju/juju | cmd/juju/commands/sshkeys.go | NewKeyManagerClient | func (c *SSHKeysBase) NewKeyManagerClient() (*keymanager.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, err
}
return keymanager.NewClient(root), nil
} | go | func (c *SSHKeysBase) NewKeyManagerClient() (*keymanager.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, err
}
return keymanager.NewClient(root), nil
} | [
"func",
"(",
"c",
"*",
"SSHKeysBase",
")",
"NewKeyManagerClient",
"(",
")",
"(",
"*",
"keymanager",
".",
"Client",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"c",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"keymanager",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // NewKeyManagerClient returns a keymanager client for the root api endpoint
// that the environment command returns. | [
"NewKeyManagerClient",
"returns",
"a",
"keymanager",
"client",
"for",
"the",
"root",
"api",
"endpoint",
"that",
"the",
"environment",
"command",
"returns",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/sshkeys.go#L18-L24 |
156,636 | juju/juju | cmd/juju/machine/flags.go | String | func (f disksFlag) String() string {
strs := make([]string, len(*f.disks))
for i, cons := range *f.disks {
strs[i] = fmt.Sprint(cons)
}
return strings.Join(strs, " ")
} | go | func (f disksFlag) String() string {
strs := make([]string, len(*f.disks))
for i, cons := range *f.disks {
strs[i] = fmt.Sprint(cons)
}
return strings.Join(strs, " ")
} | [
"func",
"(",
"f",
"disksFlag",
")",
"String",
"(",
")",
"string",
"{",
"strs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"*",
"f",
".",
"disks",
")",
")",
"\n",
"for",
"i",
",",
"cons",
":=",
"range",
"*",
"f",
".",
"disks",
"{",
"strs",
"[",
"i",
"]",
"=",
"fmt",
".",
"Sprint",
"(",
"cons",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"strs",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Set implements gnuflag.Value.String. | [
"Set",
"implements",
"gnuflag",
".",
"Value",
".",
"String",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/machine/flags.go#L32-L38 |
156,637 | juju/juju | provider/oracle/instance.go | hardwareCharacteristics | func (o *oracleInstance) hardwareCharacteristics() *instance.HardwareCharacteristics {
if o.arch == nil {
return nil
}
hc := &instance.HardwareCharacteristics{Arch: o.arch}
if o.instType != nil {
hc.Mem = &o.instType.Mem
hc.RootDisk = &o.instType.RootDisk
hc.CpuCores = &o.instType.CpuCores
}
return hc
} | go | func (o *oracleInstance) hardwareCharacteristics() *instance.HardwareCharacteristics {
if o.arch == nil {
return nil
}
hc := &instance.HardwareCharacteristics{Arch: o.arch}
if o.instType != nil {
hc.Mem = &o.instType.Mem
hc.RootDisk = &o.instType.RootDisk
hc.CpuCores = &o.instType.CpuCores
}
return hc
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"hardwareCharacteristics",
"(",
")",
"*",
"instance",
".",
"HardwareCharacteristics",
"{",
"if",
"o",
".",
"arch",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"hc",
":=",
"&",
"instance",
".",
"HardwareCharacteristics",
"{",
"Arch",
":",
"o",
".",
"arch",
"}",
"\n",
"if",
"o",
".",
"instType",
"!=",
"nil",
"{",
"hc",
".",
"Mem",
"=",
"&",
"o",
".",
"instType",
".",
"Mem",
"\n",
"hc",
".",
"RootDisk",
"=",
"&",
"o",
".",
"instType",
".",
"RootDisk",
"\n",
"hc",
".",
"CpuCores",
"=",
"&",
"o",
".",
"instType",
".",
"CpuCores",
"\n",
"}",
"\n\n",
"return",
"hc",
"\n",
"}"
] | // hardwareCharacteristics returns the hardware characteristics of the current
// instance | [
"hardwareCharacteristics",
"returns",
"the",
"hardware",
"characteristics",
"of",
"the",
"current",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L43-L56 |
156,638 | juju/juju | provider/oracle/instance.go | Id | func (o *oracleInstance) Id() instance.Id {
if o.machine.Name != "" {
name, err := extractInstanceIDFromMachineName(o.machine.Name)
if err != nil {
return instance.Id(o.machine.Name)
}
return name
}
return instance.Id(o.name)
} | go | func (o *oracleInstance) Id() instance.Id {
if o.machine.Name != "" {
name, err := extractInstanceIDFromMachineName(o.machine.Name)
if err != nil {
return instance.Id(o.machine.Name)
}
return name
}
return instance.Id(o.name)
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"Id",
"(",
")",
"instance",
".",
"Id",
"{",
"if",
"o",
".",
"machine",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"name",
",",
"err",
":=",
"extractInstanceIDFromMachineName",
"(",
"o",
".",
"machine",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"instance",
".",
"Id",
"(",
"o",
".",
"machine",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}",
"\n\n",
"return",
"instance",
".",
"Id",
"(",
"o",
".",
"name",
")",
"\n",
"}"
] | // Id is defined on the instances.Instance interface. | [
"Id",
"is",
"defined",
"on",
"the",
"instances",
".",
"Instance",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L99-L109 |
156,639 | juju/juju | provider/oracle/instance.go | Status | func (o *oracleInstance) Status(ctx context.ProviderCallContext) instance.Status {
return o.status
} | go | func (o *oracleInstance) Status(ctx context.ProviderCallContext) instance.Status {
return o.status
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"Status",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"instance",
".",
"Status",
"{",
"return",
"o",
".",
"status",
"\n",
"}"
] | // Status is defined on the instances.Instance interface. | [
"Status",
"is",
"defined",
"on",
"the",
"instances",
".",
"Instance",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L112-L114 |
156,640 | juju/juju | provider/oracle/instance.go | StorageAttachments | func (o *oracleInstance) StorageAttachments() []response.Storage {
o.mutex.Lock()
defer o.mutex.Unlock()
return o.machine.Storage_attachments
} | go | func (o *oracleInstance) StorageAttachments() []response.Storage {
o.mutex.Lock()
defer o.mutex.Unlock()
return o.machine.Storage_attachments
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"StorageAttachments",
"(",
")",
"[",
"]",
"response",
".",
"Storage",
"{",
"o",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"o",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"o",
".",
"machine",
".",
"Storage_attachments",
"\n",
"}"
] | // StorageAttachments returns the storage that was attached in the moment
// of instance creation. This storage cannot be detached dynamically.
// this is also needed if you wish to determine the free disk index
// you can use when attaching a new disk | [
"StorageAttachments",
"returns",
"the",
"storage",
"that",
"was",
"attached",
"in",
"the",
"moment",
"of",
"instance",
"creation",
".",
"This",
"storage",
"cannot",
"be",
"detached",
"dynamically",
".",
"this",
"is",
"also",
"needed",
"if",
"you",
"wish",
"to",
"determine",
"the",
"free",
"disk",
"index",
"you",
"can",
"use",
"when",
"attaching",
"a",
"new",
"disk"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L120-L124 |
156,641 | juju/juju | provider/oracle/instance.go | refresh | func (o *oracleInstance) refresh() error {
o.mutex.Lock()
defer o.mutex.Unlock()
machine, err := o.env.client.InstanceDetails(o.machine.Name)
// if the request failed for any reason
// we should not update the information and
// let the old one persist
if err != nil {
return err
}
o.machine = machine
return nil
} | go | func (o *oracleInstance) refresh() error {
o.mutex.Lock()
defer o.mutex.Unlock()
machine, err := o.env.client.InstanceDetails(o.machine.Name)
// if the request failed for any reason
// we should not update the information and
// let the old one persist
if err != nil {
return err
}
o.machine = machine
return nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"refresh",
"(",
")",
"error",
"{",
"o",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"o",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"machine",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"InstanceDetails",
"(",
"o",
".",
"machine",
".",
"Name",
")",
"\n",
"// if the request failed for any reason",
"// we should not update the information and",
"// let the old one persist",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"o",
".",
"machine",
"=",
"machine",
"\n",
"return",
"nil",
"\n",
"}"
] | // refresh refreshes the instance raw details from the oracle api
// this method is mutex protected | [
"refresh",
"refreshes",
"the",
"instance",
"raw",
"details",
"from",
"the",
"oracle",
"api",
"this",
"method",
"is",
"mutex",
"protected"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L128-L142 |
156,642 | juju/juju | provider/oracle/instance.go | waitForMachineStatus | func (o *oracleInstance) waitForMachineStatus(state ociCommon.InstanceState, timeout time.Duration) error {
timer := o.env.clock.NewTimer(timeout)
defer timer.Stop()
for {
select {
case <-timer.Chan():
return errors.Errorf(
"Timed out waiting for instance to transition from %v to %v",
o.machine.State, state,
)
case <-o.env.clock.After(10 * time.Second):
err := o.refresh()
if err != nil {
return err
}
if o.machine.State == state {
return nil
}
}
}
} | go | func (o *oracleInstance) waitForMachineStatus(state ociCommon.InstanceState, timeout time.Duration) error {
timer := o.env.clock.NewTimer(timeout)
defer timer.Stop()
for {
select {
case <-timer.Chan():
return errors.Errorf(
"Timed out waiting for instance to transition from %v to %v",
o.machine.State, state,
)
case <-o.env.clock.After(10 * time.Second):
err := o.refresh()
if err != nil {
return err
}
if o.machine.State == state {
return nil
}
}
}
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"waitForMachineStatus",
"(",
"state",
"ociCommon",
".",
"InstanceState",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"timer",
":=",
"o",
".",
"env",
".",
"clock",
".",
"NewTimer",
"(",
"timeout",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"timer",
".",
"Chan",
"(",
")",
":",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
".",
"machine",
".",
"State",
",",
"state",
",",
")",
"\n",
"case",
"<-",
"o",
".",
"env",
".",
"clock",
".",
"After",
"(",
"10",
"*",
"time",
".",
"Second",
")",
":",
"err",
":=",
"o",
".",
"refresh",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"o",
".",
"machine",
".",
"State",
"==",
"state",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // waitForMachineStatus will ping the machine status until the timeout
// duration is reached or an error appeared | [
"waitForMachineStatus",
"will",
"ping",
"the",
"machine",
"status",
"until",
"the",
"timeout",
"duration",
"is",
"reached",
"or",
"an",
"error",
"appeared"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L146-L167 |
156,643 | juju/juju | provider/oracle/instance.go | deleteInstanceAndResources | func (o *oracleInstance) deleteInstanceAndResources(cleanup bool) error {
if cleanup {
err := o.disassociatePublicIps(true)
if err != nil {
return err
}
}
if err := o.env.client.DeleteInstance(o.machine.Name); err != nil {
return errors.Trace(err)
}
if cleanup {
// Wait for instance to be deleted. The oracle API does not allow us to
// delete a security list if there is still a VM associated with it.
iteration := 0
for {
if instance, err := o.env.client.InstanceDetails(o.machine.Name); !oci.IsNotFound(err) {
if instance.State == ociCommon.StateError {
logger.Warningf("Instance %s entered error state", o.machine.Name)
break
}
if iteration >= 30 && instance.State == ociCommon.StateRunning {
logger.Warningf("Instance still in running state after %v checks. breaking loop", iteration)
break
}
if oci.IsInternalApi(err) {
logger.Errorf("got internal server error from API: %q", err)
}
<-o.env.clock.After(1 * time.Second)
iteration++
continue
}
logger.Debugf("Machine %v successfully deleted", o.machine.Name)
break
}
//
// seclist, vnicset, secrules, and acl created with
// StartInstanceParams.InstanceConfig.MachineId,
// convert o.Id() to machineId for deletion.
// o.Id() returns a string in hostname form.
tag, err := o.env.namespace.MachineTag(string(o.Id()))
if err != nil {
return errors.Annotatef(err, "failed to get a machine tag to complete cleanup of instance")
}
machineId := tag.Id()
// the VM association is now gone, now we can delete the
// machine sec list
logger.Debugf("deleting seclist for instance: %s", machineId)
if err := o.env.DeleteMachineSecList(machineId); err != nil {
logger.Errorf("failed to delete seclist: %s", err)
if !oci.IsMethodNotAllowed(err) {
return errors.Trace(err)
}
}
logger.Debugf("deleting vnic set for instance: %s", machineId)
if err := o.env.DeleteMachineVnicSet(machineId); err != nil {
logger.Errorf("failed to delete vnic set: %s", err)
if !oci.IsMethodNotAllowed(err) {
return errors.Trace(err)
}
}
}
return nil
} | go | func (o *oracleInstance) deleteInstanceAndResources(cleanup bool) error {
if cleanup {
err := o.disassociatePublicIps(true)
if err != nil {
return err
}
}
if err := o.env.client.DeleteInstance(o.machine.Name); err != nil {
return errors.Trace(err)
}
if cleanup {
// Wait for instance to be deleted. The oracle API does not allow us to
// delete a security list if there is still a VM associated with it.
iteration := 0
for {
if instance, err := o.env.client.InstanceDetails(o.machine.Name); !oci.IsNotFound(err) {
if instance.State == ociCommon.StateError {
logger.Warningf("Instance %s entered error state", o.machine.Name)
break
}
if iteration >= 30 && instance.State == ociCommon.StateRunning {
logger.Warningf("Instance still in running state after %v checks. breaking loop", iteration)
break
}
if oci.IsInternalApi(err) {
logger.Errorf("got internal server error from API: %q", err)
}
<-o.env.clock.After(1 * time.Second)
iteration++
continue
}
logger.Debugf("Machine %v successfully deleted", o.machine.Name)
break
}
//
// seclist, vnicset, secrules, and acl created with
// StartInstanceParams.InstanceConfig.MachineId,
// convert o.Id() to machineId for deletion.
// o.Id() returns a string in hostname form.
tag, err := o.env.namespace.MachineTag(string(o.Id()))
if err != nil {
return errors.Annotatef(err, "failed to get a machine tag to complete cleanup of instance")
}
machineId := tag.Id()
// the VM association is now gone, now we can delete the
// machine sec list
logger.Debugf("deleting seclist for instance: %s", machineId)
if err := o.env.DeleteMachineSecList(machineId); err != nil {
logger.Errorf("failed to delete seclist: %s", err)
if !oci.IsMethodNotAllowed(err) {
return errors.Trace(err)
}
}
logger.Debugf("deleting vnic set for instance: %s", machineId)
if err := o.env.DeleteMachineVnicSet(machineId); err != nil {
logger.Errorf("failed to delete vnic set: %s", err)
if !oci.IsMethodNotAllowed(err) {
return errors.Trace(err)
}
}
}
return nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"deleteInstanceAndResources",
"(",
"cleanup",
"bool",
")",
"error",
"{",
"if",
"cleanup",
"{",
"err",
":=",
"o",
".",
"disassociatePublicIps",
"(",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"DeleteInstance",
"(",
"o",
".",
"machine",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"cleanup",
"{",
"// Wait for instance to be deleted. The oracle API does not allow us to",
"// delete a security list if there is still a VM associated with it.",
"iteration",
":=",
"0",
"\n",
"for",
"{",
"if",
"instance",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"InstanceDetails",
"(",
"o",
".",
"machine",
".",
"Name",
")",
";",
"!",
"oci",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"if",
"instance",
".",
"State",
"==",
"ociCommon",
".",
"StateError",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"o",
".",
"machine",
".",
"Name",
")",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"iteration",
">=",
"30",
"&&",
"instance",
".",
"State",
"==",
"ociCommon",
".",
"StateRunning",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"iteration",
")",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"oci",
".",
"IsInternalApi",
"(",
"err",
")",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"<-",
"o",
".",
"env",
".",
"clock",
".",
"After",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"iteration",
"++",
"\n",
"continue",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"o",
".",
"machine",
".",
"Name",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"//",
"// seclist, vnicset, secrules, and acl created with",
"// StartInstanceParams.InstanceConfig.MachineId,",
"// convert o.Id() to machineId for deletion.",
"// o.Id() returns a string in hostname form.",
"tag",
",",
"err",
":=",
"o",
".",
"env",
".",
"namespace",
".",
"MachineTag",
"(",
"string",
"(",
"o",
".",
"Id",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"machineId",
":=",
"tag",
".",
"Id",
"(",
")",
"\n\n",
"// the VM association is now gone, now we can delete the",
"// machine sec list",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"machineId",
")",
"\n",
"if",
"err",
":=",
"o",
".",
"env",
".",
"DeleteMachineSecList",
"(",
"machineId",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"if",
"!",
"oci",
".",
"IsMethodNotAllowed",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"machineId",
")",
"\n",
"if",
"err",
":=",
"o",
".",
"env",
".",
"DeleteMachineVnicSet",
"(",
"machineId",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"if",
"!",
"oci",
".",
"IsMethodNotAllowed",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // delete will delete the instance and attempt to cleanup any instance related
// resources | [
"delete",
"will",
"delete",
"the",
"instance",
"and",
"attempt",
"to",
"cleanup",
"any",
"instance",
"related",
"resources"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L171-L237 |
156,644 | juju/juju | provider/oracle/instance.go | unusedPublicIps | func (o *oracleInstance) unusedPublicIps() ([]response.IpReservation, error) {
filter := []oci.Filter{
{
Arg: "permanent",
Value: "true",
},
{
Arg: "used",
Value: "false",
},
}
res, err := o.env.client.AllIpReservations(filter)
if err != nil {
return nil, err
}
return res.Result, nil
} | go | func (o *oracleInstance) unusedPublicIps() ([]response.IpReservation, error) {
filter := []oci.Filter{
{
Arg: "permanent",
Value: "true",
},
{
Arg: "used",
Value: "false",
},
}
res, err := o.env.client.AllIpReservations(filter)
if err != nil {
return nil, err
}
return res.Result, nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"unusedPublicIps",
"(",
")",
"(",
"[",
"]",
"response",
".",
"IpReservation",
",",
"error",
")",
"{",
"filter",
":=",
"[",
"]",
"oci",
".",
"Filter",
"{",
"{",
"Arg",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"Arg",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
",",
"}",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"AllIpReservations",
"(",
"filter",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"res",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // unusedPublicIps returns a slice of IpReservation that are currently not used | [
"unusedPublicIps",
"returns",
"a",
"slice",
"of",
"IpReservation",
"that",
"are",
"currently",
"not",
"used"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L240-L258 |
156,645 | juju/juju | provider/oracle/instance.go | associatePublicIP | func (o *oracleInstance) associatePublicIP() error {
// return all unused public IPs
unusedIps, err := o.unusedPublicIps()
if err != nil {
return err
}
for _, val := range unusedIps {
assocPoolName := ociCommon.NewIPPool(
ociCommon.IPPool(val.Name),
ociCommon.IPReservationType,
)
// create the association for it
if _, err := o.env.client.CreateIpAssociation(
assocPoolName,
o.machine.Vcable_id,
); err != nil {
if oci.IsBadRequest(err) {
// the IP probably got allocated after we fetched it
// from the API. Move on to the next one.
continue
}
return err
} else {
if _, err = o.env.client.UpdateIpReservation(val.Name, "", val.Parentpool, val.Permanent, o.machine.Tags); err != nil {
// we don't really want to terminate execution if we fail to update
// tags
logger.Errorf("failed to update IP reservation tags: %q", err)
}
return nil
}
}
// no unused IP reservations found. Allocate a new one.
reservation, err := o.env.client.CreateIpReservation(
o.machine.Name, ociCommon.PublicIPPool, true, o.machine.Tags)
if err != nil {
return err
}
// compose IP pool name
assocPoolName := ociCommon.NewIPPool(
ociCommon.IPPool(reservation.Name),
ociCommon.IPReservationType,
)
if _, err := o.env.client.CreateIpAssociation(
assocPoolName,
o.machine.Vcable_id,
); err != nil {
return err
}
return nil
} | go | func (o *oracleInstance) associatePublicIP() error {
// return all unused public IPs
unusedIps, err := o.unusedPublicIps()
if err != nil {
return err
}
for _, val := range unusedIps {
assocPoolName := ociCommon.NewIPPool(
ociCommon.IPPool(val.Name),
ociCommon.IPReservationType,
)
// create the association for it
if _, err := o.env.client.CreateIpAssociation(
assocPoolName,
o.machine.Vcable_id,
); err != nil {
if oci.IsBadRequest(err) {
// the IP probably got allocated after we fetched it
// from the API. Move on to the next one.
continue
}
return err
} else {
if _, err = o.env.client.UpdateIpReservation(val.Name, "", val.Parentpool, val.Permanent, o.machine.Tags); err != nil {
// we don't really want to terminate execution if we fail to update
// tags
logger.Errorf("failed to update IP reservation tags: %q", err)
}
return nil
}
}
// no unused IP reservations found. Allocate a new one.
reservation, err := o.env.client.CreateIpReservation(
o.machine.Name, ociCommon.PublicIPPool, true, o.machine.Tags)
if err != nil {
return err
}
// compose IP pool name
assocPoolName := ociCommon.NewIPPool(
ociCommon.IPPool(reservation.Name),
ociCommon.IPReservationType,
)
if _, err := o.env.client.CreateIpAssociation(
assocPoolName,
o.machine.Vcable_id,
); err != nil {
return err
}
return nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"associatePublicIP",
"(",
")",
"error",
"{",
"// return all unused public IPs",
"unusedIps",
",",
"err",
":=",
"o",
".",
"unusedPublicIps",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"val",
":=",
"range",
"unusedIps",
"{",
"assocPoolName",
":=",
"ociCommon",
".",
"NewIPPool",
"(",
"ociCommon",
".",
"IPPool",
"(",
"val",
".",
"Name",
")",
",",
"ociCommon",
".",
"IPReservationType",
",",
")",
"\n",
"// create the association for it",
"if",
"_",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"CreateIpAssociation",
"(",
"assocPoolName",
",",
"o",
".",
"machine",
".",
"Vcable_id",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"oci",
".",
"IsBadRequest",
"(",
"err",
")",
"{",
"// the IP probably got allocated after we fetched it",
"// from the API. Move on to the next one.",
"continue",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}",
"else",
"{",
"if",
"_",
",",
"err",
"=",
"o",
".",
"env",
".",
"client",
".",
"UpdateIpReservation",
"(",
"val",
".",
"Name",
",",
"\"",
"\"",
",",
"val",
".",
"Parentpool",
",",
"val",
".",
"Permanent",
",",
"o",
".",
"machine",
".",
"Tags",
")",
";",
"err",
"!=",
"nil",
"{",
"// we don't really want to terminate execution if we fail to update",
"// tags",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// no unused IP reservations found. Allocate a new one.",
"reservation",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"CreateIpReservation",
"(",
"o",
".",
"machine",
".",
"Name",
",",
"ociCommon",
".",
"PublicIPPool",
",",
"true",
",",
"o",
".",
"machine",
".",
"Tags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// compose IP pool name",
"assocPoolName",
":=",
"ociCommon",
".",
"NewIPPool",
"(",
"ociCommon",
".",
"IPPool",
"(",
"reservation",
".",
"Name",
")",
",",
"ociCommon",
".",
"IPReservationType",
",",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"CreateIpAssociation",
"(",
"assocPoolName",
",",
"o",
".",
"machine",
".",
"Vcable_id",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // associatePublicIP associates a public IP with the current instance | [
"associatePublicIP",
"associates",
"a",
"public",
"IP",
"with",
"the",
"current",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L261-L315 |
156,646 | juju/juju | provider/oracle/instance.go | disassociatePublicIps | func (o *oracleInstance) disassociatePublicIps(remove bool) error {
associations, err := o.publicAddressesAssociations()
if err != nil {
return err
}
for _, ipAssoc := range associations {
reservation := ipAssoc.Reservation
name := ipAssoc.Name
if err := o.env.client.DeleteIpAssociation(name); err != nil {
if oci.IsNotFound(err) {
continue
}
return err
}
if remove {
if err := o.env.client.DeleteIpReservation(reservation); err != nil {
if oci.IsNotFound(err) {
return nil
}
return err
}
}
}
return nil
} | go | func (o *oracleInstance) disassociatePublicIps(remove bool) error {
associations, err := o.publicAddressesAssociations()
if err != nil {
return err
}
for _, ipAssoc := range associations {
reservation := ipAssoc.Reservation
name := ipAssoc.Name
if err := o.env.client.DeleteIpAssociation(name); err != nil {
if oci.IsNotFound(err) {
continue
}
return err
}
if remove {
if err := o.env.client.DeleteIpReservation(reservation); err != nil {
if oci.IsNotFound(err) {
return nil
}
return err
}
}
}
return nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"disassociatePublicIps",
"(",
"remove",
"bool",
")",
"error",
"{",
"associations",
",",
"err",
":=",
"o",
".",
"publicAddressesAssociations",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ipAssoc",
":=",
"range",
"associations",
"{",
"reservation",
":=",
"ipAssoc",
".",
"Reservation",
"\n",
"name",
":=",
"ipAssoc",
".",
"Name",
"\n",
"if",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"DeleteIpAssociation",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"oci",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"remove",
"{",
"if",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"DeleteIpReservation",
"(",
"reservation",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"oci",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // dissasociatePublicIps disassociates the public IP address from the current instance.
// Optionally, the remove flag will also remove the IP reservation after the IP was disassociated | [
"dissasociatePublicIps",
"disassociates",
"the",
"public",
"IP",
"address",
"from",
"the",
"current",
"instance",
".",
"Optionally",
"the",
"remove",
"flag",
"will",
"also",
"remove",
"the",
"IP",
"reservation",
"after",
"the",
"IP",
"was",
"disassociated"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L319-L347 |
156,647 | juju/juju | provider/oracle/instance.go | publicAddressesAssociations | func (o *oracleInstance) publicAddressesAssociations() ([]response.IpAssociation, error) {
o.mutex.Lock()
defer o.mutex.Unlock()
filter := []oci.Filter{
{
Arg: "vcable",
Value: string(o.machine.Vcable_id),
},
}
assoc, err := o.env.client.AllIpAssociations(filter)
if err != nil {
return nil, errors.Trace(err)
}
return assoc.Result, nil
} | go | func (o *oracleInstance) publicAddressesAssociations() ([]response.IpAssociation, error) {
o.mutex.Lock()
defer o.mutex.Unlock()
filter := []oci.Filter{
{
Arg: "vcable",
Value: string(o.machine.Vcable_id),
},
}
assoc, err := o.env.client.AllIpAssociations(filter)
if err != nil {
return nil, errors.Trace(err)
}
return assoc.Result, nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"publicAddressesAssociations",
"(",
")",
"(",
"[",
"]",
"response",
".",
"IpAssociation",
",",
"error",
")",
"{",
"o",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"o",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"filter",
":=",
"[",
"]",
"oci",
".",
"Filter",
"{",
"{",
"Arg",
":",
"\"",
"\"",
",",
"Value",
":",
"string",
"(",
"o",
".",
"machine",
".",
"Vcable_id",
")",
",",
"}",
",",
"}",
"\n\n",
"assoc",
",",
"err",
":=",
"o",
".",
"env",
".",
"client",
".",
"AllIpAssociations",
"(",
"filter",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"assoc",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // publicAddressesAssociations returns a slice of all IP associations for the current instance | [
"publicAddressesAssociations",
"returns",
"a",
"slice",
"of",
"all",
"IP",
"associations",
"for",
"the",
"current",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L350-L367 |
156,648 | juju/juju | provider/oracle/instance.go | Addresses | func (o *oracleInstance) Addresses(ctx context.ProviderCallContext) ([]network.Address, error) {
addresses := []network.Address{}
ips, err := o.publicAddressesAssociations()
if err != nil {
return nil, errors.Trace(err)
}
if len(o.machine.Attributes.Network) > 0 {
for name, val := range o.machine.Attributes.Network {
if _, ip, err := oraclenetwork.GetMacAndIP(val.Address); err == nil {
address := network.NewScopedAddress(ip, network.ScopeCloudLocal)
addresses = append(addresses, address)
} else {
logger.Errorf("failed to get IP address for NIC %q: %q", name, err)
}
}
}
for _, val := range ips {
address := network.NewScopedAddress(val.Ip, network.ScopePublic)
addresses = append(addresses, address)
}
return addresses, nil
} | go | func (o *oracleInstance) Addresses(ctx context.ProviderCallContext) ([]network.Address, error) {
addresses := []network.Address{}
ips, err := o.publicAddressesAssociations()
if err != nil {
return nil, errors.Trace(err)
}
if len(o.machine.Attributes.Network) > 0 {
for name, val := range o.machine.Attributes.Network {
if _, ip, err := oraclenetwork.GetMacAndIP(val.Address); err == nil {
address := network.NewScopedAddress(ip, network.ScopeCloudLocal)
addresses = append(addresses, address)
} else {
logger.Errorf("failed to get IP address for NIC %q: %q", name, err)
}
}
}
for _, val := range ips {
address := network.NewScopedAddress(val.Ip, network.ScopePublic)
addresses = append(addresses, address)
}
return addresses, nil
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"Addresses",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"error",
")",
"{",
"addresses",
":=",
"[",
"]",
"network",
".",
"Address",
"{",
"}",
"\n\n",
"ips",
",",
"err",
":=",
"o",
".",
"publicAddressesAssociations",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"o",
".",
"machine",
".",
"Attributes",
".",
"Network",
")",
">",
"0",
"{",
"for",
"name",
",",
"val",
":=",
"range",
"o",
".",
"machine",
".",
"Attributes",
".",
"Network",
"{",
"if",
"_",
",",
"ip",
",",
"err",
":=",
"oraclenetwork",
".",
"GetMacAndIP",
"(",
"val",
".",
"Address",
")",
";",
"err",
"==",
"nil",
"{",
"address",
":=",
"network",
".",
"NewScopedAddress",
"(",
"ip",
",",
"network",
".",
"ScopeCloudLocal",
")",
"\n",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"address",
")",
"\n",
"}",
"else",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"val",
":=",
"range",
"ips",
"{",
"address",
":=",
"network",
".",
"NewScopedAddress",
"(",
"val",
".",
"Ip",
",",
"network",
".",
"ScopePublic",
")",
"\n",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"address",
")",
"\n",
"}",
"\n\n",
"return",
"addresses",
",",
"nil",
"\n",
"}"
] | // Addresses is defined on the instances.Instance interface. | [
"Addresses",
"is",
"defined",
"on",
"the",
"instances",
".",
"Instance",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L370-L395 |
156,649 | juju/juju | provider/oracle/instance.go | OpenPorts | func (o *oracleInstance) OpenPorts(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
if o.env.Config().FirewallMode() != config.FwInstance {
return errors.Errorf(
"invalid firewall mode %q for opening ports on instance",
o.env.Config().FirewallMode(),
)
}
return o.env.OpenPortsOnInstance(ctx, machineId, rules)
} | go | func (o *oracleInstance) OpenPorts(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
if o.env.Config().FirewallMode() != config.FwInstance {
return errors.Errorf(
"invalid firewall mode %q for opening ports on instance",
o.env.Config().FirewallMode(),
)
}
return o.env.OpenPortsOnInstance(ctx, machineId, rules)
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"OpenPorts",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"machineId",
"string",
",",
"rules",
"[",
"]",
"network",
".",
"IngressRule",
")",
"error",
"{",
"if",
"o",
".",
"env",
".",
"Config",
"(",
")",
".",
"FirewallMode",
"(",
")",
"!=",
"config",
".",
"FwInstance",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
".",
"env",
".",
"Config",
"(",
")",
".",
"FirewallMode",
"(",
")",
",",
")",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"env",
".",
"OpenPortsOnInstance",
"(",
"ctx",
",",
"machineId",
",",
"rules",
")",
"\n",
"}"
] | // OpenPorts is defined on the instances.Instance interface. | [
"OpenPorts",
"is",
"defined",
"on",
"the",
"instances",
".",
"Instance",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L398-L407 |
156,650 | juju/juju | provider/oracle/instance.go | IngressRules | func (o *oracleInstance) IngressRules(ctx context.ProviderCallContext, machineId string) ([]network.IngressRule, error) {
return o.env.MachineIngressRules(ctx, machineId)
} | go | func (o *oracleInstance) IngressRules(ctx context.ProviderCallContext, machineId string) ([]network.IngressRule, error) {
return o.env.MachineIngressRules(ctx, machineId)
} | [
"func",
"(",
"o",
"*",
"oracleInstance",
")",
"IngressRules",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"machineId",
"string",
")",
"(",
"[",
"]",
"network",
".",
"IngressRule",
",",
"error",
")",
"{",
"return",
"o",
".",
"env",
".",
"MachineIngressRules",
"(",
"ctx",
",",
"machineId",
")",
"\n",
"}"
] | // IngressRules is defined on the instances.Instance interface. | [
"IngressRules",
"is",
"defined",
"on",
"the",
"instances",
".",
"Instance",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/instance.go#L422-L424 |
156,651 | juju/juju | api/deployer/deployer.go | NewState | func NewState(caller base.APICaller) *State {
facadeCaller := base.NewFacadeCaller(caller, deployerFacade)
return &State{facade: facadeCaller}
} | go | func NewState(caller base.APICaller) *State {
facadeCaller := base.NewFacadeCaller(caller, deployerFacade)
return &State{facade: facadeCaller}
} | [
"func",
"NewState",
"(",
"caller",
"base",
".",
"APICaller",
")",
"*",
"State",
"{",
"facadeCaller",
":=",
"base",
".",
"NewFacadeCaller",
"(",
"caller",
",",
"deployerFacade",
")",
"\n",
"return",
"&",
"State",
"{",
"facade",
":",
"facadeCaller",
"}",
"\n\n",
"}"
] | // NewState creates a new State instance that makes API calls
// through the given caller. | [
"NewState",
"creates",
"a",
"new",
"State",
"instance",
"that",
"makes",
"API",
"calls",
"through",
"the",
"given",
"caller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/deployer/deployer.go#L23-L27 |
156,652 | juju/juju | api/deployer/deployer.go | unitLife | func (st *State) unitLife(tag names.UnitTag) (params.Life, error) {
return common.OneLife(st.facade, tag)
} | go | func (st *State) unitLife(tag names.UnitTag) (params.Life, error) {
return common.OneLife(st.facade, tag)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"unitLife",
"(",
"tag",
"names",
".",
"UnitTag",
")",
"(",
"params",
".",
"Life",
",",
"error",
")",
"{",
"return",
"common",
".",
"OneLife",
"(",
"st",
".",
"facade",
",",
"tag",
")",
"\n",
"}"
] | // unitLife returns the lifecycle state of the given unit. | [
"unitLife",
"returns",
"the",
"lifecycle",
"state",
"of",
"the",
"given",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/deployer/deployer.go#L30-L32 |
156,653 | juju/juju | api/deployer/deployer.go | Unit | func (st *State) Unit(tag names.UnitTag) (*Unit, error) {
life, err := st.unitLife(tag)
if err != nil {
return nil, err
}
return &Unit{
tag: tag,
life: life,
st: st,
}, nil
} | go | func (st *State) Unit(tag names.UnitTag) (*Unit, error) {
life, err := st.unitLife(tag)
if err != nil {
return nil, err
}
return &Unit{
tag: tag,
life: life,
st: st,
}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Unit",
"(",
"tag",
"names",
".",
"UnitTag",
")",
"(",
"*",
"Unit",
",",
"error",
")",
"{",
"life",
",",
"err",
":=",
"st",
".",
"unitLife",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Unit",
"{",
"tag",
":",
"tag",
",",
"life",
":",
"life",
",",
"st",
":",
"st",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Unit returns the unit with the given tag. | [
"Unit",
"returns",
"the",
"unit",
"with",
"the",
"given",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/deployer/deployer.go#L35-L45 |
156,654 | juju/juju | api/deployer/deployer.go | Machine | func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
// TODO(dfc) this cannot return an error any more
return &Machine{
tag: tag,
st: st,
}, nil
} | go | func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
// TODO(dfc) this cannot return an error any more
return &Machine{
tag: tag,
st: st,
}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Machine",
"(",
"tag",
"names",
".",
"MachineTag",
")",
"(",
"*",
"Machine",
",",
"error",
")",
"{",
"// TODO(dfc) this cannot return an error any more",
"return",
"&",
"Machine",
"{",
"tag",
":",
"tag",
",",
"st",
":",
"st",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Machine returns the machine with the given tag. | [
"Machine",
"returns",
"the",
"machine",
"with",
"the",
"given",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/deployer/deployer.go#L48-L54 |
156,655 | juju/juju | core/auditlog/config.go | Validate | func (cfg Config) Validate() error {
if cfg.Enabled && cfg.Target == nil {
return errors.NewNotValid(nil, "logging enabled but no target provided")
}
return nil
} | go | func (cfg Config) Validate() error {
if cfg.Enabled && cfg.Target == nil {
return errors.NewNotValid(nil, "logging enabled but no target provided")
}
return nil
} | [
"func",
"(",
"cfg",
"Config",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"cfg",
".",
"Enabled",
"&&",
"cfg",
".",
"Target",
"==",
"nil",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks the audit logging configuration. | [
"Validate",
"checks",
"the",
"audit",
"logging",
"configuration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/auditlog/config.go#L37-L42 |
156,656 | juju/juju | service/agentinfo.go | NewAgentInfo | func NewAgentInfo(kind AgentKind, id, dataDir, logDir string) AgentInfo {
name := fmt.Sprintf("%s-%s", kind, strings.Replace(id, "/", "-", -1))
info := AgentInfo{
Kind: kind,
ID: id,
DataDir: dataDir,
LogDir: logDir,
name: name,
}
return info
} | go | func NewAgentInfo(kind AgentKind, id, dataDir, logDir string) AgentInfo {
name := fmt.Sprintf("%s-%s", kind, strings.Replace(id, "/", "-", -1))
info := AgentInfo{
Kind: kind,
ID: id,
DataDir: dataDir,
LogDir: logDir,
name: name,
}
return info
} | [
"func",
"NewAgentInfo",
"(",
"kind",
"AgentKind",
",",
"id",
",",
"dataDir",
",",
"logDir",
"string",
")",
"AgentInfo",
"{",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"kind",
",",
"strings",
".",
"Replace",
"(",
"id",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
")",
"\n\n",
"info",
":=",
"AgentInfo",
"{",
"Kind",
":",
"kind",
",",
"ID",
":",
"id",
",",
"DataDir",
":",
"dataDir",
",",
"LogDir",
":",
"logDir",
",",
"name",
":",
"name",
",",
"}",
"\n",
"return",
"info",
"\n",
"}"
] | // NewAgentInfo composes a new AgentInfo for the given essentials. | [
"NewAgentInfo",
"composes",
"a",
"new",
"AgentInfo",
"for",
"the",
"given",
"essentials",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/agentinfo.go#L48-L60 |
156,657 | juju/juju | service/agentinfo.go | NewMachineAgentInfo | func NewMachineAgentInfo(id, dataDir, logDir string) AgentInfo {
return NewAgentInfo(AgentKindMachine, id, dataDir, logDir)
} | go | func NewMachineAgentInfo(id, dataDir, logDir string) AgentInfo {
return NewAgentInfo(AgentKindMachine, id, dataDir, logDir)
} | [
"func",
"NewMachineAgentInfo",
"(",
"id",
",",
"dataDir",
",",
"logDir",
"string",
")",
"AgentInfo",
"{",
"return",
"NewAgentInfo",
"(",
"AgentKindMachine",
",",
"id",
",",
"dataDir",
",",
"logDir",
")",
"\n",
"}"
] | // NewMachineAgentInfo returns a new AgentInfo for a machine agent. | [
"NewMachineAgentInfo",
"returns",
"a",
"new",
"AgentInfo",
"for",
"a",
"machine",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/agentinfo.go#L63-L65 |
156,658 | juju/juju | service/agentinfo.go | NewUnitAgentInfo | func NewUnitAgentInfo(id, dataDir, logDir string) AgentInfo {
return NewAgentInfo(AgentKindUnit, id, dataDir, logDir)
} | go | func NewUnitAgentInfo(id, dataDir, logDir string) AgentInfo {
return NewAgentInfo(AgentKindUnit, id, dataDir, logDir)
} | [
"func",
"NewUnitAgentInfo",
"(",
"id",
",",
"dataDir",
",",
"logDir",
"string",
")",
"AgentInfo",
"{",
"return",
"NewAgentInfo",
"(",
"AgentKindUnit",
",",
"id",
",",
"dataDir",
",",
"logDir",
")",
"\n",
"}"
] | // NewUnitAgentInfo returns a new AgentInfo for a unit agent. | [
"NewUnitAgentInfo",
"returns",
"a",
"new",
"AgentInfo",
"for",
"a",
"unit",
"agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/agentinfo.go#L68-L70 |
156,659 | juju/juju | service/agentinfo.go | ToolsDir | func (ai AgentInfo) ToolsDir(renderer shell.Renderer) string {
return renderer.FromSlash(tools.ToolsDir(ai.DataDir, ai.name))
} | go | func (ai AgentInfo) ToolsDir(renderer shell.Renderer) string {
return renderer.FromSlash(tools.ToolsDir(ai.DataDir, ai.name))
} | [
"func",
"(",
"ai",
"AgentInfo",
")",
"ToolsDir",
"(",
"renderer",
"shell",
".",
"Renderer",
")",
"string",
"{",
"return",
"renderer",
".",
"FromSlash",
"(",
"tools",
".",
"ToolsDir",
"(",
"ai",
".",
"DataDir",
",",
"ai",
".",
"name",
")",
")",
"\n",
"}"
] | // ToolsDir returns the path to the agent's tools dir. | [
"ToolsDir",
"returns",
"the",
"path",
"to",
"the",
"agent",
"s",
"tools",
"dir",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/agentinfo.go#L73-L75 |
156,660 | juju/juju | service/agentinfo.go | execArgs | func (ai AgentInfo) execArgs(renderer shell.Renderer) []string {
return []string{
string(ai.Kind),
"--data-dir", renderer.FromSlash(ai.DataDir),
idOptions[ai.Kind], ai.ID,
"--debug",
}
} | go | func (ai AgentInfo) execArgs(renderer shell.Renderer) []string {
return []string{
string(ai.Kind),
"--data-dir", renderer.FromSlash(ai.DataDir),
idOptions[ai.Kind], ai.ID,
"--debug",
}
} | [
"func",
"(",
"ai",
"AgentInfo",
")",
"execArgs",
"(",
"renderer",
"shell",
".",
"Renderer",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"string",
"(",
"ai",
".",
"Kind",
")",
",",
"\"",
"\"",
",",
"renderer",
".",
"FromSlash",
"(",
"ai",
".",
"DataDir",
")",
",",
"idOptions",
"[",
"ai",
".",
"Kind",
"]",
",",
"ai",
".",
"ID",
",",
"\"",
"\"",
",",
"}",
"\n",
"}"
] | // execArgs returns an unquoted array of service arguments in case we need
// them later. One notable place where this is needed, is the windows service
// package, where CreateService correctly does quoting of executable path and
// individual arguments | [
"execArgs",
"returns",
"an",
"unquoted",
"array",
"of",
"service",
"arguments",
"in",
"case",
"we",
"need",
"them",
"later",
".",
"One",
"notable",
"place",
"where",
"this",
"is",
"needed",
"is",
"the",
"windows",
"service",
"package",
"where",
"CreateService",
"correctly",
"does",
"quoting",
"of",
"executable",
"path",
"and",
"individual",
"arguments"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/agentinfo.go#L99-L106 |
156,661 | juju/juju | apiserver/common/block.go | RemoveAllowed | func (c *BlockChecker) RemoveAllowed() error {
if err := c.checkBlock(state.RemoveBlock); err != nil {
return err
}
// Check if change block has been enabled
return c.checkBlock(state.ChangeBlock)
} | go | func (c *BlockChecker) RemoveAllowed() error {
if err := c.checkBlock(state.RemoveBlock); err != nil {
return err
}
// Check if change block has been enabled
return c.checkBlock(state.ChangeBlock)
} | [
"func",
"(",
"c",
"*",
"BlockChecker",
")",
"RemoveAllowed",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"checkBlock",
"(",
"state",
".",
"RemoveBlock",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Check if change block has been enabled",
"return",
"c",
".",
"checkBlock",
"(",
"state",
".",
"ChangeBlock",
")",
"\n",
"}"
] | // RemoveAllowed checks if remove block is in place.
// Remove block prevents removal of machine, service, unit
// and relation from current model. | [
"RemoveAllowed",
"checks",
"if",
"remove",
"block",
"is",
"in",
"place",
".",
"Remove",
"block",
"prevents",
"removal",
"of",
"machine",
"service",
"unit",
"and",
"relation",
"from",
"current",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/block.go#L35-L41 |
156,662 | juju/juju | apiserver/common/block.go | DestroyAllowed | func (c *BlockChecker) DestroyAllowed() error {
if err := c.checkBlock(state.DestroyBlock); err != nil {
return err
}
// Check if remove block has been enabled
if err := c.checkBlock(state.RemoveBlock); err != nil {
return err
}
// Check if change block has been enabled
return c.checkBlock(state.ChangeBlock)
} | go | func (c *BlockChecker) DestroyAllowed() error {
if err := c.checkBlock(state.DestroyBlock); err != nil {
return err
}
// Check if remove block has been enabled
if err := c.checkBlock(state.RemoveBlock); err != nil {
return err
}
// Check if change block has been enabled
return c.checkBlock(state.ChangeBlock)
} | [
"func",
"(",
"c",
"*",
"BlockChecker",
")",
"DestroyAllowed",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"checkBlock",
"(",
"state",
".",
"DestroyBlock",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Check if remove block has been enabled",
"if",
"err",
":=",
"c",
".",
"checkBlock",
"(",
"state",
".",
"RemoveBlock",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Check if change block has been enabled",
"return",
"c",
".",
"checkBlock",
"(",
"state",
".",
"ChangeBlock",
")",
"\n",
"}"
] | // DestroyAllowed checks if destroy block is in place.
// Destroy block prevents destruction of current model. | [
"DestroyAllowed",
"checks",
"if",
"destroy",
"block",
"is",
"in",
"place",
".",
"Destroy",
"block",
"prevents",
"destruction",
"of",
"current",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/block.go#L45-L55 |
156,663 | juju/juju | apiserver/common/block.go | checkBlock | func (c *BlockChecker) checkBlock(blockType state.BlockType) error {
aBlock, isEnabled, err := c.getter.GetBlockForType(blockType)
if err != nil {
return errors.Trace(err)
}
if isEnabled {
return OperationBlockedError(aBlock.Message())
}
return nil
} | go | func (c *BlockChecker) checkBlock(blockType state.BlockType) error {
aBlock, isEnabled, err := c.getter.GetBlockForType(blockType)
if err != nil {
return errors.Trace(err)
}
if isEnabled {
return OperationBlockedError(aBlock.Message())
}
return nil
} | [
"func",
"(",
"c",
"*",
"BlockChecker",
")",
"checkBlock",
"(",
"blockType",
"state",
".",
"BlockType",
")",
"error",
"{",
"aBlock",
",",
"isEnabled",
",",
"err",
":=",
"c",
".",
"getter",
".",
"GetBlockForType",
"(",
"blockType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"isEnabled",
"{",
"return",
"OperationBlockedError",
"(",
"aBlock",
".",
"Message",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkBlock checks if specified operation must be blocked.
// If it does, the method throws specific error that can be examined
// to stop operation execution. | [
"checkBlock",
"checks",
"if",
"specified",
"operation",
"must",
"be",
"blocked",
".",
"If",
"it",
"does",
"the",
"method",
"throws",
"specific",
"error",
"that",
"can",
"be",
"examined",
"to",
"stop",
"operation",
"execution",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/block.go#L60-L69 |
156,664 | juju/juju | provider/azure/storage.go | createManagedDiskVolumes | func (v *azureVolumeSource) createManagedDiskVolumes(ctx context.ProviderCallContext, params []storage.VolumeParams, results []storage.CreateVolumesResult) {
for i, p := range params {
if results[i].Error != nil {
continue
}
volume, err := v.createManagedDiskVolume(ctx, p)
if err != nil {
results[i].Error = err
continue
}
results[i].Volume = volume
}
} | go | func (v *azureVolumeSource) createManagedDiskVolumes(ctx context.ProviderCallContext, params []storage.VolumeParams, results []storage.CreateVolumesResult) {
for i, p := range params {
if results[i].Error != nil {
continue
}
volume, err := v.createManagedDiskVolume(ctx, p)
if err != nil {
results[i].Error = err
continue
}
results[i].Volume = volume
}
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"createManagedDiskVolumes",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"params",
"[",
"]",
"storage",
".",
"VolumeParams",
",",
"results",
"[",
"]",
"storage",
".",
"CreateVolumesResult",
")",
"{",
"for",
"i",
",",
"p",
":=",
"range",
"params",
"{",
"if",
"results",
"[",
"i",
"]",
".",
"Error",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"volume",
",",
"err",
":=",
"v",
".",
"createManagedDiskVolume",
"(",
"ctx",
",",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
".",
"Volume",
"=",
"volume",
"\n",
"}",
"\n",
"}"
] | // createManagedDiskVolumes creates volumes with associated managed disks. | [
"createManagedDiskVolumes",
"creates",
"volumes",
"with",
"associated",
"managed",
"disks",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L181-L193 |
156,665 | juju/juju | provider/azure/storage.go | createManagedDiskVolume | func (v *azureVolumeSource) createManagedDiskVolume(ctx context.ProviderCallContext, p storage.VolumeParams) (*storage.Volume, error) {
cfg, err := newAzureStorageConfig(p.Attributes)
if err != nil {
return nil, errors.Trace(err)
}
diskTags := make(map[string]*string)
for k, v := range p.ResourceTags {
diskTags[k] = to.StringPtr(v)
}
diskName := p.Tag.String()
sizeInGib := mibToGib(p.Size)
diskModel := compute.Disk{
Name: to.StringPtr(diskName),
Location: to.StringPtr(v.env.location),
Tags: diskTags,
Sku: &compute.DiskSku{
Name: cfg.storageType,
},
DiskProperties: &compute.DiskProperties{
CreationData: &compute.CreationData{CreateOption: compute.Empty},
DiskSizeGB: to.Int32Ptr(int32(sizeInGib)),
},
}
diskClient := compute.DisksClient{v.env.disk}
sdkCtx := stdcontext.Background()
future, err := diskClient.CreateOrUpdate(sdkCtx, v.env.resourceGroup, diskName, diskModel)
if err != nil {
return nil, errorutils.HandleCredentialError(errors.Annotatef(err, "creating disk for volume %q", p.Tag.Id()), ctx)
}
err = future.WaitForCompletionRef(sdkCtx, diskClient.Client)
if err != nil {
return nil, errorutils.HandleCredentialError(errors.Annotatef(err, "creating disk for volume %q", p.Tag.Id()), ctx)
}
result, err := future.Result(diskClient)
if err != nil && !isNotFoundResult(result.Response) {
return nil, errors.Annotatef(err, "creating disk for volume %q", p.Tag.Id())
}
volume := storage.Volume{
p.Tag,
storage.VolumeInfo{
VolumeId: diskName,
Size: gibToMib(uint64(to.Int32(result.DiskSizeGB))),
Persistent: true,
},
}
return &volume, nil
} | go | func (v *azureVolumeSource) createManagedDiskVolume(ctx context.ProviderCallContext, p storage.VolumeParams) (*storage.Volume, error) {
cfg, err := newAzureStorageConfig(p.Attributes)
if err != nil {
return nil, errors.Trace(err)
}
diskTags := make(map[string]*string)
for k, v := range p.ResourceTags {
diskTags[k] = to.StringPtr(v)
}
diskName := p.Tag.String()
sizeInGib := mibToGib(p.Size)
diskModel := compute.Disk{
Name: to.StringPtr(diskName),
Location: to.StringPtr(v.env.location),
Tags: diskTags,
Sku: &compute.DiskSku{
Name: cfg.storageType,
},
DiskProperties: &compute.DiskProperties{
CreationData: &compute.CreationData{CreateOption: compute.Empty},
DiskSizeGB: to.Int32Ptr(int32(sizeInGib)),
},
}
diskClient := compute.DisksClient{v.env.disk}
sdkCtx := stdcontext.Background()
future, err := diskClient.CreateOrUpdate(sdkCtx, v.env.resourceGroup, diskName, diskModel)
if err != nil {
return nil, errorutils.HandleCredentialError(errors.Annotatef(err, "creating disk for volume %q", p.Tag.Id()), ctx)
}
err = future.WaitForCompletionRef(sdkCtx, diskClient.Client)
if err != nil {
return nil, errorutils.HandleCredentialError(errors.Annotatef(err, "creating disk for volume %q", p.Tag.Id()), ctx)
}
result, err := future.Result(diskClient)
if err != nil && !isNotFoundResult(result.Response) {
return nil, errors.Annotatef(err, "creating disk for volume %q", p.Tag.Id())
}
volume := storage.Volume{
p.Tag,
storage.VolumeInfo{
VolumeId: diskName,
Size: gibToMib(uint64(to.Int32(result.DiskSizeGB))),
Persistent: true,
},
}
return &volume, nil
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"createManagedDiskVolume",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"p",
"storage",
".",
"VolumeParams",
")",
"(",
"*",
"storage",
".",
"Volume",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"newAzureStorageConfig",
"(",
"p",
".",
"Attributes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"diskTags",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"string",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"ResourceTags",
"{",
"diskTags",
"[",
"k",
"]",
"=",
"to",
".",
"StringPtr",
"(",
"v",
")",
"\n",
"}",
"\n",
"diskName",
":=",
"p",
".",
"Tag",
".",
"String",
"(",
")",
"\n",
"sizeInGib",
":=",
"mibToGib",
"(",
"p",
".",
"Size",
")",
"\n",
"diskModel",
":=",
"compute",
".",
"Disk",
"{",
"Name",
":",
"to",
".",
"StringPtr",
"(",
"diskName",
")",
",",
"Location",
":",
"to",
".",
"StringPtr",
"(",
"v",
".",
"env",
".",
"location",
")",
",",
"Tags",
":",
"diskTags",
",",
"Sku",
":",
"&",
"compute",
".",
"DiskSku",
"{",
"Name",
":",
"cfg",
".",
"storageType",
",",
"}",
",",
"DiskProperties",
":",
"&",
"compute",
".",
"DiskProperties",
"{",
"CreationData",
":",
"&",
"compute",
".",
"CreationData",
"{",
"CreateOption",
":",
"compute",
".",
"Empty",
"}",
",",
"DiskSizeGB",
":",
"to",
".",
"Int32Ptr",
"(",
"int32",
"(",
"sizeInGib",
")",
")",
",",
"}",
",",
"}",
"\n\n",
"diskClient",
":=",
"compute",
".",
"DisksClient",
"{",
"v",
".",
"env",
".",
"disk",
"}",
"\n",
"sdkCtx",
":=",
"stdcontext",
".",
"Background",
"(",
")",
"\n",
"future",
",",
"err",
":=",
"diskClient",
".",
"CreateOrUpdate",
"(",
"sdkCtx",
",",
"v",
".",
"env",
".",
"resourceGroup",
",",
"diskName",
",",
"diskModel",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errorutils",
".",
"HandleCredentialError",
"(",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"p",
".",
"Tag",
".",
"Id",
"(",
")",
")",
",",
"ctx",
")",
"\n",
"}",
"\n",
"err",
"=",
"future",
".",
"WaitForCompletionRef",
"(",
"sdkCtx",
",",
"diskClient",
".",
"Client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errorutils",
".",
"HandleCredentialError",
"(",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"p",
".",
"Tag",
".",
"Id",
"(",
")",
")",
",",
"ctx",
")",
"\n",
"}",
"\n",
"result",
",",
"err",
":=",
"future",
".",
"Result",
"(",
"diskClient",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"isNotFoundResult",
"(",
"result",
".",
"Response",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"p",
".",
"Tag",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n\n",
"volume",
":=",
"storage",
".",
"Volume",
"{",
"p",
".",
"Tag",
",",
"storage",
".",
"VolumeInfo",
"{",
"VolumeId",
":",
"diskName",
",",
"Size",
":",
"gibToMib",
"(",
"uint64",
"(",
"to",
".",
"Int32",
"(",
"result",
".",
"DiskSizeGB",
")",
")",
")",
",",
"Persistent",
":",
"true",
",",
"}",
",",
"}",
"\n",
"return",
"&",
"volume",
",",
"nil",
"\n",
"}"
] | // createManagedDiskVolume creates a managed disk. | [
"createManagedDiskVolume",
"creates",
"a",
"managed",
"disk",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L196-L245 |
156,666 | juju/juju | provider/azure/storage.go | createUnmanagedDiskVolume | func (v *azureVolumeSource) createUnmanagedDiskVolume(
vm *compute.VirtualMachine,
p storage.VolumeParams,
) (*storage.Volume, *storage.VolumeAttachment, error) {
diskName := p.Tag.String()
sizeInGib := mibToGib(p.Size)
volumeAttachment, err := v.addDataDisk(
vm,
diskName,
p.Tag,
p.Attachment.Machine,
compute.DiskCreateOptionTypesEmpty,
to.Int32Ptr(int32(sizeInGib)),
)
if err != nil {
return nil, nil, errors.Trace(err)
}
// Data disks associate VHDs to machines. In Juju's storage model,
// the VHD is the volume and the disk is the volume attachment.
volume := storage.Volume{
p.Tag,
storage.VolumeInfo{
VolumeId: diskName,
Size: gibToMib(sizeInGib),
Persistent: true,
},
}
return &volume, volumeAttachment, nil
} | go | func (v *azureVolumeSource) createUnmanagedDiskVolume(
vm *compute.VirtualMachine,
p storage.VolumeParams,
) (*storage.Volume, *storage.VolumeAttachment, error) {
diskName := p.Tag.String()
sizeInGib := mibToGib(p.Size)
volumeAttachment, err := v.addDataDisk(
vm,
diskName,
p.Tag,
p.Attachment.Machine,
compute.DiskCreateOptionTypesEmpty,
to.Int32Ptr(int32(sizeInGib)),
)
if err != nil {
return nil, nil, errors.Trace(err)
}
// Data disks associate VHDs to machines. In Juju's storage model,
// the VHD is the volume and the disk is the volume attachment.
volume := storage.Volume{
p.Tag,
storage.VolumeInfo{
VolumeId: diskName,
Size: gibToMib(sizeInGib),
Persistent: true,
},
}
return &volume, volumeAttachment, nil
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"createUnmanagedDiskVolume",
"(",
"vm",
"*",
"compute",
".",
"VirtualMachine",
",",
"p",
"storage",
".",
"VolumeParams",
",",
")",
"(",
"*",
"storage",
".",
"Volume",
",",
"*",
"storage",
".",
"VolumeAttachment",
",",
"error",
")",
"{",
"diskName",
":=",
"p",
".",
"Tag",
".",
"String",
"(",
")",
"\n",
"sizeInGib",
":=",
"mibToGib",
"(",
"p",
".",
"Size",
")",
"\n",
"volumeAttachment",
",",
"err",
":=",
"v",
".",
"addDataDisk",
"(",
"vm",
",",
"diskName",
",",
"p",
".",
"Tag",
",",
"p",
".",
"Attachment",
".",
"Machine",
",",
"compute",
".",
"DiskCreateOptionTypesEmpty",
",",
"to",
".",
"Int32Ptr",
"(",
"int32",
"(",
"sizeInGib",
")",
")",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Data disks associate VHDs to machines. In Juju's storage model,",
"// the VHD is the volume and the disk is the volume attachment.",
"volume",
":=",
"storage",
".",
"Volume",
"{",
"p",
".",
"Tag",
",",
"storage",
".",
"VolumeInfo",
"{",
"VolumeId",
":",
"diskName",
",",
"Size",
":",
"gibToMib",
"(",
"sizeInGib",
")",
",",
"Persistent",
":",
"true",
",",
"}",
",",
"}",
"\n",
"return",
"&",
"volume",
",",
"volumeAttachment",
",",
"nil",
"\n",
"}"
] | // createUnmanagedDiskVolume updates the provided VirtualMachine's
// StorageProfile with the parameters for creating a new unmanaged
// data disk. We don't actually interact with the Azure API until
// after all changes to the VirtualMachine are made. | [
"createUnmanagedDiskVolume",
"updates",
"the",
"provided",
"VirtualMachine",
"s",
"StorageProfile",
"with",
"the",
"parameters",
"for",
"creating",
"a",
"new",
"unmanaged",
"data",
"disk",
".",
"We",
"don",
"t",
"actually",
"interact",
"with",
"the",
"Azure",
"API",
"until",
"after",
"all",
"changes",
"to",
"the",
"VirtualMachine",
"are",
"made",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L306-L335 |
156,667 | juju/juju | provider/azure/storage.go | listBlobs | func (v *azureVolumeSource) listBlobs(ctx context.ProviderCallContext) ([]internalazurestorage.Blob, error) {
blobsClient := v.maybeStorageClient.GetBlobService()
vhdContainer := blobsClient.GetContainerReference(dataDiskVHDContainer)
// TODO(axw) consider taking a set of IDs and computing the
// longest common prefix to pass in the parameters
blobs, err := vhdContainer.Blobs()
if err != nil {
errorutils.HandleCredentialError(err, ctx)
if err, ok := err.(azurestorage.AzureStorageServiceError); ok {
switch err.Code {
case "ContainerNotFound":
return nil, nil
}
}
return nil, errors.Annotate(err, "listing blobs")
}
return blobs, nil
} | go | func (v *azureVolumeSource) listBlobs(ctx context.ProviderCallContext) ([]internalazurestorage.Blob, error) {
blobsClient := v.maybeStorageClient.GetBlobService()
vhdContainer := blobsClient.GetContainerReference(dataDiskVHDContainer)
// TODO(axw) consider taking a set of IDs and computing the
// longest common prefix to pass in the parameters
blobs, err := vhdContainer.Blobs()
if err != nil {
errorutils.HandleCredentialError(err, ctx)
if err, ok := err.(azurestorage.AzureStorageServiceError); ok {
switch err.Code {
case "ContainerNotFound":
return nil, nil
}
}
return nil, errors.Annotate(err, "listing blobs")
}
return blobs, nil
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"listBlobs",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"internalazurestorage",
".",
"Blob",
",",
"error",
")",
"{",
"blobsClient",
":=",
"v",
".",
"maybeStorageClient",
".",
"GetBlobService",
"(",
")",
"\n",
"vhdContainer",
":=",
"blobsClient",
".",
"GetContainerReference",
"(",
"dataDiskVHDContainer",
")",
"\n",
"// TODO(axw) consider taking a set of IDs and computing the",
"// longest common prefix to pass in the parameters",
"blobs",
",",
"err",
":=",
"vhdContainer",
".",
"Blobs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errorutils",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"azurestorage",
".",
"AzureStorageServiceError",
")",
";",
"ok",
"{",
"switch",
"err",
".",
"Code",
"{",
"case",
"\"",
"\"",
":",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"blobs",
",",
"nil",
"\n",
"}"
] | // listBlobs returns a list of blobs in the data-disk container. | [
"listBlobs",
"returns",
"a",
"list",
"of",
"blobs",
"in",
"the",
"data",
"-",
"disk",
"container",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L383-L400 |
156,668 | juju/juju | provider/azure/storage.go | diskResourceID | func (v *azureVolumeSource) diskResourceID(name string) string {
return path.Join(
"/subscriptions",
v.env.subscriptionId,
"resourceGroups",
v.env.resourceGroup,
"providers",
"Microsoft.Compute",
"disks",
name,
)
} | go | func (v *azureVolumeSource) diskResourceID(name string) string {
return path.Join(
"/subscriptions",
v.env.subscriptionId,
"resourceGroups",
v.env.resourceGroup,
"providers",
"Microsoft.Compute",
"disks",
name,
)
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"diskResourceID",
"(",
"name",
"string",
")",
"string",
"{",
"return",
"path",
".",
"Join",
"(",
"\"",
"\"",
",",
"v",
".",
"env",
".",
"subscriptionId",
",",
"\"",
"\"",
",",
"v",
".",
"env",
".",
"resourceGroup",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
",",
")",
"\n",
"}"
] | // diskResourceID returns the full resource ID for a disk, given its name. | [
"diskResourceID",
"returns",
"the",
"full",
"resource",
"ID",
"for",
"a",
"disk",
"given",
"its",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L768-L779 |
156,669 | juju/juju | provider/azure/storage.go | virtualMachines | func (v *azureVolumeSource) virtualMachines(ctx context.ProviderCallContext, instanceIds []instance.Id) (map[instance.Id]*maybeVirtualMachine, error) {
vmsClient := compute.VirtualMachinesClient{v.env.compute}
sdkCtx := stdcontext.Background()
result, err := vmsClient.ListComplete(sdkCtx, v.env.resourceGroup)
if err != nil {
return nil, errorutils.HandleCredentialError(errors.Annotate(err, "listing virtual machines"), ctx)
}
all := make(map[instance.Id]*compute.VirtualMachine)
for ; result.NotDone(); err = result.NextWithContext(sdkCtx) {
if err != nil {
return nil, errors.Annotate(err, "listing disks")
}
vmCopy := result.Value()
all[instance.Id(to.String(vmCopy.Name))] = &vmCopy
}
results := make(map[instance.Id]*maybeVirtualMachine)
for _, id := range instanceIds {
result := &maybeVirtualMachine{vm: all[id]}
if result.vm == nil {
result.err = errors.NotFoundf("instance %v", id)
}
results[id] = result
}
return results, nil
} | go | func (v *azureVolumeSource) virtualMachines(ctx context.ProviderCallContext, instanceIds []instance.Id) (map[instance.Id]*maybeVirtualMachine, error) {
vmsClient := compute.VirtualMachinesClient{v.env.compute}
sdkCtx := stdcontext.Background()
result, err := vmsClient.ListComplete(sdkCtx, v.env.resourceGroup)
if err != nil {
return nil, errorutils.HandleCredentialError(errors.Annotate(err, "listing virtual machines"), ctx)
}
all := make(map[instance.Id]*compute.VirtualMachine)
for ; result.NotDone(); err = result.NextWithContext(sdkCtx) {
if err != nil {
return nil, errors.Annotate(err, "listing disks")
}
vmCopy := result.Value()
all[instance.Id(to.String(vmCopy.Name))] = &vmCopy
}
results := make(map[instance.Id]*maybeVirtualMachine)
for _, id := range instanceIds {
result := &maybeVirtualMachine{vm: all[id]}
if result.vm == nil {
result.err = errors.NotFoundf("instance %v", id)
}
results[id] = result
}
return results, nil
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"virtualMachines",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"instanceIds",
"[",
"]",
"instance",
".",
"Id",
")",
"(",
"map",
"[",
"instance",
".",
"Id",
"]",
"*",
"maybeVirtualMachine",
",",
"error",
")",
"{",
"vmsClient",
":=",
"compute",
".",
"VirtualMachinesClient",
"{",
"v",
".",
"env",
".",
"compute",
"}",
"\n",
"sdkCtx",
":=",
"stdcontext",
".",
"Background",
"(",
")",
"\n",
"result",
",",
"err",
":=",
"vmsClient",
".",
"ListComplete",
"(",
"sdkCtx",
",",
"v",
".",
"env",
".",
"resourceGroup",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errorutils",
".",
"HandleCredentialError",
"(",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
",",
"ctx",
")",
"\n",
"}",
"\n\n",
"all",
":=",
"make",
"(",
"map",
"[",
"instance",
".",
"Id",
"]",
"*",
"compute",
".",
"VirtualMachine",
")",
"\n",
"for",
";",
"result",
".",
"NotDone",
"(",
")",
";",
"err",
"=",
"result",
".",
"NextWithContext",
"(",
"sdkCtx",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"vmCopy",
":=",
"result",
".",
"Value",
"(",
")",
"\n",
"all",
"[",
"instance",
".",
"Id",
"(",
"to",
".",
"String",
"(",
"vmCopy",
".",
"Name",
")",
")",
"]",
"=",
"&",
"vmCopy",
"\n",
"}",
"\n",
"results",
":=",
"make",
"(",
"map",
"[",
"instance",
".",
"Id",
"]",
"*",
"maybeVirtualMachine",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"instanceIds",
"{",
"result",
":=",
"&",
"maybeVirtualMachine",
"{",
"vm",
":",
"all",
"[",
"id",
"]",
"}",
"\n",
"if",
"result",
".",
"vm",
"==",
"nil",
"{",
"result",
".",
"err",
"=",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"results",
"[",
"id",
"]",
"=",
"result",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // virtualMachines returns a mapping of instance IDs to VirtualMachines and
// errors, for each of the specified instance IDs. | [
"virtualMachines",
"returns",
"a",
"mapping",
"of",
"instance",
"IDs",
"to",
"VirtualMachines",
"and",
"errors",
"for",
"each",
"of",
"the",
"specified",
"instance",
"IDs",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L788-L813 |
156,670 | juju/juju | provider/azure/storage.go | updateVirtualMachines | func (v *azureVolumeSource) updateVirtualMachines(
ctx context.ProviderCallContext,
virtualMachines map[instance.Id]*maybeVirtualMachine, instanceIds []instance.Id,
) ([]error, error) {
results := make([]error, len(instanceIds))
vmsClient := compute.VirtualMachinesClient{v.env.compute}
for i, instanceId := range instanceIds {
vm, ok := virtualMachines[instanceId]
if !ok {
continue
}
if vm.err != nil {
results[i] = vm.err
continue
}
sdkCtx := stdcontext.Background()
future, err := vmsClient.CreateOrUpdate(
sdkCtx,
v.env.resourceGroup, to.String(vm.vm.Name), *vm.vm,
)
if err != nil {
if errorutils.MaybeInvalidateCredential(err, ctx) {
return nil, errors.Trace(err)
}
results[i] = err
vm.err = err
continue
}
err = future.WaitForCompletionRef(sdkCtx, vmsClient.Client)
if err != nil {
results[i] = err
vm.err = err
continue
}
_, err = future.Result(vmsClient)
if err != nil {
results[i] = err
vm.err = err
continue
}
// successfully updated, don't update again
delete(virtualMachines, instanceId)
}
return results, nil
} | go | func (v *azureVolumeSource) updateVirtualMachines(
ctx context.ProviderCallContext,
virtualMachines map[instance.Id]*maybeVirtualMachine, instanceIds []instance.Id,
) ([]error, error) {
results := make([]error, len(instanceIds))
vmsClient := compute.VirtualMachinesClient{v.env.compute}
for i, instanceId := range instanceIds {
vm, ok := virtualMachines[instanceId]
if !ok {
continue
}
if vm.err != nil {
results[i] = vm.err
continue
}
sdkCtx := stdcontext.Background()
future, err := vmsClient.CreateOrUpdate(
sdkCtx,
v.env.resourceGroup, to.String(vm.vm.Name), *vm.vm,
)
if err != nil {
if errorutils.MaybeInvalidateCredential(err, ctx) {
return nil, errors.Trace(err)
}
results[i] = err
vm.err = err
continue
}
err = future.WaitForCompletionRef(sdkCtx, vmsClient.Client)
if err != nil {
results[i] = err
vm.err = err
continue
}
_, err = future.Result(vmsClient)
if err != nil {
results[i] = err
vm.err = err
continue
}
// successfully updated, don't update again
delete(virtualMachines, instanceId)
}
return results, nil
} | [
"func",
"(",
"v",
"*",
"azureVolumeSource",
")",
"updateVirtualMachines",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"virtualMachines",
"map",
"[",
"instance",
".",
"Id",
"]",
"*",
"maybeVirtualMachine",
",",
"instanceIds",
"[",
"]",
"instance",
".",
"Id",
",",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"instanceIds",
")",
")",
"\n",
"vmsClient",
":=",
"compute",
".",
"VirtualMachinesClient",
"{",
"v",
".",
"env",
".",
"compute",
"}",
"\n",
"for",
"i",
",",
"instanceId",
":=",
"range",
"instanceIds",
"{",
"vm",
",",
"ok",
":=",
"virtualMachines",
"[",
"instanceId",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"vm",
".",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
"=",
"vm",
".",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"sdkCtx",
":=",
"stdcontext",
".",
"Background",
"(",
")",
"\n",
"future",
",",
"err",
":=",
"vmsClient",
".",
"CreateOrUpdate",
"(",
"sdkCtx",
",",
"v",
".",
"env",
".",
"resourceGroup",
",",
"to",
".",
"String",
"(",
"vm",
".",
"vm",
".",
"Name",
")",
",",
"*",
"vm",
".",
"vm",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errorutils",
".",
"MaybeInvalidateCredential",
"(",
"err",
",",
"ctx",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
"=",
"err",
"\n",
"vm",
".",
"err",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"err",
"=",
"future",
".",
"WaitForCompletionRef",
"(",
"sdkCtx",
",",
"vmsClient",
".",
"Client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
"=",
"err",
"\n",
"vm",
".",
"err",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"future",
".",
"Result",
"(",
"vmsClient",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
"=",
"err",
"\n",
"vm",
".",
"err",
"=",
"err",
"\n",
"continue",
"\n",
"}",
"\n",
"// successfully updated, don't update again",
"delete",
"(",
"virtualMachines",
",",
"instanceId",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // updateVirtualMachines updates virtual machines in the given map by iterating
// through the list of instance IDs in order, and updating each corresponding
// virtual machine at most once. | [
"updateVirtualMachines",
"updates",
"virtual",
"machines",
"in",
"the",
"given",
"map",
"by",
"iterating",
"through",
"the",
"list",
"of",
"instance",
"IDs",
"in",
"order",
"and",
"updating",
"each",
"corresponding",
"virtual",
"machine",
"at",
"most",
"once",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L818-L862 |
156,671 | juju/juju | provider/azure/storage.go | blobContainerURL | func blobContainerURL(storageAccount *armstorage.Account, container string) string {
return fmt.Sprintf(
"%s%s/",
to.String(storageAccount.PrimaryEndpoints.Blob),
container,
)
} | go | func blobContainerURL(storageAccount *armstorage.Account, container string) string {
return fmt.Sprintf(
"%s%s/",
to.String(storageAccount.PrimaryEndpoints.Blob),
container,
)
} | [
"func",
"blobContainerURL",
"(",
"storageAccount",
"*",
"armstorage",
".",
"Account",
",",
"container",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"to",
".",
"String",
"(",
"storageAccount",
".",
"PrimaryEndpoints",
".",
"Blob",
")",
",",
"container",
",",
")",
"\n",
"}"
] | // blobContainer returns the URL to the named blob container. | [
"blobContainer",
"returns",
"the",
"URL",
"to",
"the",
"named",
"blob",
"container",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L911-L917 |
156,672 | juju/juju | provider/azure/storage.go | blobVolumeId | func blobVolumeId(blob internalazurestorage.Blob) (string, bool) {
blobName := blob.Name()
if !strings.HasSuffix(blobName, vhdExtension) {
return "", false
}
volumeId := blobName[:len(blobName)-len(vhdExtension)]
if _, err := names.ParseVolumeTag(volumeId); err != nil {
return "", false
}
return volumeId, true
} | go | func blobVolumeId(blob internalazurestorage.Blob) (string, bool) {
blobName := blob.Name()
if !strings.HasSuffix(blobName, vhdExtension) {
return "", false
}
volumeId := blobName[:len(blobName)-len(vhdExtension)]
if _, err := names.ParseVolumeTag(volumeId); err != nil {
return "", false
}
return volumeId, true
} | [
"func",
"blobVolumeId",
"(",
"blob",
"internalazurestorage",
".",
"Blob",
")",
"(",
"string",
",",
"bool",
")",
"{",
"blobName",
":=",
"blob",
".",
"Name",
"(",
")",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"blobName",
",",
"vhdExtension",
")",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"volumeId",
":=",
"blobName",
"[",
":",
"len",
"(",
"blobName",
")",
"-",
"len",
"(",
"vhdExtension",
")",
"]",
"\n",
"if",
"_",
",",
"err",
":=",
"names",
".",
"ParseVolumeTag",
"(",
"volumeId",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"return",
"volumeId",
",",
"true",
"\n",
"}"
] | // blobVolumeId returns the volume ID for a blob, and a boolean reporting
// whether or not the blob's name matches the scheme we use. | [
"blobVolumeId",
"returns",
"the",
"volume",
"ID",
"for",
"a",
"blob",
"and",
"a",
"boolean",
"reporting",
"whether",
"or",
"not",
"the",
"blob",
"s",
"name",
"matches",
"the",
"scheme",
"we",
"use",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L921-L931 |
156,673 | juju/juju | provider/azure/storage.go | getStorageClient | func getStorageClient(
newClient internalazurestorage.NewClientFunc,
storageEndpoint string,
storageAccount *armstorage.Account,
storageAccountKey *armstorage.AccountKey,
) (internalazurestorage.Client, error) {
storageAccountName := to.String(storageAccount.Name)
const useHTTPS = true
return newClient(
storageAccountName,
to.String(storageAccountKey.Value),
storageEndpoint,
azurestorage.DefaultAPIVersion,
useHTTPS,
)
} | go | func getStorageClient(
newClient internalazurestorage.NewClientFunc,
storageEndpoint string,
storageAccount *armstorage.Account,
storageAccountKey *armstorage.AccountKey,
) (internalazurestorage.Client, error) {
storageAccountName := to.String(storageAccount.Name)
const useHTTPS = true
return newClient(
storageAccountName,
to.String(storageAccountKey.Value),
storageEndpoint,
azurestorage.DefaultAPIVersion,
useHTTPS,
)
} | [
"func",
"getStorageClient",
"(",
"newClient",
"internalazurestorage",
".",
"NewClientFunc",
",",
"storageEndpoint",
"string",
",",
"storageAccount",
"*",
"armstorage",
".",
"Account",
",",
"storageAccountKey",
"*",
"armstorage",
".",
"AccountKey",
",",
")",
"(",
"internalazurestorage",
".",
"Client",
",",
"error",
")",
"{",
"storageAccountName",
":=",
"to",
".",
"String",
"(",
"storageAccount",
".",
"Name",
")",
"\n",
"const",
"useHTTPS",
"=",
"true",
"\n",
"return",
"newClient",
"(",
"storageAccountName",
",",
"to",
".",
"String",
"(",
"storageAccountKey",
".",
"Value",
")",
",",
"storageEndpoint",
",",
"azurestorage",
".",
"DefaultAPIVersion",
",",
"useHTTPS",
",",
")",
"\n",
"}"
] | // getStorageClient returns a new storage client, given an environ config
// and a constructor. | [
"getStorageClient",
"returns",
"a",
"new",
"storage",
"client",
"given",
"an",
"environ",
"config",
"and",
"a",
"constructor",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L935-L950 |
156,674 | juju/juju | provider/azure/storage.go | getStorageAccountKey | func getStorageAccountKey(
client armstorage.AccountsClient,
resourceGroup, accountName string,
) (*armstorage.AccountKey, error) {
logger.Debugf("getting keys for storage account %q", accountName)
sdkCtx := stdcontext.Background()
listKeysResult, err := client.ListKeys(sdkCtx, resourceGroup, accountName)
if err != nil {
if isNotFoundResult(listKeysResult.Response) {
return nil, errors.NewNotFound(err, "storage account keys not found")
}
return nil, errors.Annotate(err, "listing storage account keys")
}
if listKeysResult.Keys == nil {
return nil, errors.NotFoundf("storage account keys")
}
// We need a storage key with full permissions.
var fullKey *armstorage.AccountKey
for _, key := range *listKeysResult.Keys {
logger.Debugf("storage account key: %#v", key)
// At least some of the time, Azure returns the permissions
// in title-case, which does not match the constant.
if strings.ToUpper(string(key.Permissions)) != strings.ToUpper(string(armstorage.Full)) {
continue
}
fullKey = &key
break
}
if fullKey == nil {
return nil, errors.NotFoundf(
"storage account key with %q permission",
armstorage.Full,
)
}
return fullKey, nil
} | go | func getStorageAccountKey(
client armstorage.AccountsClient,
resourceGroup, accountName string,
) (*armstorage.AccountKey, error) {
logger.Debugf("getting keys for storage account %q", accountName)
sdkCtx := stdcontext.Background()
listKeysResult, err := client.ListKeys(sdkCtx, resourceGroup, accountName)
if err != nil {
if isNotFoundResult(listKeysResult.Response) {
return nil, errors.NewNotFound(err, "storage account keys not found")
}
return nil, errors.Annotate(err, "listing storage account keys")
}
if listKeysResult.Keys == nil {
return nil, errors.NotFoundf("storage account keys")
}
// We need a storage key with full permissions.
var fullKey *armstorage.AccountKey
for _, key := range *listKeysResult.Keys {
logger.Debugf("storage account key: %#v", key)
// At least some of the time, Azure returns the permissions
// in title-case, which does not match the constant.
if strings.ToUpper(string(key.Permissions)) != strings.ToUpper(string(armstorage.Full)) {
continue
}
fullKey = &key
break
}
if fullKey == nil {
return nil, errors.NotFoundf(
"storage account key with %q permission",
armstorage.Full,
)
}
return fullKey, nil
} | [
"func",
"getStorageAccountKey",
"(",
"client",
"armstorage",
".",
"AccountsClient",
",",
"resourceGroup",
",",
"accountName",
"string",
",",
")",
"(",
"*",
"armstorage",
".",
"AccountKey",
",",
"error",
")",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"accountName",
")",
"\n",
"sdkCtx",
":=",
"stdcontext",
".",
"Background",
"(",
")",
"\n",
"listKeysResult",
",",
"err",
":=",
"client",
".",
"ListKeys",
"(",
"sdkCtx",
",",
"resourceGroup",
",",
"accountName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"isNotFoundResult",
"(",
"listKeysResult",
".",
"Response",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NewNotFound",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"listKeysResult",
".",
"Keys",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// We need a storage key with full permissions.",
"var",
"fullKey",
"*",
"armstorage",
".",
"AccountKey",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"*",
"listKeysResult",
".",
"Keys",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"// At least some of the time, Azure returns the permissions",
"// in title-case, which does not match the constant.",
"if",
"strings",
".",
"ToUpper",
"(",
"string",
"(",
"key",
".",
"Permissions",
")",
")",
"!=",
"strings",
".",
"ToUpper",
"(",
"string",
"(",
"armstorage",
".",
"Full",
")",
")",
"{",
"continue",
"\n",
"}",
"\n",
"fullKey",
"=",
"&",
"key",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"fullKey",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"armstorage",
".",
"Full",
",",
")",
"\n",
"}",
"\n",
"return",
"fullKey",
",",
"nil",
"\n",
"}"
] | // getStorageAccountKey returns the key for the storage account. | [
"getStorageAccountKey",
"returns",
"the",
"key",
"for",
"the",
"storage",
"account",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L953-L989 |
156,675 | juju/juju | provider/azure/storage.go | storageAccountTemplateResource | func storageAccountTemplateResource(
location string,
envTags map[string]string,
accountName, accountType string,
) armtemplates.Resource {
return armtemplates.Resource{
APIVersion: storageAPIVersion,
Type: "Microsoft.Storage/storageAccounts",
Name: accountName,
Location: location,
Tags: envTags,
StorageSku: &armstorage.Sku{
Name: armstorage.SkuName(accountType),
},
}
} | go | func storageAccountTemplateResource(
location string,
envTags map[string]string,
accountName, accountType string,
) armtemplates.Resource {
return armtemplates.Resource{
APIVersion: storageAPIVersion,
Type: "Microsoft.Storage/storageAccounts",
Name: accountName,
Location: location,
Tags: envTags,
StorageSku: &armstorage.Sku{
Name: armstorage.SkuName(accountType),
},
}
} | [
"func",
"storageAccountTemplateResource",
"(",
"location",
"string",
",",
"envTags",
"map",
"[",
"string",
"]",
"string",
",",
"accountName",
",",
"accountType",
"string",
",",
")",
"armtemplates",
".",
"Resource",
"{",
"return",
"armtemplates",
".",
"Resource",
"{",
"APIVersion",
":",
"storageAPIVersion",
",",
"Type",
":",
"\"",
"\"",
",",
"Name",
":",
"accountName",
",",
"Location",
":",
"location",
",",
"Tags",
":",
"envTags",
",",
"StorageSku",
":",
"&",
"armstorage",
".",
"Sku",
"{",
"Name",
":",
"armstorage",
".",
"SkuName",
"(",
"accountType",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // storageAccountTemplateResource returns a template resource definition
// for creating a storage account. | [
"storageAccountTemplateResource",
"returns",
"a",
"template",
"resource",
"definition",
"for",
"creating",
"a",
"storage",
"account",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/storage.go#L993-L1008 |
156,676 | juju/juju | apiserver/common/modelmachineswatcher.go | NewModelMachinesWatcher | func NewModelMachinesWatcher(st state.ModelMachinesWatcher, resources facade.Resources, authorizer facade.Authorizer) *ModelMachinesWatcher {
return &ModelMachinesWatcher{
st: st,
resources: resources,
authorizer: authorizer,
}
} | go | func NewModelMachinesWatcher(st state.ModelMachinesWatcher, resources facade.Resources, authorizer facade.Authorizer) *ModelMachinesWatcher {
return &ModelMachinesWatcher{
st: st,
resources: resources,
authorizer: authorizer,
}
} | [
"func",
"NewModelMachinesWatcher",
"(",
"st",
"state",
".",
"ModelMachinesWatcher",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
")",
"*",
"ModelMachinesWatcher",
"{",
"return",
"&",
"ModelMachinesWatcher",
"{",
"st",
":",
"st",
",",
"resources",
":",
"resources",
",",
"authorizer",
":",
"authorizer",
",",
"}",
"\n",
"}"
] | // NewModelMachinesWatcher returns a new ModelMachinesWatcher. The
// GetAuthFunc will be used on each invocation of WatchUnits to
// determine current permissions. | [
"NewModelMachinesWatcher",
"returns",
"a",
"new",
"ModelMachinesWatcher",
".",
"The",
"GetAuthFunc",
"will",
"be",
"used",
"on",
"each",
"invocation",
"of",
"WatchUnits",
"to",
"determine",
"current",
"permissions",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/modelmachineswatcher.go#L26-L32 |
156,677 | juju/juju | apiserver/common/modelmachineswatcher.go | WatchModelMachines | func (e *ModelMachinesWatcher) WatchModelMachines() (params.StringsWatchResult, error) {
result := params.StringsWatchResult{}
if !e.authorizer.AuthController() {
return result, ErrPerm
}
watch := e.st.WatchModelMachines()
// Consume the initial event and forward it to the result.
if changes, ok := <-watch.Changes(); ok {
result.StringsWatcherId = e.resources.Register(watch)
result.Changes = changes
} else {
err := watcher.EnsureErr(watch)
return result, fmt.Errorf("cannot obtain initial model machines: %v", err)
}
return result, nil
} | go | func (e *ModelMachinesWatcher) WatchModelMachines() (params.StringsWatchResult, error) {
result := params.StringsWatchResult{}
if !e.authorizer.AuthController() {
return result, ErrPerm
}
watch := e.st.WatchModelMachines()
// Consume the initial event and forward it to the result.
if changes, ok := <-watch.Changes(); ok {
result.StringsWatcherId = e.resources.Register(watch)
result.Changes = changes
} else {
err := watcher.EnsureErr(watch)
return result, fmt.Errorf("cannot obtain initial model machines: %v", err)
}
return result, nil
} | [
"func",
"(",
"e",
"*",
"ModelMachinesWatcher",
")",
"WatchModelMachines",
"(",
")",
"(",
"params",
".",
"StringsWatchResult",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"StringsWatchResult",
"{",
"}",
"\n",
"if",
"!",
"e",
".",
"authorizer",
".",
"AuthController",
"(",
")",
"{",
"return",
"result",
",",
"ErrPerm",
"\n",
"}",
"\n",
"watch",
":=",
"e",
".",
"st",
".",
"WatchModelMachines",
"(",
")",
"\n",
"// Consume the initial event and forward it to the result.",
"if",
"changes",
",",
"ok",
":=",
"<-",
"watch",
".",
"Changes",
"(",
")",
";",
"ok",
"{",
"result",
".",
"StringsWatcherId",
"=",
"e",
".",
"resources",
".",
"Register",
"(",
"watch",
")",
"\n",
"result",
".",
"Changes",
"=",
"changes",
"\n",
"}",
"else",
"{",
"err",
":=",
"watcher",
".",
"EnsureErr",
"(",
"watch",
")",
"\n",
"return",
"result",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // WatchModelMachines returns a StringsWatcher that notifies of
// changes to the life cycles of the top level machines in the current
// model. | [
"WatchModelMachines",
"returns",
"a",
"StringsWatcher",
"that",
"notifies",
"of",
"changes",
"to",
"the",
"life",
"cycles",
"of",
"the",
"top",
"level",
"machines",
"in",
"the",
"current",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/modelmachineswatcher.go#L37-L52 |
156,678 | juju/juju | apiserver/stateauthenticator/modeluser.go | FindEntity | func (f modelUserEntityFinder) FindEntity(tag names.Tag) (state.Entity, error) {
utag, ok := tag.(names.UserTag)
if !ok {
return f.st.FindEntity(tag)
}
model, err := f.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
modelUser, err := f.st.UserAccess(utag, model.ModelTag())
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// No model user found, so see if the user has been granted
// access to the controller.
if permission.IsEmptyUserAccess(modelUser) {
controllerUser, err := state.ControllerAccess(f.st, utag)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// TODO(perrito666) remove the following section about everyone group
// when groups are implemented, this accounts only for the lack of a local
// ControllerUser when logging in from an external user that has not been granted
// permissions on the controller but there are permissions for the special
// everyone group.
if permission.IsEmptyUserAccess(controllerUser) && !utag.IsLocal() {
everyoneTag := names.NewUserTag(common.EveryoneTagName)
controllerUser, err = f.st.UserAccess(everyoneTag, f.st.ControllerTag())
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Annotatef(err, "obtaining ControllerUser for everyone group")
}
}
if permission.IsEmptyUserAccess(controllerUser) {
return nil, errors.NotFoundf("model or controller user")
}
}
u := &modelUserEntity{
st: f.st,
modelUser: modelUser,
tag: utag,
}
if utag.IsLocal() {
user, err := f.st.User(utag)
if err != nil {
return nil, errors.Trace(err)
}
u.user = user
}
return u, nil
} | go | func (f modelUserEntityFinder) FindEntity(tag names.Tag) (state.Entity, error) {
utag, ok := tag.(names.UserTag)
if !ok {
return f.st.FindEntity(tag)
}
model, err := f.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
modelUser, err := f.st.UserAccess(utag, model.ModelTag())
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// No model user found, so see if the user has been granted
// access to the controller.
if permission.IsEmptyUserAccess(modelUser) {
controllerUser, err := state.ControllerAccess(f.st, utag)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// TODO(perrito666) remove the following section about everyone group
// when groups are implemented, this accounts only for the lack of a local
// ControllerUser when logging in from an external user that has not been granted
// permissions on the controller but there are permissions for the special
// everyone group.
if permission.IsEmptyUserAccess(controllerUser) && !utag.IsLocal() {
everyoneTag := names.NewUserTag(common.EveryoneTagName)
controllerUser, err = f.st.UserAccess(everyoneTag, f.st.ControllerTag())
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Annotatef(err, "obtaining ControllerUser for everyone group")
}
}
if permission.IsEmptyUserAccess(controllerUser) {
return nil, errors.NotFoundf("model or controller user")
}
}
u := &modelUserEntity{
st: f.st,
modelUser: modelUser,
tag: utag,
}
if utag.IsLocal() {
user, err := f.st.User(utag)
if err != nil {
return nil, errors.Trace(err)
}
u.user = user
}
return u, nil
} | [
"func",
"(",
"f",
"modelUserEntityFinder",
")",
"FindEntity",
"(",
"tag",
"names",
".",
"Tag",
")",
"(",
"state",
".",
"Entity",
",",
"error",
")",
"{",
"utag",
",",
"ok",
":=",
"tag",
".",
"(",
"names",
".",
"UserTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"f",
".",
"st",
".",
"FindEntity",
"(",
"tag",
")",
"\n",
"}",
"\n\n",
"model",
",",
"err",
":=",
"f",
".",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"modelUser",
",",
"err",
":=",
"f",
".",
"st",
".",
"UserAccess",
"(",
"utag",
",",
"model",
".",
"ModelTag",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// No model user found, so see if the user has been granted",
"// access to the controller.",
"if",
"permission",
".",
"IsEmptyUserAccess",
"(",
"modelUser",
")",
"{",
"controllerUser",
",",
"err",
":=",
"state",
".",
"ControllerAccess",
"(",
"f",
".",
"st",
",",
"utag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// TODO(perrito666) remove the following section about everyone group",
"// when groups are implemented, this accounts only for the lack of a local",
"// ControllerUser when logging in from an external user that has not been granted",
"// permissions on the controller but there are permissions for the special",
"// everyone group.",
"if",
"permission",
".",
"IsEmptyUserAccess",
"(",
"controllerUser",
")",
"&&",
"!",
"utag",
".",
"IsLocal",
"(",
")",
"{",
"everyoneTag",
":=",
"names",
".",
"NewUserTag",
"(",
"common",
".",
"EveryoneTagName",
")",
"\n",
"controllerUser",
",",
"err",
"=",
"f",
".",
"st",
".",
"UserAccess",
"(",
"everyoneTag",
",",
"f",
".",
"st",
".",
"ControllerTag",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"permission",
".",
"IsEmptyUserAccess",
"(",
"controllerUser",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"u",
":=",
"&",
"modelUserEntity",
"{",
"st",
":",
"f",
".",
"st",
",",
"modelUser",
":",
"modelUser",
",",
"tag",
":",
"utag",
",",
"}",
"\n",
"if",
"utag",
".",
"IsLocal",
"(",
")",
"{",
"user",
",",
"err",
":=",
"f",
".",
"st",
".",
"User",
"(",
"utag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"u",
".",
"user",
"=",
"user",
"\n",
"}",
"\n",
"return",
"u",
",",
"nil",
"\n",
"}"
] | // FindEntity implements state.EntityFinder. | [
"FindEntity",
"implements",
"state",
".",
"EntityFinder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/stateauthenticator/modeluser.go#L34-L86 |
156,679 | juju/juju | apiserver/stateauthenticator/modeluser.go | Refresh | func (u *modelUserEntity) Refresh() error {
if u.user == nil {
return nil
}
return u.user.Refresh()
} | go | func (u *modelUserEntity) Refresh() error {
if u.user == nil {
return nil
}
return u.user.Refresh()
} | [
"func",
"(",
"u",
"*",
"modelUserEntity",
")",
"Refresh",
"(",
")",
"error",
"{",
"if",
"u",
".",
"user",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"u",
".",
"user",
".",
"Refresh",
"(",
")",
"\n",
"}"
] | // Refresh implements state.Authenticator.Refresh. | [
"Refresh",
"implements",
"state",
".",
"Authenticator",
".",
"Refresh",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/stateauthenticator/modeluser.go#L102-L107 |
156,680 | juju/juju | apiserver/stateauthenticator/modeluser.go | SetPassword | func (u *modelUserEntity) SetPassword(pass string) error {
if u.user == nil {
return errors.New("cannot set password on external user")
}
return u.user.SetPassword(pass)
} | go | func (u *modelUserEntity) SetPassword(pass string) error {
if u.user == nil {
return errors.New("cannot set password on external user")
}
return u.user.SetPassword(pass)
} | [
"func",
"(",
"u",
"*",
"modelUserEntity",
")",
"SetPassword",
"(",
"pass",
"string",
")",
"error",
"{",
"if",
"u",
".",
"user",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"u",
".",
"user",
".",
"SetPassword",
"(",
"pass",
")",
"\n",
"}"
] | // SetPassword implements state.Authenticator.SetPassword
// by setting the password on the local user. | [
"SetPassword",
"implements",
"state",
".",
"Authenticator",
".",
"SetPassword",
"by",
"setting",
"the",
"password",
"on",
"the",
"local",
"user",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/stateauthenticator/modeluser.go#L111-L116 |
156,681 | juju/juju | apiserver/stateauthenticator/modeluser.go | PasswordValid | func (u *modelUserEntity) PasswordValid(pass string) bool {
if u.user == nil {
return false
}
return u.user.PasswordValid(pass)
} | go | func (u *modelUserEntity) PasswordValid(pass string) bool {
if u.user == nil {
return false
}
return u.user.PasswordValid(pass)
} | [
"func",
"(",
"u",
"*",
"modelUserEntity",
")",
"PasswordValid",
"(",
"pass",
"string",
")",
"bool",
"{",
"if",
"u",
".",
"user",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"u",
".",
"user",
".",
"PasswordValid",
"(",
"pass",
")",
"\n",
"}"
] | // PasswordValid implements state.Authenticator.PasswordValid. | [
"PasswordValid",
"implements",
"state",
".",
"Authenticator",
".",
"PasswordValid",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/stateauthenticator/modeluser.go#L119-L124 |
156,682 | juju/juju | apiserver/stateauthenticator/modeluser.go | LastLogin | func (u *modelUserEntity) LastLogin() (time.Time, error) {
// The last connection for the model takes precedence over
// the local user last login time.
var err error
var t time.Time
model, err := u.st.Model()
if err != nil {
return t, errors.Trace(err)
}
if !permission.IsEmptyUserAccess(u.modelUser) {
t, err = model.LastModelConnection(u.modelUser.UserTag)
} else {
err = state.NeverConnectedError("controller user")
}
if state.IsNeverConnectedError(err) || permission.IsEmptyUserAccess(u.modelUser) {
if u.user != nil {
// There's a global user, so use that login time instead.
return u.user.LastLogin()
}
// Since we're implementing LastLogin, we need
// to implement LastLogin error semantics too.
err = state.NeverLoggedInError(err.Error())
}
return t, errors.Trace(err)
} | go | func (u *modelUserEntity) LastLogin() (time.Time, error) {
// The last connection for the model takes precedence over
// the local user last login time.
var err error
var t time.Time
model, err := u.st.Model()
if err != nil {
return t, errors.Trace(err)
}
if !permission.IsEmptyUserAccess(u.modelUser) {
t, err = model.LastModelConnection(u.modelUser.UserTag)
} else {
err = state.NeverConnectedError("controller user")
}
if state.IsNeverConnectedError(err) || permission.IsEmptyUserAccess(u.modelUser) {
if u.user != nil {
// There's a global user, so use that login time instead.
return u.user.LastLogin()
}
// Since we're implementing LastLogin, we need
// to implement LastLogin error semantics too.
err = state.NeverLoggedInError(err.Error())
}
return t, errors.Trace(err)
} | [
"func",
"(",
"u",
"*",
"modelUserEntity",
")",
"LastLogin",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"// The last connection for the model takes precedence over",
"// the local user last login time.",
"var",
"err",
"error",
"\n",
"var",
"t",
"time",
".",
"Time",
"\n\n",
"model",
",",
"err",
":=",
"u",
".",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"t",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"permission",
".",
"IsEmptyUserAccess",
"(",
"u",
".",
"modelUser",
")",
"{",
"t",
",",
"err",
"=",
"model",
".",
"LastModelConnection",
"(",
"u",
".",
"modelUser",
".",
"UserTag",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"state",
".",
"NeverConnectedError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"state",
".",
"IsNeverConnectedError",
"(",
"err",
")",
"||",
"permission",
".",
"IsEmptyUserAccess",
"(",
"u",
".",
"modelUser",
")",
"{",
"if",
"u",
".",
"user",
"!=",
"nil",
"{",
"// There's a global user, so use that login time instead.",
"return",
"u",
".",
"user",
".",
"LastLogin",
"(",
")",
"\n",
"}",
"\n",
"// Since we're implementing LastLogin, we need",
"// to implement LastLogin error semantics too.",
"err",
"=",
"state",
".",
"NeverLoggedInError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // LastLogin implements loginEntity.LastLogin. | [
"LastLogin",
"implements",
"loginEntity",
".",
"LastLogin",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/stateauthenticator/modeluser.go#L132-L158 |
156,683 | juju/juju | apiserver/stateauthenticator/modeluser.go | UpdateLastLogin | func (u *modelUserEntity) UpdateLastLogin() error {
var err error
if !permission.IsEmptyUserAccess(u.modelUser) {
if u.modelUser.Object.Kind() != names.ModelTagKind {
return errors.NotValidf("%s as model user", u.modelUser.Object.Kind())
}
model, err := u.st.Model()
if err != nil {
return errors.Trace(err)
}
err = model.UpdateLastModelConnection(u.modelUser.UserTag)
}
if u.user != nil {
err1 := u.user.UpdateLastLogin()
if err == nil {
return err1
}
}
if err != nil {
return errors.Trace(err)
}
return nil
} | go | func (u *modelUserEntity) UpdateLastLogin() error {
var err error
if !permission.IsEmptyUserAccess(u.modelUser) {
if u.modelUser.Object.Kind() != names.ModelTagKind {
return errors.NotValidf("%s as model user", u.modelUser.Object.Kind())
}
model, err := u.st.Model()
if err != nil {
return errors.Trace(err)
}
err = model.UpdateLastModelConnection(u.modelUser.UserTag)
}
if u.user != nil {
err1 := u.user.UpdateLastLogin()
if err == nil {
return err1
}
}
if err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"u",
"*",
"modelUserEntity",
")",
"UpdateLastLogin",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"!",
"permission",
".",
"IsEmptyUserAccess",
"(",
"u",
".",
"modelUser",
")",
"{",
"if",
"u",
".",
"modelUser",
".",
"Object",
".",
"Kind",
"(",
")",
"!=",
"names",
".",
"ModelTagKind",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"u",
".",
"modelUser",
".",
"Object",
".",
"Kind",
"(",
")",
")",
"\n",
"}",
"\n\n",
"model",
",",
"err",
":=",
"u",
".",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"model",
".",
"UpdateLastModelConnection",
"(",
"u",
".",
"modelUser",
".",
"UserTag",
")",
"\n",
"}",
"\n\n",
"if",
"u",
".",
"user",
"!=",
"nil",
"{",
"err1",
":=",
"u",
".",
"user",
".",
"UpdateLastLogin",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"err1",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UpdateLastLogin implements loginEntity.UpdateLastLogin. | [
"UpdateLastLogin",
"implements",
"loginEntity",
".",
"UpdateLastLogin",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/stateauthenticator/modeluser.go#L161-L187 |
156,684 | juju/juju | apiserver/facades/client/backups/restore.go | Restore | func (a *API) Restore(p params.RestoreArgs) error {
logger.Infof("Starting server side restore")
// Get hold of a backup file Reader
backup, closer := newBackups(a.backend)
defer closer.Close()
// Obtain the address of current machine, where we will be performing restore.
machine, err := a.backend.Machine(a.machineID)
if err != nil {
return errors.Trace(err)
}
addr, err := machine.PrivateAddress()
if err != nil {
return errors.Annotatef(err, "error fetching internal address for machine %q", machine)
}
publicAddress, err := machine.PublicAddress()
if err != nil {
return errors.Annotatef(err, "error fetching public address for machine %q", machine)
}
info := a.backend.RestoreInfo()
// Signal to current state and api server that restore will begin
err = info.SetStatus(state.RestoreInProgress)
if err != nil {
return errors.Annotatef(err, "cannot set the server to %q mode", state.RestoreInProgress)
}
// Any abnormal termination of this function will mark restore as failed,
// successful termination will call Exit and never run this.
defer info.SetStatus(state.RestoreFailed)
instanceId, err := machine.InstanceId()
if err != nil {
return errors.Annotate(err, "cannot obtain instance id for machine to be restored")
}
logger.Infof("beginning server side restore of backup %q", p.BackupId)
// Restore
restoreArgs := backups.RestoreArgs{
PrivateAddress: addr.Value,
PublicAddress: publicAddress.Value,
NewInstId: instanceId,
NewInstTag: machine.Tag(),
NewInstSeries: machine.Series(),
}
session := a.backend.MongoSession().Copy()
defer session.Close()
// Don't go if HA isn't ready.
err = waitUntilReady(session, 60)
if err != nil {
return errors.Annotatef(err, "HA not ready; try again later")
}
oldTagString, err := backup.Restore(p.BackupId, restoreArgs)
if err != nil {
return errors.Annotate(err, "restore failed")
}
// A backup can be made of any component of an ha array.
// The files in a backup don't contain purely relativized paths.
// If the backup is made of the bootstrap node (machine 0) the
// recently created machine will have the same paths and therefore
// the startup scripts will fit the new juju. If the backup belongs
// to a different machine, we need to create a new set of startup
// scripts and exit with 0 (so that the current script does not try
// to restart the old juju, which will no longer be there).
if oldTagString != nil && oldTagString != bootstrapNode {
srvName := fmt.Sprintf("jujud-%s", oldTagString)
srv, err := service.DiscoverService(srvName, common.Conf{})
if err != nil {
return errors.Annotatef(err, "cannot find %q service", srvName)
}
if err := srv.Start(); err != nil {
return errors.Annotatef(err, "cannot start %q service", srvName)
}
// We dont want machine-0 to restart since the new one has a different tag.
// We started the new one above.
os.Exit(0)
}
// After restoring, the api server needs a forced restart, tomb will not work
// this is because we change all of juju configuration files and mongo too.
// Exiting with 0 would prevent upstart to respawn the process
// NOTE(fwereade): the apiserver needs to be restarted, yes, but
// this approach is completely broken. The only place it's ever
// ok to use os.Exit is in a main() func that's *so* simple as to
// be reasonably left untested.
//
// And passing os.Exit in wouldn't make this any better either,
// just using it subverts the expectations of *everything* else
// running in the process.
// XXX: We have ErrRestartAgent which should be capable of replacing this
os.Exit(1)
return nil
} | go | func (a *API) Restore(p params.RestoreArgs) error {
logger.Infof("Starting server side restore")
// Get hold of a backup file Reader
backup, closer := newBackups(a.backend)
defer closer.Close()
// Obtain the address of current machine, where we will be performing restore.
machine, err := a.backend.Machine(a.machineID)
if err != nil {
return errors.Trace(err)
}
addr, err := machine.PrivateAddress()
if err != nil {
return errors.Annotatef(err, "error fetching internal address for machine %q", machine)
}
publicAddress, err := machine.PublicAddress()
if err != nil {
return errors.Annotatef(err, "error fetching public address for machine %q", machine)
}
info := a.backend.RestoreInfo()
// Signal to current state and api server that restore will begin
err = info.SetStatus(state.RestoreInProgress)
if err != nil {
return errors.Annotatef(err, "cannot set the server to %q mode", state.RestoreInProgress)
}
// Any abnormal termination of this function will mark restore as failed,
// successful termination will call Exit and never run this.
defer info.SetStatus(state.RestoreFailed)
instanceId, err := machine.InstanceId()
if err != nil {
return errors.Annotate(err, "cannot obtain instance id for machine to be restored")
}
logger.Infof("beginning server side restore of backup %q", p.BackupId)
// Restore
restoreArgs := backups.RestoreArgs{
PrivateAddress: addr.Value,
PublicAddress: publicAddress.Value,
NewInstId: instanceId,
NewInstTag: machine.Tag(),
NewInstSeries: machine.Series(),
}
session := a.backend.MongoSession().Copy()
defer session.Close()
// Don't go if HA isn't ready.
err = waitUntilReady(session, 60)
if err != nil {
return errors.Annotatef(err, "HA not ready; try again later")
}
oldTagString, err := backup.Restore(p.BackupId, restoreArgs)
if err != nil {
return errors.Annotate(err, "restore failed")
}
// A backup can be made of any component of an ha array.
// The files in a backup don't contain purely relativized paths.
// If the backup is made of the bootstrap node (machine 0) the
// recently created machine will have the same paths and therefore
// the startup scripts will fit the new juju. If the backup belongs
// to a different machine, we need to create a new set of startup
// scripts and exit with 0 (so that the current script does not try
// to restart the old juju, which will no longer be there).
if oldTagString != nil && oldTagString != bootstrapNode {
srvName := fmt.Sprintf("jujud-%s", oldTagString)
srv, err := service.DiscoverService(srvName, common.Conf{})
if err != nil {
return errors.Annotatef(err, "cannot find %q service", srvName)
}
if err := srv.Start(); err != nil {
return errors.Annotatef(err, "cannot start %q service", srvName)
}
// We dont want machine-0 to restart since the new one has a different tag.
// We started the new one above.
os.Exit(0)
}
// After restoring, the api server needs a forced restart, tomb will not work
// this is because we change all of juju configuration files and mongo too.
// Exiting with 0 would prevent upstart to respawn the process
// NOTE(fwereade): the apiserver needs to be restarted, yes, but
// this approach is completely broken. The only place it's ever
// ok to use os.Exit is in a main() func that's *so* simple as to
// be reasonably left untested.
//
// And passing os.Exit in wouldn't make this any better either,
// just using it subverts the expectations of *everything* else
// running in the process.
// XXX: We have ErrRestartAgent which should be capable of replacing this
os.Exit(1)
return nil
} | [
"func",
"(",
"a",
"*",
"API",
")",
"Restore",
"(",
"p",
"params",
".",
"RestoreArgs",
")",
"error",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"// Get hold of a backup file Reader",
"backup",
",",
"closer",
":=",
"newBackups",
"(",
"a",
".",
"backend",
")",
"\n",
"defer",
"closer",
".",
"Close",
"(",
")",
"\n\n",
"// Obtain the address of current machine, where we will be performing restore.",
"machine",
",",
"err",
":=",
"a",
".",
"backend",
".",
"Machine",
"(",
"a",
".",
"machineID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"addr",
",",
"err",
":=",
"machine",
".",
"PrivateAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"machine",
")",
"\n",
"}",
"\n\n",
"publicAddress",
",",
"err",
":=",
"machine",
".",
"PublicAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"machine",
")",
"\n",
"}",
"\n\n",
"info",
":=",
"a",
".",
"backend",
".",
"RestoreInfo",
"(",
")",
"\n",
"// Signal to current state and api server that restore will begin",
"err",
"=",
"info",
".",
"SetStatus",
"(",
"state",
".",
"RestoreInProgress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"state",
".",
"RestoreInProgress",
")",
"\n",
"}",
"\n",
"// Any abnormal termination of this function will mark restore as failed,",
"// successful termination will call Exit and never run this.",
"defer",
"info",
".",
"SetStatus",
"(",
"state",
".",
"RestoreFailed",
")",
"\n\n",
"instanceId",
",",
"err",
":=",
"machine",
".",
"InstanceId",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"p",
".",
"BackupId",
")",
"\n",
"// Restore",
"restoreArgs",
":=",
"backups",
".",
"RestoreArgs",
"{",
"PrivateAddress",
":",
"addr",
".",
"Value",
",",
"PublicAddress",
":",
"publicAddress",
".",
"Value",
",",
"NewInstId",
":",
"instanceId",
",",
"NewInstTag",
":",
"machine",
".",
"Tag",
"(",
")",
",",
"NewInstSeries",
":",
"machine",
".",
"Series",
"(",
")",
",",
"}",
"\n\n",
"session",
":=",
"a",
".",
"backend",
".",
"MongoSession",
"(",
")",
".",
"Copy",
"(",
")",
"\n",
"defer",
"session",
".",
"Close",
"(",
")",
"\n\n",
"// Don't go if HA isn't ready.",
"err",
"=",
"waitUntilReady",
"(",
"session",
",",
"60",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"oldTagString",
",",
"err",
":=",
"backup",
".",
"Restore",
"(",
"p",
".",
"BackupId",
",",
"restoreArgs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// A backup can be made of any component of an ha array.",
"// The files in a backup don't contain purely relativized paths.",
"// If the backup is made of the bootstrap node (machine 0) the",
"// recently created machine will have the same paths and therefore",
"// the startup scripts will fit the new juju. If the backup belongs",
"// to a different machine, we need to create a new set of startup",
"// scripts and exit with 0 (so that the current script does not try",
"// to restart the old juju, which will no longer be there).",
"if",
"oldTagString",
"!=",
"nil",
"&&",
"oldTagString",
"!=",
"bootstrapNode",
"{",
"srvName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"oldTagString",
")",
"\n",
"srv",
",",
"err",
":=",
"service",
".",
"DiscoverService",
"(",
"srvName",
",",
"common",
".",
"Conf",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"srvName",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"srv",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"srvName",
")",
"\n",
"}",
"\n",
"// We dont want machine-0 to restart since the new one has a different tag.",
"// We started the new one above.",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n\n",
"// After restoring, the api server needs a forced restart, tomb will not work",
"// this is because we change all of juju configuration files and mongo too.",
"// Exiting with 0 would prevent upstart to respawn the process",
"// NOTE(fwereade): the apiserver needs to be restarted, yes, but",
"// this approach is completely broken. The only place it's ever",
"// ok to use os.Exit is in a main() func that's *so* simple as to",
"// be reasonably left untested.",
"//",
"// And passing os.Exit in wouldn't make this any better either,",
"// just using it subverts the expectations of *everything* else",
"// running in the process.",
"// XXX: We have ErrRestartAgent which should be capable of replacing this",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Restore implements the server side of Backups.Restore. | [
"Restore",
"implements",
"the",
"server",
"side",
"of",
"Backups",
".",
"Restore",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/restore.go#L23-L122 |
156,685 | juju/juju | apiserver/facades/client/backups/restore.go | PrepareRestore | func (a *API) PrepareRestore() error {
info := a.backend.RestoreInfo()
logger.Infof("entering restore preparation mode")
return info.SetStatus(state.RestorePending)
} | go | func (a *API) PrepareRestore() error {
info := a.backend.RestoreInfo()
logger.Infof("entering restore preparation mode")
return info.SetStatus(state.RestorePending)
} | [
"func",
"(",
"a",
"*",
"API",
")",
"PrepareRestore",
"(",
")",
"error",
"{",
"info",
":=",
"a",
".",
"backend",
".",
"RestoreInfo",
"(",
")",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"info",
".",
"SetStatus",
"(",
"state",
".",
"RestorePending",
")",
"\n",
"}"
] | // PrepareRestore implements the server side of Backups.PrepareRestore. | [
"PrepareRestore",
"implements",
"the",
"server",
"side",
"of",
"Backups",
".",
"PrepareRestore",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/restore.go#L125-L129 |
156,686 | juju/juju | apiserver/facades/client/backups/restore.go | FinishRestore | func (a *API) FinishRestore() error {
info := a.backend.RestoreInfo()
currentStatus, err := info.Status()
if err != nil {
return errors.Trace(err)
}
if currentStatus != state.RestoreFinished {
if err := info.SetStatus(state.RestoreFailed); err != nil {
return errors.Trace(err)
}
return errors.Errorf("Restore did not finish successfully")
}
logger.Infof("Successfully restored")
return info.SetStatus(state.RestoreChecked)
} | go | func (a *API) FinishRestore() error {
info := a.backend.RestoreInfo()
currentStatus, err := info.Status()
if err != nil {
return errors.Trace(err)
}
if currentStatus != state.RestoreFinished {
if err := info.SetStatus(state.RestoreFailed); err != nil {
return errors.Trace(err)
}
return errors.Errorf("Restore did not finish successfully")
}
logger.Infof("Successfully restored")
return info.SetStatus(state.RestoreChecked)
} | [
"func",
"(",
"a",
"*",
"API",
")",
"FinishRestore",
"(",
")",
"error",
"{",
"info",
":=",
"a",
".",
"backend",
".",
"RestoreInfo",
"(",
")",
"\n",
"currentStatus",
",",
"err",
":=",
"info",
".",
"Status",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"currentStatus",
"!=",
"state",
".",
"RestoreFinished",
"{",
"if",
"err",
":=",
"info",
".",
"SetStatus",
"(",
"state",
".",
"RestoreFailed",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"info",
".",
"SetStatus",
"(",
"state",
".",
"RestoreChecked",
")",
"\n",
"}"
] | // FinishRestore implements the server side of Backups.FinishRestore. | [
"FinishRestore",
"implements",
"the",
"server",
"side",
"of",
"Backups",
".",
"FinishRestore",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/backups/restore.go#L132-L146 |
156,687 | juju/juju | mongo/mongometrics/mgostatsmetrics.go | NewMgoStatsCollector | func NewMgoStatsCollector(getCurrentStats func() mgo.Stats) *MgoStatsCollector {
// We need to track previous statistics so we can
// compute the delta for counter metrics.
var mu sync.Mutex
var prevStats stats
getStats := func() (current, previous stats) {
mu.Lock()
defer mu.Unlock()
previous = prevStats
currentStats := getCurrentStats()
current = stats{
Clusters: currentStats.Clusters,
MasterConns: currentStats.MasterConns,
SlaveConns: currentStats.SlaveConns,
SentOps: currentStats.SentOps,
ReceivedOps: currentStats.ReceivedOps,
ReceivedDocs: currentStats.ReceivedDocs,
SocketsAlive: currentStats.SocketsAlive,
SocketsInUse: currentStats.SocketsInUse,
SocketRefs: currentStats.SocketRefs,
}
prevStats = current
return current, previous
}
return &MgoStatsCollector{
getStats: getStats,
clustersGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "clusters",
Help: "Current number of clusters",
}),
masterConnsGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "master_conns",
Help: "Current number of master conns",
}),
slaveConnsGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "slave_conns",
Help: "Current number of slave conns",
}),
sentOpsCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "mgo",
Name: "sent_ops_total",
Help: "Total number of sent ops",
}),
receivedOpsCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "mgo",
Name: "received_ops_total",
Help: "Total number of received ops",
}),
receivedDocsCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "mgo",
Name: "received_docs_total",
Help: "Total number of received docs",
}),
socketsAliveGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "sockets_alive",
Help: "Current number of sockets alive",
}),
socketsInuseGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "sockets_inuse",
Help: "Current number of sockets in use",
}),
socketRefsGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "socket_refs",
Help: "Current number of sockets referenced",
}),
}
} | go | func NewMgoStatsCollector(getCurrentStats func() mgo.Stats) *MgoStatsCollector {
// We need to track previous statistics so we can
// compute the delta for counter metrics.
var mu sync.Mutex
var prevStats stats
getStats := func() (current, previous stats) {
mu.Lock()
defer mu.Unlock()
previous = prevStats
currentStats := getCurrentStats()
current = stats{
Clusters: currentStats.Clusters,
MasterConns: currentStats.MasterConns,
SlaveConns: currentStats.SlaveConns,
SentOps: currentStats.SentOps,
ReceivedOps: currentStats.ReceivedOps,
ReceivedDocs: currentStats.ReceivedDocs,
SocketsAlive: currentStats.SocketsAlive,
SocketsInUse: currentStats.SocketsInUse,
SocketRefs: currentStats.SocketRefs,
}
prevStats = current
return current, previous
}
return &MgoStatsCollector{
getStats: getStats,
clustersGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "clusters",
Help: "Current number of clusters",
}),
masterConnsGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "master_conns",
Help: "Current number of master conns",
}),
slaveConnsGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "slave_conns",
Help: "Current number of slave conns",
}),
sentOpsCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "mgo",
Name: "sent_ops_total",
Help: "Total number of sent ops",
}),
receivedOpsCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "mgo",
Name: "received_ops_total",
Help: "Total number of received ops",
}),
receivedDocsCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "mgo",
Name: "received_docs_total",
Help: "Total number of received docs",
}),
socketsAliveGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "sockets_alive",
Help: "Current number of sockets alive",
}),
socketsInuseGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "sockets_inuse",
Help: "Current number of sockets in use",
}),
socketRefsGauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mgo",
Name: "socket_refs",
Help: "Current number of sockets referenced",
}),
}
} | [
"func",
"NewMgoStatsCollector",
"(",
"getCurrentStats",
"func",
"(",
")",
"mgo",
".",
"Stats",
")",
"*",
"MgoStatsCollector",
"{",
"// We need to track previous statistics so we can",
"// compute the delta for counter metrics.",
"var",
"mu",
"sync",
".",
"Mutex",
"\n",
"var",
"prevStats",
"stats",
"\n",
"getStats",
":=",
"func",
"(",
")",
"(",
"current",
",",
"previous",
"stats",
")",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"previous",
"=",
"prevStats",
"\n",
"currentStats",
":=",
"getCurrentStats",
"(",
")",
"\n",
"current",
"=",
"stats",
"{",
"Clusters",
":",
"currentStats",
".",
"Clusters",
",",
"MasterConns",
":",
"currentStats",
".",
"MasterConns",
",",
"SlaveConns",
":",
"currentStats",
".",
"SlaveConns",
",",
"SentOps",
":",
"currentStats",
".",
"SentOps",
",",
"ReceivedOps",
":",
"currentStats",
".",
"ReceivedOps",
",",
"ReceivedDocs",
":",
"currentStats",
".",
"ReceivedDocs",
",",
"SocketsAlive",
":",
"currentStats",
".",
"SocketsAlive",
",",
"SocketsInUse",
":",
"currentStats",
".",
"SocketsInUse",
",",
"SocketRefs",
":",
"currentStats",
".",
"SocketRefs",
",",
"}",
"\n",
"prevStats",
"=",
"current",
"\n",
"return",
"current",
",",
"previous",
"\n",
"}",
"\n\n",
"return",
"&",
"MgoStatsCollector",
"{",
"getStats",
":",
"getStats",
",",
"clustersGauge",
":",
"prometheus",
".",
"NewGauge",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"masterConnsGauge",
":",
"prometheus",
".",
"NewGauge",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"slaveConnsGauge",
":",
"prometheus",
".",
"NewGauge",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"sentOpsCounter",
":",
"prometheus",
".",
"NewCounter",
"(",
"prometheus",
".",
"CounterOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"receivedOpsCounter",
":",
"prometheus",
".",
"NewCounter",
"(",
"prometheus",
".",
"CounterOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"receivedDocsCounter",
":",
"prometheus",
".",
"NewCounter",
"(",
"prometheus",
".",
"CounterOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"socketsAliveGauge",
":",
"prometheus",
".",
"NewGauge",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"socketsInuseGauge",
":",
"prometheus",
".",
"NewGauge",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"socketRefsGauge",
":",
"prometheus",
".",
"NewGauge",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Namespace",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
")",
",",
"}",
"\n",
"}"
] | // NewMgoStatsCollector returns a new MgoStatsCollector. | [
"NewMgoStatsCollector",
"returns",
"a",
"new",
"MgoStatsCollector",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongometrics/mgostatsmetrics.go#L42-L116 |
156,688 | juju/juju | apiserver/facades/controller/applicationscaler/shim.go | RescaleService | func (shim backendShim) RescaleService(name string) error {
service, err := shim.st.Application(name)
if err != nil {
return errors.Trace(err)
}
return service.EnsureMinUnits()
} | go | func (shim backendShim) RescaleService(name string) error {
service, err := shim.st.Application(name)
if err != nil {
return errors.Trace(err)
}
return service.EnsureMinUnits()
} | [
"func",
"(",
"shim",
"backendShim",
")",
"RescaleService",
"(",
"name",
"string",
")",
"error",
"{",
"service",
",",
"err",
":=",
"shim",
".",
"st",
".",
"Application",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"service",
".",
"EnsureMinUnits",
"(",
")",
"\n",
"}"
] | // RescaleService is part of the Backend interface. | [
"RescaleService",
"is",
"part",
"of",
"the",
"Backend",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/applicationscaler/shim.go#L40-L46 |
156,689 | juju/juju | worker/raft/raftforwarder/worker.go | Validate | func (config Config) Validate() error {
if config.Hub == nil {
return errors.NotValidf("nil Hub")
}
if config.Raft == nil {
return errors.NotValidf("nil Raft")
}
if config.Logger == nil {
return errors.NotValidf("nil Logger")
}
if config.Topic == "" {
return errors.NotValidf("empty Topic")
}
if config.Target == nil {
return errors.NotValidf("nil Target")
}
return nil
} | go | func (config Config) Validate() error {
if config.Hub == nil {
return errors.NotValidf("nil Hub")
}
if config.Raft == nil {
return errors.NotValidf("nil Raft")
}
if config.Logger == nil {
return errors.NotValidf("nil Logger")
}
if config.Topic == "" {
return errors.NotValidf("empty Topic")
}
if config.Target == nil {
return errors.NotValidf("nil Target")
}
return nil
} | [
"func",
"(",
"config",
"Config",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"config",
".",
"Hub",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Raft",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Logger",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Topic",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Target",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks that this config can be used. | [
"Validate",
"checks",
"that",
"this",
"config",
"can",
"be",
"used",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/raftforwarder/worker.go#L45-L62 |
156,690 | juju/juju | worker/raft/raftforwarder/worker.go | NewWorker | func NewWorker(config Config) (worker.Worker, error) {
if err := config.Validate(); err != nil {
return nil, errors.Trace(err)
}
w := &forwarder{
config: config,
}
unsubscribe, err := w.config.Hub.Subscribe(w.config.Topic, w.handleRequest)
if err != nil {
return nil, errors.Annotatef(err, "subscribing to %q", w.config.Topic)
}
w.unsubscribe = unsubscribe
if err := catacomb.Invoke(catacomb.Plan{
Site: &w.catacomb,
Work: w.loop,
}); err != nil {
unsubscribe()
return nil, errors.Trace(err)
}
return w, nil
} | go | func NewWorker(config Config) (worker.Worker, error) {
if err := config.Validate(); err != nil {
return nil, errors.Trace(err)
}
w := &forwarder{
config: config,
}
unsubscribe, err := w.config.Hub.Subscribe(w.config.Topic, w.handleRequest)
if err != nil {
return nil, errors.Annotatef(err, "subscribing to %q", w.config.Topic)
}
w.unsubscribe = unsubscribe
if err := catacomb.Invoke(catacomb.Plan{
Site: &w.catacomb,
Work: w.loop,
}); err != nil {
unsubscribe()
return nil, errors.Trace(err)
}
return w, nil
} | [
"func",
"NewWorker",
"(",
"config",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"w",
":=",
"&",
"forwarder",
"{",
"config",
":",
"config",
",",
"}",
"\n",
"unsubscribe",
",",
"err",
":=",
"w",
".",
"config",
".",
"Hub",
".",
"Subscribe",
"(",
"w",
".",
"config",
".",
"Topic",
",",
"w",
".",
"handleRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"w",
".",
"config",
".",
"Topic",
")",
"\n",
"}",
"\n",
"w",
".",
"unsubscribe",
"=",
"unsubscribe",
"\n",
"if",
"err",
":=",
"catacomb",
".",
"Invoke",
"(",
"catacomb",
".",
"Plan",
"{",
"Site",
":",
"&",
"w",
".",
"catacomb",
",",
"Work",
":",
"w",
".",
"loop",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"unsubscribe",
"(",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // NewWorker creates and starts a worker that will forward leadership
// claims from non-raft-leader machines. | [
"NewWorker",
"creates",
"and",
"starts",
"a",
"worker",
"that",
"will",
"forward",
"leadership",
"claims",
"from",
"non",
"-",
"raft",
"-",
"leader",
"machines",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/raftforwarder/worker.go#L66-L86 |
156,691 | juju/juju | cloudconfig/cloudinit/cloudinit_ubuntu.go | AddPackageSource | func (cfg *ubuntuCloudConfig) AddPackageSource(src packaging.PackageSource) {
cfg.attrs["apt_sources"] = append(cfg.PackageSources(), src)
} | go | func (cfg *ubuntuCloudConfig) AddPackageSource(src packaging.PackageSource) {
cfg.attrs["apt_sources"] = append(cfg.PackageSources(), src)
} | [
"func",
"(",
"cfg",
"*",
"ubuntuCloudConfig",
")",
"AddPackageSource",
"(",
"src",
"packaging",
".",
"PackageSource",
")",
"{",
"cfg",
".",
"attrs",
"[",
"\"",
"\"",
"]",
"=",
"append",
"(",
"cfg",
".",
"PackageSources",
"(",
")",
",",
"src",
")",
"\n",
"}"
] | // AddPackageSource is defined on the PackageSourcesConfig interface. | [
"AddPackageSource",
"is",
"defined",
"on",
"the",
"PackageSourcesConfig",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit_ubuntu.go#L60-L62 |
156,692 | juju/juju | cloudconfig/cloudinit/cloudinit_ubuntu.go | AddPackagePreferences | func (cfg *ubuntuCloudConfig) AddPackagePreferences(prefs packaging.PackagePreferences) {
cfg.attrs["apt_preferences"] = append(cfg.PackagePreferences(), prefs)
} | go | func (cfg *ubuntuCloudConfig) AddPackagePreferences(prefs packaging.PackagePreferences) {
cfg.attrs["apt_preferences"] = append(cfg.PackagePreferences(), prefs)
} | [
"func",
"(",
"cfg",
"*",
"ubuntuCloudConfig",
")",
"AddPackagePreferences",
"(",
"prefs",
"packaging",
".",
"PackagePreferences",
")",
"{",
"cfg",
".",
"attrs",
"[",
"\"",
"\"",
"]",
"=",
"append",
"(",
"cfg",
".",
"PackagePreferences",
"(",
")",
",",
"prefs",
")",
"\n",
"}"
] | // AddPackagePreferences is defined on the PackageSourcesConfig interface. | [
"AddPackagePreferences",
"is",
"defined",
"on",
"the",
"PackageSourcesConfig",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit_ubuntu.go#L71-L73 |
156,693 | juju/juju | cloudconfig/cloudinit/cloudinit_ubuntu.go | PackagePreferences | func (cfg *ubuntuCloudConfig) PackagePreferences() []packaging.PackagePreferences {
prefs, _ := cfg.attrs["apt_preferences"].([]packaging.PackagePreferences)
return prefs
} | go | func (cfg *ubuntuCloudConfig) PackagePreferences() []packaging.PackagePreferences {
prefs, _ := cfg.attrs["apt_preferences"].([]packaging.PackagePreferences)
return prefs
} | [
"func",
"(",
"cfg",
"*",
"ubuntuCloudConfig",
")",
"PackagePreferences",
"(",
")",
"[",
"]",
"packaging",
".",
"PackagePreferences",
"{",
"prefs",
",",
"_",
":=",
"cfg",
".",
"attrs",
"[",
"\"",
"\"",
"]",
".",
"(",
"[",
"]",
"packaging",
".",
"PackagePreferences",
")",
"\n",
"return",
"prefs",
"\n",
"}"
] | // PackagePreferences is defined on the PackageSourcesConfig interface. | [
"PackagePreferences",
"is",
"defined",
"on",
"the",
"PackageSourcesConfig",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit_ubuntu.go#L76-L79 |
156,694 | juju/juju | cloudconfig/cloudinit/cloudinit_ubuntu.go | AddCloudArchiveCloudTools | func (cfg *ubuntuCloudConfig) AddCloudArchiveCloudTools() {
src, pref := config.GetCloudArchiveSource(cfg.series)
cfg.AddPackageSource(src)
cfg.AddPackagePreferences(pref)
} | go | func (cfg *ubuntuCloudConfig) AddCloudArchiveCloudTools() {
src, pref := config.GetCloudArchiveSource(cfg.series)
cfg.AddPackageSource(src)
cfg.AddPackagePreferences(pref)
} | [
"func",
"(",
"cfg",
"*",
"ubuntuCloudConfig",
")",
"AddCloudArchiveCloudTools",
"(",
")",
"{",
"src",
",",
"pref",
":=",
"config",
".",
"GetCloudArchiveSource",
"(",
"cfg",
".",
"series",
")",
"\n",
"cfg",
".",
"AddPackageSource",
"(",
"src",
")",
"\n",
"cfg",
".",
"AddPackagePreferences",
"(",
"pref",
")",
"\n",
"}"
] | // AddCloudArchiveCloudTools is defined on the AdvancedPackagingConfig
// interface. | [
"AddCloudArchiveCloudTools",
"is",
"defined",
"on",
"the",
"AdvancedPackagingConfig",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit_ubuntu.go#L137-L141 |
156,695 | juju/juju | cloudconfig/cloudinit/cloudinit_ubuntu.go | renameAptListFilesCommands | func renameAptListFilesCommands(newMirror, oldMirror string) []string {
oldPrefix := "old_prefix=" + config.AptListsDirectory + "/$(echo " + oldMirror + " | " + config.AptSourceListPrefix + ")"
newPrefix := "new_prefix=" + config.AptListsDirectory + "/$(echo " + newMirror + " | " + config.AptSourceListPrefix + ")"
renameFiles := `
for old in ${old_prefix}_*; do
new=$(echo $old | sed s,^$old_prefix,$new_prefix,)
mv $old $new
done`
return []string{
oldPrefix,
newPrefix,
// Don't do anything unless the mirror/source has changed.
`[ "$old_prefix" != "$new_prefix" ] &&` + renameFiles,
}
} | go | func renameAptListFilesCommands(newMirror, oldMirror string) []string {
oldPrefix := "old_prefix=" + config.AptListsDirectory + "/$(echo " + oldMirror + " | " + config.AptSourceListPrefix + ")"
newPrefix := "new_prefix=" + config.AptListsDirectory + "/$(echo " + newMirror + " | " + config.AptSourceListPrefix + ")"
renameFiles := `
for old in ${old_prefix}_*; do
new=$(echo $old | sed s,^$old_prefix,$new_prefix,)
mv $old $new
done`
return []string{
oldPrefix,
newPrefix,
// Don't do anything unless the mirror/source has changed.
`[ "$old_prefix" != "$new_prefix" ] &&` + renameFiles,
}
} | [
"func",
"renameAptListFilesCommands",
"(",
"newMirror",
",",
"oldMirror",
"string",
")",
"[",
"]",
"string",
"{",
"oldPrefix",
":=",
"\"",
"\"",
"+",
"config",
".",
"AptListsDirectory",
"+",
"\"",
"\"",
"+",
"oldMirror",
"+",
"\"",
"\"",
"+",
"config",
".",
"AptSourceListPrefix",
"+",
"\"",
"\"",
"\n",
"newPrefix",
":=",
"\"",
"\"",
"+",
"config",
".",
"AptListsDirectory",
"+",
"\"",
"\"",
"+",
"newMirror",
"+",
"\"",
"\"",
"+",
"config",
".",
"AptSourceListPrefix",
"+",
"\"",
"\"",
"\n",
"renameFiles",
":=",
"`\nfor old in ${old_prefix}_*; do\n new=$(echo $old | sed s,^$old_prefix,$new_prefix,)\n mv $old $new\ndone`",
"\n\n",
"return",
"[",
"]",
"string",
"{",
"oldPrefix",
",",
"newPrefix",
",",
"// Don't do anything unless the mirror/source has changed.",
"`[ \"$old_prefix\" != \"$new_prefix\" ] &&`",
"+",
"renameFiles",
",",
"}",
"\n",
"}"
] | // renameAptListFilesCommands takes a new and old mirror string,
// and returns a sequence of commands that will rename the files
// in aptListsDirectory. | [
"renameAptListFilesCommands",
"takes",
"a",
"new",
"and",
"old",
"mirror",
"string",
"and",
"returns",
"a",
"sequence",
"of",
"commands",
"that",
"will",
"rename",
"the",
"files",
"in",
"aptListsDirectory",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit_ubuntu.go#L246-L261 |
156,696 | juju/juju | cloudconfig/cloudinit/cloudinit_ubuntu.go | updateProxySettings | func (cfg *ubuntuCloudConfig) updateProxySettings(proxySettings proxy.Settings) {
// Write out the apt proxy settings
if (proxySettings != proxy.Settings{}) {
filename := config.AptProxyConfigFile
cfg.AddBootCmd(fmt.Sprintf(
`printf '%%s\n' %s > %s`,
utils.ShQuote(cfg.paccmder.ProxyConfigContents(proxySettings)),
filename))
}
} | go | func (cfg *ubuntuCloudConfig) updateProxySettings(proxySettings proxy.Settings) {
// Write out the apt proxy settings
if (proxySettings != proxy.Settings{}) {
filename := config.AptProxyConfigFile
cfg.AddBootCmd(fmt.Sprintf(
`printf '%%s\n' %s > %s`,
utils.ShQuote(cfg.paccmder.ProxyConfigContents(proxySettings)),
filename))
}
} | [
"func",
"(",
"cfg",
"*",
"ubuntuCloudConfig",
")",
"updateProxySettings",
"(",
"proxySettings",
"proxy",
".",
"Settings",
")",
"{",
"// Write out the apt proxy settings",
"if",
"(",
"proxySettings",
"!=",
"proxy",
".",
"Settings",
"{",
"}",
")",
"{",
"filename",
":=",
"config",
".",
"AptProxyConfigFile",
"\n",
"cfg",
".",
"AddBootCmd",
"(",
"fmt",
".",
"Sprintf",
"(",
"`printf '%%s\\n' %s > %s`",
",",
"utils",
".",
"ShQuote",
"(",
"cfg",
".",
"paccmder",
".",
"ProxyConfigContents",
"(",
"proxySettings",
")",
")",
",",
"filename",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Updates proxy settings used when rendering the conf as a script | [
"Updates",
"proxy",
"settings",
"used",
"when",
"rendering",
"the",
"conf",
"as",
"a",
"script"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit_ubuntu.go#L303-L312 |
156,697 | juju/juju | cmd/juju/commands/upgrademodel.go | Run | func (c *upgradeJujuCommand) Run(ctx *cmd.Context) (err error) {
modelType, err := c.ModelType()
if err != nil {
return errors.Trace(err)
}
if modelType == model.CAAS {
return c.upgradeCAASModel(ctx)
}
return c.upgradeIAASModel(ctx)
} | go | func (c *upgradeJujuCommand) Run(ctx *cmd.Context) (err error) {
modelType, err := c.ModelType()
if err != nil {
return errors.Trace(err)
}
if modelType == model.CAAS {
return c.upgradeCAASModel(ctx)
}
return c.upgradeIAASModel(ctx)
} | [
"func",
"(",
"c",
"*",
"upgradeJujuCommand",
")",
"Run",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"modelType",
",",
"err",
":=",
"c",
".",
"ModelType",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"modelType",
"==",
"model",
".",
"CAAS",
"{",
"return",
"c",
".",
"upgradeCAASModel",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"upgradeIAASModel",
"(",
"ctx",
")",
"\n",
"}"
] | // Run changes the version proposed for the juju envtools. | [
"Run",
"changes",
"the",
"version",
"proposed",
"for",
"the",
"juju",
"envtools",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/upgrademodel.go#L359-L368 |
156,698 | juju/juju | cmd/juju/commands/upgrademodel.go | initVersions | func (c *upgradeJujuCommand) initVersions(
client toolsAPI, cfg *config.Config, agentVersion version.Number, filterOnPrior bool,
) (*upgradeContext, bool, error) {
if c.Version == agentVersion {
return nil, false, errUpToDate
}
filterVersion := jujuversion.Current
if c.Version != version.Zero {
filterVersion = c.Version
} else if filterOnPrior {
// Trying to find the latest of the prior major version.
// TODO (cherylj) if no tools found, suggest upgrade to
// the current client version.
filterVersion.Major--
}
tryImplicitUpload, err := tryImplicitUpload(agentVersion)
if err != nil {
return nil, false, err
}
logger.Debugf("searching for agent binaries with major: %d", filterVersion.Major)
findResult, err := client.FindTools(filterVersion.Major, -1, "", "", c.AgentStream)
if err != nil {
return nil, false, err
}
err = findResult.Error
if findResult.Error != nil {
if !params.IsCodeNotFound(err) {
return nil, false, err
}
if !tryImplicitUpload && !c.BuildAgent {
// No tools found and we shouldn't upload any, so if we are not asking for a
// major upgrade, pretend there is no more recent version available.
if c.Version == version.Zero && agentVersion.Major == filterVersion.Major {
return nil, false, errUpToDate
}
return nil, tryImplicitUpload, err
}
}
agents := make(coretools.Versions, len(findResult.List))
for i, t := range findResult.List {
agents[i] = t
}
return &upgradeContext{
agent: agentVersion,
client: jujuversion.Current,
chosen: c.Version,
packagedAgents: agents,
config: cfg,
}, tryImplicitUpload, nil
} | go | func (c *upgradeJujuCommand) initVersions(
client toolsAPI, cfg *config.Config, agentVersion version.Number, filterOnPrior bool,
) (*upgradeContext, bool, error) {
if c.Version == agentVersion {
return nil, false, errUpToDate
}
filterVersion := jujuversion.Current
if c.Version != version.Zero {
filterVersion = c.Version
} else if filterOnPrior {
// Trying to find the latest of the prior major version.
// TODO (cherylj) if no tools found, suggest upgrade to
// the current client version.
filterVersion.Major--
}
tryImplicitUpload, err := tryImplicitUpload(agentVersion)
if err != nil {
return nil, false, err
}
logger.Debugf("searching for agent binaries with major: %d", filterVersion.Major)
findResult, err := client.FindTools(filterVersion.Major, -1, "", "", c.AgentStream)
if err != nil {
return nil, false, err
}
err = findResult.Error
if findResult.Error != nil {
if !params.IsCodeNotFound(err) {
return nil, false, err
}
if !tryImplicitUpload && !c.BuildAgent {
// No tools found and we shouldn't upload any, so if we are not asking for a
// major upgrade, pretend there is no more recent version available.
if c.Version == version.Zero && agentVersion.Major == filterVersion.Major {
return nil, false, errUpToDate
}
return nil, tryImplicitUpload, err
}
}
agents := make(coretools.Versions, len(findResult.List))
for i, t := range findResult.List {
agents[i] = t
}
return &upgradeContext{
agent: agentVersion,
client: jujuversion.Current,
chosen: c.Version,
packagedAgents: agents,
config: cfg,
}, tryImplicitUpload, nil
} | [
"func",
"(",
"c",
"*",
"upgradeJujuCommand",
")",
"initVersions",
"(",
"client",
"toolsAPI",
",",
"cfg",
"*",
"config",
".",
"Config",
",",
"agentVersion",
"version",
".",
"Number",
",",
"filterOnPrior",
"bool",
",",
")",
"(",
"*",
"upgradeContext",
",",
"bool",
",",
"error",
")",
"{",
"if",
"c",
".",
"Version",
"==",
"agentVersion",
"{",
"return",
"nil",
",",
"false",
",",
"errUpToDate",
"\n",
"}",
"\n",
"filterVersion",
":=",
"jujuversion",
".",
"Current",
"\n",
"if",
"c",
".",
"Version",
"!=",
"version",
".",
"Zero",
"{",
"filterVersion",
"=",
"c",
".",
"Version",
"\n",
"}",
"else",
"if",
"filterOnPrior",
"{",
"// Trying to find the latest of the prior major version.",
"// TODO (cherylj) if no tools found, suggest upgrade to",
"// the current client version.",
"filterVersion",
".",
"Major",
"--",
"\n",
"}",
"\n",
"tryImplicitUpload",
",",
"err",
":=",
"tryImplicitUpload",
"(",
"agentVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"filterVersion",
".",
"Major",
")",
"\n",
"findResult",
",",
"err",
":=",
"client",
".",
"FindTools",
"(",
"filterVersion",
".",
"Major",
",",
"-",
"1",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"c",
".",
"AgentStream",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"findResult",
".",
"Error",
"\n",
"if",
"findResult",
".",
"Error",
"!=",
"nil",
"{",
"if",
"!",
"params",
".",
"IsCodeNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"tryImplicitUpload",
"&&",
"!",
"c",
".",
"BuildAgent",
"{",
"// No tools found and we shouldn't upload any, so if we are not asking for a",
"// major upgrade, pretend there is no more recent version available.",
"if",
"c",
".",
"Version",
"==",
"version",
".",
"Zero",
"&&",
"agentVersion",
".",
"Major",
"==",
"filterVersion",
".",
"Major",
"{",
"return",
"nil",
",",
"false",
",",
"errUpToDate",
"\n",
"}",
"\n",
"return",
"nil",
",",
"tryImplicitUpload",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"agents",
":=",
"make",
"(",
"coretools",
".",
"Versions",
",",
"len",
"(",
"findResult",
".",
"List",
")",
")",
"\n",
"for",
"i",
",",
"t",
":=",
"range",
"findResult",
".",
"List",
"{",
"agents",
"[",
"i",
"]",
"=",
"t",
"\n",
"}",
"\n",
"return",
"&",
"upgradeContext",
"{",
"agent",
":",
"agentVersion",
",",
"client",
":",
"jujuversion",
".",
"Current",
",",
"chosen",
":",
"c",
".",
"Version",
",",
"packagedAgents",
":",
"agents",
",",
"config",
":",
"cfg",
",",
"}",
",",
"tryImplicitUpload",
",",
"nil",
"\n",
"}"
] | // initVersions collects state relevant to an upgrade decision. The returned
// agent and client versions, and the list of currently available tools, will
// always be accurate; the chosen version, and the flag indicating development
// mode, may remain blank until uploadTools or validate is called. | [
"initVersions",
"collects",
"state",
"relevant",
"to",
"an",
"upgrade",
"decision",
".",
"The",
"returned",
"agent",
"and",
"client",
"versions",
"and",
"the",
"list",
"of",
"currently",
"available",
"tools",
"will",
"always",
"be",
"accurate",
";",
"the",
"chosen",
"version",
"and",
"the",
"flag",
"indicating",
"development",
"mode",
"may",
"remain",
"blank",
"until",
"uploadTools",
"or",
"validate",
"is",
"called",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/upgrademodel.go#L628-L677 |
156,699 | juju/juju | cmd/juju/commands/upgrademodel.go | validate | func (context *upgradeContext) validate() (err error) {
if context.chosen == context.agent {
return errUpToDate
}
// Disallow major.minor version downgrades.
if context.chosen.Major < context.agent.Major ||
context.chosen.Major == context.agent.Major && context.chosen.Minor < context.agent.Minor {
// TODO(fwereade): I'm a bit concerned about old agent/CLI tools even
// *connecting* to environments with higher agent-versions; but ofc they
// have to connect in order to discover they shouldn't. However, once
// any of our tools detect an incompatible version, they should act to
// minimize damage: the CLI should abort politely, and the agents should
// run an Upgrader but no other tasks.
return errors.Errorf(downgradeErrMsg, context.agent, context.chosen)
}
return nil
} | go | func (context *upgradeContext) validate() (err error) {
if context.chosen == context.agent {
return errUpToDate
}
// Disallow major.minor version downgrades.
if context.chosen.Major < context.agent.Major ||
context.chosen.Major == context.agent.Major && context.chosen.Minor < context.agent.Minor {
// TODO(fwereade): I'm a bit concerned about old agent/CLI tools even
// *connecting* to environments with higher agent-versions; but ofc they
// have to connect in order to discover they shouldn't. However, once
// any of our tools detect an incompatible version, they should act to
// minimize damage: the CLI should abort politely, and the agents should
// run an Upgrader but no other tasks.
return errors.Errorf(downgradeErrMsg, context.agent, context.chosen)
}
return nil
} | [
"func",
"(",
"context",
"*",
"upgradeContext",
")",
"validate",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"context",
".",
"chosen",
"==",
"context",
".",
"agent",
"{",
"return",
"errUpToDate",
"\n",
"}",
"\n\n",
"// Disallow major.minor version downgrades.",
"if",
"context",
".",
"chosen",
".",
"Major",
"<",
"context",
".",
"agent",
".",
"Major",
"||",
"context",
".",
"chosen",
".",
"Major",
"==",
"context",
".",
"agent",
".",
"Major",
"&&",
"context",
".",
"chosen",
".",
"Minor",
"<",
"context",
".",
"agent",
".",
"Minor",
"{",
"// TODO(fwereade): I'm a bit concerned about old agent/CLI tools even",
"// *connecting* to environments with higher agent-versions; but ofc they",
"// have to connect in order to discover they shouldn't. However, once",
"// any of our tools detect an incompatible version, they should act to",
"// minimize damage: the CLI should abort politely, and the agents should",
"// run an Upgrader but no other tasks.",
"return",
"errors",
".",
"Errorf",
"(",
"downgradeErrMsg",
",",
"context",
".",
"agent",
",",
"context",
".",
"chosen",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // validate ensures an upgrade can be done using the chosen agent version.
// If validate returns no error, the environment agent-version can be set to
// the value of the chosen agent field. | [
"validate",
"ensures",
"an",
"upgrade",
"can",
"be",
"done",
"using",
"the",
"chosen",
"agent",
"version",
".",
"If",
"validate",
"returns",
"no",
"error",
"the",
"environment",
"agent",
"-",
"version",
"can",
"be",
"set",
"to",
"the",
"value",
"of",
"the",
"chosen",
"agent",
"field",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/upgrademodel.go#L814-L832 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.