Workflow:
1.The user sends a request to the Nova-API
The user sends a request to the Nova-API. There are two types:
A. Use the openstack API
From server. py's controller. Create (): Python code
- Self. helper. create_instance (req, body, self. compute_api.create)
Create_instance_helper.createinstancehelper ()
B. Use EC2 API
From cloud. py. run_instances ()
Uniformly call computer. API. Create () to insert new data back
Python code
- Self. _ ask_scheduler_to_create_instance (context, base_options,
- Instance_type, zone_blob,
- Availability_zone, injected_files,
- Admin_password, image,
- Instance_id = instance_id,
- Requested_networks = requested_networks)
2.The API forwards the processed data to scheduler through MQ. (code from computer. API)
Python code
- Rpc. Cast (context,
- Flags. scheduler_topic,
- {"Method": "run_instance ",
- "ARGs": {"topic": Flags. compute_topic,
- "Instance_id": instance_id,
- "Request_spec": request_spec,
- "Availability_zone": availability_zone,
- "Admin_password": admin_password,
- "Injected_files": injected_files,
- "Requested_networks": requested_networks }})
3.Scheduler obtains information and determines which host can run the instance.
Python code
- Def _ getattr _ (self, key ):
- Return functools. Partial (self. _ schedule, key)
Python code
- Def _ schedule (self, method, context, topic, * ARGs, ** kwargs ):
- .......
- Rpc. Cast (context,
- DB. queue_get_for (context, topic, host ),
- {"Method": method,
- "ARGs": kwargs })
- Log. debug (_ ("casted to % (topic) S % (host) s for % (method) s") % locals ())
4.The computer obtains information from the pool and asks networker to prepare an IP address, asks volume to prepare the volume, and then initializes the corresponding information, such as creating an image, ing the device, and creating a domain,
Put the domain in the running pool and wait until the instance status changes to running.
A. networker assigns ippython code
- Network_info = self. network_api.allocate_for_instance (context,
- Instance, VPN = is_vpn,
- Requested_networks = requested_networks)
Python code
- Def allocate_floating_ip (self, context ):
- Return rpc. Call (context,
- Flags. network_topic,
- {'Method': 'allocate _ floating_ip ',
- 'Args': {'Project _ id': context. project_id }})
B. Prepare the volume for volume.
Python code
- Bd_mapping = self. _ setup_block_device_mapping (context, instance_id)
- Def create (self, context, size, snapshot_id, name, description,
- Volume_type = none, metadata = none, availability_zone = none ):
- Rpc. Cast (context,
- Flags. scheduler_topic,
- {"Method": "create_volume ",
- "ARGs": {"topic": Flags. volume_topic,
- "Volume_id": volume ['id'],
- "Snapshot_id": snapshot_id }})
C call Nova. virt. libvirt. Firewall. iptablesfirewalldriver establish network rules
Here is the main scene. I have a separate post to record it ....
D call libvirt create domian and launchpython code
- Domain = self. _ create_new_domain (XML)
- Def _ create_new_domain (self, XML, persistent = true, launch_flags = 0 ):
- If persistent:
- # To create a persistent domain, first define it, then launch it.
- Domain = self. _ conn. definexml (XML)
- Domain. createwithflags (launch_flags)
- Else:
- # Createxml call creates a transient domain
- Domain = self. _ conn. createxml (XML, launch_flags)
- Return domain
E call virt. libvirt. connetion. spwan waiting
Python code
- Def spawn (self, context, instance, network_info,
- Block_device_info = none ):
- ..........
- Def _ wait_for_boot ():
- Instance_name = instance ['name']
- Try:
- State = self. get_info (instance_name) ['state']
- Failed t exception. notfound:
- MSG = _ ("during reboot, % s disappeared.") % instance_name
- Log. Error (MSG)
- Raise utils. loopingcalldone
- If State = power_state.running:
- MSG = _ ("instance % s spawned successfully.") % instance_name
- Log.info (MSG)
- Raise utils. loopingcalldone
- Timer = utils. loopingcall (_ wait_for_boot)
- Return timer. Start (interval = 0.5, now = true)
5Once the instance status changes to running, it will get network information through networker. There are several methods available here, depending on your NetworkManager
For details, see Step C.