Skip to content

Commit

Permalink
openstack provider: ignore ec2 metadata if not present
Browse files Browse the repository at this point in the history
Signed-off-by: Riccardo Piccoli <rpiccoli@redhat.com>
  • Loading branch information
rccrdpccl committed Nov 14, 2024
1 parent de95d78 commit 75c95de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/providers/openstack/configdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,21 @@ impl OpenstackConfigDrive {
impl MetadataProvider for OpenstackConfigDrive {
fn attributes(&self) -> Result<HashMap<String, String>> {
let mut out = HashMap::with_capacity(6);
let metadata_ec2: MetadataEc2JSON = self.read_metadata_ec2()?;
let metadata_openstack: MetadataOpenstackJSON = self.read_metadata_openstack()?;
if let Some(hostname) = metadata_openstack.hostname {
out.insert("OPENSTACK_HOSTNAME".to_string(), hostname);
}
if let Some(instance_id) = metadata_ec2.instance_id {
out.insert("OPENSTACK_INSTANCE_ID".to_string(), instance_id);
}
if let Some(uuid) = metadata_openstack.uuid {
out.insert("OPENSTACK_INSTANCE_UUID".to_string(), uuid);
}

let metadata_ec2 = match self.read_metadata_ec2() {
Ok(metadata) => metadata,
Err(error) => return Ok(out),
};
if let Some(instance_id) = metadata_ec2.instance_id {
out.insert("OPENSTACK_INSTANCE_ID".to_string(), instance_id);
}
if let Some(instance_type) = metadata_ec2.instance_type {
out.insert("OPENSTACK_INSTANCE_TYPE".to_string(), instance_type);
}
Expand Down

0 comments on commit 75c95de

Please sign in to comment.