This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Package

Carbon main package
import "github.com/analog-substance/carbon"

Carbon main package

Index

1 - carbon

Package carbon provides core application functionality and constants
import "github.com/analog-substance/carbon/pkg/carbon"

Package carbon provides core application functionality and constants

Index

Constants

const CloudInitDir = "cloud-init"

const ISOVarUsage = "var.iso_url"

const PackerFileIsoVars = "iso-variables.pkr.hcl"

const PackerFileLocalVars = "local-variables.pkr.hcl"

const PackerFilePacker = "packer.pkr.hcl"

const PackerFilePrivateVarsExample = "private.auto.pkrvars.hcl.example"

const PackerFileSuffixAnsible = "-ansible.pkr.hcl"

const PackerFileSuffixCloudInit = "-cloud-init.pkr.hcl"

const PackerFileSuffixVariables = "-variables.pkr.hcl"

Variables

var AllProviders = []types.Provider{
    aws.New(),
    qemu.New(),
    virtualbox.New(),
    multipass.New(),
    digitalocean.New(),
    vsphere.New(),
}

func AvailableProviders

func AvailableProviders() []types.Provider

type Carbon

type Carbon struct {
    // contains filtered or unexported fields
}

func New

func New(config common.CarbonConfig) *Carbon

func (*Carbon) FindVMByID

func (c *Carbon) FindVMByID(id string) []types.VM

func (*Carbon) FindVMByName

func (c *Carbon) FindVMByName(name string) []types.VM

func (*Carbon) GetConfig

func (c *Carbon) GetConfig() common.CarbonConfig

func (*Carbon) GetImage

func (c *Carbon) GetImage(imageID string) (types.Image, error)

func (*Carbon) GetImageBuild

func (c *Carbon) GetImageBuild(name, provider, provisioner string) (types.ImageBuild, error)

func (*Carbon) GetImageBuildTemplates

func (c *Carbon) GetImageBuildTemplates() []string

func (*Carbon) GetImageBuilds

func (c *Carbon) GetImageBuilds() ([]types.ImageBuild, error)

func (*Carbon) GetImages

func (c *Carbon) GetImages() ([]types.Image, error)

func (*Carbon) GetProject

func (c *Carbon) GetProject(name string) (types.Project, error)

func (*Carbon) GetProjects

func (c *Carbon) GetProjects() ([]types.Project, error)

func (*Carbon) GetProvider

func (c *Carbon) GetProvider(providerType string) (types.Provider, error)

func (*Carbon) GetVMs

func (c *Carbon) GetVMs() []types.VM

func (*Carbon) Profiles

func (c *Carbon) Profiles() []types.Profile

func (*Carbon) Providers

func (c *Carbon) Providers() []types.Provider

func (*Carbon) VMsFromHosts

func (c *Carbon) VMsFromHosts(hostnames []string) []types.VM

type Options

type Options struct {
    Providers    []string
    Profiles     []string
    Environments []string
}

2 - cloud_init

import "github.com/analog-substance/carbon/pkg/cloud_init"

Index

type AptSource

type AptSource struct {
    Source string `yaml:"source"`
    Keyid  string `yaml:"keyid"`
}

type CloudConfig

type CloudConfig struct {
    Timezone          string   `yaml:"timezone"`
    SSHDeletekeys     bool     `yaml:"ssh_deletekeys"`
    SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
    Apt               struct {
        Sources map[string]AptSource `yaml:"sources"`
    }   `yaml:"apt"`
    WriteFiles     []WriteFile `yaml:"write_files"`
    PackageUpgrade bool        `yaml:"package_upgrade"`
    Packages       []string    `yaml:"packages"`
    Runcmd         [][]string  `yaml:"runcmd"`
}

func (*CloudConfig) MergeWith

func (c *CloudConfig) MergeWith(otherConfig *CloudConfig)

type WriteFile

type WriteFile struct {
    Path        string `yaml:"path"`
    Content     string `yaml:"content"`
    Owner       string `yaml:"owner"`
    Permissions string `yaml:"permissions"`
    Encoding    string `yaml:"encoding,omitempty"`
}

3 - cmd

