+ # We can't store the FQDN on the name attribute or anything like it,
+ # because (a) names are static throughout the node's life (so FQDN
+ # isn't available because we don't know it at node creation time) and
+ # (b) it can't contain dots. Instead stash it in metadata.
+ hostname = arvados_node_fqdn(arvados_node)
+ metadata_req = cloud_node.extra['metadata'].copy()
+ metadata_items = metadata_req.setdefault('items', [])
+ try:
+ self._find_metadata(metadata_items, 'hostname')['value'] = hostname
+ except KeyError:
+ metadata_items.append({'key': 'hostname', 'value': hostname})
+ response = self.real.connection.async_request(
+ '/zones/{}/instances/{}/setMetadata'.format(
+ cloud_node.extra['zone'].name, cloud_node.name),
+ method='POST', data=metadata_req)
+ if not response.success():
+ raise Exception("setMetadata error: {}".format(response.error))
+
+ @classmethod
+ def node_fqdn(cls, node):
+ # See sync_node comment.
+ return cls._get_metadata(node.extra['metadata'].get('items', []),
+ 'hostname', '')