def delete_port(self, port_id):
        """delete_port. This call makes the REST request to the external

        SDN controller for un provision VLAN for the switch port where
        bare metal is connected.
        """
        LOG.debug("delete_port with port_id %(port_id)s",
                  {'port_id': port_id})
        rec_dict = {'neutron_port_id': port_id}
        ironic_port_map = db.get_hp_ironic_swport_map_by_id(self.context,
                                                            rec_dict)
        hp_switch_port_id = ironic_port_map.switch_port_id
        hp_sw_port_dict = {'id': hp_switch_port_id}
        switch_port_map = db.get_hp_switch_port_by_id(self.context,
                                                      hp_sw_port_dict)
        switch_id = switch_port_map.switch_id
        port_name = switch_port_map.port_name
        inner_switchports_dict = {'port_id': port_name, 'switch_id':
                                  switch_id}
        switchports_list = []
        switchports_list.append(inner_switchports_dict)
        switchports_dict = {'switchports': switchports_list}
        switchports_dict['segmentation_id'] = ironic_port_map.segmentation_id
        switchports_dict['access_type'] = hp_const.ACCESS
        LOG.debug(" switchports_dict %(switchports_dict)s ",
                  {'switchports_dict': switchports_dict})
        delete_port_dict = {'port': switchports_dict}
        resp = self._do_vlan_provisioning(delete_port_dict, False)
        if resp and resp.status_code == 204:
            db.delete_hp_switch_port(self.context, hp_sw_port_dict)
        else:
            LOG.error("Could not delete the switch port due to invalid"
                      "response")
 def test_get_hp_switch_port_by_id(self):
     """Test get_hp_switch_port_by_switchid_portname method."""
     self._add_switch_and_lag_port()
     result = db.get_hp_switch_port_by_id(
         self.ctx,
         {'id': "1234"})
     self.assertEqual("1234", result.id)
    def delete_port(self, port_id):
        """delete_port. This call makes the REST request to the external

        SDN controller for un provision VLAN for the switch port where
        bare metal is connected.
        """
        LOG.debug("delete_port with port_id %(port_id)s", {'port_id': port_id})
        rec_dict = {'neutron_port_id': port_id}
        ironic_port_map = db.get_hp_ironic_swport_map_by_id(
            self.context, rec_dict)
        hp_switch_port_id = ironic_port_map.switch_port_id
        hp_sw_port_dict = {'id': hp_switch_port_id}
        switch_port_map = db.get_hp_switch_port_by_id(self.context,
                                                      hp_sw_port_dict)
        switch_id = switch_port_map.switch_id
        port_name = switch_port_map.port_name
        inner_switchports_dict = {'port_id': port_name, 'switch_id': switch_id}
        switchports_list = []
        switchports_list.append(inner_switchports_dict)
        switchports_dict = {'switchports': switchports_list}
        switchports_dict['segmentation_id'] = ironic_port_map.segmentation_id
        switchports_dict['access_type'] = hp_const.ACCESS
        LOG.debug(" switchports_dict %(switchports_dict)s ",
                  {'switchports_dict': switchports_dict})
        delete_port_dict = {'port': switchports_dict}
        resp = self._do_vlan_provisioning(delete_port_dict, False)
        if resp and resp.status_code == 204:
            db.delete_hp_switch_port(self.context, hp_sw_port_dict)
        else:
            LOG.error("Could not delete the switch port due to invalid"
                      "response")
    def delete_port(self, port_id):
        """delete_port. This call makes the REST request to the external

        SDN controller for un provision VLAN for the switch port where
        bare metal is connected.
        """

        LOG.debug("delete_port with port_id %(port_id)s",
                  {'port_id': port_id})
        rec_dict = {'neutron_port_id': port_id}
        ir_ports = db.get_hp_ironic_swport_map_by_id(self.context,
                                                     rec_dict)
        if len(ir_ports) > 1:
            is_lag = True
        else:
            is_lag = False
        if not ir_ports:
                return
        host_id = ir_ports[0].host_id
        seg_id = ir_ports[0].segmentation_id
        if is_lag:
            if not host_id and not seg_id:
                self._delete_lag_ports(ir_ports)
                return
            ext_lag_id = self._get_ext_lag_id_by_port_id(port_id)
            resp = self._do_lag_request(None, False, ext_lag_id)
            if resp and resp.status_code == 204:
                self._delete_lag_ports(ir_ports)
            else:
                LOG.error("Could not delete the switch port due to invalid"
                          "response")
        else:
            hp_switch_port_id = ir_ports[0].switch_port_id
            hp_sw_port_dict = {'id': hp_switch_port_id}
            switch_port_map = db.get_hp_switch_port_by_id(self.context,
                                                          hp_sw_port_dict)
            switch_id = switch_port_map.switch_id
            port_name = switch_port_map.port_name
            inner_switchports_dict = {'port_id': port_name, 'switch_id':
                                      switch_id}
            switchports_list = []
            switchports_list.append(inner_switchports_dict)
            switchports_dict = {'switchports': switchports_list}
            switchports_dict['segmentation_id'] = ir_ports[0].segmentation_id
            switchports_dict['access_type'] = hp_const.ACCESS
            LOG.debug(" switchports_dict %(switchports_dict)s ",
                      {'switchports_dict': switchports_dict})
            delete_port_dict = {'port': switchports_dict}
            if not host_id and not seg_id:
                db.delete_hp_switch_port(self.context, hp_sw_port_dict)
                return
            resp = self._do_vlan_provisioning(delete_port_dict, False)
            if resp and resp.status_code == 204:
                db.delete_hp_switch_port(self.context, hp_sw_port_dict)
            else:
                LOG.error("Could not delete the switch port due to invalid"
                          "response")
 def test_update_hp_swport_with_lag_id(self):
     """Test update_hp_swport_with_lag_id method."""
     self._add_switch_and_lag_port()
     lag_dict = {'id': "lag1234", 'lag_id': "1234"}
     db.update_hp_switch_ports_with_lag_id(self.ctx, lag_dict)
     result = db.get_hp_switch_port_by_id(
         self.ctx,
         {'id': "1234"})
     self.assertEqual("lag1234", result.lag_id)
