summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorAlessio Ababilov <aababilov@griddynamics.com>2012-07-16 14:07:29 +0300
committerAlessio Ababilov <aababilov@griddynamics.com>2012-08-21 16:10:24 +0300
commite00a398f84562f1a0da69c8c0fd33db538365dc3 (patch)
tree0a2c00928d6c42397b6c8dbbf1b617c92498dc32 /nova/api
parent0272c063bbc32f1ff39f2baa8ae3f0764723ef73 (diff)
downloadnova-e00a398f84562f1a0da69c8c0fd33db538365dc3.tar.gz
nova-e00a398f84562f1a0da69c8c0fd33db538365dc3.tar.xz
nova-e00a398f84562f1a0da69c8c0fd33db538365dc3.zip
Implement network creation in compute API
Implements blueprint os-api-network-create The ability to create new networks is currently only exposed by the nova-manage CLI. Here we add support for network creation in the os-networks API extension. With the exception of num_networks and network_size, all the parameters supported by 'nova-manage network create' are supported. Only a single network may be created by each API call. To avoid code duplication, the nova-manage code is refactored and moved into NetworkManager so that it can be re-used by the API. DocImpact Change-Id: I682d498ab35ea43b553b64e13e677fe9eeb8e08b
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/networks.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/networks.py b/nova/api/openstack/compute/contrib/networks.py
index fb1d3d77e..f673bf43a 100644
--- a/nova/api/openstack/compute/contrib/networks.py
+++ b/nova/api/openstack/compute/contrib/networks.py
@@ -16,7 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-
+import netaddr
import webob
from webob import exc
@@ -111,8 +111,31 @@ class NetworkController(object):
raise exc.HTTPNotFound(_("Network not found"))
return exc.HTTPAccepted()
- def create(self, req, id, body=None):
- raise exc.HTTPNotImplemented()
+ def create(self, req, body):
+ context = req.environ['nova.context']
+ authorize(context)
+
+ def bad(e):
+ return exc.HTTPUnprocessableEntity(explanation=e)
+
+ if not (body and body.get("network")):
+ raise bad(_("Missing network in body"))
+
+ params = body["network"]
+ if not params.get("label"):
+ raise bad(_("Network label is required"))
+
+ cidr = params.get("cidr") or params.get("cidr_v6")
+ if not cidr:
+ raise bad(_("Network cidr or cidr_v6 is required"))
+
+ LOG.debug(_("Creating network with label %s") % params["label"])
+
+ params["num_networks"] = 1
+ params["network_size"] = netaddr.IPNetwork(cidr).size
+
+ network = self.network_api.create(context, **params)[0]
+ return {"network": network_dict(context, network)}
def add(self, req, body):
context = req.environ['nova.context']