-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,533 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
/target | ||
Cargo.lock | ||
|
||
.env | ||
.ignore | ||
examples/playground.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<div align="center"> | ||
<h1>neolite</h1> | ||
|
||
NEO Lite SDK. | ||
|
||
<a href="https://github.com/BiznetGIO/neolite/actions/workflows/ci.yml"> | ||
<img src="https://github.com/BiznetGIO/neolite/actions/workflows/ci.yml/badge.svg"> | ||
</a> | ||
<a href="https://crates.io/crates/neolite"> | ||
<img src="https://img.shields.io/crates/v/neolite.svg"> | ||
</a> | ||
|
||
</div> | ||
|
||
--- | ||
|
||
The `neolite` SDK makes it easy to work with Biznet Gio's [NEO Lite](https://www.biznetgio.com/product/neo-lite) service. With NEO Lite SDK, developers can effortlessly manage and control their VPS instances for hosting websites and applications. | ||
|
||
## Usage | ||
|
||
```rust | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let url = "https://api.portal.biznetgio.dev/v1/neolites".parse::<http::Uri>()?; | ||
let token = env::var("TOKEN").context("TOKEN env not found.")?; | ||
|
||
let config = Config::new(url, &token); | ||
let client = Client::new(config)?; | ||
|
||
let keypair = Lite::new(client).keypair().await?; | ||
let key = keypair.create("gandalf0").await?; | ||
println!("{}", key.name); | ||
Ok(()) | ||
} | ||
``` | ||
|
||
To learn more, see other [examples](/examples). | ||
|
||
## Development | ||
|
||
```bash | ||
git clone https://github.com/BiznetGIO/neolite | ||
cd neolite | ||
|
||
# Run unit tests and integration tests | ||
cargo test | ||
``` | ||
|
||
## Contributing | ||
|
||
To learn more read the [contributing guide](docs/dev/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[files] | ||
extend-exclude = ["CHANGELOG.md"] | ||
extend-exclude = ["CHANGELOG.md", "playground.rs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Guide | ||
|
||
## Common workflow | ||
|
||
- Create NEO Lite Virtual Machine. | ||
- Check available products `product.list()`. | ||
- Select preferred product `product.get(1538)`. | ||
- Select preferred billing cycle `product_resource.get_billing("Monthly")`. | ||
- Check IP availability `ip.is_available()`. | ||
- Select preferred OS `os.get(1001)`. | ||
- Create or Select existing keypair `keypair.create("gandalf0")`. | ||
- Create a virtual Machine `lite.create()`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TOKEN='eyJhbG...' | ||
VM_ID=123 | ||
PRODUCT_ID=123 | ||
KEYPAIR_ID=123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Examples | ||
|
||
Sorted by dependency order. | ||
|
||
1. Keypair | ||
2. Product | ||
3. Virtual Machine (vm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#![allow(dead_code)] | ||
use std::env; | ||
|
||
use anyhow::Context; | ||
use neolite::{client::Client, config::Config, lite::Lite, snapshot::SnapshotOpts}; | ||
|
||
async fn create(client: Client, vm_id: u32) -> anyhow::Result<()> { | ||
let lite = Lite::new(client); | ||
|
||
// (1) Select preferred billing cycle | ||
let product = lite.plan().await?; | ||
let product_resource = product.get_vm(1538).await?; | ||
let billing_resource = product_resource.get_billing("Monthly").await?; | ||
println!( | ||
"::: Billing. label: {}, price: {}", | ||
billing_resource.label, billing_resource.price, | ||
); | ||
|
||
// (2) Create a virtual machine snapshot | ||
let snapshot = lite.snapshot().await?; | ||
let opts = SnapshotOpts { | ||
billing: billing_resource, | ||
use_credit_card: false, | ||
promocode: None, | ||
}; | ||
let billing_resource = snapshot | ||
.create( | ||
vm_id, | ||
"snapshot-from-sdk".to_string(), | ||
Some("Snapshot from SDK".to_string()), | ||
&opts, | ||
) | ||
.await?; | ||
println!( | ||
"::: Snapshot. account id: {}, order id: {}", | ||
billing_resource.account_id, billing_resource.order_id | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn restore_with(client: Client) -> anyhow::Result<()> { | ||
let lite = Lite::new(client); | ||
|
||
// (1) Select preferred plan | ||
// let resource = plan.list().await?; | ||
let plan = lite.plan().await?; | ||
let plan_resource = plan.get_vm(1538).await?; | ||
println!( | ||
"::: plan. id: {}, name: {}", | ||
plan_resource.id, plan_resource.name, | ||
); | ||
|
||
// (2) Select preferred billing cycle | ||
let billing_resource = plan_resource.get_billing("Monthly").await?; | ||
println!( | ||
"::: Billing. label: {}, price: {}", | ||
billing_resource.label, billing_resource.price, | ||
); | ||
|
||
// (3) Create or Select existing keypair | ||
let keypair = lite.keypair().await?; | ||
let keypair_resource = keypair.create("gandalf0").await?; | ||
println!( | ||
"::: Keypair. id: {}, name: {}", | ||
keypair_resource.id, keypair_resource.name, | ||
); | ||
|
||
// (4) Create a virtual machine snapshot | ||
let snapshot = lite.snapshot().await?; | ||
let opts = neolite::snapshot::RestoreVirtualMachineOptions { | ||
plan: plan_resource, | ||
keypair: keypair_resource, | ||
billing: billing_resource, | ||
use_credit_card: false, | ||
promocode: None, | ||
}; | ||
let snapshot_id = 123; | ||
let billing_resource = snapshot | ||
.restore_with( | ||
snapshot_id, | ||
"thorin-os2".to_string(), | ||
Some("Thorin Virtual Machine".to_string()), | ||
"thethorin".to_string(), | ||
"SpeakFriendAndEnter123".to_string(), | ||
&opts, | ||
) | ||
.await?; | ||
println!( | ||
"::: VM created. account id: {}, order id: {}", | ||
billing_resource.account_id, billing_resource.order_id | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
env_logger::init(); | ||
dotenvy::from_filename("./examples/.env")?; | ||
|
||
let url = "https://api.portal.biznetgio.dev/v1/neolites".parse::<http::Uri>()?; | ||
let token = env::var("TOKEN").context("TOKEN env not found.")?; | ||
let id = env::var("VM_ID").context("VM_ID env not found.")?; | ||
let id: u32 = id.parse()?; | ||
|
||
let config = Config::new(url, &token); | ||
let client = Client::new(config)?; | ||
|
||
create(client, id).await?; | ||
// restore_with(client).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use std::env; | ||
|
||
use anyhow::Context; | ||
use neolite::{client::Client, config::Config, lite::Lite, vm::VirtualMachineOptions}; | ||
|
||
async fn create(client: Client) -> anyhow::Result<()> { | ||
let lite = Lite::new(client); | ||
|
||
// (1) Select preferred plan | ||
// let resource = plan.list().await?; | ||
let plan = lite.plan().await?; | ||
let plan_resource = plan.get_vm(1538).await?; | ||
println!( | ||
"::: plan. id: {}, name: {}", | ||
plan_resource.id, plan_resource.name, | ||
); | ||
|
||
// (2) Select preferred billing cycle | ||
let billing_resource = plan_resource.get_billing("Monthly").await?; | ||
println!( | ||
"::: Billing. label: {}, price: {}", | ||
billing_resource.label, billing_resource.price, | ||
); | ||
|
||
// (3) Check IP availability | ||
let ip = plan_resource.ip().await?; | ||
let is_ip_available = ip.is_available().await?; | ||
if !is_ip_available { | ||
return Err(anyhow::anyhow!("IP is not available")); | ||
} | ||
println!("::: IP availability: {}", is_ip_available); | ||
|
||
// (4) Select preferred OS | ||
let os = plan_resource.os().await?; | ||
// let oses = os.list().await?; | ||
let os_resource = os.get(1001).await?; | ||
println!("::: OS. id: {}, name: {}", os_resource.id, os_resource.name); | ||
|
||
// (5) Create or Select existing keypair | ||
let keypair = lite.keypair().await?; | ||
let keypair_resource = keypair.create("gandalf0").await?; | ||
println!( | ||
"::: Keypair. id: {}, name: {}", | ||
keypair_resource.id, keypair_resource.name, | ||
); | ||
|
||
// (6) Create a virtual Machine | ||
let vm = lite.vm().await?; | ||
let opts = VirtualMachineOptions { | ||
plan: plan_resource, | ||
os: os_resource, | ||
keypair: keypair_resource, | ||
billing: billing_resource, | ||
use_credit_card: false, | ||
promocode: None, | ||
}; | ||
let billing_resource = vm | ||
.create( | ||
"thorin-os2".to_string(), | ||
Some("Thorin Virtual Machine".to_string()), | ||
"thethorin".to_string(), | ||
"SpeakFriendAndEnter123".to_string(), | ||
&opts, | ||
) | ||
.await?; | ||
println!( | ||
"::: NeoLite VM. account id: {}, order id: {}", | ||
billing_resource.account_id, billing_resource.order_id | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
env_logger::init(); | ||
dotenvy::from_filename("./examples/.env")?; | ||
|
||
let url = "https://api.portal.biznetgio.dev/v1/neolites".parse::<http::Uri>()?; | ||
let token = env::var("TOKEN").context("TOKEN env not found.")?; | ||
let config = Config::new(url, &token); | ||
|
||
let client = Client::new(config)?; | ||
create(client).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#![allow(dead_code)] | ||
use std::env; | ||
|
||
use anyhow::Context; | ||
use neolite::{client::Client, config::Config, keypair::Keypair, lite::Lite}; | ||
|
||
async fn list(keypair: Keypair) -> anyhow::Result<()> { | ||
let keys = keypair.list().await?; | ||
for key in keys { | ||
println!("{}: {}", key.id, key.name); | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn get(keypair: Keypair, id: u32) -> anyhow::Result<()> { | ||
let key = keypair.get(id).await?; | ||
println!("id: {}, name: {}", key.id, key.name); | ||
Ok(()) | ||
} | ||
|
||
async fn create(keypair: Keypair) -> anyhow::Result<()> { | ||
let key = keypair.create("gandalf0").await?; | ||
println!("{:?}", key); | ||
println!("{}", key.name); | ||
Ok(()) | ||
} | ||
|
||
async fn delete(keypair: Keypair, id: u32) -> anyhow::Result<()> { | ||
keypair.delete(id).await?; | ||
println!("::: Keypair deleted."); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
env_logger::init(); | ||
dotenvy::from_filename("./examples/.env")?; | ||
|
||
let url = "https://api.portal.biznetgio.dev/v1/neolites".parse::<http::Uri>()?; | ||
let token = env::var("TOKEN").context("TOKEN env not found.")?; | ||
let id = env::var("KEYPAIR_ID").context("KEYPAIR_ID env not found.")?; | ||
let id: u32 = id.parse()?; | ||
|
||
let config = Config::new(url, &token); | ||
let client = Client::new(config)?; | ||
let keypair = Lite::new(client).keypair().await?; | ||
|
||
// list(keypair).await?; | ||
// create(keypair).await?; | ||
get(keypair, id).await?; | ||
// delete(keypair, id).await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.