本文整理汇总了Golang中minilog.Warn函数的典型用法代码示例。如果您正苦于以下问题:Golang Warn函数的具体用法?Golang Warn怎么用?Golang Warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: broadcastListener
// broadcastListener listens for broadcast connection solicitations and connects to
// soliciting nodes.
func (n *Node) broadcastListener() {
listenAddr := net.UDPAddr{
IP: net.IPv4(0, 0, 0, 0),
Port: n.port,
}
ln, err := net.ListenUDP("udp4", &listenAddr)
if err != nil {
log.Fatal("broadcastListener: %v", err)
}
for {
d := make([]byte, 1024)
read, _, err := ln.ReadFromUDP(d)
if err != nil {
log.Error("broadcastListener ReadFromUDP: %v", err)
continue
}
data := strings.Split(string(d[:read]), ":")
if len(data) != 3 {
log.Warn("got malformed udp data: %v", data)
continue
}
if data[0] != "meshage" {
log.Warn("got malformed udp data: %v", data)
continue
}
namespace := data[1]
host := data[2]
if namespace != n.namespace {
log.Debug("got solicitation from namespace %v, dropping", namespace)
continue
}
if host == n.name {
log.Debugln("got solicitation from myself, dropping")
continue
}
log.Debug("got solicitation from %v", host)
// to avoid spamming the node with connections, only 1/8 of the
// nodes should try to connect. If there are < 16 nodes, then
// always try.
if len(n.clients) > SOLICIT_LIMIT {
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
n := r.Intn(SOLICIT_RATIO)
if n != 0 {
log.Debugln("randomly skipping this solicitation")
continue
}
}
go n.dial(host, true)
}
}
示例2: ovsAddPort
// ovsAddPort adds a port to an openvswitch bridge. If the vlan is 0, it will
// not be vlan-tagged.
func ovsAddPort(bridge, tap string, vlan int, host bool) error {
args := []string{
"add-port",
bridge,
tap,
}
// see note in ovsAddBridge.
if len(tap) > 15 {
log.Warn("tap name is longer than 15 characters.. dragons ahead")
}
if vlan != 0 {
args = append(args, fmt.Sprintf("tag=%v", vlan))
}
if host {
args = append(args, "--")
args = append(args, "set")
args = append(args, "Interface")
args = append(args, tap)
args = append(args, "type=internal")
}
if _, err := ovsCmdWrapper(args); err == errAlreadyExists {
return err
} else if err != nil {
return fmt.Errorf("add port failed: %v", err)
}
return nil
}
示例3: hostVMs
// hostVMs is HostVMs without locking cmdLock.
func hostVMs(host string) VMs {
// Compile info command and set it not to record
cmd := minicli.MustCompile("vm info")
cmd.SetRecord(false)
cmd.SetSource(GetNamespaceName())
cmds := makeCommandHosts([]string{host}, cmd)
var vms VMs
// LOCK: see func description.
for resps := range runCommands(cmds...) {
for _, resp := range resps {
if resp.Error != "" {
log.Errorln(resp.Error)
continue
}
if vms2, ok := resp.Data.(VMs); ok {
if vms != nil {
// odd... should only be one vms per host and we're
// querying a single host
log.Warn("so many vms")
}
vms = vms2
}
}
}
return vms
}
示例4: SetRange
// SetRange reserves a range of VLANs for a particular prefix. VLANs are
// allocated in the range [min, max).
func (v *AllocatedVLANs) SetRange(prefix string, min, max int) error {
v.Lock()
defer v.Unlock()
log.Info("setting range for %v: [%v, %v)", prefix, min, max)
// Test for conflicts with other ranges
for prefix2, r := range v.ranges {
if prefix == prefix2 || prefix2 == "" {
continue
}
if min < r.Max && r.Min <= max {
return fmt.Errorf("range overlaps with another namespace: %v", prefix2)
}
}
// Warn if we detect any holes in the range
for i := min; i < max; i++ {
if _, ok := v.byVLAN[i]; ok {
log.Warn("detected hole in VLAN range %v -> %v: %v", min, max, i)
}
}
v.ranges[prefix] = &Range{
Min: min,
Max: max,
Next: min,
}
return nil
}
示例5: ProcessCommand
// Process a prepopulated Command
func ProcessCommand(c *Command) <-chan Responses {
if !c.noOp && c.Call == nil {
log.Fatal("command %v has no callback!", c)
}
respChan := make(chan Responses)
go func() {
if !c.noOp {
c.Call(c, respChan)
}
// Append the command to the history
if c.Record {
history = append(history, c.Original)
if len(history) > HistoryLen && HistoryLen > 0 {
if firstHistoryTruncate {
log.Warn("history length exceeds limit, truncating to %v entries", HistoryLen)
firstHistoryTruncate = false
}
history = history[len(history)-HistoryLen:]
}
}
close(respChan)
}()
return respChan
}
示例6: main
func main() {
// flags
flag.Parse()
logSetup()
if *f_u != "" {
log.Debug("updating with file: %v", *f_u)
err := update(filepath.Join(*f_path, "minirouter"), *f_u)
if err != nil {
log.Errorln(err)
}
return
}
// check for a running instance of minirouter
_, err := os.Stat(filepath.Join(*f_path, "minirouter"))
if err == nil {
if !*f_force {
log.Fatalln("minirouter appears to already be running, override with -force")
}
log.Warn("minirouter may already be running, proceed with caution")
err = os.Remove(filepath.Join(*f_path, "minirouter"))
if err != nil {
log.Fatalln(err)
}
}
log.Debug("using path: %v", *f_path)
// attempt to set up the base path
err = os.MkdirAll(*f_path, os.FileMode(0770))
if err != nil {
log.Fatal("mkdir base path: %v", err)
}
// start the domain socket service
go commandSocketStart()
// signal handling
sig := make(chan os.Signal, 1024)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
<-sig
// cleanup
err = os.Remove(filepath.Join(*f_path, "minirouter"))
if err != nil {
log.Fatalln(err)
}
}
示例7: ParseVLAN
// ParseVLAN parses s and returns a VLAN. If s can be parsed as an integer, the
// resulting integer is returned. If s matches an existing alias, that VLAN is
// returned. Otherwise, returns ErrUnallocated.
func (v *AllocatedVLANs) ParseVLAN(namespace, s string) (int, error) {
v.Lock()
defer v.Unlock()
log.Debug("parsing vlan: %v namespace: %v", s, namespace)
vlan, err := strconv.Atoi(s)
if err == nil {
// Check to ensure that VLAN is sane
if vlan < 0 || vlan >= 4096 {
return 0, errors.New("invalid VLAN (0 <= vlan < 4096)")
}
if alias, ok := v.byVLAN[vlan]; ok && alias != BlacklistedVLAN {
// Warn the user if they supplied an integer and it matches a VLAN
// that has an alias.
log.Warn("VLAN %d has alias %v", vlan, alias)
} else if !ok {
// Blacklist the VLAN if the user entered it manually and we don't
// have an alias for it already.
log.Warn("Blacklisting manually specified VLAN %v", vlan)
v.blacklist(vlan)
}
return vlan, nil
}
// Prepend active namespace if it doesn't look like the user is trying to
// supply a namespace already.
if !strings.Contains(s, AliasSep) {
s = namespace + AliasSep + s
}
if vlan, ok := v.byAlias[s]; ok {
return vlan, nil
}
return 0, ErrUnallocated
}
示例8: RevertNamespace
// RevertNamespace reverts the active namespace (which should match curr) back
// to the old namespace.
func RevertNamespace(old, curr *Namespace) {
namespaceLock.Lock()
defer namespaceLock.Unlock()
// This is very odd and should *never* happen unless something has gone
// horribly wrong.
if namespace != curr.Name {
log.Warn("unexpected namespace, `%v` != `%v`, when reverting to `%v`", namespace, curr, old)
}
if old == nil {
namespace = ""
} else {
namespace = old.Name
}
}
示例9: diskInjectCleanup
// diskInjectCleanup handles unmounting, disconnecting nbd, and removing mount
// directory after diskInject.
func diskInjectCleanup(mntDir, nbdPath string) {
log.Debug("cleaning up vm inject: %s %s", mntDir, nbdPath)
out, err := processWrapper("umount", mntDir)
if err != nil {
log.Error("injectCleanup: %v, %v", out, err)
}
if err := nbd.DisconnectDevice(nbdPath); err != nil {
log.Error("qemu nbd disconnect: %v", err)
log.Warn("minimega was unable to disconnect %v", nbdPath)
}
err = os.Remove(mntDir)
if err != nil {
log.Error("rm mount dir: %v", err)
}
}
示例10: meshageRecipients
// meshageRecipients expands a hosts into a list of hostnames. Supports
// expanding Wildcard to all hosts in the mesh or all hosts in the active
// namespace.
func meshageRecipients(hosts string) ([]string, error) {
ns := GetNamespace()
if hosts == Wildcard {
if ns == nil {
return meshageNode.BroadcastRecipients(), nil
}
recipients := []string{}
// Wildcard expands to all hosts in the namespace, except the local
// host, if included
for host := range ns.Hosts {
if host == hostname {
log.Info("excluding localhost, %v, from `%v`", hostname, Wildcard)
continue
}
recipients = append(recipients, host)
}
return recipients, nil
}
recipients, err := ranges.SplitList(hosts)
if err != nil {
return nil, err
}
// If a namespace is active, warn if the user is trying to mesh send hosts
// outside the namespace
if ns != nil {
for _, host := range recipients {
if !ns.Hosts[host] {
log.Warn("%v is not part of namespace %v", host, ns.Name)
}
}
}
return recipients, nil
}
示例11: getNewTap
// gets a new tap from tapChan and verifies that it doesn't already exist
func getNewTap() (string, error) {
var t string
for {
t = <-tapChan
taps, err := ioutil.ReadDir("/sys/class/net")
if err != nil {
return "", err
}
found := false
for _, v := range taps {
if v.Name() == t {
found = true
log.Warn("tap %v already exists, trying again", t)
}
}
if !found {
break
}
}
return t, nil
}
示例12: ovsAddBridge
// ovsAddBridge creates a new openvswitch bridge. Returns whether the bridge
// was created or not, or any error that occurred.
func ovsAddBridge(name string) (bool, error) {
args := []string{
"add-br",
name,
}
// Linux limits interfaces to IFNAMSIZ bytes which is currently 16,
// including the null byte. We won't return an error as this limit may not
// affect the user but we should at least warn them that openvswitch may
// fail unexectedly.
if len(name) > 15 {
log.Warn("bridge name is longer than 15 characters.. dragons ahead")
}
if _, err := ovsCmdWrapper(args); err == errAlreadyExists {
return false, nil
} else if err != nil {
return false, fmt.Errorf("add bridge failed: %v", err)
}
return true, nil
}
示例13: conflicts
func (vm *BaseVM) conflicts(vm2 *BaseVM) error {
// Return error if two VMs have same name or UUID
if vm.Namespace == vm2.Namespace {
if vm.Name == vm2.Name {
return fmt.Errorf("duplicate VM name: %s", vm.Name)
}
if vm.UUID == vm2.UUID {
return fmt.Errorf("duplicate VM UUID: %s", vm.UUID)
}
}
// Warn if we see two VMs that share a MAC on the same VLAN
for _, n := range vm.Networks {
for _, n2 := range vm2.Networks {
if n.MAC == n2.MAC && n.VLAN == n2.VLAN {
log.Warn("duplicate MAC/VLAN: %v/%v for %v and %v", vm.ID, vm2.ID)
}
}
}
return nil
}
示例14: vmInjectCleanup
// Unmount, disconnect nbd, and remove mount directory
func vmInjectCleanup(mntDir, nbdPath string) {
log.Debug("cleaning up vm inject: %s %s", mntDir, nbdPath)
p := process("umount")
cmd := exec.Command(p, mntDir)
err := cmd.Run()
if err != nil {
log.Error("injectCleanup: %v", err)
}
err = nbd.DisconnectDevice(nbdPath)
if err != nil {
log.Error("qemu nbd disconnect: %v", err)
log.Warn("minimega was unable to disconnect %v", nbdPath)
}
p = process("rm")
cmd = exec.Command(p, "-r", mntDir)
err = cmd.Run()
if err != nil {
log.Error("rm mount dir: %v", err)
}
}
示例15: getRoutes
func (n *Node) getRoutes(m *Message) (map[string][]string, error) {
routeSlices := make(map[string][]string)
n.meshLock.Lock()
defer n.meshLock.Unlock()
for _, v := range m.Recipients {
if v == n.name {
if len(m.Recipients) == 1 {
return nil, fmt.Errorf("cannot mesh send yourself")
}
continue
}
var route string
var ok bool
if route, ok = n.routes[v]; !ok {
log.Warn("no route to host: %v, skipping", v)
continue
}
routeSlices[route] = append(routeSlices[route], v)
}
return routeSlices, nil
}