rules.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_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))))$'
  14. OFFSET = (REG_NUMBER, 'offset')
  15. LIMIT = (REG_NUMBER, 'limit')
  16. PAGE = (REG_NUMBER, 'page')
  17. PAGE_SIZE = (REG_NUMBER, 'page_size')
  18. ORDER_BY = (basestring, 'order_by', (1, 30))
  19. ORDER = (basestring, 'order', ['asc', 'desc'])
  20. KEYWORD = (basestring, 'keyword')
  21. ID = (REG_NUMBER, 'id')
  22. IDS = (REG_NUMBERS, 'ids')
  23. BOOT_JOBS_ID = (REG_NUMBERS, 'boot_jobs_id')
  24. CONFIG_ID = (int, 'id')
  25. JIMV_EDITION = (int, 'jimv_edition')
  26. DFS = (int, 'dfs')
  27. DFS_VOLUME = (basestring, 'dfs_volume')
  28. STORAGE_PATH = (basestring, 'storage_path')
  29. VM_NETWORK = (basestring, 'vm_network')
  30. VM_MANAGE_NETWORK = (basestring, 'vm_manage_network')
  31. START_IP = (REG_IP, 'start_ip')
  32. END_IP = (REG_IP, 'end_ip')
  33. START_VNC_PORT = (int, 'start_vnc_port')
  34. NETMASK = (REG_IP, 'netmask')
  35. GATEWAY = (REG_IP, 'gateway')
  36. DNS1 = (REG_IP, 'dns1')
  37. DNS2 = (REG_IP, 'dns2')
  38. RSA_PRIVATE = (basestring, 'rsa_private')
  39. RSA_PUBLIC = (basestring, 'rsa_public')
  40. UUID = (basestring, 'uuid', (36, 36))
  41. NODE_ID = (basestring, 'node_id', (14, 14))
  42. UUIDS = (REG_UUIDS, 'uuids')
  43. CPU = (int, 'cpu')
  44. MEMORY = (int, 'memory')
  45. OS_TEMPLATE_ID = (int, 'os_template_id')
  46. QUANTITY = (int, 'quantity')
  47. NAME = (basestring, 'name')
  48. PATH = (basestring, 'path')
  49. PASSWORD = (basestring, 'password')
  50. LEASE_TERM = (int, 'lease_term')
  51. DESTINATION_HOST = (basestring, 'destination_host', (5, 64))
  52. DISK_UUID = (basestring, 'disk_uuid', (36, 36))
  53. DISK_SIZE = (int, 'size')
  54. DISK_SIZE_STR = (REG_NUMBER, 'size')
  55. DISK_ON_HOST = (basestring, 'on_host', (1, 128))
  56. REMARK = (basestring, 'remark')
  57. USE_FOR = (int, 'use_for')
  58. LABEL = (basestring, 'label')
  59. ACTIVE = (bool, 'active')
  60. ICON = (basestring, 'icon')
  61. BOOT_JOB_ID_EXT = (int, 'boot_job_id')
  62. OPERATE_RULE_KIND = (int, 'kind')
  63. OPERATE_RULE_SEQUENCE = (int, 'sequence')
  64. OPERATE_RULE_PATH = (basestring, 'path')
  65. OPERATE_RULE_CONTENT = (basestring, 'content')
  66. OPERATE_RULE_COMMAND = (basestring, 'command')