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

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