@@ -2979,8 +2979,152 @@ public function openvz_vm_delete($session_id, $vm_id)
29792979 return $ affected_rows ;
29802980 }
29812981
2982+ //* Start VM
2983+ public function openvz_vm_start ($ session_id , $ vm_id )
2984+ {
2985+ global $ app ;
2986+
2987+ if (!$ this ->checkPerm ($ session_id , 'vm_openvz ' )) {
2988+ $ this ->server ->fault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
2989+ return false ;
2990+ }
2991+
2992+ $ app ->uses ('remoting_lib ' );
2993+ $ app ->remoting_lib ->loadFormDef ('../vm/form/openvz_vm.tform.php ' );
2994+ $ vm = $ app ->remoting_lib ->getDataRecord ($ vm_id );
2995+
2996+ if (!is_array ($ vm )) {
2997+ $ this ->server ->fault ('action_pending ' , 'No VM with this ID available. ' );
2998+ return false ;
2999+ }
3000+
3001+ if ($ vm ['active ' ] == 'n ' ) {
3002+ $ this ->server ->fault ('action_pending ' , 'VM is not in active state. ' );
3003+ return false ;
3004+ }
3005+
3006+ $ action = 'openvz_start_vm ' ;
3007+
3008+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(action_id) as actions FROM sys_remoteaction
3009+ WHERE server_id = ' " .$ vm ['server_id ' ]."'
3010+ AND action_type = ' $ action'
3011+ AND action_param = ' " .$ vm ['veid ' ]."'
3012+ AND action_state = 'pending' " );
3013+
3014+ if ($ tmp ['actions ' ] > 0 ) {
3015+ $ this ->server ->fault ('action_pending ' , 'There is already a action pending for this VM. ' );
3016+ return false ;
3017+ } else {
3018+ $ sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
3019+ "VALUES ( " .
3020+ (int )$ vm ['server_id ' ] . ", " .
3021+ time () . ", " .
3022+ "' " .$ action ."', " .
3023+ $ vm ['veid ' ].", " .
3024+ "'pending', " .
3025+ "'' " .
3026+ ") " ;
3027+ $ app ->db ->query ($ sql );
3028+ }
3029+ }
29823030
3031+ //* Stop VM
3032+ public function openvz_vm_stop ($ session_id , $ vm_id )
3033+ {
3034+ global $ app ;
3035+
3036+ if (!$ this ->checkPerm ($ session_id , 'vm_openvz ' )) {
3037+ $ this ->server ->fault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
3038+ return false ;
3039+ }
3040+
3041+ $ app ->uses ('remoting_lib ' );
3042+ $ app ->remoting_lib ->loadFormDef ('../vm/form/openvz_vm.tform.php ' );
3043+ $ vm = $ app ->remoting_lib ->getDataRecord ($ vm_id );
3044+
3045+ if (!is_array ($ vm )) {
3046+ $ this ->server ->fault ('action_pending ' , 'No VM with this ID available. ' );
3047+ return false ;
3048+ }
3049+
3050+ if ($ vm ['active ' ] == 'n ' ) {
3051+ $ this ->server ->fault ('action_pending ' , 'VM is not in active state. ' );
3052+ return false ;
3053+ }
3054+
3055+ $ action = 'openvz_stop_vm ' ;
3056+
3057+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(action_id) as actions FROM sys_remoteaction
3058+ WHERE server_id = ' " .$ vm ['server_id ' ]."'
3059+ AND action_type = ' $ action'
3060+ AND action_param = ' " .$ vm ['veid ' ]."'
3061+ AND action_state = 'pending' " );
3062+
3063+ if ($ tmp ['actions ' ] > 0 ) {
3064+ $ this ->server ->fault ('action_pending ' , 'There is already a action pending for this VM. ' );
3065+ return false ;
3066+ } else {
3067+ $ sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
3068+ "VALUES ( " .
3069+ (int )$ vm ['server_id ' ] . ", " .
3070+ time () . ", " .
3071+ "' " .$ action ."', " .
3072+ $ vm ['veid ' ].", " .
3073+ "'pending', " .
3074+ "'' " .
3075+ ") " ;
3076+ $ app ->db ->query ($ sql );
3077+ }
3078+ }
29833079
3080+ //* Restart VM
3081+ public function openvz_vm_restart ($ session_id , $ vm_id )
3082+ {
3083+ global $ app ;
3084+
3085+ if (!$ this ->checkPerm ($ session_id , 'vm_openvz ' )) {
3086+ $ this ->server ->fault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
3087+ return false ;
3088+ }
3089+
3090+ $ app ->uses ('remoting_lib ' );
3091+ $ app ->remoting_lib ->loadFormDef ('../vm/form/openvz_vm.tform.php ' );
3092+ $ vm = $ app ->remoting_lib ->getDataRecord ($ vm_id );
3093+
3094+ if (!is_array ($ vm )) {
3095+ $ this ->server ->fault ('action_pending ' , 'No VM with this ID available. ' );
3096+ return false ;
3097+ }
3098+
3099+ if ($ vm ['active ' ] == 'n ' ) {
3100+ $ this ->server ->fault ('action_pending ' , 'VM is not in active state. ' );
3101+ return false ;
3102+ }
3103+
3104+ $ action = 'openvz_restart_vm ' ;
3105+
3106+ $ tmp = $ app ->db ->queryOneRecord ("SELECT count(action_id) as actions FROM sys_remoteaction
3107+ WHERE server_id = ' " .$ vm ['server_id ' ]."'
3108+ AND action_type = ' $ action'
3109+ AND action_param = ' " .$ vm ['veid ' ]."'
3110+ AND action_state = 'pending' " );
3111+
3112+ if ($ tmp ['actions ' ] > 0 ) {
3113+ $ this ->server ->fault ('action_pending ' , 'There is already a action pending for this VM. ' );
3114+ return false ;
3115+ } else {
3116+ $ sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
3117+ "VALUES ( " .
3118+ (int )$ vm ['server_id ' ] . ", " .
3119+ time () . ", " .
3120+ "' " .$ action ."', " .
3121+ $ vm ['veid ' ].", " .
3122+ "'pending', " .
3123+ "'' " .
3124+ ") " ;
3125+ $ app ->db ->query ($ sql );
3126+ }
3127+ }
29843128
29853129
29863130
0 commit comments