コード例 #1
0
 def delete(self, request, id, **kwargs):
     context = request.context
     self._check_admin(context)
     port_prov = None
     is_uuid = False
     if not uuidutils.is_uuid_like(id):
         switch = db.get_bnp_phys_switch_by_name(context, id)
     else:
         is_uuid = True
         switch = db.get_bnp_phys_switch(context, id)
     if not switch:
         raise webob.exc.HTTPNotFound(
             _("Switch %s does not exist") % id)
     if isinstance(switch, list) and len(switch) > 1:
         raise webob.exc.HTTPConflict(
             _("Multiple switches matches found "
               "for name %s, use an ID to be more specific.") % id)
     if isinstance(switch, list) and len(switch) == 1:
         portmap = db.get_bnp_switch_port_map_by_switchid(context,
                                                          switch[0].id)
         port_prov = switch[0].port_prov
     else:
         portmap = db.get_bnp_switch_port_map_by_switchid(context, id)
         port_prov = switch['port_prov']
     if portmap:
         raise webob.exc.HTTPConflict(
             _("Switch id %s has active port mappings") % id)
     if port_prov == const.SWITCH_STATUS['enable']:
         raise webob.exc.HTTPBadRequest(
             _("Disable the switch %s to delete") % id)
     if is_uuid:
         db.delete_bnp_phys_switch(context, id)
     else:
         db.delete_bnp_phys_switch_by_name(context, id)
 def test_delete_bnp_phys_switch(self):
     """Test delete_bnp_phys_switch method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     switch = db.get_bnp_phys_switch_by_mac(self.ctx,
                                            sw_dict['mac_address'])
     db.delete_bnp_phys_switch(self.ctx, switch['id'])
     count = self.ctx.session.query(models.BNPPhysicalSwitch).count()
     self.assertEqual(0, count)
コード例 #3
0
 def delete(self, request, id, **kwargs):
     context = request.context
     self._check_admin(context)
     switch = db.get_bnp_phys_switch(context, id)
     if not switch:
         raise webob.exc.HTTPNotFound(
             _("Switch %s does not exist") % id)
     if switch['status'] == const.SWITCH_STATUS['enable']:
         raise webob.exc.HTTPBadRequest(
             _("Disable the switch %s to delete") % id)
     db.delete_bnp_phys_switch(context, id)
コード例 #4
0
 def delete(self, request, id, **kwargs):
     context = request.context
     self._check_admin(context)
     switch = db.get_bnp_phys_switch(context, id)
     if not switch:
         raise webob.exc.HTTPNotFound(_("Switch %s does not exist") % id)
     portmap = db.get_bnp_switch_port_map_by_switchid(context, id)
     if portmap:
         raise webob.exc.HTTPConflict(
             _("Switch id %s has active port mappings") % id)
     if (switch['port_provisioning'] ==
             const.PORT_PROVISIONING_STATUS['enable']):
         raise webob.exc.HTTPBadRequest(
             _("Disable the switch %s to delete") % id)
     db.delete_bnp_phys_switch(context, id)
コード例 #5
0
 def delete(self, request, id, **kwargs):
     context = request.context
     self._check_admin(context)
     switch = db.get_bnp_phys_switch(context, id)
     portmap = db.get_bnp_switch_port_map_by_switchid(context, id)
     if portmap:
         raise webob.exc.HTTPConflict(
             _("Switch id %s has active port mappings") % id)
     if not switch:
         raise webob.exc.HTTPNotFound(
             _("Switch %s does not exist") % id)
     if switch['status'] == const.SWITCH_STATUS['enable']:
         raise webob.exc.HTTPBadRequest(
             _("Disable the switch %s to delete") % id)
     db.delete_bnp_phys_switch(context, id)