Skip to content

Commit

Permalink
feat(api-admin): add server destroy endpoint (#838)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
NathanFlurry committed Jun 1, 2024
1 parent 041ae05 commit 4ff616b
Show file tree
Hide file tree
Showing 45 changed files with 823 additions and 7 deletions.
10 changes: 10 additions & 0 deletions fern/definition/admin/clusters/servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ service:
datacenter: optional<string>
pool: optional<localCommons.PoolType>
public_ip: optional<string>
destroy:
path: /destroy
method: POST
request:
name: DestroyServersRequest
query-parameters:
server_id: optional<string>
datacenter: optional<string>
pool: optional<localCommons.PoolType>
public_ip: optional<string>

types:
ListServersResponse:
Expand Down
52 changes: 52 additions & 0 deletions lib/bolt/cli/src/commands/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ pub enum SubCommand {
#[clap(long)]
ip: Option<String>,
},
/// Destroy servers in a cluster
Destroy {
/// The name id of the cluster
#[clap(index = 1)]
cluster: String,
#[clap(long)]
server_id: Option<String>,
#[clap(long, short = 'p')]
pool: Option<String>,
#[clap(long, short = 'd')]
datacenter: Option<String>,
#[clap(long)]
ip: Option<String>,
},
/// SSH in to a server in the cluster
Ssh {
/// The name id of the cluster
Expand Down Expand Up @@ -140,6 +154,44 @@ impl SubCommand {
)
.await?;
}
Self::Destroy {
cluster: cluster_name_id,
server_id,
pool,
datacenter,
ip,
} => {
let cloud_config = ctx.openapi_config_cloud().await?;

// Look up cluster
let clusters = admin_clusters_api::admin_clusters_list(&cloud_config)
.await?
.clusters;
let cluster = clusters.iter().find(|c| c.name_id == cluster_name_id);
let cluster = match cluster {
Some(c) => c,
None => bail!("cluster with the name id {} not found", cluster_name_id),
};

// Destroy servers
let pool_type = pool
.map(|p| match p.as_str() {
"job" => Ok(models::AdminClustersPoolType::Job),
"gg" => Ok(models::AdminClustersPoolType::Gg),
"ats" => Ok(models::AdminClustersPoolType::Ats),
_ => Err(anyhow!("invalid pool type")),
})
.transpose()?;
admin_clusters_servers_api::admin_clusters_servers_destroy(
&cloud_config,
&cluster.cluster_id.to_string(),
server_id.as_deref(),
datacenter.as_deref(),
pool_type,
ip.as_deref(),
)
.await?;
}
Self::Ssh {
cluster: cluster_name_id,
command,
Expand Down
7 changes: 7 additions & 0 deletions sdks/full/go/admin/clusters/servers.go

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

92 changes: 92 additions & 0 deletions sdks/full/go/admin/clusters/servers/client.go

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

1 change: 1 addition & 0 deletions sdks/full/go/types.go

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

75 changes: 75 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.

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

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

1 change: 1 addition & 0 deletions sdks/full/rust-cli/README.md

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

Loading

0 comments on commit 4ff616b

Please sign in to comment.