Esempio n. 1
0
    def get_all_devices_in_portal(self):
        """
            This loops through the get_multiple_devices method 10 rids at a time.
        """
        rids = self.get_portal_by_name(
            self.portal_name())[2][1]['info']['aliases']

        # print("RIDS: {0}".format(rids))
        device_rids = [rid.strip() for rid in rids]

        blocks_of_ten = [
            device_rids[x:x + 10] for x in range(0, len(device_rids), 10)
        ]
        devices = []
        for block_of_ten in blocks_of_ten:
            retval = self.get_multiple_devices(block_of_ten)
            if retval is not None:
                devices.extend(retval)
            else:
                print("Not adding to device list: {!r}".format(retval))

        # Parse 'meta' key's raw string values for each device
        for device in devices:
            dictify_device_meta(device)

        return devices
Esempio n. 2
0
    def get_all_devices_in_portal(self):
        """
            This loops through the get_multiple_devices method 10 rids at a time.
        """
        rids = self.get_portal_by_name(
                        self.portal_name()
                )[2][1]['info']['aliases']

        # print("RIDS: {0}".format(rids))
        device_rids = [ rid.strip() for rid in rids ]

        blocks_of_ten = [ device_rids[x:x+10] for x in range(0, len(device_rids), 10) ]
        devices = []
        for block_of_ten in blocks_of_ten:
            retval = self.get_multiple_devices(block_of_ten)
            if retval is not None:
                devices.extend( retval )
            else:
                print("Not adding to device list: {!r}".format(retval))

        # Parse 'meta' key's raw string values for each device
        for device in devices:
            dictify_device_meta(device)

        return devices
Esempio n. 3
0
 def add_location_timezone_to_device(self, device_obj, location, timezone):
     """
         Returns 'device object' with updated location
         
         http://docs.exosite.com/portals/#update-device
         http://docs.exosite.com/portals/#device-object
     """
     dictify_device_meta(device_obj)
     device_obj['info']['description']['meta']['location'] = location
     device_obj['info']['description']['meta']['Location'] = location
     device_obj['info']['description']['meta']['timezone'] = timezone
     device_obj['info']['description']['meta']['Timezone'] = timezone
     return self.update_device(device_obj)
Esempio n. 4
0
 def add_location_timezone_to_device(self, device_obj, location, timezone):
     """
         Returns 'device object' with updated location
         
         http://docs.exosite.com/portals/#update-device
         http://docs.exosite.com/portals/#device-object
     """
     dictify_device_meta(device_obj)
     device_obj['info']['description']['meta']['location'] = location
     device_obj['info']['description']['meta']['Location'] = location
     device_obj['info']['description']['meta']['timezone'] = timezone
     device_obj['info']['description']['meta']['Timezone'] = timezone
     return self.update_device(device_obj)
Esempio n. 5
0
    def add_device(self, model, serial):
        """
            Returns 'device object' of newly created device.

            http://docs.exosite.com/portals/#create-device
            http://docs.exosite.com/portals/#device-object
        """
        device = {
                'model': model,
                'vendor': self.vendor(),
                'sn': serial,
                'type': 'vendor'
        }
        headers = {
                'User-Agent': self.user_agent(),
        }
        headers.update(self.headers())

        r = requests.post(  self.portals_url()+'/portals/'+self.portal_id()+'/devices', 
                                data=json.dumps(device),
                                headers=headers,
                                auth=self.auth())

        if HTTP_STATUS.ADDED == r.status_code:
            # fix the 'meta' to be dictionary instead of string
            device_obj = r.json()
            return dictify_device_meta(device_obj)
        else:
            print("add_device: Something went wrong: <{0}>: {1}".format(
                        r.status_code, r.reason))
            r.raise_for_status()
Esempio n. 6
0
    def add_device(self, model, serial):
        """
            Returns 'device object' of newly created device.

            http://docs.exosite.com/portals/#create-device
            http://docs.exosite.com/portals/#device-object
        """
        device = {
            'model': model,
            'vendor': self.vendor(),
            'sn': serial,
            'type': 'vendor'
        }
        headers = {
            'User-Agent': self.user_agent(),
        }
        headers.update(self.headers())

        r = requests.post(self.portals_url() + '/portals/' + self.portal_id() +
                          '/devices',
                          data=json.dumps(device),
                          headers=headers,
                          auth=self.auth())

        if HTTP_STATUS.ADDED == r.status_code:
            # fix the 'meta' to be dictionary instead of string
            device_obj = r.json()
            return dictify_device_meta(device_obj)
        else:
            print("add_device: Something went wrong: <{0}>: {1}".format(
                r.status_code, r.reason))
            r.raise_for_status()