import "github.com/analog-substance/carbon/pkg/cmd"

Index

Variables

CarbonCmd represents the base command when called without any subcommands

var CarbonCmd = &cobra.Command{
    Use:   "carbon",
    Short: "Carbon - Infrastructure automation for offensive operations.",
    Long: `Infrastructure automation for offensive operations.
- ℹ️ Checkout the latest docs [here](https://analog-substance.github.io/carbon/)
- 😢 Have a problem? [Create an Issue](https://github.com/analog-substance/carbon/issues/new?title=Something%20is%20broken)
- ❤️ Enjoying Carbon? [Star the Repo](https://github.com/analog-substance/carbon)

## Purpose

Carbon's primary purpose is to provide a consistent execution environment to
facilitate offensive security assessments.

## Dependencies

- Packer to build images.
- Terraform to provision infrastructure.
- Golang project structure.

## Supported Providers

- AWS
- QEMU (Local)
- VirtualBox (Local)
- vSphere (in progress)
- Multipass (Local)

There are plans to bring support to the following:

- GCP
- Azure
- VMware (Local)
- QEMU (Remote)
`,
    PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

        if debug {
            common.LogLevel(slog.LevelDebug)
        }
        log.Debug("debug mode", "debug", debug)

        carbonConfigFile := common.GetConfig()
        home, err := homedir.Dir()
        if err != nil {
            log.Debug("error getting home directory", "error", err)
        } else {
            err := carbonConfigFile.MergeInConfigFile(filepath.Join(home, cfgFileName))

            if err != nil {
                log.Debug("error loading carbon config from home", "error", err)
            }
        }

        err = carbonConfigFile.MergeInConfigFile(cfgFileName)
        if err != nil {
            log.Debug("error loading carbon config from home", "error", err)
        }

        carbonObj = carbon.New(carbonConfigFile.Carbon)
        updateConfigHelp()

        return nil
    },
}

func AskIfSure

func AskIfSure(msg string) bool

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func ListingDir

func ListingDir(dir string)

4 - common

import "github.com/analog-substance/carbon/pkg/common"

Index

Constants

const DefaultDeploymentsDirName = "deployments"

const DefaultImagesDirName = "images"

const DefaultInstanceConfigKey = "instance"

const DefaultInstanceDir = "."

const DefaultPackerDirName = "packer"

const DefaultProjectsDirName = "projects"

const DefaultTerraformDirName = "terraform"

const DeploymentsConfigKey = "deployments"

const ImagesConfigKey = "images"

const PackerConfigKey = "packer"

const TerraformConfigKey = "terraform"

const TerraformProjectConfigKey = "projects"

func Get

func Get(s string) any

func ImagesDir

func ImagesDir() string

func Keys

func Keys() []string

func LogLevel

func LogLevel(level slog.Level)

func Logger

func Logger() *slog.Logger

func PackerDir

func PackerDir() string

func ProjectsDir

func ProjectsDir() string

func Set

func Set(s string, v any) any

func SetProvidersTypes

func SetProvidersTypes(p []string)

func Time

func Time(what string) func()

func WithGroup

func WithGroup(groupName string) *slog.Logger

type CarbonConfig

type CarbonConfig struct {
    Dir       map[string]string         `yaml:"dir"`
    Providers map[string]ProviderConfig `yaml:"providers"`
}

func (*CarbonConfig) Get

func (cc *CarbonConfig) Get(search []string) any

func (*CarbonConfig) Keys

func (cc *CarbonConfig) Keys(prefix string) []string

func (*CarbonConfig) Set

func (cc *CarbonConfig) Set(search []string, val any) *CarbonConfig

type CarbonConfigFile

type CarbonConfigFile struct {
    Carbon CarbonConfig `yaml:"carbon"`
}

func GetConfig

func GetConfig() *CarbonConfigFile

func (*CarbonConfigFile) Get

func (cf *CarbonConfigFile) Get(search []string) any

func (*CarbonConfigFile) Keys

func (cf *CarbonConfigFile) Keys() []string

func (*CarbonConfigFile) MergeInConfigFile

