repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
vishvananda/netlink | link.go | StringToBondMode | func StringToBondMode(s string) BondMode {
mode, ok := StringToBondModeMap[s]
if !ok {
return BOND_MODE_UNKNOWN
}
return mode
} | go | func StringToBondMode(s string) BondMode {
mode, ok := StringToBondModeMap[s]
if !ok {
return BOND_MODE_UNKNOWN
}
return mode
} | [
"func",
"StringToBondMode",
"(",
"s",
"string",
")",
"BondMode",
"{",
"mode",
",",
"ok",
":=",
"StringToBondModeMap",
"[",
"s",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BOND_MODE_UNKNOWN",
"\n",
"}",
"\n",
"return",
"mode",
"\n",
"}"
] | // StringToBondMode returns bond mode, or uknonw is the s is invalid. | [
"StringToBondMode",
"returns",
"bond",
"mode",
"or",
"uknonw",
"is",
"the",
"s",
"is",
"invalid",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L420-L426 | train |
vishvananda/netlink | link.go | StringToBondXmitHashPolicy | func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
lacp, ok := StringToBondXmitHashPolicyMap[s]
if !ok {
return BOND_XMIT_HASH_POLICY_UNKNOWN
}
return lacp
} | go | func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
lacp, ok := StringToBondXmitHashPolicyMap[s]
if !ok {
return BOND_XMIT_HASH_POLICY_UNKNOWN
}
return lacp
} | [
"func",
"StringToBondXmitHashPolicy",
"(",
"s",
"string",
")",
"BondXmitHashPolicy",
"{",
"lacp",
",",
"ok",
":=",
"StringToBondXmitHashPolicyMap",
"[",
"s",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BOND_XMIT_HASH_POLICY_UNKNOWN",
"\n",
"}",
"\n",
"return",
"lacp",
"\n",
"}"
] | // StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid. | [
"StringToBondXmitHashPolicy",
"returns",
"bond",
"lacp",
"arte",
"or",
"uknonw",
"is",
"the",
"s",
"is",
"invalid",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L511-L517 | train |
vishvananda/netlink | link.go | StringToBondLacpRate | func StringToBondLacpRate(s string) BondLacpRate {
lacp, ok := StringToBondLacpRateMap[s]
if !ok {
return BOND_LACP_RATE_UNKNOWN
}
return lacp
} | go | func StringToBondLacpRate(s string) BondLacpRate {
lacp, ok := StringToBondLacpRateMap[s]
if !ok {
return BOND_LACP_RATE_UNKNOWN
}
return lacp
} | [
"func",
"StringToBondLacpRate",
"(",
"s",
"string",
")",
"BondLacpRate",
"{",
"lacp",
",",
"ok",
":=",
"StringToBondLacpRateMap",
"[",
"s",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BOND_LACP_RATE_UNKNOWN",
"\n",
"}",
"\n",
"return",
"lacp",
"\n",
"}"
] | // StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid. | [
"StringToBondLacpRate",
"returns",
"bond",
"lacp",
"arte",
"or",
"uknonw",
"is",
"the",
"s",
"is",
"invalid",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L556-L562 | train |
vishvananda/netlink | devlink_linux.go | DevLinkGetDeviceList | func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error) {
f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME)
if err != nil {
return nil, err
}
msg := &nl.Genlmsg{
Command: nl.DEVLINK_CMD_GET,
Version: nl.GENL_DEVLINK_VERSION,
}
req := h.newNetlinkRequest(int(f.ID),
unix.NLM_F_REQUEST|unix.NLM_F_ACK|unix.NLM_F_DUMP)
req.AddData(msg)
msgs, err := req.Execute(unix.NETLINK_GENERIC, 0)
if err != nil {
return nil, err
}
devices, err := parseDevLinkDeviceList(msgs)
if err != nil {
return nil, err
}
for _, d := range devices {
h.getEswitchAttrs(f, d)
}
return devices, nil
} | go | func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error) {
f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME)
if err != nil {
return nil, err
}
msg := &nl.Genlmsg{
Command: nl.DEVLINK_CMD_GET,
Version: nl.GENL_DEVLINK_VERSION,
}
req := h.newNetlinkRequest(int(f.ID),
unix.NLM_F_REQUEST|unix.NLM_F_ACK|unix.NLM_F_DUMP)
req.AddData(msg)
msgs, err := req.Execute(unix.NETLINK_GENERIC, 0)
if err != nil {
return nil, err
}
devices, err := parseDevLinkDeviceList(msgs)
if err != nil {
return nil, err
}
for _, d := range devices {
h.getEswitchAttrs(f, d)
}
return devices, nil
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"DevLinkGetDeviceList",
"(",
")",
"(",
"[",
"]",
"*",
"DevlinkDevice",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"h",
".",
"GenlFamilyGet",
"(",
"nl",
".",
"GENL_DEVLINK_NAME",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"msg",
":=",
"&",
"nl",
".",
"Genlmsg",
"{",
"Command",
":",
"nl",
".",
"DEVLINK_CMD_GET",
",",
"Version",
":",
"nl",
".",
"GENL_DEVLINK_VERSION",
",",
"}",
"\n",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"int",
"(",
"f",
".",
"ID",
")",
",",
"unix",
".",
"NLM_F_REQUEST",
"|",
"unix",
".",
"NLM_F_ACK",
"|",
"unix",
".",
"NLM_F_DUMP",
")",
"\n",
"req",
".",
"AddData",
"(",
"msg",
")",
"\n",
"msgs",
",",
"err",
":=",
"req",
".",
"Execute",
"(",
"unix",
".",
"NETLINK_GENERIC",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"devices",
",",
"err",
":=",
"parseDevLinkDeviceList",
"(",
"msgs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"devices",
"{",
"h",
".",
"getEswitchAttrs",
"(",
"f",
",",
"d",
")",
"\n",
"}",
"\n",
"return",
"devices",
",",
"nil",
"\n",
"}"
] | // DevLinkGetDeviceList provides a pointer to devlink devices and nil error,
// otherwise returns an error code. | [
"DevLinkGetDeviceList",
"provides",
"a",
"pointer",
"to",
"devlink",
"devices",
"and",
"nil",
"error",
"otherwise",
"returns",
"an",
"error",
"code",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L148-L172 | train |
vishvananda/netlink | rdma_link_linux.go | RdmaLinkByName | func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) {
proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET)
req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP)
return execRdmaGetLink(req, name)
} | go | func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) {
proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET)
req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP)
return execRdmaGetLink(req, name)
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"RdmaLinkByName",
"(",
"name",
"string",
")",
"(",
"*",
"RdmaLink",
",",
"error",
")",
"{",
"proto",
":=",
"getProtoField",
"(",
"nl",
".",
"RDMA_NL_NLDEV",
",",
"nl",
".",
"RDMA_NLDEV_CMD_GET",
")",
"\n",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"proto",
",",
"unix",
".",
"NLM_F_ACK",
"|",
"unix",
".",
"NLM_F_DUMP",
")",
"\n",
"return",
"execRdmaGetLink",
"(",
"req",
",",
"name",
")",
"\n",
"}"
] | // RdmaLinkByName finds a link by name and returns a pointer to the object if
// found and nil error, otherwise returns error code. | [
"RdmaLinkByName",
"finds",
"a",
"link",
"by",
"name",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
"if",
"found",
"and",
"nil",
"error",
"otherwise",
"returns",
"error",
"code",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rdma_link_linux.go#L112-L118 | train |
vishvananda/netlink | netlink.go | NewIPNet | func NewIPNet(ip net.IP) *net.IPNet {
if ip.To4() != nil {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)}
}
return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)}
} | go | func NewIPNet(ip net.IP) *net.IPNet {
if ip.To4() != nil {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)}
}
return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)}
} | [
"func",
"NewIPNet",
"(",
"ip",
"net",
".",
"IP",
")",
"*",
"net",
".",
"IPNet",
"{",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"ip",
",",
"Mask",
":",
"net",
".",
"CIDRMask",
"(",
"32",
",",
"32",
")",
"}",
"\n",
"}",
"\n",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"ip",
",",
"Mask",
":",
"net",
".",
"CIDRMask",
"(",
"128",
",",
"128",
")",
"}",
"\n",
"}"
] | // NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128. | [
"NewIPNet",
"generates",
"an",
"IPNet",
"from",
"an",
"ip",
"address",
"using",
"a",
"netmask",
"of",
"32",
"or",
"128",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netlink.go#L35-L40 | train |
vishvananda/netlink | link_linux.go | LinkSetVfGUID | func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error {
var err error
var guid uint64
buf := bytes.NewBuffer(vfGuid)
err = binary.Read(buf, binary.LittleEndian, &guid)
if err != nil {
return err
}
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfGUID{
Vf: uint32(vf),
GUID: guid,
}
info.AddRtAttr(guidType, vfmsg.Serialize())
req.AddData(data)
_, err = req.Execute(unix.NETLINK_ROUTE, 0)
return err
} | go | func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error {
var err error
var guid uint64
buf := bytes.NewBuffer(vfGuid)
err = binary.Read(buf, binary.LittleEndian, &guid)
if err != nil {
return err
}
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfGUID{
Vf: uint32(vf),
GUID: guid,
}
info.AddRtAttr(guidType, vfmsg.Serialize())
req.AddData(data)
_, err = req.Execute(unix.NETLINK_ROUTE, 0)
return err
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkSetVfGUID",
"(",
"link",
"Link",
",",
"vf",
"int",
",",
"vfGuid",
"net",
".",
"HardwareAddr",
",",
"guidType",
"int",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"guid",
"uint64",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"vfGuid",
")",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"buf",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"guid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"base",
":=",
"link",
".",
"Attrs",
"(",
")",
"\n",
"h",
".",
"ensureIndex",
"(",
"base",
")",
"\n",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_SETLINK",
",",
"unix",
".",
"NLM_F_ACK",
")",
"\n",
"msg",
":=",
"nl",
".",
"NewIfInfomsg",
"(",
"unix",
".",
"AF_UNSPEC",
")",
"\n",
"msg",
".",
"Index",
"=",
"int32",
"(",
"base",
".",
"Index",
")",
"\n",
"req",
".",
"AddData",
"(",
"msg",
")",
"\n",
"data",
":=",
"nl",
".",
"NewRtAttr",
"(",
"unix",
".",
"IFLA_VFINFO_LIST",
",",
"nil",
")",
"\n",
"info",
":=",
"data",
".",
"AddRtAttr",
"(",
"nl",
".",
"IFLA_VF_INFO",
",",
"nil",
")",
"\n",
"vfmsg",
":=",
"nl",
".",
"VfGUID",
"{",
"Vf",
":",
"uint32",
"(",
"vf",
")",
",",
"GUID",
":",
"guid",
",",
"}",
"\n",
"info",
".",
"AddRtAttr",
"(",
"guidType",
",",
"vfmsg",
".",
"Serialize",
"(",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"data",
")",
"\n",
"_",
",",
"err",
"=",
"req",
".",
"Execute",
"(",
"unix",
".",
"NETLINK_ROUTE",
",",
"0",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // LinkSetVfGUID sets the node or port GUID of a vf for the link. | [
"LinkSetVfGUID",
"sets",
"the",
"node",
"or",
"port",
"GUID",
"of",
"a",
"vf",
"for",
"the",
"link",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L579-L608 | train |
vishvananda/netlink | link_linux.go | LinkByName | func (h *Handle) LinkByName(name string) (Link, error) {
if h.lookupByDump {
return h.linkByNameDump(name)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
nameData := nl.NewRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(name))
req.AddData(nameData)
link, err := execGetLink(req)
if err == unix.EINVAL {
// older kernels don't support looking up via IFLA_IFNAME
// so fall back to dumping all links
h.lookupByDump = true
return h.linkByNameDump(name)
}
return link, err
} | go | func (h *Handle) LinkByName(name string) (Link, error) {
if h.lookupByDump {
return h.linkByNameDump(name)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
nameData := nl.NewRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(name))
req.AddData(nameData)
link, err := execGetLink(req)
if err == unix.EINVAL {
// older kernels don't support looking up via IFLA_IFNAME
// so fall back to dumping all links
h.lookupByDump = true
return h.linkByNameDump(name)
}
return link, err
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkByName",
"(",
"name",
"string",
")",
"(",
"Link",
",",
"error",
")",
"{",
"if",
"h",
".",
"lookupByDump",
"{",
"return",
"h",
".",
"linkByNameDump",
"(",
"name",
")",
"\n",
"}",
"\n",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETLINK",
",",
"unix",
".",
"NLM_F_ACK",
")",
"\n",
"msg",
":=",
"nl",
".",
"NewIfInfomsg",
"(",
"unix",
".",
"AF_UNSPEC",
")",
"\n",
"req",
".",
"AddData",
"(",
"msg",
")",
"\n",
"attr",
":=",
"nl",
".",
"NewRtAttr",
"(",
"unix",
".",
"IFLA_EXT_MASK",
",",
"nl",
".",
"Uint32Attr",
"(",
"nl",
".",
"RTEXT_FILTER_VF",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"attr",
")",
"\n",
"nameData",
":=",
"nl",
".",
"NewRtAttr",
"(",
"unix",
".",
"IFLA_IFNAME",
",",
"nl",
".",
"ZeroTerminated",
"(",
"name",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"nameData",
")",
"\n",
"link",
",",
"err",
":=",
"execGetLink",
"(",
"req",
")",
"\n",
"if",
"err",
"==",
"unix",
".",
"EINVAL",
"{",
"h",
".",
"lookupByDump",
"=",
"true",
"\n",
"return",
"h",
".",
"linkByNameDump",
"(",
"name",
")",
"\n",
"}",
"\n",
"return",
"link",
",",
"err",
"\n",
"}"
] | // LinkByName finds a link by name and returns a pointer to the object. | [
"LinkByName",
"finds",
"a",
"link",
"by",
"name",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1283-L1308 | train |
vishvananda/netlink | link_linux.go | LinkByAlias | func (h *Handle) LinkByAlias(alias string) (Link, error) {
if h.lookupByDump {
return h.linkByAliasDump(alias)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
nameData := nl.NewRtAttr(unix.IFLA_IFALIAS, nl.ZeroTerminated(alias))
req.AddData(nameData)
link, err := execGetLink(req)
if err == unix.EINVAL {
// older kernels don't support looking up via IFLA_IFALIAS
// so fall back to dumping all links
h.lookupByDump = true
return h.linkByAliasDump(alias)
}
return link, err
} | go | func (h *Handle) LinkByAlias(alias string) (Link, error) {
if h.lookupByDump {
return h.linkByAliasDump(alias)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
nameData := nl.NewRtAttr(unix.IFLA_IFALIAS, nl.ZeroTerminated(alias))
req.AddData(nameData)
link, err := execGetLink(req)
if err == unix.EINVAL {
// older kernels don't support looking up via IFLA_IFALIAS
// so fall back to dumping all links
h.lookupByDump = true
return h.linkByAliasDump(alias)
}
return link, err
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkByAlias",
"(",
"alias",
"string",
")",
"(",
"Link",
",",
"error",
")",
"{",
"if",
"h",
".",
"lookupByDump",
"{",
"return",
"h",
".",
"linkByAliasDump",
"(",
"alias",
")",
"\n",
"}",
"\n",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETLINK",
",",
"unix",
".",
"NLM_F_ACK",
")",
"\n",
"msg",
":=",
"nl",
".",
"NewIfInfomsg",
"(",
"unix",
".",
"AF_UNSPEC",
")",
"\n",
"req",
".",
"AddData",
"(",
"msg",
")",
"\n",
"attr",
":=",
"nl",
".",
"NewRtAttr",
"(",
"unix",
".",
"IFLA_EXT_MASK",
",",
"nl",
".",
"Uint32Attr",
"(",
"nl",
".",
"RTEXT_FILTER_VF",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"attr",
")",
"\n",
"nameData",
":=",
"nl",
".",
"NewRtAttr",
"(",
"unix",
".",
"IFLA_IFALIAS",
",",
"nl",
".",
"ZeroTerminated",
"(",
"alias",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"nameData",
")",
"\n",
"link",
",",
"err",
":=",
"execGetLink",
"(",
"req",
")",
"\n",
"if",
"err",
"==",
"unix",
".",
"EINVAL",
"{",
"h",
".",
"lookupByDump",
"=",
"true",
"\n",
"return",
"h",
".",
"linkByAliasDump",
"(",
"alias",
")",
"\n",
"}",
"\n",
"return",
"link",
",",
"err",
"\n",
"}"
] | // LinkByAlias finds a link by its alias and returns a pointer to the object.
// If there are multiple links with the alias it returns the first one | [
"LinkByAlias",
"finds",
"a",
"link",
"by",
"its",
"alias",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
".",
"If",
"there",
"are",
"multiple",
"links",
"with",
"the",
"alias",
"it",
"returns",
"the",
"first",
"one"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1318-L1343 | train |
vishvananda/netlink | link_linux.go | LinkByIndex | func (h *Handle) LinkByIndex(index int) (Link, error) {
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(index)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
return execGetLink(req)
} | go | func (h *Handle) LinkByIndex(index int) (Link, error) {
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(index)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
return execGetLink(req)
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkByIndex",
"(",
"index",
"int",
")",
"(",
"Link",
",",
"error",
")",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETLINK",
",",
"unix",
".",
"NLM_F_ACK",
")",
"\n",
"msg",
":=",
"nl",
".",
"NewIfInfomsg",
"(",
"unix",
".",
"AF_UNSPEC",
")",
"\n",
"msg",
".",
"Index",
"=",
"int32",
"(",
"index",
")",
"\n",
"req",
".",
"AddData",
"(",
"msg",
")",
"\n",
"attr",
":=",
"nl",
".",
"NewRtAttr",
"(",
"unix",
".",
"IFLA_EXT_MASK",
",",
"nl",
".",
"Uint32Attr",
"(",
"nl",
".",
"RTEXT_FILTER_VF",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"attr",
")",
"\n",
"return",
"execGetLink",
"(",
"req",
")",
"\n",
"}"
] | // LinkByIndex finds a link by index and returns a pointer to the object. | [
"LinkByIndex",
"finds",
"a",
"link",
"by",
"index",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1351-L1361 | train |
vishvananda/netlink | link_linux.go | LinkSubscribe | func LinkSubscribe(ch chan<- LinkUpdate, done <-chan struct{}) error {
return linkSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | go | func LinkSubscribe(ch chan<- LinkUpdate, done <-chan struct{}) error {
return linkSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | [
"func",
"LinkSubscribe",
"(",
"ch",
"chan",
"<-",
"LinkUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"return",
"linkSubscribeAt",
"(",
"netns",
".",
"None",
"(",
")",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
",",
"done",
",",
"nil",
",",
"false",
")",
"\n",
"}"
] | // LinkSubscribe takes a chan down which notifications will be sent
// when links change. Close the 'done' chan to stop subscription. | [
"LinkSubscribe",
"takes",
"a",
"chan",
"down",
"which",
"notifications",
"will",
"be",
"sent",
"when",
"links",
"change",
".",
"Close",
"the",
"done",
"chan",
"to",
"stop",
"subscription",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1626-L1628 | train |
vishvananda/netlink | link_linux.go | LinkSubscribeWithOptions | func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, options LinkSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return linkSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | go | func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, options LinkSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return linkSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | [
"func",
"LinkSubscribeWithOptions",
"(",
"ch",
"chan",
"<-",
"LinkUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
",",
"options",
"LinkSubscribeOptions",
")",
"error",
"{",
"if",
"options",
".",
"Namespace",
"==",
"nil",
"{",
"none",
":=",
"netns",
".",
"None",
"(",
")",
"\n",
"options",
".",
"Namespace",
"=",
"&",
"none",
"\n",
"}",
"\n",
"return",
"linkSubscribeAt",
"(",
"*",
"options",
".",
"Namespace",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
",",
"done",
",",
"options",
".",
"ErrorCallback",
",",
"options",
".",
"ListExisting",
")",
"\n",
"}"
] | // LinkSubscribeWithOptions work like LinkSubscribe but enable to
// provide additional options to modify the behavior. Currently, the
// namespace can be provided as well as an error callback. | [
"LinkSubscribeWithOptions",
"work",
"like",
"LinkSubscribe",
"but",
"enable",
"to",
"provide",
"additional",
"options",
"to",
"modify",
"the",
"behavior",
".",
"Currently",
"the",
"namespace",
"can",
"be",
"provided",
"as",
"well",
"as",
"an",
"error",
"callback",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1647-L1653 | train |
vishvananda/netlink | link_linux.go | LinkSetBondSlave | func LinkSetBondSlave(link Link, master *Bond) error {
fd, err := getSocketUDP()
if err != nil {
return err
}
defer syscall.Close(fd)
ifreq := newIocltSlaveReq(link.Attrs().Name, master.Attrs().Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.SIOCBONDENSLAVE, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return fmt.Errorf("Failed to enslave %q to %q, errno=%v", link.Attrs().Name, master.Attrs().Name, errno)
}
return nil
} | go | func LinkSetBondSlave(link Link, master *Bond) error {
fd, err := getSocketUDP()
if err != nil {
return err
}
defer syscall.Close(fd)
ifreq := newIocltSlaveReq(link.Attrs().Name, master.Attrs().Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.SIOCBONDENSLAVE, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return fmt.Errorf("Failed to enslave %q to %q, errno=%v", link.Attrs().Name, master.Attrs().Name, errno)
}
return nil
} | [
"func",
"LinkSetBondSlave",
"(",
"link",
"Link",
",",
"master",
"*",
"Bond",
")",
"error",
"{",
"fd",
",",
"err",
":=",
"getSocketUDP",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"ifreq",
":=",
"newIocltSlaveReq",
"(",
"link",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"master",
".",
"Attrs",
"(",
")",
".",
"Name",
")",
"\n",
"_",
",",
"_",
",",
"errno",
":=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"fd",
")",
",",
"unix",
".",
"SIOCBONDENSLAVE",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"ifreq",
")",
")",
")",
"\n",
"if",
"errno",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Failed to enslave %q to %q, errno=%v\"",
",",
"link",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"master",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"errno",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // LinkSetBondSlave add slave to bond link via ioctl interface. | [
"LinkSetBondSlave",
"add",
"slave",
"to",
"bond",
"link",
"via",
"ioctl",
"interface",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L2531-L2545 | train |
vishvananda/netlink | link_linux.go | VethPeerIndex | func VethPeerIndex(link *Veth) (int, error) {
fd, err := getSocketUDP()
if err != nil {
return -1, err
}
defer syscall.Close(fd)
ifreq, sSet := newIocltStringSetReq(link.Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno)
}
gstrings := ðtoolGstrings{
cmd: ETHTOOL_GSTRINGS,
stringSet: ETH_SS_STATS,
length: sSet.data[0],
}
ifreq.Data = uintptr(unsafe.Pointer(gstrings))
_, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno)
}
stats := ðtoolStats{
cmd: ETHTOOL_GSTATS,
nStats: gstrings.length,
}
ifreq.Data = uintptr(unsafe.Pointer(stats))
_, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno)
}
return int(stats.data[0]), nil
} | go | func VethPeerIndex(link *Veth) (int, error) {
fd, err := getSocketUDP()
if err != nil {
return -1, err
}
defer syscall.Close(fd)
ifreq, sSet := newIocltStringSetReq(link.Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno)
}
gstrings := ðtoolGstrings{
cmd: ETHTOOL_GSTRINGS,
stringSet: ETH_SS_STATS,
length: sSet.data[0],
}
ifreq.Data = uintptr(unsafe.Pointer(gstrings))
_, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno)
}
stats := ðtoolStats{
cmd: ETHTOOL_GSTATS,
nStats: gstrings.length,
}
ifreq.Data = uintptr(unsafe.Pointer(stats))
_, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno)
}
return int(stats.data[0]), nil
} | [
"func",
"VethPeerIndex",
"(",
"link",
"*",
"Veth",
")",
"(",
"int",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"getSocketUDP",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"defer",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"ifreq",
",",
"sSet",
":=",
"newIocltStringSetReq",
"(",
"link",
".",
"Name",
")",
"\n",
"_",
",",
"_",
",",
"errno",
":=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"fd",
")",
",",
"SIOCETHTOOL",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"ifreq",
")",
")",
")",
"\n",
"if",
"errno",
"!=",
"0",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"SIOCETHTOOL request for %q failed, errno=%v\"",
",",
"link",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"errno",
")",
"\n",
"}",
"\n",
"gstrings",
":=",
"&",
"ethtoolGstrings",
"{",
"cmd",
":",
"ETHTOOL_GSTRINGS",
",",
"stringSet",
":",
"ETH_SS_STATS",
",",
"length",
":",
"sSet",
".",
"data",
"[",
"0",
"]",
",",
"}",
"\n",
"ifreq",
".",
"Data",
"=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"gstrings",
")",
")",
"\n",
"_",
",",
"_",
",",
"errno",
"=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"fd",
")",
",",
"SIOCETHTOOL",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"ifreq",
")",
")",
")",
"\n",
"if",
"errno",
"!=",
"0",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"SIOCETHTOOL request for %q failed, errno=%v\"",
",",
"link",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"errno",
")",
"\n",
"}",
"\n",
"stats",
":=",
"&",
"ethtoolStats",
"{",
"cmd",
":",
"ETHTOOL_GSTATS",
",",
"nStats",
":",
"gstrings",
".",
"length",
",",
"}",
"\n",
"ifreq",
".",
"Data",
"=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"stats",
")",
")",
"\n",
"_",
",",
"_",
",",
"errno",
"=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"fd",
")",
",",
"SIOCETHTOOL",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"ifreq",
")",
")",
")",
"\n",
"if",
"errno",
"!=",
"0",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"SIOCETHTOOL request for %q failed, errno=%v\"",
",",
"link",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"errno",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"stats",
".",
"data",
"[",
"0",
"]",
")",
",",
"nil",
"\n",
"}"
] | // VethPeerIndex get veth peer index. | [
"VethPeerIndex",
"get",
"veth",
"peer",
"index",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L2548-L2582 | train |
vishvananda/netlink | netns_linux.go | GetNetNsIdByFd | func (h *Handle) GetNetNsIdByFd(fd int) (int, error) {
return h.getNetNsId(NETNSA_FD, uint32(fd))
} | go | func (h *Handle) GetNetNsIdByFd(fd int) (int, error) {
return h.getNetNsId(NETNSA_FD, uint32(fd))
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"GetNetNsIdByFd",
"(",
"fd",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"h",
".",
"getNetNsId",
"(",
"NETNSA_FD",
",",
"uint32",
"(",
"fd",
")",
")",
"\n",
"}"
] | // GetNetNsIdByFd looks up the network namespace ID for a given fd.
// fd must be an open file descriptor to a namespace file.
// Returns -1 if the namespace does not have an ID set. | [
"GetNetNsIdByFd",
"looks",
"up",
"the",
"network",
"namespace",
"ID",
"for",
"a",
"given",
"fd",
".",
"fd",
"must",
"be",
"an",
"open",
"file",
"descriptor",
"to",
"a",
"namespace",
"file",
".",
"Returns",
"-",
"1",
"if",
"the",
"namespace",
"does",
"not",
"have",
"an",
"ID",
"set",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L57-L59 | train |
vishvananda/netlink | netns_linux.go | SetNetNsIdByFd | func (h *Handle) SetNetNsIdByFd(fd, nsid int) error {
return h.setNetNsId(NETNSA_FD, uint32(fd), uint32(nsid))
} | go | func (h *Handle) SetNetNsIdByFd(fd, nsid int) error {
return h.setNetNsId(NETNSA_FD, uint32(fd), uint32(nsid))
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"SetNetNsIdByFd",
"(",
"fd",
",",
"nsid",
"int",
")",
"error",
"{",
"return",
"h",
".",
"setNetNsId",
"(",
"NETNSA_FD",
",",
"uint32",
"(",
"fd",
")",
",",
"uint32",
"(",
"nsid",
")",
")",
"\n",
"}"
] | // SetNetNSIdByFd sets the ID of the network namespace for a given fd.
// fd must be an open file descriptor to a namespace file.
// The ID can only be set for namespaces without an ID already set. | [
"SetNetNSIdByFd",
"sets",
"the",
"ID",
"of",
"the",
"network",
"namespace",
"for",
"a",
"given",
"fd",
".",
"fd",
"must",
"be",
"an",
"open",
"file",
"descriptor",
"to",
"a",
"namespace",
"file",
".",
"The",
"ID",
"can",
"only",
"be",
"set",
"for",
"namespaces",
"without",
"an",
"ID",
"already",
"set",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L71-L73 | train |
vishvananda/netlink | netns_linux.go | getNetNsId | func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) {
req := h.newNetlinkRequest(unix.RTM_GETNSID, unix.NLM_F_REQUEST)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID)
if err != nil {
return 0, err
}
for _, m := range msgs {
msg := nl.DeserializeRtGenMsg(m)
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return 0, err
}
for _, attr := range attrs {
switch attr.Attr.Type {
case NETNSA_NSID:
return int(int32(native.Uint32(attr.Value))), nil
}
}
}
return 0, fmt.Errorf("unexpected empty result")
} | go | func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) {
req := h.newNetlinkRequest(unix.RTM_GETNSID, unix.NLM_F_REQUEST)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID)
if err != nil {
return 0, err
}
for _, m := range msgs {
msg := nl.DeserializeRtGenMsg(m)
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return 0, err
}
for _, attr := range attrs {
switch attr.Attr.Type {
case NETNSA_NSID:
return int(int32(native.Uint32(attr.Value))), nil
}
}
}
return 0, fmt.Errorf("unexpected empty result")
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"getNetNsId",
"(",
"attrType",
"int",
",",
"val",
"uint32",
")",
"(",
"int",
",",
"error",
")",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETNSID",
",",
"unix",
".",
"NLM_F_REQUEST",
")",
"\n",
"rtgen",
":=",
"nl",
".",
"NewRtGenMsg",
"(",
")",
"\n",
"req",
".",
"AddData",
"(",
"rtgen",
")",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
",",
"4",
")",
"\n",
"native",
".",
"PutUint32",
"(",
"b",
",",
"val",
")",
"\n",
"attr",
":=",
"nl",
".",
"NewRtAttr",
"(",
"attrType",
",",
"b",
")",
"\n",
"req",
".",
"AddData",
"(",
"attr",
")",
"\n",
"msgs",
",",
"err",
":=",
"req",
".",
"Execute",
"(",
"unix",
".",
"NETLINK_ROUTE",
",",
"unix",
".",
"RTM_NEWNSID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"msgs",
"{",
"msg",
":=",
"nl",
".",
"DeserializeRtGenMsg",
"(",
"m",
")",
"\n",
"attrs",
",",
"err",
":=",
"nl",
".",
"ParseRouteAttr",
"(",
"m",
"[",
"msg",
".",
"Len",
"(",
")",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"attr",
":=",
"range",
"attrs",
"{",
"switch",
"attr",
".",
"Attr",
".",
"Type",
"{",
"case",
"NETNSA_NSID",
":",
"return",
"int",
"(",
"int32",
"(",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"unexpected empty result\"",
")",
"\n",
"}"
] | // getNetNsId requests the netnsid for a given type-val pair
// type should be either NETNSA_PID or NETNSA_FD | [
"getNetNsId",
"requests",
"the",
"netnsid",
"for",
"a",
"given",
"type",
"-",
"val",
"pair",
"type",
"should",
"be",
"either",
"NETNSA_PID",
"or",
"NETNSA_FD"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L84-L118 | train |
vishvananda/netlink | netns_linux.go | setNetNsId | func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error {
req := h.newNetlinkRequest(unix.RTM_NEWNSID, unix.NLM_F_REQUEST|unix.NLM_F_ACK)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
b1 := make([]byte, 4, 4)
native.PutUint32(b1, newnsid)
attr1 := nl.NewRtAttr(NETNSA_NSID, b1)
req.AddData(attr1)
_, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID)
return err
} | go | func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error {
req := h.newNetlinkRequest(unix.RTM_NEWNSID, unix.NLM_F_REQUEST|unix.NLM_F_ACK)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
b1 := make([]byte, 4, 4)
native.PutUint32(b1, newnsid)
attr1 := nl.NewRtAttr(NETNSA_NSID, b1)
req.AddData(attr1)
_, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID)
return err
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"setNetNsId",
"(",
"attrType",
"int",
",",
"val",
"uint32",
",",
"newnsid",
"uint32",
")",
"error",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_NEWNSID",
",",
"unix",
".",
"NLM_F_REQUEST",
"|",
"unix",
".",
"NLM_F_ACK",
")",
"\n",
"rtgen",
":=",
"nl",
".",
"NewRtGenMsg",
"(",
")",
"\n",
"req",
".",
"AddData",
"(",
"rtgen",
")",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
",",
"4",
")",
"\n",
"native",
".",
"PutUint32",
"(",
"b",
",",
"val",
")",
"\n",
"attr",
":=",
"nl",
".",
"NewRtAttr",
"(",
"attrType",
",",
"b",
")",
"\n",
"req",
".",
"AddData",
"(",
"attr",
")",
"\n",
"b1",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
",",
"4",
")",
"\n",
"native",
".",
"PutUint32",
"(",
"b1",
",",
"newnsid",
")",
"\n",
"attr1",
":=",
"nl",
".",
"NewRtAttr",
"(",
"NETNSA_NSID",
",",
"b1",
")",
"\n",
"req",
".",
"AddData",
"(",
"attr1",
")",
"\n",
"_",
",",
"err",
":=",
"req",
".",
"Execute",
"(",
"unix",
".",
"NETLINK_ROUTE",
",",
"unix",
".",
"RTM_NEWNSID",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // setNetNsId sets the netnsid for a given type-val pair
// type should be either NETNSA_PID or NETNSA_FD
// The ID can only be set for namespaces without an ID already set | [
"setNetNsId",
"sets",
"the",
"netnsid",
"for",
"a",
"given",
"type",
"-",
"val",
"pair",
"type",
"should",
"be",
"either",
"NETNSA_PID",
"or",
"NETNSA_FD",
"The",
"ID",
"can",
"only",
"be",
"set",
"for",
"namespaces",
"without",
"an",
"ID",
"already",
"set"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L123-L141 | train |
vishvananda/netlink | route.go | ipNetEqual | func ipNetEqual(ipn1 *net.IPNet, ipn2 *net.IPNet) bool {
if ipn1 == ipn2 {
return true
}
if ipn1 == nil || ipn2 == nil {
return false
}
m1, _ := ipn1.Mask.Size()
m2, _ := ipn2.Mask.Size()
return m1 == m2 && ipn1.IP.Equal(ipn2.IP)
} | go | func ipNetEqual(ipn1 *net.IPNet, ipn2 *net.IPNet) bool {
if ipn1 == ipn2 {
return true
}
if ipn1 == nil || ipn2 == nil {
return false
}
m1, _ := ipn1.Mask.Size()
m2, _ := ipn2.Mask.Size()
return m1 == m2 && ipn1.IP.Equal(ipn2.IP)
} | [
"func",
"ipNetEqual",
"(",
"ipn1",
"*",
"net",
".",
"IPNet",
",",
"ipn2",
"*",
"net",
".",
"IPNet",
")",
"bool",
"{",
"if",
"ipn1",
"==",
"ipn2",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"ipn1",
"==",
"nil",
"||",
"ipn2",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"m1",
",",
"_",
":=",
"ipn1",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"m2",
",",
"_",
":=",
"ipn2",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"return",
"m1",
"==",
"m2",
"&&",
"ipn1",
".",
"IP",
".",
"Equal",
"(",
"ipn2",
".",
"IP",
")",
"\n",
"}"
] | // ipNetEqual returns true iff both IPNet are equal | [
"ipNetEqual",
"returns",
"true",
"iff",
"both",
"IPNet",
"are",
"equal"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/route.go#L170-L180 | train |
vishvananda/netlink | ioctl_linux.go | newIocltSlaveReq | func newIocltSlaveReq(slave, master string) *IfreqSlave {
ifreq := &IfreqSlave{}
copy(ifreq.Name[:unix.IFNAMSIZ-1], master)
copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave)
return ifreq
} | go | func newIocltSlaveReq(slave, master string) *IfreqSlave {
ifreq := &IfreqSlave{}
copy(ifreq.Name[:unix.IFNAMSIZ-1], master)
copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave)
return ifreq
} | [
"func",
"newIocltSlaveReq",
"(",
"slave",
",",
"master",
"string",
")",
"*",
"IfreqSlave",
"{",
"ifreq",
":=",
"&",
"IfreqSlave",
"{",
"}",
"\n",
"copy",
"(",
"ifreq",
".",
"Name",
"[",
":",
"unix",
".",
"IFNAMSIZ",
"-",
"1",
"]",
",",
"master",
")",
"\n",
"copy",
"(",
"ifreq",
".",
"Slave",
"[",
":",
"unix",
".",
"IFNAMSIZ",
"-",
"1",
"]",
",",
"slave",
")",
"\n",
"return",
"ifreq",
"\n",
"}"
] | // newIocltSlaveReq returns filled IfreqSlave with proper interface names
// It is used by ioctl to assign slave to bond master | [
"newIocltSlaveReq",
"returns",
"filled",
"IfreqSlave",
"with",
"proper",
"interface",
"names",
"It",
"is",
"used",
"by",
"ioctl",
"to",
"assign",
"slave",
"to",
"bond",
"master"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/ioctl_linux.go#L75-L80 | train |
vishvananda/netlink | ioctl_linux.go | newIocltStringSetReq | func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) {
e := ðtoolSset{
cmd: ETHTOOL_GSSET_INFO,
mask: 1 << ETH_SS_STATS,
}
ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))}
copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName)
return ifreq, e
} | go | func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) {
e := ðtoolSset{
cmd: ETHTOOL_GSSET_INFO,
mask: 1 << ETH_SS_STATS,
}
ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))}
copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName)
return ifreq, e
} | [
"func",
"newIocltStringSetReq",
"(",
"linkName",
"string",
")",
"(",
"*",
"Ifreq",
",",
"*",
"ethtoolSset",
")",
"{",
"e",
":=",
"&",
"ethtoolSset",
"{",
"cmd",
":",
"ETHTOOL_GSSET_INFO",
",",
"mask",
":",
"1",
"<<",
"ETH_SS_STATS",
",",
"}",
"\n",
"ifreq",
":=",
"&",
"Ifreq",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"e",
")",
")",
"}",
"\n",
"copy",
"(",
"ifreq",
".",
"Name",
"[",
":",
"unix",
".",
"IFNAMSIZ",
"-",
"1",
"]",
",",
"linkName",
")",
"\n",
"return",
"ifreq",
",",
"e",
"\n",
"}"
] | // newIocltStringSetReq creates request to get interface string set | [
"newIocltStringSetReq",
"creates",
"request",
"to",
"get",
"interface",
"string",
"set"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/ioctl_linux.go#L83-L92 | train |
vishvananda/netlink | addr.go | Equal | func (a Addr) Equal(x Addr) bool {
sizea, _ := a.Mask.Size()
sizeb, _ := x.Mask.Size()
// ignore label for comparison
return a.IP.Equal(x.IP) && sizea == sizeb
} | go | func (a Addr) Equal(x Addr) bool {
sizea, _ := a.Mask.Size()
sizeb, _ := x.Mask.Size()
// ignore label for comparison
return a.IP.Equal(x.IP) && sizea == sizeb
} | [
"func",
"(",
"a",
"Addr",
")",
"Equal",
"(",
"x",
"Addr",
")",
"bool",
"{",
"sizea",
",",
"_",
":=",
"a",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"sizeb",
",",
"_",
":=",
"x",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"return",
"a",
".",
"IP",
".",
"Equal",
"(",
"x",
".",
"IP",
")",
"&&",
"sizea",
"==",
"sizeb",
"\n",
"}"
] | // Equal returns true if both Addrs have the same net.IPNet value. | [
"Equal",
"returns",
"true",
"if",
"both",
"Addrs",
"have",
"the",
"same",
"net",
".",
"IPNet",
"value",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr.go#L44-L49 | train |
vishvananda/netlink | socket_linux.go | SocketGet | func SocketGet(local, remote net.Addr) (*Socket, error) {
localTCP, ok := local.(*net.TCPAddr)
if !ok {
return nil, ErrNotImplemented
}
remoteTCP, ok := remote.(*net.TCPAddr)
if !ok {
return nil, ErrNotImplemented
}
localIP := localTCP.IP.To4()
if localIP == nil {
return nil, ErrNotImplemented
}
remoteIP := remoteTCP.IP.To4()
if remoteIP == nil {
return nil, ErrNotImplemented
}
s, err := nl.Subscribe(unix.NETLINK_INET_DIAG)
if err != nil {
return nil, err
}
defer s.Close()
req := nl.NewNetlinkRequest(nl.SOCK_DIAG_BY_FAMILY, 0)
req.AddData(&socketRequest{
Family: unix.AF_INET,
Protocol: unix.IPPROTO_TCP,
ID: SocketID{
SourcePort: uint16(localTCP.Port),
DestinationPort: uint16(remoteTCP.Port),
Source: localIP,
Destination: remoteIP,
Cookie: [2]uint32{nl.TCPDIAG_NOCOOKIE, nl.TCPDIAG_NOCOOKIE},
},
})
s.Send(req)
msgs, err := s.Receive()
if err != nil {
return nil, err
}
if len(msgs) == 0 {
return nil, errors.New("no message nor error from netlink")
}
if len(msgs) > 2 {
return nil, fmt.Errorf("multiple (%d) matching sockets", len(msgs))
}
sock := &Socket{}
if err := sock.deserialize(msgs[0].Data); err != nil {
return nil, err
}
return sock, nil
} | go | func SocketGet(local, remote net.Addr) (*Socket, error) {
localTCP, ok := local.(*net.TCPAddr)
if !ok {
return nil, ErrNotImplemented
}
remoteTCP, ok := remote.(*net.TCPAddr)
if !ok {
return nil, ErrNotImplemented
}
localIP := localTCP.IP.To4()
if localIP == nil {
return nil, ErrNotImplemented
}
remoteIP := remoteTCP.IP.To4()
if remoteIP == nil {
return nil, ErrNotImplemented
}
s, err := nl.Subscribe(unix.NETLINK_INET_DIAG)
if err != nil {
return nil, err
}
defer s.Close()
req := nl.NewNetlinkRequest(nl.SOCK_DIAG_BY_FAMILY, 0)
req.AddData(&socketRequest{
Family: unix.AF_INET,
Protocol: unix.IPPROTO_TCP,
ID: SocketID{
SourcePort: uint16(localTCP.Port),
DestinationPort: uint16(remoteTCP.Port),
Source: localIP,
Destination: remoteIP,
Cookie: [2]uint32{nl.TCPDIAG_NOCOOKIE, nl.TCPDIAG_NOCOOKIE},
},
})
s.Send(req)
msgs, err := s.Receive()
if err != nil {
return nil, err
}
if len(msgs) == 0 {
return nil, errors.New("no message nor error from netlink")
}
if len(msgs) > 2 {
return nil, fmt.Errorf("multiple (%d) matching sockets", len(msgs))
}
sock := &Socket{}
if err := sock.deserialize(msgs[0].Data); err != nil {
return nil, err
}
return sock, nil
} | [
"func",
"SocketGet",
"(",
"local",
",",
"remote",
"net",
".",
"Addr",
")",
"(",
"*",
"Socket",
",",
"error",
")",
"{",
"localTCP",
",",
"ok",
":=",
"local",
".",
"(",
"*",
"net",
".",
"TCPAddr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}",
"\n",
"remoteTCP",
",",
"ok",
":=",
"remote",
".",
"(",
"*",
"net",
".",
"TCPAddr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}",
"\n",
"localIP",
":=",
"localTCP",
".",
"IP",
".",
"To4",
"(",
")",
"\n",
"if",
"localIP",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}",
"\n",
"remoteIP",
":=",
"remoteTCP",
".",
"IP",
".",
"To4",
"(",
")",
"\n",
"if",
"remoteIP",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}",
"\n",
"s",
",",
"err",
":=",
"nl",
".",
"Subscribe",
"(",
"unix",
".",
"NETLINK_INET_DIAG",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n",
"req",
":=",
"nl",
".",
"NewNetlinkRequest",
"(",
"nl",
".",
"SOCK_DIAG_BY_FAMILY",
",",
"0",
")",
"\n",
"req",
".",
"AddData",
"(",
"&",
"socketRequest",
"{",
"Family",
":",
"unix",
".",
"AF_INET",
",",
"Protocol",
":",
"unix",
".",
"IPPROTO_TCP",
",",
"ID",
":",
"SocketID",
"{",
"SourcePort",
":",
"uint16",
"(",
"localTCP",
".",
"Port",
")",
",",
"DestinationPort",
":",
"uint16",
"(",
"remoteTCP",
".",
"Port",
")",
",",
"Source",
":",
"localIP",
",",
"Destination",
":",
"remoteIP",
",",
"Cookie",
":",
"[",
"2",
"]",
"uint32",
"{",
"nl",
".",
"TCPDIAG_NOCOOKIE",
",",
"nl",
".",
"TCPDIAG_NOCOOKIE",
"}",
",",
"}",
",",
"}",
")",
"\n",
"s",
".",
"Send",
"(",
"req",
")",
"\n",
"msgs",
",",
"err",
":=",
"s",
".",
"Receive",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"msgs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"no message nor error from netlink\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"msgs",
")",
">",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"multiple (%d) matching sockets\"",
",",
"len",
"(",
"msgs",
")",
")",
"\n",
"}",
"\n",
"sock",
":=",
"&",
"Socket",
"{",
"}",
"\n",
"if",
"err",
":=",
"sock",
".",
"deserialize",
"(",
"msgs",
"[",
"0",
"]",
".",
"Data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"sock",
",",
"nil",
"\n",
"}"
] | // SocketGet returns the Socket identified by its local and remote addresses. | [
"SocketGet",
"returns",
"the",
"Socket",
"identified",
"by",
"its",
"local",
"and",
"remote",
"addresses",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/socket_linux.go#L108-L159 | train |
vishvananda/netlink | route_linux.go | RouteSubscribe | func RouteSubscribe(ch chan<- RouteUpdate, done <-chan struct{}) error {
return routeSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | go | func RouteSubscribe(ch chan<- RouteUpdate, done <-chan struct{}) error {
return routeSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | [
"func",
"RouteSubscribe",
"(",
"ch",
"chan",
"<-",
"RouteUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"return",
"routeSubscribeAt",
"(",
"netns",
".",
"None",
"(",
")",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
",",
"done",
",",
"nil",
",",
"false",
")",
"\n",
"}"
] | // RouteSubscribe takes a chan down which notifications will be sent
// when routes are added or deleted. Close the 'done' chan to stop subscription. | [
"RouteSubscribe",
"takes",
"a",
"chan",
"down",
"which",
"notifications",
"will",
"be",
"sent",
"when",
"routes",
"are",
"added",
"or",
"deleted",
".",
"Close",
"the",
"done",
"chan",
"to",
"stop",
"subscription",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/route_linux.go#L988-L990 | train |
vishvananda/netlink | route_linux.go | RouteSubscribeWithOptions | func RouteSubscribeWithOptions(ch chan<- RouteUpdate, done <-chan struct{}, options RouteSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return routeSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | go | func RouteSubscribeWithOptions(ch chan<- RouteUpdate, done <-chan struct{}, options RouteSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return routeSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | [
"func",
"RouteSubscribeWithOptions",
"(",
"ch",
"chan",
"<-",
"RouteUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
",",
"options",
"RouteSubscribeOptions",
")",
"error",
"{",
"if",
"options",
".",
"Namespace",
"==",
"nil",
"{",
"none",
":=",
"netns",
".",
"None",
"(",
")",
"\n",
"options",
".",
"Namespace",
"=",
"&",
"none",
"\n",
"}",
"\n",
"return",
"routeSubscribeAt",
"(",
"*",
"options",
".",
"Namespace",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
",",
"done",
",",
"options",
".",
"ErrorCallback",
",",
"options",
".",
"ListExisting",
")",
"\n",
"}"
] | // RouteSubscribeWithOptions work like RouteSubscribe but enable to
// provide additional options to modify the behavior. Currently, the
// namespace can be provided as well as an error callback. | [
"RouteSubscribeWithOptions",
"work",
"like",
"RouteSubscribe",
"but",
"enable",
"to",
"provide",
"additional",
"options",
"to",
"modify",
"the",
"behavior",
".",
"Currently",
"the",
"namespace",
"can",
"be",
"provided",
"as",
"well",
"as",
"an",
"error",
"callback",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/route_linux.go#L1009-L1015 | train |
vishvananda/netlink | bpf_linux.go | loadSimpleBpf | func loadSimpleBpf(progType BpfProgType, ret uint32) (int, error) {
insns := []uint64{
0x00000000000000b7 | (uint64(ret) << 32),
0x0000000000000095,
}
license := []byte{'A', 'S', 'L', '2', '\x00'}
attr := BPFAttr{
ProgType: uint32(progType),
InsnCnt: uint32(len(insns)),
Insns: uintptr(unsafe.Pointer(&insns[0])),
License: uintptr(unsafe.Pointer(&license[0])),
}
fd, _, errno := unix.Syscall(unix.SYS_BPF,
5, /* bpf cmd */
uintptr(unsafe.Pointer(&attr)),
unsafe.Sizeof(attr))
if errno != 0 {
return 0, errno
}
return int(fd), nil
} | go | func loadSimpleBpf(progType BpfProgType, ret uint32) (int, error) {
insns := []uint64{
0x00000000000000b7 | (uint64(ret) << 32),
0x0000000000000095,
}
license := []byte{'A', 'S', 'L', '2', '\x00'}
attr := BPFAttr{
ProgType: uint32(progType),
InsnCnt: uint32(len(insns)),
Insns: uintptr(unsafe.Pointer(&insns[0])),
License: uintptr(unsafe.Pointer(&license[0])),
}
fd, _, errno := unix.Syscall(unix.SYS_BPF,
5, /* bpf cmd */
uintptr(unsafe.Pointer(&attr)),
unsafe.Sizeof(attr))
if errno != 0 {
return 0, errno
}
return int(fd), nil
} | [
"func",
"loadSimpleBpf",
"(",
"progType",
"BpfProgType",
",",
"ret",
"uint32",
")",
"(",
"int",
",",
"error",
")",
"{",
"insns",
":=",
"[",
"]",
"uint64",
"{",
"0x00000000000000b7",
"|",
"(",
"uint64",
"(",
"ret",
")",
"<<",
"32",
")",
",",
"0x0000000000000095",
",",
"}",
"\n",
"license",
":=",
"[",
"]",
"byte",
"{",
"'A'",
",",
"'S'",
",",
"'L'",
",",
"'2'",
",",
"'\\x00'",
"}",
"\n",
"attr",
":=",
"BPFAttr",
"{",
"ProgType",
":",
"uint32",
"(",
"progType",
")",
",",
"InsnCnt",
":",
"uint32",
"(",
"len",
"(",
"insns",
")",
")",
",",
"Insns",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"insns",
"[",
"0",
"]",
")",
")",
",",
"License",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"license",
"[",
"0",
"]",
")",
")",
",",
"}",
"\n",
"fd",
",",
"_",
",",
"errno",
":=",
"unix",
".",
"Syscall",
"(",
"unix",
".",
"SYS_BPF",
",",
"5",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"attr",
")",
")",
",",
"unsafe",
".",
"Sizeof",
"(",
"attr",
")",
")",
"\n",
"if",
"errno",
"!=",
"0",
"{",
"return",
"0",
",",
"errno",
"\n",
"}",
"\n",
"return",
"int",
"(",
"fd",
")",
",",
"nil",
"\n",
"}"
] | // loadSimpleBpf loads a trivial bpf program for testing purposes. | [
"loadSimpleBpf",
"loads",
"a",
"trivial",
"bpf",
"program",
"for",
"testing",
"purposes",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/bpf_linux.go#L33-L53 | train |
vishvananda/netlink | rule.go | NewRule | func NewRule() *Rule {
return &Rule{
SuppressIfgroup: -1,
SuppressPrefixlen: -1,
Priority: -1,
Mark: -1,
Mask: -1,
Goto: -1,
Flow: -1,
}
} | go | func NewRule() *Rule {
return &Rule{
SuppressIfgroup: -1,
SuppressPrefixlen: -1,
Priority: -1,
Mark: -1,
Mask: -1,
Goto: -1,
Flow: -1,
}
} | [
"func",
"NewRule",
"(",
")",
"*",
"Rule",
"{",
"return",
"&",
"Rule",
"{",
"SuppressIfgroup",
":",
"-",
"1",
",",
"SuppressPrefixlen",
":",
"-",
"1",
",",
"Priority",
":",
"-",
"1",
",",
"Mark",
":",
"-",
"1",
",",
"Mask",
":",
"-",
"1",
",",
"Goto",
":",
"-",
"1",
",",
"Flow",
":",
"-",
"1",
",",
"}",
"\n",
"}"
] | // NewRule return empty rules. | [
"NewRule",
"return",
"empty",
"rules",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rule.go#L32-L42 | train |
vishvananda/netlink | qdisc_linux.go | NewNetem | func NewNetem(attrs QdiscAttrs, nattrs NetemQdiscAttrs) *Netem {
var limit uint32 = 1000
var lossCorr, delayCorr, duplicateCorr uint32
var reorderProb, reorderCorr uint32
var corruptProb, corruptCorr uint32
latency := nattrs.Latency
loss := Percentage2u32(nattrs.Loss)
gap := nattrs.Gap
duplicate := Percentage2u32(nattrs.Duplicate)
jitter := nattrs.Jitter
// Correlation
if latency > 0 && jitter > 0 {
delayCorr = Percentage2u32(nattrs.DelayCorr)
}
if loss > 0 {
lossCorr = Percentage2u32(nattrs.LossCorr)
}
if duplicate > 0 {
duplicateCorr = Percentage2u32(nattrs.DuplicateCorr)
}
// FIXME should validate values(like loss/duplicate are percentages...)
latency = time2Tick(latency)
if nattrs.Limit != 0 {
limit = nattrs.Limit
}
// Jitter is only value if latency is > 0
if latency > 0 {
jitter = time2Tick(jitter)
}
reorderProb = Percentage2u32(nattrs.ReorderProb)
reorderCorr = Percentage2u32(nattrs.ReorderCorr)
if reorderProb > 0 {
// ERROR if lantency == 0
if gap == 0 {
gap = 1
}
}
corruptProb = Percentage2u32(nattrs.CorruptProb)
corruptCorr = Percentage2u32(nattrs.CorruptCorr)
return &Netem{
QdiscAttrs: attrs,
Latency: latency,
DelayCorr: delayCorr,
Limit: limit,
Loss: loss,
LossCorr: lossCorr,
Gap: gap,
Duplicate: duplicate,
DuplicateCorr: duplicateCorr,
Jitter: jitter,
ReorderProb: reorderProb,
ReorderCorr: reorderCorr,
CorruptProb: corruptProb,
CorruptCorr: corruptCorr,
}
} | go | func NewNetem(attrs QdiscAttrs, nattrs NetemQdiscAttrs) *Netem {
var limit uint32 = 1000
var lossCorr, delayCorr, duplicateCorr uint32
var reorderProb, reorderCorr uint32
var corruptProb, corruptCorr uint32
latency := nattrs.Latency
loss := Percentage2u32(nattrs.Loss)
gap := nattrs.Gap
duplicate := Percentage2u32(nattrs.Duplicate)
jitter := nattrs.Jitter
// Correlation
if latency > 0 && jitter > 0 {
delayCorr = Percentage2u32(nattrs.DelayCorr)
}
if loss > 0 {
lossCorr = Percentage2u32(nattrs.LossCorr)
}
if duplicate > 0 {
duplicateCorr = Percentage2u32(nattrs.DuplicateCorr)
}
// FIXME should validate values(like loss/duplicate are percentages...)
latency = time2Tick(latency)
if nattrs.Limit != 0 {
limit = nattrs.Limit
}
// Jitter is only value if latency is > 0
if latency > 0 {
jitter = time2Tick(jitter)
}
reorderProb = Percentage2u32(nattrs.ReorderProb)
reorderCorr = Percentage2u32(nattrs.ReorderCorr)
if reorderProb > 0 {
// ERROR if lantency == 0
if gap == 0 {
gap = 1
}
}
corruptProb = Percentage2u32(nattrs.CorruptProb)
corruptCorr = Percentage2u32(nattrs.CorruptCorr)
return &Netem{
QdiscAttrs: attrs,
Latency: latency,
DelayCorr: delayCorr,
Limit: limit,
Loss: loss,
LossCorr: lossCorr,
Gap: gap,
Duplicate: duplicate,
DuplicateCorr: duplicateCorr,
Jitter: jitter,
ReorderProb: reorderProb,
ReorderCorr: reorderCorr,
CorruptProb: corruptProb,
CorruptCorr: corruptCorr,
}
} | [
"func",
"NewNetem",
"(",
"attrs",
"QdiscAttrs",
",",
"nattrs",
"NetemQdiscAttrs",
")",
"*",
"Netem",
"{",
"var",
"limit",
"uint32",
"=",
"1000",
"\n",
"var",
"lossCorr",
",",
"delayCorr",
",",
"duplicateCorr",
"uint32",
"\n",
"var",
"reorderProb",
",",
"reorderCorr",
"uint32",
"\n",
"var",
"corruptProb",
",",
"corruptCorr",
"uint32",
"\n",
"latency",
":=",
"nattrs",
".",
"Latency",
"\n",
"loss",
":=",
"Percentage2u32",
"(",
"nattrs",
".",
"Loss",
")",
"\n",
"gap",
":=",
"nattrs",
".",
"Gap",
"\n",
"duplicate",
":=",
"Percentage2u32",
"(",
"nattrs",
".",
"Duplicate",
")",
"\n",
"jitter",
":=",
"nattrs",
".",
"Jitter",
"\n",
"if",
"latency",
">",
"0",
"&&",
"jitter",
">",
"0",
"{",
"delayCorr",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"DelayCorr",
")",
"\n",
"}",
"\n",
"if",
"loss",
">",
"0",
"{",
"lossCorr",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"LossCorr",
")",
"\n",
"}",
"\n",
"if",
"duplicate",
">",
"0",
"{",
"duplicateCorr",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"DuplicateCorr",
")",
"\n",
"}",
"\n",
"latency",
"=",
"time2Tick",
"(",
"latency",
")",
"\n",
"if",
"nattrs",
".",
"Limit",
"!=",
"0",
"{",
"limit",
"=",
"nattrs",
".",
"Limit",
"\n",
"}",
"\n",
"if",
"latency",
">",
"0",
"{",
"jitter",
"=",
"time2Tick",
"(",
"jitter",
")",
"\n",
"}",
"\n",
"reorderProb",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"ReorderProb",
")",
"\n",
"reorderCorr",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"ReorderCorr",
")",
"\n",
"if",
"reorderProb",
">",
"0",
"{",
"if",
"gap",
"==",
"0",
"{",
"gap",
"=",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"corruptProb",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"CorruptProb",
")",
"\n",
"corruptCorr",
"=",
"Percentage2u32",
"(",
"nattrs",
".",
"CorruptCorr",
")",
"\n",
"return",
"&",
"Netem",
"{",
"QdiscAttrs",
":",
"attrs",
",",
"Latency",
":",
"latency",
",",
"DelayCorr",
":",
"delayCorr",
",",
"Limit",
":",
"limit",
",",
"Loss",
":",
"loss",
",",
"LossCorr",
":",
"lossCorr",
",",
"Gap",
":",
"gap",
",",
"Duplicate",
":",
"duplicate",
",",
"DuplicateCorr",
":",
"duplicateCorr",
",",
"Jitter",
":",
"jitter",
",",
"ReorderProb",
":",
"reorderProb",
",",
"ReorderCorr",
":",
"reorderCorr",
",",
"CorruptProb",
":",
"corruptProb",
",",
"CorruptCorr",
":",
"corruptCorr",
",",
"}",
"\n",
"}"
] | // NOTE function is here because it uses other linux functions | [
"NOTE",
"function",
"is",
"here",
"because",
"it",
"uses",
"other",
"linux",
"functions"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/qdisc_linux.go#L15-L77 | train |
vishvananda/netlink | handle_linux.go | SupportsNetlinkFamily | func (h *Handle) SupportsNetlinkFamily(nlFamily int) bool {
_, ok := h.sockets[nlFamily]
return ok
} | go | func (h *Handle) SupportsNetlinkFamily(nlFamily int) bool {
_, ok := h.sockets[nlFamily]
return ok
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"SupportsNetlinkFamily",
"(",
"nlFamily",
"int",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"h",
".",
"sockets",
"[",
"nlFamily",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // SupportsNetlinkFamily reports whether the passed netlink family is supported by this Handle | [
"SupportsNetlinkFamily",
"reports",
"whether",
"the",
"passed",
"netlink",
"family",
"is",
"supported",
"by",
"this",
"Handle"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/handle_linux.go#L25-L28 | train |
vishvananda/netlink | handle_linux.go | NewHandle | func NewHandle(nlFamilies ...int) (*Handle, error) {
return newHandle(netns.None(), netns.None(), nlFamilies...)
} | go | func NewHandle(nlFamilies ...int) (*Handle, error) {
return newHandle(netns.None(), netns.None(), nlFamilies...)
} | [
"func",
"NewHandle",
"(",
"nlFamilies",
"...",
"int",
")",
"(",
"*",
"Handle",
",",
"error",
")",
"{",
"return",
"newHandle",
"(",
"netns",
".",
"None",
"(",
")",
",",
"netns",
".",
"None",
"(",
")",
",",
"nlFamilies",
"...",
")",
"\n",
"}"
] | // NewHandle returns a netlink handle on the current network namespace.
// Caller may specify the netlink families the handle should support.
// If no families are specified, all the families the netlink package
// supports will be automatically added. | [
"NewHandle",
"returns",
"a",
"netlink",
"handle",
"on",
"the",
"current",
"network",
"namespace",
".",
"Caller",
"may",
"specify",
"the",
"netlink",
"families",
"the",
"handle",
"should",
"support",
".",
"If",
"no",
"families",
"are",
"specified",
"all",
"the",
"families",
"the",
"netlink",
"package",
"supports",
"will",
"be",
"automatically",
"added",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/handle_linux.go#L34-L36 | train |
vishvananda/netlink | handle_linux.go | SetSocketTimeout | func (h *Handle) SetSocketTimeout(to time.Duration) error {
if to < time.Microsecond {
return fmt.Errorf("invalid timeout, minimul value is %s", time.Microsecond)
}
tv := unix.NsecToTimeval(to.Nanoseconds())
for _, sh := range h.sockets {
if err := sh.Socket.SetSendTimeout(&tv); err != nil {
return err
}
if err := sh.Socket.SetReceiveTimeout(&tv); err != nil {
return err
}
}
return nil
} | go | func (h *Handle) SetSocketTimeout(to time.Duration) error {
if to < time.Microsecond {
return fmt.Errorf("invalid timeout, minimul value is %s", time.Microsecond)
}
tv := unix.NsecToTimeval(to.Nanoseconds())
for _, sh := range h.sockets {
if err := sh.Socket.SetSendTimeout(&tv); err != nil {
return err
}
if err := sh.Socket.SetReceiveTimeout(&tv); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"SetSocketTimeout",
"(",
"to",
"time",
".",
"Duration",
")",
"error",
"{",
"if",
"to",
"<",
"time",
".",
"Microsecond",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid timeout, minimul value is %s\"",
",",
"time",
".",
"Microsecond",
")",
"\n",
"}",
"\n",
"tv",
":=",
"unix",
".",
"NsecToTimeval",
"(",
"to",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"for",
"_",
",",
"sh",
":=",
"range",
"h",
".",
"sockets",
"{",
"if",
"err",
":=",
"sh",
".",
"Socket",
".",
"SetSendTimeout",
"(",
"&",
"tv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"sh",
".",
"Socket",
".",
"SetReceiveTimeout",
"(",
"&",
"tv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetSocketTimeout sets the send and receive timeout for each socket in the
// netlink handle. Although the socket timeout has granularity of one
// microsecond, the effective granularity is floored by the kernel timer tick,
// which default value is four milliseconds. | [
"SetSocketTimeout",
"sets",
"the",
"send",
"and",
"receive",
"timeout",
"for",
"each",
"socket",
"in",
"the",
"netlink",
"handle",
".",
"Although",
"the",
"socket",
"timeout",
"has",
"granularity",
"of",
"one",
"microsecond",
"the",
"effective",
"granularity",
"is",
"floored",
"by",
"the",
"kernel",
"timer",
"tick",
"which",
"default",
"value",
"is",
"four",
"milliseconds",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/handle_linux.go#L42-L56 | train |
vishvananda/netlink | handle_linux.go | GetSocketReceiveBufferSize | func (h *Handle) GetSocketReceiveBufferSize() ([]int, error) {
results := make([]int, len(h.sockets))
i := 0
for _, sh := range h.sockets {
fd := sh.Socket.GetFd()
size, err := unix.GetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_RCVBUF)
if err != nil {
return nil, err
}
results[i] = size
i++
}
return results, nil
} | go | func (h *Handle) GetSocketReceiveBufferSize() ([]int, error) {
results := make([]int, len(h.sockets))
i := 0
for _, sh := range h.sockets {
fd := sh.Socket.GetFd()
size, err := unix.GetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_RCVBUF)
if err != nil {
return nil, err
}
results[i] = size
i++
}
return results, nil
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"GetSocketReceiveBufferSize",
"(",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"len",
"(",
"h",
".",
"sockets",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"_",
",",
"sh",
":=",
"range",
"h",
".",
"sockets",
"{",
"fd",
":=",
"sh",
".",
"Socket",
".",
"GetFd",
"(",
")",
"\n",
"size",
",",
"err",
":=",
"unix",
".",
"GetsockoptInt",
"(",
"fd",
",",
"unix",
".",
"SOL_SOCKET",
",",
"unix",
".",
"SO_RCVBUF",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
"=",
"size",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // GetSocketReceiveBufferSize gets the receiver buffer size for each
// socket in the netlink handle. The retrieved value should be the
// double to the one set for SetSocketReceiveBufferSize. | [
"GetSocketReceiveBufferSize",
"gets",
"the",
"receiver",
"buffer",
"size",
"for",
"each",
"socket",
"in",
"the",
"netlink",
"handle",
".",
"The",
"retrieved",
"value",
"should",
"be",
"the",
"double",
"to",
"the",
"one",
"set",
"for",
"SetSocketReceiveBufferSize",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/handle_linux.go#L79-L92 | train |
vishvananda/netlink | handle_linux.go | NewHandleAtFrom | func NewHandleAtFrom(newNs, curNs netns.NsHandle) (*Handle, error) {
return newHandle(newNs, curNs)
} | go | func NewHandleAtFrom(newNs, curNs netns.NsHandle) (*Handle, error) {
return newHandle(newNs, curNs)
} | [
"func",
"NewHandleAtFrom",
"(",
"newNs",
",",
"curNs",
"netns",
".",
"NsHandle",
")",
"(",
"*",
"Handle",
",",
"error",
")",
"{",
"return",
"newHandle",
"(",
"newNs",
",",
"curNs",
")",
"\n",
"}"
] | // NewHandleAtFrom works as NewHandle but allows client to specify the
// new and the origin netns Handle. | [
"NewHandleAtFrom",
"works",
"as",
"NewHandle",
"but",
"allows",
"client",
"to",
"specify",
"the",
"new",
"and",
"the",
"origin",
"netns",
"Handle",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/handle_linux.go#L103-L105 | train |
vishvananda/netlink | handle_linux.go | Delete | func (h *Handle) Delete() {
for _, sh := range h.sockets {
sh.Close()
}
h.sockets = nil
} | go | func (h *Handle) Delete() {
for _, sh := range h.sockets {
sh.Close()
}
h.sockets = nil
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"Delete",
"(",
")",
"{",
"for",
"_",
",",
"sh",
":=",
"range",
"h",
".",
"sockets",
"{",
"sh",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"h",
".",
"sockets",
"=",
"nil",
"\n",
"}"
] | // Delete releases the resources allocated to this handle | [
"Delete",
"releases",
"the",
"resources",
"allocated",
"to",
"this",
"handle"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/handle_linux.go#L124-L129 | train |
kubernetes-incubator/external-storage | snapshot/pkg/controller/cache/util.go | MakeSnapshotName | func MakeSnapshotName(snapshot *crdv1.VolumeSnapshot) string {
return snapshot.Metadata.Namespace + "/" + snapshot.Metadata.Name + "-" + string(snapshot.Metadata.UID)
} | go | func MakeSnapshotName(snapshot *crdv1.VolumeSnapshot) string {
return snapshot.Metadata.Namespace + "/" + snapshot.Metadata.Name + "-" + string(snapshot.Metadata.UID)
} | [
"func",
"MakeSnapshotName",
"(",
"snapshot",
"*",
"crdv1",
".",
"VolumeSnapshot",
")",
"string",
"{",
"return",
"snapshot",
".",
"Metadata",
".",
"Namespace",
"+",
"\"/\"",
"+",
"snapshot",
".",
"Metadata",
".",
"Name",
"+",
"\"-\"",
"+",
"string",
"(",
"snapshot",
".",
"Metadata",
".",
"UID",
")",
"\n",
"}"
] | // MakeSnapshotName makes a full name for a snapshot that includes
// the namespace and the short name | [
"MakeSnapshotName",
"makes",
"a",
"full",
"name",
"for",
"a",
"snapshot",
"that",
"includes",
"the",
"namespace",
"and",
"the",
"short",
"name"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/controller/cache/util.go#L30-L32 | train |
kubernetes-incubator/external-storage | gluster/glusterfs/pkg/volume/config.go | NewProvisionerConfig | func NewProvisionerConfig(pvName string, params map[string]string) (*ProvisionerConfig, error) {
var config ProvisionerConfig
var err error
// Set default volume type
forceCreate := false
volumeType := ""
namespace := "default"
selector := "glusterfs-node==pod"
var brickRootPaths []BrickRootPath
for k, v := range params {
switch strings.ToLower(k) {
case "brickrootpaths":
brickRootPaths, err = parseBrickRootPaths(v)
if err != nil {
return nil, err
}
case "volumetype":
volumeType = strings.TrimSpace(v)
case "namespace":
namespace = strings.TrimSpace(v)
case "selector":
selector = strings.TrimSpace(v)
case "forcecreate":
v = strings.TrimSpace(v)
forceCreate = strings.ToLower(v) == "true"
}
}
config.BrickRootPaths = brickRootPaths
config.VolumeName = pvName
config.VolumeType = volumeType
config.Namespace = namespace
config.LabelSelector = selector
config.ForceCreate = forceCreate
err = config.validate()
if err != nil {
return nil, err
}
return &config, nil
} | go | func NewProvisionerConfig(pvName string, params map[string]string) (*ProvisionerConfig, error) {
var config ProvisionerConfig
var err error
// Set default volume type
forceCreate := false
volumeType := ""
namespace := "default"
selector := "glusterfs-node==pod"
var brickRootPaths []BrickRootPath
for k, v := range params {
switch strings.ToLower(k) {
case "brickrootpaths":
brickRootPaths, err = parseBrickRootPaths(v)
if err != nil {
return nil, err
}
case "volumetype":
volumeType = strings.TrimSpace(v)
case "namespace":
namespace = strings.TrimSpace(v)
case "selector":
selector = strings.TrimSpace(v)
case "forcecreate":
v = strings.TrimSpace(v)
forceCreate = strings.ToLower(v) == "true"
}
}
config.BrickRootPaths = brickRootPaths
config.VolumeName = pvName
config.VolumeType = volumeType
config.Namespace = namespace
config.LabelSelector = selector
config.ForceCreate = forceCreate
err = config.validate()
if err != nil {
return nil, err
}
return &config, nil
} | [
"func",
"NewProvisionerConfig",
"(",
"pvName",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"ProvisionerConfig",
",",
"error",
")",
"{",
"var",
"config",
"ProvisionerConfig",
"\n",
"var",
"err",
"error",
"\n",
"forceCreate",
":=",
"false",
"\n",
"volumeType",
":=",
"\"\"",
"\n",
"namespace",
":=",
"\"default\"",
"\n",
"selector",
":=",
"\"glusterfs-node==pod\"",
"\n",
"var",
"brickRootPaths",
"[",
"]",
"BrickRootPath",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"params",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"k",
")",
"{",
"case",
"\"brickrootpaths\"",
":",
"brickRootPaths",
",",
"err",
"=",
"parseBrickRootPaths",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"case",
"\"volumetype\"",
":",
"volumeType",
"=",
"strings",
".",
"TrimSpace",
"(",
"v",
")",
"\n",
"case",
"\"namespace\"",
":",
"namespace",
"=",
"strings",
".",
"TrimSpace",
"(",
"v",
")",
"\n",
"case",
"\"selector\"",
":",
"selector",
"=",
"strings",
".",
"TrimSpace",
"(",
"v",
")",
"\n",
"case",
"\"forcecreate\"",
":",
"v",
"=",
"strings",
".",
"TrimSpace",
"(",
"v",
")",
"\n",
"forceCreate",
"=",
"strings",
".",
"ToLower",
"(",
"v",
")",
"==",
"\"true\"",
"\n",
"}",
"\n",
"}",
"\n",
"config",
".",
"BrickRootPaths",
"=",
"brickRootPaths",
"\n",
"config",
".",
"VolumeName",
"=",
"pvName",
"\n",
"config",
".",
"VolumeType",
"=",
"volumeType",
"\n",
"config",
".",
"Namespace",
"=",
"namespace",
"\n",
"config",
".",
"LabelSelector",
"=",
"selector",
"\n",
"config",
".",
"ForceCreate",
"=",
"forceCreate",
"\n",
"err",
"=",
"config",
".",
"validate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"config",
",",
"nil",
"\n",
"}"
] | // NewProvisionerConfig create ProvisionerConfig from parameters of StorageClass | [
"NewProvisionerConfig",
"create",
"ProvisionerConfig",
"from",
"parameters",
"of",
"StorageClass"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/gluster/glusterfs/pkg/volume/config.go#L41-L84 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/export.go | Export | func (e *ganeshaExporter) Export(path string) error {
// Call AddExport using dbus
conn, err := dbus.SystemBus()
if err != nil {
return fmt.Errorf("error getting dbus session bus: %v", err)
}
obj := conn.Object("org.ganesha.nfsd", "/org/ganesha/nfsd/ExportMgr")
call := obj.Call("org.ganesha.nfsd.exportmgr.AddExport", 0, e.config, fmt.Sprintf("export(path = %s)", path))
if call.Err != nil {
return fmt.Errorf("error calling org.ganesha.nfsd.exportmgr.AddExport: %v", call.Err)
}
return nil
} | go | func (e *ganeshaExporter) Export(path string) error {
// Call AddExport using dbus
conn, err := dbus.SystemBus()
if err != nil {
return fmt.Errorf("error getting dbus session bus: %v", err)
}
obj := conn.Object("org.ganesha.nfsd", "/org/ganesha/nfsd/ExportMgr")
call := obj.Call("org.ganesha.nfsd.exportmgr.AddExport", 0, e.config, fmt.Sprintf("export(path = %s)", path))
if call.Err != nil {
return fmt.Errorf("error calling org.ganesha.nfsd.exportmgr.AddExport: %v", call.Err)
}
return nil
} | [
"func",
"(",
"e",
"*",
"ganeshaExporter",
")",
"Export",
"(",
"path",
"string",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"dbus",
".",
"SystemBus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"error getting dbus session bus: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"obj",
":=",
"conn",
".",
"Object",
"(",
"\"org.ganesha.nfsd\"",
",",
"\"/org/ganesha/nfsd/ExportMgr\"",
")",
"\n",
"call",
":=",
"obj",
".",
"Call",
"(",
"\"org.ganesha.nfsd.exportmgr.AddExport\"",
",",
"0",
",",
"e",
".",
"config",
",",
"fmt",
".",
"Sprintf",
"(",
"\"export(path = %s)\"",
",",
"path",
")",
")",
"\n",
"if",
"call",
".",
"Err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"error calling org.ganesha.nfsd.exportmgr.AddExport: %v\"",
",",
"call",
".",
"Err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Export exports the given directory using NFS Ganesha, assuming it is running
// and can be connected to using D-Bus. | [
"Export",
"exports",
"the",
"given",
"directory",
"using",
"NFS",
"Ganesha",
"assuming",
"it",
"is",
"running",
"and",
"can",
"be",
"connected",
"to",
"using",
"D",
"-",
"Bus",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/export.go#L123-L136 | train |
kubernetes-incubator/external-storage | snapshot/pkg/controller/reconciler/reconciler.go | NewReconciler | func NewReconciler(
loopPeriod time.Duration,
syncDuration time.Duration,
disableReconciliationSync bool,
desiredStateOfWorld cache.DesiredStateOfWorld,
actualStateOfWorld cache.ActualStateOfWorld,
snapshotter snapshotter.VolumeSnapshotter) Reconciler {
return &reconciler{
loopPeriod: loopPeriod,
syncDuration: syncDuration,
disableReconciliationSync: disableReconciliationSync,
desiredStateOfWorld: desiredStateOfWorld,
actualStateOfWorld: actualStateOfWorld,
snapshotter: snapshotter,
timeOfLastSync: time.Now(),
}
} | go | func NewReconciler(
loopPeriod time.Duration,
syncDuration time.Duration,
disableReconciliationSync bool,
desiredStateOfWorld cache.DesiredStateOfWorld,
actualStateOfWorld cache.ActualStateOfWorld,
snapshotter snapshotter.VolumeSnapshotter) Reconciler {
return &reconciler{
loopPeriod: loopPeriod,
syncDuration: syncDuration,
disableReconciliationSync: disableReconciliationSync,
desiredStateOfWorld: desiredStateOfWorld,
actualStateOfWorld: actualStateOfWorld,
snapshotter: snapshotter,
timeOfLastSync: time.Now(),
}
} | [
"func",
"NewReconciler",
"(",
"loopPeriod",
"time",
".",
"Duration",
",",
"syncDuration",
"time",
".",
"Duration",
",",
"disableReconciliationSync",
"bool",
",",
"desiredStateOfWorld",
"cache",
".",
"DesiredStateOfWorld",
",",
"actualStateOfWorld",
"cache",
".",
"ActualStateOfWorld",
",",
"snapshotter",
"snapshotter",
".",
"VolumeSnapshotter",
")",
"Reconciler",
"{",
"return",
"&",
"reconciler",
"{",
"loopPeriod",
":",
"loopPeriod",
",",
"syncDuration",
":",
"syncDuration",
",",
"disableReconciliationSync",
":",
"disableReconciliationSync",
",",
"desiredStateOfWorld",
":",
"desiredStateOfWorld",
",",
"actualStateOfWorld",
":",
"actualStateOfWorld",
",",
"snapshotter",
":",
"snapshotter",
",",
"timeOfLastSync",
":",
"time",
".",
"Now",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewReconciler is the constructor of Reconciler | [
"NewReconciler",
"is",
"the",
"constructor",
"of",
"Reconciler"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/controller/reconciler/reconciler.go#L52-L68 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/aws/retry_handler.go | AfterRetry | func (c *CrossRequestRetryDelay) AfterRetry(r *request.Request) {
if r.Error == nil {
return
}
awsError, ok := r.Error.(awserr.Error)
if !ok {
return
}
if awsError.Code() == "RequestLimitExceeded" {
c.backoff.ReportError()
glog.Warningf("Got RequestLimitExceeded error on AWS request (%s)",
describeRequest(r))
}
} | go | func (c *CrossRequestRetryDelay) AfterRetry(r *request.Request) {
if r.Error == nil {
return
}
awsError, ok := r.Error.(awserr.Error)
if !ok {
return
}
if awsError.Code() == "RequestLimitExceeded" {
c.backoff.ReportError()
glog.Warningf("Got RequestLimitExceeded error on AWS request (%s)",
describeRequest(r))
}
} | [
"func",
"(",
"c",
"*",
"CrossRequestRetryDelay",
")",
"AfterRetry",
"(",
"r",
"*",
"request",
".",
"Request",
")",
"{",
"if",
"r",
".",
"Error",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"awsError",
",",
"ok",
":=",
"r",
".",
"Error",
".",
"(",
"awserr",
".",
"Error",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"if",
"awsError",
".",
"Code",
"(",
")",
"==",
"\"RequestLimitExceeded\"",
"{",
"c",
".",
"backoff",
".",
"ReportError",
"(",
")",
"\n",
"glog",
".",
"Warningf",
"(",
"\"Got RequestLimitExceeded error on AWS request (%s)\"",
",",
"describeRequest",
"(",
"r",
")",
")",
"\n",
"}",
"\n",
"}"
] | // AfterRetry is added to the AfterRetry chain; called after any error | [
"AfterRetry",
"is",
"added",
"to",
"the",
"AfterRetry",
"chain",
";",
"called",
"after",
"any",
"error"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/aws/retry_handler.go#L76-L89 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | Init | func (c *cinderPlugin) Init(cloud cloudprovider.Interface) {
c.cloud = cloud.(*openstack.OpenStack)
} | go | func (c *cinderPlugin) Init(cloud cloudprovider.Interface) {
c.cloud = cloud.(*openstack.OpenStack)
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"Init",
"(",
"cloud",
"cloudprovider",
".",
"Interface",
")",
"{",
"c",
".",
"cloud",
"=",
"cloud",
".",
"(",
"*",
"openstack",
".",
"OpenStack",
")",
"\n",
"}"
] | // Init inits volume plugin | [
"Init",
"inits",
"volume",
"plugin"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L43-L45 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | VolumeDelete | func (c *cinderPlugin) VolumeDelete(pv *v1.PersistentVolume) error {
if pv == nil || pv.Spec.Cinder == nil {
return fmt.Errorf("invalid Cinder PV: %v", pv)
}
volumeID := pv.Spec.Cinder.VolumeID
err := c.cloud.DeleteVolume(volumeID)
if err != nil {
return err
}
return nil
} | go | func (c *cinderPlugin) VolumeDelete(pv *v1.PersistentVolume) error {
if pv == nil || pv.Spec.Cinder == nil {
return fmt.Errorf("invalid Cinder PV: %v", pv)
}
volumeID := pv.Spec.Cinder.VolumeID
err := c.cloud.DeleteVolume(volumeID)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"VolumeDelete",
"(",
"pv",
"*",
"v1",
".",
"PersistentVolume",
")",
"error",
"{",
"if",
"pv",
"==",
"nil",
"||",
"pv",
".",
"Spec",
".",
"Cinder",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid Cinder PV: %v\"",
",",
"pv",
")",
"\n",
"}",
"\n",
"volumeID",
":=",
"pv",
".",
"Spec",
".",
"Cinder",
".",
"VolumeID",
"\n",
"err",
":=",
"c",
".",
"cloud",
".",
"DeleteVolume",
"(",
"volumeID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // VolumeDelete deletes the specified volume passed on pv | [
"VolumeDelete",
"deletes",
"the",
"specified",
"volume",
"passed",
"on",
"pv"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L58-L69 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | SnapshotCreate | func (c *cinderPlugin) SnapshotCreate(
snapshot *crdv1.VolumeSnapshot,
pv *v1.PersistentVolume,
tags *map[string]string,
) (*crdv1.VolumeSnapshotDataSource, *[]crdv1.VolumeSnapshotCondition, error) {
spec := &pv.Spec
if spec == nil || spec.Cinder == nil {
return nil, nil, fmt.Errorf("invalid PV spec %v", spec)
}
volumeID := spec.Cinder.VolumeID
snapshotName := string(pv.Name) + fmt.Sprintf("%d", time.Now().UnixNano())
snapshotDescription := "kubernetes snapshot"
glog.Infof("issuing Cinder.CreateSnapshot - SourceVol: %s, Name: %s, tags: %#v", volumeID, snapshotName, *tags)
snapID, status, err := c.cloud.CreateSnapshot(volumeID, snapshotName, snapshotDescription, *tags)
if err != nil {
return nil, nil, err
}
return &crdv1.VolumeSnapshotDataSource{
CinderSnapshot: &crdv1.CinderVolumeSnapshotSource{
SnapshotID: snapID,
},
}, c.convertSnapshotStatus(status), nil
} | go | func (c *cinderPlugin) SnapshotCreate(
snapshot *crdv1.VolumeSnapshot,
pv *v1.PersistentVolume,
tags *map[string]string,
) (*crdv1.VolumeSnapshotDataSource, *[]crdv1.VolumeSnapshotCondition, error) {
spec := &pv.Spec
if spec == nil || spec.Cinder == nil {
return nil, nil, fmt.Errorf("invalid PV spec %v", spec)
}
volumeID := spec.Cinder.VolumeID
snapshotName := string(pv.Name) + fmt.Sprintf("%d", time.Now().UnixNano())
snapshotDescription := "kubernetes snapshot"
glog.Infof("issuing Cinder.CreateSnapshot - SourceVol: %s, Name: %s, tags: %#v", volumeID, snapshotName, *tags)
snapID, status, err := c.cloud.CreateSnapshot(volumeID, snapshotName, snapshotDescription, *tags)
if err != nil {
return nil, nil, err
}
return &crdv1.VolumeSnapshotDataSource{
CinderSnapshot: &crdv1.CinderVolumeSnapshotSource{
SnapshotID: snapID,
},
}, c.convertSnapshotStatus(status), nil
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"SnapshotCreate",
"(",
"snapshot",
"*",
"crdv1",
".",
"VolumeSnapshot",
",",
"pv",
"*",
"v1",
".",
"PersistentVolume",
",",
"tags",
"*",
"map",
"[",
"string",
"]",
"string",
",",
")",
"(",
"*",
"crdv1",
".",
"VolumeSnapshotDataSource",
",",
"*",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
",",
"error",
")",
"{",
"spec",
":=",
"&",
"pv",
".",
"Spec",
"\n",
"if",
"spec",
"==",
"nil",
"||",
"spec",
".",
"Cinder",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid PV spec %v\"",
",",
"spec",
")",
"\n",
"}",
"\n",
"volumeID",
":=",
"spec",
".",
"Cinder",
".",
"VolumeID",
"\n",
"snapshotName",
":=",
"string",
"(",
"pv",
".",
"Name",
")",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"%d\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
"\n",
"snapshotDescription",
":=",
"\"kubernetes snapshot\"",
"\n",
"glog",
".",
"Infof",
"(",
"\"issuing Cinder.CreateSnapshot - SourceVol: %s, Name: %s, tags: %#v\"",
",",
"volumeID",
",",
"snapshotName",
",",
"*",
"tags",
")",
"\n",
"snapID",
",",
"status",
",",
"err",
":=",
"c",
".",
"cloud",
".",
"CreateSnapshot",
"(",
"volumeID",
",",
"snapshotName",
",",
"snapshotDescription",
",",
"*",
"tags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"crdv1",
".",
"VolumeSnapshotDataSource",
"{",
"CinderSnapshot",
":",
"&",
"crdv1",
".",
"CinderVolumeSnapshotSource",
"{",
"SnapshotID",
":",
"snapID",
",",
"}",
",",
"}",
",",
"c",
".",
"convertSnapshotStatus",
"(",
"status",
")",
",",
"nil",
"\n",
"}"
] | // SnapshotCreate creates a VolumeSnapshot from a PersistentVolumeSpec | [
"SnapshotCreate",
"creates",
"a",
"VolumeSnapshot",
"from",
"a",
"PersistentVolumeSpec"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L72-L95 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | SnapshotDelete | func (c *cinderPlugin) SnapshotDelete(src *crdv1.VolumeSnapshotDataSource, _ *v1.PersistentVolume) error {
if src == nil || src.CinderSnapshot == nil {
return fmt.Errorf("invalid VolumeSnapshotDataSource: %v", src)
}
snapshotID := src.CinderSnapshot.SnapshotID
err := c.cloud.DeleteSnapshot(snapshotID)
if err != nil {
return err
}
return nil
} | go | func (c *cinderPlugin) SnapshotDelete(src *crdv1.VolumeSnapshotDataSource, _ *v1.PersistentVolume) error {
if src == nil || src.CinderSnapshot == nil {
return fmt.Errorf("invalid VolumeSnapshotDataSource: %v", src)
}
snapshotID := src.CinderSnapshot.SnapshotID
err := c.cloud.DeleteSnapshot(snapshotID)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"SnapshotDelete",
"(",
"src",
"*",
"crdv1",
".",
"VolumeSnapshotDataSource",
",",
"_",
"*",
"v1",
".",
"PersistentVolume",
")",
"error",
"{",
"if",
"src",
"==",
"nil",
"||",
"src",
".",
"CinderSnapshot",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid VolumeSnapshotDataSource: %v\"",
",",
"src",
")",
"\n",
"}",
"\n",
"snapshotID",
":=",
"src",
".",
"CinderSnapshot",
".",
"SnapshotID",
"\n",
"err",
":=",
"c",
".",
"cloud",
".",
"DeleteSnapshot",
"(",
"snapshotID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SnapshotDelete deletes a VolumeSnapshot
// PersistentVolume is provided for volume types, if any, that need PV Spec to delete snapshot | [
"SnapshotDelete",
"deletes",
"a",
"VolumeSnapshot",
"PersistentVolume",
"is",
"provided",
"for",
"volume",
"types",
"if",
"any",
"that",
"need",
"PV",
"Spec",
"to",
"delete",
"snapshot"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L99-L109 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | SnapshotRestore | func (c *cinderPlugin) SnapshotRestore(snapshotData *crdv1.VolumeSnapshotData, pvc *v1.PersistentVolumeClaim, pvName string, parameters map[string]string) (*v1.PersistentVolumeSource, map[string]string, error) {
var tags = make(map[string]string)
var vType string
var zone string
if snapshotData == nil || snapshotData.Spec.CinderSnapshot == nil {
return nil, nil, fmt.Errorf("failed to retrieve Snapshot spec")
}
if pvc == nil {
return nil, nil, fmt.Errorf("no pvc specified")
}
snapID := snapshotData.Spec.CinderSnapshot.SnapshotID
volName := pvName
capacity := pvc.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
requestedSz := capacity.Value()
szGB := k8sVol.RoundUpSize(requestedSz, 1024*1024*1024)
for k, v := range parameters {
switch strings.ToLower(k) {
case "type":
vType = v
case "zone":
zone = v
default:
return nil, nil, fmt.Errorf("invalid option %q for volume plugin %s", k, GetPluginName())
}
}
// FIXME(j-griffith): Should probably use int64 in gophercloud?
volumeID, _, err := c.cloud.CreateVolume(volName, int(szGB), vType, zone, snapID, &tags)
if err != nil {
glog.Errorf("error create volume from snapshot: %v", err)
return nil, nil, err
}
glog.V(2).Infof("Successfully created Cinder Volume from Snapshot, Volume: %s", volumeID)
pv := &v1.PersistentVolumeSource{
Cinder: &v1.CinderPersistentVolumeSource{
VolumeID: volumeID,
FSType: "ext4",
ReadOnly: false,
},
}
return pv, nil, nil
} | go | func (c *cinderPlugin) SnapshotRestore(snapshotData *crdv1.VolumeSnapshotData, pvc *v1.PersistentVolumeClaim, pvName string, parameters map[string]string) (*v1.PersistentVolumeSource, map[string]string, error) {
var tags = make(map[string]string)
var vType string
var zone string
if snapshotData == nil || snapshotData.Spec.CinderSnapshot == nil {
return nil, nil, fmt.Errorf("failed to retrieve Snapshot spec")
}
if pvc == nil {
return nil, nil, fmt.Errorf("no pvc specified")
}
snapID := snapshotData.Spec.CinderSnapshot.SnapshotID
volName := pvName
capacity := pvc.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
requestedSz := capacity.Value()
szGB := k8sVol.RoundUpSize(requestedSz, 1024*1024*1024)
for k, v := range parameters {
switch strings.ToLower(k) {
case "type":
vType = v
case "zone":
zone = v
default:
return nil, nil, fmt.Errorf("invalid option %q for volume plugin %s", k, GetPluginName())
}
}
// FIXME(j-griffith): Should probably use int64 in gophercloud?
volumeID, _, err := c.cloud.CreateVolume(volName, int(szGB), vType, zone, snapID, &tags)
if err != nil {
glog.Errorf("error create volume from snapshot: %v", err)
return nil, nil, err
}
glog.V(2).Infof("Successfully created Cinder Volume from Snapshot, Volume: %s", volumeID)
pv := &v1.PersistentVolumeSource{
Cinder: &v1.CinderPersistentVolumeSource{
VolumeID: volumeID,
FSType: "ext4",
ReadOnly: false,
},
}
return pv, nil, nil
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"SnapshotRestore",
"(",
"snapshotData",
"*",
"crdv1",
".",
"VolumeSnapshotData",
",",
"pvc",
"*",
"v1",
".",
"PersistentVolumeClaim",
",",
"pvName",
"string",
",",
"parameters",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"v1",
".",
"PersistentVolumeSource",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"tags",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"var",
"vType",
"string",
"\n",
"var",
"zone",
"string",
"\n",
"if",
"snapshotData",
"==",
"nil",
"||",
"snapshotData",
".",
"Spec",
".",
"CinderSnapshot",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to retrieve Snapshot spec\"",
")",
"\n",
"}",
"\n",
"if",
"pvc",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"no pvc specified\"",
")",
"\n",
"}",
"\n",
"snapID",
":=",
"snapshotData",
".",
"Spec",
".",
"CinderSnapshot",
".",
"SnapshotID",
"\n",
"volName",
":=",
"pvName",
"\n",
"capacity",
":=",
"pvc",
".",
"Spec",
".",
"Resources",
".",
"Requests",
"[",
"v1",
".",
"ResourceName",
"(",
"v1",
".",
"ResourceStorage",
")",
"]",
"\n",
"requestedSz",
":=",
"capacity",
".",
"Value",
"(",
")",
"\n",
"szGB",
":=",
"k8sVol",
".",
"RoundUpSize",
"(",
"requestedSz",
",",
"1024",
"*",
"1024",
"*",
"1024",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"parameters",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"k",
")",
"{",
"case",
"\"type\"",
":",
"vType",
"=",
"v",
"\n",
"case",
"\"zone\"",
":",
"zone",
"=",
"v",
"\n",
"default",
":",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid option %q for volume plugin %s\"",
",",
"k",
",",
"GetPluginName",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"volumeID",
",",
"_",
",",
"err",
":=",
"c",
".",
"cloud",
".",
"CreateVolume",
"(",
"volName",
",",
"int",
"(",
"szGB",
")",
",",
"vType",
",",
"zone",
",",
"snapID",
",",
"&",
"tags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Errorf",
"(",
"\"error create volume from snapshot: %v\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"Successfully created Cinder Volume from Snapshot, Volume: %s\"",
",",
"volumeID",
")",
"\n",
"pv",
":=",
"&",
"v1",
".",
"PersistentVolumeSource",
"{",
"Cinder",
":",
"&",
"v1",
".",
"CinderPersistentVolumeSource",
"{",
"VolumeID",
":",
"volumeID",
",",
"FSType",
":",
"\"ext4\"",
",",
"ReadOnly",
":",
"false",
",",
"}",
",",
"}",
"\n",
"return",
"pv",
",",
"nil",
",",
"nil",
"\n",
"}"
] | // SnapshotRestore creates a new Volume using the data on the specified Snapshot | [
"SnapshotRestore",
"creates",
"a",
"new",
"Volume",
"using",
"the",
"data",
"on",
"the",
"specified",
"Snapshot"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L112-L155 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | DescribeSnapshot | func (c *cinderPlugin) DescribeSnapshot(snapshotData *crdv1.VolumeSnapshotData) (*[]crdv1.VolumeSnapshotCondition, bool, error) {
if snapshotData == nil || snapshotData.Spec.CinderSnapshot == nil {
return nil, false, fmt.Errorf("invalid VolumeSnapshotDataSource: %v", snapshotData)
}
snapshotID := snapshotData.Spec.CinderSnapshot.SnapshotID
status, isComplete, err := c.cloud.DescribeSnapshot(snapshotID)
glog.Infof("DescribeSnapshot: Snapshot %s, Status %s, isComplete: %v", snapshotID, status, isComplete)
if err != nil {
return c.convertSnapshotStatus(status), false, err
}
return c.convertSnapshotStatus(status), isComplete, nil
} | go | func (c *cinderPlugin) DescribeSnapshot(snapshotData *crdv1.VolumeSnapshotData) (*[]crdv1.VolumeSnapshotCondition, bool, error) {
if snapshotData == nil || snapshotData.Spec.CinderSnapshot == nil {
return nil, false, fmt.Errorf("invalid VolumeSnapshotDataSource: %v", snapshotData)
}
snapshotID := snapshotData.Spec.CinderSnapshot.SnapshotID
status, isComplete, err := c.cloud.DescribeSnapshot(snapshotID)
glog.Infof("DescribeSnapshot: Snapshot %s, Status %s, isComplete: %v", snapshotID, status, isComplete)
if err != nil {
return c.convertSnapshotStatus(status), false, err
}
return c.convertSnapshotStatus(status), isComplete, nil
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"DescribeSnapshot",
"(",
"snapshotData",
"*",
"crdv1",
".",
"VolumeSnapshotData",
")",
"(",
"*",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
",",
"bool",
",",
"error",
")",
"{",
"if",
"snapshotData",
"==",
"nil",
"||",
"snapshotData",
".",
"Spec",
".",
"CinderSnapshot",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid VolumeSnapshotDataSource: %v\"",
",",
"snapshotData",
")",
"\n",
"}",
"\n",
"snapshotID",
":=",
"snapshotData",
".",
"Spec",
".",
"CinderSnapshot",
".",
"SnapshotID",
"\n",
"status",
",",
"isComplete",
",",
"err",
":=",
"c",
".",
"cloud",
".",
"DescribeSnapshot",
"(",
"snapshotID",
")",
"\n",
"glog",
".",
"Infof",
"(",
"\"DescribeSnapshot: Snapshot %s, Status %s, isComplete: %v\"",
",",
"snapshotID",
",",
"status",
",",
"isComplete",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"c",
".",
"convertSnapshotStatus",
"(",
"status",
")",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"convertSnapshotStatus",
"(",
"status",
")",
",",
"isComplete",
",",
"nil",
"\n",
"}"
] | // DescribeSnapshot retrieves info for the specified Snapshot | [
"DescribeSnapshot",
"retrieves",
"info",
"for",
"the",
"specified",
"Snapshot"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L158-L169 | train |
kubernetes-incubator/external-storage | snapshot/pkg/volume/cinder/processor.go | convertSnapshotStatus | func (c *cinderPlugin) convertSnapshotStatus(status string) *[]crdv1.VolumeSnapshotCondition {
var snapConditions []crdv1.VolumeSnapshotCondition
if status == "available" {
snapConditions = []crdv1.VolumeSnapshotCondition{
{
Type: crdv1.VolumeSnapshotConditionReady,
Status: v1.ConditionTrue,
Message: "Snapshot created successfully and it is ready",
LastTransitionTime: metav1.Now(),
},
}
} else if status == "creating" {
snapConditions = []crdv1.VolumeSnapshotCondition{
{
Type: crdv1.VolumeSnapshotConditionPending,
Status: v1.ConditionUnknown,
Message: "Snapshot is being created",
LastTransitionTime: metav1.Now(),
},
}
} else {
snapConditions = []crdv1.VolumeSnapshotCondition{
{
Type: crdv1.VolumeSnapshotConditionError,
Status: v1.ConditionTrue,
Message: "Snapshot creation failed",
LastTransitionTime: metav1.Now(),
},
}
}
return &snapConditions
} | go | func (c *cinderPlugin) convertSnapshotStatus(status string) *[]crdv1.VolumeSnapshotCondition {
var snapConditions []crdv1.VolumeSnapshotCondition
if status == "available" {
snapConditions = []crdv1.VolumeSnapshotCondition{
{
Type: crdv1.VolumeSnapshotConditionReady,
Status: v1.ConditionTrue,
Message: "Snapshot created successfully and it is ready",
LastTransitionTime: metav1.Now(),
},
}
} else if status == "creating" {
snapConditions = []crdv1.VolumeSnapshotCondition{
{
Type: crdv1.VolumeSnapshotConditionPending,
Status: v1.ConditionUnknown,
Message: "Snapshot is being created",
LastTransitionTime: metav1.Now(),
},
}
} else {
snapConditions = []crdv1.VolumeSnapshotCondition{
{
Type: crdv1.VolumeSnapshotConditionError,
Status: v1.ConditionTrue,
Message: "Snapshot creation failed",
LastTransitionTime: metav1.Now(),
},
}
}
return &snapConditions
} | [
"func",
"(",
"c",
"*",
"cinderPlugin",
")",
"convertSnapshotStatus",
"(",
"status",
"string",
")",
"*",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
"{",
"var",
"snapConditions",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
"\n",
"if",
"status",
"==",
"\"available\"",
"{",
"snapConditions",
"=",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
"{",
"{",
"Type",
":",
"crdv1",
".",
"VolumeSnapshotConditionReady",
",",
"Status",
":",
"v1",
".",
"ConditionTrue",
",",
"Message",
":",
"\"Snapshot created successfully and it is ready\"",
",",
"LastTransitionTime",
":",
"metav1",
".",
"Now",
"(",
")",
",",
"}",
",",
"}",
"\n",
"}",
"else",
"if",
"status",
"==",
"\"creating\"",
"{",
"snapConditions",
"=",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
"{",
"{",
"Type",
":",
"crdv1",
".",
"VolumeSnapshotConditionPending",
",",
"Status",
":",
"v1",
".",
"ConditionUnknown",
",",
"Message",
":",
"\"Snapshot is being created\"",
",",
"LastTransitionTime",
":",
"metav1",
".",
"Now",
"(",
")",
",",
"}",
",",
"}",
"\n",
"}",
"else",
"{",
"snapConditions",
"=",
"[",
"]",
"crdv1",
".",
"VolumeSnapshotCondition",
"{",
"{",
"Type",
":",
"crdv1",
".",
"VolumeSnapshotConditionError",
",",
"Status",
":",
"v1",
".",
"ConditionTrue",
",",
"Message",
":",
"\"Snapshot creation failed\"",
",",
"LastTransitionTime",
":",
"metav1",
".",
"Now",
"(",
")",
",",
"}",
",",
"}",
"\n",
"}",
"\n",
"return",
"&",
"snapConditions",
"\n",
"}"
] | // convertSnapshotStatus converts Cinder snapshot status to crdv1.VolumeSnapshotCondition | [
"convertSnapshotStatus",
"converts",
"Cinder",
"snapshot",
"status",
"to",
"crdv1",
".",
"VolumeSnapshotCondition"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/volume/cinder/processor.go#L172-L204 | train |
kubernetes-incubator/external-storage | repo-infra/kazel/diff.go | Diff | func Diff(left, right []byte) error {
lf, err := ioutil.TempFile("/tmp", "actual-file-")
if err != nil {
return err
}
defer lf.Close()
defer os.Remove(lf.Name())
rf, err := ioutil.TempFile("/tmp", "expected-file-")
if err != nil {
return err
}
defer rf.Close()
defer os.Remove(rf.Name())
_, err = lf.Write(left)
if err != nil {
return err
}
lf.Close()
_, err = rf.Write(right)
if err != nil {
return err
}
rf.Close()
cmd := exec.Command("/usr/bin/diff", "-u", lf.Name(), rf.Name())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
return nil
} | go | func Diff(left, right []byte) error {
lf, err := ioutil.TempFile("/tmp", "actual-file-")
if err != nil {
return err
}
defer lf.Close()
defer os.Remove(lf.Name())
rf, err := ioutil.TempFile("/tmp", "expected-file-")
if err != nil {
return err
}
defer rf.Close()
defer os.Remove(rf.Name())
_, err = lf.Write(left)
if err != nil {
return err
}
lf.Close()
_, err = rf.Write(right)
if err != nil {
return err
}
rf.Close()
cmd := exec.Command("/usr/bin/diff", "-u", lf.Name(), rf.Name())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
return nil
} | [
"func",
"Diff",
"(",
"left",
",",
"right",
"[",
"]",
"byte",
")",
"error",
"{",
"lf",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"/tmp\"",
",",
"\"actual-file-\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"lf",
".",
"Close",
"(",
")",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"lf",
".",
"Name",
"(",
")",
")",
"\n",
"rf",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"/tmp\"",
",",
"\"expected-file-\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"rf",
".",
"Close",
"(",
")",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"rf",
".",
"Name",
"(",
")",
")",
"\n",
"_",
",",
"err",
"=",
"lf",
".",
"Write",
"(",
"left",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"lf",
".",
"Close",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"rf",
".",
"Write",
"(",
"right",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"rf",
".",
"Close",
"(",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"/usr/bin/diff\"",
",",
"\"-u\"",
",",
"lf",
".",
"Name",
"(",
")",
",",
"rf",
".",
"Name",
"(",
")",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"cmd",
".",
"Run",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Diff prints the unified diff of the two provided byte slices
// using the unix diff command. | [
"Diff",
"prints",
"the",
"unified",
"diff",
"of",
"the",
"two",
"provided",
"byte",
"slices",
"using",
"the",
"unix",
"diff",
"command",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/diff.go#L27-L60 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/controller/controller.go | StartLocalController | func StartLocalController(client *kubernetes.Clientset, ptable deleter.ProcTable, config *common.UserConfig) {
glog.Info("Initializing volume cache\n")
var provisionerName string
if config.UseNodeNameOnly {
provisionerName = fmt.Sprintf("local-volume-provisioner-%v", config.Node.Name)
} else {
provisionerName = fmt.Sprintf("local-volume-provisioner-%v-%v", config.Node.Name, config.Node.UID)
}
broadcaster := record.NewBroadcaster()
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(client.CoreV1().RESTClient()).Events("")})
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: provisionerName})
// We choose a random resync period between MinResyncPeriod and 2 *
// MinResyncPeriod, so that local provisioners deployed on multiple nodes
// at same time don't list the apiserver simultaneously.
resyncPeriod := time.Duration(config.MinResyncPeriod.Seconds()*(1+rand.Float64())) * time.Second
runtimeConfig := &common.RuntimeConfig{
UserConfig: config,
Cache: cache.NewVolumeCache(),
VolUtil: util.NewVolumeUtil(),
APIUtil: util.NewAPIUtil(client),
Client: client,
Name: provisionerName,
Recorder: recorder,
Mounter: mount.New("" /* default mount path */),
InformerFactory: informers.NewSharedInformerFactory(client, resyncPeriod),
}
populator.NewPopulator(runtimeConfig)
var jobController deleter.JobController
var err error
if runtimeConfig.UseJobForCleaning {
labels := map[string]string{common.NodeNameLabel: config.Node.Name}
jobController, err = deleter.NewJobController(labels, runtimeConfig)
if err != nil {
glog.Fatalf("Error initializing jobController: %v", err)
}
glog.Infof("Enabling Jobs based cleaning.")
}
cleanupTracker := &deleter.CleanupStatusTracker{ProcTable: ptable, JobController: jobController}
discoverer, err := discovery.NewDiscoverer(runtimeConfig, cleanupTracker)
if err != nil {
glog.Fatalf("Error initializing discoverer: %v", err)
}
deleter := deleter.NewDeleter(runtimeConfig, cleanupTracker)
// Start informers after all event listeners are registered.
runtimeConfig.InformerFactory.Start(wait.NeverStop)
// Wait for all started informers' cache were synced.
for v, synced := range runtimeConfig.InformerFactory.WaitForCacheSync(wait.NeverStop) {
if !synced {
glog.Fatalf("Error syncing informer for %v", v)
}
}
// Run controller logic.
if jobController != nil {
go jobController.Run(wait.NeverStop)
}
glog.Info("Controller started\n")
for {
deleter.DeletePVs()
discoverer.DiscoverLocalVolumes()
time.Sleep(10 * time.Second)
}
} | go | func StartLocalController(client *kubernetes.Clientset, ptable deleter.ProcTable, config *common.UserConfig) {
glog.Info("Initializing volume cache\n")
var provisionerName string
if config.UseNodeNameOnly {
provisionerName = fmt.Sprintf("local-volume-provisioner-%v", config.Node.Name)
} else {
provisionerName = fmt.Sprintf("local-volume-provisioner-%v-%v", config.Node.Name, config.Node.UID)
}
broadcaster := record.NewBroadcaster()
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(client.CoreV1().RESTClient()).Events("")})
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: provisionerName})
// We choose a random resync period between MinResyncPeriod and 2 *
// MinResyncPeriod, so that local provisioners deployed on multiple nodes
// at same time don't list the apiserver simultaneously.
resyncPeriod := time.Duration(config.MinResyncPeriod.Seconds()*(1+rand.Float64())) * time.Second
runtimeConfig := &common.RuntimeConfig{
UserConfig: config,
Cache: cache.NewVolumeCache(),
VolUtil: util.NewVolumeUtil(),
APIUtil: util.NewAPIUtil(client),
Client: client,
Name: provisionerName,
Recorder: recorder,
Mounter: mount.New("" /* default mount path */),
InformerFactory: informers.NewSharedInformerFactory(client, resyncPeriod),
}
populator.NewPopulator(runtimeConfig)
var jobController deleter.JobController
var err error
if runtimeConfig.UseJobForCleaning {
labels := map[string]string{common.NodeNameLabel: config.Node.Name}
jobController, err = deleter.NewJobController(labels, runtimeConfig)
if err != nil {
glog.Fatalf("Error initializing jobController: %v", err)
}
glog.Infof("Enabling Jobs based cleaning.")
}
cleanupTracker := &deleter.CleanupStatusTracker{ProcTable: ptable, JobController: jobController}
discoverer, err := discovery.NewDiscoverer(runtimeConfig, cleanupTracker)
if err != nil {
glog.Fatalf("Error initializing discoverer: %v", err)
}
deleter := deleter.NewDeleter(runtimeConfig, cleanupTracker)
// Start informers after all event listeners are registered.
runtimeConfig.InformerFactory.Start(wait.NeverStop)
// Wait for all started informers' cache were synced.
for v, synced := range runtimeConfig.InformerFactory.WaitForCacheSync(wait.NeverStop) {
if !synced {
glog.Fatalf("Error syncing informer for %v", v)
}
}
// Run controller logic.
if jobController != nil {
go jobController.Run(wait.NeverStop)
}
glog.Info("Controller started\n")
for {
deleter.DeletePVs()
discoverer.DiscoverLocalVolumes()
time.Sleep(10 * time.Second)
}
} | [
"func",
"StartLocalController",
"(",
"client",
"*",
"kubernetes",
".",
"Clientset",
",",
"ptable",
"deleter",
".",
"ProcTable",
",",
"config",
"*",
"common",
".",
"UserConfig",
")",
"{",
"glog",
".",
"Info",
"(",
"\"Initializing volume cache\\n\"",
")",
"\n",
"\\n",
"\n",
"var",
"provisionerName",
"string",
"\n",
"if",
"config",
".",
"UseNodeNameOnly",
"{",
"provisionerName",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"local-volume-provisioner-%v\"",
",",
"config",
".",
"Node",
".",
"Name",
")",
"\n",
"}",
"else",
"{",
"provisionerName",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"local-volume-provisioner-%v-%v\"",
",",
"config",
".",
"Node",
".",
"Name",
",",
"config",
".",
"Node",
".",
"UID",
")",
"\n",
"}",
"\n",
"broadcaster",
":=",
"record",
".",
"NewBroadcaster",
"(",
")",
"\n",
"broadcaster",
".",
"StartRecordingToSink",
"(",
"&",
"v1core",
".",
"EventSinkImpl",
"{",
"Interface",
":",
"v1core",
".",
"New",
"(",
"client",
".",
"CoreV1",
"(",
")",
".",
"RESTClient",
"(",
")",
")",
".",
"Events",
"(",
"\"\"",
")",
"}",
")",
"\n",
"recorder",
":=",
"broadcaster",
".",
"NewRecorder",
"(",
"scheme",
".",
"Scheme",
",",
"v1",
".",
"EventSource",
"{",
"Component",
":",
"provisionerName",
"}",
")",
"\n",
"resyncPeriod",
":=",
"time",
".",
"Duration",
"(",
"config",
".",
"MinResyncPeriod",
".",
"Seconds",
"(",
")",
"*",
"(",
"1",
"+",
"rand",
".",
"Float64",
"(",
")",
")",
")",
"*",
"time",
".",
"Second",
"\n",
"runtimeConfig",
":=",
"&",
"common",
".",
"RuntimeConfig",
"{",
"UserConfig",
":",
"config",
",",
"Cache",
":",
"cache",
".",
"NewVolumeCache",
"(",
")",
",",
"VolUtil",
":",
"util",
".",
"NewVolumeUtil",
"(",
")",
",",
"APIUtil",
":",
"util",
".",
"NewAPIUtil",
"(",
"client",
")",
",",
"Client",
":",
"client",
",",
"Name",
":",
"provisionerName",
",",
"Recorder",
":",
"recorder",
",",
"Mounter",
":",
"mount",
".",
"New",
"(",
"\"\"",
")",
",",
"InformerFactory",
":",
"informers",
".",
"NewSharedInformerFactory",
"(",
"client",
",",
"resyncPeriod",
")",
",",
"}",
"\n",
"populator",
".",
"NewPopulator",
"(",
"runtimeConfig",
")",
"\n",
"var",
"jobController",
"deleter",
".",
"JobController",
"\n",
"var",
"err",
"error",
"\n",
"if",
"runtimeConfig",
".",
"UseJobForCleaning",
"{",
"labels",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"common",
".",
"NodeNameLabel",
":",
"config",
".",
"Node",
".",
"Name",
"}",
"\n",
"jobController",
",",
"err",
"=",
"deleter",
".",
"NewJobController",
"(",
"labels",
",",
"runtimeConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"Error initializing jobController: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"glog",
".",
"Infof",
"(",
"\"Enabling Jobs based cleaning.\"",
")",
"\n",
"}",
"\n",
"cleanupTracker",
":=",
"&",
"deleter",
".",
"CleanupStatusTracker",
"{",
"ProcTable",
":",
"ptable",
",",
"JobController",
":",
"jobController",
"}",
"\n",
"discoverer",
",",
"err",
":=",
"discovery",
".",
"NewDiscoverer",
"(",
"runtimeConfig",
",",
"cleanupTracker",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"Error initializing discoverer: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"deleter",
":=",
"deleter",
".",
"NewDeleter",
"(",
"runtimeConfig",
",",
"cleanupTracker",
")",
"\n",
"runtimeConfig",
".",
"InformerFactory",
".",
"Start",
"(",
"wait",
".",
"NeverStop",
")",
"\n",
"for",
"v",
",",
"synced",
":=",
"range",
"runtimeConfig",
".",
"InformerFactory",
".",
"WaitForCacheSync",
"(",
"wait",
".",
"NeverStop",
")",
"{",
"if",
"!",
"synced",
"{",
"glog",
".",
"Fatalf",
"(",
"\"Error syncing informer for %v\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"jobController",
"!=",
"nil",
"{",
"go",
"jobController",
".",
"Run",
"(",
"wait",
".",
"NeverStop",
")",
"\n",
"}",
"\n",
"glog",
".",
"Info",
"(",
"\"Controller started\\n\"",
")",
"\n",
"}"
] | // StartLocalController starts the sync loop for the local PV discovery and deleter | [
"StartLocalController",
"starts",
"the",
"sync",
"loop",
"for",
"the",
"local",
"PV",
"discovery",
"and",
"deleter"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/controller/controller.go#L44-L114 | train |
kubernetes-incubator/external-storage | flex/pkg/volume/provision.go | NewFlexProvisioner | func NewFlexProvisioner(client kubernetes.Interface, execCommand string, flexDriver string) controller.Provisioner {
return newFlexProvisionerInternal(client, execCommand, flexDriver)
} | go | func NewFlexProvisioner(client kubernetes.Interface, execCommand string, flexDriver string) controller.Provisioner {
return newFlexProvisionerInternal(client, execCommand, flexDriver)
} | [
"func",
"NewFlexProvisioner",
"(",
"client",
"kubernetes",
".",
"Interface",
",",
"execCommand",
"string",
",",
"flexDriver",
"string",
")",
"controller",
".",
"Provisioner",
"{",
"return",
"newFlexProvisionerInternal",
"(",
"client",
",",
"execCommand",
",",
"flexDriver",
")",
"\n",
"}"
] | // NewFlexProvisioner creates a new flex provisioner | [
"NewFlexProvisioner",
"creates",
"a",
"new",
"flex",
"provisioner"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/flex/pkg/volume/provision.go#L41-L43 | train |
kubernetes-incubator/external-storage | snapshot/pkg/controller/cache/desired_state_of_world.go | AddSnapshot | func (dsw *desiredStateOfWorld) AddSnapshot(snapshot *crdv1.VolumeSnapshot) error {
if snapshot == nil {
return fmt.Errorf("nil snapshot spec")
}
dsw.Lock()
defer dsw.Unlock()
snapshotName := MakeSnapshotName(snapshot)
glog.Infof("Adding new snapshot to desired state of world: %s", snapshotName)
dsw.snapshots[snapshotName] = snapshot
return nil
} | go | func (dsw *desiredStateOfWorld) AddSnapshot(snapshot *crdv1.VolumeSnapshot) error {
if snapshot == nil {
return fmt.Errorf("nil snapshot spec")
}
dsw.Lock()
defer dsw.Unlock()
snapshotName := MakeSnapshotName(snapshot)
glog.Infof("Adding new snapshot to desired state of world: %s", snapshotName)
dsw.snapshots[snapshotName] = snapshot
return nil
} | [
"func",
"(",
"dsw",
"*",
"desiredStateOfWorld",
")",
"AddSnapshot",
"(",
"snapshot",
"*",
"crdv1",
".",
"VolumeSnapshot",
")",
"error",
"{",
"if",
"snapshot",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"nil snapshot spec\"",
")",
"\n",
"}",
"\n",
"dsw",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dsw",
".",
"Unlock",
"(",
")",
"\n",
"snapshotName",
":=",
"MakeSnapshotName",
"(",
"snapshot",
")",
"\n",
"glog",
".",
"Infof",
"(",
"\"Adding new snapshot to desired state of world: %s\"",
",",
"snapshotName",
")",
"\n",
"dsw",
".",
"snapshots",
"[",
"snapshotName",
"]",
"=",
"snapshot",
"\n",
"return",
"nil",
"\n",
"}"
] | // Adds a snapshot to the list of snapshots to be created | [
"Adds",
"a",
"snapshot",
"to",
"the",
"list",
"of",
"snapshots",
"to",
"be",
"created"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/controller/cache/desired_state_of_world.go#L67-L79 | train |
kubernetes-incubator/external-storage | snapshot/pkg/controller/cache/desired_state_of_world.go | DeleteSnapshot | func (dsw *desiredStateOfWorld) DeleteSnapshot(snapshotName string) error {
dsw.Lock()
defer dsw.Unlock()
glog.Infof("Deleting snapshot from desired state of world: %s", snapshotName)
delete(dsw.snapshots, snapshotName)
return nil
} | go | func (dsw *desiredStateOfWorld) DeleteSnapshot(snapshotName string) error {
dsw.Lock()
defer dsw.Unlock()
glog.Infof("Deleting snapshot from desired state of world: %s", snapshotName)
delete(dsw.snapshots, snapshotName)
return nil
} | [
"func",
"(",
"dsw",
"*",
"desiredStateOfWorld",
")",
"DeleteSnapshot",
"(",
"snapshotName",
"string",
")",
"error",
"{",
"dsw",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dsw",
".",
"Unlock",
"(",
")",
"\n",
"glog",
".",
"Infof",
"(",
"\"Deleting snapshot from desired state of world: %s\"",
",",
"snapshotName",
")",
"\n",
"delete",
"(",
"dsw",
".",
"snapshots",
",",
"snapshotName",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Removes the snapshot from the list of existing snapshots | [
"Removes",
"the",
"snapshot",
"from",
"the",
"list",
"of",
"existing",
"snapshots"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/controller/cache/desired_state_of_world.go#L82-L90 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/provision.go | NewNFSProvisioner | func NewNFSProvisioner(exportDir string, client kubernetes.Interface, outOfCluster bool, useGanesha bool, ganeshaConfig string, enableXfsQuota bool, serverHostname string, maxExports int, exportSubnet string) controller.Provisioner {
var exp exporter
if useGanesha {
exp = newGaneshaExporter(ganeshaConfig)
} else {
exp = newKernelExporter()
}
var quotaer quotaer
var err error
if enableXfsQuota {
quotaer, err = newXfsQuotaer(exportDir)
if err != nil {
glog.Fatalf("Error creating xfs quotaer! %v", err)
}
} else {
quotaer = newDummyQuotaer()
}
return newNFSProvisionerInternal(exportDir, client, outOfCluster, exp, quotaer, serverHostname, maxExports, exportSubnet)
} | go | func NewNFSProvisioner(exportDir string, client kubernetes.Interface, outOfCluster bool, useGanesha bool, ganeshaConfig string, enableXfsQuota bool, serverHostname string, maxExports int, exportSubnet string) controller.Provisioner {
var exp exporter
if useGanesha {
exp = newGaneshaExporter(ganeshaConfig)
} else {
exp = newKernelExporter()
}
var quotaer quotaer
var err error
if enableXfsQuota {
quotaer, err = newXfsQuotaer(exportDir)
if err != nil {
glog.Fatalf("Error creating xfs quotaer! %v", err)
}
} else {
quotaer = newDummyQuotaer()
}
return newNFSProvisionerInternal(exportDir, client, outOfCluster, exp, quotaer, serverHostname, maxExports, exportSubnet)
} | [
"func",
"NewNFSProvisioner",
"(",
"exportDir",
"string",
",",
"client",
"kubernetes",
".",
"Interface",
",",
"outOfCluster",
"bool",
",",
"useGanesha",
"bool",
",",
"ganeshaConfig",
"string",
",",
"enableXfsQuota",
"bool",
",",
"serverHostname",
"string",
",",
"maxExports",
"int",
",",
"exportSubnet",
"string",
")",
"controller",
".",
"Provisioner",
"{",
"var",
"exp",
"exporter",
"\n",
"if",
"useGanesha",
"{",
"exp",
"=",
"newGaneshaExporter",
"(",
"ganeshaConfig",
")",
"\n",
"}",
"else",
"{",
"exp",
"=",
"newKernelExporter",
"(",
")",
"\n",
"}",
"\n",
"var",
"quotaer",
"quotaer",
"\n",
"var",
"err",
"error",
"\n",
"if",
"enableXfsQuota",
"{",
"quotaer",
",",
"err",
"=",
"newXfsQuotaer",
"(",
"exportDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"Error creating xfs quotaer! %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"quotaer",
"=",
"newDummyQuotaer",
"(",
")",
"\n",
"}",
"\n",
"return",
"newNFSProvisionerInternal",
"(",
"exportDir",
",",
"client",
",",
"outOfCluster",
",",
"exp",
",",
"quotaer",
",",
"serverHostname",
",",
"maxExports",
",",
"exportSubnet",
")",
"\n",
"}"
] | // NewNFSProvisioner creates a Provisioner that provisions NFS PVs backed by
// the given directory. | [
"NewNFSProvisioner",
"creates",
"a",
"Provisioner",
"that",
"provisions",
"NFS",
"PVs",
"backed",
"by",
"the",
"given",
"directory",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/provision.go#L81-L99 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/provision.go | ShouldProvision | func (p *nfsProvisioner) ShouldProvision(claim *v1.PersistentVolumeClaim) bool {
// As long as the export limit has not been reached we're ok to provision
ok := p.checkExportLimit()
if !ok {
glog.Infof("export limit reached. skipping claim %s/%s", claim.Namespace, claim.Name)
}
return ok
} | go | func (p *nfsProvisioner) ShouldProvision(claim *v1.PersistentVolumeClaim) bool {
// As long as the export limit has not been reached we're ok to provision
ok := p.checkExportLimit()
if !ok {
glog.Infof("export limit reached. skipping claim %s/%s", claim.Namespace, claim.Name)
}
return ok
} | [
"func",
"(",
"p",
"*",
"nfsProvisioner",
")",
"ShouldProvision",
"(",
"claim",
"*",
"v1",
".",
"PersistentVolumeClaim",
")",
"bool",
"{",
"ok",
":=",
"p",
".",
"checkExportLimit",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"glog",
".",
"Infof",
"(",
"\"export limit reached. skipping claim %s/%s\"",
",",
"claim",
".",
"Namespace",
",",
"claim",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"ok",
"\n",
"}"
] | // ShouldProvision returns whether provisioning should be attempted for the given
// claim. | [
"ShouldProvision",
"returns",
"whether",
"provisioning",
"should",
"be",
"attempted",
"for",
"the",
"given",
"claim",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/provision.go#L187-L194 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/provision.go | createDirectory | func (p *nfsProvisioner) createDirectory(directory, gid string) error {
// TODO quotas
path := path.Join(p.exportDir, directory)
if _, err := os.Stat(path); !os.IsNotExist(err) {
return fmt.Errorf("the path already exists")
}
perm := os.FileMode(0777 | os.ModeSetgid)
if gid != "none" {
// Execute permission is required for stat, which kubelet uses during unmount.
perm = os.FileMode(0071 | os.ModeSetgid)
}
if err := os.MkdirAll(path, perm); err != nil {
return err
}
// Due to umask, need to chmod
if err := os.Chmod(path, perm); err != nil {
os.RemoveAll(path)
return err
}
if gid != "none" {
groupID, err := strconv.ParseUint(gid, 10, 64)
if err != nil {
os.RemoveAll(path)
return fmt.Errorf("strconv.ParseUint failed with error: %v", err)
}
cmd := exec.Command("chgrp", strconv.FormatUint(groupID, 10), path)
out, err := cmd.CombinedOutput()
if err != nil {
os.RemoveAll(path)
return fmt.Errorf("chgrp failed with error: %v, output: %s", err, out)
}
}
return nil
} | go | func (p *nfsProvisioner) createDirectory(directory, gid string) error {
// TODO quotas
path := path.Join(p.exportDir, directory)
if _, err := os.Stat(path); !os.IsNotExist(err) {
return fmt.Errorf("the path already exists")
}
perm := os.FileMode(0777 | os.ModeSetgid)
if gid != "none" {
// Execute permission is required for stat, which kubelet uses during unmount.
perm = os.FileMode(0071 | os.ModeSetgid)
}
if err := os.MkdirAll(path, perm); err != nil {
return err
}
// Due to umask, need to chmod
if err := os.Chmod(path, perm); err != nil {
os.RemoveAll(path)
return err
}
if gid != "none" {
groupID, err := strconv.ParseUint(gid, 10, 64)
if err != nil {
os.RemoveAll(path)
return fmt.Errorf("strconv.ParseUint failed with error: %v", err)
}
cmd := exec.Command("chgrp", strconv.FormatUint(groupID, 10), path)
out, err := cmd.CombinedOutput()
if err != nil {
os.RemoveAll(path)
return fmt.Errorf("chgrp failed with error: %v, output: %s", err, out)
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"nfsProvisioner",
")",
"createDirectory",
"(",
"directory",
",",
"gid",
"string",
")",
"error",
"{",
"path",
":=",
"path",
".",
"Join",
"(",
"p",
".",
"exportDir",
",",
"directory",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
";",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"the path already exists\"",
")",
"\n",
"}",
"\n",
"perm",
":=",
"os",
".",
"FileMode",
"(",
"0777",
"|",
"os",
".",
"ModeSetgid",
")",
"\n",
"if",
"gid",
"!=",
"\"none\"",
"{",
"perm",
"=",
"os",
".",
"FileMode",
"(",
"0071",
"|",
"os",
".",
"ModeSetgid",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"perm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"Chmod",
"(",
"path",
",",
"perm",
")",
";",
"err",
"!=",
"nil",
"{",
"os",
".",
"RemoveAll",
"(",
"path",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"gid",
"!=",
"\"none\"",
"{",
"groupID",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"gid",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"os",
".",
"RemoveAll",
"(",
"path",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"strconv.ParseUint failed with error: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"chgrp\"",
",",
"strconv",
".",
"FormatUint",
"(",
"groupID",
",",
"10",
")",
",",
"path",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"os",
".",
"RemoveAll",
"(",
"path",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"chgrp failed with error: %v, output: %s\"",
",",
"err",
",",
"out",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // createDirectory creates the given directory in exportDir with appropriate
// permissions and ownership according to the given gid parameter string. | [
"createDirectory",
"creates",
"the",
"given",
"directory",
"in",
"exportDir",
"with",
"appropriate",
"permissions",
"and",
"ownership",
"according",
"to",
"the",
"given",
"gid",
"parameter",
"string",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/provision.go#L449-L485 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/provision.go | createExport | func (p *nfsProvisioner) createExport(directory string, rootSquash bool) (string, uint16, error) {
path := path.Join(p.exportDir, directory)
block, exportID, err := p.exporter.AddExportBlock(path, rootSquash, p.exportSubnet)
if err != nil {
return "", 0, fmt.Errorf("error adding export block for path %s: %v", path, err)
}
err = p.exporter.Export(path)
if err != nil {
p.exporter.RemoveExportBlock(block, exportID)
return "", 0, fmt.Errorf("error exporting export block %s: %v", block, err)
}
return block, exportID, nil
} | go | func (p *nfsProvisioner) createExport(directory string, rootSquash bool) (string, uint16, error) {
path := path.Join(p.exportDir, directory)
block, exportID, err := p.exporter.AddExportBlock(path, rootSquash, p.exportSubnet)
if err != nil {
return "", 0, fmt.Errorf("error adding export block for path %s: %v", path, err)
}
err = p.exporter.Export(path)
if err != nil {
p.exporter.RemoveExportBlock(block, exportID)
return "", 0, fmt.Errorf("error exporting export block %s: %v", block, err)
}
return block, exportID, nil
} | [
"func",
"(",
"p",
"*",
"nfsProvisioner",
")",
"createExport",
"(",
"directory",
"string",
",",
"rootSquash",
"bool",
")",
"(",
"string",
",",
"uint16",
",",
"error",
")",
"{",
"path",
":=",
"path",
".",
"Join",
"(",
"p",
".",
"exportDir",
",",
"directory",
")",
"\n",
"block",
",",
"exportID",
",",
"err",
":=",
"p",
".",
"exporter",
".",
"AddExportBlock",
"(",
"path",
",",
"rootSquash",
",",
"p",
".",
"exportSubnet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"error adding export block for path %s: %v\"",
",",
"path",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"p",
".",
"exporter",
".",
"Export",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"exporter",
".",
"RemoveExportBlock",
"(",
"block",
",",
"exportID",
")",
"\n",
"return",
"\"\"",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"error exporting export block %s: %v\"",
",",
"block",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"block",
",",
"exportID",
",",
"nil",
"\n",
"}"
] | // createExport creates the export by adding a block to the appropriate config
// file and exporting it | [
"createExport",
"creates",
"the",
"export",
"by",
"adding",
"a",
"block",
"to",
"the",
"appropriate",
"config",
"file",
"and",
"exporting",
"it"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/provision.go#L489-L504 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/provision.go | createQuota | func (p *nfsProvisioner) createQuota(directory string, capacity resource.Quantity) (string, uint16, error) {
path := path.Join(p.exportDir, directory)
limit := strconv.FormatInt(capacity.Value(), 10)
block, projectID, err := p.quotaer.AddProject(path, limit)
if err != nil {
return "", 0, fmt.Errorf("error adding project for path %s: %v", path, err)
}
err = p.quotaer.SetQuota(projectID, path, limit)
if err != nil {
p.quotaer.RemoveProject(block, projectID)
return "", 0, fmt.Errorf("error setting quota for path %s: %v", path, err)
}
return block, projectID, nil
} | go | func (p *nfsProvisioner) createQuota(directory string, capacity resource.Quantity) (string, uint16, error) {
path := path.Join(p.exportDir, directory)
limit := strconv.FormatInt(capacity.Value(), 10)
block, projectID, err := p.quotaer.AddProject(path, limit)
if err != nil {
return "", 0, fmt.Errorf("error adding project for path %s: %v", path, err)
}
err = p.quotaer.SetQuota(projectID, path, limit)
if err != nil {
p.quotaer.RemoveProject(block, projectID)
return "", 0, fmt.Errorf("error setting quota for path %s: %v", path, err)
}
return block, projectID, nil
} | [
"func",
"(",
"p",
"*",
"nfsProvisioner",
")",
"createQuota",
"(",
"directory",
"string",
",",
"capacity",
"resource",
".",
"Quantity",
")",
"(",
"string",
",",
"uint16",
",",
"error",
")",
"{",
"path",
":=",
"path",
".",
"Join",
"(",
"p",
".",
"exportDir",
",",
"directory",
")",
"\n",
"limit",
":=",
"strconv",
".",
"FormatInt",
"(",
"capacity",
".",
"Value",
"(",
")",
",",
"10",
")",
"\n",
"block",
",",
"projectID",
",",
"err",
":=",
"p",
".",
"quotaer",
".",
"AddProject",
"(",
"path",
",",
"limit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"error adding project for path %s: %v\"",
",",
"path",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"p",
".",
"quotaer",
".",
"SetQuota",
"(",
"projectID",
",",
"path",
",",
"limit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"quotaer",
".",
"RemoveProject",
"(",
"block",
",",
"projectID",
")",
"\n",
"return",
"\"\"",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"error setting quota for path %s: %v\"",
",",
"path",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"block",
",",
"projectID",
",",
"nil",
"\n",
"}"
] | // createQuota creates a quota for the directory by adding a project to
// represent the directory and setting a quota on it | [
"createQuota",
"creates",
"a",
"quota",
"for",
"the",
"directory",
"by",
"adding",
"a",
"project",
"to",
"represent",
"the",
"directory",
"and",
"setting",
"a",
"quota",
"on",
"it"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/provision.go#L508-L525 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/deleter.go | NewDeleter | func NewDeleter(config *common.RuntimeConfig, cleanupTracker *CleanupStatusTracker) *Deleter {
return &Deleter{
RuntimeConfig: config,
CleanupStatus: cleanupTracker,
}
} | go | func NewDeleter(config *common.RuntimeConfig, cleanupTracker *CleanupStatusTracker) *Deleter {
return &Deleter{
RuntimeConfig: config,
CleanupStatus: cleanupTracker,
}
} | [
"func",
"NewDeleter",
"(",
"config",
"*",
"common",
".",
"RuntimeConfig",
",",
"cleanupTracker",
"*",
"CleanupStatusTracker",
")",
"*",
"Deleter",
"{",
"return",
"&",
"Deleter",
"{",
"RuntimeConfig",
":",
"config",
",",
"CleanupStatus",
":",
"cleanupTracker",
",",
"}",
"\n",
"}"
] | // NewDeleter creates a Deleter object to handle the cleanup and deletion of local PVs
// allocated by this provisioner | [
"NewDeleter",
"creates",
"a",
"Deleter",
"object",
"to",
"handle",
"the",
"cleanup",
"and",
"deletion",
"of",
"local",
"PVs",
"allocated",
"by",
"this",
"provisioner"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/deleter.go#L61-L66 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/deleter.go | DeletePVs | func (d *Deleter) DeletePVs() {
for _, pv := range d.Cache.ListPVs() {
if pv.Status.Phase != v1.VolumeReleased {
continue
}
name := pv.Name
switch pv.Spec.PersistentVolumeReclaimPolicy {
case v1.PersistentVolumeReclaimRetain:
glog.V(4).Infof("reclaimVolume[%s]: policy is Retain, nothing to do", name)
case v1.PersistentVolumeReclaimRecycle:
glog.V(4).Infof("reclaimVolume[%s]: policy is Recycle which is not supported", name)
d.RuntimeConfig.Recorder.Eventf(pv, v1.EventTypeWarning, "VolumeUnsupportedReclaimPolicy", "Volume has unsupported PersistentVolumeReclaimPolicy: Recycle")
case v1.PersistentVolumeReclaimDelete:
glog.V(4).Infof("reclaimVolume[%s]: policy is Delete", name)
// Cleanup volume
err := d.deletePV(pv)
if err != nil {
mode, modeErr := d.getVolMode(pv)
if modeErr != nil {
mode = "unknown"
}
deleteType := metrics.DeleteTypeProcess
if d.shouldRunJob(mode) {
deleteType = metrics.DeleteTypeJob
}
metrics.PersistentVolumeDeleteFailedTotal.WithLabelValues(string(mode), deleteType).Inc()
cleaningLocalPVErr := fmt.Errorf("Error cleaning PV %q: %v", name, err.Error())
d.RuntimeConfig.Recorder.Eventf(pv, v1.EventTypeWarning, common.EventVolumeFailedDelete, cleaningLocalPVErr.Error())
glog.Error(err)
continue
}
default:
// Unknown PersistentVolumeReclaimPolicy
d.RuntimeConfig.Recorder.Eventf(pv, v1.EventTypeWarning, "VolumeUnknownReclaimPolicy", "Volume has unrecognized PersistentVolumeReclaimPolicy")
}
}
} | go | func (d *Deleter) DeletePVs() {
for _, pv := range d.Cache.ListPVs() {
if pv.Status.Phase != v1.VolumeReleased {
continue
}
name := pv.Name
switch pv.Spec.PersistentVolumeReclaimPolicy {
case v1.PersistentVolumeReclaimRetain:
glog.V(4).Infof("reclaimVolume[%s]: policy is Retain, nothing to do", name)
case v1.PersistentVolumeReclaimRecycle:
glog.V(4).Infof("reclaimVolume[%s]: policy is Recycle which is not supported", name)
d.RuntimeConfig.Recorder.Eventf(pv, v1.EventTypeWarning, "VolumeUnsupportedReclaimPolicy", "Volume has unsupported PersistentVolumeReclaimPolicy: Recycle")
case v1.PersistentVolumeReclaimDelete:
glog.V(4).Infof("reclaimVolume[%s]: policy is Delete", name)
// Cleanup volume
err := d.deletePV(pv)
if err != nil {
mode, modeErr := d.getVolMode(pv)
if modeErr != nil {
mode = "unknown"
}
deleteType := metrics.DeleteTypeProcess
if d.shouldRunJob(mode) {
deleteType = metrics.DeleteTypeJob
}
metrics.PersistentVolumeDeleteFailedTotal.WithLabelValues(string(mode), deleteType).Inc()
cleaningLocalPVErr := fmt.Errorf("Error cleaning PV %q: %v", name, err.Error())
d.RuntimeConfig.Recorder.Eventf(pv, v1.EventTypeWarning, common.EventVolumeFailedDelete, cleaningLocalPVErr.Error())
glog.Error(err)
continue
}
default:
// Unknown PersistentVolumeReclaimPolicy
d.RuntimeConfig.Recorder.Eventf(pv, v1.EventTypeWarning, "VolumeUnknownReclaimPolicy", "Volume has unrecognized PersistentVolumeReclaimPolicy")
}
}
} | [
"func",
"(",
"d",
"*",
"Deleter",
")",
"DeletePVs",
"(",
")",
"{",
"for",
"_",
",",
"pv",
":=",
"range",
"d",
".",
"Cache",
".",
"ListPVs",
"(",
")",
"{",
"if",
"pv",
".",
"Status",
".",
"Phase",
"!=",
"v1",
".",
"VolumeReleased",
"{",
"continue",
"\n",
"}",
"\n",
"name",
":=",
"pv",
".",
"Name",
"\n",
"switch",
"pv",
".",
"Spec",
".",
"PersistentVolumeReclaimPolicy",
"{",
"case",
"v1",
".",
"PersistentVolumeReclaimRetain",
":",
"glog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"reclaimVolume[%s]: policy is Retain, nothing to do\"",
",",
"name",
")",
"\n",
"case",
"v1",
".",
"PersistentVolumeReclaimRecycle",
":",
"glog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"reclaimVolume[%s]: policy is Recycle which is not supported\"",
",",
"name",
")",
"\n",
"d",
".",
"RuntimeConfig",
".",
"Recorder",
".",
"Eventf",
"(",
"pv",
",",
"v1",
".",
"EventTypeWarning",
",",
"\"VolumeUnsupportedReclaimPolicy\"",
",",
"\"Volume has unsupported PersistentVolumeReclaimPolicy: Recycle\"",
")",
"\n",
"case",
"v1",
".",
"PersistentVolumeReclaimDelete",
":",
"glog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"reclaimVolume[%s]: policy is Delete\"",
",",
"name",
")",
"\n",
"err",
":=",
"d",
".",
"deletePV",
"(",
"pv",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"mode",
",",
"modeErr",
":=",
"d",
".",
"getVolMode",
"(",
"pv",
")",
"\n",
"if",
"modeErr",
"!=",
"nil",
"{",
"mode",
"=",
"\"unknown\"",
"\n",
"}",
"\n",
"deleteType",
":=",
"metrics",
".",
"DeleteTypeProcess",
"\n",
"if",
"d",
".",
"shouldRunJob",
"(",
"mode",
")",
"{",
"deleteType",
"=",
"metrics",
".",
"DeleteTypeJob",
"\n",
"}",
"\n",
"metrics",
".",
"PersistentVolumeDeleteFailedTotal",
".",
"WithLabelValues",
"(",
"string",
"(",
"mode",
")",
",",
"deleteType",
")",
".",
"Inc",
"(",
")",
"\n",
"cleaningLocalPVErr",
":=",
"fmt",
".",
"Errorf",
"(",
"\"Error cleaning PV %q: %v\"",
",",
"name",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"d",
".",
"RuntimeConfig",
".",
"Recorder",
".",
"Eventf",
"(",
"pv",
",",
"v1",
".",
"EventTypeWarning",
",",
"common",
".",
"EventVolumeFailedDelete",
",",
"cleaningLocalPVErr",
".",
"Error",
"(",
")",
")",
"\n",
"glog",
".",
"Error",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"default",
":",
"d",
".",
"RuntimeConfig",
".",
"Recorder",
".",
"Eventf",
"(",
"pv",
",",
"v1",
".",
"EventTypeWarning",
",",
"\"VolumeUnknownReclaimPolicy\"",
",",
"\"Volume has unrecognized PersistentVolumeReclaimPolicy\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // DeletePVs will scan through all the existing PVs that are released, and cleanup and
// delete them | [
"DeletePVs",
"will",
"scan",
"through",
"all",
"the",
"existing",
"PVs",
"that",
"are",
"released",
"and",
"cleanup",
"and",
"delete",
"them"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/deleter.go#L70-L106 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/deleter.go | InProgress | func (c *CleanupStatusTracker) InProgress(pvName string, isJob bool) bool {
if isJob {
return c.JobController.IsCleaningJobRunning(pvName)
}
return c.ProcTable.IsRunning(pvName)
} | go | func (c *CleanupStatusTracker) InProgress(pvName string, isJob bool) bool {
if isJob {
return c.JobController.IsCleaningJobRunning(pvName)
}
return c.ProcTable.IsRunning(pvName)
} | [
"func",
"(",
"c",
"*",
"CleanupStatusTracker",
")",
"InProgress",
"(",
"pvName",
"string",
",",
"isJob",
"bool",
")",
"bool",
"{",
"if",
"isJob",
"{",
"return",
"c",
".",
"JobController",
".",
"IsCleaningJobRunning",
"(",
"pvName",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"ProcTable",
".",
"IsRunning",
"(",
"pvName",
")",
"\n",
"}"
] | // InProgress returns true if the cleaning for the specified PV is in progress. | [
"InProgress",
"returns",
"true",
"if",
"the",
"cleaning",
"for",
"the",
"specified",
"PV",
"is",
"in",
"progress",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/deleter.go#L375-L380 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/deleter.go | RemoveStatus | func (c *CleanupStatusTracker) RemoveStatus(pvName string, isJob bool) (CleanupState, *time.Time, error) {
if isJob {
return c.JobController.RemoveJob(pvName)
}
return c.ProcTable.RemoveEntry(pvName)
} | go | func (c *CleanupStatusTracker) RemoveStatus(pvName string, isJob bool) (CleanupState, *time.Time, error) {
if isJob {
return c.JobController.RemoveJob(pvName)
}
return c.ProcTable.RemoveEntry(pvName)
} | [
"func",
"(",
"c",
"*",
"CleanupStatusTracker",
")",
"RemoveStatus",
"(",
"pvName",
"string",
",",
"isJob",
"bool",
")",
"(",
"CleanupState",
",",
"*",
"time",
".",
"Time",
",",
"error",
")",
"{",
"if",
"isJob",
"{",
"return",
"c",
".",
"JobController",
".",
"RemoveJob",
"(",
"pvName",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"ProcTable",
".",
"RemoveEntry",
"(",
"pvName",
")",
"\n",
"}"
] | // RemoveStatus removes and returns the status and start time of a completed cleaning process.
// The method returns an error if the process has not yet completed. | [
"RemoveStatus",
"removes",
"and",
"returns",
"the",
"status",
"and",
"start",
"time",
"of",
"a",
"completed",
"cleaning",
"process",
".",
"The",
"method",
"returns",
"an",
"error",
"if",
"the",
"process",
"has",
"not",
"yet",
"completed",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/deleter.go#L384-L389 | train |
kubernetes-incubator/external-storage | gluster/file/cmd/glusterfile-provisioner/glusterfile-provisioner.go | NewglusterfileProvisioner | func NewglusterfileProvisioner(client kubernetes.Interface, id string) controller.Provisioner {
return &glusterfileProvisioner{
client: client,
identity: id,
allocator: gidallocator.New(client),
}
} | go | func NewglusterfileProvisioner(client kubernetes.Interface, id string) controller.Provisioner {
return &glusterfileProvisioner{
client: client,
identity: id,
allocator: gidallocator.New(client),
}
} | [
"func",
"NewglusterfileProvisioner",
"(",
"client",
"kubernetes",
".",
"Interface",
",",
"id",
"string",
")",
"controller",
".",
"Provisioner",
"{",
"return",
"&",
"glusterfileProvisioner",
"{",
"client",
":",
"client",
",",
"identity",
":",
"id",
",",
"allocator",
":",
"gidallocator",
".",
"New",
"(",
"client",
")",
",",
"}",
"\n",
"}"
] | //NewglusterfileProvisioner create a new provisioner. | [
"NewglusterfileProvisioner",
"create",
"a",
"new",
"provisioner",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/gluster/file/cmd/glusterfile-provisioner/glusterfile-provisioner.go#L92-L98 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | IsEmpty | func (v *ProcTableImpl) IsEmpty() bool {
v.mutex.RLock()
defer v.mutex.RUnlock()
return len(v.procTable) == 0
} | go | func (v *ProcTableImpl) IsEmpty() bool {
v.mutex.RLock()
defer v.mutex.RUnlock()
return len(v.procTable) == 0
} | [
"func",
"(",
"v",
"*",
"ProcTableImpl",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"v",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"v",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"v",
".",
"procTable",
")",
"==",
"0",
"\n",
"}"
] | // IsEmpty Check if any cleanup process is running | [
"IsEmpty",
"Check",
"if",
"any",
"cleanup",
"process",
"is",
"running"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L78-L82 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | MarkFailed | func (v *ProcTableImpl) MarkFailed(pvName string) error {
return v.markStatus(pvName, CSFailed)
} | go | func (v *ProcTableImpl) MarkFailed(pvName string) error {
return v.markStatus(pvName, CSFailed)
} | [
"func",
"(",
"v",
"*",
"ProcTableImpl",
")",
"MarkFailed",
"(",
"pvName",
"string",
")",
"error",
"{",
"return",
"v",
".",
"markStatus",
"(",
"pvName",
",",
"CSFailed",
")",
"\n",
"}"
] | // MarkFailed Indicate the process has failed in its run. | [
"MarkFailed",
"Indicate",
"the",
"process",
"has",
"failed",
"in",
"its",
"run",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L97-L99 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | MarkSucceeded | func (v *ProcTableImpl) MarkSucceeded(pvName string) error {
return v.markStatus(pvName, CSSucceeded)
} | go | func (v *ProcTableImpl) MarkSucceeded(pvName string) error {
return v.markStatus(pvName, CSSucceeded)
} | [
"func",
"(",
"v",
"*",
"ProcTableImpl",
")",
"MarkSucceeded",
"(",
"pvName",
"string",
")",
"error",
"{",
"return",
"v",
".",
"markStatus",
"(",
"pvName",
",",
"CSSucceeded",
")",
"\n",
"}"
] | // MarkSucceeded Indicate the process has succeeded in its run. | [
"MarkSucceeded",
"Indicate",
"the",
"process",
"has",
"succeeded",
"in",
"its",
"run",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L102-L104 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | RemoveEntry | func (v *ProcTableImpl) RemoveEntry(pvName string) (CleanupState, *time.Time, error) {
v.mutex.Lock()
defer v.mutex.Unlock()
entry, ok := v.procTable[pvName]
if !ok {
return CSNotFound, nil, nil
}
if entry.Status == CSRunning {
return CSUnknown, nil, fmt.Errorf("cannot remove proctable entry for %q when it is still running", pvName)
}
if entry.Status == CSUnknown {
return CSUnknown, nil, fmt.Errorf("proctable entry for %q in unexpected unknown state", pvName)
}
delete(v.procTable, pvName)
return entry.Status, &entry.StartTime, nil
} | go | func (v *ProcTableImpl) RemoveEntry(pvName string) (CleanupState, *time.Time, error) {
v.mutex.Lock()
defer v.mutex.Unlock()
entry, ok := v.procTable[pvName]
if !ok {
return CSNotFound, nil, nil
}
if entry.Status == CSRunning {
return CSUnknown, nil, fmt.Errorf("cannot remove proctable entry for %q when it is still running", pvName)
}
if entry.Status == CSUnknown {
return CSUnknown, nil, fmt.Errorf("proctable entry for %q in unexpected unknown state", pvName)
}
delete(v.procTable, pvName)
return entry.Status, &entry.StartTime, nil
} | [
"func",
"(",
"v",
"*",
"ProcTableImpl",
")",
"RemoveEntry",
"(",
"pvName",
"string",
")",
"(",
"CleanupState",
",",
"*",
"time",
".",
"Time",
",",
"error",
")",
"{",
"v",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"entry",
",",
"ok",
":=",
"v",
".",
"procTable",
"[",
"pvName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"CSNotFound",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"entry",
".",
"Status",
"==",
"CSRunning",
"{",
"return",
"CSUnknown",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"cannot remove proctable entry for %q when it is still running\"",
",",
"pvName",
")",
"\n",
"}",
"\n",
"if",
"entry",
".",
"Status",
"==",
"CSUnknown",
"{",
"return",
"CSUnknown",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"proctable entry for %q in unexpected unknown state\"",
",",
"pvName",
")",
"\n",
"}",
"\n",
"delete",
"(",
"v",
".",
"procTable",
",",
"pvName",
")",
"\n",
"return",
"entry",
".",
"Status",
",",
"&",
"entry",
".",
"StartTime",
",",
"nil",
"\n",
"}"
] | // RemoveEntry Removes proctable entry and returns final state and start time of cleanup.
// Must only be called and cleanup that has ended, else error is returned. | [
"RemoveEntry",
"Removes",
"proctable",
"entry",
"and",
"returns",
"final",
"state",
"and",
"start",
"time",
"of",
"cleanup",
".",
"Must",
"only",
"be",
"called",
"and",
"cleanup",
"that",
"has",
"ended",
"else",
"error",
"is",
"returned",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L128-L143 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | Stats | func (v *ProcTableImpl) Stats() ProcTableStats {
v.mutex.RLock()
defer v.mutex.RUnlock()
running := 0
for _, entry := range v.procTable {
if entry.Status == CSRunning {
running++
}
}
return ProcTableStats{
Running: running,
Succeeded: v.succeeded,
Failed: v.failed,
}
} | go | func (v *ProcTableImpl) Stats() ProcTableStats {
v.mutex.RLock()
defer v.mutex.RUnlock()
running := 0
for _, entry := range v.procTable {
if entry.Status == CSRunning {
running++
}
}
return ProcTableStats{
Running: running,
Succeeded: v.succeeded,
Failed: v.failed,
}
} | [
"func",
"(",
"v",
"*",
"ProcTableImpl",
")",
"Stats",
"(",
")",
"ProcTableStats",
"{",
"v",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"v",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"running",
":=",
"0",
"\n",
"for",
"_",
",",
"entry",
":=",
"range",
"v",
".",
"procTable",
"{",
"if",
"entry",
".",
"Status",
"==",
"CSRunning",
"{",
"running",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ProcTableStats",
"{",
"Running",
":",
"running",
",",
"Succeeded",
":",
"v",
".",
"succeeded",
",",
"Failed",
":",
"v",
".",
"failed",
",",
"}",
"\n",
"}"
] | // Stats returns stats of ProcTable. | [
"Stats",
"returns",
"stats",
"of",
"ProcTable",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L146-L160 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | MarkFailed | func (f *FakeProcTableImpl) MarkFailed(pvName string) error {
f.MarkDoneCount++
return f.realTable.MarkFailed(pvName)
} | go | func (f *FakeProcTableImpl) MarkFailed(pvName string) error {
f.MarkDoneCount++
return f.realTable.MarkFailed(pvName)
} | [
"func",
"(",
"f",
"*",
"FakeProcTableImpl",
")",
"MarkFailed",
"(",
"pvName",
"string",
")",
"error",
"{",
"f",
".",
"MarkDoneCount",
"++",
"\n",
"return",
"f",
".",
"realTable",
".",
"MarkFailed",
"(",
"pvName",
")",
"\n",
"}"
] | // MarkFailed Indicate the process has failed. | [
"MarkFailed",
"Indicate",
"the",
"process",
"has",
"failed",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L202-L205 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | MarkSucceeded | func (f *FakeProcTableImpl) MarkSucceeded(pvName string) error {
f.MarkDoneCount++
return f.realTable.MarkSucceeded(pvName)
} | go | func (f *FakeProcTableImpl) MarkSucceeded(pvName string) error {
f.MarkDoneCount++
return f.realTable.MarkSucceeded(pvName)
} | [
"func",
"(",
"f",
"*",
"FakeProcTableImpl",
")",
"MarkSucceeded",
"(",
"pvName",
"string",
")",
"error",
"{",
"f",
".",
"MarkDoneCount",
"++",
"\n",
"return",
"f",
".",
"realTable",
".",
"MarkSucceeded",
"(",
"pvName",
")",
"\n",
"}"
] | // MarkSucceeded Indicate the process has succeeded. | [
"MarkSucceeded",
"Indicate",
"the",
"process",
"has",
"succeeded",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L208-L211 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/deleter/proctable.go | RemoveEntry | func (f *FakeProcTableImpl) RemoveEntry(pvName string) (CleanupState, *time.Time, error) {
f.RemoveCount++
return f.realTable.RemoveEntry(pvName)
} | go | func (f *FakeProcTableImpl) RemoveEntry(pvName string) (CleanupState, *time.Time, error) {
f.RemoveCount++
return f.realTable.RemoveEntry(pvName)
} | [
"func",
"(",
"f",
"*",
"FakeProcTableImpl",
")",
"RemoveEntry",
"(",
"pvName",
"string",
")",
"(",
"CleanupState",
",",
"*",
"time",
".",
"Time",
",",
"error",
")",
"{",
"f",
".",
"RemoveCount",
"++",
"\n",
"return",
"f",
".",
"realTable",
".",
"RemoveEntry",
"(",
"pvName",
")",
"\n",
"}"
] | // RemoveEntry removes the entry from the proc table. | [
"RemoveEntry",
"removes",
"the",
"entry",
"from",
"the",
"proc",
"table",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/deleter/proctable.go#L214-L217 | train |
kubernetes-incubator/external-storage | snapshot/pkg/client/client.go | NewClient | func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
scheme := runtime.NewScheme()
if err := crdv1.AddToScheme(scheme); err != nil {
return nil, nil, err
}
config := *cfg
config.GroupVersion = &crdv1.SchemeGroupVersion
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, nil, err
}
return client, scheme, nil
} | go | func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
scheme := runtime.NewScheme()
if err := crdv1.AddToScheme(scheme); err != nil {
return nil, nil, err
}
config := *cfg
config.GroupVersion = &crdv1.SchemeGroupVersion
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, nil, err
}
return client, scheme, nil
} | [
"func",
"NewClient",
"(",
"cfg",
"*",
"rest",
".",
"Config",
")",
"(",
"*",
"rest",
".",
"RESTClient",
",",
"*",
"runtime",
".",
"Scheme",
",",
"error",
")",
"{",
"scheme",
":=",
"runtime",
".",
"NewScheme",
"(",
")",
"\n",
"if",
"err",
":=",
"crdv1",
".",
"AddToScheme",
"(",
"scheme",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"config",
":=",
"*",
"cfg",
"\n",
"config",
".",
"GroupVersion",
"=",
"&",
"crdv1",
".",
"SchemeGroupVersion",
"\n",
"config",
".",
"APIPath",
"=",
"\"/apis\"",
"\n",
"config",
".",
"ContentType",
"=",
"runtime",
".",
"ContentTypeJSON",
"\n",
"config",
".",
"NegotiatedSerializer",
"=",
"serializer",
".",
"DirectCodecFactory",
"{",
"CodecFactory",
":",
"serializer",
".",
"NewCodecFactory",
"(",
"scheme",
")",
"}",
"\n",
"client",
",",
"err",
":=",
"rest",
".",
"RESTClientFor",
"(",
"&",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"client",
",",
"scheme",
",",
"nil",
"\n",
"}"
] | // NewClient creates a new RESTClient | [
"NewClient",
"creates",
"a",
"new",
"RESTClient"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/client/client.go#L41-L59 | train |
kubernetes-incubator/external-storage | snapshot/pkg/client/client.go | CreateCRD | func CreateCRD(clientset apiextensionsclient.Interface) error {
crd := &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotDataResourcePlural + "." + crdv1.GroupName,
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.ClusterScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotDataResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshotData{}).Name(),
},
},
}
res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotDataResource: %#v, err: %#v",
res, err)
}
crd = &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotResourcePlural + "." + crdv1.GroupName,
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.NamespaceScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshot{}).Name(),
},
},
}
res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
res, err)
}
return nil
} | go | func CreateCRD(clientset apiextensionsclient.Interface) error {
crd := &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotDataResourcePlural + "." + crdv1.GroupName,
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.ClusterScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotDataResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshotData{}).Name(),
},
},
}
res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotDataResource: %#v, err: %#v",
res, err)
}
crd = &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdv1.VolumeSnapshotResourcePlural + "." + crdv1.GroupName,
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: crdv1.GroupName,
Version: crdv1.SchemeGroupVersion.Version,
Scope: apiextensionsv1beta1.NamespaceScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Plural: crdv1.VolumeSnapshotResourcePlural,
Kind: reflect.TypeOf(crdv1.VolumeSnapshot{}).Name(),
},
},
}
res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
res, err)
}
return nil
} | [
"func",
"CreateCRD",
"(",
"clientset",
"apiextensionsclient",
".",
"Interface",
")",
"error",
"{",
"crd",
":=",
"&",
"apiextensionsv1beta1",
".",
"CustomResourceDefinition",
"{",
"ObjectMeta",
":",
"metav1",
".",
"ObjectMeta",
"{",
"Name",
":",
"crdv1",
".",
"VolumeSnapshotDataResourcePlural",
"+",
"\".\"",
"+",
"crdv1",
".",
"GroupName",
",",
"}",
",",
"Spec",
":",
"apiextensionsv1beta1",
".",
"CustomResourceDefinitionSpec",
"{",
"Group",
":",
"crdv1",
".",
"GroupName",
",",
"Version",
":",
"crdv1",
".",
"SchemeGroupVersion",
".",
"Version",
",",
"Scope",
":",
"apiextensionsv1beta1",
".",
"ClusterScoped",
",",
"Names",
":",
"apiextensionsv1beta1",
".",
"CustomResourceDefinitionNames",
"{",
"Plural",
":",
"crdv1",
".",
"VolumeSnapshotDataResourcePlural",
",",
"Kind",
":",
"reflect",
".",
"TypeOf",
"(",
"crdv1",
".",
"VolumeSnapshotData",
"{",
"}",
")",
".",
"Name",
"(",
")",
",",
"}",
",",
"}",
",",
"}",
"\n",
"res",
",",
"err",
":=",
"clientset",
".",
"ApiextensionsV1beta1",
"(",
")",
".",
"CustomResourceDefinitions",
"(",
")",
".",
"Create",
"(",
"crd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"apierrors",
".",
"IsAlreadyExists",
"(",
"err",
")",
"{",
"glog",
".",
"Fatalf",
"(",
"\"failed to create VolumeSnapshotDataResource: %#v, err: %#v\"",
",",
"res",
",",
"err",
")",
"\n",
"}",
"\n",
"crd",
"=",
"&",
"apiextensionsv1beta1",
".",
"CustomResourceDefinition",
"{",
"ObjectMeta",
":",
"metav1",
".",
"ObjectMeta",
"{",
"Name",
":",
"crdv1",
".",
"VolumeSnapshotResourcePlural",
"+",
"\".\"",
"+",
"crdv1",
".",
"GroupName",
",",
"}",
",",
"Spec",
":",
"apiextensionsv1beta1",
".",
"CustomResourceDefinitionSpec",
"{",
"Group",
":",
"crdv1",
".",
"GroupName",
",",
"Version",
":",
"crdv1",
".",
"SchemeGroupVersion",
".",
"Version",
",",
"Scope",
":",
"apiextensionsv1beta1",
".",
"NamespaceScoped",
",",
"Names",
":",
"apiextensionsv1beta1",
".",
"CustomResourceDefinitionNames",
"{",
"Plural",
":",
"crdv1",
".",
"VolumeSnapshotResourcePlural",
",",
"Kind",
":",
"reflect",
".",
"TypeOf",
"(",
"crdv1",
".",
"VolumeSnapshot",
"{",
"}",
")",
".",
"Name",
"(",
")",
",",
"}",
",",
"}",
",",
"}",
"\n",
"res",
",",
"err",
"=",
"clientset",
".",
"ApiextensionsV1beta1",
"(",
")",
".",
"CustomResourceDefinitions",
"(",
")",
".",
"Create",
"(",
"crd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"apierrors",
".",
"IsAlreadyExists",
"(",
"err",
")",
"{",
"glog",
".",
"Fatalf",
"(",
"\"failed to create VolumeSnapshotResource: %#v, err: %#v\"",
",",
"res",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CreateCRD creates CustomResourceDefinition | [
"CreateCRD",
"creates",
"CustomResourceDefinition"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/client/client.go#L62-L104 | train |
kubernetes-incubator/external-storage | snapshot/pkg/client/client.go | WaitForSnapshotResource | func WaitForSnapshotResource(snapshotClient *rest.RESTClient) error {
return wait.Poll(100*time.Millisecond, 60*time.Second, func() (bool, error) {
_, err := snapshotClient.Get().
Resource(crdv1.VolumeSnapshotDataResourcePlural).DoRaw()
if err == nil {
return true, nil
}
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
})
} | go | func WaitForSnapshotResource(snapshotClient *rest.RESTClient) error {
return wait.Poll(100*time.Millisecond, 60*time.Second, func() (bool, error) {
_, err := snapshotClient.Get().
Resource(crdv1.VolumeSnapshotDataResourcePlural).DoRaw()
if err == nil {
return true, nil
}
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
})
} | [
"func",
"WaitForSnapshotResource",
"(",
"snapshotClient",
"*",
"rest",
".",
"RESTClient",
")",
"error",
"{",
"return",
"wait",
".",
"Poll",
"(",
"100",
"*",
"time",
".",
"Millisecond",
",",
"60",
"*",
"time",
".",
"Second",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"snapshotClient",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"crdv1",
".",
"VolumeSnapshotDataResourcePlural",
")",
".",
"DoRaw",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"if",
"apierrors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
")",
"\n",
"}"
] | // WaitForSnapshotResource waits for the snapshot resource | [
"WaitForSnapshotResource",
"waits",
"for",
"the",
"snapshot",
"resource"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/client/client.go#L107-L119 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/openstack/openstack_instances.go | List | func (i *Instances) List(nameFilter string) ([]types.NodeName, error) {
glog.V(4).Infof("openstack List(%v) called", nameFilter)
opts := servers.ListOpts{
Name: nameFilter,
Status: "ACTIVE",
}
pager := servers.List(i.compute, opts)
ret := make([]types.NodeName, 0)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
sList, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
for i := range sList {
ret = append(ret, mapServerToNodeName(&sList[i]))
}
return true, nil
})
if err != nil {
return nil, err
}
glog.V(3).Infof("Found %v instances matching %v: %v",
len(ret), nameFilter, ret)
return ret, nil
} | go | func (i *Instances) List(nameFilter string) ([]types.NodeName, error) {
glog.V(4).Infof("openstack List(%v) called", nameFilter)
opts := servers.ListOpts{
Name: nameFilter,
Status: "ACTIVE",
}
pager := servers.List(i.compute, opts)
ret := make([]types.NodeName, 0)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
sList, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
for i := range sList {
ret = append(ret, mapServerToNodeName(&sList[i]))
}
return true, nil
})
if err != nil {
return nil, err
}
glog.V(3).Infof("Found %v instances matching %v: %v",
len(ret), nameFilter, ret)
return ret, nil
} | [
"func",
"(",
"i",
"*",
"Instances",
")",
"List",
"(",
"nameFilter",
"string",
")",
"(",
"[",
"]",
"types",
".",
"NodeName",
",",
"error",
")",
"{",
"glog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"openstack List(%v) called\"",
",",
"nameFilter",
")",
"\n",
"opts",
":=",
"servers",
".",
"ListOpts",
"{",
"Name",
":",
"nameFilter",
",",
"Status",
":",
"\"ACTIVE\"",
",",
"}",
"\n",
"pager",
":=",
"servers",
".",
"List",
"(",
"i",
".",
"compute",
",",
"opts",
")",
"\n",
"ret",
":=",
"make",
"(",
"[",
"]",
"types",
".",
"NodeName",
",",
"0",
")",
"\n",
"err",
":=",
"pager",
".",
"EachPage",
"(",
"func",
"(",
"page",
"pagination",
".",
"Page",
")",
"(",
"bool",
",",
"error",
")",
"{",
"sList",
",",
"err",
":=",
"servers",
".",
"ExtractServers",
"(",
"page",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"sList",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"mapServerToNodeName",
"(",
"&",
"sList",
"[",
"i",
"]",
")",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"glog",
".",
"V",
"(",
"3",
")",
".",
"Infof",
"(",
"\"Found %v instances matching %v: %v\"",
",",
"len",
"(",
"ret",
")",
",",
"nameFilter",
",",
"ret",
")",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // List lists node names | [
"List",
"lists",
"node",
"names"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_instances.go#L52-L80 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/openstack/openstack_instances.go | NodeAddresses | func (i *Instances) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
glog.V(4).Infof("NodeAddresses(%v) called", name)
addrs, err := getAddressesByName(i.compute, name)
if err != nil {
return nil, err
}
glog.V(4).Infof("NodeAddresses(%v) => %v", name, addrs)
return addrs, nil
} | go | func (i *Instances) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
glog.V(4).Infof("NodeAddresses(%v) called", name)
addrs, err := getAddressesByName(i.compute, name)
if err != nil {
return nil, err
}
glog.V(4).Infof("NodeAddresses(%v) => %v", name, addrs)
return addrs, nil
} | [
"func",
"(",
"i",
"*",
"Instances",
")",
"NodeAddresses",
"(",
"name",
"types",
".",
"NodeName",
")",
"(",
"[",
"]",
"v1",
".",
"NodeAddress",
",",
"error",
")",
"{",
"glog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"NodeAddresses(%v) called\"",
",",
"name",
")",
"\n",
"addrs",
",",
"err",
":=",
"getAddressesByName",
"(",
"i",
".",
"compute",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"glog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"NodeAddresses(%v) => %v\"",
",",
"name",
",",
"addrs",
")",
"\n",
"return",
"addrs",
",",
"nil",
"\n",
"}"
] | // NodeAddresses gets node addresses | [
"NodeAddresses",
"gets",
"node",
"addresses"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_instances.go#L98-L108 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/util.go | generateID | func generateID(mutex *sync.Mutex, ids map[uint16]bool) uint16 {
mutex.Lock()
id := uint16(1)
for ; id <= math.MaxUint16; id++ {
if _, ok := ids[id]; !ok {
break
}
}
ids[id] = true
mutex.Unlock()
return id
} | go | func generateID(mutex *sync.Mutex, ids map[uint16]bool) uint16 {
mutex.Lock()
id := uint16(1)
for ; id <= math.MaxUint16; id++ {
if _, ok := ids[id]; !ok {
break
}
}
ids[id] = true
mutex.Unlock()
return id
} | [
"func",
"generateID",
"(",
"mutex",
"*",
"sync",
".",
"Mutex",
",",
"ids",
"map",
"[",
"uint16",
"]",
"bool",
")",
"uint16",
"{",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"id",
":=",
"uint16",
"(",
"1",
")",
"\n",
"for",
";",
"id",
"<=",
"math",
".",
"MaxUint16",
";",
"id",
"++",
"{",
"if",
"_",
",",
"ok",
":=",
"ids",
"[",
"id",
"]",
";",
"!",
"ok",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"ids",
"[",
"id",
"]",
"=",
"true",
"\n",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"id",
"\n",
"}"
] | // generateID generates a unique exportID to assign an export | [
"generateID",
"generates",
"a",
"unique",
"exportID",
"to",
"assign",
"an",
"export"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/util.go#L31-L42 | train |
kubernetes-incubator/external-storage | nfs/pkg/volume/util.go | getExistingIDs | func getExistingIDs(config string, re *regexp.Regexp) (map[uint16]bool, error) {
ids := map[uint16]bool{}
digitsRe := "([0-9]+)"
if !strings.Contains(re.String(), digitsRe) {
return ids, fmt.Errorf("regexp %s doesn't contain digits submatch %s", re.String(), digitsRe)
}
read, err := ioutil.ReadFile(config)
if err != nil {
return ids, err
}
allMatches := re.FindAllSubmatch(read, -1)
for _, match := range allMatches {
digits := match[1]
if id, err := strconv.ParseUint(string(digits), 10, 16); err == nil {
ids[uint16(id)] = true
}
}
return ids, nil
} | go | func getExistingIDs(config string, re *regexp.Regexp) (map[uint16]bool, error) {
ids := map[uint16]bool{}
digitsRe := "([0-9]+)"
if !strings.Contains(re.String(), digitsRe) {
return ids, fmt.Errorf("regexp %s doesn't contain digits submatch %s", re.String(), digitsRe)
}
read, err := ioutil.ReadFile(config)
if err != nil {
return ids, err
}
allMatches := re.FindAllSubmatch(read, -1)
for _, match := range allMatches {
digits := match[1]
if id, err := strconv.ParseUint(string(digits), 10, 16); err == nil {
ids[uint16(id)] = true
}
}
return ids, nil
} | [
"func",
"getExistingIDs",
"(",
"config",
"string",
",",
"re",
"*",
"regexp",
".",
"Regexp",
")",
"(",
"map",
"[",
"uint16",
"]",
"bool",
",",
"error",
")",
"{",
"ids",
":=",
"map",
"[",
"uint16",
"]",
"bool",
"{",
"}",
"\n",
"digitsRe",
":=",
"\"([0-9]+)\"",
"\n",
"if",
"!",
"strings",
".",
"Contains",
"(",
"re",
".",
"String",
"(",
")",
",",
"digitsRe",
")",
"{",
"return",
"ids",
",",
"fmt",
".",
"Errorf",
"(",
"\"regexp %s doesn't contain digits submatch %s\"",
",",
"re",
".",
"String",
"(",
")",
",",
"digitsRe",
")",
"\n",
"}",
"\n",
"read",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ids",
",",
"err",
"\n",
"}",
"\n",
"allMatches",
":=",
"re",
".",
"FindAllSubmatch",
"(",
"read",
",",
"-",
"1",
")",
"\n",
"for",
"_",
",",
"match",
":=",
"range",
"allMatches",
"{",
"digits",
":=",
"match",
"[",
"1",
"]",
"\n",
"if",
"id",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"string",
"(",
"digits",
")",
",",
"10",
",",
"16",
")",
";",
"err",
"==",
"nil",
"{",
"ids",
"[",
"uint16",
"(",
"id",
")",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] | // getExistingIDs populates a map with existing ids found in the given config
// file using the given regexp. Regexp must have a "digits" submatch. | [
"getExistingIDs",
"populates",
"a",
"map",
"with",
"existing",
"ids",
"found",
"in",
"the",
"given",
"config",
"file",
"using",
"the",
"given",
"regexp",
".",
"Regexp",
"must",
"have",
"a",
"digits",
"submatch",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/util.go#L52-L74 | train |
kubernetes-incubator/external-storage | snapshot/pkg/controller/snapshot-controller/snapshot-controller.go | NewSnapshotController | func NewSnapshotController(client *rest.RESTClient,
scheme *runtime.Scheme,
clientset kubernetes.Interface,
volumePlugins *map[string]volume.Plugin,
syncDuration time.Duration) SnapshotController {
sc := &snapshotController{
snapshotClient: client,
snapshotScheme: scheme,
}
// Watch snapshot objects
source := kcache.NewListWatchFromClient(
sc.snapshotClient,
crdv1.VolumeSnapshotResourcePlural,
apiv1.NamespaceAll,
fields.Everything())
sc.snapshotStore, sc.snapshotController = kcache.NewInformer(
source,
// The object type.
&crdv1.VolumeSnapshot{},
// resyncPeriod
// Every resyncPeriod, all resources in the kcache will retrigger events.
// Set to 0 to disable the resync.
time.Minute*60,
// Your custom resource event handlers.
kcache.ResourceEventHandlerFuncs{
AddFunc: sc.onSnapshotAdd,
UpdateFunc: sc.onSnapshotUpdate,
DeleteFunc: sc.onSnapshotDelete,
})
//eventBroadcaster := record.NewBroadcaster()
//eventBroadcaster.StartLogging(glog.Infof)
//eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(client).Events("")})
// sc.recorder = eventBroadcaster.NewRecorder(api.Scheme, apiv1.EventSource{Component: "volume snapshotting"})
sc.desiredStateOfWorld = cache.NewDesiredStateOfWorld()
sc.actualStateOfWorld = cache.NewActualStateOfWorld()
sc.snapshotter = snapshotter.NewVolumeSnapshotter(
client,
scheme,
clientset,
sc.actualStateOfWorld,
volumePlugins)
sc.reconciler = reconciler.NewReconciler(
reconcilerLoopPeriod,
syncDuration,
false, /* disableReconciliationSync */
sc.desiredStateOfWorld,
sc.actualStateOfWorld,
sc.snapshotter)
sc.desiredStateOfWorldPopulator = populator.NewDesiredStateOfWorldPopulator(
desiredStateOfWorldPopulatorLoopSleepPeriod,
desiredStateOfWorldPopulatorListSnapshotsRetryDuration,
sc.snapshotStore,
sc.desiredStateOfWorld,
)
return sc
} | go | func NewSnapshotController(client *rest.RESTClient,
scheme *runtime.Scheme,
clientset kubernetes.Interface,
volumePlugins *map[string]volume.Plugin,
syncDuration time.Duration) SnapshotController {
sc := &snapshotController{
snapshotClient: client,
snapshotScheme: scheme,
}
// Watch snapshot objects
source := kcache.NewListWatchFromClient(
sc.snapshotClient,
crdv1.VolumeSnapshotResourcePlural,
apiv1.NamespaceAll,
fields.Everything())
sc.snapshotStore, sc.snapshotController = kcache.NewInformer(
source,
// The object type.
&crdv1.VolumeSnapshot{},
// resyncPeriod
// Every resyncPeriod, all resources in the kcache will retrigger events.
// Set to 0 to disable the resync.
time.Minute*60,
// Your custom resource event handlers.
kcache.ResourceEventHandlerFuncs{
AddFunc: sc.onSnapshotAdd,
UpdateFunc: sc.onSnapshotUpdate,
DeleteFunc: sc.onSnapshotDelete,
})
//eventBroadcaster := record.NewBroadcaster()
//eventBroadcaster.StartLogging(glog.Infof)
//eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(client).Events("")})
// sc.recorder = eventBroadcaster.NewRecorder(api.Scheme, apiv1.EventSource{Component: "volume snapshotting"})
sc.desiredStateOfWorld = cache.NewDesiredStateOfWorld()
sc.actualStateOfWorld = cache.NewActualStateOfWorld()
sc.snapshotter = snapshotter.NewVolumeSnapshotter(
client,
scheme,
clientset,
sc.actualStateOfWorld,
volumePlugins)
sc.reconciler = reconciler.NewReconciler(
reconcilerLoopPeriod,
syncDuration,
false, /* disableReconciliationSync */
sc.desiredStateOfWorld,
sc.actualStateOfWorld,
sc.snapshotter)
sc.desiredStateOfWorldPopulator = populator.NewDesiredStateOfWorldPopulator(
desiredStateOfWorldPopulatorLoopSleepPeriod,
desiredStateOfWorldPopulatorListSnapshotsRetryDuration,
sc.snapshotStore,
sc.desiredStateOfWorld,
)
return sc
} | [
"func",
"NewSnapshotController",
"(",
"client",
"*",
"rest",
".",
"RESTClient",
",",
"scheme",
"*",
"runtime",
".",
"Scheme",
",",
"clientset",
"kubernetes",
".",
"Interface",
",",
"volumePlugins",
"*",
"map",
"[",
"string",
"]",
"volume",
".",
"Plugin",
",",
"syncDuration",
"time",
".",
"Duration",
")",
"SnapshotController",
"{",
"sc",
":=",
"&",
"snapshotController",
"{",
"snapshotClient",
":",
"client",
",",
"snapshotScheme",
":",
"scheme",
",",
"}",
"\n",
"source",
":=",
"kcache",
".",
"NewListWatchFromClient",
"(",
"sc",
".",
"snapshotClient",
",",
"crdv1",
".",
"VolumeSnapshotResourcePlural",
",",
"apiv1",
".",
"NamespaceAll",
",",
"fields",
".",
"Everything",
"(",
")",
")",
"\n",
"sc",
".",
"snapshotStore",
",",
"sc",
".",
"snapshotController",
"=",
"kcache",
".",
"NewInformer",
"(",
"source",
",",
"&",
"crdv1",
".",
"VolumeSnapshot",
"{",
"}",
",",
"time",
".",
"Minute",
"*",
"60",
",",
"kcache",
".",
"ResourceEventHandlerFuncs",
"{",
"AddFunc",
":",
"sc",
".",
"onSnapshotAdd",
",",
"UpdateFunc",
":",
"sc",
".",
"onSnapshotUpdate",
",",
"DeleteFunc",
":",
"sc",
".",
"onSnapshotDelete",
",",
"}",
")",
"\n",
"sc",
".",
"desiredStateOfWorld",
"=",
"cache",
".",
"NewDesiredStateOfWorld",
"(",
")",
"\n",
"sc",
".",
"actualStateOfWorld",
"=",
"cache",
".",
"NewActualStateOfWorld",
"(",
")",
"\n",
"sc",
".",
"snapshotter",
"=",
"snapshotter",
".",
"NewVolumeSnapshotter",
"(",
"client",
",",
"scheme",
",",
"clientset",
",",
"sc",
".",
"actualStateOfWorld",
",",
"volumePlugins",
")",
"\n",
"sc",
".",
"reconciler",
"=",
"reconciler",
".",
"NewReconciler",
"(",
"reconcilerLoopPeriod",
",",
"syncDuration",
",",
"false",
",",
"sc",
".",
"desiredStateOfWorld",
",",
"sc",
".",
"actualStateOfWorld",
",",
"sc",
".",
"snapshotter",
")",
"\n",
"sc",
".",
"desiredStateOfWorldPopulator",
"=",
"populator",
".",
"NewDesiredStateOfWorldPopulator",
"(",
"desiredStateOfWorldPopulatorLoopSleepPeriod",
",",
"desiredStateOfWorldPopulatorListSnapshotsRetryDuration",
",",
"sc",
".",
"snapshotStore",
",",
"sc",
".",
"desiredStateOfWorld",
",",
")",
"\n",
"return",
"sc",
"\n",
"}"
] | // NewSnapshotController creates a new SnapshotController | [
"NewSnapshotController",
"creates",
"a",
"new",
"SnapshotController"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/controller/snapshot-controller/snapshot-controller.go#L96-L163 | train |
kubernetes-incubator/external-storage | snapshot/pkg/controller/snapshot-controller/snapshot-controller.go | Run | func (c *snapshotController) Run(ctx <-chan struct{}) {
glog.Infof("Starting snapshot controller")
go c.snapshotController.Run(ctx)
if !kcontroller.WaitForCacheSync("snapshot-controller", ctx, c.snapshotController.HasSynced) {
return
}
go c.reconciler.Run(ctx)
go c.desiredStateOfWorldPopulator.Run(ctx)
} | go | func (c *snapshotController) Run(ctx <-chan struct{}) {
glog.Infof("Starting snapshot controller")
go c.snapshotController.Run(ctx)
if !kcontroller.WaitForCacheSync("snapshot-controller", ctx, c.snapshotController.HasSynced) {
return
}
go c.reconciler.Run(ctx)
go c.desiredStateOfWorldPopulator.Run(ctx)
} | [
"func",
"(",
"c",
"*",
"snapshotController",
")",
"Run",
"(",
"ctx",
"<-",
"chan",
"struct",
"{",
"}",
")",
"{",
"glog",
".",
"Infof",
"(",
"\"Starting snapshot controller\"",
")",
"\n",
"go",
"c",
".",
"snapshotController",
".",
"Run",
"(",
"ctx",
")",
"\n",
"if",
"!",
"kcontroller",
".",
"WaitForCacheSync",
"(",
"\"snapshot-controller\"",
",",
"ctx",
",",
"c",
".",
"snapshotController",
".",
"HasSynced",
")",
"{",
"return",
"\n",
"}",
"\n",
"go",
"c",
".",
"reconciler",
".",
"Run",
"(",
"ctx",
")",
"\n",
"go",
"c",
".",
"desiredStateOfWorldPopulator",
".",
"Run",
"(",
"ctx",
")",
"\n",
"}"
] | // Run starts an Snapshot resource controller | [
"Run",
"starts",
"an",
"Snapshot",
"resource",
"controller"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/controller/snapshot-controller/snapshot-controller.go#L166-L178 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/aws/aws_loadbalancer.go | ensureLoadBalancerHealthCheck | func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDescription, listeners []*elb.Listener) error {
name := aws.StringValue(loadBalancer.LoadBalancerName)
actual := loadBalancer.HealthCheck
// Default AWS settings
expectedHealthyThreshold := int64(2)
expectedUnhealthyThreshold := int64(6)
expectedTimeout := int64(5)
expectedInterval := int64(10)
// We only configure a TCP health-check on the first port
expectedTarget := ""
for _, listener := range listeners {
if listener.InstancePort == nil {
continue
}
expectedTarget = "TCP:" + strconv.FormatInt(*listener.InstancePort, 10)
break
}
if expectedTarget == "" {
return fmt.Errorf("unable to determine health check port for %q (no valid listeners)", name)
}
if expectedTarget == orEmpty(actual.Target) &&
expectedHealthyThreshold == orZero(actual.HealthyThreshold) &&
expectedUnhealthyThreshold == orZero(actual.UnhealthyThreshold) &&
expectedTimeout == orZero(actual.Timeout) &&
expectedInterval == orZero(actual.Interval) {
return nil
}
glog.V(2).Infof("Updating load-balancer health-check for %q", name)
healthCheck := &elb.HealthCheck{}
healthCheck.HealthyThreshold = &expectedHealthyThreshold
healthCheck.UnhealthyThreshold = &expectedUnhealthyThreshold
healthCheck.Timeout = &expectedTimeout
healthCheck.Interval = &expectedInterval
healthCheck.Target = &expectedTarget
request := &elb.ConfigureHealthCheckInput{}
request.HealthCheck = healthCheck
request.LoadBalancerName = loadBalancer.LoadBalancerName
_, err := c.elb.ConfigureHealthCheck(request)
if err != nil {
return fmt.Errorf("error configuring load-balancer health-check for %q: %v", name, err)
}
return nil
} | go | func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDescription, listeners []*elb.Listener) error {
name := aws.StringValue(loadBalancer.LoadBalancerName)
actual := loadBalancer.HealthCheck
// Default AWS settings
expectedHealthyThreshold := int64(2)
expectedUnhealthyThreshold := int64(6)
expectedTimeout := int64(5)
expectedInterval := int64(10)
// We only configure a TCP health-check on the first port
expectedTarget := ""
for _, listener := range listeners {
if listener.InstancePort == nil {
continue
}
expectedTarget = "TCP:" + strconv.FormatInt(*listener.InstancePort, 10)
break
}
if expectedTarget == "" {
return fmt.Errorf("unable to determine health check port for %q (no valid listeners)", name)
}
if expectedTarget == orEmpty(actual.Target) &&
expectedHealthyThreshold == orZero(actual.HealthyThreshold) &&
expectedUnhealthyThreshold == orZero(actual.UnhealthyThreshold) &&
expectedTimeout == orZero(actual.Timeout) &&
expectedInterval == orZero(actual.Interval) {
return nil
}
glog.V(2).Infof("Updating load-balancer health-check for %q", name)
healthCheck := &elb.HealthCheck{}
healthCheck.HealthyThreshold = &expectedHealthyThreshold
healthCheck.UnhealthyThreshold = &expectedUnhealthyThreshold
healthCheck.Timeout = &expectedTimeout
healthCheck.Interval = &expectedInterval
healthCheck.Target = &expectedTarget
request := &elb.ConfigureHealthCheckInput{}
request.HealthCheck = healthCheck
request.LoadBalancerName = loadBalancer.LoadBalancerName
_, err := c.elb.ConfigureHealthCheck(request)
if err != nil {
return fmt.Errorf("error configuring load-balancer health-check for %q: %v", name, err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cloud",
")",
"ensureLoadBalancerHealthCheck",
"(",
"loadBalancer",
"*",
"elb",
".",
"LoadBalancerDescription",
",",
"listeners",
"[",
"]",
"*",
"elb",
".",
"Listener",
")",
"error",
"{",
"name",
":=",
"aws",
".",
"StringValue",
"(",
"loadBalancer",
".",
"LoadBalancerName",
")",
"\n",
"actual",
":=",
"loadBalancer",
".",
"HealthCheck",
"\n",
"expectedHealthyThreshold",
":=",
"int64",
"(",
"2",
")",
"\n",
"expectedUnhealthyThreshold",
":=",
"int64",
"(",
"6",
")",
"\n",
"expectedTimeout",
":=",
"int64",
"(",
"5",
")",
"\n",
"expectedInterval",
":=",
"int64",
"(",
"10",
")",
"\n",
"expectedTarget",
":=",
"\"\"",
"\n",
"for",
"_",
",",
"listener",
":=",
"range",
"listeners",
"{",
"if",
"listener",
".",
"InstancePort",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"expectedTarget",
"=",
"\"TCP:\"",
"+",
"strconv",
".",
"FormatInt",
"(",
"*",
"listener",
".",
"InstancePort",
",",
"10",
")",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"expectedTarget",
"==",
"\"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"unable to determine health check port for %q (no valid listeners)\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"expectedTarget",
"==",
"orEmpty",
"(",
"actual",
".",
"Target",
")",
"&&",
"expectedHealthyThreshold",
"==",
"orZero",
"(",
"actual",
".",
"HealthyThreshold",
")",
"&&",
"expectedUnhealthyThreshold",
"==",
"orZero",
"(",
"actual",
".",
"UnhealthyThreshold",
")",
"&&",
"expectedTimeout",
"==",
"orZero",
"(",
"actual",
".",
"Timeout",
")",
"&&",
"expectedInterval",
"==",
"orZero",
"(",
"actual",
".",
"Interval",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"Updating load-balancer health-check for %q\"",
",",
"name",
")",
"\n",
"healthCheck",
":=",
"&",
"elb",
".",
"HealthCheck",
"{",
"}",
"\n",
"healthCheck",
".",
"HealthyThreshold",
"=",
"&",
"expectedHealthyThreshold",
"\n",
"healthCheck",
".",
"UnhealthyThreshold",
"=",
"&",
"expectedUnhealthyThreshold",
"\n",
"healthCheck",
".",
"Timeout",
"=",
"&",
"expectedTimeout",
"\n",
"healthCheck",
".",
"Interval",
"=",
"&",
"expectedInterval",
"\n",
"healthCheck",
".",
"Target",
"=",
"&",
"expectedTarget",
"\n",
"request",
":=",
"&",
"elb",
".",
"ConfigureHealthCheckInput",
"{",
"}",
"\n",
"request",
".",
"HealthCheck",
"=",
"healthCheck",
"\n",
"request",
".",
"LoadBalancerName",
"=",
"loadBalancer",
".",
"LoadBalancerName",
"\n",
"_",
",",
"err",
":=",
"c",
".",
"elb",
".",
"ConfigureHealthCheck",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"error configuring load-balancer health-check for %q: %v\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Makes sure that the health check for an ELB matches the configured listeners | [
"Makes",
"sure",
"that",
"the",
"health",
"check",
"for",
"an",
"ELB",
"matches",
"the",
"configured",
"listeners"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/aws/aws_loadbalancer.go#L327-L379 | train |
kubernetes-incubator/external-storage | ceph/rbd/pkg/provision/rbd_util.go | CreateImage | func (u *RBDUtil) CreateImage(image string, pOpts *rbdProvisionOptions, options controller.VolumeOptions) (*v1.RBDPersistentVolumeSource, int, error) {
var output []byte
var err error
capacity := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
volSizeBytes := capacity.Value()
// convert to MB that rbd defaults on
sz := int(util.RoundUpSize(volSizeBytes, 1024*1024))
if sz <= 0 {
return nil, 0, fmt.Errorf("invalid storage '%s' requested for RBD provisioner, it must greater than zero", capacity.String())
}
volSz := fmt.Sprintf("%d", sz)
// rbd create
mon := u.kernelRBDMonitorsOpt(pOpts.monitors)
if pOpts.imageFormat == rbdImageFormat2 {
klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s", image, volSz, pOpts.imageFormat, pOpts.imageFeatures, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
} else {
klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", image, volSz, pOpts.imageFormat, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
}
args := []string{"create", image, "--size", volSz, "--pool", pOpts.pool, "--id", pOpts.adminID, "-m", mon, "--key=" + pOpts.adminSecret, "--image-format", pOpts.imageFormat}
if pOpts.imageFormat == rbdImageFormat2 {
// if no image features is provided, it results in empty string
// which disable all RBD image format 2 features as we expected
features := strings.Join(pOpts.imageFeatures, ",")
args = append(args, "--image-feature", features)
}
output, err = u.execCommand("rbd", args)
if err != nil {
klog.Warningf("failed to create rbd image, output %v", string(output))
return nil, 0, fmt.Errorf("failed to create rbd image: %v, command output: %s", err, string(output))
}
return &v1.RBDPersistentVolumeSource{
CephMonitors: pOpts.monitors,
RBDImage: image,
RBDPool: pOpts.pool,
FSType: pOpts.fsType,
}, sz, nil
} | go | func (u *RBDUtil) CreateImage(image string, pOpts *rbdProvisionOptions, options controller.VolumeOptions) (*v1.RBDPersistentVolumeSource, int, error) {
var output []byte
var err error
capacity := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
volSizeBytes := capacity.Value()
// convert to MB that rbd defaults on
sz := int(util.RoundUpSize(volSizeBytes, 1024*1024))
if sz <= 0 {
return nil, 0, fmt.Errorf("invalid storage '%s' requested for RBD provisioner, it must greater than zero", capacity.String())
}
volSz := fmt.Sprintf("%d", sz)
// rbd create
mon := u.kernelRBDMonitorsOpt(pOpts.monitors)
if pOpts.imageFormat == rbdImageFormat2 {
klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s", image, volSz, pOpts.imageFormat, pOpts.imageFeatures, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
} else {
klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", image, volSz, pOpts.imageFormat, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
}
args := []string{"create", image, "--size", volSz, "--pool", pOpts.pool, "--id", pOpts.adminID, "-m", mon, "--key=" + pOpts.adminSecret, "--image-format", pOpts.imageFormat}
if pOpts.imageFormat == rbdImageFormat2 {
// if no image features is provided, it results in empty string
// which disable all RBD image format 2 features as we expected
features := strings.Join(pOpts.imageFeatures, ",")
args = append(args, "--image-feature", features)
}
output, err = u.execCommand("rbd", args)
if err != nil {
klog.Warningf("failed to create rbd image, output %v", string(output))
return nil, 0, fmt.Errorf("failed to create rbd image: %v, command output: %s", err, string(output))
}
return &v1.RBDPersistentVolumeSource{
CephMonitors: pOpts.monitors,
RBDImage: image,
RBDPool: pOpts.pool,
FSType: pOpts.fsType,
}, sz, nil
} | [
"func",
"(",
"u",
"*",
"RBDUtil",
")",
"CreateImage",
"(",
"image",
"string",
",",
"pOpts",
"*",
"rbdProvisionOptions",
",",
"options",
"controller",
".",
"VolumeOptions",
")",
"(",
"*",
"v1",
".",
"RBDPersistentVolumeSource",
",",
"int",
",",
"error",
")",
"{",
"var",
"output",
"[",
"]",
"byte",
"\n",
"var",
"err",
"error",
"\n",
"capacity",
":=",
"options",
".",
"PVC",
".",
"Spec",
".",
"Resources",
".",
"Requests",
"[",
"v1",
".",
"ResourceName",
"(",
"v1",
".",
"ResourceStorage",
")",
"]",
"\n",
"volSizeBytes",
":=",
"capacity",
".",
"Value",
"(",
")",
"\n",
"sz",
":=",
"int",
"(",
"util",
".",
"RoundUpSize",
"(",
"volSizeBytes",
",",
"1024",
"*",
"1024",
")",
")",
"\n",
"if",
"sz",
"<=",
"0",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid storage '%s' requested for RBD provisioner, it must greater than zero\"",
",",
"capacity",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"volSz",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%d\"",
",",
"sz",
")",
"\n",
"mon",
":=",
"u",
".",
"kernelRBDMonitorsOpt",
"(",
"pOpts",
".",
"monitors",
")",
"\n",
"if",
"pOpts",
".",
"imageFormat",
"==",
"rbdImageFormat2",
"{",
"klog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s\"",
",",
"image",
",",
"volSz",
",",
"pOpts",
".",
"imageFormat",
",",
"pOpts",
".",
"imageFeatures",
",",
"mon",
",",
"pOpts",
".",
"pool",
",",
"pOpts",
".",
"adminID",
",",
"pOpts",
".",
"adminSecret",
")",
"\n",
"}",
"else",
"{",
"klog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"rbd: create %s size %s format %s using mon %s, pool %s id %s key %s\"",
",",
"image",
",",
"volSz",
",",
"pOpts",
".",
"imageFormat",
",",
"mon",
",",
"pOpts",
".",
"pool",
",",
"pOpts",
".",
"adminID",
",",
"pOpts",
".",
"adminSecret",
")",
"\n",
"}",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"create\"",
",",
"image",
",",
"\"--size\"",
",",
"volSz",
",",
"\"--pool\"",
",",
"pOpts",
".",
"pool",
",",
"\"--id\"",
",",
"pOpts",
".",
"adminID",
",",
"\"-m\"",
",",
"mon",
",",
"\"--key=\"",
"+",
"pOpts",
".",
"adminSecret",
",",
"\"--image-format\"",
",",
"pOpts",
".",
"imageFormat",
"}",
"\n",
"if",
"pOpts",
".",
"imageFormat",
"==",
"rbdImageFormat2",
"{",
"features",
":=",
"strings",
".",
"Join",
"(",
"pOpts",
".",
"imageFeatures",
",",
"\",\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"--image-feature\"",
",",
"features",
")",
"\n",
"}",
"\n",
"output",
",",
"err",
"=",
"u",
".",
"execCommand",
"(",
"\"rbd\"",
",",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"klog",
".",
"Warningf",
"(",
"\"failed to create rbd image, output %v\"",
",",
"string",
"(",
"output",
")",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to create rbd image: %v, command output: %s\"",
",",
"err",
",",
"string",
"(",
"output",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"v1",
".",
"RBDPersistentVolumeSource",
"{",
"CephMonitors",
":",
"pOpts",
".",
"monitors",
",",
"RBDImage",
":",
"image",
",",
"RBDPool",
":",
"pOpts",
".",
"pool",
",",
"FSType",
":",
"pOpts",
".",
"fsType",
",",
"}",
",",
"sz",
",",
"nil",
"\n",
"}"
] | // CreateImage creates a new ceph image with provision and volume options. | [
"CreateImage",
"creates",
"a",
"new",
"ceph",
"image",
"with",
"provision",
"and",
"volume",
"options",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/ceph/rbd/pkg/provision/rbd_util.go#L48-L86 | train |
kubernetes-incubator/external-storage | ceph/rbd/pkg/provision/rbd_util.go | rbdStatus | func (u *RBDUtil) rbdStatus(image string, pOpts *rbdProvisionOptions) (bool, error) {
var err error
var output string
var cmd []byte
mon := u.kernelRBDMonitorsOpt(pOpts.monitors)
// cmd "rbd status" list the rbd client watch with the following output:
//
// # there is a watcher (exit=0)
// Watchers:
// watcher=10.16.153.105:0/710245699 client.14163 cookie=1
//
// # there is no watcher (exit=0)
// Watchers: none
//
// Otherwise, exit is non-zero, for example:
//
// # image does not exist (exit=2)
// rbd: error opening image kubernetes-dynamic-pvc-<UUID>: (2) No such file or directory
//
klog.V(4).Infof("rbd: status %s using mon %s, pool %s id %s key %s", image, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
args := []string{"status", image, "--pool", pOpts.pool, "-m", mon, "--id", pOpts.adminID, "--key=" + pOpts.adminSecret}
cmd, err = u.execCommand("rbd", args)
output = string(cmd)
// If command never succeed, returns its last error.
if err != nil {
return false, err
}
if strings.Contains(output, imageWatcherStr) {
klog.V(4).Infof("rbd: watchers on %s: %s", image, output)
return true, nil
}
klog.Warningf("rbd: no watchers on %s", image)
return false, nil
} | go | func (u *RBDUtil) rbdStatus(image string, pOpts *rbdProvisionOptions) (bool, error) {
var err error
var output string
var cmd []byte
mon := u.kernelRBDMonitorsOpt(pOpts.monitors)
// cmd "rbd status" list the rbd client watch with the following output:
//
// # there is a watcher (exit=0)
// Watchers:
// watcher=10.16.153.105:0/710245699 client.14163 cookie=1
//
// # there is no watcher (exit=0)
// Watchers: none
//
// Otherwise, exit is non-zero, for example:
//
// # image does not exist (exit=2)
// rbd: error opening image kubernetes-dynamic-pvc-<UUID>: (2) No such file or directory
//
klog.V(4).Infof("rbd: status %s using mon %s, pool %s id %s key %s", image, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
args := []string{"status", image, "--pool", pOpts.pool, "-m", mon, "--id", pOpts.adminID, "--key=" + pOpts.adminSecret}
cmd, err = u.execCommand("rbd", args)
output = string(cmd)
// If command never succeed, returns its last error.
if err != nil {
return false, err
}
if strings.Contains(output, imageWatcherStr) {
klog.V(4).Infof("rbd: watchers on %s: %s", image, output)
return true, nil
}
klog.Warningf("rbd: no watchers on %s", image)
return false, nil
} | [
"func",
"(",
"u",
"*",
"RBDUtil",
")",
"rbdStatus",
"(",
"image",
"string",
",",
"pOpts",
"*",
"rbdProvisionOptions",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"output",
"string",
"\n",
"var",
"cmd",
"[",
"]",
"byte",
"\n",
"mon",
":=",
"u",
".",
"kernelRBDMonitorsOpt",
"(",
"pOpts",
".",
"monitors",
")",
"\n",
"klog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"rbd: status %s using mon %s, pool %s id %s key %s\"",
",",
"image",
",",
"mon",
",",
"pOpts",
".",
"pool",
",",
"pOpts",
".",
"adminID",
",",
"pOpts",
".",
"adminSecret",
")",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"status\"",
",",
"image",
",",
"\"--pool\"",
",",
"pOpts",
".",
"pool",
",",
"\"-m\"",
",",
"mon",
",",
"\"--id\"",
",",
"pOpts",
".",
"adminID",
",",
"\"--key=\"",
"+",
"pOpts",
".",
"adminSecret",
"}",
"\n",
"cmd",
",",
"err",
"=",
"u",
".",
"execCommand",
"(",
"\"rbd\"",
",",
"args",
")",
"\n",
"output",
"=",
"string",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"output",
",",
"imageWatcherStr",
")",
"{",
"klog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"rbd: watchers on %s: %s\"",
",",
"image",
",",
"output",
")",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"klog",
".",
"Warningf",
"(",
"\"rbd: no watchers on %s\"",
",",
"image",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // rbdStatus checks if there is watcher on the image.
// It returns true if there is a watcher onthe image, otherwise returns false. | [
"rbdStatus",
"checks",
"if",
"there",
"is",
"watcher",
"on",
"the",
"image",
".",
"It",
"returns",
"true",
"if",
"there",
"is",
"a",
"watcher",
"onthe",
"image",
"otherwise",
"returns",
"false",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/ceph/rbd/pkg/provision/rbd_util.go#L90-L126 | train |
kubernetes-incubator/external-storage | ceph/rbd/pkg/provision/rbd_util.go | DeleteImage | func (u *RBDUtil) DeleteImage(image string, pOpts *rbdProvisionOptions) error {
var output []byte
found, err := u.rbdStatus(image, pOpts)
if err != nil {
return err
}
if found {
klog.Info("rbd is still being used ", image)
return fmt.Errorf("rbd %s is still being used", image)
}
// rbd rm
mon := u.kernelRBDMonitorsOpt(pOpts.monitors)
klog.V(4).Infof("rbd: rm %s using mon %s, pool %s id %s key %s", image, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
args := []string{"rm", image, "--pool", pOpts.pool, "--id", pOpts.adminID, "-m", mon, "--key=" + pOpts.adminSecret}
output, err = u.execCommand("rbd", args)
if err == nil {
return nil
}
klog.Errorf("failed to delete rbd image: %v, command output: %s", err, string(output))
return err
} | go | func (u *RBDUtil) DeleteImage(image string, pOpts *rbdProvisionOptions) error {
var output []byte
found, err := u.rbdStatus(image, pOpts)
if err != nil {
return err
}
if found {
klog.Info("rbd is still being used ", image)
return fmt.Errorf("rbd %s is still being used", image)
}
// rbd rm
mon := u.kernelRBDMonitorsOpt(pOpts.monitors)
klog.V(4).Infof("rbd: rm %s using mon %s, pool %s id %s key %s", image, mon, pOpts.pool, pOpts.adminID, pOpts.adminSecret)
args := []string{"rm", image, "--pool", pOpts.pool, "--id", pOpts.adminID, "-m", mon, "--key=" + pOpts.adminSecret}
output, err = u.execCommand("rbd", args)
if err == nil {
return nil
}
klog.Errorf("failed to delete rbd image: %v, command output: %s", err, string(output))
return err
} | [
"func",
"(",
"u",
"*",
"RBDUtil",
")",
"DeleteImage",
"(",
"image",
"string",
",",
"pOpts",
"*",
"rbdProvisionOptions",
")",
"error",
"{",
"var",
"output",
"[",
"]",
"byte",
"\n",
"found",
",",
"err",
":=",
"u",
".",
"rbdStatus",
"(",
"image",
",",
"pOpts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"found",
"{",
"klog",
".",
"Info",
"(",
"\"rbd is still being used \"",
",",
"image",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"rbd %s is still being used\"",
",",
"image",
")",
"\n",
"}",
"\n",
"mon",
":=",
"u",
".",
"kernelRBDMonitorsOpt",
"(",
"pOpts",
".",
"monitors",
")",
"\n",
"klog",
".",
"V",
"(",
"4",
")",
".",
"Infof",
"(",
"\"rbd: rm %s using mon %s, pool %s id %s key %s\"",
",",
"image",
",",
"mon",
",",
"pOpts",
".",
"pool",
",",
"pOpts",
".",
"adminID",
",",
"pOpts",
".",
"adminSecret",
")",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"rm\"",
",",
"image",
",",
"\"--pool\"",
",",
"pOpts",
".",
"pool",
",",
"\"--id\"",
",",
"pOpts",
".",
"adminID",
",",
"\"-m\"",
",",
"mon",
",",
"\"--key=\"",
"+",
"pOpts",
".",
"adminSecret",
"}",
"\n",
"output",
",",
"err",
"=",
"u",
".",
"execCommand",
"(",
"\"rbd\"",
",",
"args",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"klog",
".",
"Errorf",
"(",
"\"failed to delete rbd image: %v, command output: %s\"",
",",
"err",
",",
"string",
"(",
"output",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteImage deletes a ceph image with provision and volume options. | [
"DeleteImage",
"deletes",
"a",
"ceph",
"image",
"with",
"provision",
"and",
"volume",
"options",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/ceph/rbd/pkg/provision/rbd_util.go#L129-L149 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/aws/aws_routes.go | DeleteRoute | func (c *Cloud) DeleteRoute(clusterName string, route *cloudprovider.Route) error {
table, err := c.findRouteTable(clusterName)
if err != nil {
return err
}
request := &ec2.DeleteRouteInput{}
request.DestinationCidrBlock = aws.String(route.DestinationCIDR)
request.RouteTableId = table.RouteTableId
_, err = c.ec2.DeleteRoute(request)
if err != nil {
return fmt.Errorf("error deleting AWS route (%s): %v", route.DestinationCIDR, err)
}
return nil
} | go | func (c *Cloud) DeleteRoute(clusterName string, route *cloudprovider.Route) error {
table, err := c.findRouteTable(clusterName)
if err != nil {
return err
}
request := &ec2.DeleteRouteInput{}
request.DestinationCidrBlock = aws.String(route.DestinationCIDR)
request.RouteTableId = table.RouteTableId
_, err = c.ec2.DeleteRoute(request)
if err != nil {
return fmt.Errorf("error deleting AWS route (%s): %v", route.DestinationCIDR, err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cloud",
")",
"DeleteRoute",
"(",
"clusterName",
"string",
",",
"route",
"*",
"cloudprovider",
".",
"Route",
")",
"error",
"{",
"table",
",",
"err",
":=",
"c",
".",
"findRouteTable",
"(",
"clusterName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"request",
":=",
"&",
"ec2",
".",
"DeleteRouteInput",
"{",
"}",
"\n",
"request",
".",
"DestinationCidrBlock",
"=",
"aws",
".",
"String",
"(",
"route",
".",
"DestinationCIDR",
")",
"\n",
"request",
".",
"RouteTableId",
"=",
"table",
".",
"RouteTableId",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"ec2",
".",
"DeleteRoute",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"error deleting AWS route (%s): %v\"",
",",
"route",
".",
"DestinationCIDR",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeleteRoute implements Routes.DeleteRoute
// Delete the specified route | [
"DeleteRoute",
"implements",
"Routes",
".",
"DeleteRoute",
"Delete",
"the",
"specified",
"route"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/aws/aws_routes.go#L188-L204 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/discovery/discovery.go | NewDiscoverer | func NewDiscoverer(config *common.RuntimeConfig, cleanupTracker *deleter.CleanupStatusTracker) (*Discoverer, error) {
sharedInformer := config.InformerFactory.Storage().V1().StorageClasses()
sharedInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
// We don't need an actual event handler for StorageClasses,
// but we must pass a non-nil one to cache.NewInformer()
AddFunc: nil,
UpdateFunc: nil,
DeleteFunc: nil,
})
labelMap := make(map[string]string)
for _, labelName := range config.NodeLabelsForPV {
labelVal, ok := config.Node.Labels[labelName]
if ok {
labelMap[labelName] = labelVal
}
}
if config.UseAlphaAPI {
nodeAffinity, err := generateNodeAffinity(config.Node)
if err != nil {
return nil, fmt.Errorf("Failed to generate node affinity: %v", err)
}
tmpAnnotations := map[string]string{}
err = StorageNodeAffinityToAlphaAnnotation(tmpAnnotations, nodeAffinity)
if err != nil {
return nil, fmt.Errorf("Failed to convert node affinity to alpha annotation: %v", err)
}
return &Discoverer{
RuntimeConfig: config,
Labels: labelMap,
CleanupTracker: cleanupTracker,
classLister: sharedInformer.Lister(),
nodeAffinityAnn: tmpAnnotations[common.AlphaStorageNodeAffinityAnnotation]}, nil
}
volumeNodeAffinity, err := generateVolumeNodeAffinity(config.Node)
if err != nil {
return nil, fmt.Errorf("Failed to generate volume node affinity: %v", err)
}
return &Discoverer{
RuntimeConfig: config,
Labels: labelMap,
CleanupTracker: cleanupTracker,
classLister: sharedInformer.Lister(),
nodeAffinity: volumeNodeAffinity}, nil
} | go | func NewDiscoverer(config *common.RuntimeConfig, cleanupTracker *deleter.CleanupStatusTracker) (*Discoverer, error) {
sharedInformer := config.InformerFactory.Storage().V1().StorageClasses()
sharedInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
// We don't need an actual event handler for StorageClasses,
// but we must pass a non-nil one to cache.NewInformer()
AddFunc: nil,
UpdateFunc: nil,
DeleteFunc: nil,
})
labelMap := make(map[string]string)
for _, labelName := range config.NodeLabelsForPV {
labelVal, ok := config.Node.Labels[labelName]
if ok {
labelMap[labelName] = labelVal
}
}
if config.UseAlphaAPI {
nodeAffinity, err := generateNodeAffinity(config.Node)
if err != nil {
return nil, fmt.Errorf("Failed to generate node affinity: %v", err)
}
tmpAnnotations := map[string]string{}
err = StorageNodeAffinityToAlphaAnnotation(tmpAnnotations, nodeAffinity)
if err != nil {
return nil, fmt.Errorf("Failed to convert node affinity to alpha annotation: %v", err)
}
return &Discoverer{
RuntimeConfig: config,
Labels: labelMap,
CleanupTracker: cleanupTracker,
classLister: sharedInformer.Lister(),
nodeAffinityAnn: tmpAnnotations[common.AlphaStorageNodeAffinityAnnotation]}, nil
}
volumeNodeAffinity, err := generateVolumeNodeAffinity(config.Node)
if err != nil {
return nil, fmt.Errorf("Failed to generate volume node affinity: %v", err)
}
return &Discoverer{
RuntimeConfig: config,
Labels: labelMap,
CleanupTracker: cleanupTracker,
classLister: sharedInformer.Lister(),
nodeAffinity: volumeNodeAffinity}, nil
} | [
"func",
"NewDiscoverer",
"(",
"config",
"*",
"common",
".",
"RuntimeConfig",
",",
"cleanupTracker",
"*",
"deleter",
".",
"CleanupStatusTracker",
")",
"(",
"*",
"Discoverer",
",",
"error",
")",
"{",
"sharedInformer",
":=",
"config",
".",
"InformerFactory",
".",
"Storage",
"(",
")",
".",
"V1",
"(",
")",
".",
"StorageClasses",
"(",
")",
"\n",
"sharedInformer",
".",
"Informer",
"(",
")",
".",
"AddEventHandler",
"(",
"cache",
".",
"ResourceEventHandlerFuncs",
"{",
"AddFunc",
":",
"nil",
",",
"UpdateFunc",
":",
"nil",
",",
"DeleteFunc",
":",
"nil",
",",
"}",
")",
"\n",
"labelMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"labelName",
":=",
"range",
"config",
".",
"NodeLabelsForPV",
"{",
"labelVal",
",",
"ok",
":=",
"config",
".",
"Node",
".",
"Labels",
"[",
"labelName",
"]",
"\n",
"if",
"ok",
"{",
"labelMap",
"[",
"labelName",
"]",
"=",
"labelVal",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"config",
".",
"UseAlphaAPI",
"{",
"nodeAffinity",
",",
"err",
":=",
"generateNodeAffinity",
"(",
"config",
".",
"Node",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Failed to generate node affinity: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"tmpAnnotations",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"err",
"=",
"StorageNodeAffinityToAlphaAnnotation",
"(",
"tmpAnnotations",
",",
"nodeAffinity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Failed to convert node affinity to alpha annotation: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"Discoverer",
"{",
"RuntimeConfig",
":",
"config",
",",
"Labels",
":",
"labelMap",
",",
"CleanupTracker",
":",
"cleanupTracker",
",",
"classLister",
":",
"sharedInformer",
".",
"Lister",
"(",
")",
",",
"nodeAffinityAnn",
":",
"tmpAnnotations",
"[",
"common",
".",
"AlphaStorageNodeAffinityAnnotation",
"]",
"}",
",",
"nil",
"\n",
"}",
"\n",
"volumeNodeAffinity",
",",
"err",
":=",
"generateVolumeNodeAffinity",
"(",
"config",
".",
"Node",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Failed to generate volume node affinity: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"Discoverer",
"{",
"RuntimeConfig",
":",
"config",
",",
"Labels",
":",
"labelMap",
",",
"CleanupTracker",
":",
"cleanupTracker",
",",
"classLister",
":",
"sharedInformer",
".",
"Lister",
"(",
")",
",",
"nodeAffinity",
":",
"volumeNodeAffinity",
"}",
",",
"nil",
"\n",
"}"
] | // NewDiscoverer creates a Discoverer object that will scan through
// the configured directories and create local PVs for any new directories found | [
"NewDiscoverer",
"creates",
"a",
"Discoverer",
"object",
"that",
"will",
"scan",
"through",
"the",
"configured",
"directories",
"and",
"create",
"local",
"PVs",
"for",
"any",
"new",
"directories",
"found"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/discovery/discovery.go#L52-L99 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/discovery/discovery.go | DiscoverLocalVolumes | func (d *Discoverer) DiscoverLocalVolumes() {
for class, config := range d.DiscoveryMap {
d.discoverVolumesAtPath(class, config)
}
} | go | func (d *Discoverer) DiscoverLocalVolumes() {
for class, config := range d.DiscoveryMap {
d.discoverVolumesAtPath(class, config)
}
} | [
"func",
"(",
"d",
"*",
"Discoverer",
")",
"DiscoverLocalVolumes",
"(",
")",
"{",
"for",
"class",
",",
"config",
":=",
"range",
"d",
".",
"DiscoveryMap",
"{",
"d",
".",
"discoverVolumesAtPath",
"(",
"class",
",",
"config",
")",
"\n",
"}",
"\n",
"}"
] | // DiscoverLocalVolumes reads the configured discovery paths, and creates PVs for the new volumes | [
"DiscoverLocalVolumes",
"reads",
"the",
"configured",
"discovery",
"paths",
"and",
"creates",
"PVs",
"for",
"the",
"new",
"volumes"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/discovery/discovery.go#L154-L158 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/discovery/discovery.go | roundDownCapacityPretty | func roundDownCapacityPretty(capacityBytes int64) int64 {
easyToReadUnitsBytes := []int64{esUtil.GiB, esUtil.MiB}
// Round down to the nearest easy to read unit
// such that there are at least 10 units at that size.
for _, easyToReadUnitBytes := range easyToReadUnitsBytes {
// Round down the capacity to the nearest unit.
size := capacityBytes / easyToReadUnitBytes
if size >= 10 {
return size * easyToReadUnitBytes
}
}
return capacityBytes
} | go | func roundDownCapacityPretty(capacityBytes int64) int64 {
easyToReadUnitsBytes := []int64{esUtil.GiB, esUtil.MiB}
// Round down to the nearest easy to read unit
// such that there are at least 10 units at that size.
for _, easyToReadUnitBytes := range easyToReadUnitsBytes {
// Round down the capacity to the nearest unit.
size := capacityBytes / easyToReadUnitBytes
if size >= 10 {
return size * easyToReadUnitBytes
}
}
return capacityBytes
} | [
"func",
"roundDownCapacityPretty",
"(",
"capacityBytes",
"int64",
")",
"int64",
"{",
"easyToReadUnitsBytes",
":=",
"[",
"]",
"int64",
"{",
"esUtil",
".",
"GiB",
",",
"esUtil",
".",
"MiB",
"}",
"\n",
"for",
"_",
",",
"easyToReadUnitBytes",
":=",
"range",
"easyToReadUnitsBytes",
"{",
"size",
":=",
"capacityBytes",
"/",
"easyToReadUnitBytes",
"\n",
"if",
"size",
">=",
"10",
"{",
"return",
"size",
"*",
"easyToReadUnitBytes",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"capacityBytes",
"\n",
"}"
] | // Round down the capacity to an easy to read value. | [
"Round",
"down",
"the",
"capacity",
"to",
"an",
"easy",
"to",
"read",
"value",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/discovery/discovery.go#L339-L353 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/discovery/discovery.go | GetStorageNodeAffinityFromAnnotation | func GetStorageNodeAffinityFromAnnotation(annotations map[string]string) (*v1.NodeAffinity, error) {
if len(annotations) > 0 && annotations[common.AlphaStorageNodeAffinityAnnotation] != "" {
var affinity v1.NodeAffinity
err := json.Unmarshal([]byte(annotations[common.AlphaStorageNodeAffinityAnnotation]), &affinity)
if err != nil {
return nil, err
}
return &affinity, nil
}
return nil, nil
} | go | func GetStorageNodeAffinityFromAnnotation(annotations map[string]string) (*v1.NodeAffinity, error) {
if len(annotations) > 0 && annotations[common.AlphaStorageNodeAffinityAnnotation] != "" {
var affinity v1.NodeAffinity
err := json.Unmarshal([]byte(annotations[common.AlphaStorageNodeAffinityAnnotation]), &affinity)
if err != nil {
return nil, err
}
return &affinity, nil
}
return nil, nil
} | [
"func",
"GetStorageNodeAffinityFromAnnotation",
"(",
"annotations",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"v1",
".",
"NodeAffinity",
",",
"error",
")",
"{",
"if",
"len",
"(",
"annotations",
")",
">",
"0",
"&&",
"annotations",
"[",
"common",
".",
"AlphaStorageNodeAffinityAnnotation",
"]",
"!=",
"\"\"",
"{",
"var",
"affinity",
"v1",
".",
"NodeAffinity",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"annotations",
"[",
"common",
".",
"AlphaStorageNodeAffinityAnnotation",
"]",
")",
",",
"&",
"affinity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"affinity",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // GetStorageNodeAffinityFromAnnotation gets the json serialized data from PersistentVolume.Annotations
// and converts it to the NodeAffinity type in core. | [
"GetStorageNodeAffinityFromAnnotation",
"gets",
"the",
"json",
"serialized",
"data",
"from",
"PersistentVolume",
".",
"Annotations",
"and",
"converts",
"it",
"to",
"the",
"NodeAffinity",
"type",
"in",
"core",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/discovery/discovery.go#L357-L367 | train |
kubernetes-incubator/external-storage | local-volume/provisioner/pkg/discovery/discovery.go | StorageNodeAffinityToAlphaAnnotation | func StorageNodeAffinityToAlphaAnnotation(annotations map[string]string, affinity *v1.NodeAffinity) error {
if affinity == nil {
return nil
}
json, err := json.Marshal(*affinity)
if err != nil {
return err
}
annotations[common.AlphaStorageNodeAffinityAnnotation] = string(json)
return nil
} | go | func StorageNodeAffinityToAlphaAnnotation(annotations map[string]string, affinity *v1.NodeAffinity) error {
if affinity == nil {
return nil
}
json, err := json.Marshal(*affinity)
if err != nil {
return err
}
annotations[common.AlphaStorageNodeAffinityAnnotation] = string(json)
return nil
} | [
"func",
"StorageNodeAffinityToAlphaAnnotation",
"(",
"annotations",
"map",
"[",
"string",
"]",
"string",
",",
"affinity",
"*",
"v1",
".",
"NodeAffinity",
")",
"error",
"{",
"if",
"affinity",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"json",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"*",
"affinity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"annotations",
"[",
"common",
".",
"AlphaStorageNodeAffinityAnnotation",
"]",
"=",
"string",
"(",
"json",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // StorageNodeAffinityToAlphaAnnotation converts NodeAffinity type to Alpha annotation for use in PersistentVolumes | [
"StorageNodeAffinityToAlphaAnnotation",
"converts",
"NodeAffinity",
"type",
"to",
"Alpha",
"annotation",
"for",
"use",
"in",
"PersistentVolumes"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/discovery/discovery.go#L370-L381 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | newGCECloud | func newGCECloud(config io.Reader) (*Cloud, error) {
projectID, zone, err := getProjectAndZone()
if err != nil {
return nil, err
}
region, err := GetGCERegion(zone)
if err != nil {
return nil, err
}
networkName, err := getNetworkNameViaMetadata()
if err != nil {
return nil, err
}
networkURL := gceNetworkURL(projectID, networkName)
// By default, Kubernetes clusters only run against one zone
managedZones := []string{zone}
tokenSource := google.ComputeTokenSource("")
var nodeTags []string
var nodeInstancePrefix string
if config != nil {
var cfg Config
if err := gcfg.ReadInto(&cfg, config); err != nil {
glog.Errorf("Couldn't read config: %v", err)
return nil, err
}
glog.Infof("Using GCE provider config %+v", cfg)
if cfg.Global.ProjectID != "" {
projectID = cfg.Global.ProjectID
}
if cfg.Global.NetworkName != "" {
if strings.Contains(cfg.Global.NetworkName, "/") {
networkURL = cfg.Global.NetworkName
} else {
networkURL = gceNetworkURL(cfg.Global.ProjectID, cfg.Global.NetworkName)
}
}
if cfg.Global.TokenURL != "" {
tokenSource = NewAltTokenSource(cfg.Global.TokenURL, cfg.Global.TokenBody)
}
nodeTags = cfg.Global.NodeTags
nodeInstancePrefix = cfg.Global.NodeInstancePrefix
if cfg.Global.Multizone {
managedZones = nil // Use all zones in region
}
}
return CreateGCECloud(projectID, region, zone, managedZones, networkURL, nodeTags, nodeInstancePrefix, tokenSource, true /* useMetadataServer */)
} | go | func newGCECloud(config io.Reader) (*Cloud, error) {
projectID, zone, err := getProjectAndZone()
if err != nil {
return nil, err
}
region, err := GetGCERegion(zone)
if err != nil {
return nil, err
}
networkName, err := getNetworkNameViaMetadata()
if err != nil {
return nil, err
}
networkURL := gceNetworkURL(projectID, networkName)
// By default, Kubernetes clusters only run against one zone
managedZones := []string{zone}
tokenSource := google.ComputeTokenSource("")
var nodeTags []string
var nodeInstancePrefix string
if config != nil {
var cfg Config
if err := gcfg.ReadInto(&cfg, config); err != nil {
glog.Errorf("Couldn't read config: %v", err)
return nil, err
}
glog.Infof("Using GCE provider config %+v", cfg)
if cfg.Global.ProjectID != "" {
projectID = cfg.Global.ProjectID
}
if cfg.Global.NetworkName != "" {
if strings.Contains(cfg.Global.NetworkName, "/") {
networkURL = cfg.Global.NetworkName
} else {
networkURL = gceNetworkURL(cfg.Global.ProjectID, cfg.Global.NetworkName)
}
}
if cfg.Global.TokenURL != "" {
tokenSource = NewAltTokenSource(cfg.Global.TokenURL, cfg.Global.TokenBody)
}
nodeTags = cfg.Global.NodeTags
nodeInstancePrefix = cfg.Global.NodeInstancePrefix
if cfg.Global.Multizone {
managedZones = nil // Use all zones in region
}
}
return CreateGCECloud(projectID, region, zone, managedZones, networkURL, nodeTags, nodeInstancePrefix, tokenSource, true /* useMetadataServer */)
} | [
"func",
"newGCECloud",
"(",
"config",
"io",
".",
"Reader",
")",
"(",
"*",
"Cloud",
",",
"error",
")",
"{",
"projectID",
",",
"zone",
",",
"err",
":=",
"getProjectAndZone",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"region",
",",
"err",
":=",
"GetGCERegion",
"(",
"zone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"networkName",
",",
"err",
":=",
"getNetworkNameViaMetadata",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"networkURL",
":=",
"gceNetworkURL",
"(",
"projectID",
",",
"networkName",
")",
"\n",
"managedZones",
":=",
"[",
"]",
"string",
"{",
"zone",
"}",
"\n",
"tokenSource",
":=",
"google",
".",
"ComputeTokenSource",
"(",
"\"\"",
")",
"\n",
"var",
"nodeTags",
"[",
"]",
"string",
"\n",
"var",
"nodeInstancePrefix",
"string",
"\n",
"if",
"config",
"!=",
"nil",
"{",
"var",
"cfg",
"Config",
"\n",
"if",
"err",
":=",
"gcfg",
".",
"ReadInto",
"(",
"&",
"cfg",
",",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Errorf",
"(",
"\"Couldn't read config: %v\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"glog",
".",
"Infof",
"(",
"\"Using GCE provider config %+v\"",
",",
"cfg",
")",
"\n",
"if",
"cfg",
".",
"Global",
".",
"ProjectID",
"!=",
"\"\"",
"{",
"projectID",
"=",
"cfg",
".",
"Global",
".",
"ProjectID",
"\n",
"}",
"\n",
"if",
"cfg",
".",
"Global",
".",
"NetworkName",
"!=",
"\"\"",
"{",
"if",
"strings",
".",
"Contains",
"(",
"cfg",
".",
"Global",
".",
"NetworkName",
",",
"\"/\"",
")",
"{",
"networkURL",
"=",
"cfg",
".",
"Global",
".",
"NetworkName",
"\n",
"}",
"else",
"{",
"networkURL",
"=",
"gceNetworkURL",
"(",
"cfg",
".",
"Global",
".",
"ProjectID",
",",
"cfg",
".",
"Global",
".",
"NetworkName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"cfg",
".",
"Global",
".",
"TokenURL",
"!=",
"\"\"",
"{",
"tokenSource",
"=",
"NewAltTokenSource",
"(",
"cfg",
".",
"Global",
".",
"TokenURL",
",",
"cfg",
".",
"Global",
".",
"TokenBody",
")",
"\n",
"}",
"\n",
"nodeTags",
"=",
"cfg",
".",
"Global",
".",
"NodeTags",
"\n",
"nodeInstancePrefix",
"=",
"cfg",
".",
"Global",
".",
"NodeInstancePrefix",
"\n",
"if",
"cfg",
".",
"Global",
".",
"Multizone",
"{",
"managedZones",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"CreateGCECloud",
"(",
"projectID",
",",
"region",
",",
"zone",
",",
"managedZones",
",",
"networkURL",
",",
"nodeTags",
",",
"nodeInstancePrefix",
",",
"tokenSource",
",",
"true",
")",
"\n",
"}"
] | // newGCECloud creates a new instance of GCECloud. | [
"newGCECloud",
"creates",
"a",
"new",
"instance",
"of",
"GCECloud",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L279-L330 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | translateAffinityType | func translateAffinityType(affinityType v1.ServiceAffinity) string {
switch affinityType {
case v1.ServiceAffinityClientIP:
return gceAffinityTypeClientIP
case v1.ServiceAffinityNone:
return gceAffinityTypeNone
default:
glog.Errorf("Unexpected affinity type: %v", affinityType)
return gceAffinityTypeNone
}
} | go | func translateAffinityType(affinityType v1.ServiceAffinity) string {
switch affinityType {
case v1.ServiceAffinityClientIP:
return gceAffinityTypeClientIP
case v1.ServiceAffinityNone:
return gceAffinityTypeNone
default:
glog.Errorf("Unexpected affinity type: %v", affinityType)
return gceAffinityTypeNone
}
} | [
"func",
"translateAffinityType",
"(",
"affinityType",
"v1",
".",
"ServiceAffinity",
")",
"string",
"{",
"switch",
"affinityType",
"{",
"case",
"v1",
".",
"ServiceAffinityClientIP",
":",
"return",
"gceAffinityTypeClientIP",
"\n",
"case",
"v1",
".",
"ServiceAffinityNone",
":",
"return",
"gceAffinityTypeNone",
"\n",
"default",
":",
"glog",
".",
"Errorf",
"(",
"\"Unexpected affinity type: %v\"",
",",
"affinityType",
")",
"\n",
"return",
"gceAffinityTypeNone",
"\n",
"}",
"\n",
"}"
] | // translate from what K8s supports to what the cloud provider supports for session affinity. | [
"translate",
"from",
"what",
"K8s",
"supports",
"to",
"what",
"the",
"cloud",
"provider",
"supports",
"for",
"session",
"affinity",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1007-L1017 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | DeleteForwardingRule | func (gce *Cloud) DeleteForwardingRule(name string) error {
region, err := GetGCERegion(gce.localZone)
if err != nil {
return err
}
return gce.deleteForwardingRule(name, region)
} | go | func (gce *Cloud) DeleteForwardingRule(name string) error {
region, err := GetGCERegion(gce.localZone)
if err != nil {
return err
}
return gce.deleteForwardingRule(name, region)
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"DeleteForwardingRule",
"(",
"name",
"string",
")",
"error",
"{",
"region",
",",
"err",
":=",
"GetGCERegion",
"(",
"gce",
".",
"localZone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"gce",
".",
"deleteForwardingRule",
"(",
"name",
",",
"region",
")",
"\n",
"}"
] | // DeleteForwardingRule deletes the forwarding rule | [
"DeleteForwardingRule",
"deletes",
"the",
"forwarding",
"rule"
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1488-L1494 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | DeleteTargetPool | func (gce *Cloud) DeleteTargetPool(name string, hc *compute.HttpHealthCheck) error {
region, err := GetGCERegion(gce.localZone)
if err != nil {
return err
}
return gce.deleteTargetPool(name, region, hc)
} | go | func (gce *Cloud) DeleteTargetPool(name string, hc *compute.HttpHealthCheck) error {
region, err := GetGCERegion(gce.localZone)
if err != nil {
return err
}
return gce.deleteTargetPool(name, region, hc)
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"DeleteTargetPool",
"(",
"name",
"string",
",",
"hc",
"*",
"compute",
".",
"HttpHealthCheck",
")",
"error",
"{",
"region",
",",
"err",
":=",
"GetGCERegion",
"(",
"gce",
".",
"localZone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"gce",
".",
"deleteTargetPool",
"(",
"name",
",",
"region",
",",
"hc",
")",
"\n",
"}"
] | // DeleteTargetPool deletes the given target pool. | [
"DeleteTargetPool",
"deletes",
"the",
"given",
"target",
"pool",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1497-L1503 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | UpdateFirewall | func (gce *Cloud) UpdateFirewall(name, desc string, sourceRanges netsets.IPNet, ports []int64, hostNames []string) error {
region, err := GetGCERegion(gce.localZone)
if err != nil {
return err
}
// TODO: This completely breaks modularity in the cloudprovider but the methods
// shared with the TCPLoadBalancer take v1.ServicePorts.
svcPorts := []v1.ServicePort{}
// TODO: Currently the only consumer of this method is the GCE L7
// loadbalancer controller, which never needs a protocol other than TCP.
// We should pipe through a mapping of port:protocol and default to TCP
// if UDP ports are required. This means the method signature will change,
// forcing downstream clients to refactor interfaces.
for _, p := range ports {
svcPorts = append(svcPorts, v1.ServicePort{Port: int32(p), Protocol: v1.ProtocolTCP})
}
hosts, err := gce.getInstancesByNames(hostNames)
if err != nil {
return err
}
return gce.updateFirewall(name, region, desc, sourceRanges, svcPorts, hosts)
} | go | func (gce *Cloud) UpdateFirewall(name, desc string, sourceRanges netsets.IPNet, ports []int64, hostNames []string) error {
region, err := GetGCERegion(gce.localZone)
if err != nil {
return err
}
// TODO: This completely breaks modularity in the cloudprovider but the methods
// shared with the TCPLoadBalancer take v1.ServicePorts.
svcPorts := []v1.ServicePort{}
// TODO: Currently the only consumer of this method is the GCE L7
// loadbalancer controller, which never needs a protocol other than TCP.
// We should pipe through a mapping of port:protocol and default to TCP
// if UDP ports are required. This means the method signature will change,
// forcing downstream clients to refactor interfaces.
for _, p := range ports {
svcPorts = append(svcPorts, v1.ServicePort{Port: int32(p), Protocol: v1.ProtocolTCP})
}
hosts, err := gce.getInstancesByNames(hostNames)
if err != nil {
return err
}
return gce.updateFirewall(name, region, desc, sourceRanges, svcPorts, hosts)
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"UpdateFirewall",
"(",
"name",
",",
"desc",
"string",
",",
"sourceRanges",
"netsets",
".",
"IPNet",
",",
"ports",
"[",
"]",
"int64",
",",
"hostNames",
"[",
"]",
"string",
")",
"error",
"{",
"region",
",",
"err",
":=",
"GetGCERegion",
"(",
"gce",
".",
"localZone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"svcPorts",
":=",
"[",
"]",
"v1",
".",
"ServicePort",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"ports",
"{",
"svcPorts",
"=",
"append",
"(",
"svcPorts",
",",
"v1",
".",
"ServicePort",
"{",
"Port",
":",
"int32",
"(",
"p",
")",
",",
"Protocol",
":",
"v1",
".",
"ProtocolTCP",
"}",
")",
"\n",
"}",
"\n",
"hosts",
",",
"err",
":=",
"gce",
".",
"getInstancesByNames",
"(",
"hostNames",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"gce",
".",
"updateFirewall",
"(",
"name",
",",
"region",
",",
"desc",
",",
"sourceRanges",
",",
"svcPorts",
",",
"hosts",
")",
"\n",
"}"
] | // UpdateFirewall applies the given firewall rule as an update to an existing
// firewall rule with the same name. | [
"UpdateFirewall",
"applies",
"the",
"given",
"firewall",
"rule",
"as",
"an",
"update",
"to",
"an",
"existing",
"firewall",
"rule",
"with",
"the",
"same",
"name",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1614-L1635 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | DeleteGlobalStaticIP | func (gce *Cloud) DeleteGlobalStaticIP(name string) error {
op, err := gce.service.GlobalAddresses.Delete(gce.projectID, name).Do()
if err != nil {
return err
}
return gce.waitForGlobalOp(op)
} | go | func (gce *Cloud) DeleteGlobalStaticIP(name string) error {
op, err := gce.service.GlobalAddresses.Delete(gce.projectID, name).Do()
if err != nil {
return err
}
return gce.waitForGlobalOp(op)
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"DeleteGlobalStaticIP",
"(",
"name",
"string",
")",
"error",
"{",
"op",
",",
"err",
":=",
"gce",
".",
"service",
".",
"GlobalAddresses",
".",
"Delete",
"(",
"gce",
".",
"projectID",
",",
"name",
")",
".",
"Do",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"gce",
".",
"waitForGlobalOp",
"(",
"op",
")",
"\n",
"}"
] | // DeleteGlobalStaticIP deletes a global static IP by name. | [
"DeleteGlobalStaticIP",
"deletes",
"a",
"global",
"static",
"IP",
"by",
"name",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1656-L1662 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | GetGlobalStaticIP | func (gce *Cloud) GetGlobalStaticIP(name string) (address *compute.Address, err error) {
return gce.service.GlobalAddresses.Get(gce.projectID, name).Do()
} | go | func (gce *Cloud) GetGlobalStaticIP(name string) (address *compute.Address, err error) {
return gce.service.GlobalAddresses.Get(gce.projectID, name).Do()
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"GetGlobalStaticIP",
"(",
"name",
"string",
")",
"(",
"address",
"*",
"compute",
".",
"Address",
",",
"err",
"error",
")",
"{",
"return",
"gce",
".",
"service",
".",
"GlobalAddresses",
".",
"Get",
"(",
"gce",
".",
"projectID",
",",
"name",
")",
".",
"Do",
"(",
")",
"\n",
"}"
] | // GetGlobalStaticIP returns the global static IP by name. | [
"GetGlobalStaticIP",
"returns",
"the",
"global",
"static",
"IP",
"by",
"name",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1665-L1667 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | GetURLMap | func (gce *Cloud) GetURLMap(name string) (*compute.UrlMap, error) {
return gce.service.UrlMaps.Get(gce.projectID, name).Do()
} | go | func (gce *Cloud) GetURLMap(name string) (*compute.UrlMap, error) {
return gce.service.UrlMaps.Get(gce.projectID, name).Do()
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"GetURLMap",
"(",
"name",
"string",
")",
"(",
"*",
"compute",
".",
"UrlMap",
",",
"error",
")",
"{",
"return",
"gce",
".",
"service",
".",
"UrlMaps",
".",
"Get",
"(",
"gce",
".",
"projectID",
",",
"name",
")",
".",
"Do",
"(",
")",
"\n",
"}"
] | // UrlMap management
// GetURLMap returns the URLMap by name. | [
"UrlMap",
"management",
"GetURLMap",
"returns",
"the",
"URLMap",
"by",
"name",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1672-L1674 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | CreateURLMap | func (gce *Cloud) CreateURLMap(backend *compute.BackendService, name string) (*compute.UrlMap, error) {
urlMap := &compute.UrlMap{
Name: name,
DefaultService: backend.SelfLink,
}
op, err := gce.service.UrlMaps.Insert(gce.projectID, urlMap).Do()
if err != nil {
return nil, err
}
if err = gce.waitForGlobalOp(op); err != nil {
return nil, err
}
return gce.GetURLMap(name)
} | go | func (gce *Cloud) CreateURLMap(backend *compute.BackendService, name string) (*compute.UrlMap, error) {
urlMap := &compute.UrlMap{
Name: name,
DefaultService: backend.SelfLink,
}
op, err := gce.service.UrlMaps.Insert(gce.projectID, urlMap).Do()
if err != nil {
return nil, err
}
if err = gce.waitForGlobalOp(op); err != nil {
return nil, err
}
return gce.GetURLMap(name)
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"CreateURLMap",
"(",
"backend",
"*",
"compute",
".",
"BackendService",
",",
"name",
"string",
")",
"(",
"*",
"compute",
".",
"UrlMap",
",",
"error",
")",
"{",
"urlMap",
":=",
"&",
"compute",
".",
"UrlMap",
"{",
"Name",
":",
"name",
",",
"DefaultService",
":",
"backend",
".",
"SelfLink",
",",
"}",
"\n",
"op",
",",
"err",
":=",
"gce",
".",
"service",
".",
"UrlMaps",
".",
"Insert",
"(",
"gce",
".",
"projectID",
",",
"urlMap",
")",
".",
"Do",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"gce",
".",
"waitForGlobalOp",
"(",
"op",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"gce",
".",
"GetURLMap",
"(",
"name",
")",
"\n",
"}"
] | // CreateURLMap creates an url map, using the given backend service as the default service. | [
"CreateURLMap",
"creates",
"an",
"url",
"map",
"using",
"the",
"given",
"backend",
"service",
"as",
"the",
"default",
"service",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1677-L1690 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | UpdateURLMap | func (gce *Cloud) UpdateURLMap(urlMap *compute.UrlMap) (*compute.UrlMap, error) {
op, err := gce.service.UrlMaps.Update(gce.projectID, urlMap.Name, urlMap).Do()
if err != nil {
return nil, err
}
if err = gce.waitForGlobalOp(op); err != nil {
return nil, err
}
return gce.service.UrlMaps.Get(gce.projectID, urlMap.Name).Do()
} | go | func (gce *Cloud) UpdateURLMap(urlMap *compute.UrlMap) (*compute.UrlMap, error) {
op, err := gce.service.UrlMaps.Update(gce.projectID, urlMap.Name, urlMap).Do()
if err != nil {
return nil, err
}
if err = gce.waitForGlobalOp(op); err != nil {
return nil, err
}
return gce.service.UrlMaps.Get(gce.projectID, urlMap.Name).Do()
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"UpdateURLMap",
"(",
"urlMap",
"*",
"compute",
".",
"UrlMap",
")",
"(",
"*",
"compute",
".",
"UrlMap",
",",
"error",
")",
"{",
"op",
",",
"err",
":=",
"gce",
".",
"service",
".",
"UrlMaps",
".",
"Update",
"(",
"gce",
".",
"projectID",
",",
"urlMap",
".",
"Name",
",",
"urlMap",
")",
".",
"Do",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"gce",
".",
"waitForGlobalOp",
"(",
"op",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"gce",
".",
"service",
".",
"UrlMaps",
".",
"Get",
"(",
"gce",
".",
"projectID",
",",
"urlMap",
".",
"Name",
")",
".",
"Do",
"(",
")",
"\n",
"}"
] | // UpdateURLMap applies the given UrlMap as an update, and returns the new UrlMap. | [
"UpdateURLMap",
"applies",
"the",
"given",
"UrlMap",
"as",
"an",
"update",
"and",
"returns",
"the",
"new",
"UrlMap",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1693-L1702 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | ListURLMaps | func (gce *Cloud) ListURLMaps() (*compute.UrlMapList, error) {
// TODO: use PageToken to list all not just the first 500
return gce.service.UrlMaps.List(gce.projectID).Do()
} | go | func (gce *Cloud) ListURLMaps() (*compute.UrlMapList, error) {
// TODO: use PageToken to list all not just the first 500
return gce.service.UrlMaps.List(gce.projectID).Do()
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"ListURLMaps",
"(",
")",
"(",
"*",
"compute",
".",
"UrlMapList",
",",
"error",
")",
"{",
"return",
"gce",
".",
"service",
".",
"UrlMaps",
".",
"List",
"(",
"gce",
".",
"projectID",
")",
".",
"Do",
"(",
")",
"\n",
"}"
] | // ListURLMaps lists all URLMaps in the project. | [
"ListURLMaps",
"lists",
"all",
"URLMaps",
"in",
"the",
"project",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1717-L1720 | train |
kubernetes-incubator/external-storage | snapshot/pkg/cloudprovider/providers/gce/gce.go | GetTargetHTTPProxy | func (gce *Cloud) GetTargetHTTPProxy(name string) (*compute.TargetHttpProxy, error) {
return gce.service.TargetHttpProxies.Get(gce.projectID, name).Do()
} | go | func (gce *Cloud) GetTargetHTTPProxy(name string) (*compute.TargetHttpProxy, error) {
return gce.service.TargetHttpProxies.Get(gce.projectID, name).Do()
} | [
"func",
"(",
"gce",
"*",
"Cloud",
")",
"GetTargetHTTPProxy",
"(",
"name",
"string",
")",
"(",
"*",
"compute",
".",
"TargetHttpProxy",
",",
"error",
")",
"{",
"return",
"gce",
".",
"service",
".",
"TargetHttpProxies",
".",
"Get",
"(",
"gce",
".",
"projectID",
",",
"name",
")",
".",
"Do",
"(",
")",
"\n",
"}"
] | // TargetHttpProxy management
// GetTargetHTTPProxy returns the UrlMap by name. | [
"TargetHttpProxy",
"management",
"GetTargetHTTPProxy",
"returns",
"the",
"UrlMap",
"by",
"name",
"."
] | fbfedbf60da4e5ee25a3151bfe8504f3e3281319 | https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1725-L1727 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.