예제 #1
0
def get_connection(db_class, trigger=None):
    # The trigger is the start() method of the NeutronWorker class
    if trigger and trigger.im_class == ovsdb_monitor.OvnWorker:
        cls = ovsdb_monitor.OvnConnection
    else:
        cls = connection.Connection

    if db_class == OvsdbNbOvnIdl:
        return cls(cfg.get_ovn_nb_connection(), cfg.get_ovn_ovsdb_timeout(),
                   'OVN_Northbound')
    elif db_class == OvsdbSbOvnIdl:
        return cls(cfg.get_ovn_sb_connection(), cfg.get_ovn_ovsdb_timeout(),
                   'OVN_Southbound')
예제 #2
0
def get_connection(db_class, trigger=None):
    # The trigger is the start() method of the NeutronWorker class
    if trigger and trigger.im_class == ovsdb_monitor.OvnWorker:
        cls = ovsdb_monitor.OvnConnection
    else:
        cls = connection.Connection

    if db_class == OvsdbNbOvnIdl:
        return cls(cfg.get_ovn_nb_connection(),
                   cfg.get_ovn_ovsdb_timeout(), 'OVN_Northbound')
    elif db_class == OvsdbSbOvnIdl:
        return cls(cfg.get_ovn_sb_connection(),
                   cfg.get_ovn_ovsdb_timeout(), 'OVN_Southbound')
예제 #3
0
    def __init__(self, driver, trigger=None):
        super(OvsdbNbOvnIdl, self).__init__()
        try:
            if OvsdbNbOvnIdl.ovsdb_connection is None:
                OvsdbNbOvnIdl.ovsdb_connection = get_connection(
                    OvsdbNbOvnIdl, trigger)
            if isinstance(OvsdbNbOvnIdl.ovsdb_connection,
                          ovsdb_monitor.OvnConnection):
                OvsdbNbOvnIdl.ovsdb_connection.start(driver)
            else:
                OvsdbNbOvnIdl.ovsdb_connection.start()
            self.idl = OvsdbNbOvnIdl.ovsdb_connection.idl
            self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()

            # FIXME(lucasagomes): We should not access the _session
            # private attribute like this, ideally the IDL class would
            # expose a public method to allow others to tune the probe
            # interval. This shoule be done in the OVS python library.
            self.idl._session.reconnect.set_probe_interval(
                cfg.get_ovn_ovsdb_probe_interval())
        except Exception as e:
            connection_exception = OvsdbConnectionUnavailable(
                db_schema='OVN_Northbound', error=e)
            LOG.exception(connection_exception)
            raise connection_exception
예제 #4
0
def get_connection(trigger):
    # The trigger is the start() method of the NeutronWorker class
    if trigger.im_class == ovsdb_monitor.OvnWorker:
        cls = ovsdb_monitor.OvnConnection
    else:
        cls = connection.Connection
    return cls(cfg.get_ovn_ovsdb_connection(),
               cfg.get_ovn_ovsdb_timeout(), 'OVN_Northbound')
예제 #5
0
def get_connection(db_class, trigger=None, leader_info=None):
    # The trigger is the start() method of the NeutronWorker class
    if trigger and trigger.im_class == ovsdb_monitor.OvnWorker:
        cls = ovsdb_monitor.OvnConnection
    else:
        cls = connection.Connection

    Stream.ssl_set_private_key_file(cfg.get_ovn_ovsdb_private_key_file())
    Stream.ssl_set_certificate_file(cfg.get_ovn_ovsdb_certificate_file())
    Stream.ssl_set_ca_cert_file(cfg.get_ovn_ovsdb_ca_cert_file())

    if db_class == OvsdbNbOvnIdl:
        if leader_info is None:
            leader_info = cfg.get_ovn_nb_connection()
        return cls(leader_info, cfg.get_ovn_ovsdb_timeout(), 'OVN_Northbound')
    elif db_class == OvsdbSbOvnIdl:
        return cls(cfg.get_ovn_sb_connection(), cfg.get_ovn_ovsdb_timeout(),
                   'OVN_Southbound')
예제 #6
0
 def __init__(self, driver, trigger=None):
     super(OvsdbOvnIdl, self).__init__()
     if OvsdbOvnIdl.ovsdb_connection is None:
         OvsdbOvnIdl.ovsdb_connection = get_connection(trigger)
     if isinstance(OvsdbOvnIdl.ovsdb_connection,
                   ovsdb_monitor.OvnConnection):
         OvsdbOvnIdl.ovsdb_connection.start(driver)
     else:
         OvsdbOvnIdl.ovsdb_connection.start()
     self.idl = OvsdbOvnIdl.ovsdb_connection.idl
     self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
