代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。