Пример #1
0
func instanceID() (*types.InstanceID, error) {
	hostName, err := utils.HostName()
	if err != nil {
		return nil, err
	}
	iid := &types.InstanceID{ID: hostName, Driver: vfs.Name}
	if ok, _ := strconv.ParseBool(os.Getenv("VFS_INSTANCEID_USE_FIELDS")); ok {
		iid.Fields = map[string]string{"region": "east"}
	}
	return iid, nil
}
Пример #2
0
// InstanceID returns the local system's InstanceID.
func (d *driver) InstanceID(
	ctx types.Context,
	opts types.Store) (*types.InstanceID, error) {

	iid := &types.InstanceID{Driver: vfs.Name}
	hostName, err := utils.HostName()
	if err != nil {
		return nil, err
	}

	if ok, _ := strconv.ParseBool(os.Getenv("VFS_INSTANCEID_USE_FIELDS")); ok {
		iid.ID = hostName
		iid.Fields = map[string]string{"region": "east"}
		return iid, nil
	}

	if err := iid.MarshalMetadata(hostName); err != nil {
		return nil, err
	}
	return iid, nil
}
Пример #3
0
func newTestConfigAll(
	t *testing.T) (
	[]byte,
	[]byte,
	map[string]*types.Volume,
	map[string]*types.Snapshot) {

	hostName, err := utils.HostName()
	assert.NoError(t, err)
	if err != nil {
		t.FailNow()
	}

	d, err := ioutil.TempDir("", "")
	assert.NoError(t, err)
	if err != nil {
		t.FailNow()
	}
	t.Logf("created temp vfs root dir: %s", d)

	func() {
		testDirsLock.Lock()
		defer testDirsLock.Unlock()
		testDirs = append(testDirs, d)
	}()

	vd := path.Join(d, "vol")
	if err := os.MkdirAll(vd, 0755); err != nil {
		assert.NoError(t, err)
		t.FailNow()
	}
	t.Logf("created temp vfs vol dir: %s", vd)
	sd := path.Join(d, "snap")
	if err := os.MkdirAll(sd, 0755); err != nil {
		assert.NoError(t, err)
		t.FailNow()
	}
	t.Logf("created temp vfs snap dir: %s", sd)

	dp := path.Join(d, "dev")
	devFileContents := []byte(fmt.Sprintf(devFile, d))
	err = ioutil.WriteFile(dp, devFileContents, 0644)
	assert.NoError(t, err)
	if err != nil {
		t.FailNow()
	}
	t.Logf("created temp vfs dev file: %s", dp)

	vols := map[string]*types.Volume{}
	snaps := map[string]*types.Snapshot{}

	for x := 0; x < 3; x++ {
		var vj []byte
		if x < 2 {
			vj = []byte(fmt.Sprintf(volJSON, x, hostName))
		} else {
			vj = []byte(fmt.Sprintf(volNoAttachJSON, x, hostName))
		}
		v := &types.Volume{}
		if err := json.Unmarshal(vj, v); err != nil {
			assert.NoError(t, err)
			t.FailNow()
		}
		vols[v.ID] = v
		vjp := path.Join(vd, fmt.Sprintf("%s.json", v.ID))
		os.MkdirAll(path.Join(vd, v.ID), 0755)
		if err := ioutil.WriteFile(vjp, vj, 0644); err != nil {
			assert.NoError(t, err)
			t.FailNow()
		}

		for y := 0; y < 3; y++ {
			sj := []byte(fmt.Sprintf(snapJSON, x, y, time.Now().Unix()))
			s := &types.Snapshot{}
			if err := json.Unmarshal(sj, s); err != nil {
				assert.NoError(t, err)
				t.FailNow()
			}
			snaps[s.ID] = s
			sjp := path.Join(sd, fmt.Sprintf("vfs-%03d-%03d.json", x, y))
			if err := ioutil.WriteFile(sjp, sj, 0644); err != nil {
				assert.NoError(t, err)
				t.FailNow()
			}
		}
	}

	return []byte(fmt.Sprintf(configYAML, d)), devFileContents, vols, snaps
}