예제 #7
0
 def __init__(self, driver, trigger=None):
     super(OvsdbOvnIdl, self).__init__()
     if OvsdbOvnIdl.ovsdb_connection is None:
         OvsdbOvnIdl.ovsdb_connection = get_connection(trigger)
     if isinstance(OvsdbOvnIdl.ovsdb_connection,
                   ovsdb_monitor.OvnConnection):
         OvsdbOvnIdl.ovsdb_connection.start(driver)
     else:
         OvsdbOvnIdl.ovsdb_connection.start()
     self.idl = OvsdbOvnIdl.ovsdb_connection.idl
     self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
예제 #8
0
 def __init__(self, driver, trigger=None):
     super(OvsdbSbOvnIdl, self).__init__()
     if OvsdbSbOvnIdl.ovsdb_connection is None:
         OvsdbSbOvnIdl.ovsdb_connection = get_connection(
             OvsdbSbOvnIdl, trigger)
     if isinstance(OvsdbSbOvnIdl.ovsdb_connection,
                   ovsdb_monitor.OvnConnection):
         # We only need to know the content of Chassis in OVN_Southbound
         OvsdbSbOvnIdl.ovsdb_connection.start(driver,
                                              table_name_list=['Chassis'])
     self.idl = OvsdbSbOvnIdl.ovsdb_connection.idl
     self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
예제 #9
0
 def __init__(self, driver, trigger=None):
     super(OvsdbSbOvnIdl, self).__init__()
     if OvsdbSbOvnIdl.ovsdb_connection is None:
         OvsdbSbOvnIdl.ovsdb_connection = get_connection(OvsdbSbOvnIdl,
                                                         trigger)
     if isinstance(OvsdbSbOvnIdl.ovsdb_connection,
                   ovsdb_monitor.OvnConnection):
         # We only need to know the content of Chassis in OVN_Southbound
         OvsdbSbOvnIdl.ovsdb_connection.start(driver,
                                              table_name_list=['Chassis'])
     self.idl = OvsdbSbOvnIdl.ovsdb_connection.idl
     self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
예제 #10
0
def get_connection(db_class, trigger=None, driver=None):
    # The trigger is the start() method of the worker class
    if db_class == OvsdbNbOvnIdl:
        args = (cfg.get_ovn_nb_connection(), 'OVN_Northbound')
        cls = ovsdb_monitor.OvnNbIdl
    elif db_class == OvsdbSbOvnIdl:
        args = (cfg.get_ovn_sb_connection(), 'OVN_Southbound')
        cls = ovsdb_monitor.OvnSbIdl

    if trigger and utils.get_method_class(trigger) == ovsdb_monitor.OvnWorker:
        idl_ = cls.from_server(*args, driver=driver)
    else:
        if db_class == OvsdbSbOvnIdl:
            idl_ = ovsdb_monitor.BaseOvnSbIdl.from_server(*args)
        else:
            idl_ = ovsdb_monitor.BaseOvnIdl.from_server(*args)
    return connection.Connection(idl_, timeout=cfg.get_ovn_ovsdb_timeout())
예제 #11
0
 def __init__(self, driver, trigger=None):
     super(OvsdbNbOvnIdl, self).__init__()
     try:
         if OvsdbNbOvnIdl.ovsdb_connection is None:
             OvsdbNbOvnIdl.ovsdb_connection = get_connection(
                 OvsdbNbOvnIdl, trigger)
         if isinstance(OvsdbNbOvnIdl.ovsdb_connection,
                       ovsdb_monitor.OvnConnection):
             OvsdbNbOvnIdl.ovsdb_connection.start(driver)
         else:
             OvsdbNbOvnIdl.ovsdb_connection.start()
         self.idl = OvsdbNbOvnIdl.ovsdb_connection.idl
         self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
     except Exception as e:
         connection_exception = OvsdbConnectionUnavailable(
             db_schema='OVN_Northbound', error=e)
         LOG.exception(connection_exception)
         raise connection_exception
