コード例 #1
0
 def _create_image(self, request, provider_uuid, identity_uuid):
     _permission_to_act(identity_uuid, "Imaging")
     # request.data is r/o
     # Copy allows for editing
     data = copy.deepcopy(request.data)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis', 'public') != 'public':
         user_list = data.get('shared_with', '')
         if type(user_list) == str:
             user_list = re.split(', | |\n', user_list)
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user]  # Skips blanks
         # TODO: Remove duplicates as well..
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         # Add parent machine to request
         instance = serializer.validated_data['instance']
         parent_machine = instance.source.providermachine
         serializer.validated_data['parent_machine'] = parent_machine
         user = serializer.validated_data['new_machine_owner']
         identity_member = IdentityMembership.objects.get(
             identity__provider=serializer.
             validated_data['new_machine_provider'],
             identity__created_by=user)
         serializer.validated_data['membership'] = identity_member
         serializer.validated_data['created_by'] = user
         self._permission_to_image(identity_uuid, instance)
         pending_status = StatusType.objects.get(name='pending')
         machine_request = serializer.save(status=pending_status)
         instance = machine_request.instance
         # NOTE: THIS IS A HACK -- While we enforce all images
         #       to go to iPlant Cloud - Tucson.
         # THIS CODE SHOULD BE REMOVED
         try:
             tucson_provider = Provider.objects.get(
                 location='iPlant Cloud - Tucson')
             if machine_request.new_machine_provider.location\
                != tucson_provider.location:
                 machine_request.new_machine_provider = tucson_provider
         except:
             # Will skip this step if no provider is named
             # iPlant Cloud - Tucson.
             pass
         # Object now has an ID for links..
         machine_request_id = machine_request.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.auto_imaging
         requestImaging(request,
                        machine_request_id,
                        auto_approve=auto_approve)
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return bad_request(serializer.errors, prefix="Invalid value for ")
コード例 #2
0
 def _create_image(self, request, provider_uuid, identity_uuid):
     _permission_to_act(identity_uuid, "Imaging")
     # request.DATA is r/o
     # Copy allows for editing
     data = copy.deepcopy(request.DATA)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis', 'public') != 'public':
         user_list = data.get('shared_with', '')
         if type(user_list) == str:
             user_list = re.split(', | |\n', user_list)
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user]  # Skips blanks
         # TODO: Remove duplicates as well..
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         # Add parent machine to request
         instance = serializer.validated_data['instance']
         parent_machine = instance.source.providermachine
         serializer.validated_data['parent_machine'] = parent_machine
         user = serializer.validated_data['new_machine_owner']
         identity_member = IdentityMembership.objects.get(
                 identity__provider=serializer.validated_data['new_machine_provider'],
                 identity__created_by=user)
         serializer.validated_data['membership'] = identity_member
         serializer.validated_data['created_by'] = user
         self._permission_to_image(identity_uuid, instance)
         machine_request = serializer.save()
         instance = machine_request.instance
         # NOTE: THIS IS A HACK -- While we enforce all images
         #       to go to iPlant Cloud - Tucson.
         # THIS CODE SHOULD BE REMOVED
         try:
             tucson_provider = Provider.objects.get(
                 location='iPlant Cloud - Tucson')
             if machine_request.new_machine_provider.location\
                != tucson_provider.location:
                 machine_request.new_machine_provider = tucson_provider
         except:
             # Will skip this step if no provider is named
             # iPlant Cloud - Tucson.
             pass
         serializer.save()
         # Object now has an ID for links..
         machine_request_id = machine_request.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.auto_imaging
         requestImaging(request, machine_request_id,
                        auto_approve=auto_approve)
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data,
                         status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
 def _create_image(self, request, provider_uuid, identity_uuid):
     _permission_to_act(identity_uuid, "Imaging")
     # request.data is r/o
     # Copy allows for editing
     data = copy.deepcopy(request.data)
     data.update({'owner': data.get('created_for', request.user.username)})
     if data.get('vis', 'public') != 'public':
         user_list = data.get('shared_with', '')
         if type(user_list) == str:
             user_list = re.split(', | |\n', user_list)
         share_with_admins(user_list, data.get('provider'))
         share_with_self(user_list, request.user.username)
         user_list = [user for user in user_list if user]    # Skips blanks
         # TODO: Remove duplicates as well..
         data['shared_with'] = user_list
     logger.info(data)
     serializer = MachineRequestSerializer(data=data)
     if serializer.is_valid():
         # Add parent machine to request
         instance = serializer.validated_data['instance']
         parent_machine = instance.source.providermachine
         serializer.validated_data['parent_machine'] = parent_machine
         user = serializer.validated_data['new_machine_owner']
         identity_member = IdentityMembership.objects.get(
             identity__provider=serializer.
             validated_data['new_machine_provider'],
             identity__created_by=user
         )
         serializer.validated_data['membership'] = identity_member
         serializer.validated_data['created_by'] = user
         self._permission_to_image(identity_uuid, instance)
         pending_status, _ = StatusType.objects.get_or_create(name='pending')
         machine_request = serializer.save(status=pending_status)
         instance = machine_request.instance
         if getattr(settings, 'REPLICATION_PROVIDER_LOCATION'):
             try:
                 replication_provider = Provider.objects.get(
                     location=settings.REPLICATION_PROVIDER_LOCATION
                 )
                 if machine_request.new_machine_provider.location\
                    != replication_provider.location:
                     machine_request.new_machine_provider = replication_provider
             except:
                 # Will skip this step if no provider is named
                 # as the REPLICATION_PROVIDER_LOCATION
                 pass
         # Object now has an ID for links..
         machine_request_id = machine_request.id
         active_provider = machine_request.active_provider()
         auto_approve = active_provider.auto_imaging
         requestImaging(
             request, machine_request_id, auto_approve=auto_approve
         )
         if auto_approve:
             start_machine_imaging(machine_request)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return bad_request(serializer.errors, prefix="Invalid value for ")
コード例 #4
0
 def submit_action(self, instance):
     """
     Submits a resource request email
     """
     provider = instance.active_provider()
     pre_approved = provider.auto_imaging
     requestImaging(self.request, instance.id, auto_approve=pre_approved)
     
     if pre_approved:
         status, _ = StatusType.objects.get_or_create(name="approved")
         instance.status = status
         instance.save()
         start_machine_imaging(instance)
コード例 #5
0
    def submit_action(self, instance):
        """
        Submits a resource request email
        """
        #NOTE/FIXME: This should be considered when locking down "Imaging Strategy" for a "Provider Grouping"
        new_provider = self._get_new_provider()
        pre_approved = new_provider.auto_imaging
        requestImaging(self.request, instance.id, auto_approve=pre_approved)

        if pre_approved:
            status, _ = StatusType.objects.get_or_create(name="approved")
            instance.status = status
            instance.save()
            start_machine_imaging(instance)
コード例 #6
0
    def submit_action(self, instance):
        """
        Submits a resource request email
        """
        #NOTE/FIXME: This should be considered when locking down "Imaging Strategy" for a "Provider Grouping"
        new_provider = self._get_new_provider()
        pre_approved = new_provider.auto_imaging
        requestImaging(self.request, instance.id, auto_approve=pre_approved)

        if pre_approved:
            status, _ = StatusType.objects.get_or_create(name="approved")
            instance.status = status
            instance.save()
            start_machine_imaging(instance)