1 Star 0 Fork 0

powerpaas/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
migrate_v2_v3.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
Olivier Gambier 提交于 2015-11-04 17:28 . Lint
package host
import (
"bytes"
"encoding/json"
"github.com/docker/machine/libmachine/log"
)
type RawHost struct {
Driver *json.RawMessage
}
func MigrateHostV2ToHostV3(hostV2 *V2, data []byte, storePath string) *Host {
// Migrate to include RawDriver so that driver plugin will work
// smoothly.
rawHost := &RawHost{}
if err := json.Unmarshal(data, &rawHost); err != nil {
log.Warnf("Could not unmarshal raw host for RawDriver information: %s", err)
}
m := make(map[string]interface{})
// Must migrate to include store path in driver since it was not
// previously stored in drivers directly
d := json.NewDecoder(bytes.NewReader(*rawHost.Driver))
d.UseNumber()
if err := d.Decode(&m); err != nil {
log.Warnf("Could not unmarshal raw host into map[string]interface{}: %s", err)
}
m["StorePath"] = storePath
// Now back to []byte
rawDriver, err := json.Marshal(m)
if err != nil {
log.Warnf("Could not re-marshal raw driver: %s", err)
}
h := &Host{
ConfigVersion: 2,
DriverName: hostV2.DriverName,
Name: hostV2.Name,
HostOptions: hostV2.HostOptions,
RawDriver: rawDriver,
}
return h
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/powerpaas/machine.git
git@gitee.com:powerpaas/machine.git
powerpaas
machine
machine
v0.8.0-rc1

搜索帮助