Add first version of the windows ASG provider

This commit is contained in:
Marcos Lilljedahl
2017-08-04 21:54:03 -03:00
parent f810c0c92f
commit ed7cefcf9c
10 changed files with 388 additions and 29 deletions

View File

@@ -48,6 +48,19 @@ func (store *storage) SessionPut(s *types.Session) error {
return store.save()
}
func (store *storage) InstanceGetAllWindows() ([]*types.WindowsInstance, error) {
store.rw.Lock()
defer store.rw.Unlock()
instances := []*types.WindowsInstance{}
for _, s := range store.db {
instances = append(instances, s.WindowsAssigned...)
}
return instances, nil
}
func (store *storage) InstanceGet(sessionId, name string) (*types.Instance, error) {
store.rw.Lock()
defer store.rw.Unlock()
@@ -94,6 +107,20 @@ func (store *storage) InstanceCreate(sessionId string, instance *types.Instance)
return store.save()
}
func (store *storage) InstanceCreateWindows(instance *types.WindowsInstance) error {
store.rw.Lock()
defer store.rw.Unlock()
s, found := store.db[instance.SessionId]
if !found {
return fmt.Errorf("Session %s", notFound)
}
s.WindowsAssigned = append(s.WindowsAssigned, instance)
return store.save()
}
func (store *storage) InstanceDelete(sessionId, name string) error {
store.rw.Lock()
defer store.rw.Unlock()
@@ -111,6 +138,25 @@ func (store *storage) InstanceDelete(sessionId, name string) error {
return store.save()
}
func (store *storage) InstanceDeleteWindows(sessionId, id string) error {
store.rw.Lock()
defer store.rw.Unlock()
s, found := store.db[sessionId]
if !found {
return fmt.Errorf("Session %s", notFound)
}
for i, winst := range s.WindowsAssigned {
if winst.ID == id {
s.WindowsAssigned = append(s.WindowsAssigned[:i], s.WindowsAssigned[i+1:]...)
}
}
return store.save()
}
func (store *storage) SessionCount() (int, error) {
store.rw.Lock()
defer store.rw.Unlock()