本文整理汇总了Golang中github.com/coreos/go-systemd/unit.Deserialize函数的典型用法代码示例。如果您正苦于以下问题:Golang Deserialize函数的具体用法?Golang Deserialize怎么用?Golang Deserialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Deserialize函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: checkCreateFileCall
func (s *initSystemSuite) checkCreateFileCall(c *gc.C, index int, filename, content string, perm os.FileMode) {
if content == "" {
name := filename
filename = fmt.Sprintf("%s/init/%s/%s.service", s.dataDir, name, name)
content = s.newConfStr(name)
}
call := s.stub.Calls()[index]
if !c.Check(call.FuncName, gc.Equals, "CreateFile") {
return
}
if !c.Check(call.Args, gc.HasLen, 3) {
return
}
callFilename, callData, callPerm := call.Args[0], call.Args[1], call.Args[2]
c.Check(callFilename, gc.Equals, filename)
// Some tests don't generate valid ini files, instead including placeholder
// strings (e.g. "a\nb\nc\n"). To avoid parsing errors, we only try and
// parse actual and expected file content if they don't exactly match.
if content != string(callData.([]byte)) {
// Parse the ini configurations and compare those.
expected, err := unit.Deserialize(bytes.NewReader(callData.([]byte)))
c.Assert(err, jc.ErrorIsNil)
cfg, err := unit.Deserialize(strings.NewReader(content))
c.Assert(err, jc.ErrorIsNil)
c.Check(cfg, jc.SameContents, expected)
}
c.Check(callPerm, gc.Equals, perm)
}
开发者ID:Pankov404,项目名称:juju,代码行数:32,代码来源:service_test.go
示例2: findRktID
// findRktID returns the rkt uuid for the pod.
// TODO(yifan): This is unefficient which require us to list
// all the unit files.
func (r *runtime) findRktID(pod *kubecontainer.Pod) (string, error) {
units, err := r.systemd.ListUnits()
if err != nil {
return "", err
}
unitName := makePodServiceFileName(pod.ID)
for _, u := range units {
// u.Name contains file name ext such as .service, .socket, etc.
if u.Name != unitName {
continue
}
f, err := os.Open(path.Join(systemdServiceDir, u.Name))
if err != nil {
return "", err
}
defer f.Close()
opts, err := unit.Deserialize(f)
if err != nil {
return "", err
}
for _, opt := range opts {
if opt.Section == unitKubernetesSection && opt.Name == unitRktID {
return opt.Value, nil
}
}
}
return "", fmt.Errorf("rkt uuid not found for pod %v", pod)
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:35,代码来源:rkt.go
示例3: deserialize
// deserialize parses the provided data (in the systemd unit file
// format) and populates a new Conf with the result.
func deserialize(data []byte, renderer shell.Renderer) (common.Conf, error) {
opts, err := unit.Deserialize(bytes.NewBuffer(data))
if err != nil {
return common.Conf{}, errors.Trace(err)
}
return deserializeOptions(opts, renderer)
}
开发者ID:Pankov404,项目名称:juju,代码行数:9,代码来源:conf.go
示例4: NewUnitFile
func NewUnitFile(raw string) (*UnitFile, error) {
reader := strings.NewReader(raw)
opts, err := unit.Deserialize(reader)
if err != nil {
return nil, err
}
return NewUnitFromOptions(opts), nil
}
开发者ID:mikedanese,项目名称:heapster,代码行数:9,代码来源:unit.go
示例5: Load
// take a unit file as string and convert it to a unit object.
func Load(name string, unitAsFile io.Reader) (u *Unit) {
opts, err := unit.Deserialize(unitAsFile)
if err != nil {
panic(err)
}
u = &Unit{}
u.Options = opts
u.Name = name + ".service"
return
}
开发者ID:brianredbeard,项目名称:astralboot,代码行数:11,代码来源:frontend.go
示例6: validateUnitContent
func validateUnitContent(content string) error {
c := bytes.NewBufferString(content)
unit, err := unit.Deserialize(c)
if err != nil {
return fmt.Errorf("invalid unit content: %s", err)
}
if len(unit) == 0 {
return errEmptyUnit
}
return nil
}
开发者ID:hashicorp,项目名称:terraform,代码行数:13,代码来源:provider.go
示例7: readServiceFile
// readServiceFile reads the service file and constructs the runtime pod and the rkt info.
func (r *runtime) readServiceFile(serviceName string) (*kubecontainer.Pod, *rktInfo, error) {
f, err := os.Open(serviceFilePath(serviceName))
if err != nil {
return nil, nil, err
}
defer f.Close()
var pod kubecontainer.Pod
opts, err := unit.Deserialize(f)
if err != nil {
return nil, nil, err
}
info := emptyRktInfo()
for _, opt := range opts {
if opt.Section != unitKubernetesSection {
continue
}
switch opt.Name {
case unitPodName:
err = json.Unmarshal([]byte(opt.Value), &pod)
if err != nil {
return nil, nil, err
}
case unitRktID:
info.uuid = opt.Value
case unitRestartCount:
cnt, err := strconv.Atoi(opt.Value)
if err != nil {
return nil, nil, err
}
info.restartCount = cnt
default:
return nil, nil, fmt.Errorf("rkt: unexpected key: %q", opt.Name)
}
}
if info.isEmpty() {
return nil, nil, fmt.Errorf("rkt: cannot find rkt info of pod %v, unit file is broken", pod)
}
return &pod, info, nil
}
开发者ID:previousnext,项目名称:kube-ingress,代码行数:43,代码来源:rkt.go
示例8: unitFileToJson
func unitFileToJson(unitFileContent string) ([]byte, error) {
// deserialize to units
opts, err := unit.Deserialize(strings.NewReader(unitFileContent))
if err != nil {
return nil, err
}
fleetUnit := struct {
Options []*unit.UnitOption `json:"options"`
DesiredState string `json:"desiredState"`
}{
Options: opts,
DesiredState: "launched",
}
bytes, err := json.Marshal(fleetUnit)
return bytes, err
}
开发者ID:clanstyles,项目名称:couchbase-cluster-go,代码行数:20,代码来源:fleet.go
示例9: makeRuntimePod
// makeRuntimePod constructs the container runtime pod. It will:
// 1, Construct the pod by the information stored in the unit file.
// 2, Construct the pod status from pod info.
func (r *runtime) makeRuntimePod(unitName string, podInfos map[string]*podInfo) (*kubecontainer.Pod, error) {
f, err := os.Open(path.Join(systemdServiceDir, unitName))
if err != nil {
return nil, err
}
defer f.Close()
var pod kubecontainer.Pod
opts, err := unit.Deserialize(f)
if err != nil {
return nil, err
}
var rktID string
for _, opt := range opts {
if opt.Section != unitKubernetesSection {
continue
}
switch opt.Name {
case unitPodName:
err = json.Unmarshal([]byte(opt.Value), &pod)
if err != nil {
return nil, err
}
case unitRktID:
rktID = opt.Value
default:
return nil, fmt.Errorf("rkt: Unexpected key: %q", opt.Name)
}
}
if len(rktID) == 0 {
return nil, fmt.Errorf("rkt: cannot find rkt ID of pod %v, unit file is broken", pod)
}
info, found := podInfos[rktID]
if !found {
return nil, fmt.Errorf("rkt: cannot find info for pod %q, rkt uuid: %q", pod.Name, rktID)
}
pod.Status = info.toPodStatus(&pod)
return &pod, nil
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:44,代码来源:rkt.go
示例10: findRktID
// findRktID returns the rkt uuid for the pod.
func (r *runtime) findRktID(pod *kubecontainer.Pod) (string, error) {
serviceName := makePodServiceFileName(pod.ID)
f, err := os.Open(serviceFilePath(serviceName))
if err != nil {
if os.IsNotExist(err) {
return "", fmt.Errorf("no service file %v for runtime pod %q, ID %q", serviceName, pod.Name, pod.ID)
}
return "", err
}
defer f.Close()
opts, err := unit.Deserialize(f)
if err != nil {
return "", err
}
for _, opt := range opts {
if opt.Section == unitKubernetesSection && opt.Name == unitRktID {
return opt.Value, nil
}
}
return "", fmt.Errorf("rkt uuid not found for pod %v", pod)
}
开发者ID:previousnext,项目名称:kube-ingress,代码行数:25,代码来源:rkt.go
示例11: makeRuntimePod
// makeRuntimePod constructs the container runtime pod. It will:
// 1, Construct the pod by the information stored in the unit file.
// 2, Return the rkt uuid.
func (r *runtime) makeRuntimePod(unitName string) (*kubecontainer.Pod, string, error) {
f, err := os.Open(path.Join(systemdServiceDir, unitName))
if err != nil {
return nil, "", err
}
defer f.Close()
var pod kubecontainer.Pod
opts, err := unit.Deserialize(f)
if err != nil {
return nil, "", err
}
var rktID string
for _, opt := range opts {
if opt.Section != unitKubernetesSection {
continue
}
switch opt.Name {
case unitPodName:
err = json.Unmarshal([]byte(opt.Value), &pod)
if err != nil {
return nil, "", err
}
case unitRktID:
rktID = opt.Value
default:
return nil, "", fmt.Errorf("rkt: Unexpected key: %q", opt.Name)
}
}
if len(rktID) == 0 {
return nil, "", fmt.Errorf("rkt: cannot find rkt ID of pod %v, unit file is broken", pod)
}
return &pod, "", nil
}
开发者ID:kzkohashi,项目名称:kubernetes,代码行数:39,代码来源:rkt.go
注:本文中的github.com/coreos/go-systemd/unit.Deserialize函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论