Nova queries, creates, deletes flavor through the Python API

Source: Internet
Author: User

1[[Email protected] ~]#Cat flavor.py2  fromNovaclientImportClient as Nvclient3  fromNovaclientImportUtils4  fromNovaclientImportBase5 6  fromKeystoneauth1.identityImportv37  fromKeystoneauth1ImportSession8  fromKeystoneclient.v3ImportClient9 Ten Import Time One ImportSYS A ImportKeystoneclient.v3.client as Ksclient -  fromNeutronclient.v2_0ImportClient as Netclient -  the #Keystone Get project_id -Auth = v3. Password (user_domain_name='Default', -Username='Admin', -password='OpenStack', +Project_domain_name='Default', -Project_name='Admin', +Auth_url='Http://controller:35357/v3') ASess = Session. Session (auth=auth) atKeystone = client. Client (session=sess) -  -Projects_list =keystone.projects.list () -  forOinchprojects_list: -Name = GetAttr (O,"name","') -     ifName = ="Admin": inproject_id = GetAttr (o,"ID","') -          Break to  + #Nova -Nova = nvclient. Client ('2.42','Admin','OpenStack', project_id,'http://controller:5000/v2.0') the  * defflavors_list (): $Flavors_list =nova.flavors.list ()Panax Notoginseng     Print "================ List Flavor ==============" -      forDatainchflavors_list: the         Print "ID:"+data.id +         Print "Name:"+Data.name A         Print "CPU:"+Str (data.vcpus) the         Print "MEM:"+Str (data.ram) +         Print "Disk:"+Str (data.disk) -         Print "===========================================" $     Print "" $  - defflavors_create (name, RAM, Vcpus, disk): -     Print "=============== Create Flavor =============" theFlavors_create = nova.flavors.create (name, RAM, Vcpus, disk, flavorid="Auto", -Ephemeral=0, Swap=0, rxtx_factor=1.0, is_public=True)Wuyi     Printflavors_create the     Print "=================== End =================" -     Print "" Wu  - defSet_key_flavor (name): About     Print "============== Set key flavor =============" $Key = {'Hw:cpu_cores':'4','hw:cpu_sockets':'1'} -Flavors_list =nova.flavors.list () -      forDatainchflavors_list: -         ifData.name = =Name: A             PrintData + Data.set_keys (Key) the     Print "=================== End =================" -     Print "" $  the defflavors_delete (name): the     Print "=============== Delete Flavor =============" theFlavors_list =nova.flavors.list () the      forDatainchflavors_list: -         ifData.name = =Name: in             PrintData the nova.flavors.delete (data) the     Print "=================== End =================" About  the flavors_list () theFlavors_create (name='Flavor_demo', ram=4096, vcpus='4', disk=0) theSet_key_flavor (name='Flavor_demo') + flavors_list () -Flavors_delete (name='Flavor_demo')

Operating effect:

[email protected] ~]# python flavor.py
================ List Flavor ==============

=============== Create Flavor =============
<Flavor:flavor_demo>
=================== End =================

============== Set Key Flavor =============
<Flavor:flavor_demo>
=================== End =================

[Email protected] ~]# vim flavor.py
[email protected] ~]# python flavor.py
================ List Flavor ==============

=============== Create Flavor =============
<Flavor:flavor_demo>
=================== End =================

============== Set Key Flavor =============
<Flavor:flavor_demo>
=================== End =================

================ List Flavor ==============
Id:c2c99abd-82d2-4ef5-9656-10bfaca5b8e8
Name:flavor_demo
Cpu:4
mem:4096
disk:0
===========================================

=============== Delete Flavor =============
<Flavor:flavor_demo>
=================== End =================

Nova queries, creates, deletes flavor through the Python API

Related Article

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.