mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
agent: adds endpoint for disk ejection
This commit is contained in:
committed by
Aiden McClelland
parent
89ff5de01b
commit
4e0ad21384
@@ -38,6 +38,7 @@
|
|||||||
/v0/apps/#AppId/autoconfig/#AppId AutoconfigureR POST
|
/v0/apps/#AppId/autoconfig/#AppId AutoconfigureR POST
|
||||||
|
|
||||||
/v0/disks ListDisksR GET
|
/v0/disks ListDisksR GET
|
||||||
|
/v0/disks/#Text EjectDiskR DELETE
|
||||||
|
|
||||||
/v0/update UpdateAgentR POST
|
/v0/update UpdateAgentR POST
|
||||||
/v0/wifi WifiR GET POST
|
/v0/wifi WifiR GET POST
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ postRestoreBackupR appId = disableEndpointOnFailedUpdate $ do
|
|||||||
getListDisksR :: Handler (JSONResponse [AppMgr.DiskInfo])
|
getListDisksR :: Handler (JSONResponse [AppMgr.DiskInfo])
|
||||||
getListDisksR = fmap JSONResponse . runM . handleS9ErrC $ listDisksLogic
|
getListDisksR = fmap JSONResponse . runM . handleS9ErrC $ listDisksLogic
|
||||||
|
|
||||||
|
deleteEjectDiskR :: Text -> Handler ()
|
||||||
|
deleteEjectDiskR t = runM . handleS9ErrC $ ejectDiskLogic t
|
||||||
|
|
||||||
|
|
||||||
-- Logic
|
-- Logic
|
||||||
|
|
||||||
@@ -203,6 +206,16 @@ restoreBackupLogic appId RestoreBackupReq {..} = do
|
|||||||
listDisksLogic :: (Has (Error S9Error) sig m, MonadIO m) => m [AppMgr.DiskInfo]
|
listDisksLogic :: (Has (Error S9Error) sig m, MonadIO m) => m [AppMgr.DiskInfo]
|
||||||
listDisksLogic = runExceptT AppMgr.diskShow >>= liftEither
|
listDisksLogic = runExceptT AppMgr.diskShow >>= liftEither
|
||||||
|
|
||||||
|
ejectDiskLogic :: (Has (Error S9Error) sig m, MonadIO m) => Text -> m ()
|
||||||
|
ejectDiskLogic t = runExceptT (diskEject t) >>= liftEither
|
||||||
|
|
||||||
|
diskEject :: MonadIO m => Text -> S9ErrT m ()
|
||||||
|
diskEject t = do
|
||||||
|
(ec, _) <- AppMgr.readProcessInheritStderr "eject" [toS t] ""
|
||||||
|
case ec of
|
||||||
|
ExitSuccess -> pure ()
|
||||||
|
ExitFailure n -> throwE $ EjectE n
|
||||||
|
|
||||||
insertBackupResult :: MonadIO m => AppId -> Version -> Bool -> SqlPersistT m (Entity BackupRecord)
|
insertBackupResult :: MonadIO m => AppId -> Version -> Bool -> SqlPersistT m (Entity BackupRecord)
|
||||||
insertBackupResult appId appVersion succeeded = do
|
insertBackupResult appId appVersion succeeded = do
|
||||||
uuid <- liftIO nextRandom
|
uuid <- liftIO nextRandom
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ data S9Error =
|
|||||||
| AppMgrParseE Text Text String
|
| AppMgrParseE Text Text String
|
||||||
| AppMgrInvalidConfigE Text
|
| AppMgrInvalidConfigE Text
|
||||||
| AppMgrE Text Int
|
| AppMgrE Text Int
|
||||||
|
| EjectE Int
|
||||||
| AvahiE Text
|
| AvahiE Text
|
||||||
| MetricE Text
|
| MetricE Text
|
||||||
| AppMgrVersionE Version VersionRange
|
| AppMgrVersionE Version VersionRange
|
||||||
@@ -86,6 +87,7 @@ toError = \case
|
|||||||
AppMgrParseE cmd result e ->
|
AppMgrParseE cmd result e ->
|
||||||
ErrorResponse APPMGR_PARSE_ERROR [i|"appmgr #{cmd}" yielded an unparseable result:#{result}\nError: #{e}|]
|
ErrorResponse APPMGR_PARSE_ERROR [i|"appmgr #{cmd}" yielded an unparseable result:#{result}\nError: #{e}|]
|
||||||
AppMgrE cmd code -> ErrorResponse APPMGR_ERROR [i|"appmgr #{cmd}" exited with #{code}|]
|
AppMgrE cmd code -> ErrorResponse APPMGR_ERROR [i|"appmgr #{cmd}" exited with #{code}|]
|
||||||
|
EjectE code -> ErrorResponse EJECT_ERROR [i|"eject" command exited with #{code}|]
|
||||||
AppMgrVersionE av avs ->
|
AppMgrVersionE av avs ->
|
||||||
ErrorResponse APPMGR_ERROR [i|"appmgr version #{av}" fails to satisfy requisite spec #{avs}|]
|
ErrorResponse APPMGR_ERROR [i|"appmgr version #{av}" fails to satisfy requisite spec #{avs}|]
|
||||||
AvahiE e -> ErrorResponse AVAHI_ERROR [i|#{e}|]
|
AvahiE e -> ErrorResponse AVAHI_ERROR [i|#{e}|]
|
||||||
@@ -151,6 +153,7 @@ data ErrorCode =
|
|||||||
| APPMGR_CONFIG_ERROR
|
| APPMGR_CONFIG_ERROR
|
||||||
| APPMGR_PARSE_ERROR
|
| APPMGR_PARSE_ERROR
|
||||||
| APPMGR_ERROR
|
| APPMGR_ERROR
|
||||||
|
| EJECT_ERROR
|
||||||
| AVAHI_ERROR
|
| AVAHI_ERROR
|
||||||
| REGISTRY_ERROR
|
| REGISTRY_ERROR
|
||||||
| APP_NOT_INSTALLED
|
| APP_NOT_INSTALLED
|
||||||
@@ -201,6 +204,7 @@ toStatus = \case
|
|||||||
AppMgrParseE{} -> status500
|
AppMgrParseE{} -> status500
|
||||||
AppMgrInvalidConfigE _ -> status400
|
AppMgrInvalidConfigE _ -> status400
|
||||||
AppMgrE _ _ -> status500
|
AppMgrE _ _ -> status500
|
||||||
|
EjectE _ -> status500
|
||||||
AppMgrVersionE _ _ -> status500
|
AppMgrVersionE _ _ -> status500
|
||||||
AvahiE _ -> status500
|
AvahiE _ -> status500
|
||||||
MetricE _ -> status500
|
MetricE _ -> status500
|
||||||
|
|||||||
Reference in New Issue
Block a user