-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_create.go
executable file
·60 lines (47 loc) · 1.35 KB
/
project_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Copyright © 2022 PlusServer GmbH
*/
package cmd
import (
"context"
"fmt"
"os"
"github.com/pluscloudopen/reseller-cli/v2/pkg/openapi"
"github.com/spf13/cobra"
)
var projectDescription string
var projectWithDefaultNetwork bool
// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create a new reseller project",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please specify the name of the project")
os.Exit(1)
}
if len(args) > 1 {
fmt.Println("Please only specify the name of the project")
os.Exit(1)
}
psOsClient := fetchPsOpenStackClientOrDie()
ctx := context.Background()
enabled := true
resp, err := psOsClient.CreateProject(ctx, openapi.ProjectCreate{
Name: args[0],
Description: projectDescription,
Enabled: &enabled,
NetworkPreconfigure: &projectWithDefaultNetwork,
})
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Println(resp.Id)
},
}
func init() {
projectCmd.AddCommand(createCmd)
createCmd.Flags().StringVarP(&projectDescription, "description", "d", "No Description", "Specify the description of the project")
createCmd.Flags().BoolVar(&projectWithDefaultNetwork, "with-default-network", false, "Specify if the default network should be created (default false)")
}