Load Balancing as a Service (LBaaS) for OpenStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.9KB

  1. # Copyright 2019 Red Hat, Inc. All rights reserved.
  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. from octavia_lib.common import constants as lib_consts
  15. from octavia.api.drivers import utils as driver_utils
  16. from octavia.common import constants
  17. from octavia.db import api as db_api
  18. from octavia.db import repositories
  19. def process_get(get_data):
  20. session = db_api.get_session()
  21. if get_data[constants.OBJECT] == lib_consts.LOADBALANCERS:
  22. lb_repo = repositories.LoadBalancerRepository()
  23. db_lb = lb_repo.get(session, id=get_data[lib_consts.ID],
  24. show_deleted=False)
  25. if db_lb:
  26. provider_lb = (
  27. driver_utils.db_loadbalancer_to_provider_loadbalancer(db_lb))
  28. return provider_lb.to_dict(recurse=True, render_unsets=True)
  29. elif get_data[constants.OBJECT] == lib_consts.LISTENERS:
  30. listener_repo = repositories.ListenerRepository()
  31. db_listener = listener_repo.get(
  32. session, id=get_data[lib_consts.ID], show_deleted=False)
  33. if db_listener:
  34. provider_listener = (
  35. driver_utils.db_listener_to_provider_listener(db_listener))
  36. return provider_listener.to_dict(recurse=True, render_unsets=True)
  37. elif get_data[constants.OBJECT] == lib_consts.POOLS:
  38. pool_repo = repositories.PoolRepository()
  39. db_pool = pool_repo.get(session, id=get_data[lib_consts.ID],
  40. show_deleted=False)
  41. if db_pool:
  42. provider_pool = (
  43. driver_utils.db_pool_to_provider_pool(db_pool))
  44. return provider_pool.to_dict(recurse=True, render_unsets=True)
  45. elif get_data[constants.OBJECT] == lib_consts.MEMBERS:
  46. member_repo = repositories.MemberRepository()
  47. db_member = member_repo.get(session, id=get_data[lib_consts.ID],
  48. show_deleted=False)
  49. if db_member:
  50. provider_member = (
  51. driver_utils.db_member_to_provider_member(db_member))
  52. return provider_member.to_dict(recurse=True, render_unsets=True)
  53. elif get_data[constants.OBJECT] == lib_consts.HEALTHMONITORS:
  54. hm_repo = repositories.HealthMonitorRepository()
  55. db_hm = hm_repo.get(session, id=get_data[lib_consts.ID],
  56. show_deleted=False)
  57. if db_hm:
  58. provider_hm = (
  59. driver_utils.db_HM_to_provider_HM(db_hm))
  60. return provider_hm.to_dict(recurse=True, render_unsets=True)
  61. elif get_data[constants.OBJECT] == lib_consts.L7POLICIES:
  62. l7policy_repo = repositories.L7PolicyRepository()
  63. db_l7policy = l7policy_repo.get(session, id=get_data[lib_consts.ID],
  64. show_deleted=False)
  65. if db_l7policy:
  66. provider_l7policy = (
  67. driver_utils.db_l7policy_to_provider_l7policy(db_l7policy))
  68. return provider_l7policy.to_dict(recurse=True, render_unsets=True)
  69. elif get_data[constants.OBJECT] == lib_consts.L7RULES:
  70. l7rule_repo = repositories.L7RuleRepository()
  71. db_l7rule = l7rule_repo.get(session, id=get_data[lib_consts.ID],
  72. show_deleted=False)
  73. if db_l7rule:
  74. provider_l7rule = (
  75. driver_utils.db_l7rule_to_provider_l7rule(db_l7rule))
  76. return provider_l7rule.to_dict(recurse=True, render_unsets=True)
  77. return {}