pythonopenstackopenstacksdk

Create a flavour with openstack SDK


I have a heat template yaml file for creating a flavor named "flavor_one" on compute node placed at specific path /opt/config/template.yml

How can I create a flavor with the template file with openstack SDK in python. I tried with the below. But failed:

 image = conn.create_flavor(
                    filename='/opt/config/template.yml' + flavor_one,
                    wait=True)

Any help ? I am a novice at openstack SDK. I have successfully established a connection with clouds.yaml file


Solution

  • You can use the create_flavor method...

    import json, openstack
    
    try:    
      os_connect = openstack.connect(
           auth_url="https://controller:5000/v3/",
           project_name="admin", username="admin",
           password="secretPassword",
           region_name="RegionOne",
           user_domain_name="Default",
           project_domain_name="default",
           app_version='1.0')
    
      # Change name, ram, vcpus, disk to your favourite values
      os_connect.create_flavor(name, ram, vcpus, disk, flavorid='auto', ephemeral=0, swap=0, rxtx_factor=1.0, is_public=True)