本文整理汇总了Golang中github.com/openshift/openshift-sdn/pkg/netutils.GetNodeIP函数的典型用法代码示例。如果您正苦于以下问题:Golang GetNodeIP函数的具体用法?Golang GetNodeIP怎么用?Golang GetNodeIP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetNodeIP函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BaseInit
// Called by plug factory functions to initialize the generic plugin instance
func (oc *OvsController) BaseInit(registry *Registry, flowController FlowController, pluginHooks PluginHooks, hostname string, selfIP string) error {
if hostname == "" {
output, err := kexec.New().Command("uname", "-n").CombinedOutput()
if err != nil {
return err
}
hostname = strings.TrimSpace(string(output))
}
if selfIP == "" {
var err error
selfIP, err = netutils.GetNodeIP(hostname)
if err != nil {
return err
}
}
log.Infof("Self IP: %s.", selfIP)
oc.pluginHooks = pluginHooks
oc.Registry = registry
oc.flowController = flowController
oc.localIP = selfIP
oc.hostName = hostname
oc.VNIDMap = make(map[string]uint)
oc.sig = make(chan struct{})
oc.podNetworkReady = make(chan struct{})
oc.adminNamespaces = make([]string, 0)
oc.services = make(map[string]api.Service)
return nil
}
示例2: GetNodeIP
func GetNodeIP(node *kapi.Node) (string, error) {
if len(node.Status.Addresses) > 0 {
return node.Status.Addresses[0].Address, nil
} else {
return netutils.GetNodeIP(node.Name)
}
}
示例3: WatchNodes
func (registry *Registry) WatchNodes(receiver chan<- *NodeEvent) error {
eventQueue := registry.runEventQueue("Nodes")
nodeAddressMap := map[types.UID]string{}
for {
eventType, obj, err := eventQueue.Pop()
if err != nil {
return err
}
node := obj.(*kapi.Node)
nodeIP := ""
if len(node.Status.Addresses) > 0 {
nodeIP = node.Status.Addresses[0].Address
} else {
nodeIP, err = netutils.GetNodeIP(node.ObjectMeta.Name)
if err != nil {
return err
}
}
switch eventType {
case watch.Added, watch.Modified:
oldNodeIP, ok := nodeAddressMap[node.ObjectMeta.UID]
if ok && (oldNodeIP == nodeIP) {
continue
}
receiver <- &NodeEvent{Type: Added, Node: node}
nodeAddressMap[node.ObjectMeta.UID] = nodeIP
case watch.Deleted:
receiver <- &NodeEvent{Type: Deleted, Node: node}
delete(nodeAddressMap, node.ObjectMeta.UID)
}
}
}
示例4: WatchNodes
func (registry *Registry) WatchNodes(receiver chan<- *osdnapi.NodeEvent, ready chan<- bool, start <-chan string, stop <-chan bool) error {
eventQueue, startVersion := registry.createAndRunEventQueue("Node", ready, start)
nodeAddressMap, err := registry.getNodeAddressMap()
if err != nil {
return err
}
checkCondition := true
for {
eventType, obj, err := getEvent(eventQueue, startVersion, &checkCondition)
if err != nil {
return err
}
node := obj.(*kapi.Node)
nodeIP := ""
if len(node.Status.Addresses) > 0 {
nodeIP = node.Status.Addresses[0].Address
} else {
nodeIP, err = netutils.GetNodeIP(node.ObjectMeta.Name)
if err != nil {
return err
}
}
switch eventType {
case watch.Added:
receiver <- &osdnapi.NodeEvent{Type: osdnapi.Added, Node: osdnapi.Node{Name: node.ObjectMeta.Name, IP: nodeIP}}
nodeAddressMap[node.ObjectMeta.UID] = nodeIP
case watch.Modified:
oldNodeIP, ok := nodeAddressMap[node.ObjectMeta.UID]
if ok && oldNodeIP != nodeIP {
// Node Added event will handle update subnet if there is ip mismatch
receiver <- &osdnapi.NodeEvent{Type: osdnapi.Added, Node: osdnapi.Node{Name: node.ObjectMeta.Name, IP: nodeIP}}
nodeAddressMap[node.ObjectMeta.UID] = nodeIP
}
case watch.Deleted:
receiver <- &osdnapi.NodeEvent{Type: osdnapi.Deleted, Node: osdnapi.Node{Name: node.ObjectMeta.Name}}
delete(nodeAddressMap, node.ObjectMeta.UID)
}
}
}
示例5: GetNodes
func (registry *Registry) GetNodes() ([]osdnapi.Node, string, error) {
knodes, err := registry.kClient.Nodes().List(kapi.ListOptions{})
if err != nil {
return nil, "", err
}
nodes := make([]osdnapi.Node, 0, len(knodes.Items))
for _, node := range knodes.Items {
var nodeIP string
if len(node.Status.Addresses) > 0 {
nodeIP = node.Status.Addresses[0].Address
} else {
nodeIP, err = netutils.GetNodeIP(node.ObjectMeta.Name)
if err != nil {
return nil, "", err
}
}
nodes = append(nodes, osdnapi.Node{Name: node.ObjectMeta.Name, IP: nodeIP})
}
return nodes, knodes.ListMeta.ResourceVersion, nil
}
示例6: NewNodePlugin
// Called by higher layers to create the plugin SDN node instance
func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclient.Client, hostname string, selfIP string, iptablesSyncPeriod time.Duration, mtu uint) (api.OsdnNodePlugin, error) {
if !IsOpenShiftNetworkPlugin(pluginName) {
return nil, nil
}
log.Infof("Initializing SDN node of type %q with configured hostname %q (IP %q), iptables sync period %q", pluginName, hostname, selfIP, iptablesSyncPeriod.String())
if hostname == "" {
output, err := kexec.New().Command("uname", "-n").CombinedOutput()
if err != nil {
return nil, err
}
hostname = strings.TrimSpace(string(output))
log.Infof("Resolved hostname to %q", hostname)
}
if selfIP == "" {
var err error
selfIP, err = netutils.GetNodeIP(hostname)
if err != nil {
log.V(5).Infof("Failed to determine node address from hostname %s; using default interface (%v)", hostname, err)
defaultIP, err := kubeutilnet.ChooseHostInterface()
if err != nil {
return nil, err
}
selfIP = defaultIP.String()
log.Infof("Resolved IP address to %q", selfIP)
}
}
plugin := &OsdnNode{
multitenant: IsOpenShiftMultitenantNetworkPlugin(pluginName),
registry: newRegistry(osClient, kClient),
localIP: selfIP,
hostName: hostname,
vnids: newVnidMap(),
podNetworkReady: make(chan struct{}),
iptablesSyncPeriod: iptablesSyncPeriod,
mtu: mtu,
}
return plugin, nil
}
示例7: BaseInit
// Called by plug factory functions to initialize the generic plugin instance
func (oc *OvsController) BaseInit(registry *Registry, flowController FlowController, pluginHooks PluginHooks, hostname string, selfIP string) error {
if hostname == "" {
output, err := kexec.New().Command("uname", "-n").CombinedOutput()
if err != nil {
return err
}
hostname = strings.TrimSpace(string(output))
}
if selfIP == "" {
var err error
selfIP, err = netutils.GetNodeIP(hostname)
if err != nil {
log.V(5).Infof("Failed to determine node address from hostname %s; using default interface (%v)", hostname, err)
defaultIP, err := kubeutilnet.ChooseHostInterface()
if err != nil {
return err
}
selfIP = defaultIP.String()
}
}
log.Infof("Self IP: %s.", selfIP)
oc.pluginHooks = pluginHooks
oc.Registry = registry
oc.flowController = flowController
oc.localIP = selfIP
oc.hostName = hostname
oc.VNIDMap = make(map[string]uint)
oc.sig = make(chan struct{})
oc.podNetworkReady = make(chan struct{})
oc.adminNamespaces = make([]string, 0)
oc.services = make(map[string]api.Service)
return nil
}