def check_vlan_bridge(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = CheckVlanBridgeResponse()
        if not linux.is_bridge(cmd.bridgeName):
            rsp.error = "can not find vlan bridge[%s]" % cmd.bridgeName
            rsp.success = False

        return jsonobject.dumps(rsp)
Esempio n. 2
0
    def check_vlan_bridge(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = CheckVlanBridgeResponse()
        if not linux.is_bridge(cmd.bridgeName):
            rsp.error = "can not find vlan bridge[%s]" % cmd.bridgeName
            rsp.success = False
        else:
            self._ifup_device_if_down(cmd.physicalInterfaceName)

        return jsonobject.dumps(rsp)
 def create_vlan_bridge(self, req):
     cmd = jsonobject.loads(req[http.REQUEST_BODY])
     rsp = CreateVlanBridgeResponse()
     if linux.is_bridge(cmd.bridgeName):
         logger.debug('%s is a bridge device, no need to create bridge' % cmd.physicalInterfaceName)
         return jsonobject.dumps(rsp)
     
     try:
         linux.create_vlan_bridge(cmd.bridgeName, cmd.physicalInterfaceName, cmd.vlan)
         logger.debug('successfully realize vlan bridge[name:%s, vlan:%s] from device[%s]' % (cmd.bridgeName, cmd.vlan, cmd.physicalInterfaceName))
     except Exception as e:
         logger.warning(traceback.format_exc())
         rsp.error = 'unable to create vlan bridge[name:%s, vlan:%s] from device[%s], because %s' % (cmd.bridgeName, cmd.vlan, cmd.physicalInterfaceName, str(e))
         rsp.success = False
         
     return jsonobject.dumps(rsp)
 def _setup_docker_bridge(self):
     #enable bridge. use default l2network setting.
     br_dev = 'br_%s' % self.br_dev
     if not linux.is_bridge(br_dev):
         linux.create_bridge(br_dev, br_dev)
 
     #set docker args
     rhel_docker_config = '/etc/sysconfig/docker'
     ubuntu_docker_config = '/etc/default/docker'
 
     if os.path.exists(rhel_docker_config):
         open(rhel_docker_config, 'w').write('other_args="-b=%s"' % br_dev)
         shell.ShellCmd('service docker restart')()
 
     if os.path.exists(ubuntu_docker_config):
         open(ubuntu_docker_config, 'w').write('other_args="-b=%s"' % \
                 br_dev)
         shell.ShellCmd('service docker restart')()