util

package
v0.0.0-...-8427cc7 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 29 Imported by: 3

Documentation

Overview

Copyright IBM Corp. 2018, 2019.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright IBM Corp. 2018, 2019.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright IBM Corp. 2018, 2019.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright IBM Corp. 2018, 2019.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (

	// Fake Token/Server objects to help with any tests run
	FakeToken  = "01234567890123456789012345678901"
	FakeServer *httptest.Server
)
View Source
var ExecCommand = exec.Command

ExecCommand : Holds exec.Command object

Log : Global logger

Functions

func AttachVolumeToVM

func AttachVolumeToVM(cloud OpenstackCloudI, vmID string,
	volumeID string, volume *resources.OSVolume) (bool, error)

AttachVolumeToVM : Attach volume to VM

func CloseLogFile

func CloseLogFile()

CloseLogFile : Close our plugin log file

func CreateCinderClient

func CreateCinderClient(testParam ...string) (*gophercloud.ServiceClient, error)

CreateCinderClient : Create a Cinder Service Client and Authenticate to OpenStack

func CreateHostnameToDetailsMap

func CreateHostnameToDetailsMap(cloud OpenstackCloudI) (map[string](*resources.Hypervisor), error)

CreateHostnameToDetailsMap : Creates map of hypervisor hostname to host details map

func CreateVMIDToIPMap

func CreateVMIDToIPMap(cloud OpenstackCloudI) (map[string][]string, error)

CreateVMIDToIPMap : Function creates map of VM ID to list of its assigned IPs

func CreateVMIPToVMDetailsMap

func CreateVMIPToVMDetailsMap(cloud OpenstackCloudI) (map[string](resources.OSServer), error)

CreateVMIPToVMDetailsMap : Creates map of VM IP to VM details

func DeleteScsiDevice

func DeleteScsiDevice(devicePath string)

DeleteScsiDevice : Remove block device from SCSI sub-system

func DetachVolumeFromVM

func DetachVolumeFromVM(cloud OpenstackCloudI, vmID string,
	volumeID string, volume resources.OSVolume) (bool, error)

DetachVolumeFromVM : detach volume on openstack

func ErrorStruct

func ErrorStruct(msg string) map[string]string

ErrorStruct : creates error message structure

func FakeEndpoint

func FakeEndpoint() string

Fake Endpoint object to help with any tests run

func FakeServiceClient

func FakeServiceClient() *gophercloud.ServiceClient

Fake ServiceClient object to help with any tests run

func FindAttachedVolumeDirectoryPath

func FindAttachedVolumeDirectoryPath(dirName string) string

FindAttachedVolumeDirectoryPath : Returns directory path of attached volume For multipath device, return device mapper parent

func FindSlaveDevicesOfMultipathParent

func FindSlaveDevicesOfMultipathParent(dm string) []string

FindSlaveDevicesOfMultipathParent : Find slaves of device mapper parent

func GetAssociatedBlockDevices

func GetAssociatedBlockDevices(devicePath string) (string, []string, error)

GetAssociatedBlockDevices : Function to get associated block device for a multipath device. Returns device mapper parent and associated block devices names

func GetCinderVolume

func GetCinderVolume(cinderClient *gophercloud.ServiceClient, volumeID string) (*resources.OSVolume, error)

GetCinderVolume : Function returns volume given volume id

func GetDeviceOfMount

func GetDeviceOfMount(volMountDir string) (string, error)

GetDeviceOfMount Function to get the block device or multipath device of mounted directory

func GetJSONArgs

func GetJSONArgs(args string) map[string]string

GetJSONArgs : parses and returns json args

func GetOSVolumeByID

func GetOSVolumeByID(cloud OpenstackCloudI, volumeID string) (*resources.OSVolume, error)

GetOSVolumeByID : Returns Openstack Volume, given its id.

func GetVMID

func GetVMID(cloud OpenstackCloudI, vmIP string) (string, error)

GetVMID : Get ID of VM given its IP using Neutron API

func GetVMIDThruNova

func GetVMIDThruNova(cloud OpenstackCloudI, vmIP string) (string, error)

GetVMIDThruNova : Get ID of VM given its IP using Nova API

func GetVolumeByMetadataProperty

func GetVolumeByMetadataProperty(cloud OpenstackCloudI,
	volumeMeta map[string]string) (*[]resources.OSVolume, error)

GetVolumeByMetadataProperty : Retrieve volume by querying its metadata

func GetVolumeDirectoryName

func GetVolumeDirectoryName(cloud OpenstackCloudI, nodeAddr string, volumeID string, volume *resources.OSVolume) (string, error)

