salt.modules.nova

Module for handling OpenStack Nova calls

depends:
  • novaclient Python module
configuration:

This module is not usable until the user, password, tenant, and auth URL are specified either in a pillar or in the minion's config file. For example:

keystone.user: admin
keystone.password: verybadpass
keystone.tenant: admin
keystone.auth_url: 'http://127.0.0.1:5000/v2.0/'
# Optional
keystone.region_name: 'regionOne'

If configuration for multiple OpenStack accounts is required, they can be set up as different configuration profiles: For example:

openstack1:
  keystone.user: admin
  keystone.password: verybadpass
  keystone.tenant: admin
  keystone.auth_url: 'http://127.0.0.1:5000/v2.0/'

openstack2:
  keystone.user: admin
  keystone.password: verybadpass
  keystone.tenant: admin
  keystone.auth_url: 'http://127.0.0.2:5000/v2.0/'

With this configuration in place, any of the nova functions can make use of a configuration profile by declaring it explicitly. For example:

salt '*' nova.flavor_list profile=openstack1
salt.modules.nova.boot(name, flavor_id=0, image_id=0, profile=None, timeout=300)

Boot (create) a new instance

name
Name of the new instance (must be first)
flavor_id
Unique integer ID for the flavor
image_id
Unique integer ID for the image
timeout

How long to wait, after creating the instance, for the provider to return information about it (default 300 seconds).

2014.1.0 新版功能.

CLI 范例:

salt '*' nova.boot myinstance flavor_id=4596 image_id=2

The flavor_id and image_id are obtained from nova.flavor_list and nova.image_list

salt '*' nova.flavor_list
salt '*' nova.image_list
salt.modules.nova.delete(instance_id, profile=None)

Delete an instance

instance_id
ID of the instance to be deleted

CLI 范例:

salt '*' nova.delete 1138
salt.modules.nova.flavor_create(name, flavor_id=0, ram=0, disk=0, vcpus=1, profile=None)

Add a flavor to nova (nova flavor-create). The following parameters are required:

name
Name of the new flavor (must be first)
flavor_id
Unique integer ID for the new flavor
ram
Memory size in MB
disk
Disk size in GB
vcpus
Number of vcpus

CLI 范例:

salt '*' nova.flavor_create myflavor flavor_id=6                 ram=4096 disk=10 vcpus=1
salt.modules.nova.flavor_delete(flavor_id, profile=None)

Delete a flavor from nova by id (nova flavor-delete)

CLI 范例:

salt '*' nova.flavor_delete 7
salt.modules.nova.flavor_list(profile=None)

Return a list of available flavors (nova flavor-list)

CLI 范例:

salt '*' nova.flavor_list
salt.modules.nova.image_list(name=None, profile=None)

Return a list of available images (nova images-list + nova image-show) If a name is provided, only that image will be displayed.

CLI范例:

salt '*' nova.image_list
salt '*' nova.image_list myimage
salt.modules.nova.image_meta_delete(image_id=None, name=None, keys=None, profile=None)

Delete a key=value pair from the metadata for an image (nova image-meta set)

CLI范例:

salt '*' nova.image_meta_delete                 6f52b2ff-0b31-4d84-8fd1-af45b84824f6 keys=cheese
salt '*' nova.image_meta_delete name=myimage keys=salad,beans
salt.modules.nova.image_meta_set(image_id=None, name=None, profile=None, **kwargs)

Sets a key=value pair in the metadata for an image (nova image-meta set)

CLI范例:

salt '*' nova.image_meta_set 6f52b2ff-0b31-4d84-8fd1-af45b84824f6                 cheese=gruyere
salt '*' nova.image_meta_set name=myimage salad=pasta beans=baked
salt.modules.nova.keypair_add(name, pubfile=None, pubkey=None, profile=None)

Add a keypair to nova (nova keypair-add)

CLI范例:

salt '*' nova.keypair_add mykey pubfile='/home/myuser/.ssh/id_rsa.pub'
salt '*' nova.keypair_add mykey pubkey='ssh-rsa <key> myuser@mybox'
salt.modules.nova.keypair_delete(name, profile=None)

