当前位置: 首页>>代码示例>>Golang>>正文


Golang unit.NewUnitFile函数代码示例

本文整理汇总了Golang中github.com/coreos/fleet/unit.NewUnitFile函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUnitFile函数的具体用法?Golang NewUnitFile怎么用?Golang NewUnitFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewUnitFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewUnit

// NewUnit takes a component type and returns a Fleet unit
// that includes the relevant systemd service template
func NewUnit(component string, templatePaths []string, decorate bool) (uf *unit.UnitFile, err error) {
	template, err := readTemplate(component, templatePaths)
	if err != nil {
		return
	}
	if decorate {
		decorator, err := readDecorator(component)
		if err != nil {
			return nil, err
		}
		uf, err = unit.NewUnitFile(string(template) + "\n" + string(decorator))
	} else {
		uf, err = unit.NewUnitFile(string(template))
	}
	return
}
开发者ID:CodeJuan,项目名称:deis,代码行数:18,代码来源:unit.go

示例2: newUnitFile

func newUnitFile(t *testing.T, contents string) *unit.UnitFile {
	uf, err := unit.NewUnitFile(contents)
	if err != nil {
		t.Fatalf("error creating NewUnitFile from %s: %v", contents, err)
	}
	return uf
}
开发者ID:pulcy,项目名称:j2,代码行数:7,代码来源:fleetctl_test.go

示例3: getUnitByHash

// getUnitByHash retrieves from the Registry the Unit associated with the given Hash
func (r *EtcdRegistry) getUnitByHash(hash unit.Hash) *unit.UnitFile {
	key := r.hashedUnitPath(hash)
	opts := &etcd.GetOptions{
		Recursive: true,
	}
	resp, err := r.kAPI.Get(r.ctx(), key, opts)
	if err != nil {
		if isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
			err = nil
		}
		return nil
	}
	var um unitModel
	if err := unmarshal(resp.Node.Value, &um); err != nil {
		log.Errorf("error unmarshaling Unit(%s): %v", hash, err)
		return nil
	}

	u, err := unit.NewUnitFile(um.Raw)
	if err != nil {
		log.Errorf("error parsing Unit(%s): %v", hash, err)
		return nil
	}

	return u
}
开发者ID:gambol99,项目名称:node-register,代码行数:27,代码来源:unit.go

示例4: newUF

func newUF(t *testing.T, contents string) unit.UnitFile {
	uf, err := unit.NewUnitFile(contents)
	if err != nil {
		t.Fatalf("error creating new unit file from %v: %v", contents, err)
	}
	return *uf
}
开发者ID:ericcapricorn,项目名称:fleet,代码行数:7,代码来源:reconcile_test.go

示例5: newUnit

func newUnit(t *testing.T, str string) *unit.UnitFile {
	u, err := unit.NewUnitFile(str)
	if err != nil {
		t.Fatalf("Unexpected error creating unit from %q: %v", str, err)
	}
	return u
}
开发者ID:hugoduncan,项目名称:fleet,代码行数:7,代码来源:job_test.go

示例6: getUnitByHash

// getUnitByHash retrieves from the Registry the Unit associated with the given Hash
func (r *EtcdRegistry) getUnitByHash(hash unit.Hash) *unit.UnitFile {
	req := etcd.Get{
		Key:       r.hashedUnitPath(hash),
		Recursive: true,
	}
	resp, err := r.etcd.Do(&req)
	if err != nil {
		if isKeyNotFound(err) {
			err = nil
		}
		return nil
	}
	var um unitModel
	if err := unmarshal(resp.Node.Value, &um); err != nil {
		log.Errorf("error unmarshaling Unit(%s): %v", hash, err)
		return nil
	}

	u, err := unit.NewUnitFile(um.Raw)
	if err != nil {
		log.Errorf("error parsing Unit(%s): %v", hash, err)
		return nil
	}

	return u
}
开发者ID:hugoduncan,项目名称:fleet,代码行数:27,代码来源:unit.go

示例7: StartUnitsInDir