GetVolumeDirectoryName : Given VM IP and volume ID, this function determines the directory name on the VM where the volume will show up after SCSI rescan.

func HasFSOnVolumeDevice

func HasFSOnVolumeDevice(volPath string) (bool, error)

HasFSOnVolumeDevice : Determines the File System installed on attached volume

func IsVolumeAttached

func IsVolumeAttached(cloud OpenstackCloudI, vmID string, volumeID string) (bool, error)

IsVolumeAttached : Check if volume is attached to the VM

func RemoveMultipathForDevice

func RemoveMultipathForDevice(devicePath string) error

RemoveMultipathForDevice : Cleans up given multipath

func ResolveNodeAddress

func ResolveNodeAddress(nodeName string) string

ResolveNodeAddress : Converts the Node Name to an IP Address if not already

func RunCommand

func RunCommand(cmdStr string, cmdArgs []string) (string, string, error)

RunCommand : Run shell command

func RunPipedCommands

func RunPipedCommands(cmd1 string, cmd1Args []string, cmd2 string, cmd2Args []string) (string, string)

RunPipedCommands : Run cmd1 | cmd2 on OS

func ScsiHostScan

func ScsiHostScan()

ScsiHostScan : Function rescans the scsi bus

func SetupLogging

func SetupLogging()

SetupLogging : Sets up logging for the driver

func UdevdHandleEvents

func UdevdHandleEvents(volPath string) error

UdevdHandleEvents : Indicate udevd to handle device creation and deletion events

func UpdateVolumeMetadata

func UpdateVolumeMetadata(cloud OpenstackCloudI, volumeID string,
	volumeMeta map[string]string, isDelete bool) error

UpdateVolumeMetadata : Update volume's metadata at Openstack

func ValidateArgs

func ValidateArgs(args []string) (bool, string)

ValidateArgs : Validate required arguments for operation

Types

type OpenstackCloud

type OpenstackCloud struct {
	Provider *gophercloud.ProviderClient
}

OpenstackCloud : Reference to openstack provider

func (*OpenstackCloud) AttachVolumeToVM

func (opnStk *OpenstackCloud) AttachVolumeToVM(vmID string, volumeID string, volume *resources.OSVolume) (bool, error)

AttachVolumeToVM : attaches volume to VM

func (*OpenstackCloud) DetachVolumeFromVM

func (opnStk *OpenstackCloud) DetachVolumeFromVM(vmID string, volumeID string, volume *resources.OSVolume) (bool, error)

DetachVolumeFromVM : detaches volume from VM

func (*OpenstackCloud) GetAllOSVMs

func (opnStk *OpenstackCloud) GetAllOSVMs() (*[]resources.OSServer, error)

GetAllOSVMs : Returns list of all VMs from Openstack

func (*OpenstackCloud) GetOSVolumeByID

func (opnStk *OpenstackCloud) GetOSVolumeByID(volumeID string) (*resources.OSVolume, error)

GetOSVolumeByID : Function returns volume given volume id

func (*OpenstackCloud) GetProviderClient

func (opnStk *OpenstackCloud) GetProviderClient() *gophercloud.ProviderClient

GetProviderClient : Returns back the embedded ProviderClient in the Interface

func (*OpenstackCloud) GetServerIDFromNodeName

func (opnStk *OpenstackCloud) GetServerIDFromNodeName(nodeName string) (string, error)

GetServerIDFromNodeName : Returns VM ID given its IP

func (*OpenstackCloud) GetStorageHostRegistration

func (opnStk *OpenstackCloud) GetStorageHostRegistration(hostname string) (*resources.StorageRegistration, error)

GetStorageHostRegistration : Returns storage host registration by name

func (*OpenstackCloud) GetVolumeByMetadataProperty

func (opnStk *OpenstackCloud) GetVolumeByMetadataProperty(volumeMeta map[string]string) (*[]resources.OSVolume, error)

GetVolumeByMetadataProperty : Retrieves Openstack cinder volume by querying its metadata

func (*OpenstackCloud) IsVolumeAttached

func (opnStk *OpenstackCloud) IsVolumeAttached(vmID string, volumeID string) (bool, error)

IsVolumeAttached : Determines if a volume is attached to a VM

func (*OpenstackCloud) ListHypervisors

func (opnStk *OpenstackCloud) ListHypervisors() (*[]hypervisors.Hypervisor, error)

ListHypervisors : Returns hypervisor list

func (*OpenstackCloud) NewComputeV2

func (opnStk *OpenstackCloud) NewComputeV2() (*gophercloud.ServiceClient, error)

NewComputeV2 : Returns nova service client

