Online Search Cloudstack Source article is still very few, not as much as OpenStack, spent two days, will cloudstack create the source of the VM read it again, exclamation points: Create a VM process, query operation database really many. A few days ago listen to cloudstack people say, Cloudstack Management Server installed in a 16g/4c physical machine, running six months, will hang off, then that Khan ah ...
First, attach the process diagram
The following steps follow each step:
1. The Com.cloud.api.ApiServlet.processRequest (httpservletrequest, httpservletresponse) function handles all requests. Specific processing login, log out request other requests for forwarding, into the next step
2, Com.cloud.api.ApiServer.handleRequest (Map, String, StringBuffer)
Receiving a request to create a VM, the parsing parameter instantiates the class of the API based on the parameter "command" and assigns the request parameter to the object created by the class, and for the VM creation, the instantiated class is:
Org.apache.cloudstack.api.command.user.vm.DeployVMCmd.
Because it inherits from Baseasynccreatecmd, you need to call the Deployvmcmd create function first, and then call the Execute function
Note: Based on annotation assignment: Com.cloud.api.ApiDispatcher.processParameters (Basecmd, map<string, string>), rights Management is also done through annotations.
3, Org.apache.cloudstack.api.command.user.vm.DeployVMCmd.create ()
3.1 Check zone, serviceoffering, TemplateID, diskoffering, zone whether local storage is enabled, get IPv4, IPv6 address, Judge is basic zone, or advanced zone
3.2 If the basic zone, you need to call the function
Com.cloud.vm.UserVmManagerImpl.createBasicSecurityGroupVirtualMachine (Datacenter,serviceoffering, Virtualmachinetemplate, List<long>, account, String, string, long, long, string, Hypervisortype, HttpMethod, String, String, Map<long, Ipaddresses>, ipaddresses, Boolean, String, List<long>, Map<string, string> )
3.3 If the advanced zone, first determine whether the zone is enabled for security groups, and if security groups are enabled, call the function
Com.cloud.vm.UserVmManagerImpl.createAdvancedSecurityGroupVirtualMachine (DataCenter, serviceoffering, Virtualmachinetemplate, List<long>, List<long>, account, String, string, long, long, string, Hypervisortype , HttpMethod, String, String, Map<long, Ipaddresses>, Ipaddresses, Boolean, String, List<long> String, string>)
If security groups are not enabled, call the function:
Com.cloud.vm.UserVmManagerImpl.createAdvancedVirtualMachine (DataCenter, serviceoffering, Virtualmachinetemplate, List<long>, Account, String, string, long, long, string, Hypervisortype, HttpMethod, String, String, Map<long, Ip Addresses>, ipaddresses, Boolean, String, List<long>, map<string, string>)
To create a VM in basic zone for example, read the source code
4. function
Com.cloud.vm.UserVmManagerImpl.createBasicSecurityGroupVirtualMachine (Datacenter,serviceoffering, Virtualmachinetemplate, List<long>, account, String, string, long, long, string, Hypervisortype, HttpMethod, String, String, Map<long, Ipaddresses>, ipaddresses, Boolean, String, List<long>, Map<string, string> )
(4.1) According to ZoneID get the default network within the zone, execute the SQL
Select *from networks where Data_center_id=1 and account_id=1 and guesttype= ' Shared ' and traffic_type= ' Guest ';
Save the query to the default network to memory for later use. (need to join the virtual machine to the network for management)