From ea5a0f2471c1b1ed11c5cb367a80eef381ef1ebd Mon Sep 17 00:00:00 2001 From: 10190269 Date: Thu, 8 Dec 2016 17:03:19 +0800 Subject: [PATCH] The interface can't be assigned Dataplane when the interface is bond and that is linux bond Change-Id: I4288be4534c3141eb92e10a0e653628ce299a20b --- code/daisy/daisy/api/v1/hosts.py | 64 ++++++++++++++++--- .../versions/029_add_bond_type.py | 25 ++++++++ code/daisy/daisy/db/sqlalchemy/models.py | 1 + code/daisyclient/daisyclient/v1/shell.py | 5 +- .../environment/deploy/bonding_views.py | 1 + .../deploy/templates/deploy/bonding.html | 1 + 6 files changed, 87 insertions(+), 10 deletions(-) mode change 100644 => 100755 code/daisy/daisy/api/v1/hosts.py create mode 100755 code/daisy/daisy/db/sqlalchemy/migrate_repo/versions/029_add_bond_type.py diff --git a/code/daisy/daisy/api/v1/hosts.py b/code/daisy/daisy/api/v1/hosts.py old mode 100644 new mode 100755 index f00213c4..38c76a1d --- a/code/daisy/daisy/api/v1/hosts.py +++ b/code/daisy/daisy/api/v1/hosts.py @@ -263,7 +263,8 @@ class Controller(controller.BaseController): return all_networks - def _check_assigned_networks(self, req, cluster_id, assigned_networks): + def _check_asged_net(self, req, cluster_id, assigned_networks, + bond_type=None): LOG.info("assigned_networks %s " % assigned_networks) cluster_networks = self.get_cluster_networks_info(req, cluster_id) list_of_assigned_networks = [] @@ -301,6 +302,25 @@ class Controller(controller.BaseController): raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") + else: + if bond_type: + cluster_roles = daisy_cmn. \ + get_cluster_roles_detail(req, cluster_id) + cluster_backends = set([role['deployment_backend'] + for role in cluster_roles if + daisy_cmn.get_hosts_of_role( + req, role['id'])]) + for backend in cluster_backends: + try: + backend_common = importutils.import_module( + 'daisy.api.backends.%s.common' % backend) + except Exception: + pass + else: + if hasattr(backend_common, + 'check_dataplane_bond_type'): + backend_common.check_dataplane_bond_type( + req, bond_type) else: msg = "can't find network named '%s' in cluster '%s'" % ( assigned_network['name'], cluster_id) @@ -426,11 +446,28 @@ class Controller(controller.BaseController): interface['assigned_networks']): have_assigned_network = True if cluster_id: - assigned_networks_of_one_interface = self.\ - _check_assigned_networks(req, + if interface.get('type', None) == "bond": + bond_type = interface.get("bond_type", None) + if bond_type: + assigned_networks_of_one_interface = self. \ + _check_asged_net(req, cluster_id, interface[ - 'assigned_networks']) + 'assigned_networks'], + bond_type) + else: + msg = "bond type must be given when interface " \ + "type is bond" + LOG.error(msg) + raise HTTPBadRequest(explanation=msg, + request=req, + content_type="text/plain") + else: + assigned_networks_of_one_interface = self. \ + _check_asged_net(req, + cluster_id, + interface[ + 'assigned_networks']) else: msg = "cluster must be given first when network " \ "plane is allocated" @@ -1585,11 +1622,22 @@ class Controller(controller.BaseController): LOG.info( "interface['assigned_networks']: %s" % interface['assigned_networks']) - assigned_networks_of_one_interface = self.\ - _check_assigned_networks(req, + if interface.get('type', None) == "bond": + bond_type = interface.get("bond_type", None) + if bond_type: + assigned_networks_of_one_interface = self. \ + _check_asged_net(req, cluster_id, - interface['assigned_' - 'networks']) + interface[ + 'assigned_networks'], + bond_type) + else: + assigned_networks_of_one_interface = self. \ + _check_asged_net(req, + cluster_id, + interface[ + 'assigned_networks']) + self._update_networks_phyname( req, interface, cluster_id) host_meta['cluster'] = cluster_id diff --git a/code/daisy/daisy/db/sqlalchemy/migrate_repo/versions/029_add_bond_type.py b/code/daisy/daisy/db/sqlalchemy/migrate_repo/versions/029_add_bond_type.py new file mode 100755 index 00000000..2ee43bb4 --- /dev/null +++ b/code/daisy/daisy/db/sqlalchemy/migrate_repo/versions/029_add_bond_type.py @@ -0,0 +1,25 @@ +# Copyright 2013 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import MetaData, Table, Column, String + +bond_type = Column('bond_type', String(36)) + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + host_interfaces = Table('host_interfaces', meta, autoload=True) + host_interfaces.create_column(bond_type) diff --git a/code/daisy/daisy/db/sqlalchemy/models.py b/code/daisy/daisy/db/sqlalchemy/models.py index 8370f22f..9da23b3e 100755 --- a/code/daisy/daisy/db/sqlalchemy/models.py +++ b/code/daisy/daisy/db/sqlalchemy/models.py @@ -280,6 +280,7 @@ class HostInterface(BASE, DaisyBase): type = Column(String(32), nullable=False, default='ether') slave1 = Column(String(32)) slave2 = Column(String(32)) + bond_type = Column(String(36)) mode = Column(String(36)) is_deployment = Column(Boolean(), default=False) state = Column(String(64)) diff --git a/code/daisyclient/daisyclient/v1/shell.py b/code/daisyclient/daisyclient/v1/shell.py index 804df3c0..2df6bcae 100755 --- a/code/daisyclient/daisyclient/v1/shell.py +++ b/code/daisyclient/daisyclient/v1/shell.py @@ -129,7 +129,7 @@ def do_host_add(gc, args): "type": "", "name": "", "mac": "", "ip": "", "netmask": "", "assigned_networks": "", "slaves": "", "is_deployment": "", - "vswitch_type": ""} + "vswitch_type": "", "bond_type": ""} for kv_str in interface.split(","): try: k, v = kv_str.split("=", 1) @@ -273,7 +273,8 @@ def do_host_update(gc, args): "type": "", "name": "", "mac": "", "ip": "", "netmask": "", "mode": "", "assigned_networks": "", "slaves": "", - "is_deployment": "", "vswitch_type": ""} + "is_deployment": "", "vswitch_type": "", + "bond_type": ""} for kv_str in interfaces.split(","): try: k, v = kv_str.split("=", 1) diff --git a/code/horizon/openstack_dashboard/dashboards/environment/deploy/bonding_views.py b/code/horizon/openstack_dashboard/dashboards/environment/deploy/bonding_views.py index cb4dccd9..d601a218 100755 --- a/code/horizon/openstack_dashboard/dashboards/environment/deploy/bonding_views.py +++ b/code/horizon/openstack_dashboard/dashboards/environment/deploy/bonding_views.py @@ -226,6 +226,7 @@ def update_interfaces(interfaces_old, bond_params): "type": "bond", "name": bond_params["name"], "mode": bond_params["mode"], + "bond_type": bond_params["bond_type"], "slaves": bond_params["net_ports"] }) ether_interfaces.extend(bond_interfaces) diff --git a/code/horizon/openstack_dashboard/dashboards/environment/deploy/templates/deploy/bonding.html b/code/horizon/openstack_dashboard/dashboards/environment/deploy/templates/deploy/bonding.html index 5bb7e2de..3258c920 100755 --- a/code/horizon/openstack_dashboard/dashboards/environment/deploy/templates/deploy/bonding.html +++ b/code/horizon/openstack_dashboard/dashboards/environment/deploy/templates/deploy/bonding.html @@ -376,6 +376,7 @@ var bond_params = { "net_ports": net_ports, "name": name, + "bond_type": $('#select_bond_type').val(), "mode": bond_mode }; var url = "/dashboard/environment/deploy/" + $("#cluster_id").val() + '/bond_net_port';