Add a keypair to nova (nova keypair-delete)

CLI 范例:

salt '*' nova.keypair_delete mykey'
salt.modules.nova.keypair_list(profile=None)

Return a list of available keypairs (nova keypair-list)

CLI 范例:

salt '*' nova.keypair_list
salt.modules.nova.list(profile=None)

To maintain the feel of the nova command line, this function simply calls the server_list function.

salt.modules.nova.lock(instance_id, profile=None)

Lock an instance

instance_id
ID of the instance to be locked

CLI 范例:

salt '*' nova.lock 1138
salt.modules.nova.resume(instance_id, profile=None)

Resume an instance

instance_id
ID of the instance to be resumed

CLI 范例:

salt '*' nova.resume 1138
salt.modules.nova.secgroup_create(name, description, profile=None)

Add a secgroup to nova (nova secgroup-create)

CLI 范例:

salt '*' nova.secgroup_create mygroup 'This is my security group'
salt.modules.nova.secgroup_delete(name, profile=None)

Delete a secgroup to nova (nova secgroup-delete)

CLI 范例:

salt '*' nova.secgroup_delete mygroup
salt.modules.nova.secgroup_list(profile=None)

Return a list of available security groups (nova items-list)

CLI 范例:

salt '*' nova.secgroup_list
salt.modules.nova.server_by_name(name, profile=None)

Return information about a server

name
Server Name

CLI 范例:

salt '*' nova.server_by_name myserver profile=openstack
salt.modules.nova.server_list(profile=None)

Return list of active servers

CLI 范例:

salt '*' nova.server_list
salt.modules.nova.server_list_detailed(profile=None)

Return detailed list of active servers

CLI 范例:

salt '*' nova.server_list_detailed
salt.modules.nova.server_show(server_id, profile=None)

Return detailed information for an active server

CLI 范例:

salt '*' nova.server_show <server_id>
salt.modules.nova.show(server_id, profile=None)

To maintain the feel of the nova command line, this function simply calls the server_show function.

CLI 范例:

salt '*' nova.show
salt.modules.nova.suspend(instance_id, profile=None)

Suspend an instance

instance_id
ID of the instance to be suspended

CLI 范例:

salt '*' nova.suspend 1138
salt.modules.nova.volume_attach(name, server_name, device='/dev/xvdb', profile=None, timeout=300)

Attach a block storage volume

name
Name of the new volume to attach
server_name
Name of the server to attach to
device
Name of the device on the server
profile
Profile to build on

CLI 范例:

salt '*' nova.volume_attach myblock slice.example.com profile=openstack
salt '*' nova.volume_attach myblock server.example.com                 device='/dev/xvdb' profile=openstack
salt.modules.nova.volume_create(name, size=100, snapshot=None, voltype=None, profile=None)

Create a block storage volume

name
Name of the new volume (must be first)
size
Volume size
snapshot
Block storage snapshot id
voltype
Type of storage
profile
Profile to build on

CLI 范例:

salt '*' nova.volume_create myblock size=300 profile=openstack
salt.modules.nova.volume_delete(name, profile=None)

Destroy the volume

name
Name of the volume
profile
Profile to build on

CLI 范例:

salt '*' nova.volume_delete myblock profile=openstack
salt.modules.nova.volume_detach(name, profile=None, timeout=300)

Attach a block storage volume

name
Name of the new volume to attach
server_name
Name of the server to detach from
profile
Profile to build on

CLI 范例:

salt '*' nova.volume_detach myblock profile=openstack
salt.modules.nova.volume_list(search_opts=None, profile=None)

List storage volumes

search_opts
Dictionary of search options
profile
Profile to use

CLI 范例:

salt '*' nova.volume_list                 search_opts='{"display_name": "myblock"}'                 profile=openstack
salt.modules.nova.volume_show(name, profile=None)

Create a block storage volume

name
Name of the volume
profile
Profile to use

CLI 范例:

salt '*' nova.volume_show myblock profile=openstack