예제 #12
0
def get_connection(db_class, trigger=None, driver=None, binding_events=False):
    if db_class == OvsdbNbOvnIdl:
        args = (cfg.get_ovn_nb_connection(), 'OVN_Northbound')
    elif db_class == OvsdbSbOvnIdl:
        args = (cfg.get_ovn_sb_connection(), 'OVN_Southbound')

    if binding_events:
        if db_class == OvsdbNbOvnIdl:
            idl_ = ovsdb_monitor.OvnNbIdl.from_server(*args, driver=driver)
        else:
            idl_ = ovsdb_monitor.OvnSbIdl.from_server(*args, driver=driver)
    else:
        if db_class == OvsdbNbOvnIdl:
            idl_ = ovsdb_monitor.BaseOvnIdl.from_server(*args)
        else:
            idl_ = ovsdb_monitor.BaseOvnSbIdl.from_server(*args)

    return connection.Connection(idl_, timeout=cfg.get_ovn_ovsdb_timeout())
 def __init__(self, driver, trigger=None):
     super(OvsdbNbOvnIdl, self).__init__()
     try:
         if OvsdbNbOvnIdl.ovsdb_connection is None:
             OvsdbNbOvnIdl.ovsdb_connection = get_connection(
                 OvsdbNbOvnIdl, trigger)
         if isinstance(OvsdbNbOvnIdl.ovsdb_connection,
                       ovsdb_monitor.OvnConnection):
             OvsdbNbOvnIdl.ovsdb_connection.start(driver)
         else:
             OvsdbNbOvnIdl.ovsdb_connection.start()
         self.idl = OvsdbNbOvnIdl.ovsdb_connection.idl
         self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
     except Exception as e:
         connection_exception = OvsdbConnectionUnavailable(
             db_schema='OVN_Northbound', error=e)
         LOG.exception(connection_exception)
         raise connection_exception
예제 #14
0
 def __init__(self, driver, trigger=None):
     super(OvsdbSbOvnIdl, self).__init__()
     try:
         if OvsdbSbOvnIdl.ovsdb_connection is None:
             OvsdbSbOvnIdl.ovsdb_connection = get_connection(OvsdbSbOvnIdl,
                                                             trigger)
         if isinstance(OvsdbSbOvnIdl.ovsdb_connection,
                       ovsdb_monitor.OvnConnection):
             # We only need to know the content of Chassis in OVN_Southbound
             OvsdbSbOvnIdl.ovsdb_connection.start(
                 driver, table_name_list=['Chassis'])
         else:
             OvsdbSbOvnIdl.ovsdb_connection.start()
         self.idl = OvsdbSbOvnIdl.ovsdb_connection.idl
         self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
     except Exception as e:
         connection_exception = OvsdbConnectionUnavailable(
             db_schema='OVN_Southbound', error=e)
         LOG.exception(connection_exception)
         raise connection_exception
예제 #15
0
 def __init__(self, driver, trigger=None):
     super(OvsdbSbOvnIdl, self).__init__()
     try:
         if OvsdbSbOvnIdl.ovsdb_connection is None:
             OvsdbSbOvnIdl.ovsdb_connection = get_connection(
                 OvsdbSbOvnIdl, trigger)
         if isinstance(OvsdbSbOvnIdl.ovsdb_connection,
                       ovsdb_monitor.OvnConnection):
             # We only need to know the content of Chassis in OVN_Southbound
             OvsdbSbOvnIdl.ovsdb_connection.start(
                 driver, table_name_list=['Chassis'])
         else:
             OvsdbSbOvnIdl.ovsdb_connection.start()
         self.idl = OvsdbSbOvnIdl.ovsdb_connection.idl
         self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
     except Exception as e:
         connection_exception = OvsdbConnectionUnavailable(
             db_schema='OVN_Southbound', error=e)
         LOG.exception(connection_exception)
         raise connection_exception
예제 #16
0
    def __init__(self, driver, trigger=None):
        super(OvsdbNbOvnIdl, self).__init__()
        self.driver, self.trigger = driver, trigger
        self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()

        if OvsdbNbOvnIdl.ovsdb_leader_thread is None:
            hosts = ()
            for etcd_connect in cfg.get_ovn_etcd_connection():
                url = urlparse(etcd_connect)
                hosts = hosts + ((url.hostname, url.port), )
            if len(hosts) > 0:
                thread = OVSDBWatchLeaderThread(hosts)
                thread.setDaemon(True)
                thread.start()
                OvsdbNbOvnIdl.leader_info = thread.get_ovsdb_leader()
                OvsdbNbOvnIdl.ovsdb_leader_thread = thread

        if OvsdbNbOvnIdl.ovsdb_connection is None:
            self.__init_connect__(OvsdbNbOvnIdl.leader_info)
        self.idl = OvsdbNbOvnIdl.ovsdb_connection.idl
        if OvsdbNbOvnIdl.ovsdb_leader_thread is not None:
            OvsdbNbOvnIdl.ovsdb_leader_thread.registered(self)