func (cf *CarbonConfigFile) MergeInConfigFile(cfgFile string) error

func (*CarbonConfigFile) Set

func (cf *CarbonConfigFile) Set(search []string, val any) *CarbonConfigFile

type ProfileConfig

type ProfileConfig struct {
    Enabled         bool            `yaml:"enabled"`
    Username        string          `yaml:"username" `
    Password        string          `yaml:"password" `
    PasswordCommand string          `yaml:"password_command"`
    Use1PassCLI     bool            `yaml:"use_1pass_cli" `
    URL             string          `yaml:"url"`
    Environments    map[string]bool `yaml:"environments"`
}

func DefaultProfileConfig

func DefaultProfileConfig() ProfileConfig

func (*ProfileConfig) Get

func (pc *ProfileConfig) Get(search []string) any

func (*ProfileConfig) GetPassword

func (pc *ProfileConfig) GetPassword() string

func (*ProfileConfig) Keys

func (pc *ProfileConfig) Keys(prefix string) []string

func (*ProfileConfig) Set

func (pc *ProfileConfig) Set(search []string, val any) *ProfileConfig

func (*ProfileConfig) UnmarshalYAML

func (pc *ProfileConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type ProviderConfig

type ProviderConfig struct {
    Enabled      bool                     `yaml:"enabled"`
    AutoDiscover bool                     `yaml:"auto_discover"`
    Profiles     map[string]ProfileConfig `yaml:"profiles"`
}

func DefaultProviderConfig

func DefaultProviderConfig() ProviderConfig

func (*ProviderConfig) Get

func (pc *ProviderConfig) Get(search []string) any

func (*ProviderConfig) Keys

func (pc *ProviderConfig) Keys(prefix string) []string

func (*ProviderConfig) Set

func (pc *ProviderConfig) Set(search []string, val any) *ProviderConfig

func (*ProviderConfig) UnmarshalYAML

func (pc *ProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

5 - models

import "github.com/analog-substance/carbon/pkg/models"

Index

func GetImageBuildsForProvider

func GetImageBuildsForProvider(provider string) ([]types.ImageBuild, error)

func NewImage

func NewImage(imageID string, imageName string, createdAt time.Time, env types.Environment) types.Image

type BuildBlock

type BuildBlock struct {
    Name        string   `hcl:"name,optional"`
    Description string   `hcl:"description,optional"`
    FromSources []string `hcl:"sources,optional"`
    Config      hcl.Body `hcl:",remain"`
}

type Image

type Image struct {
    // contains filtered or unexported fields
}

func (*Image) CreatedAt

func (i *Image) CreatedAt() string

func (*Image) Destroy

func (i *Image) Destroy() error

func (*Image) Environment

func (i *Image) Environment() types.Environment

func (*Image) ID

func (i *Image) ID() string

func (*Image) Launch

func (i *Image) Launch(imageLaunchOptions types.ImageLaunchOptions) error

func (*Image) MarshalJSON

func (i *Image) MarshalJSON() ([]byte, error)

func (*Image) Name

func (i *Image) Name() string

func (*Image) Profile

func (i *Image) Profile() types.Profile

func (*Image) Provider

func (i *Image) Provider() types.Provider

type ImageBuild

type ImageBuild struct {
    // contains filtered or unexported fields
}

func NewImageBuild

func NewImageBuild(buildPath, provider, provisioner string) *ImageBuild

func (*ImageBuild) Build

func (b *ImageBuild) Build() error

func (*ImageBuild) MarshalJSON

func (b *ImageBuild) MarshalJSON() ([]byte, error)

func (*ImageBuild) Name

func (b *ImageBuild) Name() string

func (*ImageBuild) ProviderType

func (b *ImageBuild) ProviderType() string

func (*ImageBuild) Provisioner

func (b *ImageBuild) Provisioner() string

type Machine

type Machine struct {
    InstanceName       string             `json:"name"`
    InstanceID         string             `json:"id"`
    CurrentUpTime      time.Duration      `json:"up_time"`
    InstanceType       string             `json:"type"`
    PublicIPAddresses  []string           `json:"public_ip_addresses"`
    PrivateIPAddresses []string           `json:"private_ip_addresses"`
    CurrentState       types.MachineState `json:"current_state"`
    Env                types.Environment  `json:"-"`
}

func (*Machine) Cmd

func (m *Machine) Cmd(user string, privateIP bool, cmdArgs ...string) (string, error)

func (*Machine) Destroy

func (m *Machine) Destroy() error

func (*Machine) Environment

func (m *Machine) Environment() types.Environment

func (*Machine) ExecSSH

func (m *Machine) ExecSSH(user string, privateIP bool, cmdArgs ...string) error

func (*Machine) ID

func (m *Machine) ID() string

func (*Machine) IPAddress

func (m *Machine) IPAddress() string

func (*Machine) Name

func (m *Machine) Name() string

func (*Machine) NewSSHSession

func (m *Machine) NewSSHSession(user string, privateIP bool) (*ssh_util.Session, error)

func (*Machine) PrivateIPAddress

func (m *Machine) PrivateIPAddress() string

func (*Machine) Profile

func (m *Machine) Profile() types.Profile

func (*Machine) Provider

func (m *Machine) Provider() types.Provider

func (*Machine) Restart

func (m *Machine) Restart() error

func (*Machine) Start

func (m *Machine) Start() error

func (*Machine) StartRDPClient

func (m *Machine) StartRDPClient(user string, privateIP bool) error

func (*Machine) StartVNC

func (m *Machine) StartVNC(user string, privateIP bool, killVNC bool) error

StartVNC will create a VNC session on the virtual machine It accomplishes this by:

  • SSH to the VM.
  • Start VNC if it is not already running.
  • Forward a port through the SSH session.
  • VNC to the forwarded port.

Requires TigerVNC to be installed.

func (*Machine) State

func (m *Machine) State() string

func (*Machine) Stop

func (m *Machine) Stop() error

func (*Machine) Type

func (m *Machine) Type() string

func (*Machine) UpTime

func (m *Machine) UpTime() time.Duration

type PackerConfig

type PackerConfig struct {
    Source SourceBlock `hcl:"source,block"`
    Build  BuildBlock  `hcl:"build,block"`
}

type Project

type Project struct {
    // contains filtered or unexported fields
}

func NewProject

func NewProject(buildPath string) *Project

func (*Project) AddMachine

func (d *Project) AddMachine(machine *types.ProjectMachine, noApply bool) error

func (*Project) GetConfig

func (d *Project) GetConfig() (*types.ProjectConfig, error)

func (*Project) MarshalJSON

func (d *Project) MarshalJSON() ([]byte, error)

func (*Project) Name

func (d *Project) Name() string

func (*Project) SaveConfig

func (d *Project) SaveConfig() error

func (*Project) TerraformApply

func (d *Project) TerraformApply() error

type SourceBlock

type SourceBlock struct {
    Type   string   `hcl:"type,label"`
    Name   string   `hcl:"name,label"`
    Config hcl.Body `hcl:",remain"`
}

6 - Providers

6.1 - aws

Package aws handles communications with AWS APIs
import "github.com/analog-substance/carbon/pkg/providers/aws"

Package aws handles communications with AWS APIs

Index

func New

func New() types.Provider

New creates new instance of an AWS Provider and returns it. Defaults to no awsProfileNames, this forces a query of the AWS config at runtime.

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) AWSProfiles

func (p *Provider) AWSProfiles() []string

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

6.2 - base

import "github.com/analog-substance/carbon/pkg/providers/base"

Index

Constants

const CloudInitDir = "cloud-init"

const ISOVarUsage = "var.iso_url"

const PackerFileIsoVars = "iso-variables.pkr.hcl"

const PackerFileLocalVars = "local-variables.pkr.hcl"

const PackerFilePacker = "packer.pkr.hcl"

const PackerFilePrivateVarsExample = "private.auto.pkrvars.hcl.example"

const PackerFileSuffixAnsible = "-ansible.pkr.hcl"

const PackerFileSuffixCloudInit = "-cloud-init.pkr.hcl"

const PackerFileSuffixVariables = "-variables.pkr.hcl"

func DestroyImageForFileBasedProvider

func DestroyImageForFileBasedProvider(imageID string) error

func GetImagesForFileBasedProvider

func GetImagesForFileBasedProvider(providerType string, e types.Environment) ([]types.Image, error)

func New

func New() types.Provider

func NewProfile

func NewProfile(name string, providerInstance types.Provider, config common.ProfileConfig) types.Profile

func NewWithName

func NewWithName(name string) types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type ImageBuildDate

type ImageBuildDate struct {
    Name string
}

type Profile

type Profile struct {
    // contains filtered or unexported fields
}

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

func (*Profile) GetConfig

func (p *Profile) GetConfig() common.ProfileConfig

func (*Profile) Name

func (p *Profile) Name() string

func (*Profile) Provider

func (p *Profile) Provider() types.Provider

func (*Profile) SetConfig

func (p *Profile) SetConfig(config common.ProfileConfig)

func (*Profile) ShouldIncludeEnvironment

func (p *Profile) ShouldIncludeEnvironment(envName string) bool

type Provider

type Provider struct {
    // contains filtered or unexported fields
}

func (*Provider) GetConfig

func (p *Provider) GetConfig() common.ProviderConfig

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) NewImageBuild

