Exemplo n.º 1
0
 def convert_to_data_center_asset(cls, instances, **kwargs):
     from ralph.data_center.models.physical import DataCenterAsset, Rack  # noqa
     from ralph.back_office.helpers import bo_asset_to_dc_asset_status_converter  # noqa
     with transaction.atomic():
         for i, instance in enumerate(instances):
             data_center_asset = DataCenterAsset()
             data_center_asset.rack = Rack.objects.get(pk=kwargs['rack'])
             data_center_asset.position = kwargs['position']
             data_center_asset.service_env = ServiceEnvironment.objects.get(
                 pk=kwargs['service_env'])
             data_center_asset.model = AssetModel.objects.get(
                 pk=kwargs['model'])
             target_status = int(
                 Transition.objects.values_list('target', flat=True).get(
                     pk=kwargs['transition_id'])  # noqa
             )
             data_center_asset.status = bo_asset_to_dc_asset_status_converter(  # noqa
                 instance.status, target_status)
             move_parents_models(instance,
                                 data_center_asset,
                                 exclude_copy_fields=[
                                     'rack', 'model', 'service_env',
                                     'status'
                                 ])
             data_center_asset.save()
             # Save new asset to list, required to redirect url.
             # RunTransitionView.get_success_url()
             instances[i] = data_center_asset
Exemplo n.º 2
0
    def convert_to_backoffice_asset(cls, instances, **kwargs):
        with transaction.atomic():
            for i, instance in enumerate(instances):
                back_office_asset = BackOfficeAsset()

                back_office_asset.region = Region.objects.get(
                    pk=kwargs['region'])
                back_office_asset.warehouse = Warehouse.objects.get(
                    pk=kwargs['warehouse'])
                target_status = int(
                    Transition.objects.values_list('target', flat=True).get(
                        pk=kwargs['transition_id'])  # noqa
                )
                back_office_asset.status = dc_asset_to_bo_asset_status_converter(  # noqa
                    instance.status, target_status)
                move_parents_models(instance,
                                    back_office_asset,
                                    exclude_copy_fields=['status'])
                # Save new asset to list, required to redirect url.
                # RunTransitionView.get_success_url()
                instances[i] = back_office_asset