bitkeeper revision 1.1108.1.12 (40ffee27o1VPDwZVRgzbC8H1a0rrLQ)

Small fix in error handling.
This commit is contained in:
mjw@wray-m-3.hpl.hp.com committed 2004-07-22 16:41:11 +00:00
1 parent 10cd0830a1
commit f1d52d4e73
2 files changed
+85 -20

No files matched your search

+84 -18
View File
@@ -3,8 +3,58 @@
"""Handler for vnet operations.
"""
from xen.util import Brctl
import sxp
import XendDB
from XendError import XendError
from XendLogging import log
def vnet_cmd(cmd):
out = None
try:
try:
out = file("/proc/vnet/policy", "wb")
sxp.show(cmd, out)
except IOError, ex:
raise XendError(str(ex))
finally:
if out: out.close()
class XendVnetInfo:
vifctl_ops = {'up': 'vif.add', 'down': 'vif.del'}
def __init__(self, config):
self.config = config
self.id = sxp.child_value(config, 'id')
self.id = str(self.id)
self.bridge = sxp.child_value(config, 'bridge')
if not self.bridge:
self.bridge = "vnet%s" % self.id
self.vnetif = sxp.child_value(config, 'vnetif')
if not self.vnetif:
self.vnetif = "vnetif%s" % self.id
def sxpr(self):
return self.config
def configure(self):
log.info("Configuring vnet %s", self.id)
val = vnet_cmd(['vnet.add'] + sxp.children(self.config))
Brctl.bridge_create(self.bridge)
Brctl.vif_bridge_add({'bridge': self.bridge, 'vif': self.vnetif})
return val
def delete(self):
log.info("Deleting vnet %s", self.id)
Brctl.vif_bridge_rem({'bridge': self.bridge, 'vif': self.vnetif})
Brctl.bridge_del(self.bridge)
return vnet_cmd(['vnet.del', self.id])
def vifctl(self, op, vif, vmac):
fn = self.vifctl_ops[op]
return vnet_cmd([fn, ['vif', vif], ['vmac', vmac]])
class XendVnet:
"""Index of all vnets. Singleton.
@@ -16,49 +66,65 @@ class XendVnet:
# Table of vnet info indexed by vnet id.
self.vnet = {}
self.db = XendDB.XendDB(self.dbpath)
self.vnet = self.db.fetchall("")
vnets = self.db.fetchall("")
for config in vnets.values():
info = XendVnetInfo(config)
self.vnet[info.id] = info
try:
info.configure()
except:
log.exception("Error configuring vnet")
def vnet_of_bridge(self, bridge):
"""Get the vnet for a bridge (if any).
@param bridge: bridge name
@return vnet or None
"""
for v in self.vnet.values():
if v.bridge == bridge:
return v
else:
return None
def vnet_ls(self):
"""List all vnets.
"""List all vnet ids.
"""
return self.vnet.keys()
def vnets(self):
"""List all vnets.
"""
return self.vnet.values()
def vnet_get(self, id):
"""Get a vnet.
id vnet id
@param id: vnet id
"""
id = str(id)
return self.vnet.get(id)
def vnet_create(self, info):
def vnet_create(self, config):
"""Create a vnet.
info config
@param config: config
"""
self.vnet_configure(info)
def vnet_configure(self, info):
"""Configure a vnet.
id vnet id
info config
"""
# Need to configure for real.
# Only sync if succeeded - otherwise need to back out.
info = XendVnetInfo(config)
self.vnet[info.id] = info
self.db.save(info.id, info)
self.db.save(info.id, info.sxpr())
info.configure()
def vnet_delete(self, id):
"""Delete a vnet.
id vnet id
@param id: vnet id
"""
# Need to delete for real. What if fails?
if id in self.vnet:
info = self.vnet_get(id)
if info:
del self.vnet[id]
self.db.delete(id)
info.delete()
def instance():
global inst
+1 -2
View File
@@ -161,8 +161,7 @@ class SrvBase(resource.Resource):
sxp.show(['xend.err', str(err)], out=req)
else:
req.setHeader("Content-Type", "text/plain")
req.write('Error in ')
req.write(op)
req.write('Error ')
req.write(': ')
req.write(str(err))
if dfr:
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.