Merge "Check usable portgroups and ports"
This commit is contained in:
commit
a092b14092
@ -60,12 +60,10 @@ class BaseEngineDriver(object):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_ports_from_node(self, node_uuid, detail=True):
|
||||
"""Get a node's ports info.
|
||||
def get_portgroups_and_ports(self, node_uuid):
|
||||
"""Get a node's portgroups and ports info.
|
||||
|
||||
:param node_uuid: node id to get ports info.
|
||||
:param detail: whether to get detailed info of all the ports,
|
||||
default to False.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
|
||||
from ironicclient import exc as ironic_exc
|
||||
from ironicclient import exceptions as client_e
|
||||
from oslo_log import log as logging
|
||||
@ -227,13 +229,24 @@ class IronicDriver(base_driver.BaseEngineDriver):
|
||||
|
||||
_log_ironic_polling(message, node, server)
|
||||
|
||||
def get_ports_from_node(self, node_uuid, detail=True):
|
||||
"""List the MAC addresses and the port types from a node."""
|
||||
ports = self.ironicclient.call("node.list_ports",
|
||||
node_uuid, detail=detail)
|
||||
portgroups = self.ironicclient.call("portgroup.list", node=node_uuid,
|
||||
detail=detail)
|
||||
return ports + portgroups
|
||||
def get_portgroups_and_ports(self, node_uuid):
|
||||
"""List ports and portgroups of a node."""
|
||||
free_ports = []
|
||||
ports_by_portgroup = collections.defaultdict(list)
|
||||
ports = self.ironicclient.call("node.list_ports", node_uuid,
|
||||
detail=True)
|
||||
for p in ports:
|
||||
if p.portgroup_uuid is None:
|
||||
free_ports.append(p)
|
||||
else:
|
||||
ports_by_portgroup[p.portgroup_uuid].append(p)
|
||||
|
||||
portgroups = self.ironicclient.call("portgroup.list", node=node_uuid)
|
||||
for pg in portgroups:
|
||||
if ports_by_portgroup[pg.uuid]:
|
||||
free_ports.append(pg)
|
||||
|
||||
return free_ports
|
||||
|
||||
def plug_vif(self, node_uuid, port_id):
|
||||
self.ironicclient.call("node.vif_attach", node_uuid, port_id)
|
||||
|
@ -134,10 +134,7 @@ class BuildNetworkTask(flow_utils.MoganTask):
|
||||
self.manager = manager
|
||||
|
||||
def _build_networks(self, context, server, requested_networks):
|
||||
|
||||
# TODO(zhenguo): This seems not needed as our scheduler has already
|
||||
# guaranteed this.
|
||||
ports = self.manager.driver.get_ports_from_node(server.node_uuid)
|
||||
ports = self.manager.driver.get_portgroups_and_ports(server.node_uuid)
|
||||
if len(requested_networks) > len(ports):
|
||||
raise exception.InterfacePlugException(_(
|
||||
"Ironic node: %(id)s virtual to physical interface count"
|
||||
|
Loading…
Reference in New Issue
Block a user