func StartUnitsInDir(path string) {
	files, _ := ioutil.ReadDir(path)

	for _, f := range files {
		unitpath := fmt.Sprintf("v1-alpha/units/%s", f.Name())
		url := getFullAPIURL("10001", unitpath)
		filepath := fmt.Sprintf("%s/%s", path, f.Name())

		readfile, err := ioutil.ReadFile(filepath)
		checkForErrors(err)
		content := string(readfile)

		u, _ := unit.NewUnitFile(content)

		options_bytes, _ := json.Marshal(u.Options)
		options_str := lowerCasingOfUnitOptionsStr(string(options_bytes))

		json_str := fmt.Sprintf(
			`{"name": "%s", "desiredState":"launched", "options": %s}`,
			f.Name(),
			options_str)

		resp := httpPutRequest(url, []byte(json_str))

		if resp.StatusCode != 204 {
			body, err := ioutil.ReadAll(resp.Body)
			log.Printf("[Error] in HTTP Body: %s", body)
			checkForErrors(err)
		}
	}
}
开发者ID:bketelsen,项目名称:corekube,代码行数:31,代码来源:fleet_utils.go

示例8: TestRpcUnitToJobUnit

func TestRpcUnitToJobUnit(t *testing.T) {
	contents := `
[Unit]
Description = Foo
`
	unitFile, err := unit.NewUnitFile(contents)
	if err != nil {
		t.Fatalf("unexpected error parsing unit %q: %v", contents, err)
	}

	want := &pb.Unit{
		Name:         "foo",
		Unit:         unitFile.ToPB(),
		DesiredState: pb.TargetState_LOADED,
	}
	expect := &job.Unit{
		Name:        "foo",
		Unit:        *unitFile,
		TargetState: job.JobStateLoaded,
	}

	got := rpcUnitToJobUnit(want)
	if !reflect.DeepEqual(got, expect) {
		t.Fatalf("got %#v, expected %#v", got, expect)
	}
}
开发者ID:jonboulle,项目名称:fleet,代码行数:26,代码来源:rpcutils_test.go

示例9: newUnitWithMetadata

func newUnitWithMetadata(t *testing.T, metadata string) unit.UnitFile {
	contents := fmt.Sprintf("[X-Fleet]\nMachineMetadata=%s", metadata)
	u, err := unit.NewUnitFile(contents)
	if err != nil {
		t.Fatalf("error creating unit from %q: %v", contents, err)
	}
	return *u
}
开发者ID:artik2015,项目名称:fleet,代码行数:8,代码来源:state_test.go

示例10: getUnitFromFile

// getUnitFromFile attempts to load a Unit from a given filename
// It returns the Unit or nil, and any error encountered
func getUnitFromFile(file string) (*unit.UnitFile, error) {
	out, err := ioutil.ReadFile(file)
	if err != nil {
		panic(err)
	}

	return unit.NewUnitFile(string(out))
}
开发者ID:kennethkalmer,项目名称:fleet-diff,代码行数:10,代码来源:main.go

示例11: getUnitFromStdin

// getUnitFromStdin attempts to load a Unit from stdin
func getUnitFromStdin() (*unit.UnitFile, error) {
	bytes, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	return unit.NewUnitFile(string(bytes))
}
开发者ID:kennethkalmer,项目名称:fleet-diff,代码行数:9,代码来源:main.go

示例12: TestFakeRegistryUnitLifecycle

