deploy

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CopyPrivateKeyFunc string = `` /* 180-byte string literal not displayed */
View Source
const CreateInstanceUserFunc string = `` /* 593-byte string literal not displayed */
View Source
const InitVolumeAttachmentFunc string = `` /* 1289-byte string literal not displayed */
View Source
const LogColorGreen string = "\033[32m"
View Source
const LogColorRed string = "\033[31m"
View Source
const LogColorReset string = "\033[0m"

Variables

This section is empty.

Functions

func AddLogMsg

func AddLogMsg(sb *strings.Builder, logMsg LogMsg)

func CmdChainExecToString

func CmdChainExecToString(title string, logContent string, err error, isVerbose bool) string

func ExecSshForClient

func ExecSshForClient(sshClient *ssh.Client, cmd string) (string, string, error)

func FileGroupUpDefsToSpecs

func FileGroupUpDefsToSpecs(prj *Project, fileGroupsToUpload map[string]*FileGroupUpDef) ([]*FileUploadSpec, []*AfterFileUploadSpec, error)

func FindOpenstackColumnValue

func FindOpenstackColumnValue(rows []map[string]string, fieldNameToReturn string, fieldNameToSearch string, fieldValueToSearch string) string

func FindOpenstackFieldValue

func FindOpenstackFieldValue(rows []map[string]string, fieldName string) string

func NewCopyPrivateKeysCommands

func NewCopyPrivateKeysCommands(iDef *InstanceDef) ([]string, error)

func NewCreateInstanceUsersCommands

func NewCreateInstanceUsersCommands(iDef *InstanceDef) ([]string, error)

func ParseOpenstackOutput

func ParseOpenstackOutput(input string) ([]map[string]string, error)

Types

type AfterFileUploadSpec

type AfterFileUploadSpec struct {
	IpAddress string
	Env       map[string]string
	Cmd       []string
}

type AttachedVolumeDef

type AttachedVolumeDef struct {
	AttachmentId  string `json:"attachment_id"`
	Device        string `json:"device"`
	BlockDeviceId string `json:"block_device_id"`
}

type ExecResult

type ExecResult struct {
	Cmd     string
	Stdout  string
	Stderr  string
	Elapsed float64
	Error   error
}

func ExecLocal

func ExecLocal(prj *Project, cmdPath string, params []string) ExecResult

func ExecLocalAndParseOpenstackOutput

func ExecLocalAndParseOpenstackOutput(prj *Project, cmdPath string, params []string) ([]map[string]string, ExecResult)

func ExecSsh

func ExecSsh(sshConfig *SshConfigDef, ipAddress string, cmd string) ExecResult

func ExecSshAndReturnLastLine

func ExecSshAndReturnLastLine(sshConfig *SshConfigDef, ipAddress string, cmd string) (string, ExecResult)

func (*ExecResult) ToString

func (er *ExecResult) ToString() string

type ExecTimeouts

type ExecTimeouts struct {
	OpenstackCmd              int `json:"openstack_cmd"`
	OpenstackInstanceCreation int `json:"openstack_instance_creation"`
	AttachVolume              int `json:"attach_volume"`
}

type FileDownloadSpec

type FileDownloadSpec struct {
	IpAddress string
	Src       string
	Dst       string
}

func FileGroupDownDefsToSpecs

func FileGroupDownDefsToSpecs(prj *Project, fileGroupsToDownload map[string]*FileGroupDownDef) ([]*FileDownloadSpec, error)

func InstanceFileGroupDownDefsToSpecs

func InstanceFileGroupDownDefsToSpecs(prj *Project, ipAddress string, fgDef *FileGroupDownDef) ([]*FileDownloadSpec, error)

type FileGroupDownDef

type FileGroupDownDef struct {
	Src string `json:"src"`
	Dst string `json:"dst"`
}

type FileGroupUpAfter