Esempio n. 6
0
 def test_get_hp_switch_port_by_id(self):
     """Test get_hp_switch_port_by_switchid_portname method."""
     with self.ctx.session.begin(subtransactions=True):
         entry = models.HPSwitchPort(id="phy1234",
                                     switch_id="switch1",
                                     port_name="Tengig0/1",
                                     lag_id=None)
         self.ctx.session.add(entry)
     result = db.get_hp_switch_port_by_id(self.ctx, {'id': "phy1234"})
     self.assertEqual(entry, result)
    def update_port(self, port_dict):
        """update_port. This call makes the REST request to the external

        SDN controller for provision VLAN on switch port where bare metal
        is connected.
        """

        LOG.debug("update_port with port dict %(port_dict)s",
                  {'port_dict': port_dict})
        port_id = port_dict['port']['id']
        host_id = port_dict['port']['host_id']
        rec_dict = {'neutron_port_id': port_id}
        ironic_port_list = db.get_hp_ironic_swport_map_by_id(self.context,
                                                             rec_dict)
        switchports = port_dict['port']['switchports']
        if not ironic_port_list:
            # We are creating the switch ports because initial ironic
            # port-create will not supply local link information for tenant .
            # networks . Later ironic port-update , the local link information
            # value will be supplied.
            self.create_switch_port(port_dict)
            return
        if not len(switchports) == len(ironic_port_list):
            err_msg = "given switchports dict does not match"
            self._raise_hp_net_provisioning_error(wexc.HTTPConflict,
                                                  'update_port',
                                                  err_msg)
        for ironic_port in ironic_port_list:
            hp_switch_port_id = ironic_port.switch_port_id
            hp_sw_port_dict = {'id': hp_switch_port_id}
            switch_port_map = db.get_hp_switch_port_by_id(self.context,
                                                          hp_sw_port_dict)
            switch_id_db = switch_port_map.switch_id
            port_name_db = switch_port_map.port_name
            if not any(d['port_id'] == port_name_db for d in switchports):
                err_msg = "given port does not exists"
                self._raise_hp_net_provisioning_error(wexc.HTTPNotFound,
                                                      'update_port',
                                                      err_msg)
            if not any(d['switch_id'] == switch_id_db for d in switchports):
                err_msg = "given switch does not exists"
                self._raise_hp_net_provisioning_error(wexc.HTTPNotFound,
                                                      'update_port',
                                                      err_msg)
            rec_dict = {'switch_id': switch_id_db,
                        'port_name': port_name_db}
            switch_ports = db.get_all_hp_sw_port_by_swchid_portname(
                self.context, rec_dict)
            if len(switch_ports) > 1 and host_id:
                for switch_port in switch_ports:
                    self._is_port_already_bound(switch_port, port_id)
        update_dict = {'neutron_port_id': port_id,
                       'host_id': host_id}
        db.update_hp_ironic_swport_map_with_host_id(self.context,
                                                    update_dict)
 def test_get_hp_switch_port_by_id(self):
     """Test get_hp_switch_port_by_switchid_portname method."""
     with self.ctx.session.begin(subtransactions=True):
         entry = models.HPSwitchPort(
             id="phy1234",
             switch_id="switch1",
             port_name="Tengig0/1",
             lag_id=None)
         self.ctx.session.add(entry)
     result = db.get_hp_switch_port_by_id(
         self.ctx,
         {'id': "phy1234"})
     self.assertEqual(entry, result)