func (p *Provider) NewImageBuild(name, tplDir string) (types.ImageBuild, error)

func (*Provider) NewProject

func (p *Provider) NewProject(name string, force bool) (types.Project, error)

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

func (*Provider) SetConfig

func (p *Provider) SetConfig(config common.ProviderConfig)

func (*Provider) Type

func (p *Provider) Type() string

6.3 - digitalocean

import "github.com/analog-substance/carbon/pkg/providers/digitalocean"

Index

func New

func New() types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
    // contains filtered or unexported fields
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

6.4 - example

import "github.com/analog-substance/carbon/pkg/providers/example"

Index

func New

func New() types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

6.5 - multipass

import "github.com/analog-substance/carbon/pkg/providers/multipass"

Index

func New

func New() types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

6.5.1 - api

import "github.com/analog-substance/carbon/pkg/providers/multipass/api"

Index

func AppPath

func AppPath() string

func RestartVM

func RestartVM(id string) error

func SleepVM

func SleepVM(id string) error

func StartVM

func StartVM(id string) error

type MultipassListOutput

type MultipassListOutput struct {
    List []MultipassVM `json:"list"`
}

type MultipassVM

type MultipassVM struct {
    Ipv4    []string `json:"ipv4"`
    Name    string   `json:"name"`
    Release string   `json:"release"`
    State   string   `json:"state"`
}

func ListVMs

func ListVMs() []MultipassVM

6.6 - qemu

import "github.com/analog-substance/carbon/pkg/providers/qemu"

Index

func New

func New() types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

6.6.1 - api

import "github.com/analog-substance/carbon/pkg/providers/qemu/api"

Index

type Domain

type Domain struct {
    LVDomain *libvirt.Domain

    LVDomainState *libvirt.DomainState
    ID            string
    Name          string

    PublicIPAddresses  []string
    PrivateIPAddresses []string
    CurrentUpTime      time.Duration
    // contains filtered or unexported fields
}

func (*Domain) Destroy

func (d *Domain) Destroy() error

func (*Domain) Reboot

func (d *Domain) Reboot() error

func (*Domain) Start

func (d *Domain) Start() error

func (*Domain) Suspend

func (d *Domain) Suspend() error

type QEMU

type QEMU struct {
    // contains filtered or unexported fields
}

func Connect

func Connect(libVirtURL string) (*QEMU, error)

func (*QEMU) AllNetworks

func (q *QEMU) AllNetworks() ([]libvirt.Network, error)

func (*QEMU) Close

func (q *QEMU) Close() error

func (*QEMU) CreateDomain

func (q *QEMU) CreateDomain(name string, storageVol *StorageVolume) (*Domain, error)

func (*QEMU) GetDomain

func (q *QEMU) GetDomain(id string) (*Domain, error)

func (*QEMU) GetDomains

func (q *QEMU) GetDomains() ([]*Domain, error)

func (*QEMU) GetStoragePool

