From 182403cca806b6faabc7a967ceee55ea830e8f93 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 21 May 2024 13:11:25 -0400 Subject: [PATCH 1/7] node init --- node/node.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++ node/supported.go | 22 ++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 node/node.go create mode 100644 node/supported.go diff --git a/node/node.go b/node/node.go new file mode 100644 index 0000000..2e47c8b --- /dev/null +++ b/node/node.go @@ -0,0 +1,59 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +// SSHConfig contains the configuration for connecting to a node over SSH +type SSHConfig struct { + // Username to use when connecting to the nodeßß + User string + + // Path to the private key to use when connecting to the node + // If this is empty, the SSH agent will be used + KeyPath string + + // Parameters to pass to the ssh command. + // See man ssh_config(5) for more information + // By defalult it's StrictHostKeyChecking=no + Params map[string]string // additional parameters to pass to the ssh command +} + +// CloudConfig contains the configuration for deploying a node in the cloud +type CloudConfig struct { + // Cloud region to deploy the node in + Region string + + // Cloud image to use for the node. + // For AWS it's the AMI ID, for GCP it's the image name + Image string + + // Cloud key pair to use for the node + KeyPair string + + // Cloud security group to use for the node. + SecurityGroup string + + // Cloud type to deploy the node in + Cloud SupportedCloud + + // Cloud static IP assigned to the node + // It's empty if the node has ephemeral IP + ElasticIP string + + // Roles of the node + Roles []SupportedRole +} + +type Node struct { + // ID of the node + ID string + + // IP address of the node + IP string + + // SSH configuration for the node + SSHConfig SSHConfig + + // Cloud configuration for the node + CloudConfig CloudConfig +} diff --git a/node/supported.go b/node/supported.go new file mode 100644 index 0000000..e00a664 --- /dev/null +++ b/node/supported.go @@ -0,0 +1,22 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +type SupportedCloud int + +const ( + AWS SupportedCloud = iota + GCP + Docker // fake Cloud used for E2E tests +) + +type SupportedRole int + +const ( + Validator SupportedRole = iota + API + AWMRelayer +) + +// LoadTest and Monitor nodes are not supported yet From d397b1133ff80fff3bed8be9a99db4a05ccc12db Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 21 May 2024 13:58:34 -0400 Subject: [PATCH 2/7] user should be private to read --- node/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node.go b/node/node.go index 2e47c8b..fb0ef87 100644 --- a/node/node.go +++ b/node/node.go @@ -6,7 +6,7 @@ package node // SSHConfig contains the configuration for connecting to a node over SSH type SSHConfig struct { // Username to use when connecting to the nodeßß - User string + user string // Path to the private key to use when connecting to the node // If this is empty, the SSH agent will be used From 8384df9b146666d5eaf78ff61ff0bf8147dc6c6c Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 21 May 2024 14:08:17 -0400 Subject: [PATCH 3/7] add node operations: - create - destroy - exec - post --- node/create.go | 10 ++++++++++ node/destroy.go | 9 +++++++++ node/exec.go | 9 +++++++++ node/post.go | 9 +++++++++ 4 files changed, 37 insertions(+) create mode 100644 node/create.go create mode 100644 node/destroy.go create mode 100644 node/exec.go create mode 100644 node/post.go diff --git a/node/create.go b/node/create.go new file mode 100644 index 0000000..0d1ca04 --- /dev/null +++ b/node/create.go @@ -0,0 +1,10 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +// Create creates a new node. +// If wait is true, this function will block until the node is ready. +func Create(wait bool) (Node, error) { + return Node{}, nil +} diff --git a/node/destroy.go b/node/destroy.go new file mode 100644 index 0000000..d1f782e --- /dev/null +++ b/node/destroy.go @@ -0,0 +1,9 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +// Destoy destroys a node. +func Destoy(node Node) error { + return nil +} diff --git a/node/exec.go b/node/exec.go new file mode 100644 index 0000000..0dea0d8 --- /dev/null +++ b/node/exec.go @@ -0,0 +1,9 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +// Exec executes a command on a node. +func Exec(node Node, cmd string) error { + return nil +} diff --git a/node/post.go b/node/post.go new file mode 100644 index 0000000..beafe7c --- /dev/null +++ b/node/post.go @@ -0,0 +1,9 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +// Post sends a POST request to the node at the specified path with the provided body. +func Post(node Node, path string, body string) error { + return nil +} From ab7cef8137940f7f8fd9e9b4bf7bc84b2f465b34 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 21 May 2024 14:47:00 -0400 Subject: [PATCH 4/7] cloud spec configs --- node/cloud.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ node/create.go | 2 +- node/node.go | 31 ++++------------------------ 3 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 node/cloud.go diff --git a/node/cloud.go b/node/cloud.go new file mode 100644 index 0000000..1fe6f76 --- /dev/null +++ b/node/cloud.go @@ -0,0 +1,56 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +// CloudConfig contains the configuration for deploying a node in the cloud +type CloudConfig struct { + // Cloud region to deploy the node in + Region string + + // Cloud image to use for the node. + // For AWS it's the AMI ID, for GCP it's the image name + Image string + + // Cloud key pair to use for the node + KeyPair string + + // Cloud security group to use for the node. + SecurityGroup string + + // Cloud static IP assigned to the node + // It's empty if the node has ephemeral IP + ElasticIP string + + // Cloud instance type to use for the node + InstanceType string + + // Cloud specific configuration + CloudSpec interface{} +} + +// AWS specific configuration +type AWSSpec struct { + // AWS profile to use for the node + Profile string + + // AWS volume size in GB + VolumeSize int + + // AWS volume type + VolumeType string + + // AWS volume IOPS + VolumeIOPS int + + // AWS volume throughput + VolumeThroughput int +} + +type GCPSpec struct { + // GCP project to use for the node + Project string + + // GCP credentials to use for the node + Credentials string +} diff --git a/node/create.go b/node/create.go index 0d1ca04..1af35fb 100644 --- a/node/create.go +++ b/node/create.go @@ -5,6 +5,6 @@ package node // Create creates a new node. // If wait is true, this function will block until the node is ready. -func Create(wait bool) (Node, error) { +func Create(awsProfile string, wait bool) (Node, error) { return Node{}, nil } diff --git a/node/node.go b/node/node.go index fb0ef87..15862b4 100644 --- a/node/node.go +++ b/node/node.go @@ -18,32 +18,6 @@ type SSHConfig struct { Params map[string]string // additional parameters to pass to the ssh command } -// CloudConfig contains the configuration for deploying a node in the cloud -type CloudConfig struct { - // Cloud region to deploy the node in - Region string - - // Cloud image to use for the node. - // For AWS it's the AMI ID, for GCP it's the image name - Image string - - // Cloud key pair to use for the node - KeyPair string - - // Cloud security group to use for the node. - SecurityGroup string - - // Cloud type to deploy the node in - Cloud SupportedCloud - - // Cloud static IP assigned to the node - // It's empty if the node has ephemeral IP - ElasticIP string - - // Roles of the node - Roles []SupportedRole -} - type Node struct { // ID of the node ID string @@ -55,5 +29,8 @@ type Node struct { SSHConfig SSHConfig // Cloud configuration for the node - CloudConfig CloudConfig + Cloud SupportedCloud + + // Roles of the node + Roles []SupportedRole } From 882ff81e5d2957f78d34791ac2f331aa1a53f6df Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 21 May 2024 15:36:36 -0400 Subject: [PATCH 5/7] cloud spec for node --- node/cloud.go | 53 ++++++++++++++++++++++++------------------------ node/node.go | 3 +++ subnet/subnet.go | 3 +-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/node/cloud.go b/node/cloud.go index 1fe6f76..44c5469 100644 --- a/node/cloud.go +++ b/node/cloud.go @@ -3,32 +3,6 @@ package node -// CloudConfig contains the configuration for deploying a node in the cloud -type CloudConfig struct { - // Cloud region to deploy the node in - Region string - - // Cloud image to use for the node. - // For AWS it's the AMI ID, for GCP it's the image name - Image string - - // Cloud key pair to use for the node - KeyPair string - - // Cloud security group to use for the node. - SecurityGroup string - - // Cloud static IP assigned to the node - // It's empty if the node has ephemeral IP - ElasticIP string - - // Cloud instance type to use for the node - InstanceType string - - // Cloud specific configuration - CloudSpec interface{} -} - // AWS specific configuration type AWSSpec struct { // AWS profile to use for the node @@ -45,6 +19,21 @@ type AWSSpec struct { // AWS volume throughput VolumeThroughput int + + // AWS Elastic IP to use for the node + ElasticIP string + + // AWS security group to use for the node + SecurityGroup string + + // AWS Region to use for the node + Region string + + // AWS AMI id to use for the node + Image string + + // AWS Instance type to use for the node + InstanceType string } type GCPSpec struct { @@ -53,4 +42,16 @@ type GCPSpec struct { // GCP credentials to use for the node Credentials string + + // GCP static IP to use for the node + StaticIP string + + // GCP network label to use for the node + Network string + + // GCP Image to use for the node + Image string + + // GCP Instance type to use for the node + InstanceType string } diff --git a/node/node.go b/node/node.go index 15862b4..d455371 100644 --- a/node/node.go +++ b/node/node.go @@ -31,6 +31,9 @@ type Node struct { // Cloud configuration for the node Cloud SupportedCloud + //CloudConfig is the cloud specific configuration for the node + CloudConfig interface{} + // Roles of the node Roles []SupportedRole } diff --git a/subnet/subnet.go b/subnet/subnet.go index 6a42983..a2fae3b 100644 --- a/subnet/subnet.go +++ b/subnet/subnet.go @@ -3,5 +3,4 @@ package subnet -type Subnet struct { -} +type Subnet struct{} From aefadb756ddf6490cad79500090e5959c3d77ead Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 21 May 2024 15:45:06 -0400 Subject: [PATCH 6/7] refactor for cloud spec --- node/cloud.go | 32 +++++++++++++++++--------------- node/create.go | 2 +- node/node.go | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/node/cloud.go b/node/cloud.go index 44c5469..48f043e 100644 --- a/node/cloud.go +++ b/node/cloud.go @@ -3,6 +3,23 @@ package node +type CloudSpec struct { + CommonSpec + AWSSpec + GCPSpec +} + +type CommonSpec struct { + // Region to use for the node + Region string + + // Image to use for the node + Image string + + // Instance type to use for the node + InstanceType string +} + // AWS specific configuration type AWSSpec struct { // AWS profile to use for the node @@ -25,15 +42,6 @@ type AWSSpec struct { // AWS security group to use for the node SecurityGroup string - - // AWS Region to use for the node - Region string - - // AWS AMI id to use for the node - Image string - - // AWS Instance type to use for the node - InstanceType string } type GCPSpec struct { @@ -48,10 +56,4 @@ type GCPSpec struct { // GCP network label to use for the node Network string - - // GCP Image to use for the node - Image string - - // GCP Instance type to use for the node - InstanceType string } diff --git a/node/create.go b/node/create.go index 1af35fb..12abca2 100644 --- a/node/create.go +++ b/node/create.go @@ -5,6 +5,6 @@ package node // Create creates a new node. // If wait is true, this function will block until the node is ready. -func Create(awsProfile string, wait bool) (Node, error) { +func Create(cloudSpec CloudSpec, wait bool) (Node, error) { return Node{}, nil } diff --git a/node/node.go b/node/node.go index d455371..84613d3 100644 --- a/node/node.go +++ b/node/node.go @@ -31,7 +31,7 @@ type Node struct { // Cloud configuration for the node Cloud SupportedCloud - //CloudConfig is the cloud specific configuration for the node + // CloudConfig is the cloud specific configuration for the node CloudConfig interface{} // Roles of the node From 41739ee642beda86d8d0d6876564bc15d89e2743 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Fri, 24 May 2024 10:09:02 -0400 Subject: [PATCH 7/7] v2 --- node/cloud.go | 25 +++++++++++-------------- node/create.go | 2 +- node/destroy.go | 4 ++-- node/{post.go => net.go} | 7 +++++++ node/node.go | 2 +- node/supported.go | 4 ++-- 6 files changed, 24 insertions(+), 20 deletions(-) rename node/{post.go => net.go} (68%) diff --git a/node/cloud.go b/node/cloud.go index 48f043e..b214cfe 100644 --- a/node/cloud.go +++ b/node/cloud.go @@ -3,13 +3,13 @@ package node -type CloudSpec struct { - CommonSpec - AWSSpec - GCPSpec +type CloudParams struct { + CommonParams + AWSParams + GCPParams } -type CommonSpec struct { +type CommonParams struct { // Region to use for the node Region string @@ -18,10 +18,13 @@ type CommonSpec struct { // Instance type to use for the node InstanceType string + + // Static IP to use for the node + StaticIP string } -// AWS specific configuration -type AWSSpec struct { +// AWS Paramsific configuration +type AWSParams struct { // AWS profile to use for the node Profile string @@ -37,23 +40,17 @@ type AWSSpec struct { // AWS volume throughput VolumeThroughput int - // AWS Elastic IP to use for the node - ElasticIP string - // AWS security group to use for the node SecurityGroup string } -type GCPSpec struct { +type GCPParams struct { // GCP project to use for the node Project string // GCP credentials to use for the node Credentials string - // GCP static IP to use for the node - StaticIP string - // GCP network label to use for the node Network string } diff --git a/node/create.go b/node/create.go index 12abca2..388bbda 100644 --- a/node/create.go +++ b/node/create.go @@ -5,6 +5,6 @@ package node // Create creates a new node. // If wait is true, this function will block until the node is ready. -func Create(cloudSpec CloudSpec, wait bool) (Node, error) { +func Create(CloudParams CloudParams, waitForSSH bool) (Node, error) { return Node{}, nil } diff --git a/node/destroy.go b/node/destroy.go index d1f782e..f356746 100644 --- a/node/destroy.go +++ b/node/destroy.go @@ -3,7 +3,7 @@ package node -// Destoy destroys a node. -func Destoy(node Node) error { +// Destroy destroys a node. +func Destroy(node Node) error { return nil } diff --git a/node/post.go b/node/net.go similarity index 68% rename from node/post.go rename to node/net.go index beafe7c..a6f188f 100644 --- a/node/post.go +++ b/node/net.go @@ -3,6 +3,13 @@ package node +import "net" + +// Connect returns the connection to the node. +func Connect(node Node) (*net.Conn, error) { + return nil, nil +} + // Post sends a POST request to the node at the specified path with the provided body. func Post(node Node, path string, body string) error { return nil diff --git a/node/node.go b/node/node.go index 84613d3..74b700c 100644 --- a/node/node.go +++ b/node/node.go @@ -5,7 +5,7 @@ package node // SSHConfig contains the configuration for connecting to a node over SSH type SSHConfig struct { - // Username to use when connecting to the nodeßß + // Username to use when connecting to the node user string // Path to the private key to use when connecting to the node diff --git a/node/supported.go b/node/supported.go index e00a664..6bdf736 100644 --- a/node/supported.go +++ b/node/supported.go @@ -6,8 +6,8 @@ package node type SupportedCloud int const ( - AWS SupportedCloud = iota - GCP + AWSCloud SupportedCloud = iota + GCPCloud Docker // fake Cloud used for E2E tests )