From 864ec75a57d85655dac13e426da9897f580edfea Mon Sep 17 00:00:00 2001 From: caishan Date: Tue, 19 Jun 2018 18:36:13 -0700 Subject: [PATCH] Add create_network method in etcd db. Add create_network method in etcd db. Now support two db types, both etcd and sql for storing network. Relatated bug: https://bugs.launchpad.net/zun/+bug/1777770 Change-Id: I6542a7889d0e355a5ddc394aa209db5e8dcc7ead --- zun/db/etcd/api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/zun/db/etcd/api.py b/zun/db/etcd/api.py index 2a60a87da..294ff6f0b 100644 --- a/zun/db/etcd/api.py +++ b/zun/db/etcd/api.py @@ -1336,3 +1336,17 @@ class EtcdAPI(object): except Exception as e: LOG.error('Error occurred while retrieving quota usage: %s', six.text_type(e)) + + @lockutils.synchronized('etcd_network') + def create_network(self, context, network_value): + if not network_value.get('uuid'): + network_value['uuid'] = uuidutils.generate_uuid() + if network_value.get('name'): + self._validate_unique_container_name(context, + network_value['name']) + network = models.Network(network_value) + try: + network.save() + except Exception: + raise + return network