type FileGroupUpAfter struct {
	Env map[string]string `json:"env,omitempty"`
	Cmd []string          `json:"cmd,omitempty"`
}

type FileGroupUpDef

type FileGroupUpDef struct {
	Src             string           `json:"src"`
	Dst             string           `json:"dst"`
	DirPermissions  int              `json:"dir_permissions"`
	FilePermissions int              `json:"file_permissions"`
	Owner           string           `json:"owner,omitempty"`
	After           FileGroupUpAfter `json:"after,omitempty"`
}

type FileUploadSpec

type FileUploadSpec struct {
	IpAddress       string
	Src             string
	Dst             string
	DirPermissions  int
	FilePermissions int
	Owner           string
}

type InstanceDef

type InstanceDef struct {
	HostName              string                        `json:"host_name"`
	SecurityGroupNickname string                        `json:"security_group"`
	IpAddress             string                        `json:"ip_address"`
	FloatingIpAddress     string                        `json:"floating_ip_address,omitempty"`
	FlavorName            string                        `json:"flavor"`
	ImageName             string                        `json:"image"`
	AttachedVolumes       map[string]*AttachedVolumeDef `json:"attached_volumes,omitempty"`
	Id                    string                        `json:"id"`
	Users                 []UserDef                     `json:"users,omitempty"`
	PrivateKeys           []PrivateKeyDef               `json:"private_keys,omitempty"`
	Service               ServiceDef                    `json:"service"`
	ApplicableFileGroups  []string                      `json:"applicable_file_groups,omitempty"`
}

func (*InstanceDef) BestIpAddress

func (iDef *InstanceDef) BestIpAddress() string

func (*InstanceDef) Clean

func (iDef *InstanceDef) Clean()

type LogBuilder

type LogBuilder struct {
	Sb        *strings.Builder
	IsVerbose bool
	Header    string
	StartTs   time.Time
}

func NewLogBuilder

func NewLogBuilder(header string, isVerbose bool) *LogBuilder

func (*LogBuilder) Add

func (lb *LogBuilder) Add(content string)

func (*LogBuilder) Complete

func (lb *LogBuilder) Complete(err error) (LogMsg, error)

type LogMsg

type LogMsg string

func AssignFloatingIp

func AssignFloatingIp(prj *Project, instanceId string, floatingIp string, isVerbose bool) (LogMsg, error)

func AttachVolume

func AttachVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func CreateInstance

func CreateInstance(prjPair *ProjectPair, iNickname string, flavorId string, imageId string, isVerbose bool) (LogMsg, error)

func CreateInstanceAndWaitForCompletion

func CreateInstanceAndWaitForCompletion(prjPair *ProjectPair, iNickname string, flavorId string, imageId string, isVerbose bool) (LogMsg, error)

func CreateNetwork

