Skip to content

Instantly share code, notes, and snippets.

@slashk
Created May 16, 2012 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slashk/2714727 to your computer and use it in GitHub Desktop.
Save slashk/2714727 to your computer and use it in GitHub Desktop.
openstack nova resize instance
Using the v1.1/{tenant_id}/servers/{server_id}/action API call, you can change the flavor/instance type of the running instance. 
Here's an example of resizing an instance via the nova command line tool (with debug on to see the API calls).
First, create the instance:
$ nova boot --image bc6e9a0c-7ede-4c54-9f22-401dd87ec367 --flavor 1 ken
+------------------------+--------------------------------------+
| Property | Value |
+------------------------+--------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-STS:power_state | 0 |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| accessIPv4 | |
| accessIPv6 | |
| adminPass | Viv3Nhovp9Uq |
| config_drive | |
| created | 2012-05-16T22:49:01Z |
| flavor | m1.tiny |
| hostId | |
| id | 75198f07-e377-4b6d-9dbf-ab5021df1e0f |
| image | cirros-0.3.0-x86_64-uec |
| key_name | |
| metadata | {} |
| name | ken |
| progress | 0 |
| status | BUILD |
| tenant_id | 9b2c8212caaf46c68d0543b3a36f3bea |
| updated | 2012-05-16T22:49:01Z |
| user_id | 01ecf33c921941749b039f4e1a416a68 |
+------------------------+--------------------------------------+
Then, check to make sure it's running ...
$ nova show 75198f07-e377-4b6d-9dbf-ab5021df1e0f
+------------------------+----------------------------------------------------------+
| Property | Value |
+------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-STS:power_state | 1 |
| OS-EXT-STS:task_state | None |
| OS-EXT-STS:vm_state | active |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2012-05-16T22:49:01Z |
| flavor | m1.tiny |
| hostId | 4561a98e0a99bb43a84b7ea5ebedb27d7d015ff9970f4963cad31592 |
| id | 75198f07-e377-4b6d-9dbf-ab5021df1e0f |
| image | cirros-0.3.0-x86_64-uec |
| key_name | |
| metadata | {} |
| name | ken |
| private network | 10.0.0.2 |
| progress | 0 |
| status | ACTIVE |
| tenant_id | 9b2c8212caaf46c68d0543b3a36f3bea |
| updated | 2012-05-16T22:49:19Z |
| user_id | 01ecf33c921941749b039f4e1a416a68 |
+------------------------+----------------------------------------------------------+
Now, resize it to something larger (flavor 2) -- this is where it gets good
(i've turned on debug to see the actual API calls):
$ nova --debug resize 75198f07-e377-4b6d-9dbf-ab5021df1e0f 2
connect: (192.168.1.111, 5000)
send: 'POST /v2.0/tokens HTTP/1.1\r\nHost: 192.168.1.111:5000\r\nContent-Length: 98\r\ncontent-type: application/json\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: python-novaclient\r\n\r\n{"auth": {"tenantName": "demo", "passwordCredentials": {"username": "demo", "password": "stack"}}}'
reply: 'HTTP/1.1 200 OK\r\n'
header: Content-Type: application/json
header: Vary: X-Auth-Token
header: Content-Length: 2482
header: Date: Wed, 16 May 2012 22:52:16 GMT
connect: (192.168.1.111, 8774)
send: u'GET /v2/9b2c8212caaf46c68d0543b3a36f3bea/servers/75198f07-e377-4b6d-9dbf-ab5021df1e0f HTTP/1.1\r\nHost: 192.168.1.111:8774\r\nx-auth-project-id: demo\r\nx-auth-token: 42392ceaa07b4e0584de280e5466e1c3\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: python-novaclient\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: X-Compute-Request-Id: req-047f1047-5bf4-449b-945d-dc4c01b20d57
header: Content-Type: application/json
header: Content-Length: 1240
header: Date: Wed, 16 May 2012 22:52:16 GMT
send: u'GET /v2/9b2c8212caaf46c68d0543b3a36f3bea/flavors/2 HTTP/1.1\r\nHost: 192.168.1.111:8774\r\nx-auth-project-id: demo\r\nx-auth-token: 42392ceaa07b4e0584de280e5466e1c3\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: python-novaclient\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: X-Compute-Request-Id: req-2d7446f0-6de0-44c2-9af6-1cdd6c17a181
header: Content-Type: application/json
header: Content-Length: 357
header: Date: Wed, 16 May 2012 22:52:16 GMT
send: u'POST /v2/9b2c8212caaf46c68d0543b3a36f3bea/servers/75198f07-e377-4b6d-9dbf-ab5021df1e0f/action HTTP/1.1\r\nHost: 192.168.1.111:8774\r\nContent-Length: 30\r\nx-auth-project-id: demo\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nx-auth-token: 42392ceaa07b4e0584de280e5466e1c3\r\nuser-agent: python-novaclient\r\ncontent-type: application/json\r\n\r\n{"resize": {"flavorRef": "2"}}'
reply: 'HTTP/1.1 202 Accepted\r\n'
header: Content-Type: text/html; charset=UTF-8
header: Content-Length: 0
header: Date: Wed, 16 May 2012 22:52:16 GMT
Now, wait for it to hit the VERIFY_RESIZE status and then confirm the resize
with the "nova resize-confirm" command:
$ nova list
+--------------------------------------+------+---------------+------------------+
|                  ID                  | Name |     Status    |     Networks     |
+--------------------------------------+------+---------------+------------------+
| 75198f07-e377-4b6d-9dbf-ab5021df1e0f | ken  | VERIFY_RESIZE | private=10.0.0.2 |
+--------------------------------------+------+---------------+------------------+
$ nova resize-confirm 75198f07-e377-4b6d-9dbf-ab5021df1e0f
$ nova show 75198f07-e377-4b6d-9dbf-ab5021df1e0f
+------------------------+----------------------------------------------------------+
|        Property        |                          Value                           |
+------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig      | MANUAL                                                   |
| OS-EXT-STS:power_state | 1                                                        |
| OS-EXT-STS:task_state  | None                                                     |
| OS-EXT-STS:vm_state    | active                                                   |
| accessIPv4             |                                                          |
| accessIPv6             |                                                          |
| config_drive           |                                                          |
| created                | 2012-05-16T22:49:01Z                                     |
| flavor                 | m1.small                                                 |
| hostId                 | 4561a98e0a99bb43a84b7ea5ebedb27d7d015ff9970f4963cad31592 |
| id                     | 75198f07-e377-4b6d-9dbf-ab5021df1e0f                     |
| image                  | cirros-0.3.0-x86_64-uec                                  |
| key_name               |                                                          |
| metadata               | {}                                                       |
| name                   | ken                                                      |
| private network        | 10.0.0.2                                                 |
| progress               | 0                                                        |
| status                 | ACTIVE                                                   |
| tenant_id              | 9b2c8212caaf46c68d0543b3a36f3bea                         |
| updated                | 2012-05-16T22:54:25Z                                     |
| user_id                | 01ecf33c921941749b039f4e1a416a68                         |
+------------------------+----------------------------------------------------------+
Done.
@robinmv
Copy link

robinmv commented Jan 18, 2016

We have the similar setup (vmware integrated openstack). when i run resize-confirm, i am getting this error.
ERROR (Conflict): Cannot 'confirmResize' instance 10b5bbba-6bf3-457e-b6ae-acd69e5cb9cf while it is in vm_state active (HTTP 409) (Request-ID: req-58d2651f-350b-48c7-b9b9-e7c9a7102ded)
Can you please suggest, what i missed in my setup.

Thanks in Advance,
Robin

@estuardolh
Copy link

Just start the instance.
Is never late to answer haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment