Skip to content

Commit

Permalink
feat: Add publicip feature
Browse files Browse the repository at this point in the history
  • Loading branch information
David MICHENEAU committed Nov 23, 2023
1 parent b25a7e2 commit e7dde53
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 79 deletions.
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
64 changes: 20 additions & 44 deletions cmd/publicip.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 All @@ -31,9 +30,9 @@ func init() {

// ? Create command
publicipCmd.AddCommand(publicipCreateCmd)
publicipCreateCmd.PersistentFlags().String("name", "", "vdc name")
publicipCreateCmd.PersistentFlags().String("name", "", "edge gateway name")
if err := publicipCreateCmd.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 @@ -47,7 +46,7 @@ var publicipListCmd = &cobra.Command{
// Get the list of vdc
ips, err := c.V1.PublicIP.GetIPs()
if err != nil {
log.Default().Println("Error from IP List", err)
fmt.Println("Error from IP List", err)
return
}

Expand Down Expand Up @@ -80,7 +79,7 @@ var publicipListCmd = &cobra.Command{
// deleteCmd represents the delete command
var publicipDelCmd = &cobra.Command{
Use: "delete",
Example: "publicip delete <name> [<name>] [<name>] ...",
Example: "publicip delete <ip> [<ip>] [<ip>] ...",
Short: "Delete publicip resource(s)",

Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -89,21 +88,21 @@ var publicipDelCmd = &cobra.Command{
fmt.Println("delete publicip resource " + arg)
ip, err := c.V1.PublicIP.GetIP(arg)
if err != nil {
log.Default().Println("Error from ip", err)
fmt.Println("Error from ip: ", err)
return
}
job, err := ip.Delete()
if err != nil {
log.Default().Println("Unable to delete ip", err)
fmt.Println("Unable to delete ip: ", err)
return
}
err = job.Wait(15, 300)
if err != nil {
log.Default().Println("Error during ip Deletion !!", err)
fmt.Println("Error during ip Deletion !!", err)
return
}
fmt.Println("ip resource deleted " + arg + " successfully !!\n")
fmt.Println("ip resource list after deletion:")
fmt.Println("ip resource deleted " + arg + " successfully !!")
fmt.Println("\nip resource list after deletion:")
publicipListCmd.Run(cmd, []string{})
}

Expand All @@ -121,49 +120,26 @@ var publicipCreateCmd = &cobra.Command{
// Get the name from the command line
gwName, err := cmd.Flags().GetString("name")
if err != nil {
log.Default().Println("Malformed EdgeGateway Name ", err)
fmt.Println("Malformed argument EdgeGateway Name ", err)
return
}

// // Get EdgeGateway from name
// gw, err := c.V1.EdgeGateway.GetByName(gwName)
// if err != nil {
// log.Default().Println("EdgeGateway not found", err)
// return
// }

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

// c.V1.EdgeGateway.

// _, err = c.V1.VDC.New(&v1.CAVVirtualDataCenter{Vdc: v1.CAVVirtualDataCenterVDC{
// Name: vdcName,
// ServiceClass: "STD",
// BillingModel: "PAYG",
// CPUAllocated: 22000,
// VcpuInMhz2: 2200,
// Description: "vdc created by cloudavenue-cli",
// MemoryAllocated: 30,
// DisponibilityClass: "ONE-ROOM",
// StorageBillingModel: "PAYG",
// StorageProfiles: []v1.VDCStrorageProfile{
// v1.VDCStrorageProfile{ //nolint
// Class: "gold",
// Limit: 500,
// Default: true,
// },
// },
// }})

job, err := c.V1.PublicIP.New(gwName)
if err != nil {
log.Default().Println("Error from vdc", err)
fmt.Println("Unable to create public ip", err)
return
}

fmt.Println("vdc resource created successfully !")
fmt.Println("\nvdc resource list after creation:")
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{})

},
Expand Down
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("Malformed VDC name", 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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.5 h1:/GzeWP+RPyiRBNsvnswq1HfMDWu12Ta1l5fnrRG/AMU=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.5/go.mod h1:cWQdAHu+UlpulY0Vv4i+yPG17PUp8ZhK06VOR5Oq8iM=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.6 h1:S2miIutUXVRB4UTY0zOXa3xZujKLtOqLUCAOYzweoDw=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.6/go.mod h1:cWQdAHu+UlpulY0Vv4i+yPG17PUp8ZhK06VOR5Oq8iM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
2 changes: 1 addition & 1 deletion release-ci

0 comments on commit e7dde53

Please sign in to comment.