in gg_group_setup/cmd.py [0:0]
def associate_devices(self, thing_names, config_file, region=None,
profile_name=None):
# TODO remove this function when Group discovery is enriched
"""
Using the `thing_names` values, associate existing Things in AWS IoT
with the config of another Greengrass Group for use as Greengrass
Devices.
:param thing_names: the thing name or list of thing names to associate
as Greengrass Devices
:param config_file: config file used to track the Greengrass Devices in
the group
:param region: the region in which to associate devices.
[default: us-west-2]
:param profile_name: the name of the `awscli` profile to use.
[default: None]
"""
logging.info("associate_devices thing_names:{0}".format(thing_names))
config = GroupConfigFile(config_file=config_file)
if region is None:
region = self._region
devices = config['devices']
if type(thing_names) is str:
thing_names = [thing_names]
iot_client = _get_iot_session(region=region, profile_name=profile_name)
for thing_name in thing_names:
thing = iot_client.describe_thing(thingName=thing_name)
logging.info("Found existing Thing:{0}".format(thing))
p = iot_client.list_thing_principals(thingName=thing_name)
logging.info("Existing Thing has principals:{0}".format(p))
devices[thing_name] = {
'thing_arn': thing['attributes']['thingArn'],
'cert_arn': p['principals'][0],
'cert_id': thing['attributes']['certificateId'],
'thing_name': thing_name
}
logging.info("Thing:'{0}' associated with config:'{1}'".format(
thing_name, config_file))
config['devices'] = devices