Procedure for creating an instance on openstack

Source: Internet
Author: User

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

  1. 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
  1. Self. _ ask_scheduler_to_create_instance (context, base_options,
  2. Instance_type, zone_blob,
  3. Availability_zone, injected_files,
  4. Admin_password, image,
  5. Instance_id = instance_id,
  6. Requested_networks = requested_networks)


2.The API forwards the processed data to scheduler through MQ. (code from computer. API)
 

Python code
  1. Rpc. Cast (context,
  2. Flags. scheduler_topic,
  3. {"Method": "run_instance ",
  4. "ARGs": {"topic": Flags. compute_topic,
  5. "Instance_id": instance_id,
  6. "Request_spec": request_spec,
  7. "Availability_zone": availability_zone,
  8. "Admin_password": admin_password,
  9. "Injected_files": injected_files,
  10. "Requested_networks": requested_networks }})

3.Scheduler obtains information and determines which host can run the instance.
Python code

  1. Def _ getattr _ (self, key ):
  2. Return functools. Partial (self. _ schedule, key)

Python code

  1. Def _ schedule (self, method, context, topic, * ARGs, ** kwargs ):
  2. .......
  3. Rpc. Cast (context,
  4. DB. queue_get_for (context, topic, host ),
  5. {"Method": method,
  6. "ARGs": kwargs })
  7. 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

  1. Network_info = self. network_api.allocate_for_instance (context,
  2. Instance, VPN = is_vpn,
  3. Requested_networks = requested_networks)
Python code
  1. Def allocate_floating_ip (self, context ):
  2. Return rpc. Call (context,
  3. Flags. network_topic,
  4. {'Method': 'allocate _ floating_ip ',
  5. 'Args': {'Project _ id': context. project_id }})

B. Prepare the volume for volume.

Python code
  1. Bd_mapping = self. _ setup_block_device_mapping (context, instance_id)
  2. Def create (self, context, size, snapshot_id, name, description,
  3. Volume_type = none, metadata = none, availability_zone = none ):
  4. Rpc. Cast (context,
  5. Flags. scheduler_topic,
  6. {"Method": "create_volume ",
  7. "ARGs": {"topic": Flags. volume_topic,
  8. "Volume_id": volume ['id'],
  9. "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

  1. Domain = self. _ create_new_domain (XML)
  2. Def _ create_new_domain (self, XML, persistent = true, launch_flags = 0 ):
  3. If persistent:
  4. # To create a persistent domain, first define it, then launch it.
  5. Domain = self. _ conn. definexml (XML)
  6. Domain. createwithflags (launch_flags)
  7. Else:
  8. # Createxml call creates a transient domain
  9. Domain = self. _ conn. createxml (XML, launch_flags)
  10. Return domain

E call virt. libvirt. connetion. spwan waiting

Python code
  1. Def spawn (self, context, instance, network_info,
  2. Block_device_info = none ):
  3. ..........
  4. Def _ wait_for_boot ():
  5. Instance_name = instance ['name']
  6. Try:
  7. State = self. get_info (instance_name) ['state']
  8. Failed t exception. notfound:
  9. MSG = _ ("during reboot, % s disappeared.") % instance_name
  10. Log. Error (MSG)
  11. Raise utils. loopingcalldone
  12. If State = power_state.running:
  13. MSG = _ ("instance % s spawned successfully.") % instance_name
  14. Log.info (MSG)
  15. Raise utils. loopingcalldone
  16. Timer = utils. loopingcall (_ wait_for_boot)
  17. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.