openstack

package
v0.0.0-...-8023bdc Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: Apache-2.0 Imports: 32 Imported by: 7

Documentation

Index

Constants

View Source
const (
	StatusCodeAlreadyExists int = 409

	HostnameMaxLen = 63

	// Service affinities
	ServiceAffinityNone     = "None"
	ServiceAffinityClientIP = "ClientIP"
)

Variables

View Source
var (
	ErrNotFound        = errors.New("NotFound")
	ErrMultipleResults = errors.New("MultipleResults")
)

Functions

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.

Types

type CalledDetail

type CalledDetail struct {
	// Name of the function called.
	Name string
	// Argument of the function called.
	Argument []interface{}
}

CalledDetail is the struct contains called function name and arguments.

type Client

type Client struct {
	Identity          *gophercloud.ServiceClient
	Provider          *gophercloud.ProviderClient
	Network           *gophercloud.ServiceClient
	Region            string
	ExtNetID          string
	PluginName        string
	IntegrationBridge string
	CRDClient         crdClient.Interface
}

Client implements the openstack client Interface.

func (*Client) CheckTenantByID

func (os *Client) CheckTenantByID(tenantID string) (bool, error)

CheckTenantByID checks tenant exist or not by tenantID.

func (*Client) CreateNetwork

func (os *Client) CreateNetwork(network *drivertypes.Network) error

CreateNetwork creates network.

func (*Client) CreatePort

func (os *Client) CreatePort(networkID, tenantID, portName string) (*portsbinding.Port, error)

CreatePort creates port by neworkID, tenantID and portName.

func (*Client) CreateTenant

func (os *Client) CreateTenant(tenantName string) (string, error)

CreateTenant creates tenant by tenantname.

func (*Client) CreateUser

func (os *Client) CreateUser(username, password, tenantID string) error

CreateUser creates user with username, password in the tenant.

func (*Client) DeleteAllUsersOnTenant

func (os *Client) DeleteAllUsersOnTenant(tenantName string) error

DeleteAllUsersOnTenant deletes all users on the tenant.

func (*Client) DeleteNetwork

func (os *Client) DeleteNetwork(networkName string) error

DeleteNetwork deletes network by networkName.

func (*Client) DeletePortByID

func (os *Client) DeletePortByID(portID string) error

DeletePortByID deletes port by portID.

func (*Client) DeletePortByName

func (os *Client) DeletePortByName(portName string) error

DeletePortByName deletes port by portName

func (*Client) DeleteTenant

func (os *Client) DeleteTenant(tenantName string) error

DeleteTenant deletes tenant by tenantName.

func (*Client) EnsureLoadBalancer

func (os *Client) EnsureLoadBalancer(lb *LoadBalancer) (*LoadBalancerStatus, error)

EnsureLoadBalancer ensures a load balancer is created.

func (*Client) EnsureLoadBalancerDeleted

func (os *Client) EnsureLoadBalancerDeleted(name string) error

EnsureLoadBalancerDeleted ensures a load balancer is deleted.

func (*Client) GetCRDClient

func (os *Client) GetCRDClient() crdClient.Interface

GetCRDClient returns the CRDClient.

func (*Client) GetIntegrationBridge

func (os *Client) GetIntegrationBridge() string

GetIntegrationBridge returns the integration bridge name.

func (*Client) GetLoadBalancer

func (os *Client) GetLoadBalancer(name string) (*LoadBalancer, error)

GetLoadBalancer gets a load balancer by name.

func (*Client) GetNetworkByID

func (os *Client) GetNetworkByID(networkID string) (*drivertypes.Network, error)

GetNetworkByID gets network by networkID

func (*Client) GetNetworkByName

func (os *Client) GetNetworkByName(networkName string) (*drivertypes.Network, error)

GetNetworkByName gets network by networkName

func (*Client) GetOpenStackNetworkByTenantID

func (os *Client) GetOpenStackNetworkByTenantID(tenantID string) (*networks.Network, error)

GetOpenStackNetworkByTenantID gets tenant's network by tenantID(tenant and network are one to one mapping in stackube)

func (*Client) GetPluginName

func (os *Client) GetPluginName() string

GetPluginName returns the plugin name.

