Initial commit

This commit is contained in:
2021-03-21 23:10:46 +01:00
commit 3144420a47
22 changed files with 2364 additions and 0 deletions

33
cloud/google_gce.go Normal file
View File

@@ -0,0 +1,33 @@
package gcp
import (
"google.golang.org/api/compute/v1"
)
// GetIPAddresses returns a list of external IP addresses used for the SHH connection
func (c *ComputeClient) GetIPAddresses(instances []*compute.Instance) []string {
addresses := []string{}
for _, instance := range instances {
addresses = append(addresses, instance.NetworkInterfaces[0].AccessConfigs[0].NatIP+":22")
}
return addresses
}
// GetInstances returns a list of external IP addresses used for the SHH connection
func (c *ComputeClient) GetInstances(filter string) ([]*compute.Instance, error) {
listCall := c.Instances.AggregatedList(c.Project)
listCall.Filter(filter)
list, err := listCall.Do()
if err != nil {
return nil, err
}
instances := []*compute.Instance{}
for _, item := range list.Items {
for _, instance := range item.Instances {
instances = append(instances, instance)
}
}
return instances, nil
}