cloudfoundry-community/bosh-cloudstack-cpi

View on GitHub
go_agent/src/bosh/infrastructure/aws_infrastructure.go

Summary

Maintainability
C
7 hrs
Test Coverage
package infrastructure

import (
    bosherr "bosh/errors"
    boshdpresolv "bosh/infrastructure/devicepathresolver"
    boshlog "bosh/logger"
    boshplatform "bosh/platform"
    boshsettings "bosh/settings"
)

const awsInfrastructureLogTag = "awsInfrastructure"

type awsInfrastructure struct {
    metadataService    MetadataService
    registry           Registry
    platform           boshplatform.Platform
    devicePathResolver boshdpresolv.DevicePathResolver
    logger             boshlog.Logger
}

func NewAwsInfrastructure(
    metadataService MetadataService,
    registry Registry,
    platform boshplatform.Platform,
    devicePathResolver boshdpresolv.DevicePathResolver,
    logger boshlog.Logger,
) (inf awsInfrastructure) {
    inf.metadataService = metadataService
    inf.registry = registry
    inf.platform = platform
    inf.devicePathResolver = devicePathResolver
    inf.logger = logger
    return
}

func (inf awsInfrastructure) GetDevicePathResolver() boshdpresolv.DevicePathResolver {
    return inf.devicePathResolver
}

func (inf awsInfrastructure) SetupSSH(username string) error {
    publicKey, err := inf.metadataService.GetPublicKey()
    if err != nil {
        return bosherr.WrapError(err, "Error getting public key")
    }

    return inf.platform.SetupSSH(publicKey, username)
}

func (inf awsInfrastructure) GetSettings() (boshsettings.Settings, error) {
    settings, err := inf.registry.GetSettings()
    if err != nil {
        return settings, bosherr.WrapError(err, "Getting settings from registry")
    }

    return settings, nil
}

func (inf awsInfrastructure) SetupNetworking(networks boshsettings.Networks) (err error) {
    return inf.platform.SetupDhcp(networks)
}

func (inf awsInfrastructure) GetEphemeralDiskPath(devicePath string) (realPath string, found bool) {
    if devicePath == "" {
        inf.logger.Info(awsInfrastructureLogTag, "Ephemeral disk path is empty")
        return "", false
    }

    return inf.platform.NormalizeDiskPath(devicePath)
}