def add_tunnel_port(self, name, tunnel_type, remote_ip, local_ip=None, key=None, ofport=None): """ Creates a tunnel port. :param name: Port name to be created :param tunnel_type: Type of tunnel (gre or vxlan) :param remote_ip: Remote IP address of tunnel :param local_ip: Local IP address of tunnel :param key: Key of GRE or VNI of VxLAN :param ofport: Requested OpenFlow port number """ options = 'remote_ip=%(remote_ip)s' % locals() if key: options += ',key=%(key)s' % locals() if local_ip: options += ',local_ip=%(local_ip)s' % locals() args = [ 'Interface', name, 'type=%s' % tunnel_type, 'options:%s' % options ] if ofport: args.append('ofport_request=%(ofport)s' % locals()) command_add = ovs_vsctl.VSCtlCommand('add-port', (self.br_name, name)) command_set = ovs_vsctl.VSCtlCommand('set', args) self.run_command([command_add, command_set])
def set_qos(self, port_name, type='linux-htb', max_rate=None, queues=None): """ Sets a Qos rule and creates Queues on the given port. """ queues = queues if queues else [] command_qos = ovs_vsctl.VSCtlCommand('set-qos', [port_name, type, max_rate]) command_queue = ovs_vsctl.VSCtlCommand('set-queue', [port_name, queues]) self.run_command([command_qos, command_queue]) if command_qos.result and command_queue.result: return command_qos.result + command_queue.result return None
def del_qos(self, port_name): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Deletes the Qos rule on the given port. """ command = ovs_vsctl.VSCtlCommand('del-qos', [port_name]) self.run_command([command])
def get_quantum_ports(self, port_name): LOG.debug('port_name %s', port_name) command = ovs_vsctl.VSCtlCommand( 'list-ifaces-verbose', [dpid_lib.dpid_to_str(self.datapath_id), port_name]) self.run_command([command]) if command.result: return command.result[0] return None
def del_controller(self): """ Deletes the configured OpenFlow controller address. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl del-controller <bridge> """ command = ovs_vsctl.VSCtlCommand('del-controller', [self.br_name]) self.run_command([command])
def del_port(self, port_name): """ Deletes a port on OVS instance. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl del-port <bridge> <port> """ command = ovs_vsctl.VSCtlCommand('del-port', (self.br_name, port_name)) self.run_command([command])
def clear_db_attribute(self, table, record, column): """ Clears values from 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl clear TBL REC COL """ command = ovs_vsctl.VSCtlCommand('clear', (table, record, column)) self.run_command([command])
def set_controller(self, controllers): """ Sets the OpenFlow controller address. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl set-controller <bridge> <target>... """ command = ovs_vsctl.VSCtlCommand('set-controller', [self.br_name]) command.args.extend(controllers) self.run_command([command])
def get_quantum_ports(self, port_name): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) LOG.debug('port_name %s', port_name) command = ovs_vsctl.VSCtlCommand( 'list-ifaces-verbose', [dpid_lib.dpid_to_str(self.datapath_id), port_name]) self.run_command([command]) if command.result: return command.result[0] return None
def get_port_name_list(self): """ Gets a list of all ports on OVS instance. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl list-ports <bridge> """ command = ovs_vsctl.VSCtlCommand('list-ports', (self.br_name, )) self.run_command([command]) return command.result
def _get_bridge_name(self): """ get Bridge name of a given 'datapath_id' """ command = ovs_vsctl.VSCtlCommand( 'find', ('Bridge', 'datapath_id=%s' % dpid_lib.dpid_to_str(self.datapath_id))) self.run_command([command]) if not isinstance(command.result, list) or len(command.result) != 1: raise OVSBridgeNotFound( datapath_id=dpid_lib.dpid_to_str(self.datapath_id)) return command.result[0].name
def del_controller(self): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Deletes the configured OpenFlow controller address. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl del-controller <bridge> """ command = ovs_vsctl.VSCtlCommand('del-controller', [self.br_name]) self.run_command([command])
def get_controller(self): """ Gets the configured OpenFlow controller address. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl get-controller <bridge> """ command = ovs_vsctl.VSCtlCommand('get-controller', [self.br_name]) self.run_command([command]) result = command.result return result[0] if len(result) == 1 else result
def del_port(self, port_name): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Deletes a port on OVS instance. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl del-port <bridge> <port> """ command = ovs_vsctl.VSCtlCommand('del-port', (self.br_name, port_name)) self.run_command([command])
def db_get_val(self, table, record, column): """ Gets values of 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl get TBL REC COL """ command = ovs_vsctl.VSCtlCommand('get', (table, record, column)) self.run_command([command]) assert len(command.result) == 1 return command.result[0]
def add_db_attribute(self, table, record, column, value, key=None): """ Adds ('key'=)'value' into 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl add TBL REC COL [KEY=]VALUE """ if key is not None: value = '%s=%s' % (key, value) command = ovs_vsctl.VSCtlCommand('add', (table, record, column, value)) self.run_command([command])
def clear_db_attribute(self, table, record, column): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Clears values from 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl clear TBL REC COL """ command = ovs_vsctl.VSCtlCommand('clear', (table, record, column)) self.run_command([command])
def set_controller(self, controllers): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Sets the OpenFlow controller address. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl set-controller <bridge> <target>... """ command = ovs_vsctl.VSCtlCommand('set-controller', [self.br_name]) command.args.extend(controllers) self.run_command([command])
def set_db_attribute(self, table, record, column, value, key=None): """ Sets 'value' into 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl set TBL REC COL[:KEY]=VALUE """ if key is not None: column = '%s:%s' % (column, key) command = ovs_vsctl.VSCtlCommand('set', (table, record, '%s=%s' % (column, value))) self.run_command([command])
def get_port_name_list(self): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Gets a list of all ports on OVS instance. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl list-ports <bridge> """ command = ovs_vsctl.VSCtlCommand('list-ports', (self.br_name, )) self.run_command([command]) return command.result
def list_db_attributes(self, table, record=None): """ Lists 'record' (or all records) in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl list TBL [REC] """ command = ovs_vsctl.VSCtlCommand('list', (table, record)) self.run_command([command]) if command.result: return command.result return []
def db_get_val(self, table, record, column): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Gets values of 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl get TBL REC COL """ command = ovs_vsctl.VSCtlCommand('get', (table, record, column)) self.run_command([command]) assert len(command.result) == 1 return command.result[0]
def list_db_attributes(self, table, record=None): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Lists 'record' (or all records) in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl list TBL [REC] """ command = ovs_vsctl.VSCtlCommand('list', (table, record)) self.run_command([command]) if command.result: return command.result return []
def remove_db_attribute(self, table, record, column, value, key=None): LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2)) """ Removes ('key'=)'value' into 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl remove TBL REC COL [KEY=]VALUE """ if key is not None: value = '%s=%s' % (key, value) command = ovs_vsctl.VSCtlCommand('remove', (table, record, column, value)) self.run_command([command])
def get_db_attribute(self, table, record, column, key=None): """ Gets values of 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl get TBL REC COL[:KEY] """ if key is not None: column = '%s:%s' % (column, key) command = ovs_vsctl.VSCtlCommand('get', (table, record, column)) self.run_command([command]) if command.result: return command.result[0] return None
def find_db_attributes(self, table, *conditions): """ Lists records satisfying 'conditions' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl find TBL CONDITION... .. Note:: Currently, only '=' condition is supported. To support other condition is TODO. """ args = [table] args.extend(conditions) command = ovs_vsctl.VSCtlCommand('find', args) self.run_command([command]) if command.result: return command.result return []
def add_bond(self, name, ifaces, bond_mode=None, lacp=None): """ Creates a bonded port. :param name: Port name to be created :param ifaces: List of interfaces containing at least 2 interfaces :param bond_mode: Bonding mode (active-backup, balance-tcp or balance-slb) :param lacp: LACP mode (active, passive or off) """ assert len(ifaces) >= 2 options = '' if bond_mode: options += 'bond_mode=%(bond_mode)s' % locals() if lacp: options += 'lacp=%(lacp)s' % locals() command_add = ovs_vsctl.VSCtlCommand('add-bond', (self.br_name, name, ifaces), options) self.run_command([command_add])
def del_qos(self, port_name): """ Deletes the Qos rule on the given port. """ command = ovs_vsctl.VSCtlCommand('del-qos', [port_name]) self.run_command([command])