本文整理汇总了Golang中github.com/snapcore/snapd/overlord/state.NewTaskSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTaskSet函数的具体用法?Golang NewTaskSet怎么用?Golang NewTaskSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTaskSet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNewTaskSet
func (cs *taskSuite) TestNewTaskSet(c *C) {
ts0 := state.NewTaskSet()
c.Check(ts0.Tasks(), HasLen, 0)
st := state.New(nil)
st.Lock()
t1 := st.NewTask("download", "1...")
t2 := st.NewTask("install", "2...")
ts2 := state.NewTaskSet(t1, t2)
st.Unlock()
c.Assert(ts2.Tasks(), DeepEquals, []*state.Task{t1, t2})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:13,代码来源:task_test.go
示例2: Enable
// Enable sets a snap to the active state
func Enable(s *state.State, name string) (*state.TaskSet, error) {
var snapst SnapState
err := Get(s, name, &snapst)
if err == state.ErrNoState {
return nil, fmt.Errorf("cannot find snap %q", name)
}
if err != nil {
return nil, err
}
if snapst.Active {
return nil, fmt.Errorf("snap %q already enabled", name)
}
if err := checkChangeConflict(s, name, nil); err != nil {
return nil, err
}
ss := &SnapSetup{
SideInfo: snapst.CurrentSideInfo(),
}
prepareSnap := s.NewTask("prepare-snap", fmt.Sprintf(i18n.G("Prepare snap %q (%s)"), ss.Name(), snapst.Current))
prepareSnap.Set("snap-setup", &ss)
linkSnap := s.NewTask("link-snap", fmt.Sprintf(i18n.G("Make snap %q (%s) available to the system"), ss.Name(), snapst.Current))
linkSnap.Set("snap-setup", &ss)
linkSnap.WaitFor(prepareSnap)
startSnapServices := s.NewTask("start-snap-services", fmt.Sprintf(i18n.G("Start snap %q (%s) services"), ss.Name(), snapst.Current))
startSnapServices.Set("snap-setup", &ss)
startSnapServices.WaitFor(linkSnap)
return state.NewTaskSet(prepareSnap, linkSnap, startSnapServices), nil
}
开发者ID:elopio,项目名称:snappy,代码行数:36,代码来源:snapstate.go
示例3: setSnapConf
func setSnapConf(c *Command, r *http.Request, user *auth.UserState) Response {
vars := muxVars(r)
snapName := vars["name"]
var patchValues map[string]interface{}
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&patchValues); err != nil {
return BadRequest("cannot decode request body into patch values: %v", err)
}
// TODO: Add patch values to configmanager
s := c.d.overlord.State()
s.Lock()
defer s.Unlock()
hookTaskSummary := fmt.Sprintf(i18n.G("Run apply-config hook for %s"), snapName)
task := hookstate.HookTask(s, hookTaskSummary, snapName, snap.Revision{}, "apply-config")
taskset := state.NewTaskSet(task)
change := s.NewChange("configure-snap", fmt.Sprintf("Setting config for %s", snapName))
change.AddAll(taskset)
s.EnsureBefore(0)
return AsyncResponse(nil, &Meta{Change: change.ID()})
}
开发者ID:clobrano,项目名称:snappy,代码行数:27,代码来源:api.go
示例4: Alias
// Alias enables the provided aliases for the snap with the given name.
func Alias(st *state.State, snapName string, aliases []string) (*state.TaskSet, error) {
var snapst SnapState
err := Get(st, snapName, &snapst)
if err == state.ErrNoState {
return nil, fmt.Errorf("cannot find snap %q", snapName)
}
if err != nil {
return nil, err
}
if !snapst.Active {
return nil, fmt.Errorf("enabling aliases for disabled snap %q not supported", snapName)
}
if err := checkChangeConflict(st, snapName, nil); err != nil {
return nil, err
}
snapsup := &SnapSetup{
SideInfo: &snap.SideInfo{RealName: snapName},
}
alias := st.NewTask("alias", fmt.Sprintf(i18n.G("Enable aliases for snap %q"), snapsup.Name()))
alias.Set("snap-setup", &snapsup)
toEnable := map[string]string{}
for _, alias := range aliases {
toEnable[alias] = "enabled"
}
alias.Set("aliases", toEnable)
return state.NewTaskSet(alias), nil
}
开发者ID:chipaca,项目名称:snappy,代码行数:31,代码来源:aliases.go
示例5: ResetAliases
// ResetAliases resets the provided aliases for the snap with the given name to their default state, enabled for auto-aliases, disabled otherwise.
func ResetAliases(st *state.State, snapName string, aliases []string) (*state.TaskSet, error) {
var snapst SnapState
err := Get(st, snapName, &snapst)
if err == state.ErrNoState {
return nil, fmt.Errorf("cannot find snap %q", snapName)
}
if err != nil {
return nil, err
}
if !snapst.Active { // TODO: we might want to support this
return nil, fmt.Errorf("resetting aliases to their default state for disabled snap %q not supported", snapName)
}
if err := checkChangeConflict(st, snapName, nil); err != nil {
return nil, err
}
snapsup := &SnapSetup{
SideInfo: &snap.SideInfo{RealName: snapName},
}
alias := st.NewTask("alias", fmt.Sprintf(i18n.G("Reset aliases for snap %q"), snapsup.Name()))
alias.Set("snap-setup", &snapsup)
toReset := map[string]string{}
for _, alias := range aliases {
toReset[alias] = "auto"
}
alias.Set("aliases", toReset)
return state.NewTaskSet(alias), nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:31,代码来源:aliases.go
示例6: Disable
// Disable sets a snap to the inactive state
func Disable(s *state.State, name string) (*state.TaskSet, error) {
var snapst SnapState
err := Get(s, name, &snapst)
if err == state.ErrNoState {
return nil, fmt.Errorf("cannot find snap %q", name)
}
if err != nil {
return nil, err
}
if !snapst.Active {
return nil, fmt.Errorf("snap %q already disabled", name)
}
if err := checkChangeConflict(s, name, nil); err != nil {
return nil, err
}
ss := &SnapSetup{
SideInfo: &snap.SideInfo{
RealName: name,
Revision: snapst.Current,
},
}
stopSnapServices := s.NewTask("stop-snap-services", fmt.Sprintf(i18n.G("Stop snap %q (%s) services"), ss.Name(), snapst.Current))
stopSnapServices.Set("snap-setup", &ss)
unlinkSnap := s.NewTask("unlink-snap", fmt.Sprintf(i18n.G("Make snap %q (%s) unavailable to the system"), ss.Name(), snapst.Current))
unlinkSnap.Set("snap-setup-task", stopSnapServices.ID())
unlinkSnap.WaitFor(stopSnapServices)
return state.NewTaskSet(stopSnapServices, unlinkSnap), nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:33,代码来源:snapstate.go
示例7: Disconnect
// Disconnect returns a set of tasks for disconnecting an interface.
func Disconnect(s *state.State, plugSnap, plugName, slotSnap, slotName string) (*state.TaskSet, error) {
summary := fmt.Sprintf(i18n.G("Disconnect %s:%s from %s:%s"),
plugSnap, plugName, slotSnap, slotName)
task := s.NewTask("disconnect", summary)
task.Set("slot", interfaces.SlotRef{Snap: slotSnap, Name: slotName})
task.Set("plug", interfaces.PlugRef{Snap: plugSnap, Name: plugName})
return state.NewTaskSet(task), nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:9,代码来源:ifacemgr.go
示例8: TestTaskSetWaitAll
func (ts *taskSuite) TestTaskSetWaitAll(c *C) {
st := state.New(nil)
st.Lock()
defer st.Unlock()
t1 := st.NewTask("download", "1...")
t2 := st.NewTask("check", "2...")
t3 := st.NewTask("setup", "3...")
t4 := st.NewTask("link", "4...")
ts12 := state.NewTaskSet(t1, t2)
ts34 := state.NewTaskSet(t3, t4)
ts34.WaitAll(ts12)
c.Assert(t3.WaitTasks(), DeepEquals, []*state.Task{t1, t2})
c.Assert(t4.WaitTasks(), DeepEquals, []*state.Task{t1, t2})
c.Assert(t1.HaltTasks(), HasLen, 2)
c.Assert(t2.HaltTasks(), HasLen, 2)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:18,代码来源:task_test.go
示例9: addSetupSnapSecurityChange
func (s *interfaceManagerSuite) addSetupSnapSecurityChange(c *C, snapsup *snapstate.SnapSetup) *state.Change {
s.state.Lock()
defer s.state.Unlock()
task := s.state.NewTask("setup-profiles", "")
task.Set("snap-setup", snapsup)
taskset := state.NewTaskSet(task)
change := s.state.NewChange("test", "")
change.AddAll(taskset)
return change
}
开发者ID:pedronis,项目名称:snappy,代码行数:11,代码来源:ifacemgr_test.go
示例10: Connect
// Connect returns a set of tasks for connecting an interface.
//
func Connect(s *state.State, plugSnap, plugName, slotSnap, slotName string) (*state.TaskSet, error) {
// TODO: Store the intent-to-connect in the state so that we automatically
// try to reconnect on reboot (reconnection can fail or can connect with
// different parameters so we cannot store the actual connection details).
summary := fmt.Sprintf(i18n.G("Connect %s:%s to %s:%s"),
plugSnap, plugName, slotSnap, slotName)
task := s.NewTask("connect", summary)
task.Set("slot", interfaces.SlotRef{Snap: slotSnap, Name: slotName})
task.Set("plug", interfaces.PlugRef{Snap: plugSnap, Name: plugName})
return state.NewTaskSet(task), nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:13,代码来源:ifacemgr.go
示例11: TestTaskSetAddTaskAndAddAll
func (ts *taskSuite) TestTaskSetAddTaskAndAddAll(c *C) {
st := state.New(nil)
st.Lock()
defer st.Unlock()
t1 := st.NewTask("download", "1...")
t2 := st.NewTask("check", "2...")
t3 := st.NewTask("setup", "3...")
t4 := st.NewTask("link", "4...")
ts0 := state.NewTaskSet(t1)
ts0.AddTask(t2)
ts0.AddAll(state.NewTaskSet(t3, t4))
// these do nothing
ts0.AddTask(t2)
ts0.AddAll(state.NewTaskSet(t3, t4))
c.Check(ts0.Tasks(), DeepEquals, []*state.Task{t1, t2, t3, t4})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:21,代码来源:task_test.go
示例12: ensureOperational
func (m *DeviceManager) ensureOperational() error {
m.state.Lock()
defer m.state.Unlock()
device, err := auth.Device(m.state)
if err != nil {
return err
}
if device.Serial != "" {
// serial is set, we are all set
return nil
}
if device.Brand == "" || device.Model == "" {
// need first-boot, loading of model assertion info
if release.OnClassic {
// TODO: are we going to have model assertions on classic or need will need to cheat here?
return nil
}
// cannot proceed yet, once first boot is done these will be set
// and we can pick up from there
return nil
}
for _, chg := range m.state.Changes() {
if chg.Kind() == "become-operational" && !chg.Status().Ready() {
// change already in motion
return nil
}
}
if serialRequestURL == "" {
// cannot do anything actually
return nil
}
// XXX: some of these will need to be split and use hooks
// retries might need to embrace more than one "task" then,
// need to be careful
genKey := m.state.NewTask("generate-device-key", i18n.G("Generate device key"))
requestSerial := m.state.NewTask("request-serial", i18n.G("Request device serial"))
requestSerial.WaitFor(genKey)
chg := m.state.NewChange("become-operational", i18n.G("Initialize device"))
chg.AddAll(state.NewTaskSet(genKey, requestSerial))
return nil
}
开发者ID:clobrano,项目名称:snappy,代码行数:50,代码来源:devicemgr.go
示例13: TestTaskWaitAll
func (ts *taskSuite) TestTaskWaitAll(c *C) {
st := state.New(nil)
st.Lock()
defer st.Unlock()
t1 := st.NewTask("download", "1...")
t2 := st.NewTask("install", "2...")
t3 := st.NewTask("setup", "3...")
t3.WaitAll(state.NewTaskSet(t1, t2))
c.Assert(t3.WaitTasks(), HasLen, 2)
c.Assert(t1.HaltTasks(), DeepEquals, []*state.Task{t3})
c.Assert(t2.HaltTasks(), DeepEquals, []*state.Task{t3})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:task_test.go
示例14: TestTaskSetWaitFor
func (ts *taskSuite) TestTaskSetWaitFor(c *C) {
st := state.New(nil)
st.Lock()
defer st.Unlock()
t1 := st.NewTask("download", "1...")
t2 := st.NewTask("install", "2...")
t3 := st.NewTask("setup", "3...")
ts23 := state.NewTaskSet(t2, t3)
ts23.WaitFor(t1)
c.Assert(t2.WaitTasks(), DeepEquals, []*state.Task{t1})
c.Assert(t3.WaitTasks(), DeepEquals, []*state.Task{t1})
c.Assert(t1.HaltTasks(), HasLen, 2)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:15,代码来源:task_test.go
示例15: TestAddAll
func (cs *changeSuite) TestAddAll(c *C) {
st := state.New(nil)
st.Lock()
defer st.Unlock()
chg := st.NewChange("install", "...")
t1 := st.NewTask("download", "1...")
t2 := st.NewTask("verify", "2...")
chg.AddAll(state.NewTaskSet(t1, t2))
tasks := chg.Tasks()
c.Check(tasks, DeepEquals, []*state.Task{t1, t2})
c.Check(t1.Change(), Equals, chg)
c.Check(t2.Change(), Equals, chg)
}
开发者ID:pedronis,项目名称:snappy,代码行数:16,代码来源:change_test.go
示例16: addDiscardConnsChange
func (s *interfaceManagerSuite) addDiscardConnsChange(c *C, snapName string) *state.Change {
s.state.Lock()
defer s.state.Unlock()
task := s.state.NewTask("discard-conns", "")
snapsup := snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: snapName,
},
}
task.Set("snap-setup", snapsup)
taskset := state.NewTaskSet(task)
change := s.state.NewChange("test", "")
change.AddAll(taskset)
return change
}
开发者ID:pedronis,项目名称:snappy,代码行数:16,代码来源:ifacemgr_test.go
示例17: addRemoveSnapSecurityChange
func (s *interfaceManagerSuite) addRemoveSnapSecurityChange(c *C, snapName string) *state.Change {
s.state.Lock()
defer s.state.Unlock()
task := s.state.NewTask("remove-profiles", "")
ss := snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: snapName,
},
}
task.Set("snap-setup", ss)
taskset := state.NewTaskSet(task)
change := s.state.NewChange("test", "")
change.AddAll(taskset)
return change
}
开发者ID:niemeyer,项目名称:snapd,代码行数:16,代码来源:ifacemgr_test.go
示例18: removeInactiveRevision
func removeInactiveRevision(s *state.State, name string, revision snap.Revision) *state.TaskSet {
ss := SnapSetup{
SideInfo: &snap.SideInfo{
RealName: name,
Revision: revision,
},
}
clearData := s.NewTask("clear-snap", fmt.Sprintf(i18n.G("Remove data for snap %q (%s)"), name, revision))
clearData.Set("snap-setup", ss)
discardSnap := s.NewTask("discard-snap", fmt.Sprintf(i18n.G("Remove snap %q (%s) from the system"), name, revision))
discardSnap.WaitFor(clearData)
discardSnap.Set("snap-setup-task", clearData.ID())
return state.NewTaskSet(clearData, discardSnap)
}
开发者ID:elopio,项目名称:snappy,代码行数:17,代码来源:snapstate.go
示例19: TestDeviceManagerEnsureSeedYamlHappy
func (s *deviceMgrSuite) TestDeviceManagerEnsureSeedYamlHappy(c *C) {
release.OnClassic = false
restore := devicestate.MockPopulateStateFromSeed(func(*state.State) (ts []*state.TaskSet, err error) {
t := s.state.NewTask("test-task", "a random task")
ts = append(ts, state.NewTaskSet(t))
return ts, nil
})
defer restore()
err := s.mgr.EnsureSeedYaml()
c.Assert(err, IsNil)
s.state.Lock()
defer s.state.Unlock()
c.Check(s.state.Changes(), HasLen, 1)
}
开发者ID:pedronis,项目名称:snappy,代码行数:18,代码来源:devicemgr_test.go
示例20: Configure
// Configure returns a taskset to apply the given configuration patch.
func Configure(s *state.State, snapName string, patch map[string]interface{}) *state.TaskSet {
hooksup := &hookstate.HookSetup{
Snap: snapName,
Hook: "configure",
Optional: len(patch) == 0,
}
var contextData map[string]interface{}
if len(patch) > 0 {
contextData = map[string]interface{}{"patch": patch}
}
var summary string
if hooksup.Optional {
summary = fmt.Sprintf(i18n.G("Run configure hook of %q snap if present"), snapName)
} else {
summary = fmt.Sprintf(i18n.G("Run configure hook of %q snap"), snapName)
}
task := hookstate.HookTask(s, summary, hooksup, contextData)
return state.NewTaskSet(task)
}
开发者ID:pedronis,项目名称:snappy,代码行数:20,代码来源:tasksets.go
注:本文中的github.com/snapcore/snapd/overlord/state.NewTaskSet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论