Skip to content

Commit

Permalink
feat: return ids of the instances attached to a volume when doing blo…
Browse files Browse the repository at this point in the history
…ck storage inventory.

Closes #366
  • Loading branch information
demeringo committed Oct 27, 2023
1 parent 78cab2d commit 8b48a00
Showing 9 changed files with 37 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,12 @@ _This paragraph may describe WIP/unreleased features_

### Changed

## [1.0.1]-2023-10-27

### Added

- [Return ids of the instances attached to a volume when doing block storage inventory · Issue #366 · Boavizta/cloud-scanner](https://github.com/Boavizta/cloud-scanner/issues/366)

## [1.0.0]-2023-10-12

First stable release of cloud-scanner that supports latest Boavizta API v1.x [Releases · Boavizta/boaviztapi](https://github.com/Boavizta/boaviztapi/releases).
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cloud-scanner-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
authors = ["boavizta.org", "Olivier de Meringo <demeringo@gmail.com>"]
edition = "2021"
name = "cloud-scanner-cli"
version = "1.0.0"
version = "1.0.1"

[dependencies]
aws-types = "0.56.1"
15 changes: 15 additions & 0 deletions cloud-scanner-cli/src/aws_inventory.rs
Original file line number Diff line number Diff line change
@@ -267,19 +267,34 @@ impl AwsInventory {

for volume in volumes {
let volume_id = volume.volume_id().unwrap();

let usage: StorageUsage = StorageUsage {
size_gb: volume.size().unwrap(),
usage_duration_seconds: 3600,
};

let volume_type: String = volume.volume_type().unwrap().as_str().to_string();
let mut attached_instances: Option<Vec<StorageAttachment>> = None;

if let Some(all_volume_attachments) = volume.attachments.clone() {
for single_attachment in all_volume_attachments {
let mut attachment_list: Vec<StorageAttachment> = Vec::new();

if let Some(instance_id) = single_attachment.instance_id {
attachment_list.push(StorageAttachment { instance_id });
}
attached_instances = Some(attachment_list);
}
}

let disk = CloudResource {
provider: CloudProvider::AWS,
id: volume_id.into(),
location: location.clone(),
resource_details: ResourceDetails::BlockStorage {
storage_type: volume_type,
usage: Some(usage),
attached_instances,
},
tags: Self::cloud_resource_tags_from_aws_tags(volume.tags()),
};
4 changes: 4 additions & 0 deletions cloud-scanner-cli/src/boavizta_api_v1.rs
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ impl BoaviztaApiV1 {
ResourceDetails::BlockStorage {
storage_type,
usage,
attached_instances: _,
} => {
//let duration: f32 = usage.unwrap().usage_duration_seconds.into();
let disk = Disk {
@@ -211,6 +212,7 @@ pub fn boa_impacts_to_cloud_resource_with_impacts(
ResourceDetails::BlockStorage {
storage_type: _,
usage: _,
attached_instances: _,
} => {
// TODO: handle empty values differently, it could be better to have an option to be explicit about null values.
info!("Impacts of the use phase of storage are not counted (only embedded impacts are counted).");
@@ -321,6 +323,7 @@ mod tests {
size_gb: 1000,
usage_duration_seconds: 0,
}),
attached_instances: None,
},
tags: Vec::new(),
};
@@ -348,6 +351,7 @@ mod tests {
size_gb: 1000,
usage_duration_seconds: 3600,
}),
attached_instances: None,
},
tags: Vec::new(),
};
6 changes: 6 additions & 0 deletions cloud-scanner-cli/src/cloud_resource.rs
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ pub enum ResourceDetails {
BlockStorage {
storage_type: String,
usage: Option<StorageUsage>,
attached_instances: Option<Vec<StorageAttachment>>,
},
ObjectStorage,
}
@@ -52,6 +53,11 @@ pub struct StorageUsage {
pub usage_duration_seconds: u32,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct StorageAttachment {
pub instance_id: String,
}

/// A tag (just a mandatory key + optional value)
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct CloudResourceTag {
2 changes: 1 addition & 1 deletion cloud-scanner-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ enum SubCommand {
/// List instances and their average cpu load for the last 5 minutes (without returning impacts)
Inventory {
#[arg(long, short = 'b', action)]
/// List block storage
/// Experimental feature: include block storage in the inventory
include_block_storage: bool,
},
/// Run as a standalone server.
2 changes: 1 addition & 1 deletion cloud-scanner-lambda/Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
authors = ["boavizta.org", "Olivier de Meringo <demeringo@gmail.com>"]
edition = "2021"
name = "cloud-scanner-lambda"
version = "1.0.0"
version = "1.0.1"
[[bin]]
name = "bootstrap-scan"
path = "src/main.rs"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ services:
cloud_scanner:
container_name: "cloud_scanner_boa"
hostname: cloud_scanner
image: ghcr.io/boavizta/cloud-scanner-cli:1.0.0
image: ghcr.io/boavizta/cloud-scanner-cli:1.0.1
command:
- -b http://boavizta_api:5000
- -vv

0 comments on commit 8b48a00

Please sign in to comment.