示例#1
0
    def update_campaign(self,
                        campaign_object=None,
                        campaign_id=None,
                        **kwargs):
        """Update an update campaign.

        :param :class:`Campaign` campaign_object: Campaign object to update (Required)
        :return: updated campaign object
        :rtype: Campaign
        """
        api = self._get_api(update_service.DefaultApi)
        if campaign_object:
            campaign_id = campaign_object.id
            campaign_object = campaign_object._create_patch_request()
        else:
            campaign_object = Campaign._create_request_map(kwargs)
        if 'device_filter' in campaign_object:
            campaign_object["device_filter"] = filters.legacy_filter_formatter(
                dict(filter=campaign_object["device_filter"]),
                Device._get_attributes_map())['filter']
        if 'when' in campaign_object:
            # FIXME: randomly validating an input here is a sure route to nasty surprises elsewhere
            campaign_object['when'] = force_utc(campaign_object['when'])
        return Campaign(
            api.update_campaign_update(campaign_id=campaign_id,
                                       campaign=campaign_object))
 def _verify_arguments(self, interval, kwargs):
     start = kwargs.get("start", None)
     end = kwargs.get("end", None)
     period = kwargs.get("period", None)
     if not start and not end and not period:
         raise CloudValueError("start and end is mandatory if period is not specified.")
     if start and not end:
         raise CloudValueError("end is required if start is specified.")
     if end and not start:
         raise CloudValueError("start is required if end is specified.")
     pattern = re.compile("[0-9]+[h|d|w]$")
     if period and not pattern.match(period):
         raise CloudValueError("period is incorrect. Sample values: 2h, 3w, 4d.")
     if interval and not pattern.match(interval):
         raise CloudValueError("interval is incorrect. Sample values: 2h, 3w, 4d.")
     # convert start into UTC RFC3339 format
     if start:
         kwargs['start'] = utils.force_utc(start, 'start', precision=3)
     # convert end into UTC RFC3339 format
     if end:
         kwargs['end'] = utils.force_utc(end, 'end', precision=3)
    def add_campaign(self, name, device_filter, **kwargs):
        """Add new update campaign.

        Add an update campaign with a name and device filtering. Example:

        .. code-block:: python

            device_api, update_api = DeviceDirectoryAPI(), UpdateAPI()

            # Get a filter to use for update campaign
            query_obj = device_api.get_query(query_id="MYID")

            # Create the campaign
            new_campaign = update_api.add_campaign(
                name="foo",
                device_filter=query_obj.filter
            )

        :param str name: Name of the update campaign (Required)
        :param str device_filter: The device filter to use (Required)
        :param str manifest_id: ID of the manifest with description of the update
        :param str description: Description of the campaign
        :param int scheduled_at: The timestamp at which update campaign is scheduled to start
        :param str state: The state of the campaign. Values:
            "draft", "scheduled", "devicefetch", "devicecopy", "publishing",
            "deploying", "deployed", "manifestremoved", "expired"
        :return: newly created campaign object
        :rtype: Campaign
        """
        device_filter = filters.legacy_filter_formatter(
            dict(filter=device_filter),
            Device._get_attributes_map()
        )
        campaign = Campaign._create_request_map(kwargs)
        if 'when' in campaign:
            campaign['when'] = force_utc(campaign['when'])
        body = UpdateCampaignPostRequest(
            name=name,
            device_filter=device_filter['filter'],
            **campaign)
        api = self._get_api(update_service.DefaultApi)
        return Campaign(api.update_campaign_create(body))