func TestFakeRegistryUnitLifecycle(t *testing.T) {
	reg := NewFakeRegistry()

	units, err := reg.Units()
	if err != nil {
		t.Fatalf("Received error while calling Jobs: %v", err)
	}
	if !reflect.DeepEqual([]job.Unit{}, units) {
		t.Fatalf("Expected no units, got %v", units)
	}

	uf, _ := unit.NewUnitFile("")
	u1 := job.Unit{Name: "u1.service", Unit: *uf, TargetState: job.JobStateLoaded}
	err = reg.CreateUnit(&u1)
	if err != nil {
		t.Fatalf("Received error while calling CreateUnit: %v", err)
	}

	units, err = reg.Units()
	if err != nil {
		t.Fatalf("Received error while calling Units: %v", err)
	}
	if len(units) != 1 {
		t.Fatalf("Expected 1 Unit, got %v", units)
	}
	if !reflect.DeepEqual(u1, units[0]) {
		t.Fatalf("Expected unit %v, got %v", u1, units[0])
	}

	err = reg.ScheduleUnit("u1.service", "XXX")
	if err != nil {
		t.Fatalf("Received error while calling ScheduleUnit: %v", err)
	}

	su, err := reg.ScheduledUnit("u1.service")
	if err != nil {
		t.Fatalf("Received error while calling ScheduledUnit: %v", err)
	}
	if su.TargetMachineID != "XXX" {
		t.Fatalf("Unit should be scheduled to XXX, got %v", su.TargetMachineID)
	}

	err = reg.DestroyUnit("u1.service")
	if err != nil {
		t.Fatalf("Received error while calling DestroyUnit: %v", err)
	}

	units, err = reg.Units()
	if err != nil {
		t.Fatalf("Received error while calling Units: %v", err)
	}
	if !reflect.DeepEqual([]job.Unit{}, units) {
		t.Fatalf("Expected no units, got %v", units)
	}
}
开发者ID:Crispy1975,项目名称:deis,代码行数:55,代码来源:fake_test.go

示例13: NewUnit

// NewUnit takes a component type and returns a Fleet unit
// that includes the relevant systemd service template
func NewUnit(component string) (uf *unit.UnitFile, err error) {
	template, err := readTemplate(component)
	if err != nil {
		return
	}
	uf, err = unit.NewUnitFile(string(template))
	if err != nil {
		return
	}
	return
}
开发者ID:tob1k,项目名称:deisctl,代码行数:13,代码来源:unit.go

示例14: getUnitFromFile

// getUnitFromFile attempts to load a Unit from a given filename
// It returns the Unit or nil, and any error encountered
func getUnitFromFile(file string) (*unit.UnitFile, error) {
	out, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}

	unitName := path.Base(file)
	log.Debugf("Unit(%s) found in local filesystem", unitName)

	return unit.NewUnitFile(string(out))
}
开发者ID:pquast,项目名称:fleet,代码行数:13,代码来源:fleetctl.go

示例15: buildWantedUnits

func (d *deployer) buildWantedUnits() (map[string]*schema.Unit, error) {
	units := make(map[string]*schema.Unit)
	servicesDefinition, err := d.serviceDefinitionClient.servicesDefinition()
	if err != nil {
		return nil, err
	}
	for _, srv := range servicesDefinition.Services {
		vars := make(map[string]interface{})
		serviceTemplate, err := d.serviceDefinitionClient.serviceFile(srv)
		if err != nil {
			log.Printf("%v", err)
			continue
		}
		vars["version"] = srv.Version
		serviceFile, err := renderedServiceFile(serviceTemplate, vars)
		if err != nil {
			log.Printf("%v", err)
			return nil, err
		}

		// fleet deploy
		uf, err := unit.NewUnitFile(serviceFile)
		if err != nil {
			//Broken service file, skip it and continue
			log.Printf("WARNING service file %s is incorrect: %v [SKIPPING]", srv.Name, err)
			continue
		}

		if srv.Count == 0 && !strings.Contains(srv.Name, "@") {
			u := &schema.Unit{
				Name:         srv.Name,
				Options:      schema.MapUnitFileToSchemaUnitOptions(uf),
				DesiredState: srv.DesiredState,
			}

			units[srv.Name] = u
		} else if srv.Count > 0 && strings.Contains(srv.Name, "@") {
			for i := 0; i < srv.Count; i++ {
				xName := strings.Replace(srv.Name, "@", fmt.Sprintf("@%d", i+1), -1)

				u := &schema.Unit{
					Name:         xName,
					Options:      schema.MapUnitFileToSchemaUnitOptions(uf),
					DesiredState: srv.DesiredState,
				}

				units[u.Name] = u
			}
		} else {
			log.Printf("WARNING skipping service: %s, incorrect service definition", srv.Name)
		}
	}
	return units, nil
}
开发者ID:dgem,项目名称:coco-fleet-deployer,代码行数:54,代码来源:deployer.go


注:本文中的github.com/coreos/fleet/unit.NewUnitFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。