All files / src/api/cloud-volumes index.js

100% Statements 16/16
100% Branches 0/0
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98    1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                                                                         2x     1x     2x                            
// @flow
 
import callCloudVolumes, {
  type CloudVolumesConf,
} from '../../service/cloud-volumes';
import logger from '../../logger';
import activeDirectory, { type ActiveDirectoryAPI } from './active-directory';
import backups, { type BackupsAPI } from './backups';
import catalog, { type CatalogAPI } from './catalog';
import ipRanges, { type IPRangesAPI } from './ip-ranges';
import jobs, { type JobsAPI } from './utils/jobs';
import networks, { type NetworksAPI } from './networks';
import regions, { type RegionsAPI } from './regions';
import serviceLevels, { type ServiceLevelAPI } from './service-levels';
import snapshots, { type SnapshotsAPI } from './snapshots';
import volumes, { type VolumesAPI } from './volumes';
import zones, { type ZonesAPI } from './zones';
 
export type Caller = (
  method: string,
  command: string,
  data?: any,
) => Promise<any>;
 
export type { CloudVolumesConf };
 
export type Job = {
  jobId: string,
  action: 'create' | 'update' | 'delete',
  objectId: string,
  objectType: 'Volume' | 'Snapshot' | 'Backup' | 'MountTarget',
  state: 'ongoing' | 'done' | 'error',
  stateDetails: string,
};
 
export interface Async<T> {
  value: T;
  finish(
    sideEffect?: ?(job: Job) => Promise<void>,
    interval?: number,
    timeout?: number,
  ): Promise<Job[]>;
}
 
/**
 * The Cloud Volumes resources API.
 */
export interface CloudVolumes {
  activeDirectory: ActiveDirectoryAPI;
  backups: BackupsAPI;
  catalog: CatalogAPI;
  ipRanges: IPRangesAPI;
  jobs: JobsAPI;
  networks: NetworksAPI;
  regions: RegionsAPI;
  serviceLevels: ServiceLevelAPI;
  snapshots: SnapshotsAPI;
  volumes: VolumesAPI;
  zones: ZonesAPI;
}
 
/**
 * Manage cloud volumes storage resources.
 *
 * @example
 *
 * import api from 'qstack-client/api/cloud-volumes';
 *
 * const conf = {
 *   apiKey: 'api-key',
 *   secretKey: 'secret-key',
 *   url: 'http://nfs.example.com',
 * };
 *
 * api(conf).volumes.list();
 */
export default function cloudVolumes(conf: CloudVolumesConf): CloudVolumes {
  logger.silly(`CloudVolumes conf=${JSON.stringify(conf)}`);
 
  function call(method, command, data) {
    return callCloudVolumes(conf, method, command, data);
  }
 
  return {
    activeDirectory: activeDirectory(call),
    backups: backups(call),
    catalog: catalog(call),
    ipRanges: ipRanges(call),
    jobs: jobs(call),
    networks: networks(call),
    regions: regions(call),
    serviceLevels: serviceLevels(call),
    snapshots: snapshots(call),
    volumes: volumes(call),
    zones: zones(call),
  };
}