func (q *QEMU) GetStoragePool(name string) (*StoragePool, error)

func (*QEMU) GetStoragePools

func (q *QEMU) GetStoragePools() ([]*StoragePool, error)

type StoragePool

type StoragePool struct {
    LVStoragePool *libvirt.StoragePool
    Volumes       []*StorageVolume
    // contains filtered or unexported fields
}

func (*StoragePool) GetVolumes

func (s *StoragePool) GetVolumes() ([]*StorageVolume, error)

func (*StoragePool) ImportImage

func (s *StoragePool) ImportImage(name string, imageFile string) (*StorageVolume, error)

type StorageVolume

type StorageVolume struct {
    LVStorageVolume *libvirt.StorageVol
    // contains filtered or unexported fields
}

6.7 - virtualbox

import "github.com/analog-substance/carbon/pkg/providers/virtualbox"

Index

func New

func New() types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

6.7.1 - api

import "github.com/analog-substance/carbon/pkg/providers/virtualbox/api"

Index

func AppPath

func AppPath() string

func RestartVM

func RestartVM(id string) error

func SleepVM

func SleepVM(id string) error

func StartVM

func StartVM(id string) error

type VBoxVM

type VBoxVM struct {
    Name               string
    ID                 string
    State              string
    GuestOS            string
    UpTime             time.Duration
    PrivateIPAddresses []string
    // contains filtered or unexported fields
}

func ListVMs

func ListVMs() []VBoxVM

6.8 - vsphere

import "github.com/analog-substance/carbon/pkg/providers/vsphere"

Index

func New

func New() types.Provider

type Environment

type Environment struct {
    // contains filtered or unexported fields
}

func (*Environment) CreateVM

func (e *Environment) CreateVM(options types.MachineLaunchOptions) error

func (*Environment) DestroyImage

func (e *Environment) DestroyImage(imageID string) error

func (*Environment) DestroyVM

func (e *Environment) DestroyVM(id string) error

func (*Environment) ImageBuilds

func (e *Environment) ImageBuilds() ([]types.ImageBuild, error)

func (*Environment) Images

func (e *Environment) Images() ([]types.Image, error)

func (*Environment) Name

func (e *Environment) Name() string

func (*Environment) Profile

func (e *Environment) Profile() types.Profile

func (*Environment) RestartVM

func (e *Environment) RestartVM(id string) error

func (*Environment) StartVM

func (e *Environment) StartVM(id string) error

func (*Environment) StopVM

func (e *Environment) StopVM(id string) error

func (*Environment) VMs

func (e *Environment) VMs() []types.VM

type Profile

type Profile struct {
    types.Profile
    // contains filtered or unexported fields
}

func NewProfile

func NewProfile(name string, providerInstance *Provider, config common.ProfileConfig) *Profile

func (*Profile) Environments

func (p *Profile) Environments() []types.Environment

type Provider

type Provider struct {
    types.Provider
    // contains filtered or unexported fields
}

func (*Provider) IsAvailable

func (p *Provider) IsAvailable() bool

func (*Provider) Profiles

func (p *Provider) Profiles() []types.Profile

7 - rdp_client

import "github.com/analog-substance/carbon/pkg/rdp_client"

Index

func Start

func Start(options Options) error

func StartRDPClient

func StartRDPClient(options Options) error

type Options

type Options struct {
    Delay int
    User  string
    Host  string
}

8 - ssh_util

import "github.com/analog-substance/carbon/pkg/ssh_util"

Index

type Session

type Session struct {
    Session *ssh.Session
    Client  *ssh.Client
    // contains filtered or unexported fields
}

func NewSession

func NewSession() (*Session, error)

func (*Session) ClientConfig

func (session *Session) ClientConfig(user string) *ssh.ClientConfig

func (*Session) Close

func (session *Session) Close()

func (*Session) Connect

func (session *Session) Connect(serverAddr, user string) error

func (*Session) ForwardAgent

func (session *Session) ForwardAgent() error

func (*Session) ForwardLocalPort

func (session *Session) ForwardLocalPort(localPort, remotePort int) error

func (*Session) Output

