2020-08-08 20:23:27 +02:00
|
|
|
package dorkbox.netUtil
|
|
|
|
|
2020-08-18 22:34:13 +02:00
|
|
|
import dorkbox.executor.Executor
|
|
|
|
|
2020-08-08 20:23:27 +02:00
|
|
|
object VirtualEth {
|
2021-04-06 23:42:45 +02:00
|
|
|
/**
|
|
|
|
* Gets the version number.
|
|
|
|
*/
|
2022-03-03 00:39:25 +01:00
|
|
|
const val version = "2.9.1"
|
2021-04-06 23:42:45 +02:00
|
|
|
|
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-08 20:23:27 +02:00
|
|
|
}
|
|
|
|
|
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-08 20:23:27 +02:00
|
|
|
}
|
|
|
|
|
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.")
|
|
|
|
}
|
2020-08-08 20:23:27 +02:00
|
|
|
}
|
|
|
|
}
|