1 Star 0 Fork 0

litian/machine

加入 Gitee
與超過 1200 萬 開發者一起發現、參與優秀開源項目,私有倉庫也完全免費 :)
免費加入
文件
克隆/下載
ubuntu.go 3.24 KB
一鍵複製 編輯 原始數據 按行查看 歷史
package provision
import (
"fmt"
"github.com/docker/machine/drivers"
"github.com/docker/machine/libmachine/auth"
"github.com/docker/machine/libmachine/engine"
"github.com/docker/machine/libmachine/provision/pkgaction"
"github.com/docker/machine/libmachine/swarm"
"github.com/docker/machine/log"
"github.com/docker/machine/utils"
)
func init() {
Register("Ubuntu", &RegisteredProvisioner{
New: NewUbuntuProvisioner,
})
}
func NewUbuntuProvisioner(d drivers.Driver) Provisioner {
return &UbuntuProvisioner{
GenericProvisioner{
DockerOptionsDir: "/etc/docker",
DaemonOptionsFile: "/etc/default/docker",
OsReleaseId: "ubuntu",
Packages: []string{
"curl",
},
Driver: d,
},
}
}
type UbuntuProvisioner struct {
GenericProvisioner
}
func (provisioner *UbuntuProvisioner) Service(name string, action pkgaction.ServiceAction) error {
command := fmt.Sprintf("sudo service %s %s", name, action.String())
if _, err := provisioner.SSHCommand(command); err != nil {
return err
}
return nil
}
func (provisioner *UbuntuProvisioner) Package(name string, action pkgaction.PackageAction) error {
var (
packageAction string
updateMetadata = true
)
switch action {
case pkgaction.Install:
packageAction = "install"
case pkgaction.Remove:
packageAction = "remove"
updateMetadata = false
case pkgaction.Upgrade:
packageAction = "upgrade"
}
// TODO: This should probably have a const
switch name {
case "docker":
name = "lxc-docker"
}
if updateMetadata {
// issue apt-get update for metadata
if _, err := provisioner.SSHCommand("sudo -E apt-get update"); err != nil {
return err
}
}
command := fmt.Sprintf("DEBIAN_FRONTEND=noninteractive sudo -E apt-get %s -y %s", packageAction, name)
if _, err := provisioner.SSHCommand(command); err != nil {
return err
}
return nil
}
func (provisioner *UbuntuProvisioner) dockerDaemonResponding() bool {
if _, err := provisioner.SSHCommand("sudo docker version"); err != nil {
log.Warnf("Error getting SSH command to check if the daemon is up: %s", err)
return false
}
// The daemon is up if the command worked. Carry on.
return true
}
func (provisioner *UbuntuProvisioner) Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions, engineOptions engine.EngineOptions) error {
provisioner.SwarmOptions = swarmOptions
provisioner.AuthOptions = authOptions
provisioner.EngineOptions = engineOptions
if provisioner.EngineOptions.StorageDriver == "" {
provisioner.EngineOptions.StorageDriver = "aufs"
}
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
}
for _, pkg := range provisioner.Packages {
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
return err
}
}
if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil {
return err
}
if err := utils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
if err := makeDockerOptionsDir(provisioner); err != nil {
return err
}
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
if err := ConfigureAuth(provisioner); err != nil {
return err
}
if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil {
return err
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.4.0-rc2

搜索幫助

0d507c66 1850385 C8b1a773 1850385