func (*Client) GetPort

func (os *Client) GetPort(name string) (*ports.Port, error)

GetPort gets port by portName.

func (*Client) GetProviderSubnet

func (os *Client) GetProviderSubnet(osSubnetID string) (*drivertypes.Subnet, error)

GetProviderSubnet gets provider subnet by subnetID

func (*Client) GetTenantIDFromName

func (os *Client) GetTenantIDFromName(tenantName string) (string, error)

GetTenantIDFromName gets tenantID by tenantName.

func (*Client) ListPorts

func (os *Client) ListPorts(networkID, deviceOwner string) ([]ports.Port, error)

ListPorts lists ports by networkID and deviceOwner.

func (*Client) LoadBalancerExist

func (os *Client) LoadBalancerExist(name string) (bool, error)

LoadBalancerExist returns whether a load balancer has already been exist.

func (*Client) OSNetworktoProviderNetwork

func (os *Client) OSNetworktoProviderNetwork(osNetwork *networks.Network) (*drivertypes.Network, error)

OSNetworktoProviderNetwork transfers networks.Network to drivertypes.Network.

func (*Client) ToProviderStatus

func (os *Client) ToProviderStatus(status string) string

ToProviderStatus transfers networks.Network's status to drivertypes.Network's status.

func (*Client) UpdateNetwork

func (os *Client) UpdateNetwork(network *drivertypes.Network) error

UpdateNetwork updates network.

func (*Client) UpdatePortsBinding

func (os *Client) UpdatePortsBinding(portID, deviceOwner string) error

UpdatePortsBinding updates port binding.

type Config

type Config struct {
	Global struct {
		AuthUrl    string `gcfg:"auth-url"`
		Username   string `gcfg:"username"`
		Password   string `gcfg:"password"`
		TenantName string `gcfg:"tenant-name"`
		Region     string `gcfg:"region"`
		ExtNetID   string `gcfg:"ext-net-id"`
	}
	Plugin PluginOpts
}

Config used to configure the openstack client.

type Endpoint

type Endpoint struct {
	Address string
	Port    int
}

Endpoint represents a container endpoint.

type FakeOSClient

type FakeOSClient struct {
	sync.Mutex

	Tenants           map[string]*tenants.Tenant
	Users             map[string]*users.User
	Networks          map[string]*drivertypes.Network
	Subnets           map[string]*subnets.Subnet
	Routers           map[string]*routers.Router
	Ports             map[string][]ports.Port
	LoadBalancers     map[string]*LoadBalancer
	CRDClient         crdClient.Interface
	PluginName        string
	IntegrationBridge string
	// contains filtered or unexported fields
}

FakeOSClient is a simple fake openstack client, so that stackube can be run for testing without requiring a real openstack setup.

func NewFake

func NewFake(crdClient crdClient.Interface) *FakeOSClient

NewFake creates a new FakeOSClient.

func (*FakeOSClient) CheckTenantByID

func (f *FakeOSClient) CheckTenantByID(tenantID string) (bool, error)

CheckTenantByID is a test implementation of Interface.CheckTenantByID.

func (*FakeOSClient) ClearErrors

func (f *FakeOSClient) ClearErrors()

ClearErrors clear errors for call

func (*FakeOSClient) CreateNetwork

func (f *FakeOSClient) CreateNetwork(network *drivertypes.Network) error

CreateNetwork is a test implementation of Interface.CreateNetwork.

func (*FakeOSClient) CreatePort

func (f *FakeOSClient) CreatePort(networkID, tenantID, portName string) (*portsbinding.Port, error)

CreatePort is a test implementation of Interface.CreatePort.

func (*FakeOSClient) CreateTenant

func (f *FakeOSClient) CreateTenant(tenantName string) (string, error)

CreateTenant is a test implementation of Interface.CreateTenant.

func (*FakeOSClient) CreateUser

func (f *FakeOSClient) CreateUser(username, password, tenantID string) error

CreateUser is a test implementation of Interface.CreateUser.

func (*FakeOSClient) DeleteAllUsersOnTenant

func (f *FakeOSClient) DeleteAllUsersOnTenant(tenantName string) error

DeleteAllUsersOnTenant is a test implementation of Interface.DeleteAllUsersOnTenant.

