implement ippool
1. support vlan ippool management 2. support calico ippool management Signed-off-by: Duan Jiong <djduanjiong@gmail.com>
This commit is contained in:
37
pkg/simple/client/network/utils/utils.go
Normal file
37
pkg/simple/client/network/utils/utils.go
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
)
|
||||
|
||||
func EthRandomAddr(ip net.IP) string {
|
||||
buf := make([]byte, 2)
|
||||
rand.Read(buf)
|
||||
|
||||
// Clear multicast bit
|
||||
buf[0] &= 0xfe
|
||||
// Set the local bit
|
||||
buf[0] |= 2
|
||||
|
||||
//TODO support ipv6
|
||||
buf = append(buf, []byte(ip)...)
|
||||
return fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5])
|
||||
}
|
||||
Reference in New Issue
Block a user