Welcome Guest. Please Login or Register  


You are here: Index > Virtualizor - Virtual Server Control Panel > General Support > Topic : KVM AfterCreate()



Normal Mode | Print  

KVM AfterCreate()
asim_shaikh
Group: Member
Post Group: Elite Member
Posts: 381
Status:
Quote
Hi again,

I don't think you're following me.

I dont want to assign an IP because Virtualizor does that.

I want to run the receipt in order to change the network of the VPS.

My FreeBSD template DOESN'T AUTO CONFIGURE, so I need to insert in
the NEW VPS /etc/rc.conf file some lines so the NETWORK Works.

I understood that Receipt will run inside the VPS the bash script
BUT that doesnt work unless i can pass to the SCRIPT the IP ASSIGN TO
THE VPS by Virtualizor.

I can't be much more explicit sir..
   
   


Hi,

Ok, in that case no information will be available inside the VPS.
In such what you can do is you can mount the VPS and alter the /etc/rc.conf file.
For that firstly you will need to shutdown the VPS, then mount the VPS.

To get the gateway of the IP assigned to the VPS you will first need to get the ippool id to fetch the ippool details from the ippool table.

You can get the IPpool id from the ips table.

You can use the following code to do your task.
Let me know if you face any issue.

PHP Code

 include_once(dirname(__DIR__)'/main/funtions.php');
    
    function 
__after_createvps($vps){

        
$vid $vps['vpsid'];

       
$res mysql_query("SELECT ippid from ips where vpsid = '.$vid.' AND primary = 1");

      
$row mysql_fetch_assoc($res);

      
$res mysql_query("SELECT * from ippool where ippid = '.$row['ippid'].'");


      
$row mysql_fetch_assoc($res);

      
$gateway $row['gateway '];
        
        
exec('virsh destroy '.$vps['vps_name']);
        
        
sleep(5);       
        
        
// Mount it
        
$mount mount($vid);
        
        
// Did it mount ?
        
if(!is_array($mount)){
            return 
false;
        }
        
        
$code '
ifconfig_em0="inet IP.FAIL.OVER netmask 255.255.255.255 broadcast IP.FAIL.OVER"
static_routes="net1 net2"
route_net1="-net '
.$gateway.'/32 IP.FAIL.OVER"
route_net2="default "'
.$gateway;
        
        
file_put_contents($mount['mount_point'].'/etc/rc.conf'$codeFILE_APPEND);
                
        
// Unmount it
        
$umount umount($mount);
    } 





Edited by asim_shaikh : September 14, 2016, 7:01 am

-----------------------
Regards,
Virtualizor Team
http://www.virtualizor.com
IP: --   


Threads
 netheld   KVM AfterCreate(), Edit VM file before start (7 Replies, Read 3812 times)
    |--  asim_shaikh   Hi there guys,...   on September 9, 2016, 6:22 am
    |--  netheld   Ok I did...   on September 9, 2016, 11:44 pm
    |--  asim_shaikh   Ok I did...   on September 12, 2016, 5:47 am
    |--  netheld   Ok I did...   on September 12, 2016, 11:38 am
    |--  asim_shaikh   You didnt answer...   on September 12, 2016, 12:44 pm
    |--  netheld   You didnt answer...   on September 12, 2016, 1:09 pm
    |--  asim_shaikh   Hi again, I...   on September 14, 2016, 7:01 am

« Previous    Next »

Normal Mode | Print  



Users viewing this topic
1 guests, 0 users.


All times are GMT. The time now is May 11, 2025, 12:58 am.

  Powered By AEF 1.0.8 © 2007-2008 Electron Inc.Queries: 10  |  Page Created In:0.027