Skip to content

Commit

Permalink
Add instance create options for compute and storage size (#1137)
Browse files Browse the repository at this point in the history
The new `--compute-size` and `--storage-size` options allow specifying
the amount of compute and storage respectively.  The new `--free-tier`
(exclusive with `...-size`) can be used to explicitly request a Free
tier instance.
  • Loading branch information
elprans authored Oct 11, 2023
1 parent 72cc74d commit 97e845f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/cloud/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,20 @@ pub struct Version {
pub version: String,
}

#[derive(Debug, serde::Serialize)]
pub struct CloudInstanceResourceRequest {
pub name: String,
pub value: u16,
}

#[derive(Debug, serde::Serialize)]
pub struct CloudInstanceCreate {
pub name: String,
pub org: String,
pub version: String,
pub region: Option<String>,
pub requested_resources: Option<Vec<CloudInstanceResourceRequest>>,
pub tier: Option<String>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub default_database: Option<String>,
// #[serde(skip_serializing_if = "Option::is_none")]
Expand Down
53 changes: 51 additions & 2 deletions src/portable/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,57 @@ fn create_cloud(cmd: &Create, org_slug: &str, name: &str, client: &cloud::client
)?;

let server_ver = cloud::versions::get_version(&query, client)?;
let tier = if cmd.free_tier {
String::from("Free")
} else {
String::from("Pro")
};

let compute_size = cmd.compute_size.unwrap_or(1);
let storage_size = cmd.storage_size.unwrap_or(20);

let req_resources = match cmd.free_tier {
true => {
None
},
false => {
Some(vec![
cloud::ops::CloudInstanceResourceRequest{
name: "compute".to_string(),
value: compute_size,
},
cloud::ops::CloudInstanceResourceRequest{
name: "storage".to_string(),
value: storage_size,
},
])
},
};

let resources_display = if req_resources.is_some() {
format!(
"\nCompute Size: {} compute unit{}\
\nStorage Size: {} gigabyte{}",
compute_size,
if compute_size == 1 {""} else {"s"},
storage_size,
if storage_size == 1 {""} else {"s"},
)
} else {
format!(
"\nCompute Size: 1/4 compute units\
\nStorage Size: 1 gigabyte",
)
};

if !cmd.non_interactive && !question::Confirm::new(format!(
"This will create a new EdgeDB cloud instance with the following parameters: \
\n\n Region: {region}\n Server Version: {server_ver}\nIs this acceptable?",
"This will create a new EdgeDB cloud instance with the following parameters:\
\n\
\nTier: {tier}\
\nRegion: {region}\
\nServer Version: {server_ver}\
{resources_display}\
\n\nIs this acceptable?",
)).ask()? {
return Ok(());
}
Expand All @@ -203,6 +250,8 @@ fn create_cloud(cmd: &Create, org_slug: &str, name: &str, client: &cloud::client
org: org_slug.to_string(),
version: server_ver.to_string(),
region: Some(region),
requested_resources: req_resources,
tier: Some(tier),
};
cloud::ops::create_cloud_instance(&client, &request)?;
echo!(
Expand Down
14 changes: 14 additions & 0 deletions src/portable/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ pub struct Create {
#[clap(long)]
pub region: Option<String>,

/// Request a free tier instance.
#[clap(long, conflicts_with_all=&["compute_size", "storage_size"])]
pub free_tier: bool,

/// The size of compute to be allocated for the Cloud instance in
/// Compute Units.
#[clap(long, value_name="number")]
pub compute_size: Option<u16>,

/// The size of storage to be allocated for the Cloud instance in
/// Gigabytes.
#[clap(long, value_name="GiB")]
pub storage_size: Option<u16>,

/// Deprecated parameter, unused.
#[clap(long, hide=true, possible_values=&["auto", "manual"][..])]
pub start_conf: Option<StartConf>,
Expand Down
7 changes: 6 additions & 1 deletion src/portable/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct Unlink {
#[clap(long, value_hint=ValueHint::DirPath)]
pub project_dir: Option<PathBuf>,

/// If specified, the associated EdgeDB instance is destroyed
/// If specified, the associated EdgeDB instance is destroyed
/// using `edgedb instance destroy`.
#[clap(long, short='D')]
pub destroy_server_instance: bool,
Expand Down Expand Up @@ -690,6 +690,9 @@ fn do_init(name: &str, pkg: &PackageInfo,
channel: q.cli_channel(),
version: q.version,
region: None,
free_tier: false,
compute_size: None,
storage_size: None,
port: Some(port),
start_conf: None,
default_database: "edgedb".into(),
Expand Down Expand Up @@ -769,6 +772,8 @@ fn do_cloud_init(
org: org.clone(),
version: version.to_string(),
region: None,
tier: None,
requested_resources: None,
};
crate::cloud::ops::create_cloud_instance(client, &request)?;
let full_name = format!("{}/{}", org, name);
Expand Down

0 comments on commit 97e845f

Please sign in to comment.