Implement network association in OS API

Networks are associated with projects automatically during launch
of an instance. The network is chosen rather randomly.
This commit adds support for association of given network and project.

DocImpact - when this lands, need to update openstack-manuals repo:
doc/src/docbkx/openstack-api-site/src/wadls/compute-api/src/ext/os-networks.wadl

Implements: blueprint os-api-network-associate
Change-Id: Iafaf4a5ae3d3e16a6c649f1d7850fceba732efab
Update extra specs calls to use deleted: False.

Updates the instance type extra specs and volume type extra specs
create/update functions so that 'deleted' is treated as a boolean.

This resolves issues when trying to create/update extra specs
on Postgres.

Fixes LP Bug #1036287.

Change-Id: I7f38b40122240af3254d8a817f5144ce9fafd6db
volumes: fix check_for_export() in non-exporting volume drivers

This overrides the default check_for_export so that drivers that don't
need to export block devices on the host like Sheepdog and RBD don't
raise a NotImplemented exception when this is called.

Change-Id: I9e46f84a2a491f8e1f281b3eea86106147b27976
Reported-by: Mark Moseley <moseleymark@gmail.com>
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
Change time.sleep to greenthread.sleep

time is not imported. use greenthread to make it consistent with
the rest of the module

Change-Id: Iea6b2b0f49faa5e48198b61ff1b0ef52da58f48b
Simple checks for instance user data.

Check that instance user data wont be truncated, and that it is
valid base64 data. This partially resolves bug 1035055. I don't
love the hard coded maximum length, but I haven't worked out how
to get sqlalchemy to tell me the maximum size of the data type.

Change-Id: I045d6b4481563d01cae371cf61a91781cfed6f4b
Merge "Change time.sleep to greenthread.sleep"
Enforce quota limitations for instance resize.

Fixes LP 1030010.

Close off a back-door allowing users to go over-quota on ram
and/or cores by creating a tiny instance and then resizing
to any size regardless of the remaining usage headroom.

The quota management logic is distributed in the sense that
the reservations are passed with the RPC casts that may fail
silently, so that the rollback or commit is handled by the
actor finalizing the resize/confirmation/reversion.

Up-sizing requires there is sufficient quota headroom upfront
to accommodate the larger size, whereas conversely down-sizing
only results in a usage reduction when the resize is confirmed.

Change-Id: I2b1cbb098c79e37d7ad19221fe23657eb018eae6
Allow stop API to be called in Error

We already allow the stop API to be called when the VM is in Error
state. This is to update the diagram in devref doc.

Change-Id: I792028dc6f851f66d42b852c27505c479eab4df7
Validate that min_count & max_count parameters are numeric.

Changed nova/api/openstack/compute/servers.py to include
validation of min_count and max_count. min_count and max_count
must be numeric values >=1 and min_count must be <= max_count.
Also, added tests to test_servers.py to verify these restrictions.

Fixes: bug #1035482
Change-Id: I530c11b683a905ee67f679ef485c9f7669f1e074
Fix uuid related bug in console/api

A number of variables are undefined while refactoring uuid in
I4032419d66e9bbb17b770d8974a92a136bf9c5d2.
self._translate_uuid_if_necessary is also no longer available.
Those problems are fixed in this patch.

Change-Id: Ifb88b4faa11b2ba8178a9a705ba6da1e4d9b4182
Merge "Allow stop API to be called in Error"
Revert task_state on failed instance actions

Right now, the task_state logic in compute/api.py can be broken, such
that instances can get stuck in an uneditable state if an action is
performed that fails. The task_state remains something like 'stopping'
even though the action has not been completed or queued, and further
requests that depend on task_state will fail (see check_instance_state()
in compute/apy.py).

The only way out of it is to delete the instance or hack the database.

This patch adds a reverts_task_state() decorator to compute/manager.py,
which, upon operation failure, reverts the instance's task_state back
to None.

It also adds a test_state_revert() test to verify that all the actions
marked for state reversion do the right thing. It also corrects several
other tests that specifically expect the task_state to remain after
an error has occurred.

Fixes bug 1025722

Change-Id: Id4358c508156c713cb953dfa0f01a6f598bc1e7d
Merge "volumes: fix check_for_export() in non-exporting volume drivers"
Merge "Revert task_state on failed instance actions"
Merge "Update extra specs calls to use deleted: False."
Merge "Fix uuid related bug in console/api"
Return values from wrapped functions in decorators

Calling compute manager methods requires that the decorators
return the value from the underlying function.

This doesn't actually change any return values from methods, because
all existing methods effectively return None.

Fixes bug 1036793

Change-Id: I64eea506ee1395678a7de3c6963a3da8e40d6962
continue config-drive-v2, add openstack metadata api

This continues the work Michael did on blueprint config-drive-v2

Things added:
 * web service /openstack/2012-08-10 with:
   user_data
   meta_data.json
 * web service supporting /openstack/content

Things changed:
 * Changed the name 'files' (/openstack/files) to be 'content'
   This is to be more generic and apply to future re-use of it
   for some purpose other than personalities (injected_files)
 * 'meta_data.json' and 'user_data' are used for openstack
 * 'user-data' (without .raw) in the ec2 config drive rendering
 * 'content_path' is a attribute of each of the entries in the 'files'
   its value is the path from the openstack metadata service root to
   where the content is located.

   This means that the user does not have to know anything explicit about
   '/content'.  They just have to take the 'content_path' and append it
   to the top level entry point of metadata service.

   Explicit example:
   http://169.254.169.254/openstack/2012-08-10/meta_data.json
   has:
     files[{path: "/etc/passwd", content_path: "/content/0001"}]
   To get the file, user appends 'content_path' to
     http://169.254.169.254/openstack
 * network config (Template) is available in /content also, and
   the key that points to it is 'network_config'. This occurs only
   if there are network's that are "injected" (same behavior as previously)

The meta_data.json now contains
  uuid: <instance uuid>
  meta: meta tags provided they will appear in a dict here
  files:
     This is a list of dicts, where each dict has 2 fields:
       * 'path' (the path provided)
       * 'content_id': the location in /content/ that will give the content
  public-keys:
     Dict of keyname : value
  network_config:
     This is a dict, containing 'content_path' and 'name' (network_config)
  hostname: the hostname
  name: the nova boot name

TODO:
 * want to add other items into openstack metadata
   * public-hostname
   * IP addresses
   * keystone-endpoint
   * url of metadata service: ideally only show this if there
     is a web service available.  the path seems hard coded at the moment
     to be http://169.254.169.254/openstack, but I do not know if there
     is a way to determine if one is present or not.
 * document config-drive-v2

Change-Id: I6b9097624a9c1a972e4851d79f6d557376f59d32
Merge "continue config-drive-v2, add openstack metadata api"
Set task_state=None when finished snapshotting.

Reverts part of recent reverts_task_state commit
d8d7100f8c10ecd388d1943bee9298a913a6990a which removed
code that resets the task_state to None once a snapshot has
been completed.

Fixes LP Bug #1036835.

Change-Id: I7d30d16ca110f022b0d1f6b2fb05ba3aa52fa4d1