Beispiel #1
0
    def test_delete(self):
        switch = self.deserialize(
            self.fmt, self._create_switch(self.fmt, 'switch0', '1.2.3.4'))
        switch_id = switch['switch']['id']

        req = self.new_delete_request('switches', switch_id)
        res = req.get_response(self.ext_api)

        self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code)

        switch = ironic_db.get_switch(switch_id)
        self.assertEqual(switch, None)
    def test_delete(self):
        switch = self.deserialize(
            self.fmt, self._create_switch(self.fmt, 'switch0', '1.2.3.4')
        )
        switch_id = switch['switch']['id']

        req = self.new_delete_request('switches', switch_id)
        res = req.get_response(self.ext_api)

        self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code)

        switch = ironic_db.get_switch(switch_id)
        self.assertEqual(switch, None)
 def show(self, request, id):
     switch = db.get_switch(id)
     if not switch:
         raise exc.NotFound(
             resource="switch %s" % (id))
     return dict(switch=switch.as_dict())
    def validate_switchports(cls, switchports, session=None):
        """TODO(morgabra) Split this up, think about it more. It's
        inefficient and large.
        """
        if not session:
            session = db_api.get_session()

        if not switchports:
            raise exc.BadRequest(
                resource="switchports",
                reason="must specify at least 1 switchport")

        hardware_id = cls._validate_hardware_id(switchports)

        # Ensure no switchports exist for the given hardware_id
        existing = list(db.filter_switchports(
            hardware_id=hardware_id, session=session))
        if existing:
            raise exc.BadRequest(
                resource="switchports",
                reason=("switchports already exist for "
                        "hardware_id='%s'" % hardware_id))

        # Ensure all given names are !None
        names = set([s.get("name") for s in switchports])
        if None in names:
            raise exc.BadRequest(
                resource="switchports",
                reason="name cannot be empty")

        # Ensure all given names are unique
        if (len(names) != len(switchports)):
            raise exc.BadRequest(
                resource="switchports",
                reason="all switchport names must be unique")

        # Ensure all given switch_id/port maps are unique
        ports = set([(s.get("switch_id"), s.get("port")) for s in switchports])
        if (len(ports) != len(switchports)):
            raise exc.BadRequest(
                resource="switchports",
                reason=("cannot add switchport with identical "
                        "switch_id/port values"))

        for switch_id, port in ports:

            # Ensure switch_id is !None
            if not switch_id:
                raise exc.BadRequest(
                    resource="switchports",
                    reason="switch_id cannot be empty")

            # Ensure switch_id is !None
            if not port:
                raise exc.BadRequest(
                    resource="switchports",
                    reason="port cannot be empty")

            # Ensure referenced switch actually exists
            switch = db.get_switch(switch_id, session=session)
            if not switch:
                raise exc.NotFound(
                    resource="switch %s" % (switch_id))

            # Ensure switchport not taken by another hardware_id
            existing = list(db.filter_switchports(
                switch_id=switch_id, port=port, session=session))
            if len(existing) >= 1:
                raise exc.BadRequest(
                    resource="switchport",
                    reason=("port already mapped to hardware_id "
                            "'%s'" % (existing[0].hardware_id)))

        return switchports
Beispiel #5
0
 def show(self, request, id):
     switch = db.get_switch(id)
     if not switch:
         raise exc.NotFound(resource="switch %s" % (id))
     return dict(switch=switch.as_dict())
Beispiel #6
0
    def validate_switchports(cls, switchports, session=None):
        """TODO(morgabra) Split this up, think about it more. It's
        inefficient and large.
        """
        if not session:
            session = db_api.get_session()

        if not switchports:
            raise exc.BadRequest(resource="switchports",
                                 reason="must specify at least 1 switchport")

        hardware_id = cls._validate_hardware_id(switchports)

        # Ensure no switchports exist for the given hardware_id
        existing = list(
            db.filter_switchports(hardware_id=hardware_id, session=session))
        if existing:
            raise exc.BadRequest(resource="switchports",
                                 reason=("switchports already exist for "
                                         "hardware_id='%s'" % hardware_id))

        # Ensure all given names are !None
        names = set([s.get("name") for s in switchports])
        if None in names:
            raise exc.BadRequest(resource="switchports",
                                 reason="name cannot be empty")

        # Ensure all given names are unique
        if (len(names) != len(switchports)):
            raise exc.BadRequest(resource="switchports",
                                 reason="all switchport names must be unique")

        # Ensure all given switch_id/port maps are unique
        ports = set([(s.get("switch_id"), s.get("port")) for s in switchports])
        if (len(ports) != len(switchports)):
            raise exc.BadRequest(
                resource="switchports",
                reason=("cannot add switchport with identical "
                        "switch_id/port values"))

        for switch_id, port in ports:

            # Ensure switch_id is !None
            if not switch_id:
                raise exc.BadRequest(resource="switchports",
                                     reason="switch_id cannot be empty")

            # Ensure switch_id is !None
            if not port:
                raise exc.BadRequest(resource="switchports",
                                     reason="port cannot be empty")

            # Ensure referenced switch actually exists
            switch = db.get_switch(switch_id, session=session)
            if not switch:
                raise exc.NotFound(resource="switch %s" % (switch_id))

            # Ensure switchport not taken by another hardware_id
            existing = list(
                db.filter_switchports(switch_id=switch_id,
                                      port=port,
                                      session=session))
            if len(existing) >= 1:
                raise exc.BadRequest(
                    resource="switchport",
                    reason=("port already mapped to hardware_id "
                            "'%s'" % (existing[0].hardware_id)))

        return switchports