Fuel UI
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.

urls.py 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2013 Mirantis, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. import web
  16. from nailgun.extensions import get_all_extensions
  17. from nailgun.api.v1.handlers.assignment import NodeAssignmentHandler
  18. from nailgun.api.v1.handlers.assignment import NodeUnassignmentHandler
  19. from nailgun.api.v1.handlers.capacity import CapacityLogCsvHandler
  20. from nailgun.api.v1.handlers.capacity import CapacityLogHandler
  21. from nailgun.api.v1.handlers.cluster import ClusterAttributesDefaultsHandler
  22. from nailgun.api.v1.handlers.cluster import ClusterAttributesDeployedHandler
  23. from nailgun.api.v1.handlers.cluster import ClusterAttributesHandler
  24. from nailgun.api.v1.handlers.cluster import ClusterChangesForceRedeployHandler
  25. from nailgun.api.v1.handlers.cluster import ClusterChangesHandler
  26. from nailgun.api.v1.handlers.cluster import ClusterCollectionHandler
  27. from nailgun.api.v1.handlers.cluster import \
  28. ClusterDeploymentGraphCollectionHandler
  29. from nailgun.api.v1.handlers.cluster import ClusterDeploymentGraphHandler
  30. from nailgun.api.v1.handlers.cluster import ClusterDeploymentTasksHandler
  31. from nailgun.api.v1.handlers.cluster import ClusterExtensionsHandler
  32. from nailgun.api.v1.handlers.cluster import ClusterGeneratedData
  33. from nailgun.api.v1.handlers.cluster import ClusterHandler
  34. from nailgun.api.v1.handlers.cluster import ClusterOwnDeploymentTasksHandler
  35. from nailgun.api.v1.handlers.cluster import \
  36. ClusterPluginsDeploymentTasksHandler
  37. from nailgun.api.v1.handlers.cluster import \
  38. ClusterReleaseDeploymentTasksHandler
  39. from nailgun.api.v1.handlers.cluster import ClusterResetHandler
  40. from nailgun.api.v1.handlers.cluster import ClusterStopDeploymentHandler
  41. from nailgun.api.v1.handlers.cluster import VmwareAttributesDefaultsHandler
  42. from nailgun.api.v1.handlers.cluster import VmwareAttributesHandler
  43. from nailgun.api.v1.handlers.component import ComponentCollectionHandler
  44. from nailgun.api.v1.handlers.cluster_plugin_link \
  45. import ClusterPluginLinkCollectionHandler
  46. from nailgun.api.v1.handlers.cluster_plugin_link \
  47. import ClusterPluginLinkHandler
  48. from nailgun.api.v1.handlers.deployment_history \
  49. import DeploymentHistoryCollectionHandler
  50. from nailgun.api.v1.handlers.extension import ExtensionHandler
  51. from nailgun.api.v1.handlers.logs import LogEntryCollectionHandler
  52. from nailgun.api.v1.handlers.logs import LogPackageDefaultConfig
  53. from nailgun.api.v1.handlers.logs import LogPackageHandler
  54. from nailgun.api.v1.handlers.logs import LogSourceByNodeCollectionHandler
  55. from nailgun.api.v1.handlers.logs import LogSourceCollectionHandler
  56. from nailgun.api.v1.handlers.logs import SnapshotDownloadHandler
  57. from nailgun.api.v1.handlers.node_group import NodeGroupCollectionHandler
  58. from nailgun.api.v1.handlers.node_group import NodeGroupHandler
  59. from nailgun.api.v1.handlers.node import NodeAgentHandler
  60. from nailgun.api.v1.handlers.node import NodeAttributesDefaultsHandler
  61. from nailgun.api.v1.handlers.node import NodeAttributesHandler
  62. from nailgun.api.v1.handlers.node import NodeCollectionHandler
  63. from nailgun.api.v1.handlers.node import NodeHandler
  64. from nailgun.api.v1.handlers.node import NodesAllocationStatsHandler
  65. from nailgun.api.v1.handlers.plugin import PluginCollectionHandler
  66. from nailgun.api.v1.handlers.plugin import \
  67. PluginDeploymentGraphCollectionHandler
  68. from nailgun.api.v1.handlers.plugin import PluginDeploymentGraphHandler
  69. from nailgun.api.v1.handlers.plugin import PluginHandler
  70. from nailgun.api.v1.handlers.plugin import PluginSyncHandler
  71. from nailgun.api.v1.handlers.plugin_link import PluginLinkCollectionHandler
  72. from nailgun.api.v1.handlers.plugin_link import PluginLinkHandler
  73. from nailgun.api.v1.handlers.notifications import NotificationCollectionHandler
  74. from nailgun.api.v1.handlers.notifications import \
  75. NotificationCollectionStatsHandler
  76. from nailgun.api.v1.handlers.notifications import \
  77. NotificationStatusHandler
  78. from nailgun.api.v1.handlers.notifications import NotificationHandler
  79. from nailgun.api.v1.handlers.orchestrator import DefaultDeploymentInfo
  80. from nailgun.api.v1.handlers.orchestrator import DefaultPostPluginsHooksInfo
  81. from nailgun.api.v1.handlers.orchestrator import DefaultPrePluginsHooksInfo
  82. from nailgun.api.v1.handlers.orchestrator import DefaultProvisioningInfo
  83. from nailgun.api.v1.handlers.orchestrator import DeploymentInfo
  84. from nailgun.api.v1.handlers.orchestrator import DeploySelectedNodes
  85. from nailgun.api.v1.handlers.orchestrator import DeploySelectedNodesWithTasks
  86. from nailgun.api.v1.handlers.orchestrator import ProvisioningInfo
  87. from nailgun.api.v1.handlers.orchestrator import ProvisionSelectedNodes
  88. from nailgun.api.v1.handlers.orchestrator import SerializedTasksHandler
  89. from nailgun.api.v1.handlers.orchestrator import TaskDeployGraph
  90. from nailgun.api.v1.handlers.release import ReleaseAttributesMetadataHandler
  91. from nailgun.api.v1.handlers.release import ReleaseCollectionHandler
  92. from nailgun.api.v1.handlers.release import \
  93. ReleaseDeploymentGraphCollectionHandler
  94. from nailgun.api.v1.handlers.release import ReleaseDeploymentGraphHandler
  95. from nailgun.api.v1.handlers.release import ReleaseDeploymentTasksHandler
  96. from nailgun.api.v1.handlers.release import ReleaseHandler
  97. from nailgun.api.v1.handlers.release import ReleaseNetworksHandler
  98. from nailgun.api.v1.handlers.role import RoleCollectionHandler
  99. from nailgun.api.v1.handlers.role import RoleHandler
  100. from nailgun.api.v1.handlers.tag import TagCollectionHandler
  101. from nailgun.api.v1.handlers.tag import TagHandler
  102. from nailgun.api.v1.handlers.tasks import TaskCollectionHandler
  103. from nailgun.api.v1.handlers.tasks import TaskHandler
  104. from nailgun.api.v1.handlers.transactions import TransactionClusterSettings
  105. from nailgun.api.v1.handlers.transactions import TransactionCollectionHandler
  106. from nailgun.api.v1.handlers.transactions import TransactionDeploymentInfo
  107. from nailgun.api.v1.handlers.transactions import TransactionHandler
  108. from nailgun.api.v1.handlers.transactions import TransactionNetworkSettings
  109. from nailgun.api.v1.handlers.version import VersionHandler
  110. from nailgun.api.v1.handlers.vms import NodeVMsHandler
  111. from nailgun.api.v1.handlers.vms import SpawnVmsHandler
  112. from nailgun.api.v1.handlers.removed import RemovedIn51RedHatAccountHandler
  113. from nailgun.api.v1.handlers.removed import RemovedIn51RedHatSetupHandler
  114. from nailgun.api.v1.handlers.master_node_settings \
  115. import MasterNodeSettingsHandler
  116. from nailgun.api.v1.handlers.openstack_config \
  117. import OpenstackConfigCollectionHandler
  118. from nailgun.api.v1.handlers.openstack_config \
  119. import OpenstackConfigExecuteHandler
  120. from nailgun.api.v1.handlers.openstack_config import OpenstackConfigHandler
  121. from nailgun.api.v1.handlers.deployment_graph import \
  122. DeploymentGraphCollectionHandler
  123. from nailgun.api.v1.handlers.deployment_graph import \
  124. DeploymentGraphHandler
  125. from nailgun.api.v1.handlers.deployment_graph import GraphsExecutorHandler
  126. from nailgun.api.v1.handlers.deployment_sequence import \
  127. SequenceCollectionHandler
  128. from nailgun.api.v1.handlers.deployment_sequence import SequenceExecutorHandler
  129. from nailgun.api.v1.handlers.deployment_sequence import SequenceHandler
  130. from nailgun.settings import settings
  131. urls = (
  132. r'/releases/?$',
  133. ReleaseCollectionHandler,
  134. r'/releases/(?P<obj_id>\d+)/attributes_metadata/?$',
  135. ReleaseAttributesMetadataHandler,
  136. r'/releases/(?P<obj_id>\d+)/?$',
  137. ReleaseHandler,
  138. r'/releases/(?P<obj_id>\d+)/networks/?$',
  139. ReleaseNetworksHandler,
  140. r'/releases/(?P<obj_id>\d+)/deployment_tasks/?$',
  141. ReleaseDeploymentTasksHandler,
  142. r'/releases/(?P<release_id>\d+)/components/?$',
  143. ComponentCollectionHandler,
  144. r'/(?P<obj_type>releases|clusters)/(?P<obj_id>\d+)/roles/?$',
  145. RoleCollectionHandler,
  146. r'/(?P<obj_type>releases|clusters)/(?P<obj_id>\d+)/roles/'
  147. '(?P<role_name>[a-zA-Z0-9-_]+)/?$',
  148. RoleHandler,
  149. r'/(?P<obj_type>releases|clusters)/(?P<obj_id>\d+)/tags/?$',
  150. TagCollectionHandler,
  151. r'/(?P<obj_type>releases|clusters)/(?P<obj_id>\d+)/tags/'
  152. '(?P<tag_name>[a-zA-Z0-9-_]+)/?$',
  153. TagHandler,
  154. r'/releases/(?P<obj_id>\d+)/deployment_graphs/?$',
  155. ReleaseDeploymentGraphCollectionHandler,
  156. r'/releases/(?P<obj_id>\d+)/deployment_graphs/'
  157. r'(?P<graph_type>[a-zA-Z0-9-_]+)/?$',
  158. ReleaseDeploymentGraphHandler,
  159. r'/clusters/?$',
  160. ClusterCollectionHandler,
  161. r'/clusters/(?P<obj_id>\d+)/?$',
  162. ClusterHandler,
  163. r'/clusters/(?P<cluster_id>\d+)/changes/?$',
  164. ClusterChangesHandler,
  165. r'/clusters/(?P<cluster_id>\d+)/changes/redeploy/?$',
  166. ClusterChangesForceRedeployHandler,
  167. r'/clusters/(?P<cluster_id>\d+)/attributes/?$',
  168. ClusterAttributesHandler,
  169. r'/clusters/(?P<cluster_id>\d+)/attributes/defaults/?$',
  170. ClusterAttributesDefaultsHandler,
  171. r'/clusters/(?P<cluster_id>\d+)/attributes/deployed/?$',
  172. ClusterAttributesDeployedHandler,
  173. r'/clusters/(?P<cluster_id>\d+)/orchestrator/deployment/?$',
  174. DeploymentInfo,
  175. r'/clusters/(?P<cluster_id>\d+)/orchestrator/deployment/defaults/?$',
  176. DefaultDeploymentInfo,
  177. r'/clusters/(?P<cluster_id>\d+)/orchestrator/provisioning/?$',
  178. ProvisioningInfo,
  179. r'/clusters/(?P<cluster_id>\d+)/orchestrator/provisioning/defaults/?$',
  180. DefaultProvisioningInfo,
  181. r'/clusters/(?P<cluster_id>\d+)/generated/?$',
  182. ClusterGeneratedData,
  183. r'/clusters/(?P<cluster_id>\d+)/orchestrator/plugins_pre_hooks/?$',
  184. DefaultPrePluginsHooksInfo,
  185. r'/clusters/(?P<cluster_id>\d+)/orchestrator/plugins_post_hooks/?$',
  186. DefaultPostPluginsHooksInfo,
  187. r'/clusters/(?P<cluster_id>\d+)/serialized_tasks/?$',
  188. SerializedTasksHandler,
  189. r'/clusters/(?P<cluster_id>\d+)/provision/?$',
  190. ProvisionSelectedNodes,
  191. r'/clusters/(?P<cluster_id>\d+)/deploy/?$',
  192. DeploySelectedNodes,
  193. r'/clusters/(?P<cluster_id>\d+)/deploy_tasks/?$',
  194. DeploySelectedNodesWithTasks,
  195. r'/clusters/(?P<cluster_id>\d+)/deploy_tasks/graph.gv$',
  196. TaskDeployGraph,
  197. r'/clusters/(?P<cluster_id>\d+)/stop_deployment/?$',
  198. ClusterStopDeploymentHandler,
  199. r'/clusters/(?P<cluster_id>\d+)/reset/?$',
  200. ClusterResetHandler,
  201. r'/clusters/(?P<obj_id>\d+)/deployment_tasks/?$',
  202. ClusterDeploymentTasksHandler,
  203. r'/clusters/(?P<obj_id>\d+)/deployment_tasks/own/?$',
  204. ClusterOwnDeploymentTasksHandler,
  205. r'/clusters/(?P<obj_id>\d+)/deployment_tasks/plugins/?$',
  206. ClusterPluginsDeploymentTasksHandler,
  207. r'/clusters/(?P<obj_id>\d+)/deployment_tasks/release/?$',
  208. ClusterReleaseDeploymentTasksHandler,
  209. r'/clusters/(?P<obj_id>\d+)/deployment_graphs/?$',
  210. ClusterDeploymentGraphCollectionHandler,
  211. r'/clusters/(?P<obj_id>\d+)/deployment_graphs/'
  212. r'(?P<graph_type>[a-zA-Z0-9-_]+)/?$',
  213. ClusterDeploymentGraphHandler,
  214. r'/graphs/?$',
  215. DeploymentGraphCollectionHandler,
  216. r'/graphs/(?P<obj_id>\d+)/?$',
  217. DeploymentGraphHandler,
  218. r'/graphs/execute/?$',
  219. GraphsExecutorHandler,
  220. r'/sequences/?$',
  221. SequenceCollectionHandler,
  222. r'/sequences/(?P<obj_id>\d+)/?$',
  223. SequenceHandler,
  224. r'/sequences/(?P<obj_id>\d+)/execute/?$',
  225. SequenceExecutorHandler,
  226. r'/clusters/(?P<cluster_id>\d+)/assignment/?$',
  227. NodeAssignmentHandler,
  228. r'/clusters/(?P<cluster_id>\d+)/unassignment/?$',
  229. NodeUnassignmentHandler,
  230. r'/clusters/(?P<cluster_id>\d+)/vmware_attributes/?$',
  231. VmwareAttributesHandler,
  232. r'/clusters/(?P<cluster_id>\d+)/vmware_attributes/defaults/?$',
  233. VmwareAttributesDefaultsHandler,
  234. r'/clusters/(?P<cluster_id>\d+)/plugin_links/?$',
  235. ClusterPluginLinkCollectionHandler,
  236. r'/clusters/(?P<cluster_id>\d+)/plugin_links/(?P<obj_id>\d+)/?$',
  237. ClusterPluginLinkHandler,
  238. r'/extensions/?$',
  239. ExtensionHandler,
  240. r'/clusters/(?P<cluster_id>\d+)/extensions/?$',
  241. ClusterExtensionsHandler,
  242. r'/nodegroups/?$',
  243. NodeGroupCollectionHandler,
  244. r'/nodegroups/(?P<obj_id>\d+)/?$',
  245. NodeGroupHandler,
  246. r'/nodes/?$',
  247. NodeCollectionHandler,
  248. r'/nodes/agent/?$',
  249. NodeAgentHandler,
  250. r'/nodes/(?P<obj_id>\d+)/?$',
  251. NodeHandler,
  252. r'/nodes/(?P<node_id>\d+)/attributes/?$',
  253. NodeAttributesHandler,
  254. r'/nodes/(?P<node_id>\d+)/attributes/defaults/?$',
  255. NodeAttributesDefaultsHandler,
  256. r'/nodes/allocation/stats/?$',
  257. NodesAllocationStatsHandler,
  258. r'/tasks/?$',
  259. TaskCollectionHandler,
  260. r'/tasks/(?P<obj_id>\d+)/?$',
  261. TaskHandler,
  262. r'/transactions/?$',
  263. TransactionCollectionHandler,
  264. r'/transactions/(?P<obj_id>\d+)/?$',
  265. TransactionHandler,
  266. r'/transactions/(?P<transaction_id>\d+)/deployment_history/?$',
  267. DeploymentHistoryCollectionHandler,
  268. r'/transactions/(?P<transaction_id>\d+)/deployment_info/?$',
  269. TransactionDeploymentInfo,
  270. r'/transactions/(?P<transaction_id>\d+)/network_configuration/?$',
  271. TransactionNetworkSettings,
  272. r'/transactions/(?P<transaction_id>\d+)/settings/?$',
  273. TransactionClusterSettings,
  274. r'/plugins/(?P<plugin_id>\d+)/links/?$',
  275. PluginLinkCollectionHandler,
  276. r'/plugins/(?P<plugin_id>\d+)/links/(?P<obj_id>\d+)/?$',
  277. PluginLinkHandler,
  278. r'/plugins/(?P<obj_id>\d+)/?$',
  279. PluginHandler,
  280. r'/plugins/?$',
  281. PluginCollectionHandler,
  282. r'/plugins/sync/?$',
  283. PluginSyncHandler,
  284. r'/plugins/(?P<obj_id>\d+)/deployment_graphs/?$',
  285. PluginDeploymentGraphCollectionHandler,
  286. r'/plugins/(?P<obj_id>\d+)/deployment_graphs/'
  287. r'(?P<graph_type>[a-zA-Z0-9-_]+)/?$',
  288. PluginDeploymentGraphHandler,
  289. r'/notifications/?$',
  290. NotificationCollectionHandler,
  291. r'/notifications/change_status/?$',
  292. NotificationStatusHandler,
  293. r'/notifications/(?P<obj_id>\d+)/?$',
  294. NotificationHandler,
  295. r'/notifications/stats/?$',
  296. NotificationCollectionStatsHandler,
  297. r'/dump/(?P<snapshot_name>[A-Za-z0-9-_.]+)$',
  298. SnapshotDownloadHandler,
  299. r'/logs/?$',
  300. LogEntryCollectionHandler,
  301. r'/logs/package/?$',
  302. LogPackageHandler,
  303. r'/logs/package/config/default/?$',
  304. LogPackageDefaultConfig,
  305. r'/logs/sources/?$',
  306. LogSourceCollectionHandler,
  307. r'/logs/sources/nodes/(?P<node_id>\d+)/?$',
  308. LogSourceByNodeCollectionHandler,
  309. r'/version/?$',
  310. VersionHandler,
  311. r'/capacity/?$',
  312. CapacityLogHandler,
  313. r'/capacity/csv/?$',
  314. CapacityLogCsvHandler,
  315. r'/redhat/account/?$',
  316. RemovedIn51RedHatAccountHandler,
  317. r'/redhat/setup/?$',
  318. RemovedIn51RedHatSetupHandler,
  319. r'/settings/?$',
  320. MasterNodeSettingsHandler,
  321. r'/openstack-config/?$',
  322. OpenstackConfigCollectionHandler,
  323. r'/openstack-config/(?P<obj_id>\d+)/?$',
  324. OpenstackConfigHandler,
  325. r'/openstack-config/execute/?$',
  326. OpenstackConfigExecuteHandler,
  327. )
  328. feature_groups_urls = {
  329. 'advanced': (
  330. r'/clusters/(?P<cluster_id>\d+)/spawn_vms/?$',
  331. SpawnVmsHandler,
  332. r'/nodes/(?P<node_id>\d+)/vms_conf/?$',
  333. NodeVMsHandler,
  334. )
  335. }
  336. urls = [i if isinstance(i, str) else i.__name__ for i in urls]
  337. _locals = locals()
  338. def get_extensions_urls():
  339. """Get handlers and urls from extensions, convert them into web.py format
  340. :returns: dict in the next format:
  341. {'urls': (r'/url/', 'ClassName'),
  342. 'handlers': [{
  343. 'class': ClassName,
  344. 'name': 'ClassName'}]}
  345. """
  346. urls = []
  347. handlers = []
  348. for extension in get_all_extensions():
  349. for url in extension.urls:
  350. # TODO(eli): handler name should be extension specific
  351. # not to have problems when several extensions use
  352. # the same name for handler classes.
  353. # Should be done as a part of blueprint:
  354. # https://blueprints.launchpad.net/fuel/+spec
  355. # /volume-manager-refactoring
  356. handler_name = url['handler'].__name__
  357. handlers.append({
  358. 'class': url['handler'],
  359. 'name': handler_name})
  360. urls.extend((url['uri'], handler_name))
  361. return {'urls': urls, 'handlers': handlers}
  362. def get_feature_groups_urls():
  363. """Method for retrieving urls dependant on feature groups
  364. Feature groups can be 'experimental' or 'advanced' which should be
  365. enable only for this modes.
  366. :returns: list of urls
  367. """
  368. urls = []
  369. for feature in settings.VERSION['feature_groups']:
  370. urls.extend([i if isinstance(i, str) else i.__name__ for i in
  371. feature_groups_urls.get(feature, [])])
  372. return urls
  373. def get_all_urls():
  374. """Merges urls and handlers from core and from extensions"""
  375. ext_urls = get_extensions_urls()
  376. all_urls = list(urls)
  377. all_urls.extend(get_feature_groups_urls())
  378. all_urls.extend(ext_urls['urls'])
  379. for handler in ext_urls['handlers']:
  380. _locals[handler['name']] = handler['class']
  381. return [all_urls, _locals]
  382. def app():
  383. return web.application(*get_all_urls())
  384. def public_urls():
  385. return {
  386. r'/nodes/?$': ['POST'],
  387. r'/nodes/agent/?$': ['PUT'],
  388. r'/clusters/(?P<cluster_id>\d+)/plugin_links/?$': ['POST']
  389. }
  390. def cookie_urls():
  391. return [
  392. r'/api(/v[0-9]+)?/dump/[A-Za-z0-9-_.]+$',
  393. r'/api(/v[0-9]+)?/capacity/csv/?$'
  394. ]