rules.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from enum import Enum
  4. __author__ = 'James Iter'
  5. __date__ = '2017/3/21'
  6. __contact__ = 'james.iter.cn@gmail.com'
  7. __copyright__ = '(c) 2017 by James Iter.'
  8. # TODO: 考虑按视角归类,比如自身视角名称(uuid),外部视角名称(guest_uuid)
  9. class Rules(Enum):
  10. # 正则表达式方便校验其来自URL的参数
  11. REG_NUMBER = 'regex:^\d{1,17}$'
  12. REG_NUMBERS = 'regex:^(\d{1,17})(,\d{1,17})*$'
  13. REG_UUIDS = 'regex:^([\w-]{36})(,[\w-]{36})*$'
  14. REG_HOSTS_NAME = 'regex:^([\S-]{1,128})(,[\S-]{1,128})*$'
  15. REG_IP = 'regex:^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))$'
  16. OFFSET = (REG_NUMBER, 'offset')
  17. LIMIT = (REG_NUMBER, 'limit')
  18. PAGE = (REG_NUMBER, 'page')
  19. PAGE_SIZE = (REG_NUMBER, 'page_size')
  20. ORDER_BY = (basestring, 'order_by', (1, 30))
  21. ORDER = (basestring, 'order', ['asc', 'desc'])
  22. KEYWORD = (basestring, 'keyword')
  23. ID = (REG_NUMBER, 'id')
  24. IDS = (REG_NUMBERS, 'ids')
  25. HOSTS_NAME = (REG_HOSTS_NAME, 'hosts_name')
  26. CONFIG_ID = (int, 'id')
  27. JIMV_EDITION = (int, 'jimv_edition')
  28. STORAGE_MODE = (int, 'storage_mode')
  29. DFS_VOLUME = (basestring, 'dfs_volume')
  30. STORAGE_PATH = (basestring, 'storage_path')
  31. VM_NETWORK = (basestring, 'vm_network')
  32. VM_MANAGE_NETWORK = (basestring, 'vm_manage_network')
  33. IOPS_BASE = (int, 'iops_base')
  34. IOPS_PRE_UNIT = (int, 'iops_pre_unit')
  35. IOPS_CAP = (int, 'iops_cap')
  36. IOPS_MAX = (int, 'iops_max')
  37. IOPS_MAX_LENGTH = (int, 'iops_max_length')
  38. BPS_BASE = (int, 'iops_base')
  39. BPS_PRE_UNIT = (int, 'iops_pre_unit')
  40. BPS_CAP = (int, 'iops_cap')
  41. BPS_MAX = (int, 'iops_max')
  42. BPS_MAX_LENGTH = (int, 'iops_max_length')
  43. BANDWIDTH = (int, 'bandwidth')
  44. BANDWIDTH_IN_URL = (REG_NUMBER, 'bandwidth')
  45. BANDWIDTH_UNIT = (basestring, 'bandwidth_unit', ['k', 'm', 'g'])
  46. IP = (REG_IP, 'ip')
  47. START_IP = (REG_IP, 'start_ip')
  48. END_IP = (REG_IP, 'end_ip')
  49. START_VNC_PORT = (int, 'start_vnc_port')
  50. NETMASK = (REG_IP, 'netmask')
  51. GATEWAY = (REG_IP, 'gateway')
  52. DNS1 = (REG_IP, 'dns1')
  53. DNS2 = (REG_IP, 'dns2')
  54. ACTIVITY = (int, 'activity')
  55. SSH_KEY_ID_EXT = (REG_NUMBER, 'ssh_key_id')
  56. SSH_KEYS_ID = (list, 'ssh_keys_id')
  57. PUBLIC_KEY = (basestring, 'public_key')
  58. UUID = (basestring, 'uuid', (36, 36))
  59. NODE_ID = (basestring, 'node_id', (16, 16))
  60. UUIDS = (REG_UUIDS, 'uuids')
  61. CPU = (int, 'cpu')
  62. MEMORY = (int, 'memory')
  63. OS_TEMPLATE_IMAGE_ID = (int, 'os_template_image_id')
  64. QUANTITY = (int, 'quantity')
  65. NAME = (basestring, 'name')
  66. PATH = (basestring, 'path')
  67. LOGIN_NAME = (basestring, 'login_name')
  68. PASSWORD = (basestring, 'password')
  69. LEASE_TERM = (int, 'lease_term')
  70. DESTINATION_HOST = (basestring, 'destination_host', (5, 64))
  71. DISK_UUID = (basestring, 'disk_uuid', (36, 36))
  72. DISK_SIZE = (int, 'size')
  73. DISK_SIZE_STR = (REG_NUMBER, 'size')
  74. IOPS = (int, 'iops')
  75. IOPS_RD = (int, 'iops_rd')
  76. IOPS_WR = (int, 'iops_wr')
  77. BPS = (int, 'bps')
  78. BPS_RD = (int, 'bps_rd')
  79. BPS_WR = (int, 'bps_wr')
  80. INFLUENCE_CURRENT_GUEST = (bool, 'influence_current_guest')
  81. GUEST_UUID = (basestring, 'guest_uuid', (36, 36))
  82. SNAPSHOT_ID = (basestring, 'snapshot_id', (10, 12))
  83. SNAPSHOTS_ID = (basestring, 'snapshots_id', (10, 1200))
  84. REMARK = (basestring, 'remark')
  85. USE_FOR = (int, 'use_for')
  86. LABEL = (basestring, 'label')
  87. DESCRIPTION = (basestring, 'description')
  88. OS_TYPE = (basestring, 'os_type')
  89. OS_DISTRO = (basestring, 'os_distro')
  90. OS_MAJOR = (int, 'os_major')
  91. OS_MINOR = (int, 'os_minor')
  92. OS_ARCH = (basestring, 'os_arch')
  93. OS_PRODUCT_NAME = (basestring, 'os_product_name')
  94. ACTIVE = (bool, 'active')
  95. ICON = (basestring, 'icon')
  96. LOGO = (basestring, 'logo')
  97. OS_TEMPLATE_IMAGE_KIND = (int, 'kind')
  98. OS_TEMPLATE_PROFILE_ID_EXT = (int, 'os_template_profile_id')
  99. OS_TEMPLATE_INITIALIZE_OPERATE_SET_ID_EXT = (int, 'os_template_initialize_operate_set_id')
  100. OS_TEMPLATE_INITIALIZE_OPERATE_KIND = (int, 'kind')
  101. OS_TEMPLATE_INITIALIZE_OPERATE_SEQUENCE = (int, 'sequence')
  102. OS_TEMPLATE_INITIALIZE_OPERATE_PATH = (basestring, 'path')
  103. OS_TEMPLATE_INITIALIZE_OPERATE_CONTENT = (basestring, 'content')
  104. OS_TEMPLATE_INITIALIZE_OPERATE_COMMAND = (basestring, 'command')
  105. OPERATE_RULE_KIND = (int, 'kind')
  106. OPERATE_RULE_SEQUENCE = (int, 'sequence')
  107. OPERATE_RULE_PATH = (basestring, 'path')
  108. OPERATE_RULE_CONTENT = (basestring, 'content')
  109. OPERATE_RULE_COMMAND = (basestring, 'command')
  110. TOKEN = (basestring, 'token')
  111. PROJECT_ID = (int, 'project_id')
  112. PROJECTS_ID = (REG_NUMBERS, 'projects_id')
  113. SERVICE_ID = (int, 'service_id')
  114. SERVICE_ID_IN_URL = (REG_NUMBER, 'service_id')
  115. SERVICES_ID = (REG_NUMBERS, 'services_id')