func (*FakeOSClient) DeleteNetwork

func (f *FakeOSClient) DeleteNetwork(networkName string) error

DeleteNetwork is a test implementation of Interface.DeleteNetwork.

func (*FakeOSClient) DeletePortByID

func (f *FakeOSClient) DeletePortByID(portID string) error

DeletePortByID is a test implementation of Interface.DeletePortByID.

func (*FakeOSClient) DeletePortByName

func (f *FakeOSClient) DeletePortByName(portName string) error

DeletePortByName is a test implementation of Interface.DeletePortByName.

func (*FakeOSClient) DeleteTenant

func (f *FakeOSClient) DeleteTenant(tenantName string) error

DeleteTenant is a test implementation of Interface.DeleteTenant.

func (*FakeOSClient) EnsureLoadBalancer

func (f *FakeOSClient) EnsureLoadBalancer(lb *LoadBalancer) (*LoadBalancerStatus, error)

EnsureLoadBalancer is a test implementation of Interface.EnsureLoadBalancer.

func (*FakeOSClient) EnsureLoadBalancerDeleted

func (f *FakeOSClient) EnsureLoadBalancerDeleted(name string) error

EnsureLoadBalancerDeleted is a test implementation of Interface.EnsureLoadBalancerDeleted.

func (*FakeOSClient) GetCRDClient

func (f *FakeOSClient) GetCRDClient() crdClient.Interface

GetCRDClient is a test implementation of Interface.GetCRDClient.

func (*FakeOSClient) GetCalledDetails

func (f *FakeOSClient) GetCalledDetails() []CalledDetail

GetCalledDetails get detail of each call.

func (*FakeOSClient) GetCalledNames

func (f *FakeOSClient) GetCalledNames() []string

GetCalledNames get names of call

func (*FakeOSClient) GetIntegrationBridge

func (f *FakeOSClient) GetIntegrationBridge() string

GetIntegrationBridge is a test implementation of Interface.GetIntegrationBridge.

func (*FakeOSClient) GetNetworkByID

func (f *FakeOSClient) GetNetworkByID(networkID string) (*drivertypes.Network, error)

GetNetworkByID is a test implementation of Interface.GetNetworkByID.

func (*FakeOSClient) GetNetworkByName

func (f *FakeOSClient) GetNetworkByName(networkName string) (*drivertypes.Network, error)

GetNetworkByName is a test implementation of Interface.GetNetworkByName.

func (*FakeOSClient) GetPluginName

func (f *FakeOSClient) GetPluginName() string

GetPluginName is a test implementation of Interface.GetPluginName.

func (*FakeOSClient) GetPort

func (f *FakeOSClient) GetPort(name string) (*ports.Port, error)

GetPort is a test implementation of Interface.GetPort.

func (*FakeOSClient) GetProviderSubnet

func (f *FakeOSClient) GetProviderSubnet(osSubnetID string) (*drivertypes.Subnet, error)

GetProviderSubnet is a test implementation of Interface.GetProviderSubnet.

func (*FakeOSClient) GetTenantIDFromName

func (f *FakeOSClient) GetTenantIDFromName(tenantName string) (string, error)

GetTenantIDFromName is a test implementation of Interface.GetTenantIDFromName.

func (*FakeOSClient) InjectError

func (f *FakeOSClient) InjectError(fn string, err error)

InjectError inject error for call

func (*FakeOSClient) InjectErrors

func (f *FakeOSClient) InjectErrors(errs map[string]error)

InjectErrors inject errors for calls

func (*FakeOSClient) ListPorts

func (f *FakeOSClient) ListPorts(networkID, deviceOwner string) ([]ports.Port, error)

ListPorts is a test implementation of Interface.ListPorts.

func (*FakeOSClient) LoadBalancerExist

func (f *FakeOSClient) LoadBalancerExist(name string) (bool, error)

LoadBalancerExist is a test implementation of Interface.LoadBalancerExist.

func (*FakeOSClient) SetLoadbalancer

func (f *FakeOSClient) SetLoadbalancer(lb *LoadBalancer)

SetLoadbalancer injects fake loadbalancer.

func (*FakeOSClient) SetNetwork

