Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add feature publicip #5

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
19 changes: 19 additions & 0 deletions .changelog/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:feature
`publicip` - Add List, Create, Delete operations for publicip.
```

```release-note:feature
`s3` - Add List, Create, Delete operations for s3.
```

```release-note:feature
`vdc` - Add List, Create, Delete operations for vdc.
```

```release-note:feature
`edgegateway` - Add List, Create, Delete operations for edgegateway.
```

```release-note:dependency
deps: bumps orange-cloudavenue/cloudavenue-sdk-go from 0.5.5 to 0.5.6
```
25 changes: 12 additions & 13 deletions cmd/edgegateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"log"

jsontmpl "github.com/orange-cloudavenue/cloudavenue-cli/pkg/templates/json"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,11 +33,11 @@ func init() {
gwCreateCmd.PersistentFlags().String("vdc", "", "vdc name")
gwCreateCmd.PersistentFlags().String("t0", "", "t0 name")
if err := gwCreateCmd.MarkPersistentFlagRequired("vdc"); err != nil {
log.Default().Println("Error from Flag VDC, is require.", err)
fmt.Println("Error from Flag VDC, is require.", err)
return
}
if err := gwCreateCmd.MarkPersistentFlagRequired("t0"); err != nil {
log.Default().Println("Error from Flag T0, is require.", err)
fmt.Println("Error from Flag T0, is require.", err)
return
}
}
Expand All @@ -51,7 +50,7 @@ var gwListCmd = &cobra.Command{

edgeGateways, err := c.V1.EdgeGateway.List()
if err != nil {
log.Default().Println("Error from EdgeGateway", err)
fmt.Println("Error from EdgeGateway", err)
}

jsontmpl.Format(jsontmpl.JsonTemplate{
Expand All @@ -76,22 +75,22 @@ var gwDelCmd = &cobra.Command{
if err != nil {
gw, err = c.V1.EdgeGateway.GetByID(arg)
if err != nil {
log.Default().Println("Unable to find EdgeGateway ID or Name", err)
fmt.Println("Unable to find EdgeGateway ID or Name", err)
return
}
}
job, err := gw.Delete()
if err != nil {
log.Default().Println("Unable to delete EdgeGateway", err)
fmt.Println("Unable to delete EdgeGateway", err)
return
}
err = job.Wait(15, 300)
if err != nil {
log.Default().Println("Error during EdgeGateway Deletion !!", err)
fmt.Println("Error during EdgeGateway Deletion !!", err)
return
}
fmt.Println("EdgeGateway resource deleted " + arg + " successfully !!\n")
fmt.Println("EdgeGateway resource list after deletion:")
fmt.Println("EdgeGateway resource deleted " + arg + " successfully !!")
fmt.Println("\nEdgeGateway resource list after deletion:")
gwListCmd.Run(cmd, []string{})
}

Expand All @@ -109,14 +108,14 @@ var gwCreateCmd = &cobra.Command{
// Get the vdc name from the command line
vdc, err := cmd.Flags().GetString("vdc")
if err != nil {
log.Default().Println("Error from VDC", err)
fmt.Println("Error from VDC", err)
return
}

// Get the t0 name from the command line
t0, err := cmd.Flags().GetString("t0")
if err != nil {
log.Default().Println("Error from T0", err)
fmt.Println("Error from T0", err)
return
}

Expand All @@ -126,12 +125,12 @@ var gwCreateCmd = &cobra.Command{
fmt.Println("t0 name: " + t0)
job, err := c.V1.EdgeGateway.New(vdc, t0)
if err != nil {
log.Default().Println("Error from EdgeGateway", err)
fmt.Println("Error from EdgeGateway", err)
return
}
err = job.Wait(15, 300)
if err != nil {
log.Default().Println("Error during EdgeGateway Creation !!", err)
fmt.Println("Error during EdgeGateway Creation !!", err)
return
}
fmt.Println("EdgeGateway resource created successfully !")
Expand Down
146 changes: 146 additions & 0 deletions cmd/publicip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

jsontmpl "github.com/orange-cloudavenue/cloudavenue-cli/pkg/templates/json"
"github.com/spf13/cobra"
)

// publicipCmd represents the vdc command
var publicipCmd = &cobra.Command{
Use: "publicip",
Example: "publicip <list | create | delete>",
Short: "Option to manage your public ip on CloudAvenue.",
}

func init() {
rootCmd.AddCommand(publicipCmd)

// ? List command
publicipCmd.Args = cobra.NoArgs
publicipCmd.AddCommand(publicipListCmd)

// ? Delete command
publicipCmd.AddCommand(publicipDelCmd)
publicipDelCmd.Args = cobra.MinimumNArgs(1)

// ? Create command
publicipCmd.AddCommand(publicipCreateCmd)
publicipCreateCmd.PersistentFlags().String("name", "", "edge gateway name")
if err := publicipCreateCmd.MarkPersistentFlagRequired("name"); err != nil {
fmt.Println("Error from Flag name, is require.", err)
return
}
}

// listCmd represents the list command
var publicipListCmd = &cobra.Command{
Use: "list",
Short: "A brief list of your publicip resources",
Run: func(cmd *cobra.Command, args []string) {

// Get the list of vdc
ips, err := c.V1.PublicIP.GetIPs()
if err != nil {
fmt.Println("Error from IP List", err)
return
}

// Struct to print a basic view
type basicIP = struct {
IP string `json:"ip"`
IPnat string `json:"ip_nat"`
EdgeGatewayName string `json:"edge_gateway_name"`
}
basicIPs := []*basicIP{}

// Set the struct
for _, ip := range ips.NetworkConfig {
x := &basicIP{
IP: ip.UplinkIP,
IPnat: ip.TranslatedIP,
EdgeGatewayName: ip.EdgeGatewayName,
}
basicIPs = append(basicIPs, x)
}

// Print the result
jsontmpl.Format(jsontmpl.JsonTemplate{
Fields: []string{"ip", "ip_nat", "edge_gateway_name"},
Data: basicIPs,
})
},
}

// deleteCmd represents the delete command
var publicipDelCmd = &cobra.Command{
Use: "delete",
Example: "publicip delete <ip> [<ip>] [<ip>] ...",
Short: "Delete publicip resource(s)",

Run: func(cmd *cobra.Command, args []string) {

for _, arg := range args {
fmt.Println("delete publicip resource " + arg)
ip, err := c.V1.PublicIP.GetIP(arg)
if err != nil {
fmt.Println("Error from ip: ", err)
return
}
job, err := ip.Delete()
if err != nil {
fmt.Println("Unable to delete ip: ", err)
return
}
err = job.Wait(15, 300)
if err != nil {
fmt.Println("Error during ip Deletion !!", err)
return
}
fmt.Println("ip resource deleted " + arg + " successfully !!")
fmt.Println("\nip resource list after deletion:")
publicipListCmd.Run(cmd, []string{})
}

},
}

// createCmd represents the create command
var publicipCreateCmd = &cobra.Command{
Use: "create",
Short: "Create an ip",
Example: "ip create --name <edgegateway name>",

Run: func(cmd *cobra.Command, args []string) {

// Get the name from the command line
gwName, err := cmd.Flags().GetString("name")
if err != nil {
fmt.Println("Malformed argument EdgeGateway Name ", err)
return
}

// Create a public ip
fmt.Println("create public ip resource")
fmt.Println("for EdgeGateway name: " + gwName)

job, err := c.V1.PublicIP.New(gwName)
if err != nil {
fmt.Println("Unable to create public ip", err)
return
}
err = job.Wait(5, 300)
if err != nil {
fmt.Println("Error during public ip creation !!", err)
return
}
fmt.Println("public ip resource created successfully !")
fmt.Println("\npublic ip resource list after creation:")
publicipListCmd.Run(cmd, []string{})

},
}
15 changes: 7 additions & 8 deletions cmd/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/service/s3"
jsontmpl "github.com/orange-cloudavenue/cloudavenue-cli/pkg/templates/json"
Expand Down Expand Up @@ -35,7 +34,7 @@ func init() {
s3Cmd.AddCommand(s3CreateCmd)
s3CreateCmd.PersistentFlags().String("name", "", "s3 bucket name")
if err := s3CreateCmd.MarkPersistentFlagRequired("name"); err != nil {
log.Default().Println("Error from Flag name, is require.", err)
fmt.Println("Error from Flag name, is require.", err)
return
}
}
Expand All @@ -52,7 +51,7 @@ var s3ListCmd = &cobra.Command{
// Get the list of buckets
output, err := s3Client.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
log.Default().Println("Error from S3 List", err)
fmt.Println("Error from S3 List", err)
return
}

Expand Down Expand Up @@ -96,11 +95,11 @@ var s3DelCmd = &cobra.Command{
// Del the bucket
_, err := s3Client.DeleteBucket(&s3.DeleteBucketInput{Bucket: &args[i]})
if err != nil {
log.Default().Println("Error from S3 Delete", err)
fmt.Println("Error from S3 Delete", err)
return
}
fmt.Println("Bucket resource deleted " + arg + " successfully !!\n")
fmt.Println("Bucket resource list after deletion:")
fmt.Println("Bucket resource deleted " + arg + " successfully !!")
fmt.Println("\nBucket resource list after deletion:")
}
s3ListCmd.Run(cmd, []string{})

Expand All @@ -120,7 +119,7 @@ var s3CreateCmd = &cobra.Command{

bucketName, err := cmd.Flags().GetString("name")
if err != nil {
log.Default().Println("Unknow bucket name ", err)
fmt.Println("Malformed bucket name ", err)
return
}

Expand All @@ -130,7 +129,7 @@ var s3CreateCmd = &cobra.Command{

_, err = s3Client.CreateBucket(&s3.CreateBucketInput{Bucket: &bucketName})
if err != nil {
log.Default().Println("Error from S3 Create", err)
fmt.Println("Error from S3 Create", err)
return
}

Expand Down
19 changes: 9 additions & 10 deletions cmd/vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"log"

jsontmpl "github.com/orange-cloudavenue/cloudavenue-cli/pkg/templates/json"
v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1"
Expand Down Expand Up @@ -34,7 +33,7 @@ func init() {
vdcCmd.AddCommand(vdcCreateCmd)
vdcCreateCmd.PersistentFlags().String("name", "", "vdc name")
if err := vdcCreateCmd.MarkPersistentFlagRequired("name"); err != nil {
log.Default().Println("Error from Flag name, is require.", err)
fmt.Println("Error from Flag name, is require.", err)
return
}
}
Expand All @@ -48,7 +47,7 @@ var vdcListCmd = &cobra.Command{
// Get the list of vdc
vdcs, err := c.V1.VDC.List()
if err != nil {
log.Default().Println("Error from VDC List", err)
fmt.Println("Error from VDC List", err)
return
}

Expand Down Expand Up @@ -96,21 +95,21 @@ var vdcDelCmd = &cobra.Command{
fmt.Println("delete vdc resource " + arg)
vdc, err := c.V1.VDC.Get(arg)
if err != nil {
log.Default().Println("Error from vdc", err)
fmt.Println("Error from vdc", err)
return
}
job, err := vdc.Delete()
if err != nil {
log.Default().Println("Unable to delete vdc", err)
fmt.Println("Unable to delete vdc", err)
return
}
err = job.Wait(15, 300)
if err != nil {
log.Default().Println("Error during vdc Deletion !!", err)
fmt.Println("Error during vdc Deletion !!", err)
return
}
fmt.Println("vdc resource deleted " + arg + " successfully !!\n")
fmt.Println("vdc resource list after deletion:")
fmt.Println("vdc resource deleted " + arg + " successfully !!")
fmt.Println("\nvdc resource list after deletion:")
vdcListCmd.Run(cmd, []string{})
}

Expand All @@ -128,7 +127,7 @@ var vdcCreateCmd = &cobra.Command{
// Get the vdc name from the command line
vdcName, err := cmd.Flags().GetString("vdc")
if err != nil {
log.Default().Println("Unknow VDC ", err)
fmt.Println("Malformed VDC name", err)
return
}

Expand Down Expand Up @@ -156,7 +155,7 @@ var vdcCreateCmd = &cobra.Command{
}})

if err != nil {
log.Default().Println("Error from vdc", err)
fmt.Println("Error from vdc", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.3
require (
github.com/aws/aws-sdk-go v1.47.9
github.com/fbiville/markdown-table-formatter v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.5
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.6
github.com/spf13/cobra v1.8.0
)

Expand Down
Loading
Loading