getInstanceList :: Options -> IO ([Instance], [Instance])
getInstanceList opts = do
  let srvAddr = optConfdAddr opts
      srvPort = optConfdPort opts
      instFile = optInstances opts
      fromConfdUnchecked :: IO (BT.Result ([Instance], [Instance]))
      fromConfdUnchecked = getHostName >>= \n -> getInstances n srvAddr srvPort
      fromConfd :: IO (BT.Result ([Instance], [Instance]))
      fromConfd =
        liftM (either (BT.Bad . show) id) (E.try fromConfdUnchecked :: 
          IO (Either IOError (BT.Result ([Instance], [Instance]))))
      fromFile :: FilePath -> IO (BT.Result ([Instance], [Instance]))
      fromFile inputFile = do
        contents <-
          ((E.try $ readFile inputFile) :: IO (Either IOError String))
            >>= exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok
        return . fromJResult "Not a list of instances" $ J.decode contents
  instances <- maybe fromConfd fromFile instFile
  exitIfBad "Unable to obtain the list of instances" instances

-- | Adds the name of the instance to the information about one logical volume.
getInstanceList :: Options -> IO ([Instance], [Instance])
getInstanceList opts = do
  let srvAddr = optConfdAddr opts
      srvPort = optConfdPort opts
      instFile = optInstances opts
      fromConfdUnchecked :: IO (BT.Result ([Instance], [Instance]))
      fromConfdUnchecked = getHostName >>= \n -> getInstances n srvAddr srvPort
      fromConfd :: IO (BT.Result ([Instance], [Instance]))
      fromConfd =
        liftM (either (BT.Bad . show) id) (E.try fromConfdUnchecked :: 
          IO (Either IOError (BT.Result ([Instance], [Instance]))))
      fromFile :: FilePath -> IO (BT.Result ([Instance], [Instance]))
      fromFile inputFile = do
        contents <-
          ((E.try $ readFile inputFile) :: IO (Either IOError String))
            >>= exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok
        return . fromJResult "Not a list of instances" $ J.decode contents
  instances <- maybe fromConfd fromFile instFile
  exitIfBad "Unable to obtain the list of instances" instances

-- | Adds the name of the instance to the information about one logical volume.
getInstanceList opts = do
  let srvAddr = optConfdAddr opts
      srvPort = optConfdPort opts
      instFile = optInstances opts
      fromConfdUnchecked :: IO (BT.Result ([Instance], [Instance]))
      fromConfdUnchecked = getHostName >>= \n -> getInstances n srvAddr srvPort
      fromConfd :: IO (BT.Result ([Instance], [Instance]))
      fromConfd =
        liftM (either (BT.Bad . show) id) (E.try fromConfdUnchecked :: 
          IO (Either IOError (BT.Result ([Instance], [Instance]))))
      fromFile :: FilePath -> IO (BT.Result ([Instance], [Instance]))
      fromFile inputFile = do
        contents <-
          ((E.try $ readFile inputFile) :: IO (Either IOError String))
            >>= exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok
        return . fromJResult "Not a list of instances" $ J.decode contents
  instances <- maybe fromConfd fromFile instFile
  exitIfBad "Unable to obtain the list of instances" instances

-- | Adds the name of the instance to the information about one logical volume.