dom0/core: change QubesVm.netvm_vm to QubesVm.netvm
To simplify setters and getters.
This commit is contained in:
parent
4d6899827d
commit
7db35b7ce6
@ -192,7 +192,7 @@ class QubesVm(object):
|
|||||||
def __init__(self, qid, name,
|
def __init__(self, qid, name,
|
||||||
dir_path, conf_file = None,
|
dir_path, conf_file = None,
|
||||||
uses_default_netvm = True,
|
uses_default_netvm = True,
|
||||||
netvm_vm = None,
|
netvm = None,
|
||||||
installed_by_rpm = False,
|
installed_by_rpm = False,
|
||||||
updateable = False,
|
updateable = False,
|
||||||
label = None,
|
label = None,
|
||||||
@ -223,9 +223,9 @@ class QubesVm(object):
|
|||||||
self.conf_file = self.absolute_path(conf_file, name + ".conf")
|
self.conf_file = self.absolute_path(conf_file, name + ".conf")
|
||||||
|
|
||||||
self.uses_default_netvm = uses_default_netvm
|
self.uses_default_netvm = uses_default_netvm
|
||||||
self.netvm_vm = netvm_vm
|
self.netvm = netvm
|
||||||
if netvm_vm is not None:
|
if netvm is not None:
|
||||||
netvm_vm.connected_vms[qid] = self
|
netvm.connected_vms[qid] = self
|
||||||
|
|
||||||
self._mac = mac
|
self._mac = mac
|
||||||
|
|
||||||
@ -355,29 +355,29 @@ class QubesVm(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ip(self):
|
def ip(self):
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
return self.netvm_vm.get_ip_for_vm(self.qid)
|
return self.netvm.get_ip_for_vm(self.qid)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def netmask(self):
|
def netmask(self):
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
return self.netvm_vm.netmask
|
return self.netvm.netmask
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gateway(self):
|
def gateway(self):
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
return self.netvm_vm.gateway
|
return self.netvm.gateway
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def secondary_dns(self):
|
def secondary_dns(self):
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
return self.netvm_vm.secondary_dns
|
return self.netvm.secondary_dns
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -385,7 +385,7 @@ class QubesVm(object):
|
|||||||
def vif(self):
|
def vif(self):
|
||||||
if self.xid < 0:
|
if self.xid < 0:
|
||||||
return None
|
return None
|
||||||
if self.netvm_vm is None:
|
if self.netvm is None:
|
||||||
return None
|
return None
|
||||||
return "vif{0}.+".format(self.xid)
|
return "vif{0}.+".format(self.xid)
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ class QubesVm(object):
|
|||||||
if self.is_netvm():
|
if self.is_netvm():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -425,11 +425,11 @@ class QubesVm(object):
|
|||||||
raise QubesException ("Change 'updateable' flag is not supported. Please use qvm-create.")
|
raise QubesException ("Change 'updateable' flag is not supported. Please use qvm-create.")
|
||||||
|
|
||||||
|
|
||||||
def set_netvm_vm(self, netvm_vm):
|
def set_netvm(self, netvm):
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
self.netvm_vm.connected_vms.pop(self.qid)
|
self.netvm.connected_vms.pop(self.qid)
|
||||||
|
|
||||||
if netvm_vm is None:
|
if netvm is None:
|
||||||
# Set also firewall to block all traffic as discussed in #370
|
# Set also firewall to block all traffic as discussed in #370
|
||||||
if os.path.exists(self.firewall_conf):
|
if os.path.exists(self.firewall_conf):
|
||||||
shutil.copy(self.firewall_conf, "%s/backup/%s-firewall-%s.xml"
|
shutil.copy(self.firewall_conf, "%s/backup/%s-firewall-%s.xml"
|
||||||
@ -437,9 +437,9 @@ class QubesVm(object):
|
|||||||
self.write_firewall_conf({'allow': False, 'allowDns': False,
|
self.write_firewall_conf({'allow': False, 'allowDns': False,
|
||||||
'allowIcmp': False, 'rules': []})
|
'allowIcmp': False, 'rules': []})
|
||||||
else:
|
else:
|
||||||
netvm_vm.connected_vms[self.qid]=self
|
netvm.connected_vms[self.qid]=self
|
||||||
|
|
||||||
self.netvm_vm = netvm_vm
|
self.netvm = netvm
|
||||||
|
|
||||||
def pre_rename(self, new_name):
|
def pre_rename(self, new_name):
|
||||||
pass
|
pass
|
||||||
@ -769,15 +769,15 @@ class QubesVm(object):
|
|||||||
"{0}/qubes_netvm_network".format(domain_path),
|
"{0}/qubes_netvm_network".format(domain_path),
|
||||||
self.network)
|
self.network)
|
||||||
|
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
xs.write('', "{0}/qubes_ip".format(domain_path), self.ip)
|
xs.write('', "{0}/qubes_ip".format(domain_path), self.ip)
|
||||||
xs.write('', "{0}/qubes_netmask".format(domain_path),
|
xs.write('', "{0}/qubes_netmask".format(domain_path),
|
||||||
self.netvm_vm.netmask)
|
self.netvm.netmask)
|
||||||
xs.write('', "{0}/qubes_gateway".format(domain_path),
|
xs.write('', "{0}/qubes_gateway".format(domain_path),
|
||||||
self.netvm_vm.gateway)
|
self.netvm.gateway)
|
||||||
xs.write('',
|
xs.write('',
|
||||||
"{0}/qubes_secondary_dns".format(domain_path),
|
"{0}/qubes_secondary_dns".format(domain_path),
|
||||||
self.netvm_vm.secondary_dns)
|
self.netvm.secondary_dns)
|
||||||
|
|
||||||
tzname = self.get_timezone()
|
tzname = self.get_timezone()
|
||||||
if tzname:
|
if tzname:
|
||||||
@ -817,10 +817,10 @@ class QubesVm(object):
|
|||||||
args['mem'] = str(self.memory)
|
args['mem'] = str(self.memory)
|
||||||
args['maxmem'] = str(self.maxmem)
|
args['maxmem'] = str(self.maxmem)
|
||||||
args['vcpus'] = str(self.vcpus)
|
args['vcpus'] = str(self.vcpus)
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
args['netdev'] = "'mac={mac},script=/etc/xen/scripts/vif-route-qubes,ip={ip}".format(ip=self.ip, mac=self.mac)
|
args['netdev'] = "'mac={mac},script=/etc/xen/scripts/vif-route-qubes,ip={ip}".format(ip=self.ip, mac=self.mac)
|
||||||
if self.netvm_vm.qid != 0:
|
if self.netvm.qid != 0:
|
||||||
args['netdev'] += ",backend={0}".format(self.netvm_vm.name)
|
args['netdev'] += ",backend={0}".format(self.netvm.name)
|
||||||
args['netdev'] += "'"
|
args['netdev'] += "'"
|
||||||
else:
|
else:
|
||||||
args['netdev'] = ''
|
args['netdev'] = ''
|
||||||
@ -936,7 +936,7 @@ class QubesVm(object):
|
|||||||
print >> sys.stderr, "Ooops, there was a problem creating appmenus for {0} VM!".format (self.name)
|
print >> sys.stderr, "Ooops, there was a problem creating appmenus for {0} VM!".format (self.name)
|
||||||
|
|
||||||
def get_clone_attrs(self):
|
def get_clone_attrs(self):
|
||||||
return ['kernel', 'uses_default_kernel', 'netvm_vm', 'uses_default_netvm', \
|
return ['kernel', 'uses_default_kernel', 'netvm', 'uses_default_netvm', \
|
||||||
'memory', 'maxmem', 'kernelopts', 'uses_default_kernelopts', 'services', 'vcpus', \
|
'memory', 'maxmem', 'kernelopts', 'uses_default_kernelopts', 'services', 'vcpus', \
|
||||||
'_mac']
|
'_mac']
|
||||||
|
|
||||||
@ -1224,7 +1224,7 @@ class QubesVm(object):
|
|||||||
raise QubesException ("VM not running!")
|
raise QubesException ("VM not running!")
|
||||||
|
|
||||||
if netvm is None:
|
if netvm is None:
|
||||||
netvm = self.netvm_vm
|
netvm = self.netvm
|
||||||
|
|
||||||
if netvm is None:
|
if netvm is None:
|
||||||
raise QubesException ("NetVM not set!")
|
raise QubesException ("NetVM not set!")
|
||||||
@ -1282,12 +1282,12 @@ class QubesVm(object):
|
|||||||
if self.get_power_state() != "Halted":
|
if self.get_power_state() != "Halted":
|
||||||
raise QubesException ("VM is already running!")
|
raise QubesException ("VM is already running!")
|
||||||
|
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
if self.netvm_vm.qid != 0:
|
if self.netvm.qid != 0:
|
||||||
if not self.netvm_vm.is_running():
|
if not self.netvm.is_running():
|
||||||
if verbose:
|
if verbose:
|
||||||
print >> sys.stderr, "--> Starting NetVM {0}...".format(self.netvm_vm.name)
|
print >> sys.stderr, "--> Starting NetVM {0}...".format(self.netvm.name)
|
||||||
self.netvm_vm.start()
|
self.netvm.start()
|
||||||
|
|
||||||
self.reset_volatile_storage(verbose=verbose)
|
self.reset_volatile_storage(verbose=verbose)
|
||||||
if verbose:
|
if verbose:
|
||||||
@ -1409,7 +1409,7 @@ class QubesVm(object):
|
|||||||
attrs[prop] = str(self.__getattribute__(prop))
|
attrs[prop] = str(self.__getattribute__(prop))
|
||||||
if self._mac is not None:
|
if self._mac is not None:
|
||||||
attrs["mac"] = str(self._mac)
|
attrs["mac"] = str(self._mac)
|
||||||
attrs["netvm_qid"] = str(self.netvm_vm.qid) if self.netvm_vm is not None else "none"
|
attrs["netvm_qid"] = str(self.netvm.qid) if self.netvm is not None else "none"
|
||||||
attrs["template_qid"] = str(self.template_vm.qid) if self.template_vm and not self.is_updateable() else "none"
|
attrs["template_qid"] = str(self.template_vm.qid) if self.template_vm and not self.is_updateable() else "none"
|
||||||
attrs["label"] = self.label.name
|
attrs["label"] = self.label.name
|
||||||
return attrs
|
return attrs
|
||||||
@ -1794,14 +1794,14 @@ class QubesProxyVm(QubesNetVm):
|
|||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
retcode = super(QubesProxyVm, self).start(debug_console=debug_console, verbose=verbose, preparing_dvm=preparing_dvm)
|
retcode = super(QubesProxyVm, self).start(debug_console=debug_console, verbose=verbose, preparing_dvm=preparing_dvm)
|
||||||
self.netvm_vm.add_external_ip_permission(self.get_xid())
|
self.netvm.add_external_ip_permission(self.get_xid())
|
||||||
self.write_netvm_domid_entry()
|
self.write_netvm_domid_entry()
|
||||||
return retcode
|
return retcode
|
||||||
|
|
||||||
def force_shutdown(self):
|
def force_shutdown(self):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
self.netvm_vm.remove_external_ip_permission(self.get_xid())
|
self.netvm.remove_external_ip_permission(self.get_xid())
|
||||||
super(QubesProxyVm, self).force_shutdown()
|
super(QubesProxyVm, self).force_shutdown()
|
||||||
|
|
||||||
def create_xenstore_entries(self, xid = None):
|
def create_xenstore_entries(self, xid = None):
|
||||||
@ -1823,7 +1823,7 @@ class QubesProxyVm(QubesNetVm):
|
|||||||
xid = self.get_xid()
|
xid = self.get_xid()
|
||||||
|
|
||||||
xs.write('', "/local/domain/{0}/qubes_netvm_domid".format(xid),
|
xs.write('', "/local/domain/{0}/qubes_netvm_domid".format(xid),
|
||||||
"{0}".format(self.netvm_vm.get_xid()))
|
"{0}".format(self.netvm.get_xid()))
|
||||||
|
|
||||||
def write_iptables_xenstore_entry(self):
|
def write_iptables_xenstore_entry(self):
|
||||||
xs.rm('', "/local/domain/{0}/qubes_iptables_domainrules".format(self.get_xid()))
|
xs.rm('', "/local/domain/{0}/qubes_iptables_domainrules".format(self.get_xid()))
|
||||||
@ -1892,9 +1892,9 @@ class QubesProxyVm(QubesNetVm):
|
|||||||
iptables += " -j {0}\n".format(rules_action)
|
iptables += " -j {0}\n".format(rules_action)
|
||||||
|
|
||||||
if conf["allowDns"]:
|
if conf["allowDns"]:
|
||||||
# PREROUTING does DNAT to NetVM DNSes, so we need self.netvm_vm. properties
|
# PREROUTING does DNAT to NetVM DNSes, so we need self.netvm. properties
|
||||||
iptables += "-A FORWARD -i {0} -p udp -d {1} --dport 53 -j ACCEPT\n".format(vif,self.netvm_vm.gateway)
|
iptables += "-A FORWARD -i {0} -p udp -d {1} --dport 53 -j ACCEPT\n".format(vif,self.netvm.gateway)
|
||||||
iptables += "-A FORWARD -i {0} -p udp -d {1} --dport 53 -j ACCEPT\n".format(vif,self.netvm_vm.secondary_dns)
|
iptables += "-A FORWARD -i {0} -p udp -d {1} --dport 53 -j ACCEPT\n".format(vif,self.netvm.secondary_dns)
|
||||||
if conf["allowIcmp"]:
|
if conf["allowIcmp"]:
|
||||||
iptables += "-A FORWARD -i {0} -p icmp -j ACCEPT\n".format(vif)
|
iptables += "-A FORWARD -i {0} -p icmp -j ACCEPT\n".format(vif)
|
||||||
|
|
||||||
@ -1910,7 +1910,7 @@ class QubesProxyVm(QubesNetVm):
|
|||||||
|
|
||||||
def get_xml_attrs(self):
|
def get_xml_attrs(self):
|
||||||
attrs = super(QubesProxyVm, self).get_xml_attrs()
|
attrs = super(QubesProxyVm, self).get_xml_attrs()
|
||||||
attrs["netvm_qid"] = str(self.netvm_vm.qid) if self.netvm_vm is not None else "none"
|
attrs["netvm_qid"] = str(self.netvm.qid) if self.netvm is not None else "none"
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
class QubesDom0NetVm(QubesNetVm):
|
class QubesDom0NetVm(QubesNetVm):
|
||||||
@ -1992,8 +1992,8 @@ class QubesDisposableVm(QubesVm):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ip(self):
|
def ip(self):
|
||||||
if self.netvm_vm is not None:
|
if self.netvm is not None:
|
||||||
return self.netvm_vm.get_ip_for_dispvm(self.dispid)
|
return self.netvm.get_ip_for_dispvm(self.dispid)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -2106,7 +2106,7 @@ class QubesVmCollection(dict):
|
|||||||
vm = QubesAppVm (qid=qid, name=name, template_vm=template_vm,
|
vm = QubesAppVm (qid=qid, name=name, template_vm=template_vm,
|
||||||
dir_path=dir_path, conf_file=conf_file,
|
dir_path=dir_path, conf_file=conf_file,
|
||||||
private_img=private_img,
|
private_img=private_img,
|
||||||
netvm_vm = self.get_default_netvm_vm(),
|
netvm = self.get_default_netvm(),
|
||||||
kernel = self.get_default_kernel(),
|
kernel = self.get_default_kernel(),
|
||||||
uses_default_kernel = True,
|
uses_default_kernel = True,
|
||||||
updateable=updateable,
|
updateable=updateable,
|
||||||
@ -2122,7 +2122,7 @@ class QubesVmCollection(dict):
|
|||||||
|
|
||||||
qid = self.get_new_unused_qid()
|
qid = self.get_new_unused_qid()
|
||||||
vm = QubesDisposableVm (qid=qid, name=name, template_vm=template_vm,
|
vm = QubesDisposableVm (qid=qid, name=name, template_vm=template_vm,
|
||||||
netvm_vm = self.get_default_netvm_vm(),
|
netvm = self.get_default_netvm(),
|
||||||
label=label, dispid=dispid)
|
label=label, dispid=dispid)
|
||||||
|
|
||||||
if not self.verify_new_vm (vm):
|
if not self.verify_new_vm (vm):
|
||||||
@ -2140,7 +2140,7 @@ class QubesVmCollection(dict):
|
|||||||
dir_path=dir_path, conf_file=conf_file,
|
dir_path=dir_path, conf_file=conf_file,
|
||||||
root_img=root_img, private_img=private_img,
|
root_img=root_img, private_img=private_img,
|
||||||
installed_by_rpm=installed_by_rpm,
|
installed_by_rpm=installed_by_rpm,
|
||||||
netvm_vm = self.get_default_netvm_vm(),
|
netvm = self.get_default_netvm(),
|
||||||
kernel = self.get_default_kernel(),
|
kernel = self.get_default_kernel(),
|
||||||
uses_default_kernel = True)
|
uses_default_kernel = True)
|
||||||
|
|
||||||
@ -2182,7 +2182,7 @@ class QubesVmCollection(dict):
|
|||||||
self[vm.qid]=vm
|
self[vm.qid]=vm
|
||||||
|
|
||||||
if self.default_fw_netvm_qid is None:
|
if self.default_fw_netvm_qid is None:
|
||||||
self.set_default_fw_netvm_vm(vm)
|
self.set_default_fw_netvm(vm)
|
||||||
|
|
||||||
# by default ClockVM is the first NetVM
|
# by default ClockVM is the first NetVM
|
||||||
if self.clockvm_qid is None:
|
if self.clockvm_qid is None:
|
||||||
@ -2204,14 +2204,14 @@ class QubesVmCollection(dict):
|
|||||||
updateable=updateable,
|
updateable=updateable,
|
||||||
kernel = self.get_default_kernel(),
|
kernel = self.get_default_kernel(),
|
||||||
uses_default_kernel = True,
|
uses_default_kernel = True,
|
||||||
netvm_vm = self.get_default_fw_netvm_vm())
|
netvm = self.get_default_fw_netvm())
|
||||||
|
|
||||||
if not self.verify_new_vm (vm):
|
if not self.verify_new_vm (vm):
|
||||||
assert False, "Wrong VM description!"
|
assert False, "Wrong VM description!"
|
||||||
self[vm.qid]=vm
|
self[vm.qid]=vm
|
||||||
|
|
||||||
if self.default_netvm_qid is None:
|
if self.default_netvm_qid is None:
|
||||||
self.set_default_netvm_vm(vm)
|
self.set_default_netvm(vm)
|
||||||
|
|
||||||
if self.updatevm_qid is None:
|
if self.updatevm_qid is None:
|
||||||
self.set_updatevm_vm(vm)
|
self.set_updatevm_vm(vm)
|
||||||
@ -2228,11 +2228,11 @@ class QubesVmCollection(dict):
|
|||||||
else:
|
else:
|
||||||
return self[self.default_template_qid]
|
return self[self.default_template_qid]
|
||||||
|
|
||||||
def set_default_netvm_vm(self, vm):
|
def set_default_netvm(self, vm):
|
||||||
assert vm.is_netvm(), "VM {0} does not provide network!".format(vm.name)
|
assert vm.is_netvm(), "VM {0} does not provide network!".format(vm.name)
|
||||||
self.default_netvm_qid = vm.qid
|
self.default_netvm_qid = vm.qid
|
||||||
|
|
||||||
def get_default_netvm_vm(self):
|
def get_default_netvm(self):
|
||||||
if self.default_netvm_qid is None:
|
if self.default_netvm_qid is None:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
@ -2245,11 +2245,11 @@ class QubesVmCollection(dict):
|
|||||||
def get_default_kernel(self):
|
def get_default_kernel(self):
|
||||||
return self.default_kernel
|
return self.default_kernel
|
||||||
|
|
||||||
def set_default_fw_netvm_vm(self, vm):
|
def set_default_fw_netvm(self, vm):
|
||||||
assert vm.is_netvm(), "VM {0} does not provide network!".format(vm.name)
|
assert vm.is_netvm(), "VM {0} does not provide network!".format(vm.name)
|
||||||
self.default_fw_netvm_qid = vm.qid
|
self.default_fw_netvm_qid = vm.qid
|
||||||
|
|
||||||
def get_default_fw_netvm_vm(self):
|
def get_default_fw_netvm(self):
|
||||||
if self.default_fw_netvm_qid is None:
|
if self.default_fw_netvm_qid is None:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
@ -2487,22 +2487,22 @@ class QubesVmCollection(dict):
|
|||||||
else:
|
else:
|
||||||
vm.uses_default_netvm = True if kwargs["uses_default_netvm"] == "True" else False
|
vm.uses_default_netvm = True if kwargs["uses_default_netvm"] == "True" else False
|
||||||
if vm.uses_default_netvm is True:
|
if vm.uses_default_netvm is True:
|
||||||
netvm_vm = self.get_default_netvm_vm()
|
netvm = self.get_default_netvm()
|
||||||
kwargs.pop("netvm_qid")
|
kwargs.pop("netvm_qid")
|
||||||
else:
|
else:
|
||||||
if kwargs["netvm_qid"] == "none" or kwargs["netvm_qid"] is None:
|
if kwargs["netvm_qid"] == "none" or kwargs["netvm_qid"] is None:
|
||||||
netvm_vm = None
|
netvm = None
|
||||||
kwargs.pop("netvm_qid")
|
kwargs.pop("netvm_qid")
|
||||||
else:
|
else:
|
||||||
netvm_qid = int(kwargs.pop("netvm_qid"))
|
netvm_qid = int(kwargs.pop("netvm_qid"))
|
||||||
if netvm_qid not in self:
|
if netvm_qid not in self:
|
||||||
netvm_vm = None
|
netvm = None
|
||||||
else:
|
else:
|
||||||
netvm_vm = self[netvm_qid]
|
netvm = self[netvm_qid]
|
||||||
|
|
||||||
vm.netvm_vm = netvm_vm
|
vm.netvm = netvm
|
||||||
if netvm_vm:
|
if netvm:
|
||||||
netvm_vm.connected_vms[vm.qid] = vm
|
netvm.connected_vms[vm.qid] = vm
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
@ -2664,7 +2664,7 @@ class QubesVmCollection(dict):
|
|||||||
else:
|
else:
|
||||||
kwargs["template_vm"] = template_vm
|
kwargs["template_vm"] = template_vm
|
||||||
|
|
||||||
kwargs["netvm_vm"] = self.get_default_netvm_vm()
|
kwargs["netvm"] = self.get_default_netvm()
|
||||||
|
|
||||||
if kwargs["label"] is not None:
|
if kwargs["label"] is not None:
|
||||||
if kwargs["label"] not in QubesVmLabels:
|
if kwargs["label"] not in QubesVmLabels:
|
||||||
@ -2687,8 +2687,8 @@ class QubesVmCollection(dict):
|
|||||||
if self.default_netvm_qid is not None:
|
if self.default_netvm_qid is not None:
|
||||||
clockvm = self[self.default_netvm_qid]
|
clockvm = self[self.default_netvm_qid]
|
||||||
# Find root of netvm chain
|
# Find root of netvm chain
|
||||||
while clockvm.netvm_vm is not None:
|
while clockvm.netvm is not None:
|
||||||
clockvm = clockvm.netvm_vm
|
clockvm = clockvm.netvm
|
||||||
|
|
||||||
self.clockvm_qid = clockvm.qid
|
self.clockvm_qid = clockvm.qid
|
||||||
|
|
||||||
|
@ -635,21 +635,21 @@ def backup_restore_prepare(backup_dir, options = {}, host_collection = None):
|
|||||||
vms_to_restore[vm.name]['missing-template'] = True
|
vms_to_restore[vm.name]['missing-template'] = True
|
||||||
vms_to_restore[vm.name]['good-to-go'] = False
|
vms_to_restore[vm.name]['good-to-go'] = False
|
||||||
|
|
||||||
if vm.netvm_vm is None:
|
if vm.netvm is None:
|
||||||
vms_to_restore[vm.name]['netvm'] = None
|
vms_to_restore[vm.name]['netvm'] = None
|
||||||
else:
|
else:
|
||||||
netvm_name = vm.netvm_vm.name
|
netvm_name = vm.netvm.name
|
||||||
vms_to_restore[vm.name]['netvm'] = netvm_name
|
vms_to_restore[vm.name]['netvm'] = netvm_name
|
||||||
netvm_vm_on_host = host_collection.get_vm_by_name (netvm_name)
|
netvm_on_host = host_collection.get_vm_by_name (netvm_name)
|
||||||
|
|
||||||
# No netvm on the host?
|
# No netvm on the host?
|
||||||
if not ((netvm_vm_on_host is not None) and netvm_vm_on_host.is_netvm()):
|
if not ((netvm_on_host is not None) and netvm_on_host.is_netvm()):
|
||||||
|
|
||||||
# Maybe the (custom) netvm is in the backup?
|
# Maybe the (custom) netvm is in the backup?
|
||||||
netvm_vm_on_backup = backup_collection.get_vm_by_name (netvm_name)
|
netvm_on_backup = backup_collection.get_vm_by_name (netvm_name)
|
||||||
if not ((netvm_vm_on_backup is not None) and netvm_vm_on_backup.is_netvm):
|
if not ((netvm_on_backup is not None) and netvm_on_backup.is_netvm):
|
||||||
if options['use-default-netvm']:
|
if options['use-default-netvm']:
|
||||||
vms_to_restore[vm.name]['netvm'] = host_collection.get_default_netvm_vm().name
|
vms_to_restore[vm.name]['netvm'] = host_collection.get_default_netvm().name
|
||||||
vm.uses_default_netvm = True
|
vm.uses_default_netvm = True
|
||||||
elif options['use-none-netvm']:
|
elif options['use-none-netvm']:
|
||||||
vms_to_restore[vm.name]['netvm'] = None
|
vms_to_restore[vm.name]['netvm'] = None
|
||||||
@ -701,7 +701,7 @@ def backup_restore_print_summary(restore_info, print_callback = print_stdout):
|
|||||||
|
|
||||||
"netvm": {"func": "'n/a' if vm.is_netvm() else\
|
"netvm": {"func": "'n/a' if vm.is_netvm() else\
|
||||||
('*' if vm.uses_default_netvm else '') +\
|
('*' if vm.uses_default_netvm else '') +\
|
||||||
vm_info['netvm'] if vm.netvm_vm is not None else '-'"},
|
vm_info['netvm'] if vm.netvm is not None else '-'"},
|
||||||
|
|
||||||
"label" : {"func" : "vm.label.name"},
|
"label" : {"func" : "vm.label.name"},
|
||||||
}
|
}
|
||||||
@ -876,7 +876,7 @@ def backup_restore_do(backup_dir, restore_info, host_collection = None, print_ca
|
|||||||
|
|
||||||
if not vm.uses_default_netvm:
|
if not vm.uses_default_netvm:
|
||||||
uses_default_netvm = False
|
uses_default_netvm = False
|
||||||
netvm_vm = host_collection.get_vm_by_name (vm_info['netvm']) if vm_info['netvm'] is not None else None
|
netvm = host_collection.get_vm_by_name (vm_info['netvm']) if vm_info['netvm'] is not None else None
|
||||||
else:
|
else:
|
||||||
uses_default_netvm = True
|
uses_default_netvm = True
|
||||||
|
|
||||||
@ -907,7 +907,7 @@ def backup_restore_do(backup_dir, restore_info, host_collection = None, print_ca
|
|||||||
|
|
||||||
if vm.is_proxyvm() and not uses_default_netvm:
|
if vm.is_proxyvm() and not uses_default_netvm:
|
||||||
new_vm.uses_default_netvm = False
|
new_vm.uses_default_netvm = False
|
||||||
new_vm.netvm_vm = netvm_vm
|
new_vm.netvm = netvm
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_vm.verify_files()
|
new_vm.verify_files()
|
||||||
@ -941,7 +941,7 @@ def backup_restore_do(backup_dir, restore_info, host_collection = None, print_ca
|
|||||||
|
|
||||||
if not vm.uses_default_netvm:
|
if not vm.uses_default_netvm:
|
||||||
uses_default_netvm = False
|
uses_default_netvm = False
|
||||||
netvm_vm = host_collection.get_vm_by_name (vm_info['netvm']) if vm_info['netvm'] is not None else None
|
netvm = host_collection.get_vm_by_name (vm_info['netvm']) if vm_info['netvm'] is not None else None
|
||||||
else:
|
else:
|
||||||
uses_default_netvm = True
|
uses_default_netvm = True
|
||||||
|
|
||||||
@ -964,7 +964,7 @@ def backup_restore_do(backup_dir, restore_info, host_collection = None, print_ca
|
|||||||
|
|
||||||
if not uses_default_netvm:
|
if not uses_default_netvm:
|
||||||
new_vm.uses_default_netvm = False
|
new_vm.uses_default_netvm = False
|
||||||
new_vm.netvm_vm = netvm_vm
|
new_vm.netvm = netvm
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_vm.create_appmenus(verbose=True)
|
new_vm.create_appmenus(verbose=True)
|
||||||
|
@ -33,9 +33,9 @@ def get_netvm():
|
|||||||
qvm_collection.lock_db_for_reading()
|
qvm_collection.lock_db_for_reading()
|
||||||
qvm_collection.load()
|
qvm_collection.load()
|
||||||
qvm_collection.unlock_db()
|
qvm_collection.unlock_db()
|
||||||
netvm = qvm_collection.get_default_netvm_vm()
|
netvm = qvm_collection.get_default_netvm()
|
||||||
while netvm.netvm_vm is not None:
|
while netvm.netvm is not None:
|
||||||
netvm = netvm.netvm_vm
|
netvm = netvm.netvm
|
||||||
if netvm is None or netvm.name == 'dom0':
|
if netvm is None or netvm.name == 'dom0':
|
||||||
print >> sys.stderr, 'There seems to be no dedicated default netvm, aborting.'
|
print >> sys.stderr, 'There seems to be no dedicated default netvm, aborting.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -30,8 +30,8 @@ import sys
|
|||||||
|
|
||||||
def handle_vm(vms, label, new_value = None):
|
def handle_vm(vms, label, new_value = None):
|
||||||
functions = { # label: [ getter, setter ],
|
functions = { # label: [ getter, setter ],
|
||||||
'default-netvm': [ 'get_default_netvm_vm', 'set_default_netvm_vm' ],
|
'default-netvm': [ 'get_default_netvm', 'set_default_netvm' ],
|
||||||
'default-fw-netvm': [ 'get_default_fw_netvm_vm', 'set_default_fw_netvm_vm' ],
|
'default-fw-netvm': [ 'get_default_fw_netvm', 'set_default_fw_netvm' ],
|
||||||
'default-template': [ 'get_default_template_vm', 'set_default_template_vm' ],
|
'default-template': [ 'get_default_template_vm', 'set_default_template_vm' ],
|
||||||
'clockvm': [ 'get_clockvm_vm', 'set_clockvm_vm' ],
|
'clockvm': [ 'get_clockvm_vm', 'set_clockvm_vm' ],
|
||||||
'updatevm': [ 'get_updatevm_vm', 'set_updatevm_vm' ],
|
'updatevm': [ 'get_updatevm_vm', 'set_updatevm_vm' ],
|
||||||
|
@ -52,8 +52,8 @@ fields = {
|
|||||||
|
|
||||||
"netvm": {"func": "'n/a' if vm.is_netvm() and not vm.is_proxyvm() else\
|
"netvm": {"func": "'n/a' if vm.is_netvm() and not vm.is_proxyvm() else\
|
||||||
('*' if vm.uses_default_netvm else '') +\
|
('*' if vm.uses_default_netvm else '') +\
|
||||||
qvm_collection[vm.netvm_vm.qid].name\
|
qvm_collection[vm.netvm.qid].name\
|
||||||
if vm.netvm_vm is not None else '-'"},
|
if vm.netvm is not None else '-'"},
|
||||||
|
|
||||||
"ip" : {"func": "vm.ip"},
|
"ip" : {"func": "vm.ip"},
|
||||||
"netmask" : {"func": "vm.netmask"},
|
"netmask" : {"func": "vm.netmask"},
|
||||||
|
@ -39,8 +39,8 @@ def do_list(vm):
|
|||||||
print fmt.format ("type", vm.type)
|
print fmt.format ("type", vm.type)
|
||||||
if vm.template_vm is not None:
|
if vm.template_vm is not None:
|
||||||
print fmt.format ("template", vm.template_vm.name)
|
print fmt.format ("template", vm.template_vm.name)
|
||||||
if vm.netvm_vm is not None:
|
if vm.netvm is not None:
|
||||||
print fmt.format ("netvm", vm.netvm_vm.name)
|
print fmt.format ("netvm", vm.netvm.name)
|
||||||
print fmt.format ("updateable?", vm.is_updateable())
|
print fmt.format ("updateable?", vm.is_updateable())
|
||||||
print fmt.format ("installed by RPM?", vm.installed_by_rpm)
|
print fmt.format ("installed by RPM?", vm.installed_by_rpm)
|
||||||
print fmt.format ("dir", vm.dir_path)
|
print fmt.format ("dir", vm.dir_path)
|
||||||
@ -134,30 +134,30 @@ def set_netvm(vms, vm, args):
|
|||||||
|
|
||||||
netvm = args[0]
|
netvm = args[0]
|
||||||
if netvm == "none":
|
if netvm == "none":
|
||||||
netvm_vm = None
|
netvm = None
|
||||||
vm.uses_default_netvm = False
|
vm.uses_default_netvm = False
|
||||||
elif netvm == "default":
|
elif netvm == "default":
|
||||||
netvm_vm = vms.get_default_netvm_vm()
|
netvm = vms.get_default_netvm()
|
||||||
vm.uses_default_netvm = True
|
vm.uses_default_netvm = True
|
||||||
else:
|
else:
|
||||||
netvm_vm = vms.get_vm_by_name (netvm)
|
netvm = vms.get_vm_by_name (netvm)
|
||||||
if netvm_vm is None:
|
if netvm is None:
|
||||||
print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(netvm)
|
print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(netvm)
|
||||||
exit(1)
|
exit(1)
|
||||||
if not netvm_vm.is_netvm():
|
if not netvm.is_netvm():
|
||||||
print >> sys.stderr, "VM '{0}' is not a NetVM".format(netvm)
|
print >> sys.stderr, "VM '{0}' is not a NetVM".format(netvm)
|
||||||
exit (1)
|
exit (1)
|
||||||
vm.uses_default_netvm = False
|
vm.uses_default_netvm = False
|
||||||
|
|
||||||
vm.set_netvm_vm(netvm_vm)
|
vm.set_netvm(netvm)
|
||||||
if not vm.is_running():
|
if not vm.is_running():
|
||||||
return
|
return
|
||||||
# this can fail if VM was not connected to any NetVM
|
# this can fail if VM was not connected to any NetVM
|
||||||
subprocess.call(["xl", "network-detach", vm.name, "0"], stderr=subprocess.PIPE)
|
subprocess.call(["xl", "network-detach", vm.name, "0"], stderr=subprocess.PIPE)
|
||||||
if vm.netvm_vm is None:
|
if vm.netvm is None:
|
||||||
return
|
return
|
||||||
if not vm.netvm_vm.is_running():
|
if not vm.netvm.is_running():
|
||||||
subprocess.check_call(["qvm-start", vm.netvm_vm.name])
|
subprocess.check_call(["qvm-start", vm.netvm.name])
|
||||||
# refresh IP, DNS etc
|
# refresh IP, DNS etc
|
||||||
vm.create_xenstore_entries()
|
vm.create_xenstore_entries()
|
||||||
vm.attach_network(verbose = True)
|
vm.attach_network(verbose = True)
|
||||||
|
@ -31,8 +31,8 @@ qvm_collection = None
|
|||||||
|
|
||||||
def get_netvm_of_vm(vm):
|
def get_netvm_of_vm(vm):
|
||||||
netvm = vm
|
netvm = vm
|
||||||
while netvm.netvm_vm is not None:
|
while netvm.netvm is not None:
|
||||||
netvm = netvm.netvm_vm
|
netvm = netvm.netvm
|
||||||
if netvm is None or netvm.name == 'dom0':
|
if netvm is None or netvm.name == 'dom0':
|
||||||
print >> sys.stderr, 'There seems to be no network connected to ClockVM, aborting.'
|
print >> sys.stderr, 'There seems to be no network connected to ClockVM, aborting.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user