예제 #17
0
 def __init__(self):
     super(OvsdbOvnIdl, self).__init__()
     OvsdbOvnIdl.ovsdb_connection.start()
     self.idl = OvsdbOvnIdl.ovsdb_connection.idl
     self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
예제 #18
0
 def start(self):
     conn = connection.Connection(self,
                                  timeout=config.get_ovn_ovsdb_timeout())
     return idl_ovn.OvsdbSbOvnIdl(conn)
예제 #19
0
 def __init__(self):
     super(OvsdbOvnIdl, self).__init__()
     OvsdbOvnIdl.ovsdb_connection.start()
     self.idl = OvsdbOvnIdl.ovsdb_connection.idl
     self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()
예제 #20
0
 def start(self):
     ovsdb_monitor._check_and_set_ssl_files(self.SCHEMA)
     conn = connection.Connection(self,
                                  timeout=config.get_ovn_ovsdb_timeout())
     return idl_ovn.OvsdbSbOvnIdl(conn)
예제 #21
0
class OvsdbOvnIdl(ovn_api.API):

    ovsdb_connection = connection.Connection(cfg.get_ovn_ovsdb_connection(),
                                             cfg.get_ovn_ovsdb_timeout(),
                                             'OVN_Northbound')

    def __init__(self):
        super(OvsdbOvnIdl, self).__init__()
        OvsdbOvnIdl.ovsdb_connection.start()
        self.idl = OvsdbOvnIdl.ovsdb_connection.idl
        self.ovsdb_timeout = cfg.get_ovn_ovsdb_timeout()

    @property
    def _tables(self):
        return self.idl.tables

    def transaction(self, check_error=False, log_errors=True, **kwargs):
        return impl_idl.Transaction(self, OvsdbOvnIdl.ovsdb_connection,
                                    self.ovsdb_timeout, check_error,
                                    log_errors)

    def create_lswitch(self, lswitch_name, may_exist=True, **columns):
        return cmd.AddLSwitchCommand(self, lswitch_name, may_exist, **columns)

    def delete_lswitch(self, lswitch_name=None, ext_id=None, if_exists=True):
        if (lswitch_name is not None):
            return cmd.DelLSwitchCommand(self, lswitch_name, if_exists)
        else:
            raise RuntimeError(
                _("Currently only supports delete "
                  "by lswitch-name"))

    def set_lswitch_ext_id(self, lswitch_id, ext_id):
        return cmd.LSwitchSetExternalIdCommand(self, lswitch_id, ext_id[0],
                                               ext_id[1])

    def create_lport(self,
                     lport_name,
                     lswitch_name,
                     may_exist=True,
                     **columns):
        return cmd.AddLogicalPortCommand(self, lport_name, lswitch_name,
                                         may_exist, **columns)

    def set_lport(self, lport_name, **columns):
        return cmd.SetLogicalPortCommand(self, lport_name, **columns)

    def delete_lport(self,
                     lport_name=None,
                     lswitch=None,
                     ext_id=None,
                     if_exists=True):
        if (lport_name is not None):
            return cmd.DelLogicalPortCommand(self, lport_name, lswitch,
                                             if_exists)
        else:
            raise RuntimeError(
                _("Currently only supports "
                  "delete by lport-name"))

    def create_acl_rule(self,
                        lswitch_name,
                        priority,
                        match,
                        action,
                        ext_ids_dict=None):
        return cmd.CreateACLRuleCommand(self, lswitch_name, priority, match,
                                        action, ext_ids_dict)

    def get_all_logical_switches_ids(self):
        result = {}
        for row in self._tables['Logical_Switch'].rows.values():
            result[row.name] = row.external_ids
        return result

    def get_all_logical_ports_ids(self):
        result = {}
        for row in self._tables['Logical_Port'].rows.values():
            result[row.name] = row.external_ids
        return result

    def create_lrouter(self, name, may_exist=True, **columns):
        return cmd.AddLRouterCommand(self, name, may_exist, **columns)

    def delete_lrouter(self, name, if_exists=True):
        return cmd.DelLRouterCommand(self, name, if_exists)

    def add_lrouter_port(self,
                         name,
                         lrouter,
                         lswitch,
                         may_exist=True,
                         **columns):
        return cmd.AddLRouterPortCommand(self, name, lrouter, lswitch,
                                         may_exist, **columns)

    def delete_lrouter_port(self, name, lrouter, lswitch, if_exists=True):
        return cmd.DelLRouterPortCommand(self, name, lrouter, lswitch,
                                         if_exists)