func (f *FakeOSClient) SetNetwork(network *drivertypes.Network)

SetNetwork injects fake network.

func (*FakeOSClient) SetPort

func (f *FakeOSClient) SetPort(networkID, deviceOwner, deviceID string)

SetPort injects fake port.

func (*FakeOSClient) SetTenant

func (f *FakeOSClient) SetTenant(tenantName, tenantID string)

SetTenant injects fake tenant.

func (*FakeOSClient) SetUser

func (f *FakeOSClient) SetUser(userName, userID, tenantID string)

SetUser injects fake user.

func (*FakeOSClient) UpdatePortsBinding

func (f *FakeOSClient) UpdatePortsBinding(portID, deviceOwner string) error

UpdatePortsBinding is a test implementation of Interface.UpdatePortsBinding.

type Interface

type Interface interface {
	// CreateTenant creates tenant by tenantname.
	CreateTenant(tenantName string) (string, error)
	// DeleteTenant deletes tenant by tenantName.
	DeleteTenant(tenantName string) error
	// GetTenantIDFromName gets tenantID by tenantName.
	GetTenantIDFromName(tenantName string) (string, error)
	// CheckTenantByID checks tenant exist or not by tenantID.
	CheckTenantByID(tenantID string) (bool, error)
	// CreateUser creates user with username, password in the tenant.
	CreateUser(username, password, tenantID string) error
	// DeleteAllUsersOnTenant deletes all users on the tenant.
	DeleteAllUsersOnTenant(tenantName string) error
	// CreateNetwork creates network.
	CreateNetwork(network *drivertypes.Network) error
	// GetNetworkByID gets network by networkID.
	GetNetworkByID(networkID string) (*drivertypes.Network, error)
	// GetNetworkByName gets network by networkName.
	GetNetworkByName(networkName string) (*drivertypes.Network, error)
	// DeleteNetwork deletes network by networkName.
	DeleteNetwork(networkName string) error
	// GetProviderSubnet gets provider subnet by id
	GetProviderSubnet(osSubnetID string) (*drivertypes.Subnet, error)
	// CreatePort creates port by neworkID, tenantID and portName.
	CreatePort(networkID, tenantID, portName string) (*portsbinding.Port, error)
	// GetPort gets port by portName.
	GetPort(name string) (*ports.Port, error)
	// ListPorts lists ports by networkID and deviceOwner.
	ListPorts(networkID, deviceOwner string) ([]ports.Port, error)
	// DeletePortByName deletes port by portName.
	DeletePortByName(portName string) error
	// DeletePortByID deletes port by portID.
	DeletePortByID(portID string) error
	// UpdatePortsBinding updates port binding.
	UpdatePortsBinding(portID, deviceOwner string) error
	// LoadBalancerExist returns whether a load balancer has already been exist.
	LoadBalancerExist(name string) (bool, error)
	// EnsureLoadBalancer ensures a load balancer is created.
	EnsureLoadBalancer(lb *LoadBalancer) (*LoadBalancerStatus, error)
	// EnsureLoadBalancerDeleted ensures a load balancer is deleted.
	EnsureLoadBalancerDeleted(name string) error
	// GetCRDClient returns the CRDClient.
	GetCRDClient() crdClient.Interface
	// GetPluginName returns the plugin name.
	GetPluginName() string
	// GetIntegrationBridge returns the integration bridge name.
	GetIntegrationBridge() string
}

Interface should be implemented by a openstack client.

func NewClient

func NewClient(config string, kubeConfig string) (Interface, error)

NewClient returns a new openstack client.

type LoadBalancer

type LoadBalancer struct {
	Name            string
	ServicePort     int
	TenantID        string
	SubnetID        string
	Protocol        string
	InternalIP      string
	ExternalIP      string
	SessionAffinity bool
	Endpoints       []Endpoint
}

LoadBalancer contains all essential information of kubernetes service.

type LoadBalancerStatus

type LoadBalancerStatus struct {
	InternalIP string
	ExternalIP string
}

LoadBalancerStatus contains the status of a load balancer.

type PluginOpts

type PluginOpts struct {
	PluginName        string `gcfg:"plugin-name"`
	IntegrationBridge string `gcfg:"integration-bridge"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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