Search code examples
sdkopenstackopenstacksdk

Openstack SDK to resize the instance


I have a requirement to read the input YAML file and resize the servers with the specified configuration like(VCPU, Disk,memory..). Note that the server name is already exist in the environment. I have automated this using python code using the cli command. Reference link for command https://docs.openstack.org/nova/latest/user/resize.html

But the requirement is to implement this via SDK. Please let me know how to implement this logic via python code by invoking openstack SDK?

Operating System: Ubuntu 16.04

Input Yaml: Servername1: test1 VCPU: 2 Disk: 4000 Memory: 200

Servername2: test2 VCPU: 1 Disk: 1000 Memory: 100


Solution

  • According to the SDK API documentation, the Compute class (doc) has methods called resize_server, confirm_resize_server and revert_resize_server.

    Please let me know how to implement this logic via python code by invoking openstack SDK?

    The sequence would be:

    1. Read your yaml file.
    2. Find the existing server that you want to resize.
    3. Lookup flavor1 with the specs that you need (VCPUs, disk, memory, etc).
    4. Check that the server doesn't have that flavor already.
    5. Resize the server
    6. Check server is working correctly. How you do that will depend on the context. But if you skip this step and "confirm" anyway there is a risk that you will lose the existing server.
    7. Either confirm resize or revert resize

    For more information how to obtain and make calls on the Compute object, please see "Using OpenStack Compute".


    1 - You could also synthesize flavors on the fly, but that is liable to give you a flavor management issue in the long term.