Пример #1
0
def environment_rack(user, environment_list, rack):

    # Insert all environments in environment rack table
    # Insert rack switches in rack environments
    for env in environment_list:
        try:
            ambienteRack = EnvironmentRack()
            ambienteRack.ambiente = env
            ambienteRack.rack = rack
            ambienteRack.create(user)
        except EnvironmentRackDuplicatedError:
            pass

        for switch in [rack.id_sw1, rack.id_sw2]:
            try:
                equipamento_ambiente = EquipamentoAmbiente()
                equipamento_ambiente.ambiente = env
                equipamento_ambiente.equipamento = switch
                equipamento_ambiente.is_router = True
                equipamento_ambiente.create(user)
            except EquipamentoAmbienteDuplicatedError:
                pass
Пример #2
0
    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all Racks

        URLs: /rack/list-rack-environment/<rack_id>/
        """

        self.log.info('Find all racks environment')

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT,
                            AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            environment_list = []
            id = kwargs.get('rack_id')
            env = EnvironmentRack()
            environments = env.get_by_rack(id)
            for envs in environments:
                envs = model_to_dict(envs)
                amb = Ambiente()
                ambiente = amb.get_by_pk(envs['ambiente'])
                if "PROD" in ambiente.ambiente_logico.nome:
                    environment_list.append(get_environment_map(ambiente))

            return self.response(
                dumps_networkapi({'ambiente': environment_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RackError:
            return self.response_error(397)