@@ -68,21 +68,29 @@ def init_session():
6868
6969 return True
7070
71- # By default, the "bridge-id" external id in the Bridge table is the
72- # same as "xs-network-uuids". This may be overridden by defining a
73- # "nicira-bridge-id" key in the "other_config" field of the network
74- # record of XAPI.
75- def get_bridge_id (br_name , default = None ):
71+ def get_network_by_bridge (br_name ):
7672 if not init_session ():
7773 s_log .warning ("Failed to get bridge id %s because"
7874 " XAPI session could not be initialized" % br_name )
79- return default
75+ return None
8076
8177 for n in session .xenapi .network .get_all ():
8278 rec = session .xenapi .network .get_record (n )
83- if rec ['bridge' ] != br_name :
84- continue
79+ if rec ['bridge' ] == br_name :
80+ return rec
81+
82+ return None
83+
84+ # By default, the "bridge-id" external id in the Bridge table is the
85+ # same as "xs-network-uuids". This may be overridden by defining a
86+ # "nicira-bridge-id" key in the "other_config" field of the network
87+ # record of XAPI. If nicira-bridge-id is undefined returns default.
88+ # On error returns None.
89+ def get_bridge_id (br_name , default = None ):
90+ rec = get_network_by_bridge (br_name )
91+ if rec :
8592 return rec ['other_config' ].get ('nicira-bridge-id' , default )
93+ return None
8694
8795# By default, the "iface-id" external id in the Interface table is the
8896# same as "xs-vif-uuid". This may be overridden by defining a
@@ -107,13 +115,16 @@ def get_iface_id(if_name, xs_vif_uuid):
107115 s_log .warning ("Could not find XAPI entry for VIF %s" % if_name )
108116 return xs_vif_uuid
109117
110- def set_external_id (table , record , key , value ):
111- col = 'external-ids:"' + key + '"="' + value + '"'
112- cmd = [vsctl , "--timeout=30" , "-vANY:console:emer" , "set" , table , record , col ]
118+ def call_vsctl (args ):
119+ cmd = [vsctl , "--timeout=30" , "-vANY:console:emer" ] + args
113120 exitcode = subprocess .call (cmd )
114121 if exitcode != 0 :
115122 s_log .warning ("Couldn't call ovs-vsctl" )
116123
124+ def set_external_id (table , record , key , value ):
125+ col = 'external-ids:"' + key + '"="' + value + '"'
126+ call_vsctl (["set" , table , record , col ])
127+
117128# XAPI on XenServer 5.6 uses the external-id "network-uuids" for internal
118129# networks, but we now prefer "xs-network-uuids". Look for its use and
119130# write our preferred external-id.
@@ -122,6 +133,25 @@ def update_network_uuids(name, ids):
122133 set_external_id ("Bridge" , name , "xs-network-uuids" ,
123134 ids ["network-uuids" ])
124135
136+ def update_fail_mode (name ):
137+ rec = get_network_by_bridge (name )
138+
139+ if not rec :
140+ return
141+
142+ fail_mode = rec ['other_config' ].get ('vswitch-controller-fail-mode' )
143+
144+ if not fail_mode :
145+ pools = session .xenapi .pool .get_all ()
146+ if len (pools ) == 1 :
147+ prec = session .xenapi .pool .get_record (pools [0 ])
148+ fail_mode = prec ['other_config' ].get ('vswitch-controller-fail-mode' )
149+
150+ if fail_mode not in ['standalone' , 'secure' ]:
151+ fail_mode = 'standalone'
152+
153+ call_vsctl (["set" , "bridge" , name , "fail_mode=" + fail_mode ])
154+
125155def update_bridge_id (name , ids ):
126156 id = get_bridge_id (name , ids .get ("xs-network-uuids" ))
127157
@@ -257,6 +287,7 @@ def main(argv):
257287 # so only check for "network-uuids" on creation.
258288 if name not in bridges :
259289 update_network_uuids (name , ids )
290+ update_fail_mode (name )
260291
261292 if (name not in bridges ) or (bridges [name ] != ids ):
262293 update_bridge_id (name , ids )
0 commit comments