Skip to content

Commit

Permalink
feat(bolt): update datacenters from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelOnFira committed Apr 22, 2024
1 parent 36818ad commit bbf3a6b
Show file tree
Hide file tree
Showing 25 changed files with 817 additions and 3 deletions.
9 changes: 9 additions & 0 deletions errors/api/admin/cluster/cluster-not-found.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name = "CLUSTER_NOT_FOUND"
description = "The requested cluster was not found."
http_status = 404
---

# API Not Found

The requested cluster was not found.
15 changes: 15 additions & 0 deletions fern/definition/admin/clusters/datacenters/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ service:
request:
body: CreateRequest
response: CreateResponse
update:
path: /{datacenter_id}
path-parameters:
datacenter_id:
type: uuid
method: PUT
request:
body: UpdateRequest
taint:
path: /{datacenter_id}/taint
path-parameters:
Expand All @@ -42,3 +50,10 @@ types:
CreateResponse:
properties:
datacenter_id: uuid
UpdateRequest:
properties:
pool_type: localCommons.PoolType
hardware: list<localCommons.Hardware>
desired_count: optional<integer>
max_count: optional<integer>
drain_timeout: optional<long>
87 changes: 87 additions & 0 deletions lib/bolt/cli/src/commands/admin/cluster/datacenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ impl From<DatacenterBuildDeliveryMethod> for models::AdminBuildDeliveryMethod {
}
}

#[derive(ValueEnum, Clone)]
pub enum DatacenterPoolType {
Job,
Gg,
Ats,
}

impl From<DatacenterPoolType> for models::AdminPoolType {
fn from(pool_type: DatacenterPoolType) -> Self {
match pool_type {
DatacenterPoolType::Job => models::AdminPoolType::Job,
DatacenterPoolType::Gg => models::AdminPoolType::Gg,
DatacenterPoolType::Ats => models::AdminPoolType::Ats,
}
}
}

#[derive(Parser)]
pub enum SubCommand {
/// Creates a new datacenter
Expand Down Expand Up @@ -71,6 +88,29 @@ pub enum SubCommand {
#[clap(long, short = 'd')]
datacenter_name_id: String,
},
Update {
/// The name id of the cluster
#[clap(long, short = 'c')]
cluster_name_id: String,
/// The name id of the datacenter
#[clap(long, short = 'd')]
datacenter_name_id: String,
/// The pool type
#[clap(long)]
pool_type: DatacenterPoolType,
/// The hardware types
#[clap(long)]
hardware: Vec<String>,
/// The desired count
#[clap(long)]
desired_count: Option<i32>,
/// The max count
#[clap(long)]
max_count: Option<i32>,
/// The drain timeout
#[clap(long)]
drain_timeout: Option<i64>,
},
}

#[derive(Tabled)]
Expand Down Expand Up @@ -164,6 +204,53 @@ impl SubCommand {
)
.await?;
}
Self::Update {
cluster_name_id,
datacenter_name_id,
pool_type,
hardware,
desired_count,
max_count,
drain_timeout,
} => {
let cluster_ids =
admin_clusters_api::admin_clusters_list(&ctx.openapi_config_cloud().await?)
.await?;

let clusters = get_clusters(&ctx, cluster_ids).await?;

let cluster = clusters
.clusters
.iter()
.find(|cluster| cluster.name_id == cluster_name_id);

let cluster = match cluster {
Some(cluster) => cluster,
None => bail!("cluster with the name id {} not found", cluster_name_id),
};

let datacenter_ids =
admin_clusters_datacenters_api::admin_clusters_datacenters_list(
&ctx.openapi_config_cloud().await?,
&cluster.cluster_id.to_string(),
)
.await?;

let datacenters = get_datacenters(&ctx, cluster.cluster_id, datacenter_ids).await?;

let datacenter = datacenters
.datacenters
.iter()
.find(|datacenter| datacenter.name_id == datacenter_name_id);

let datacenter = match datacenter {
Some(datacenter) => datacenter,
None => bail!(
"datacenter with the name id {} not found",
datacenter_name_id
),
};
}
}

Ok(())
Expand Down
76 changes: 76 additions & 0 deletions sdks/full/go/admin/clusters/datacenters/client/client.go

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

33 changes: 33 additions & 0 deletions sdks/full/go/admin/clusters/datacenters/datacenters.go

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

83 changes: 83 additions & 0 deletions sdks/full/openapi/openapi.yml

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

Loading

0 comments on commit bbf3a6b

Please sign in to comment.