NetworkUtils/src/dorkbox/netUtil/VirtualEth.kt

35 lines
942 B
Kotlin
Raw Normal View History

package dorkbox.netUtil
2020-08-18 22:34:13 +02:00
import dorkbox.executor.Executor
object VirtualEth {
/**
* Gets the version number.
*/
2022-03-03 00:39:25 +01:00
const val version = "2.9.1"
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) {
2020-08-18 22:35:27 +02:00
Executor().command("/sbin/ip", "link", "set", guest, "netns", nameSpace).startBlocking()
2020-08-18 22:34:13 +02:00
} else {
throw RuntimeException("NOT IMPL.")
}
}
}