本文整理汇总了Golang中github.com/docker/machine/libmachine/mcnutils.GetHomeDir函数的典型用法代码示例。如果您正苦于以下问题:Golang GetHomeDir函数的具体用法?Golang GetHomeDir怎么用?Golang GetHomeDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetHomeDir函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetCreateFlags
// GetCreateFlags registers the flags this driver adds to
// "docker hosts create"
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
// TODO
return []mcnflag.Flag{
mcnflag.StringFlag{
EnvVar: "HYPRIOT_IP_ADDRESS",
Name: "hypriot-ip-address",
Usage: "IP Address of machine",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "HYPRIOT_SSH_USER",
Name: "hypriot-ssh-user",
Usage: "SSH user",
Value: "root",
},
mcnflag.StringFlag{
EnvVar: "HYPRIOT_SSH_KEY",
Name: "hypriot-ssh-key",
Usage: "SSH private key path",
Value: filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_rsa"),
},
mcnflag.IntFlag{
EnvVar: "HYPRIOT_SSH_PORT",
Name: "hypriot-ssh-port",
Usage: "SSH port",
Value: 22,
},
}
}
示例2: GetBaseDir
func GetBaseDir() string {
baseDir := os.Getenv("MACHINE_STORAGE_PATH")
if baseDir == "" {
baseDir = filepath.Join(mcnutils.GetHomeDir(), ".docker", "machine")
}
return baseDir
}
示例3: TestGetDockerDir
func TestGetDockerDir(t *testing.T) {
homeDir := mcnutils.GetHomeDir()
baseDir := GetBaseDir()
if strings.Index(baseDir, homeDir) != 0 {
t.Fatalf("expected base dir with prefix %s; received %s", homeDir, baseDir)
}
}
示例4: TestGetBaseDir
func TestGetBaseDir(t *testing.T) {
// reset any override env var
homeDir := mcnutils.GetHomeDir()
baseDir := GetBaseDir()
if strings.Index(baseDir, homeDir) != 0 {
t.Fatalf("expected base dir with prefix %s; received %s", homeDir, baseDir)
}
}
示例5: GetDefaultStore
func GetDefaultStore() *persist.Filestore {
homeDir := mcnutils.GetHomeDir()
certsDir := filepath.Join(homeDir, ".docker", "machine", "certs")
return &persist.Filestore{
Path: homeDir,
CaCertPath: certsDir,
CaPrivateKeyPath: certsDir,
}
}
示例6: SetConfigFromFlags
// SetConfigFromFlags configures the driver with the object that was returned
// by RegisterCreateFlags
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.CloudApiURL = flags.String("triton-url")
d.Account = flags.String("triton-account")
d.DataCenter = flags.String("triton-datacenter")
d.PrivateKey = flags.String("triton-key")
d.SkipTlsVerify = flags.Bool("triton-skip-tls-verify")
if d.CloudApiURL == "" {
if d.DataCenter == "" {
return fmt.Errorf("You must specify a cloudapi url or datacenter name")
}
// Shortend format for the cloudapi name, e.g. "us-east-1"
d.CloudApiURL = fmt.Sprintf("https://%s.%s", d.DataCenter, TritonDefaultCloudapiDomain)
}
if d.Account == "" {
return fmt.Errorf("You must specify the account name using --triton-account")
}
if d.PrivateKey == "" {
homedir := mcnutils.GetHomeDir()
if homedir == "" {
return fmt.Errorf("You must specify the SSH key using --triton-key")
}
d.PrivateKey = path.Join(homedir, ".ssh", "id_rsa")
}
_, err := os.Stat(d.PrivateKey)
if err != nil {
return fmt.Errorf("Unable to access SSH key file %s", d.PrivateKey)
}
log.Debugf("CloudApiURL: %s", d.CloudApiURL)
log.Debugf("Account: %s", d.Account)
log.Debugf("DataCenter: %s", d.DataCenter)
log.Debugf("PrivateKey: %s", d.PrivateKey)
log.Debugf("SkipTlsVerify: %d", d.SkipTlsVerify)
return nil
}
示例7: GetCreateFlags
"github.com/docker/machine/libmachine/state"
)
type Driver struct {
*drivers.BaseDriver
SSHKey string
}
const (
defaultSSHUser = "root"
defaultSSHPort = 22
defaultTimeout = 1 * time.Second
)
var (
defaultSSHKey = filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_rsa")
)
// GetCreateFlags registers the flags this driver adds to
// "docker hosts create"
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{
mcnflag.StringFlag{
Name: "generic-ip-address",
Usage: "IP Address of machine",
},
mcnflag.StringFlag{
Name: "generic-ssh-user",
Usage: "SSH user",
Value: defaultSSHUser,
},
示例8: CreateVM
func (d *Driver) CreateVM() error {
if err := d.b2dUpdater.CopyIsoToMachineDir(d.StorePath, d.MachineName, d.Boot2DockerURL); err != nil {
return err
}
log.Info("Creating VirtualBox VM...")
// import b2d VM if requested
if d.Boot2DockerImportVM != "" {
name := d.Boot2DockerImportVM
// make sure vm is stopped
_ = d.vbm("controlvm", name, "poweroff")
diskInfo, err := getVMDiskInfo(name, d.VBoxManager)
if err != nil {
return err
}
if _, err := os.Stat(diskInfo.Path); err != nil {
return err
}
if err := d.vbm("clonehd", diskInfo.Path, d.diskPath()); err != nil {
return err
}
log.Debugf("Importing VM settings...")
vmInfo, err := getVMInfo(name, d.VBoxManager)
if err != nil {
return err
}
d.CPU = vmInfo.CPUs
d.Memory = vmInfo.Memory
log.Debugf("Importing SSH key...")
keyPath := filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_boot2docker")
if err := mcnutils.CopyFile(keyPath, d.GetSSHKeyPath()); err != nil {
return err
}
} else {
log.Infof("Creating SSH key...")
if err := d.sshKeyGenerator.Generate(d.GetSSHKeyPath()); err != nil {
return err
}
log.Debugf("Creating disk image...")
if err := d.diskCreator.Create(d.DiskSize, d.publicSSHKeyPath(), d.diskPath()); err != nil {
return err
}
}
if err := d.vbm("createvm",
"--basefolder", d.ResolveStorePath("."),
"--name", d.MachineName,
"--register"); err != nil {
return err
}
log.Debugf("VM CPUS: %d", d.CPU)
log.Debugf("VM Memory: %d", d.Memory)
cpus := d.CPU
if cpus < 1 {
cpus = int(runtime.NumCPU())
}
if cpus > 32 {
cpus = 32
}
hostDNSResolver := "off"
if d.HostDNSResolver {
hostDNSResolver = "on"
}
dnsProxy := "off"
if d.DNSProxy {
dnsProxy = "on"
}
if err := d.vbm("modifyvm", d.MachineName,
"--firmware", "bios",
"--bioslogofadein", "off",
"--bioslogofadeout", "off",
"--bioslogodisplaytime", "0",
"--biosbootmenu", "disabled",
"--ostype", "Linux26_64",
"--cpus", fmt.Sprintf("%d", cpus),
"--memory", fmt.Sprintf("%d", d.Memory),
"--acpi", "on",
"--ioapic", "on",
"--rtcuseutc", "on",
"--natdnshostresolver1", hostDNSResolver,
"--natdnsproxy1", dnsProxy,
"--cpuhotplug", "off",
"--pae", "on",
"--hpet", "on",
"--hwvirtex", "on",
"--nestedpaging", "on",
//.........这里部分代码省略.........
示例9: tokenCachePath
// tokenCachePath returns the full path the OAuth 2.0 token should be saved at
// for given tenant ID.
func tokenCachePath(tenantID string) string {
return filepath.Join(mcnutils.GetHomeDir(), ".docker", "machine", "credentials", "azure", fmt.Sprintf("%s.json", tenantID))
}
示例10: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
if d.IsVTXDisabled() {
// Let's log a warning to warn the user. When the vm is started, logs
// will be checked for an error anyway.
// We could fail right here but the method to check didn't prove being
// bulletproof.
log.Warn("This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory.")
}
log.Infof("Creating VirtualBox VM...")
// import b2d VM if requested
if d.Boot2DockerImportVM != "" {
name := d.Boot2DockerImportVM
// make sure vm is stopped
_ = d.vbm("controlvm", name, "poweroff")
diskInfo, err := d.getVMDiskInfo(name)
if err != nil {
return err
}
if _, err := os.Stat(diskInfo.Path); err != nil {
return err
}
if err := d.vbm("clonehd", diskInfo.Path, d.diskPath()); err != nil {
return err
}
log.Debugf("Importing VM settings...")
vmInfo, err := d.getVMInfo(name)
if err != nil {
return err
}
d.CPU = vmInfo.CPUs
d.Memory = vmInfo.Memory
log.Debugf("Importing SSH key...")
keyPath := filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_boot2docker")
if err := mcnutils.CopyFile(keyPath, d.GetSSHKeyPath()); err != nil {
return err
}
} else {
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Debugf("Creating disk image...")
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
}
if err := d.vbm("createvm",
"--basefolder", d.ResolveStorePath("."),
"--name", d.MachineName,
"--register"); err != nil {
return err
}
log.Debugf("VM CPUS: %d", d.CPU)
log.Debugf("VM Memory: %d", d.Memory)
cpus := d.CPU
if cpus < 1 {
cpus = int(runtime.NumCPU())
}
if cpus > 32 {
cpus = 32
}
if err := d.vbm("modifyvm", d.MachineName,
"--firmware", "bios",
"--bioslogofadein", "off",
"--bioslogofadeout", "off",
"--bioslogodisplaytime", "0",
"--biosbootmenu", "disabled",
"--ostype", "Linux26_64",
"--cpus", fmt.Sprintf("%d", cpus),
"--memory", fmt.Sprintf("%d", d.Memory),
"--acpi", "on",
"--ioapic", "on",
"--rtcuseutc", "on",
"--natdnshostresolver1", "off",
"--natdnsproxy1", "off",
"--cpuhotplug", "off",
"--pae", "on",
"--hpet", "on",
"--hwvirtex", "on",
"--nestedpaging", "on",
"--largepages", "on",
//.........这里部分代码省略.........
示例11: azureCredsPath
// azureCredsPath returns the directory the azure credentials are stored in.
func azureCredsPath() string {
return filepath.Join(mcnutils.GetHomeDir(), ".docker", "machine", "credentials", "azure")
}
示例12: GetDockerDir
func GetDockerDir() string {
return filepath.Join(mcnutils.GetHomeDir(), ".docker")
}
示例13: GetBaseDir
func GetBaseDir() string {
if BaseDir == "" {
BaseDir = filepath.Join(mcnutils.GetHomeDir(), ".docker", "machine")
}
return BaseDir
}
示例14:
"azure-location": "West US",
"azure-size": "Small",
"azure-ssh-port": 22,
"azure-username": "ubuntu",
"digitalocean-image": "ubuntu-14-04-x64",
"digitalocean-region": "nyc3",
"digitalocean-size": "512mb",
"exoscale-instance-profile": "small",
"exoscale-disk-size": 50,
"exoscale-image": "ubuntu-14.04",
"exoscale-availability-zone": "ch-gva-2",
"generic-ssh-user": "root",
"generic-ssh-key": filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_rsa"),
"generic-ssh-port": 22,
"google-zone": "us-central1-a",
"google-machine-type": "f1-micro",
"google-username": "docker-user",
"google-scopes": "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write",
"google-disk-size": "pd-standard",
"google-disk-type": 10,
"hyper-v-disk-size": 20000,
"hyper-v-memory": 1024,
"openstack-ssh-user": "root",
"openstack-ssh-port": 22,
"openstack-active-timeout": 200,