Use openstacksdk for setting the tags.
Implements: blueprint switch-to-openstacksdk Change-Id: I1f91227c855b64872476d807838e55254ca219d5
This commit is contained in:
parent
09b07992b0
commit
be132b1aeb
|
@ -180,7 +180,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||
if not sg_id:
|
||||
sg = os_net.create_security_group(
|
||||
name=loadbalancer.name, project_id=loadbalancer.project_id)
|
||||
c_utils.tag_neutron_resources('security-groups', [sg.id])
|
||||
c_utils.tag_neutron_resources([sg])
|
||||
loadbalancer.security_groups.append(sg.id)
|
||||
vip_port = self._get_vip_port(loadbalancer)
|
||||
os_net.update_port(vip_port.id, security_groups=[sg.id])
|
||||
|
@ -393,7 +393,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||
if not sg_id:
|
||||
sg = os_net.create_security_group(
|
||||
name=loadbalancer.name, project_id=loadbalancer.project_id)
|
||||
c_utils.tag_neutron_resources('security-groups', [sg.id])
|
||||
c_utils.tag_neutron_resources([sg])
|
||||
loadbalancer.security_groups.append(sg.id)
|
||||
vip_port = self._get_vip_port(loadbalancer)
|
||||
os_net.update_port(
|
||||
|
|
|
@ -102,7 +102,7 @@ class NamespacePodSecurityGroupsDriver(base.PodSecurityGroupsDriver):
|
|||
# The rest can be accessed from the default one
|
||||
sg = os_net.create_security_group(name=sg_name,
|
||||
project_id=project_id)
|
||||
utils.tag_neutron_resources('security-groups', [sg.id])
|
||||
utils.tag_neutron_resources([sg])
|
||||
os_net.create_security_group_rule(
|
||||
direction="ingress",
|
||||
remote_ip_prefix=crd_spec['subnetCIDR'],
|
||||
|
|
|
@ -159,7 +159,7 @@ class NamespacePodSubnetDriver(default_subnet.DefaultPodSubnetDriver):
|
|||
try:
|
||||
neutron_net = os_net.create_network(name=network_name,
|
||||
project_id=project_id)
|
||||
c_utils.tag_neutron_resources('networks', [neutron_net.id])
|
||||
c_utils.tag_neutron_resources([neutron_net])
|
||||
|
||||
# create a subnet within that network
|
||||
try:
|
||||
|
@ -175,7 +175,7 @@ class NamespacePodSubnetDriver(default_subnet.DefaultPodSubnetDriver):
|
|||
"raising ResourceNotReady to retry subnet creation "
|
||||
"for %s", subnet_name)
|
||||
raise exceptions.ResourceNotReady(subnet_name)
|
||||
c_utils.tag_neutron_resources('subnets', [neutron_subnet['id']])
|
||||
c_utils.tag_neutron_resources([neutron_subnet])
|
||||
|
||||
# connect the subnet to the router
|
||||
clients.handle_neutron_errors(os_net.add_interface_to_router,
|
||||
|
|
|
@ -44,7 +44,7 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
|
||||
rq = self._get_port_request(pod, project_id, subnets, security_groups)
|
||||
port = os_net.create_port(**rq)
|
||||
utils.tag_neutron_resources('ports', [port.id])
|
||||
utils.tag_neutron_resources([port])
|
||||
vlan_id = self._add_subport(trunk_id, port.id)
|
||||
|
||||
return ovu.neutron_to_osvif_vif_nested_vlan(port, subnets, vlan_id)
|
||||
|
@ -85,7 +85,7 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
except os_exc.SDKException:
|
||||
LOG.exception("Error creating bulk ports: %s", bulk_port_rq)
|
||||
raise
|
||||
utils.tag_neutron_resources('ports', [port.id for port in ports])
|
||||
utils.tag_neutron_resources(ports)
|
||||
|
||||
for index, port in enumerate(ports):
|
||||
subports_info[index]['port_id'] = port['id']
|
||||
|
|
|
@ -164,7 +164,7 @@ class NetworkPolicyDriver(base.NetworkPolicyDriver):
|
|||
sg = self.os_net.create_security_group(name=sg_name,
|
||||
project_id=project_id,
|
||||
description=desc)
|
||||
driver_utils.tag_neutron_resources('security-groups', [sg.id])
|
||||
driver_utils.tag_neutron_resources([sg])
|
||||
# NOTE(dulek): Neutron populates every new SG with two rules
|
||||
# allowing egress on IPv4 and IPv6. This collides with
|
||||
# how network policies are supposed to work, because
|
||||
|
|
|
@ -37,7 +37,7 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
|
|||
|
||||
rq = self._get_port_request(pod, project_id, subnets, security_groups)
|
||||
port = os_net.create_port(**rq)
|
||||
utils.tag_neutron_resources('ports', [port.id])
|
||||
utils.tag_neutron_resources([port])
|
||||
|
||||
return ovu.neutron_to_osvif_vif(port.binding_vif_type, port, subnets)
|
||||
|
||||
|
@ -54,7 +54,7 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
|
|||
except os_exc.SDKException:
|
||||
LOG.exception("Error creating bulk ports: %s", bulk_port_rq)
|
||||
raise
|
||||
utils.tag_neutron_resources('ports', [port.id for port in ports])
|
||||
utils.tag_neutron_resources(ports)
|
||||
|
||||
vif_plugin = ports[0].binding_vif_type
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class FipPubIpDriver(BasePubIpDriver):
|
|||
LOG.exception("Failed to create floating IP - netid=%s ",
|
||||
pub_net_id)
|
||||
raise
|
||||
utils.tag_neutron_resources('networks', [fip.id])
|
||||
utils.tag_neutron_resources([fip])
|
||||
return fip.id, fip.floating_ip_address
|
||||
|
||||
def free_ip(self, res_id):
|
||||
|
|
|
@ -56,7 +56,7 @@ class SriovVIFDriver(neutron_vif.NeutronPodVIFDriver):
|
|||
subnets, security_groups)
|
||||
|
||||
port = os_net.create_port(**rq)
|
||||
c_utils.tag_neutron_resources('ports', [port['id']])
|
||||
c_utils.tag_neutron_resources([port])
|
||||
vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnets)
|
||||
vif.physnet = physnet
|
||||
vif.pod_name = pod_name
|
||||
|
|
|
@ -409,17 +409,22 @@ def get_namespace_subnet_cidr(namespace):
|
|||
return net_crd['spec']['subnetCIDR']
|
||||
|
||||
|
||||
def tag_neutron_resources(resource, res_ids):
|
||||
def tag_neutron_resources(resources):
|
||||
"""Set tags to the provided resources.
|
||||
|
||||
param resources: list of openstacksdk objects to tag.
|
||||
"""
|
||||
tags = CONF.neutron_defaults.resource_tags
|
||||
if tags:
|
||||
neutron = clients.get_neutron_client()
|
||||
for res_id in res_ids:
|
||||
try:
|
||||
neutron.replace_tag(resource, res_id, body={"tags": tags})
|
||||
except n_exc.NeutronClientException:
|
||||
LOG.warning("Failed to tag %s %s with %s. Ignoring, but this "
|
||||
"is still unexpected.", resource, res_id, tags,
|
||||
exc_info=True)
|
||||
if not tags:
|
||||
return
|
||||
|
||||
os_net = clients.get_network_client()
|
||||
for res in resources:
|
||||
try:
|
||||
os_net.set_tags(res, tags=tags)
|
||||
except n_exc.NeutronClientException:
|
||||
LOG.warning("Failed to tag %s with %s. Ignoring, but this is "
|
||||
"still unexpected.", res, tags, exc_info=True)
|
||||
|
||||
|
||||
def get_services(namespace=None):
|
||||
|
|
Loading…
Reference in New Issue