Exemple #1
0
    def update_openvpn_status_by_agent(self, context,
                                       service_status_info_list):
        with context.session.begin(subtransactions=True):
            for vpnservice in service_status_info_list:
                try:
                    vpnservice_db = self._get_vpnservice(
                        context, vpnservice['id'])
                except vpnaas.VPNServiceNotFound:
                    LOG.warn(_LW('vpnservice %s in db is already deleted'),
                             vpnservice['id'])
                    continue

                if (not utils.in_pending_status(vpnservice_db.status)
                        or vpnservice['updated_pending_status']):
                    vpnservice_db.status = vpnservice['status']
                for openvpnconnection_id, conn in vpnservice[
                        'openvpn_connections'].items():
                    try:
                        conn_db = self._get_resource(
                            context, vpn_models.OpenvpnConnection,
                            openvpnconnection_id)
                    except openvpn.OpenvpnConnectionNotFound:
                        continue
                    if (not utils.in_pending_status(conn_db.status)
                            or conn['updated_pending_status']):
                        conn_db.status = conn['status']
Exemple #2
0
    def update(self):
        """Update Status based on vpnservice configuration."""

        # Disable the process if a vpnservice is disabled or it has no
        # enabled IPSec site connections.
        vpnservice_has_active_ipsec_site_conns = any([
            ipsec_site_conn['admin_state_up']
            for ipsec_site_conn in self.vpnservice['ipsec_site_connections']
        ])
        if (not self.vpnservice['admin_state_up']
                or not vpnservice_has_active_ipsec_site_conns):
            self.disable()
        else:
            self.enable()

        if plugin_utils.in_pending_status(self.vpnservice['status']):
            self.updated_pending_status = True

        self.vpnservice['status'] = self.status
        for ipsec_site_conn in self.vpnservice['ipsec_site_connections']:
            if plugin_utils.in_pending_status(ipsec_site_conn['status']):
                conn_id = ipsec_site_conn['id']
                conn_status = self.connection_status.get(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                ipsec_site_conn['status'] = conn_status['status']
Exemple #3
0
    def update(self):
        """Update Status based on vpnservice configuration."""

        # Disable the process if a vpnservice is disabled or it has no
        # enabled IPSec site connections.
        vpnservice_has_active_ipsec_site_conns = any(
            [ipsec_site_conn['admin_state_up']
             for ipsec_site_conn in self.vpnservice['ipsec_site_connections']])
        if (not self.vpnservice['admin_state_up'] or
                not vpnservice_has_active_ipsec_site_conns):
            self.disable()
        else:
            self.enable()

        if plugin_utils.in_pending_status(self.vpnservice['status']):
            self.updated_pending_status = True

        self.vpnservice['status'] = self.status
        for ipsec_site_conn in self.vpnservice['ipsec_site_connections']:
            if plugin_utils.in_pending_status(ipsec_site_conn['status']):
                conn_id = ipsec_site_conn['id']
                conn_status = self.connection_status.get(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                ipsec_site_conn['status'] = conn_status['status']
Exemple #4
0
    def update_status_by_agent(self, context, service_status_info_list):
        """Updating vpnservice and vpnconnection status.

        :param context: context variable
        :param service_status_info_list: list of status
        The structure is
        [{id: vpnservice_id,
          status: ACTIVE|DOWN|ERROR,
          updated_pending_status: True|False
          ipsec_site_connections: {
              ipsec_site_connection_id: {
                  status: ACTIVE|DOWN|ERROR,
                  updated_pending_status: True|False
              }
          }]
        The agent will set updated_pending_status as True,
        when agent update any pending status.
        """
        with context.session.begin(subtransactions=True):
            for vpnservice in service_status_info_list:
                try:
                    vpnservice_db = self._get_vpnservice(context, vpnservice["id"])
                except vpnaas.VPNServiceNotFound:
                    LOG.warn(_("vpnservice %s in db is already deleted"), vpnservice["id"])
                    continue

                if not utils.in_pending_status(vpnservice_db.status) or vpnservice["updated_pending_status"]:
                    vpnservice_db.status = vpnservice["status"]
                for conn_id, conn in vpnservice["ipsec_site_connections"].items():
                    try:
                        conn_db = self._get_ipsec_site_connection(context, conn_id)
                    except vpnaas.IPsecSiteConnectionNotFound:
                        continue
                    if not utils.in_pending_status(conn_db.status) or conn["updated_pending_status"]:
                        conn_db.status = conn["status"]
Exemple #5
0
    def build_report_for_service(self, vpn_service):
        """Create the report info for a VPN service and its IPSec connections.

        Get the report info for the connections on the service, and include
        it into the report info for the VPN service. If there is no report
        info for the connection, then no change has occurred and no report
        will be generated. If there is only one connection for the service,
        we'll set the service state to match the connection (with ERROR seen
        as DOWN).
        """
        conn_report = self.build_report_for_connections_on(vpn_service)
        if conn_report:
            pending_handled = plugin_utils.in_pending_status(
                vpn_service.last_status)
            if (len(conn_report) == 1 and
                conn_report.values()[0]['status'] != constants.ACTIVE):
                vpn_service.last_status = constants.DOWN
            else:
                vpn_service.last_status = constants.ACTIVE
            LOG.debug(_("Report: Adding info for VPN service %s"),
                      vpn_service.service_id)
            return {u'id': vpn_service.service_id,
                    u'status': vpn_service.last_status,
                    u'updated_pending_status': pending_handled,
                    u'ipsec_site_connections': conn_report}
        else:
            return {}
Exemple #6
0
 def update_status_and_build_report(self, current_status):
     if current_status != self.last_status:
         pending_handled = plugin_utils.in_pending_status(self.last_status)
         self.last_status = current_status
         return {self.conn_id: {"status": current_status, "updated_pending_status": pending_handled}}
     else:
         return {}
Exemple #7
0
    def build_report_for_service(self, vpn_service):
        """Create the report info for a VPN service and its IPSec connections.

        Get the report info for the connections on the service, and include
        it into the report info for the VPN service. If there is no report
        info for the connection, then no change has occurred and no report
        will be generated. If there is only one connection for the service,
        we'll set the service state to match the connection (with ERROR seen
        as DOWN).
        """
        conn_report = self.build_report_for_connections_on(vpn_service)
        if conn_report or vpn_service.connections_removed:
            pending_handled = plugin_utils.in_pending_status(
                vpn_service.last_status)
            vpn_service.update_last_status()
            LOG.debug(_("Report: Adding info for VPN service %s"),
                      vpn_service.service_id)
            return {
                u'id': vpn_service.service_id,
                u'status': vpn_service.last_status,
                u'updated_pending_status': pending_handled,
                u'ipsec_site_connections': conn_report
            }
        else:
            return {}
Exemple #8
0
 def build_report_based_on_status(self, current_status):
     if current_status != self.last_status:
         pending_handled = plugin_utils.in_pending_status(self.last_status)
         self.last_status = current_status
         return {self.conn_id: {'status': current_status,
                                'updated_pending_status': pending_handled}}
     else:
         return {}
Exemple #9
0
 def update_status_and_build_report(self, current_status):
     if current_status != self.last_status:
         pending_handled = plugin_utils.in_pending_status(self.last_status)
         self.last_status = current_status
         return {self.conn_id: {'status': current_status,
                                'updated_pending_status': pending_handled}}
     else:
         return {}
    def update(self):
        """Update Status based on vpnservice configuration."""
        if self.vpnservice and not self.vpnservice['admin_state_up']:
            self.disable()
        else:
            self.enable()

        if plugin_utils.in_pending_status(self.vpnservice['status']):
            self.updated_pending_status = True
Exemple #11
0
    def update(self):
        """Update Status based on vpnservice configuration."""
        if self.vpnservice and not self.vpnservice['admin_state_up']:
            self.disable()
        else:
            self.enable()

        if plugin_utils.in_pending_status(self.vpnservice['status']):
            self.updated_pending_status = True
Exemple #12
0
    def _update_sslvpn_status_by_agent(
        self, context, service_status_info_list):
        """Updating vpnservice and vpnconnection status.

        :param context: context variable
        :param service_status_info_list: list of status
        The structure is
        [{id: vpnservice_id,
          status: ACTIVE|DOWN|ERROR,
          updated_pending_status: True|False
          ssl_vpn_connections: {
              ssl_vpn_connection_id: {
                  status: ACTIVE|DOWN|ERROR,
                  updated_pending_status: True|False
              }
          }]
        The agent will set updated_pending_status as True,
        when agent update any pending status.
        """
        with context.session.begin(subtransactions=True):
            for vpnservice in service_status_info_list:
                try:
                    vpnservice_db = self._get_vpnservice(
                        context, vpnservice['id'])
                except vpnaas.VPNServiceNotFound:
                    LOG.warn(_('vpnservice %s in db is already deleted'),
                             vpnservice['id'])
                    continue

                if (not utils.in_pending_status(vpnservice_db.status)
                    or vpnservice['updated_pending_status']):
                    vpnservice_db.status = vpnservice['status']
                for conn_id, conn in vpnservice[
                    'ssl_vpn_connections'].items():
                    try:
                        conn_db = self._get_resource(
                            context, vpn_db.SSLVPNConnection, conn_id)

                    except SSLVPNConnectionNotFound:
                        continue
                    if (not utils.in_pending_status(conn_db.status)
                        or conn['updated_pending_status']):
                        conn_db.status = conn['status']
Exemple #13
0
    def _update_sslvpn_status_by_agent(self, context,
                                       service_status_info_list):
        """Updating vpnservice and vpnconnection status.

        :param context: context variable
        :param service_status_info_list: list of status
        The structure is
        [{id: vpnservice_id,
          status: ACTIVE|DOWN|ERROR,
          updated_pending_status: True|False
          ssl_vpn_connections: {
              ssl_vpn_connection_id: {
                  status: ACTIVE|DOWN|ERROR,
                  updated_pending_status: True|False
              }
          }]
        The agent will set updated_pending_status as True,
        when agent update any pending status.
        """
        with context.session.begin(subtransactions=True):
            for vpnservice in service_status_info_list:
                try:
                    vpnservice_db = self._get_vpnservice(
                        context, vpnservice['id'])
                except vpnaas.VPNServiceNotFound:
                    LOG.warn(_('vpnservice %s in db is already deleted'),
                             vpnservice['id'])
                    continue

                if (not utils.in_pending_status(vpnservice_db.status)
                        or vpnservice['updated_pending_status']):
                    vpnservice_db.status = vpnservice['status']
                for conn_id, conn in vpnservice['ssl_vpn_connections'].items():
                    try:
                        conn_db = self._get_resource(context,
                                                     vpn_db.SSLVPNConnection,
                                                     conn_id)

                    except SSLVPNConnectionNotFound:
                        continue
                    if (not utils.in_pending_status(conn_db.status)
                            or conn['updated_pending_status']):
                        conn_db.status = conn['status']
Exemple #14
0
    def update(self):
        """Update Status based on vpnservice configuration."""
        if self.vpnservice and not self.vpnservice['admin_state_up']:
            self.disable()
        else:
            self.enable()

        if plugin_utils.in_pending_status(self.vpnservice['status']):
            self.updated_pending_status = True

        self.vpnservice['status'] = self.status
        for ipsec_site_conn in self.vpnservice['ipsec_site_connections']:
            if plugin_utils.in_pending_status(ipsec_site_conn['status']):
                conn_id = ipsec_site_conn['id']
                conn_status = self.connection_status.get(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                ipsec_site_conn['status'] = conn_status['status']
Exemple #15
0
    def update(self):
        """Update Status based on vpnservice configuration."""
        if self.vpnservice and not self.vpnservice['admin_state_up']:
            self.disable()
        else:
            self.enable()

        if plugin_utils.in_pending_status(self.vpnservice['status']):
            self.updated_pending_status = True

        self.vpnservice['status'] = self.status
        for ipsec_site_conn in self.vpnservice['ipsec_site_connections']:
            if plugin_utils.in_pending_status(ipsec_site_conn['status']):
                conn_id = ipsec_site_conn['id']
                conn_status = self.connection_status.get(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                ipsec_site_conn['status'] = conn_status['status']
Exemple #16
0
    def update(self):
        """Update Status based on vpnservice configuration."""
        super(BaseSwanProcess, self).update()

        self.vpnservice['status'] = self.status
        for ipsec_site_conn in self.vpnservice['ipsec_site_connections']:
            if plugin_utils.in_pending_status(ipsec_site_conn['status']):
                conn_id = ipsec_site_conn['id']
                conn_status = self.connection_status.get(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                ipsec_site_conn['status'] = conn_status['status']
Exemple #17
0
    def update(self):
        """Update Status based on vpnservice configuration."""
        super(BaseSwanProcess, self).update()

        self.vpnservice['status'] = self.status
        for ipsec_site_conn in self.vpnservice['ipsec_site_connections']:
            if plugin_utils.in_pending_status(ipsec_site_conn['status']):
                conn_id = ipsec_site_conn['id']
                conn_status = self.connection_status.get(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                ipsec_site_conn['status'] = conn_status['status']
    def update(self):
        """Update Status based on vpnservice configuration."""
        super(BasePPTPDProcess, self).update()

        self.vpnservice['status'] = self.status
        for pptp_conn in self.vpnservice['pptpconnections']:
            if plugin_utils.in_pending_status(pptp_conn['status']):
                conn_id = pptp_conn['id']
                conn_status = self.get_connection_status(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                conn_status['status'] = self.vpnservice['status']
                pptp_conn['status'] = conn_status['status']
Exemple #19
0
    def _update_connection_status(self, context, conn_id, new_status,
                                  updated_pending):
        """Update the connection status, if changed.

        If the connection is not in a pending state, unconditionally update
        the status. Likewise, if in a pending state, and have an indication
        that the status has changed, then update the database.
        """
        try:
            conn_db = self._get_ipsec_site_connection(context, conn_id)
        except vpnaas.IPsecSiteConnectionNotFound:
            return
        if not utils.in_pending_status(conn_db.status) or updated_pending:
            conn_db.status = new_status
    def update(self):
        """Update Status based on vpnservice configuration."""
        super(BaseSSLVpnProcess, self).update()

        self.vpnservice['status'] = self.get_status()
        for openvpnconnection in self.vpnservice['openvpnconnections']:
            if plugin_utils.in_pending_status(openvpnconnection['status']):
                conn_id = openvpnconnection['id']
                conn_status = self.get_connection_status(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                conn_status['status'] = self.vpnservice['status']
                openvpnconnection['status'] = conn_status['status']
Exemple #21
0
    def _update_connection_status(self, context, conn_id, new_status,
                                  updated_pending):
        """Update the connection status, if changed.

        If the connection is not in a pending state, unconditionally update
        the status. Likewise, if in a pending state, and have an indication
        that the status has changed, then update the database.
        """
        try:
            conn_db = self._get_ipsec_site_connection(context, conn_id)
        except vpnaas.IPsecSiteConnectionNotFound:
            return
        if not utils.in_pending_status(conn_db.status) or updated_pending:
            conn_db.status = new_status
Exemple #22
0
    def update(self):
        """Update Status based on vpnservice configuration."""
        super(OpenVPNProcess, self).update()

        self.vpnservice['status'] = self.status
        for ssl_vpn_conn in self.vpnservice['ssl_vpn_connections']:
            if plugin_utils.in_pending_status(ssl_vpn_conn['status']):
                conn_id = ssl_vpn_conn['id']
                conn_status = self.get_connection_status(conn_id)
                if not conn_status:
                    continue
                conn_status['updated_pending_status'] = True
                conn_status['status'] = self.vpnservice['status']
                ssl_vpn_conn['status'] = self.vpnservice['status']
Exemple #23
0
    def build_report_for_service(self, vpn_service):
        """Create the report info for a VPN service and its IPSec connections.

        Get the report info for the connections on the service, and include
        it into the report info for the VPN service. If there is no report
        info for the connection, then no change has occurred and no report
        will be generated. If there is only one connection for the service,
        we'll set the service state to match the connection (with ERROR seen
        as DOWN).
        """
        conn_report = self.build_report_for_connections_on(vpn_service)
        if conn_report or vpn_service.connections_removed:
            pending_handled = plugin_utils.in_pending_status(vpn_service.last_status)
            vpn_service.update_last_status()
            LOG.debug(_("Report: Adding info for VPN service %s"), vpn_service.service_id)
            return {
                u"id": vpn_service.service_id,
                u"status": vpn_service.last_status,
                u"updated_pending_status": pending_handled,
                u"ipsec_site_connections": conn_report,
            }
        else:
            return {}
Exemple #24
0
 def assert_update_allowed(self, obj):
     status = getattr(obj, 'status', None)
     if utils.in_pending_status(status):
         raise vpnaas.VPNStateInvalid(id=id, state=status)
Exemple #25
0
 def assert_update_allowed(self, obj):
     status = getattr(obj, 'status', None)
     _id = getattr(obj, 'id', None)
     if utils.in_pending_status(status):
         raise vpnaas.VPNStateInvalidToUpdate(id=_id, state=status)
Exemple #26
0
 def assert_update_allowed(self, obj):
     status = getattr(obj, "status", None)
     _id = getattr(obj, "id", None)
     if utils.in_pending_status(status):
         raise vpnaas.VPNStateInvalidToUpdate(id=_id, state=status)