func (session *Session) Output(cmd string) (string, error)

Output uses ssh_util.Session to run cmd on the remote host and returns its standard output.

9 - types

import "github.com/analog-substance/carbon/pkg/types"

Index

Variables

var StateRunning = MachineState{"Running"}

var StateSleeping = MachineState{"Sleeping"}

var StateStarting = MachineState{"Starting"}

var StateStopped = MachineState{"Stopped"}

var StateStopping = MachineState{"Stopping"}

var StateTerminated = MachineState{"Terminated"}

var StateTerminating = MachineState{"Terminating"}

var StateUnknown = MachineState{"Unknown"}

type Environment

type Environment interface {
    Name() string
    VMs() []VM
    Profile() Profile
    StartVM(string) error
    StopVM(string) error
    RestartVM(string) error
    ImageBuilds() ([]ImageBuild, error)
    Images() ([]Image, error)
    CreateVM(MachineLaunchOptions) error
    DestroyVM(string) error
    DestroyImage(string) error
}

type Image

type Image interface {
    ID() string
    Name() string
    CreatedAt() string
    Environment() Environment
    Profile() Profile
    Provider() Provider
    Launch(imageLaunchOptions ImageLaunchOptions) error
    Destroy() error
}

type ImageBuild

type ImageBuild interface {
    Name() string
    ProviderType() string
    Provisioner() string
    Build() error
}

type ImageLaunchOptions

type ImageLaunchOptions struct {
    Name string
}

type MachineLaunchOptions

type MachineLaunchOptions struct {
    CloudInitTpl string `json:"cloud-init"`
    Image        Image  `json:"image"`
    Name         string `json:"name"`
}

type MachineState

type MachineState struct {
    Name string `json:"name"`
}

type Profile

type Profile interface {
    Environments() []Environment
    Name() string
    Provider() Provider
    SetConfig(config common.ProfileConfig)
    GetConfig() common.ProfileConfig
    ShouldIncludeEnvironment(envName string) bool
}

type Project

type Project interface {
    Name() string
    TerraformApply() error
    AddMachine(machine *ProjectMachine, noApply bool) error
}

type ProjectConfig

type ProjectConfig struct {
    Machines []*ProjectMachine `yaml:"machines"`
}

type ProjectMachine

type ProjectMachine struct {
    Name       string `yaml:"name"`
    Image      string `yaml:"image,omitempty"`
    Type       string `yaml:"type,omitempty"`
    Profile    string `yaml:"profile,omitempty"`
    Purpose    string `yaml:"purpose,omitempty"`
    VolumeSize int    `yaml:"volume_size,omitempty"`
    Provider   string `yaml:"provider,omitempty"`
}

type Provider

type Provider interface {
    Profiles() []Profile
    Name() string
    Type() string
    IsAvailable() bool
    SetConfig(config common.ProviderConfig)
    GetConfig() common.ProviderConfig
    NewImageBuild(name string, tplDir string) (ImageBuild, error)
    NewProject(name string, force bool) (Project, error)
}

type VM

VM interface provides access to useful information and actions related to Virtual Machines

type VM interface {
    // Name returns the name of a virtual machine
    Name() string

    // ID returns the ID of the virtual machine
    ID() string

    // IPAddress returns the public IP address of the virtual machine
    IPAddress() string

    // PrivateIPAddress of the virtual machine
    PrivateIPAddress() string
    UpTime() time.Duration
    State() string
    Type() string

    Environment() Environment
    Profile() Profile
    Provider() Provider

    Destroy() error
    Start() error
    Stop() error
    Restart() error

    ExecSSH(string, bool, ...string) error
    StartVNC(user string, privateIP bool, killVNC bool) error
    StartRDPClient(user string, privateIP bool) error
    Cmd(string, bool, ...string) (string, error)
    NewSSHSession(string, bool) (*ssh_util.Session, error)
}

10 - vnc_viewer

import "github.com/analog-substance/carbon/pkg/vnc_viewer"

Index

func Start

func Start(options Options) error

func StartViewer

func StartViewer(options Options) error

type Options

type Options struct {
    Delay        int
    PasswordFile string
    Host         string
}