"Fossies" - the Fresh Open Source Software Archive

Member "octavia-8.0.0/octavia/controller/worker/task_utils.py" (14 Apr 2021, 11353 Bytes) of package /linux/misc/openstack/octavia-8.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "task_utils.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 7.1.1_vs_8.0.0.

    1 #    Copyright 2016 Rackspace
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 """ Methods common to the controller work tasks."""
   16 
   17 from oslo_log import log as logging
   18 
   19 from octavia.common import constants
   20 from octavia.db import api as db_apis
   21 from octavia.db import repositories as repo
   22 
   23 LOG = logging.getLogger(__name__)
   24 
   25 
   26 class TaskUtils(object):
   27     """Class of helper/utility methods used by tasks."""
   28 
   29     def __init__(self, **kwargs):
   30         self.amphora_repo = repo.AmphoraRepository()
   31         self.health_mon_repo = repo.HealthMonitorRepository()
   32         self.listener_repo = repo.ListenerRepository()
   33         self.loadbalancer_repo = repo.LoadBalancerRepository()
   34         self.member_repo = repo.MemberRepository()
   35         self.pool_repo = repo.PoolRepository()
   36         self.amp_health_repo = repo.AmphoraHealthRepository()
   37         self.l7policy_repo = repo.L7PolicyRepository()
   38         self.l7rule_repo = repo.L7RuleRepository()
   39         super().__init__(**kwargs)
   40 
   41     def unmark_amphora_health_busy(self, amphora_id):
   42         """Unmark the amphora_health record busy for an amphora.
   43 
   44         NOTE: This should only be called from revert methods.
   45 
   46         :param amphora_id: The amphora id to unmark busy
   47         """
   48         LOG.debug('Unmarking health monitoring busy on amphora: %s',
   49                   amphora_id)
   50         try:
   51             self.amp_health_repo.update(db_apis.get_session(),
   52                                         amphora_id=amphora_id,
   53                                         busy=False)
   54         except Exception as e:
   55             LOG.debug('Failed to update amphora health record %(amp)s '
   56                       'due to: %(except)s',
   57                       {'amp': amphora_id, 'except': str(e)})
   58 
   59     def mark_amphora_status_error(self, amphora_id):
   60         """Sets an amphora status to ERROR.
   61 
   62         NOTE: This should only be called from revert methods.
   63 
   64         :param amphora_id: Amphora ID to set the status to ERROR
   65         """
   66         try:
   67             self.amphora_repo.update(db_apis.get_session(),
   68                                      id=amphora_id,
   69                                      status=constants.ERROR)
   70         except Exception as e:
   71             LOG.error("Failed to update amphora %(amp)s "
   72                       "status to ERROR due to: "
   73                       "%(except)s", {'amp': amphora_id, 'except': str(e)})
   74 
   75     def mark_health_mon_prov_status_error(self, health_mon_id):
   76         """Sets a health monitor provisioning status to ERROR.
   77 
   78         NOTE: This should only be called from revert methods.
   79 
   80         :param health_mon_id: Health Monitor ID to set prov status to ERROR
   81         """
   82         try:
   83             self.health_mon_repo.update(db_apis.get_session(),
   84                                         id=health_mon_id,
   85                                         provisioning_status=constants.ERROR)
   86         except Exception as e:
   87             LOG.error("Failed to update health monitor %(health)s "
   88                       "provisioning status to ERROR due to: "
   89                       "%(except)s",
   90                       {'health': health_mon_id, 'except': str(e)})
   91 
   92     def mark_l7policy_prov_status_active(self, l7policy_id):
   93         """Sets a L7 policy provisioning status to ACTIVE.
   94 
   95         NOTE: This should only be called from revert methods.
   96 
   97         :param l7policy_id: L7 Policy ID to set provisioning status to ACTIVE
   98         """
   99         try:
  100             self.l7policy_repo.update(db_apis.get_session(),
  101                                       id=l7policy_id,
  102                                       provisioning_status=constants.ACTIVE)
  103         except Exception as e:
  104             LOG.error("Failed to update l7policy %(l7p)s "
  105                       "provisioning status to ACTIVE due to: "
  106                       "%(except)s", {'l7p': l7policy_id, 'except': str(e)})
  107 
  108     def mark_l7policy_prov_status_error(self, l7policy_id):
  109         """Sets a L7 policy provisioning status to ERROR.
  110 
  111         NOTE: This should only be called from revert methods.
  112 
  113         :param l7policy_id: L7 Policy ID to set provisioning status to ERROR
  114         """
  115         try:
  116             self.l7policy_repo.update(db_apis.get_session(),
  117                                       id=l7policy_id,
  118                                       provisioning_status=constants.ERROR)
  119         except Exception as e:
  120             LOG.error("Failed to update l7policy %(l7p)s "
  121                       "provisioning status to ERROR due to: "
  122                       "%(except)s", {'l7p': l7policy_id, 'except': str(e)})
  123 
  124     def mark_l7rule_prov_status_error(self, l7rule_id):
  125         """Sets a L7 rule provisioning status to ERROR.
  126 
  127         NOTE: This should only be called from revert methods.
  128 
  129         :param l7rule_id: L7 Rule ID to set provisioning status to ERROR
  130         """
  131         try:
  132             self.l7rule_repo.update(db_apis.get_session(),
  133                                     id=l7rule_id,
  134                                     provisioning_status=constants.ERROR)
  135         except Exception as e:
  136             LOG.error("Failed to update l7rule %(l7r)s "
  137                       "provisioning status to ERROR due to: "
  138                       "%(except)s", {'l7r': l7rule_id, 'except': str(e)})
  139 
  140     def mark_listener_prov_status_error(self, listener_id):
  141         """Sets a listener provisioning status to ERROR.
  142 
  143         NOTE: This should only be called from revert methods.
  144 
  145         :param listener_id: Listener ID to set provisioning status to ERROR
  146         """
  147         try:
  148             self.listener_repo.update(db_apis.get_session(),
  149                                       id=listener_id,
  150                                       provisioning_status=constants.ERROR)
  151         except Exception as e:
  152             LOG.error("Failed to update listener %(list)s "
  153                       "provisioning status to ERROR due to: "
  154                       "%(except)s", {'list': listener_id, 'except': str(e)})
  155 
  156     def mark_loadbalancer_prov_status_error(self, loadbalancer_id):
  157         """Sets a load balancer provisioning status to ERROR.
  158 
  159         NOTE: This should only be called from revert methods.
  160 
  161         :param loadbalancer_id: Load balancer ID to set provisioning
  162                                 status to ERROR
  163         """
  164         try:
  165             self.loadbalancer_repo.update(db_apis.get_session(),
  166                                           id=loadbalancer_id,
  167                                           provisioning_status=constants.ERROR)
  168         except Exception as e:
  169             LOG.error("Failed to update load balancer %(lb)s "
  170                       "provisioning status to ERROR due to: "
  171                       "%(except)s", {'lb': loadbalancer_id, 'except': str(e)})
  172 
  173     def mark_listener_prov_status_active(self, listener_id):
  174         """Sets a listener provisioning status to ACTIVE.
  175 
  176         NOTE: This should only be called from revert methods.
  177 
  178         :param listener_id: Listener ID to set provisioning
  179                             status to ACTIVE
  180         """
  181         try:
  182             self.listener_repo.update(db_apis.get_session(),
  183                                       id=listener_id,
  184                                       provisioning_status=constants.ACTIVE)
  185         except Exception as e:
  186             LOG.error("Failed to update listener %(list)s "
  187                       "provisioning status to ACTIVE due to: "
  188                       "%(except)s", {'list': listener_id, 'except': str(e)})
  189 
  190     def mark_pool_prov_status_active(self, pool_id):
  191         """Sets a pool provisioning status to ACTIVE.
  192 
  193         NOTE: This should only be called from revert methods.
  194 
  195         :param pool_id: Pool ID to set provisioning status to ACTIVE
  196         """
  197         try:
  198             self.pool_repo.update(db_apis.get_session(),
  199                                   id=pool_id,
  200                                   provisioning_status=constants.ACTIVE)
  201         except Exception as e:
  202             LOG.error("Failed to update pool %(pool)s provisioning status "
  203                       "to ACTIVE due to: %(except)s", {'pool': pool_id,
  204                                                        'except': str(e)})
  205 
  206     def mark_loadbalancer_prov_status_active(self, loadbalancer_id):
  207         """Sets a load balancer provisioning status to ACTIVE.
  208 
  209         NOTE: This should only be called from revert methods.
  210 
  211         :param loadbalancer_id: Load balancer ID to set provisioning
  212                                 status to ACTIVE
  213         """
  214         try:
  215             self.loadbalancer_repo.update(db_apis.get_session(),
  216                                           id=loadbalancer_id,
  217                                           provisioning_status=constants.ACTIVE)
  218         except Exception as e:
  219             LOG.error("Failed to update load balancer %(lb)s "
  220                       "provisioning status to ACTIVE due to: "
  221                       "%(except)s", {'lb': loadbalancer_id, 'except': str(e)})
  222 
  223     def mark_member_prov_status_error(self, member_id):
  224         """Sets a member provisioning status to ERROR.
  225 
  226         NOTE: This should only be called from revert methods.
  227 
  228         :param member_id: Member ID to set provisioning status to ERROR
  229         """
  230         try:
  231             self.member_repo.update(db_apis.get_session(),
  232                                     id=member_id,
  233                                     provisioning_status=constants.ERROR)
  234         except Exception as e:
  235             LOG.error("Failed to update member %(member)s "
  236                       "provisioning status to ERROR due to: "
  237                       "%(except)s", {'member': member_id, 'except': str(e)})
  238 
  239     def mark_pool_prov_status_error(self, pool_id):
  240         """Sets a pool provisioning status to ERROR.
  241 
  242         NOTE: This should only be called from revert methods.
  243 
  244         :param pool_id: Pool ID to set provisioning status to ERROR
  245         """
  246         try:
  247             self.pool_repo.update(db_apis.get_session(),
  248                                   id=pool_id,
  249                                   provisioning_status=constants.ERROR)
  250         except Exception as e:
  251             LOG.error("Failed to update pool %(pool)s "
  252                       "provisioning status to ERROR due to: "
  253                       "%(except)s", {'pool': pool_id, 'except': str(e)})
  254 
  255     def get_current_loadbalancer_from_db(self, loadbalancer_id):
  256         """Gets a Loadbalancer from db.
  257 
  258         :param: loadbalancer_id: Load balancer ID which to get from db
  259         """
  260         try:
  261             return self.loadbalancer_repo.get(db_apis.get_session(),
  262                                               id=loadbalancer_id)
  263         except Exception as e:
  264             LOG.error("Failed to get loadbalancer %(loadbalancer)s "
  265                       "due to: %(except)s",
  266                       {'loadbalancer': loadbalancer_id, 'except': str(e)})
  267         return None