func (*OpenstackCloud) NewNetworkV2

func (opnStk *OpenstackCloud) NewNetworkV2() (*gophercloud.ServiceClient, error)

NewNetworkV2 : Returns Neutron service client

func (*OpenstackCloud) NewVolumeV3

func (opnStk *OpenstackCloud) NewVolumeV3() (*gophercloud.ServiceClient, error)

NewVolumeV3 : Returns cinder service client

func (*OpenstackCloud) UpdateVolumeMetadata

func (opnStk *OpenstackCloud) UpdateVolumeMetadata(volumeID string,
	volumeMeta map[string]string, isDelete bool) error

UpdateVolumeMetadata : Updates volume metadata

type OpenstackCloudI

type OpenstackCloudI interface {
	GetAllOSVMs() (*[]resources.OSServer, error)
	GetOSVolumeByID(volumeID string) (*resources.OSVolume, error)
	GetStorageHostRegistration(hostname string) (*resources.StorageRegistration, error)
	AttachVolumeToVM(vmID string, volumeID string, volume *resources.OSVolume) (bool, error)
	DetachVolumeFromVM(vmID string, volumeID string, volume *resources.OSVolume) (bool, error)
	IsVolumeAttached(vmID string, volumeID string) (bool, error)
	GetVolumeByMetadataProperty(volumeMeta map[string]string) (*[]resources.OSVolume, error)
	UpdateVolumeMetadata(volumeID string, volumeMeta map[string]string, isDelete bool) error
	ListHypervisors() (*[]hypervisors.Hypervisor, error)
	GetServerIDFromNodeName(nodeName string) (string, error)
	GetProviderClient() *gophercloud.ProviderClient
}

OpenstackCloudI : Interface that defines openstack cloud API methods

func CreateOpenstackClient

func CreateOpenstackClient(testParam ...string) (OpenstackCloudI, error)

CreateOpenstackClient : Create an OpenStack Client and Authenticate to OpenStack

type OpenstackCloudMock

type OpenstackCloudMock struct{}

OpenstackCloudMock : Our mock that we will plug in for tests.

func (*OpenstackCloudMock) AttachVolumeToVM

func (opnStk *OpenstackCloudMock) AttachVolumeToVM(vmID string, volumeID string, volume *resources.OSVolume) (bool, error)

AttachVolumeToVM :

func (*OpenstackCloudMock) DetachVolumeFromVM

func (opnStk *OpenstackCloudMock) DetachVolumeFromVM(vmID string, volumeID string, volume *resources.OSVolume) (bool, error)

DetachVolumeFromVM :

func (*OpenstackCloudMock) GetAllOSVMs

func (opnStk *OpenstackCloudMock) GetAllOSVMs() (*[]resources.OSServer, error)

GetAllOSVMs :

func (*OpenstackCloudMock) GetOSVolumeByID

func (opnStk *OpenstackCloudMock) GetOSVolumeByID(volumeID string) (*resources.OSVolume, error)

GetOSVolumeByID :

func (*OpenstackCloudMock) GetProviderClient

func (opnStk *OpenstackCloudMock) GetProviderClient() *gophercloud.ProviderClient

GetProviderClient : Returns back the embedded ProviderClient in the Interface

func (*OpenstackCloudMock) GetServerIDFromNodeName

func (opnStk *OpenstackCloudMock) GetServerIDFromNodeName(nodeName string) (string, error)

GetServerIDFromNodeName :

func (*OpenstackCloudMock) GetStorageHostRegistration

func (opnStk *OpenstackCloudMock) GetStorageHostRegistration(hostname string) (*resources.StorageRegistration, error)

GetStorageHostRegistration :

func (*OpenstackCloudMock) GetVolumeByMetadataProperty

func (opnStk *OpenstackCloudMock) GetVolumeByMetadataProperty(
	volumeMeta map[string]string) (*[]resources.OSVolume, error)

GetVolumeByMetadataProperty :

func (*OpenstackCloudMock) IsVolumeAttached

func (opnStk *OpenstackCloudMock) IsVolumeAttached(vmID string, volumeID string) (bool, error)

IsVolumeAttached :

func (*OpenstackCloudMock) ListHypervisors

func (opnStk *OpenstackCloudMock) ListHypervisors() (*[]hypervisors.Hypervisor, error)

ListHypervisors :

func (*OpenstackCloudMock) UpdateVolumeMetadata

func (opnStk *OpenstackCloudMock) UpdateVolumeMetadata(volumeID string, volumeMeta map[string]string, isDelete bool) error

UpdateVolumeMetadata :

Jump to

Keyboard shortcuts

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