summaryrefslogtreecommitdiff
path: root/ironic/db/sqlalchemy/api.py
diff options
context:
space:
mode:
authorKaifeng Wang <kaifeng.w@gmail.com>2020-11-28 01:07:18 +0800
committerKaifeng Wang <kaifeng.w@gmail.com>2020-11-29 13:37:55 +0800
commitb7ddeb314d98961b5d169f5356a451eec78c8cc7 (patch)
tree9c61c95a37ae1379dcf666da137a34a33075eb21 /ironic/db/sqlalchemy/api.py
parenta08da8551a66815bedef7c6444fde5f9082a6aea (diff)
downloadironic-b7ddeb314d98961b5d169f5356a451eec78c8cc7.tar.gz
Support port name
MAC address is not user friendly for port management, having a name field is also a feature parity with other resources. This patch implements db related change. Change-Id: Ibad9a1b6bbfddc0af1950def4e27db3757904cb1 Story: 2003091 Task: 23180
Diffstat (limited to 'ironic/db/sqlalchemy/api.py')
-rw-r--r--ironic/db/sqlalchemy/api.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index 7c478b009..7891122ce 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -705,6 +705,13 @@ class Connection(api.Connection):
except NoResultFound:
raise exception.PortNotFound(port=address)
+ def get_port_by_name(self, port_name):
+ query = model_query(models.Port).filter_by(name=port_name)
+ try:
+ return query.one()
+ except NoResultFound:
+ raise exception.PortNotFound(port=port_name)
+
def get_port_list(self, limit=None, marker=None,
sort_key=None, sort_dir=None, owner=None,
project=None):
@@ -773,8 +780,11 @@ class Connection(api.Connection):
session.flush()
except NoResultFound:
raise exception.PortNotFound(port=port_id)
- except db_exc.DBDuplicateEntry:
- raise exception.MACAlreadyExists(mac=values['address'])
+ except db_exc.DBDuplicateEntry as exc:
+ if 'name' in exc.columns:
+ raise exception.PortDuplicateName(name=values['name'])
+ else:
+ raise exception.MACAlreadyExists(mac=values['address'])
return ref
@oslo_db_api.retry_on_deadlock