def _get_core(self, ver_arn): # コア定義バージョンのARNから、 # コア定義IDとコア定義バージョンIDを抽出する def_id, ver_id = self._extract_version_arn(ver_arn) # コア定義バージョンを取得する core_ver = self.greengrass.get_core_definition_version( CoreDefinitionId=def_id, CoreDefinitionVersionId=ver_id) # コアは配列だが、最初の要素のみを参照する cores = core_ver.get('Definition', {}).get('Cores', ()) if len(cores) == 0: raise entity.NotFound('Missing core') core = cores[0] # コアに紐付くモノのARNから、モノの名前を抽出する thing_name = self._extract_last_token(core.get('ThingArn', '')) # コアに紐付くモノを取得する thing_e = self._get_thing(thing_name) core_e = entity.Core( id=core.get('Id', ''), thing=thing_e, ) return entity.CoreDefinition( id=def_id, version_arn=ver_arn, core=core_e, )
def describe_thing(self, **kwargs): thing = self.things.get(kwargs['thingName']) if thing is None: raise entity.NotFound('describe_thing') return thing
def attach_thing_principal(self, **kwargs): if kwargs['thingName'] not in self.things: raise entity.NotFound('attach_thing_principal')
def get_device_definition_version(self, **kwargs): dev_ver = self.device_versions.get(kwargs['DeviceDefinitionId'] + ':' + kwargs['DeviceDefinitionVersionId']) if dev_ver is None: raise entity.NotFound('get_device_definition_version') return dev_ver
def get_core_definition_version(self, **kwargs): core_ver = self.core_versions.get(kwargs['CoreDefinitionId'] + ':' + kwargs['CoreDefinitionVersionId']) if core_ver is None: raise entity.NotFound('get_core_definition_version') return core_ver
def get_group_version(self, **kwargs): group_ver = self.group_versions.get(kwargs['GroupId'] + ':' + kwargs['GroupVersionId']) if group_ver is None: raise entity.NotFound('get_group_version') return group_ver
def get_group(self, **kwargs): group = self.groups.get(kwargs['GroupId']) if group is None: raise entity.NotFound('get_group') return group
def _extract_last_token(s): tokens = s.rsplit('/', 1) if len(tokens) != 2: raise entity.NotFound('No tokens found') return tokens[1]
def _extract_version_arn(s): tokens = s.rsplit('/', 3) if len(tokens) != 4 or tokens[2] != 'versions': raise entity.NotFound('Invalid ARN format') return (tokens[1], tokens[3])