1 Star 0 Fork 0

powerpaas/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
provider.go 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
package libmachine
import (
"fmt"
"os"
"path/filepath"
"github.com/docker/machine/drivers"
"github.com/docker/machine/utils"
)
type Provider struct {
store Store
}
func New(store Store) (*Provider, error) {
return &Provider{
store: store,
}, nil
}
func (provider *Provider) Create(name string, driverName string, hostOptions *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) {
validName := ValidateHostName(name)
if !validName {
return nil, ErrInvalidHostname
}
exists, err := provider.store.Exists(name)
if err != nil {
return nil, err
}
if exists {
return nil, fmt.Errorf("Machine %s already exists", name)
}
hostPath := filepath.Join(utils.GetMachineDir(), name)
host, err := NewHost(name, driverName, hostOptions)
if err != nil {
return host, err
}
if driverConfig != nil {
if err := host.Driver.SetConfigFromFlags(driverConfig); err != nil {
return host, err
}
}
if err := host.Driver.PreCreateCheck(); err != nil {
return nil, err
}
if err := os.MkdirAll(hostPath, 0700); err != nil {
return nil, err
}
if err := host.SaveConfig(); err != nil {
return host, err
}
if err := host.Create(name); err != nil {
return host, err
}
return host, nil
}
func (provider *Provider) Exists(name string) (bool, error) {
return provider.store.Exists(name)
}
func (provider *Provider) GetActive() (*Host, error) {
return provider.store.GetActive()
}
func (provider *Provider) List() ([]*Host, error) {
return provider.store.List()
}
func (provider *Provider) Get(name string) (*Host, error) {
return provider.store.Get(name)
}
func (provider *Provider) Remove(name string, force bool) error {
host, err := provider.store.Get(name)
if err != nil {
return err
}
if err := host.Remove(force); err != nil {
if !force {
return err
}
}
return provider.store.Remove(name, force)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/powerpaas/machine.git
git@gitee.com:powerpaas/machine.git
powerpaas
machine
machine
v0.3.1-rc1

搜索帮助