Commit dad51817 by Zoltan Karsa

ip sup

parent fb783689
iptables -I FORWARD -m state -d $1 --state NEW,RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 10.5.1.3 --dport 3389 -j DNAT --to-destination 192.168.122.28:3389
\ No newline at end of file
import libvirt
def fwd_port(dom, guest_port, host_port):
ifaces = dom.interfaceAddresses(libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, 0)
def show_ip(dom):
ifaces = dom.interfaceAddresses(libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, 0)
for (name, val) in ifaces.iteritems():
if val['addrs']:
for ipaddr in val['addrs']:
if ipaddr['type'] == libvirt.VIR_IP_ADDR_TYPE_IPV4:
print(ipaddr['addr'] + " VIR_IP_ADDR_TYPE_IPV4")
elif ipaddr['type'] == libvirt.VIR_IP_ADDR_TYPE_IPV6:
print(ipaddr['addr'] + " VIR_IP_ADDR_TYPE_IPV6")
\ No newline at end of file
......@@ -4,6 +4,8 @@ import uuid
from jinja2 import Environment, select_autoescape, FileSystemLoader
import subprocess
from utils import fwd_port, show_ip
try:
conn = libvirt.open("qemu:///system")
except libvirt.libvirtError:
......@@ -68,6 +70,11 @@ print(dom.info())
print("Type stop, to shutdown vm!")
cmd = input()
while cmd != "stop":
cmdarr = cmd.split()
if cmdarr[0] == "fwd":
fwd_port(dom, int(cmdarr[1]), int(cmdarr[2]))
elif cmdarr[0] == "showip":
show_ip(dom)
cmd = input()
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment