rules.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. class Rules(Enum):
  9. # 正则表达式方便校验其来自URL的参数
  10. REG_NUMBER = 'regex:^\d{1,17}$'
  11. REG_NUMBERS = 'regex:^(\d{1,17})(,\d{1,17})*$'
  12. REG_UUIDS = 'regex:^([\w-]{36})(,[\w-]{36})*$'
  13. REG_HOSTS_NAME = 'regex:^([\S-]{1,128})(,[\S-]{1,128})*$'
  14. 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))))$'
  15. OFFSET = (REG_NUMBER, 'offset')
  16. LIMIT = (REG_NUMBER, 'limit')
  17. PAGE = (REG_NUMBER, 'page')
  18. PAGE_SIZE = (REG_NUMBER, 'page_size')
  19. ORDER_BY = (basestring, 'order_by', (1, 30))
  20. ORDER = (basestring, 'order', ['asc', 'desc'])
  21. KEYWORD = (basestring, 'keyword')
  22. ID = (REG_NUMBER, 'id')
  23. IDS = (REG_NUMBERS, 'ids')
  24. HOSTS_NAME = (REG_HOSTS_NAME, 'hosts_name')
  25. BOOT_JOBS_ID = (REG_NUMBERS, 'boot_jobs_id')
  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. START_IP = (REG_IP, 'start_ip')
  34. END_IP = (REG_IP, 'end_ip')
  35. START_VNC_PORT = (int, 'start_vnc_port')
  36. NETMASK = (REG_IP, 'netmask')
  37. GATEWAY = (REG_IP, 'gateway')
  38. DNS1 = (REG_IP, 'dns1')
  39. DNS2 = (REG_IP, 'dns2')
  40. IOPS_BASE = (int, 'iops_base')
  41. IOPS_PRE_UNIT = (int, 'iops_pre_unit')
  42. IOPS_CAP = (int, 'iops_cap')
  43. IOPS_MAX = (int, 'iops_max')
  44. IOPS_MAX_LENGTH = (int, 'iops_max_length')
  45. BPS_BASE = (int, 'iops_base')
  46. BPS_PRE_UNIT = (int, 'iops_pre_unit')
  47. BPS_CAP = (int, 'iops_cap')
  48. BPS_MAX = (int, 'iops_max')
  49. BPS_MAX_LENGTH = (int, 'iops_max_length')
  50. SSH_KEY_ID_EXT = (REG_NUMBER, 'ssh_key_id')
  51. PUBLIC_KEY = (basestring, 'public_key')
  52. UUID = (basestring, 'uuid', (36, 36))
  53. NODE_ID = (basestring, 'node_id', (16, 16))
  54. UUIDS = (REG_UUIDS, 'uuids')
  55. CPU = (int, 'cpu')
  56. MEMORY = (int, 'memory')
  57. OS_TEMPLATE_IMAGE_ID = (int, 'os_template_image_id')
  58. QUANTITY = (int, 'quantity')
  59. NAME = (basestring, 'name')
  60. PATH = (basestring, 'path')
  61. LOGIN_NAME = (basestring, 'login_name')
  62. PASSWORD = (basestring, 'password')
  63. LEASE_TERM = (int, 'lease_term')
  64. DESTINATION_HOST = (basestring, 'destination_host', (5, 64))
  65. DISK_UUID = (basestring, 'disk_uuid', (36, 36))
  66. DISK_SIZE = (int, 'size')
  67. DISK_SIZE_STR = (REG_NUMBER, 'size')
  68. IOPS = (int, 'iops')
  69. IOPS_RD = (int, 'iops_rd')
  70. IOPS_WR = (int, 'iops_wr')
  71. BPS = (int, 'bps')
  72. BPS_RD = (int, 'bps_rd')
  73. BPS_WR = (int, 'bps_wr')
  74. INFLUENCE_CURRENT_GUEST = (bool, 'influence_current_guest')
  75. REMARK = (basestring, 'remark')
  76. USE_FOR = (int, 'use_for')
  77. LABEL = (basestring, 'label')
  78. DESCRIPTION = (basestring, 'description')
  79. OS_TYPE = (basestring, 'os_type')
  80. OS_DISTRO = (basestring, 'os_distro')
  81. OS_MAJOR = (int, 'os_major')
  82. OS_MINOR = (int, 'os_minor')
  83. OS_ARCH = (basestring, 'os_arch')
  84. OS_PRODUCT_NAME = (basestring, 'os_product_name')
  85. ACTIVE = (bool, 'active')
  86. ICON = (basestring, 'icon')
  87. LOGO = (basestring, 'logo')
  88. OS_TEMPLATE_PROFILE_ID_EXT = (int, 'os_template_profile_id')
  89. OS_TEMPLATE_INITIALIZE_OPERATE_SET_ID_EXT = (int, 'os_template_initialize_operate_set_id')
  90. OS_TEMPLATE_INITIALIZE_OPERATE_KIND = (int, 'kind')
  91. OS_TEMPLATE_INITIALIZE_OPERATE_SEQUENCE = (int, 'sequence')
  92. OS_TEMPLATE_INITIALIZE_OPERATE_PATH = (basestring, 'path')
  93. OS_TEMPLATE_INITIALIZE_OPERATE_CONTENT = (basestring, 'content')
  94. OS_TEMPLATE_INITIALIZE_OPERATE_COMMAND = (basestring, 'command')
  95. OPERATE_RULE_KIND = (int, 'kind')
  96. OPERATE_RULE_SEQUENCE = (int, 'sequence')
  97. OPERATE_RULE_PATH = (basestring, 'path')
  98. OPERATE_RULE_CONTENT = (basestring, 'content')
  99. OPERATE_RULE_COMMAND = (basestring, 'command')
  100. TOKEN = (basestring, 'token')