func CreateNetwork(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func CreateNetworking

func CreateNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func CreateRouter

func CreateRouter(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func CreateSecurityGroup

func CreateSecurityGroup(prjPair *ProjectPair, sgNickname string, isVerbose bool) (LogMsg, error)

func CreateSecurityGroups

func CreateSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func CreateSubnet

func CreateSubnet(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func CreateVolume

func CreateVolume(prjPair *ProjectPair, volNickname string, isVerbose bool) (LogMsg, error)

func DeleteInstance

func DeleteInstance(prjPair *ProjectPair, iNickname string, isVerbose bool) (LogMsg, error)

func DeleteNetwork

func DeleteNetwork(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func DeleteNetworking

func DeleteNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func DeleteRouter

func DeleteRouter(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func DeleteSecurityGroup

func DeleteSecurityGroup(prjPair *ProjectPair, sgNickname string, isVerbose bool) (LogMsg, error)

func DeleteSecurityGroups

func DeleteSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func DeleteSubnet

func DeleteSubnet(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func DeleteVolume

func DeleteVolume(prjPair *ProjectPair, volNickname string, isVerbose bool) (LogMsg, error)

func DownloadFileSftp

func DownloadFileSftp(prj *Project, ipAddress string, srcPath string, dstPath string, isVerbose bool) (LogMsg, error)

func ExecCommandsOnInstance

func ExecCommandsOnInstance(sshConfig *SshConfigDef, ipAddress string, cmds []string, isVerbose bool) (LogMsg, error)

func ExecScriptsOnInstance

func ExecScriptsOnInstance(sshConfig *SshConfigDef, ipAddress string, env map[string]string, prjFileDirPath string, shellScriptFiles []string, isVerbose bool) (LogMsg, error)

func GetFlavorIds

func GetFlavorIds(prjPair *ProjectPair, flavorMap map[string]string, isVerbose bool) (LogMsg, error)

func GetImageIds

func GetImageIds(prjPair *ProjectPair, imageMap map[string]string, isVerbose bool) (LogMsg, error)

func ShowVolumeAttachment

func ShowVolumeAttachment(prj *Project, volNickname string, iNickname string, isVerbose bool) (string, LogMsg, error)

func UploadFileSftp

func UploadFileSftp(prj *Project, ipAddress string, srcPath string, dstPath string, dirPermissions int, filePermissions int, owner string, isVerbose bool) (LogMsg, error)

func WaitForEntityToBeCreated

func WaitForEntityToBeCreated(prj *Project, entityType string, entityName string, entityId string, timeoutSeconds int, isVerbose bool) (LogMsg, error)

type NetworkDef

type NetworkDef struct {
	Name   string    `json:"name"`
	Id     string    `json:"id"`
	Subnet SubnetDef `json:"subnet"`
	Router RouterDef `json:"router"`
}

type PrivateKeyDef

type PrivateKeyDef struct {
	Name       string `json:"name"`
	PrivateKey string `json:"private_key"`
}

type Project

type Project struct {
	DeploymentName        string                       `json:"deployment_name"`
	SshConfig             *SshConfigDef                `json:"ssh_config"`
	RootKeyName           string                       `json:"root_key_name"`
	AvailabilityZone      string                       `json:"availability_zone"`
	Timeouts              ExecTimeouts                 `json:"timeouts"`
	OpenstackEnvVariables map[string]string            `json:"openstack_environment_variables"`
	SecurityGroups        map[string]*SecurityGroupDef `json:"security_groups"`
	Network               NetworkDef                   `json:"network"`
	Volumes               map[string]*VolumeDef        `json:"volumes"`
	FileGroupsUp          map[string]*FileGroupUpDef   `json:"file_groups_up"`
	FileGroupsDown        map[string]*FileGroupDownDef `json:"file_groups_down"`
	Instances             map[string]*InstanceDef      `json:"instances"`
}

func (*Project) SaveProject

func (prj *Project) SaveProject(fullPrjPath string) error

type ProjectPair

type ProjectPair struct {
	Template           Project
	Live               Project
	ProjectFileDirPath string
}

func LoadProject

func LoadProject(prjFile string, prjParamsFile string) (*ProjectPair, string, error)

func (*ProjectPair) CleanInstance

func (prjPair *ProjectPair) CleanInstance(iNickname string)

func (*ProjectPair) CleanSecurityGroup

func (prjPair *ProjectPair) CleanSecurityGroup(sgNickname string)

func (*ProjectPair) SetAttachedVolumeDevice

func (prjPair *ProjectPair) SetAttachedVolumeDevice(iNickname string, volNickname string, device string)

func (*ProjectPair) SetInstanceId

func (prjPair *ProjectPair) SetInstanceId(iNickname string, newId string)

func (*ProjectPair) SetNetworkId

func (prjPair *ProjectPair) SetNetworkId(newId string)

func (*ProjectPair) SetRouterId

func (prjPair *ProjectPair) SetRouterId(newId string)

func (*ProjectPair) SetSecurityGroupId

func (prjPair *ProjectPair) SetSecurityGroupId(sgNickname string, newId string)

func (*ProjectPair) SetSecurityGroupRuleId

func (prjPair *ProjectPair) SetSecurityGroupRuleId(sgNickname string, ruleIdx int, newId string)

func (*ProjectPair) SetSubnetId

func (prjPair *ProjectPair) SetSubnetId(newId string)

func (*ProjectPair) SetVolumeAttachmentId

func (prjPair *ProjectPair) SetVolumeAttachmentId(iNickname string, volNickname string, newId string)

func (*ProjectPair) SetVolumeBlockDeviceId

func (prjPair *ProjectPair) SetVolumeBlockDeviceId(iNickname string, volNickname string, newId string)

func (*ProjectPair) SetVolumeId

func (prjPair *ProjectPair) SetVolumeId(volNickname string, newId string)

type RouterDef

type RouterDef struct {
	Name                       string `json:"name"`
	Id                         string `json:"id"`
	ExternalGatewayNetworkName string `json:"external_gateway_network_name"`
}

type RouterInterfaceInfo

type RouterInterfaceInfo struct {
	PortId    string `json:"port_id"`
	IpAddress string `json:"ip_address"`
	SubnetId  string `json:"subnet_id"`
}

type SecurityGroupDef

type SecurityGroupDef struct {
	Name  string                  `json:"name"`
	Id    string                  `json:"id"`
	Rules []*SecurityGroupRuleDef `json:"rules"`
}

func (*SecurityGroupDef) Clean

func (sg *SecurityGroupDef) Clean()

type SecurityGroupRuleDef

type SecurityGroupRuleDef struct {
	Desc      string `json:"desc"`      // human-readable
	Id        string `json:"id"`        // guid
	Protocol  string `json:"protocol"`  // tcp
	Ethertype string `json:"ethertype"` // IPv4
	RemoteIp  string `json:"remote_ip"` // 0.0.0.0/0
	Port      int    `json:"port"`      // 22
	Direction string `json:"direction"` // ingress
}

type ServiceCommandsDef

type ServiceCommandsDef struct {
	Install []string `json:"install"`
	Config  []string `json:"config"`
	Start   []string `json:"start"`
	Stop    []string `json:"stop"`
}

type ServiceDef

type ServiceDef struct {
	Env map[string]string  `json:"env"`
	Cmd ServiceCommandsDef `json:"cmd"`
}

type SshConfigDef

type SshConfigDef struct {
	BastionIpAddress   string `json:"bastion_ip_address"`
	Port               int    `json:"port"`
	User               string `json:"user"`
	PrivateKeyPath     string `json:"private_key_path"`
	PrivateKeyPassword string `json:"private_key_password"`
}

type SubnetDef

type SubnetDef struct {
	Name           string `json:"name"`
	Id             string `json:"id"`
	Cidr           string `json:"cidr"`
	AllocationPool string `json:"allocation_pool"` //start=192.168.199.2,end=192.168.199.254
}

type TunneledSshClient

type TunneledSshClient struct {
	ProxySshClient  *ssh.Client
	TunneledTcpConn net.Conn
	TunneledSshConn ssh.Conn
	SshClient       *ssh.Client
}

func NewTunneledSshClient

func NewTunneledSshClient(sshConfig *SshConfigDef, ipAddress string) (*TunneledSshClient, error)

func (*TunneledSshClient) Close

func (tsc *TunneledSshClient) Close()

type UserDef

type UserDef struct {
	Name      string `json:"name"`
	PublicKey string `json:"public_key"`
}

type VolumeDef

type VolumeDef struct {
	Name        string `json:"name"`
	MountPoint  string `json:"mount_point"`
	Size        int    `json:"size"`
	Type        string `json:"type"`
	Permissions int    `json:"permissions"`
	Owner       string `json:"owner"`
	Id          string `json:"id"`
}

Jump to

Keyboard shortcuts

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