OpenStack Baremetal Compute Service
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.

server.py 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. from mogan.notifications.objects import base
  13. from mogan.objects import base as mogan_base
  14. from mogan.objects import fields
  15. @mogan_base.MoganObjectRegistry.register_notification
  16. class ServerPayload(base.NotificationPayloadBase):
  17. SCHEMA = {
  18. 'name': ('server', 'name'),
  19. 'uuid': ('server', 'uuid'),
  20. 'user_id': ('server', 'user_id'),
  21. 'project_id': ('server', 'project_id'),
  22. 'availability_zone': ('server', 'availability_zone'),
  23. 'image_uuid': ('server', 'image_uuid'),
  24. 'created_at': ('server', 'created_at'),
  25. 'launched_at': ('server', 'launched_at'),
  26. 'updated_at': ('server', 'updated_at'),
  27. 'status': ('server', 'status'),
  28. 'power_state': ('server', 'power_state'),
  29. 'flavor_uuid': ('server', 'flavor_uuid'),
  30. 'description': ('server', 'description'),
  31. 'locked': ('server', 'locked'),
  32. 'locked_by': ('server', 'locked_by'),
  33. 'affinity_zone': ('server', 'affinity_zone'),
  34. 'metadata': ('server', 'metadata'),
  35. 'partitions': ('server', 'partitions'),
  36. 'key_name': ('server', 'key_name'),
  37. 'node': ('server', 'node')
  38. }
  39. # Version 1.0: Initial version
  40. VERSION = '1.0'
  41. fields = {
  42. 'name': fields.StringField(nullable=False),
  43. 'uuid': fields.UUIDField(nullable=False),
  44. 'user_id': fields.StringField(nullable=True),
  45. 'project_id': fields.StringField(nullable=True),
  46. 'description': fields.StringField(nullable=True),
  47. 'flavor_uuid': fields.UUIDField(nullable=False),
  48. 'image_uuid': fields.UUIDField(nullable=True),
  49. 'availability_zone': fields.StringField(nullable=True),
  50. 'power_state': fields.StringField(nullable=True),
  51. 'created_at': fields.DateTimeField(nullable=True),
  52. 'launched_at': fields.DateTimeField(nullable=True),
  53. 'updated_at': fields.DateTimeField(nullable=True),
  54. 'status': fields.StringField(nullable=True),
  55. 'locked': fields.BooleanField(nullable=True),
  56. 'locked_by': fields.StringField(nullable=True),
  57. 'affinity_zone': fields.StringField(nullable=True),
  58. 'metadata': fields.FlexibleDictField(nullable=True),
  59. 'partitions': fields.FlexibleDictField(nullable=True),
  60. 'key_name': fields.StringField(nullable=True),
  61. 'node': fields.StringField(nullable=True),
  62. 'addresses': fields.ListOfObjectsField('ServerAddressesPayload',
  63. nullable=True)
  64. }
  65. def __init__(self, server):
  66. super(ServerPayload, self).__init__()
  67. self.populate_schema(server=server)
  68. self.addresses = ServerAddressesPayload.from_server_obj(server)
  69. @mogan_base.MoganObjectRegistry.register_notification
  70. class ServerAddressesPayload(base.NotificationPayloadBase):
  71. # Version 1.0: Initial version
  72. VERSION = '1.0'
  73. fields = {
  74. 'port_id': fields.UUIDField(nullable=True),
  75. 'mac_address': fields.MACAddressField(),
  76. 'fixed_ips': fields.ListOfDictOfNullableStringsField(
  77. nullable=True),
  78. 'network_id': fields.UUIDField(nullable=True),
  79. 'floating_ip': fields.StringField(nullable=True),
  80. 'preserve_on_delete': fields.BooleanField(nullable=True)
  81. }
  82. SCHEMA = {
  83. 'port_id': ('nic', 'port_id'),
  84. 'mac_address': ('nic', 'mac_address'),
  85. 'fixed_ips': ('nic', 'fixed_ips'),
  86. 'network_id': ('nic', 'network_id'),
  87. 'floating_ip': ('nic', 'floating_ip'),
  88. 'preserve_on_delete': ('nic', 'preserve_on_delete'),
  89. }
  90. def __init__(self, nic_obj):
  91. super(ServerAddressesPayload, self).__init__()
  92. self.populate_schema(nic=nic_obj)
  93. @classmethod
  94. def from_server_obj(cls, server):
  95. """Returns a list of a server's addresses.
  96. """
  97. if not server.nics:
  98. return []
  99. addresses = []
  100. for nic in server.nics:
  101. addresses.append(cls(nic))
  102. return addresses
  103. @mogan_base.MoganObjectRegistry.register_notification
  104. class ServerActionPayload(ServerPayload):
  105. # No SCHEMA as all the additional fields are calculated
  106. VERSION = '1.0'
  107. fields = {
  108. 'fault': fields.ObjectField('ExceptionPayload', nullable=True),
  109. }
  110. def __init__(self, server, fault):
  111. super(ServerActionPayload, self).__init__(server=server)
  112. self.fault = fault
  113. @base.notification_sample('server-create-start.json')
  114. @base.notification_sample('server-create-end.json')
  115. @base.notification_sample('server-create-error.json')
  116. @base.notification_sample('server-delete-start.json')
  117. @base.notification_sample('server-delete-end.json')
  118. @mogan_base.MoganObjectRegistry.register_notification
  119. class ServerActionNotification(base.NotificationBase):
  120. # Version 1.0: Initial version
  121. VERSION = '1.0'
  122. fields = {
  123. 'payload': fields.ObjectField('ServerActionPayload')
  124. }