NetworkUtils/src/dorkbox/netUtil/VirtualEth.kt

33 lines
874 B
Kotlin
Raw Normal View History

package dorkbox.netUtil
2020-08-18 22:34:13 +02:00
import dorkbox.executor.Executor
/**
*
*/
object VirtualEth {
2020-08-18 22:34:13 +02:00
fun add(host: String, guest: String) {
if (Common.OS_LINUX) {
Executor().command("/sbin/ip", "link", "add", "name", host, "type", "veth", "peer", "name", guest).startBlocking()
} else {
throw RuntimeException("NOT IMPL.")
}
}
2020-08-18 22:34:13 +02:00
fun delete(host: String) {
if (Common.OS_LINUX) {
Executor().command("/sbin/ip", "link", "del", host).startBlocking()
} else {
throw RuntimeException("NOT IMPL.")
}
}
2020-08-18 22:34:13 +02:00
fun assignNameSpace(nameSpace: String, guest: String) {
if (Common.OS_LINUX) {
Executor().command("/sbin/ip", "link", "set", "guest", "netns", nameSpace).startBlocking()
} else {
throw RuntimeException("NOT IMPL.")
}
}
}