diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-08-19 13:37:57 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2022-09-28 09:48:46 -0400 |
commit | d9884ab144a253b788f4cfc966301f645ffed5fb (patch) | |
tree | 9201c757219ccc92c939b1e3085d8be3a90442ab | |
parent | 3f586b776e44cdc9d3b4aaa1e7b0d53fecf0acde (diff) | |
download | sos-d9884ab144a253b788f4cfc966301f645ffed5fb.tar.gz |
[gcp] Move metadata collection to `collect()`
Moves the collection and writing of GCP metadata to `collect()` and out
of `setup()`.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/report/plugins/gcp.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/sos/report/plugins/gcp.py b/sos/report/plugins/gcp.py index adbc2525..8ed0ec8f 100644 --- a/sos/report/plugins/gcp.py +++ b/sos/report/plugins/gcp.py @@ -59,20 +59,19 @@ class GCP(Plugin, IndependentPlugin): # Capture gcloud auth list self.add_cmd_output("gcloud auth list", tags=['gcp']) - # Get and store Metadata - try: - self.metadata = self.get_metadata() - self.scrub_metadata() - self.add_string_as_file(json.dumps(self.metadata, indent=4), - "metadata.json", plug_dir=True, - tags=['gcp']) - except RuntimeError as err: - self.add_string_as_file(str(err), 'metadata.json', - plug_dir=True, tags=['gcp']) - # Add journal entries self.add_journal(units="google*", tags=['gcp']) + def collect(self): + # Get and store Metadata + with self.collection_file('metadata.json', tags=['gcp']) as mfile: + try: + self.metadata = self.get_metadata() + self.scrub_metadata() + mfile.write(json.dumps(self.metadata, indent=4)) + except RuntimeError as err: + mfile.write(str(err)) + def get_metadata(self) -> dict: """ Retrieves metadata from the Metadata Server and transforms it into a |