PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/plugins/lvm-storage/web/openqrm-lvm-aoe-deployment-auth-hook.php

https://github.com/qyjohn/openqrm
PHP | 342 lines | 212 code | 61 blank | 69 comment | 8 complexity | e6f77fa4f9daf23a8ae009ad1776743f MD5 | raw file
  1. <?php
  2. /**
  3. * @package openQRM
  4. */
  5. /*
  6. This file is part of openQRM.
  7. openQRM is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License version 2
  9. as published by the Free Software Foundation.
  10. openQRM is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with openQRM. If not, see <http://www.gnu.org/licenses/>.
  16. Copyright 2009, Matthias Rechenburg <matt@openqrm.com>
  17. */
  18. // error_reporting(E_ALL);
  19. $RootDir = $_SERVER["DOCUMENT_ROOT"].'/openqrm/base/';
  20. require_once "$RootDir/include/user.inc.php";
  21. require_once "$RootDir/class/event.class.php";
  22. require_once "$RootDir/class/resource.class.php";
  23. require_once "$RootDir/class/image.class.php";
  24. require_once "$RootDir/class/image_authentication.class.php";
  25. require_once "$RootDir/class/storage.class.php";
  26. require_once "$RootDir/class/deployment.class.php";
  27. require_once "$RootDir/class/appliance.class.php";
  28. require_once "$RootDir/class/openqrm_server.class.php";
  29. require_once "$RootDir/include/openqrm-server-config.php";
  30. /**
  31. * @package openQRM
  32. * @author Matt Rechenburg <mattr_sf@users.sourceforge.net>
  33. * @version 1.0
  34. */
  35. global $OPENQRM_SERVER_BASE_DIR;
  36. global $OPENQRM_EXEC_PORT;
  37. global $IMAGE_AUTHENTICATION_TABLE;
  38. $openqrm_server = new openqrm_server();
  39. $OPENQRM_SERVER_IP_ADDRESS=$openqrm_server->get_ip_address();
  40. global $OPENQRM_SERVER_IP_ADDRESS;
  41. global $openqrm_server;
  42. $event = new event();
  43. global $event;
  44. //--------------------------------------------------
  45. /**
  46. * authenticates the storage volume for the appliance resource
  47. * <code>
  48. * storage_auth_function("start", 2);
  49. * </code>
  50. * @access public
  51. */
  52. //--------------------------------------------------
  53. function storage_auth_function($cmd, $appliance_id) {
  54. global $event;
  55. global $OPENQRM_SERVER_BASE_DIR;
  56. global $OPENQRM_SERVER_IP_ADDRESS;
  57. global $OPENQRM_EXEC_PORT;
  58. global $IMAGE_AUTHENTICATION_TABLE;
  59. global $openqrm_server;
  60. $appliance = new appliance();
  61. $appliance->get_instance_by_id($appliance_id);
  62. $image = new image();
  63. $image->get_instance_by_id($appliance->imageid);
  64. $image_name=$image->name;
  65. $image_rootdevice=$image->rootdevice;
  66. // parse the rootdevice infos
  67. $ident_separate=strpos($image_rootdevice, ":");
  68. $volume_group=substr($image_rootdevice, 0, $ident_separate);
  69. $image_rootdevice_rest=substr($image_rootdevice, $ident_separate+1);
  70. $ident_separate2=strpos($image_rootdevice_rest, ":");
  71. $image_location_name=substr($image_rootdevice_rest, 0, $ident_separate2);
  72. $root_device=substr($image_rootdevice_rest, $ident_separate2+1);
  73. $storage = new storage();
  74. $storage->get_instance_by_id($image->storageid);
  75. $storage_resource = new resource();
  76. $storage_resource->get_instance_by_id($storage->resource_id);
  77. $storage_ip = $storage_resource->ip;
  78. $deployment = new deployment();
  79. $deployment->get_instance_by_type($image->type);
  80. $deployment_type = $deployment->type;
  81. $deployment_plugin_name = $deployment->storagetype;
  82. $resource = new resource();
  83. $resource->get_instance_by_id($appliance->resources);
  84. $resource_mac=$resource->mac;
  85. $resource_ip=$resource->ip;
  86. switch($cmd) {
  87. case "start":
  88. // authenticate the rootfs / needs openqrm user + pass
  89. $openqrm_admin_user = new user("openqrm");
  90. $openqrm_admin_user->set_user();
  91. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Authenticating $image_name / $image_rootdevice to resource $resource_mac", "", "", 0, 0, $appliance_id);
  92. $auth_start_cmd = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/$deployment_plugin_name/bin/openqrm-$deployment_plugin_name auth -n $image_name -r $image_rootdevice -i $resource_mac -t lvm-aoe-deployment -u $openqrm_admin_user->name -p $openqrm_admin_user->password";
  93. $resource->send_command($storage_ip, $auth_start_cmd);
  94. // give time to settle restart of openqrm-exec daemon
  95. sleep(3);
  96. // authenticate the install-from-nfs export
  97. $run_disable_deployment_export=0;
  98. $install_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_INSTALL_FROM_NFS"));
  99. if (strlen($install_from_nfs_param)) {
  100. // storage -> resource -> auth
  101. $ip_storage_id=$deployment->parse_deployment_parameter("id", $install_from_nfs_param);
  102. $ip_storage_ip=$deployment->parse_deployment_parameter("ip", $install_from_nfs_param);
  103. $ip_image_rootdevice=$deployment->parse_deployment_parameter("path", $install_from_nfs_param);
  104. $ip_storage = new storage();
  105. $ip_storage->get_instance_by_id($ip_storage_id);
  106. $ip_storage_resource = new resource();
  107. $ip_storage_resource->get_instance_by_id($ip_storage->resource_id);
  108. $op_storage_ip = $ip_storage_resource->ip;
  109. $ip_deployment = new deployment();
  110. $ip_deployment->get_instance_by_id($ip_storage->type);
  111. $ip_deployment_type = $ip_deployment->type;
  112. $ip_deployment_plugin_name = $ip_deployment->storagetype;
  113. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Install-from-NFS: Authenticating $resource_ip on storage id $ip_storage_id:$ip_storage_ip:$ip_image_rootdevice", "", "", 0, 0, $appliance_id);
  114. $auth_install_from_nfs_start_cmd = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/$ip_deployment_plugin_name/bin/openqrm-$ip_deployment_plugin_name auth -r $ip_image_rootdevice -i $resource_ip -t $ip_deployment_type";
  115. $resource->send_command($ip_storage_ip, $auth_install_from_nfs_start_cmd);
  116. $run_disable_deployment_export=1;
  117. }
  118. // authenticate the transfer-to-nfs export
  119. $transfer_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_TRANSFER_TO_NFS"));
  120. if (strlen($transfer_from_nfs_param)) {
  121. // storage -> resource -> auth
  122. $tp_storage_id=$deployment->parse_deployment_parameter("id", $transfer_from_nfs_param);
  123. $tp_storage_ip=$deployment->parse_deployment_parameter("ip", $transfer_from_nfs_param);
  124. $tp_image_rootdevice=$deployment->parse_deployment_parameter("path", $transfer_from_nfs_param);
  125. $tp_storage = new storage();
  126. $tp_storage->get_instance_by_id($tp_storage_id);
  127. $tp_storage_resource = new resource();
  128. $tp_storage_resource->get_instance_by_id($tp_storage->resource_id);
  129. $op_storage_ip = $tp_storage_resource->ip;
  130. $tp_deployment = new deployment();
  131. $tp_deployment->get_instance_by_id($tp_storage->type);
  132. $tp_deployment_type = $tp_deployment->type;
  133. $tp_deployment_plugin_name = $tp_deployment->storagetype;
  134. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Transfer-to-NFS: Authenticating $resource_ip on storage id $tp_storage_id:$tp_storage_ip:$tp_image_rootdevice", "", "", 0, 0, $appliance_id);
  135. $auth_install_from_nfs_start_cmd = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/$tp_deployment_plugin_name/bin/openqrm-$tp_deployment_plugin_name auth -r $tp_image_rootdevice -i $resource_ip -t $tp_deployment_type";
  136. $resource->send_command($tp_storage_ip, $auth_install_from_nfs_start_cmd);
  137. $run_disable_deployment_export=1;
  138. }
  139. // do we need to disable the install-from/transfer-to-nfs exports ?
  140. if ($run_disable_deployment_export == 1) {
  141. $image_authentication = new image_authentication();
  142. $ia_id = openqrm_db_get_free_id('ia_id', $IMAGE_AUTHENTICATION_TABLE);
  143. $image_auth_ar = array(
  144. 'ia_id' => $ia_id,
  145. 'ia_image_id' => $appliance->imageid,
  146. 'ia_resource_id' => $appliance->resources,
  147. 'ia_auth_type' => 1,
  148. );
  149. $image_authentication->add($image_auth_ar);
  150. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Registered image $appliance->imageid for de-authentication the deployment exports when resource $appliance->resources is fully up.", "", "", 0, 0, $appliance_id);
  151. }
  152. break;
  153. case "stop":
  154. $image_authentication = new image_authentication();
  155. $ia_id = openqrm_db_get_free_id('ia_id', $IMAGE_AUTHENTICATION_TABLE);
  156. $image_auth_ar = array(
  157. 'ia_id' => $ia_id,
  158. 'ia_image_id' => $appliance->imageid,
  159. 'ia_resource_id' => $appliance->resources,
  160. 'ia_auth_type' => 0,
  161. );
  162. $image_authentication->add($image_auth_ar);
  163. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Registered image $appliance->imageid for de-authentication the root-fs exports when resource $appliance->resources is idle again.", "", "", 0, 0, $appliance_id);
  164. break;
  165. }
  166. }
  167. //--------------------------------------------------
  168. /**
  169. * de-authenticates the storage volume for the appliance resource
  170. * (runs via the image_authentication class)
  171. * <code>
  172. * storage_auth_stop(2);
  173. * </code>
  174. * @access public
  175. */
  176. //--------------------------------------------------
  177. function storage_auth_stop($image_id) {
  178. global $event;
  179. global $OPENQRM_SERVER_BASE_DIR;
  180. global $OPENQRM_SERVER_IP_ADDRESS;
  181. global $OPENQRM_EXEC_PORT;
  182. $image = new image();
  183. $image->get_instance_by_id($image_id);
  184. $image_name=$image->name;
  185. $image_rootdevice=$image->rootdevice;
  186. // parse the rootdevice infos
  187. $ident_separate=strpos($image_rootdevice, ":");
  188. $volume_group=substr($image_rootdevice, 0, $ident_separate);
  189. $image_rootdevice_rest=substr($image_rootdevice, $ident_separate+1);
  190. $ident_separate2=strpos($image_rootdevice_rest, ":");
  191. $image_location_name=substr($image_rootdevice_rest, 0, $ident_separate2);
  192. $root_device=substr($image_rootdevice_rest, $ident_separate2+1);
  193. $storage = new storage();
  194. $storage->get_instance_by_id($image->storageid);
  195. $storage_resource = new resource();
  196. $storage_resource->get_instance_by_id($storage->resource_id);
  197. $storage_ip = $storage_resource->ip;
  198. $deployment = new deployment();
  199. $deployment->get_instance_by_type($image->type);
  200. $deployment_type = $deployment->type;
  201. $deployment_plugin_name = $deployment->storagetype;
  202. $auth_stop_cmd = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/$deployment_plugin_name/bin/openqrm-$deployment_plugin_name auth -r $image_rootdevice -i 00:00:00:00:00:00 -t lvm-aoe-deployment";
  203. $resource = new resource();
  204. $resource->send_command($storage_ip, $auth_stop_cmd);
  205. }
  206. //--------------------------------------------------
  207. /**
  208. * de-authenticates the storage deployment volumes for the appliance resource
  209. * (runs via the image_authentication class)
  210. * <code>
  211. * storage_auth_deployment_stop(2);
  212. * </code>
  213. * @access public
  214. */
  215. //--------------------------------------------------
  216. function storage_auth_deployment_stop($image_id) {
  217. global $event;
  218. global $OPENQRM_SERVER_BASE_DIR;
  219. global $OPENQRM_SERVER_IP_ADDRESS;
  220. global $OPENQRM_EXEC_PORT;
  221. $image = new image();
  222. $image->get_instance_by_id($image_id);
  223. $image_name=$image->name;
  224. $image_rootdevice=$image->rootdevice;
  225. $storage = new storage();
  226. $storage->get_instance_by_id($image->storageid);
  227. $storage_resource = new resource();
  228. $storage_resource->get_instance_by_id($storage->resource_id);
  229. $storage_ip = $storage_resource->ip;
  230. $deployment = new deployment();
  231. $deployment->get_instance_by_type($image->type);
  232. $deployment_type = $deployment->type;
  233. $deployment_plugin_name = $deployment->storagetype;
  234. // just for sending the commands
  235. $resource = new resource();
  236. // get install deployment params
  237. $install_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_INSTALL_FROM_NFS"));
  238. if (strlen($install_from_nfs_param)) {
  239. // storage -> resource -> auth
  240. $ip_storage_id=$deployment->parse_deployment_parameter("id", $install_from_nfs_param);
  241. $ip_storage_ip=$deployment->parse_deployment_parameter("ip", $install_from_nfs_param);
  242. $ip_image_rootdevice=$deployment->parse_deployment_parameter("path", $install_from_nfs_param);
  243. $ip_storage = new storage();
  244. $ip_storage->get_instance_by_id($ip_storage_id);
  245. $ip_storage_resource = new resource();
  246. $ip_storage_resource->get_instance_by_id($ip_storage->resource_id);
  247. $op_storage_ip = $ip_storage_resource->ip;
  248. $ip_deployment = new deployment();
  249. $ip_deployment->get_instance_by_id($ip_storage->type);
  250. $ip_deployment_type = $ip_deployment->type;
  251. $ip_deployment_plugin_name = $ip_deployment->storagetype;
  252. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Install-from-NFS: Authenticating $resource_ip on storage id $ip_storage_id:$ip_storage_ip:$ip_image_rootdevice", "", "", 0, 0, $appliance_id);
  253. $auth_install_from_nfs_start_cmd = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/$ip_deployment_plugin_name/bin/openqrm-$ip_deployment_plugin_name auth -r $ip_image_rootdevice -i $OPENQRM_SERVER_IP_ADDRESS -t $ip_deployment_type";
  254. $resource->send_command($ip_storage_ip, $auth_install_from_nfs_start_cmd);
  255. }
  256. // get transfer deployment params
  257. $transfer_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_TRANSFER_TO_NFS"));
  258. if (strlen($transfer_from_nfs_param)) {
  259. // storage -> resource -> auth
  260. $tp_storage_id=$deployment->parse_deployment_parameter("id", $transfer_from_nfs_param);
  261. $tp_storage_ip=$deployment->parse_deployment_parameter("ip", $transfer_from_nfs_param);
  262. $tp_image_rootdevice=$deployment->parse_deployment_parameter("path", $transfer_from_nfs_param);
  263. $tp_storage = new storage();
  264. $tp_storage->get_instance_by_id($tp_storage_id);
  265. $tp_storage_resource = new resource();
  266. $tp_storage_resource->get_instance_by_id($tp_storage->resource_id);
  267. $op_storage_ip = $tp_storage_resource->ip;
  268. $tp_deployment = new deployment();
  269. $tp_deployment->get_instance_by_id($tp_storage->type);
  270. $tp_deployment_type = $tp_deployment->type;
  271. $tp_deployment_plugin_name = $tp_deployment->storagetype;
  272. $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-aoe-deployment-auth-hook.php", "Install-from-NFS: Authenticating $resource_ip on storage id $tp_storage_id:$tp_storage_ip:$tp_image_rootdevice", "", "", 0, 0, $appliance_id);
  273. $auth_install_from_nfs_start_cmd = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/$tp_deployment_plugin_name/bin/openqrm-$tp_deployment_plugin_name auth -r $tp_image_rootdevice -i $OPENQRM_SERVER_IP_ADDRESS -t $tp_deployment_type";
  274. $resource->send_command($tp_storage_ip, $auth_install_from_nfs_start_cmd);
  275. }
  276. }
  277. ?>