Set correct Nova NIC boot option

Update Nova NIC boot options to reflect the CLI Nova option names.
That patch keep precedent attribute name to preserve compatibility
with old template.

Signed-off-by: Édouard Thuleau <edouard.thuleau@cloudwatt.com>
Change-Id: I9b4a939a2ced4e9157df8685052cbe7594061ac8
This commit is contained in:
Édouard Thuleau 2014-08-06 19:11:06 +02:00
parent 57ff32c095
commit 2a8fddd51a
3 changed files with 36 additions and 2 deletions

View File

@ -5,3 +5,4 @@ requests>=1.1
PyYAML>=3.1.0
python-openstackclient==0.2.2
python-neutronclient>=2.3.4,<3
netaddr

View File

@ -54,6 +54,11 @@
# volumes:
# - name: vol01
# device: /dev/sdh
# networks:
# - name: net01
# v4-fixed-ip: 10.123.2.25
# - name: net01
# v6-fixed-ip: dead:beef::25/64
# securitygroups: [demo, ]
###############################################################################
@ -78,6 +83,10 @@
# host_routes:
# - destination: 10.0.0.0/24
# nexthop: 10.123.2.2
#- network: net01
# name: sub02
# cidr: dead:beef::/64
# ip_version: 6
###############################################################################
# Router

View File

@ -18,6 +18,8 @@
import uuid
from netaddr import AddrFormatError
from netaddr import IPAddress
from neutronclient.common import exceptions as neutron_exc
from neutronclient.neutron import v2_0 as neutronV20
from novaclient import exceptions as nova_exc
@ -221,10 +223,32 @@ class Server(Base):
networks = []
for obj in options.get("networks", []):
net = Network(self._agent).find(obj["name"])
ipv4_addr = None
ipv6_addr = None
if obj.get("fixed_ip"):
# Note(ethuleau): keep 'fixed_ip' attribute for compatibility
try:
ip_addr = IPAddress(obj.get("fixed_ip"))
except AddrFormatError:
raise Exception("Invalid IP address: %s",
obj.get("fixed_ip"))
if ip_addr.version == 4:
ipv4_addr = str(ip_addr)
else:
ipv6_addr = str(ip_addr)
if obj.get("v4-fixed-ip"):
ipv4_addr = obj.get("v4-fixed-ip")
if obj.get("v6-fixed-ip"):
ipv6_addr = obj.get("v6-fixed-ip")
# Note(ethuleau): keep 'port' attribute for compatibility
port_id = obj.get("port")
if obj.get("port-id"):
port_id = obj.get("port-id")
networks.append({
"net-id": net.id,
"v4-fixed-ip": obj.get("fixed_ip"),
"port-id": obj.get("port")})
"v4-fixed-ip": ipv4_addr,
"v6-fixed-ip": ipv6_addr,
"port-id": port_id})
userdata = None
if "userdata" in options: