def change_qos(self, _xv): meta_path = self._meta_path(_xv.vps_id) if not os.path.exists(meta_path): xv = self.load_vps_meta(_xv.vps_id, is_trash=True) xv.vif_ext.bandwidth = _xv.vif_ext.bandwidth bandwidth = float(_xv.vif_ext.bandwidth or 0) vif_name = xv.vif_ext.ifname self.save_vps_meta(xv, is_trash=True) else: xv = self._load_vps_meta(meta_path) if not _xv.vif_ext or not xv.vif_ext: return xv.vif_ext.bandwidth = _xv.vif_ext.bandwidth bandwidth = float(_xv.vif_ext.bandwidth or 0) vif_name = xv.vif_ext.ifname self.save_vps_meta(xv) if conf.USE_OVS: if xv.is_running(): ovsops = OVSOps() ovsops.unset_traffic_limit(vif_name) ovsops.set_traffic_limit(vif_name, int(bandwidth * 1000)) self.loginfo(xv, "updated vif=%s bandwidth to %s Mbps" % (vif_name, bandwidth)) if not xv.wait_until_reachable(5): raise Exception("ip unreachable!") else: # if xv.stop(): # self.loginfo(xv, "vps stopped") # else: # xv.destroy() # self.loginfo(xv, "vps cannot shutdown, destroyed it") self.create_xen_config(xv)
def change_qos(self, _xv): meta_path = self._meta_path(_xv.vps_id) if not os.path.exists(meta_path): xv = self.load_vps_meta(_xv.vps_id, is_trash=True) xv.vif_ext.bandwidth = _xv.vif_ext.bandwidth bandwidth = float(_xv.vif_ext.bandwidth or 0) vif_name = xv.vif_ext.ifname self.save_vps_meta(xv, is_trash=True) else: xv = self._load_vps_meta(meta_path) if not _xv.vif_ext or not xv.vif_ext: return xv.vif_ext.bandwidth = _xv.vif_ext.bandwidth bandwidth = float(_xv.vif_ext.bandwidth or 0) vif_name = xv.vif_ext.ifname self.save_vps_meta(xv) if conf.USE_OVS: if xv.is_running(): ovsops = OVSOps() ovsops.unset_traffic_limit(vif_name) ovsops.set_traffic_limit(vif_name, int(bandwidth * 1000)) self.loginfo( xv, "updated vif=%s bandwidth to %s Mbps" % (vif_name, bandwidth)) if not xv.wait_until_reachable(5): raise Exception("ip unreachable!") else: # if xv.stop(): # self.loginfo(xv, "vps stopped") # else: # xv.destroy() # self.loginfo(xv, "vps cannot shutdown, destroyed it") self.create_xen_config(xv)
def main(): bridge = args[0] vif_name = args[1] logger = Log("vps_mgr", config=conf) vpsops = VPSOps(logger) logger.debug("set %s" % vif_name) try: ovsops = OVSOps() om = re.match(r'^\w+?(\d+)\w*?$', vif_name) if not om: print >> sys.stderr, "wrong vif format %s" % (vif_name) return 1 vps_id = int(om.group(1)) xv = vpsops.load_vps_meta(vps_id) vif = xv.vifs.get(vif_name) if not vif: logger.error("no vif %s in metadata of %s" % (vif_name, vps_id)) return 1 ofport = ovsops.find_ofport_by_name(vif_name) if ofport < 0: logger.error( "vif %s ofport=%s, fix it by delete the port from bridge " % (vif_name, ofport)) ovsops.del_port_from_bridge(bridge, vif_name) ovsops.add_port_to_bridge(bridge, vif_name) ofport = ovsops.find_ofport_by_name(vif_name) if ofport < 0: logger.error("vif %s ofport=%s, impossible " % (vif_name, ofport)) if ofport >= 0: ovsops.set_mac_filter(bridge, ofport, vif.ip_dict.keys()) ovsops.unset_traffic_limit(vif_name) bandwidth = float(vif.bandwidth or 0) ovsops.set_traffic_limit(vif_name, int(bandwidth * 1000)) print "set vif %s bandwidth %sm/s" % (vif_name, vif.bandwidth) return 0 except Exception, e: logger.exception(e) print >> sys.stderr, str(e) return 1
def main(): bridge = args[0] vif_name = args[1] logger = Log("vps_mgr", config=conf) vpsops = VPSOps(logger) logger.debug("set %s" % vif_name) try: ovsops = OVSOps() om = re.match(r"^\w+?(\d+)\w*?$", vif_name) if not om: print >> sys.stderr, "wrong vif format %s" % (vif_name) return 1 vps_id = int(om.group(1)) xv = vpsops.load_vps_meta(vps_id) vif = xv.vifs.get(vif_name) if not vif: logger.error("no vif %s in metadata of %s" % (vif_name, vps_id)) return 1 ofport = ovsops.find_ofport_by_name(vif_name) if ofport < 0: logger.error("vif %s ofport=%s, fix it by delete the port from bridge " % (vif_name, ofport)) ovsops.del_port_from_bridge(bridge, vif_name) ovsops.add_port_to_bridge(bridge, vif_name) ofport = ovsops.find_ofport_by_name(vif_name) if ofport < 0: logger.error("vif %s ofport=%s, impossible " % (vif_name, ofport)) if ofport >= 0: ovsops.set_mac_filter(bridge, ofport, vif.ip_dict.keys()) ovsops.unset_traffic_limit(vif_name) bandwidth = float(vif.bandwidth or 0) ovsops.set_traffic_limit(vif_name, int(bandwidth * 1000)) print "set vif %s bandwidth %sm/s" % (vif_name, vif.bandwidth) return 0 except Exception, e: logger.exception(e) print >> sys.stderr, str(e) return 1