port

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "port",
	Short: "Create PowerVS network port",
	Long:  `Create PowerVS network port`,
	RunE: func(cmd *cobra.Command, args []string) error {
		opt := pkg.Options

		c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
		if err != nil {
			klog.Errorf("failed to create a session with IBM cloud: %v", err)
			return err
		}

		pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment)
		if err != nil {
			return err
		}

		networks, err := pvmclient.NetworkClient.GetAll()
		if err != nil {
			return fmt.Errorf("failed to get the networks, err: %v", err)
		}

		var networkNames, networkIDs []string
		for _, net := range networks.Networks {
			networkIDs = append(networkIDs, *net.NetworkID)
			networkNames = append(networkNames, *net.Name)
		}

		var netID string

		if utils.Contains(networkIDs, network) {
			netID = network
		} else if utils.Contains(networkNames, network) {
			for _, n := range networks.Networks {
				if *n.Name == network {
					netID = *n.NetworkID
				}
			}
		} else {
			return fmt.Errorf("not able to find network: \"%s\" by ID or name in the list: ids:[%s], names: [%s]", network, strings.Join(networkIDs, ","), strings.Join(networkNames, ","))
		}

		params := &models.NetworkPortCreate{
			Description: description,
			IPAddress:   ipaddress,
		}

		port, err := pvmclient.NetworkClient.CreatePort(netID, params)
		if err != nil {
			return fmt.Errorf("failed to create a port, err: %v", err)
		}
		klog.Infof("Successfully created a port, id: %s", *port.PortID)

		table := utils.NewTable()
		table.Render([]*models.NetworkPort{port}, []string{})
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL