|
| 1 | +package interconnections |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + metal "github.com/equinix-labs/metal-go/metal/v1" |
| 8 | + "github.com/spf13/cobra" |
| 9 | +) |
| 10 | + |
| 11 | +func (c *Client) Create() *cobra.Command { |
| 12 | + var name, metro, redundancy, connType, projectID, organizationID string |
| 13 | + var vrfs []string |
| 14 | + |
| 15 | + createInterconnectionsCmd := &cobra.Command{ |
| 16 | + Use: `create -n <name> [-m <metro>] [-r <redundancy> ] [-t <type> ] [-p <project_id> ] | [-O <organization_id> ]`, |
| 17 | + Short: "Creates an interconnection.", |
| 18 | + Long: "Creates a new interconnection as per the organization ID or project ID ", |
| 19 | + Example: ` # Creates a new interconnection named "it-interconnection": |
| 20 | + metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "dedicated" ] [-p <project_id>] | [-O <organization_id>] |
| 21 | +
|
| 22 | + metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> |
| 23 | +
|
| 24 | + metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> -v <vrfs>`, |
| 25 | + |
| 26 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 27 | + cmd.SilenceUsage = true |
| 28 | + var interconn *metal.Interconnection |
| 29 | + var err error |
| 30 | + |
| 31 | + createOrganizationInterconnectionRequest := metal.CreateOrganizationInterconnectionRequest{DedicatedPortCreateInput: metal.NewDedicatedPortCreateInput(metro, name, redundancy, metal.DedicatedPortCreateInputType(connType))} |
| 32 | + if projectID != "" { |
| 33 | + |
| 34 | + interconn, _, err = c.Service.CreateProjectInterconnection(context.Background(), projectID).CreateOrganizationInterconnectionRequest(createOrganizationInterconnectionRequest).Execute() |
| 35 | + if err != nil { |
| 36 | + return fmt.Errorf("could not create interconnections: %w", err) |
| 37 | + |
| 38 | + } |
| 39 | + } else if organizationID != "" { |
| 40 | + interconn, _, err = c.Service.CreateOrganizationInterconnection(context.Background(), organizationID).CreateOrganizationInterconnectionRequest(createOrganizationInterconnectionRequest).Execute() |
| 41 | + if err != nil { |
| 42 | + return fmt.Errorf("could not create interconnections: %w", err) |
| 43 | + } |
| 44 | + } else { |
| 45 | + return fmt.Errorf("Could you provide at least either of projectID OR organizationID") |
| 46 | + } |
| 47 | + |
| 48 | + data := make([][]string, 1) |
| 49 | + |
| 50 | + data[0] = []string{interconn.GetId(), interconn.GetName(), string(interconn.GetType()), interconn.GetCreatedAt().String()} |
| 51 | + header := []string{"ID", "Name", "Type", "Created"} |
| 52 | + |
| 53 | + return c.Out.Output(interconn, header, &data) |
| 54 | + }, |
| 55 | + } |
| 56 | + |
| 57 | + createInterconnectionsCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the interconnection") |
| 58 | + createInterconnectionsCmd.Flags().StringVarP(&metro, "metro", "m", "", "metro in the interconnection") |
| 59 | + createInterconnectionsCmd.Flags().StringVarP(&redundancy, "redundancy", "r", "", "Website URL of the organization.") |
| 60 | + createInterconnectionsCmd.Flags().StringVarP(&connType, "type", "t", "", "type of of interconnection.") |
| 61 | + // createInterconnectionsCmd.Flags().StringVarP(&connType, "serviceTokentype", "T", "", "service token type for interconnection either fabric OR Metal builds") |
| 62 | + createInterconnectionsCmd.Flags().StringSliceVarP(&vrfs, "vrfs", "v", []string{}, "Return only the specified vrfs.") |
| 63 | + createInterconnectionsCmd.Flags().StringVarP(&projectID, "projectID", "p", "", "project ID") |
| 64 | + createInterconnectionsCmd.Flags().StringVarP(&organizationID, "organizationID", "O", "", "Org ID") |
| 65 | + |
| 66 | + _ = createInterconnectionsCmd.MarkFlagRequired("name") |
| 67 | + _ = createInterconnectionsCmd.MarkFlagRequired("metro") |
| 68 | + _ = createInterconnectionsCmd.MarkFlagRequired("redundancy") |
| 69 | + _ = createInterconnectionsCmd.MarkFlagRequired("type") |
| 70 | + return createInterconnectionsCmd |
| 71 | +} |
0 commit comments