|
| 1 | +import OracleInstanceManager from './oracle_instance_manager'; |
| 2 | +import CustomInstanceManager from './custom_instance_manager'; |
| 3 | +import DigitalOceanInstanceManager from './digital_ocean_instance_manager'; |
| 4 | +import { CloudInstanceManager } from './cloud_instance_manager'; |
| 5 | + |
| 6 | +export interface CloudInstanceManagerSelectorOptions { |
| 7 | + cloudProviders: string[]; |
| 8 | + isDryRun: boolean; |
| 9 | + ociConfigurationFilePath: string; |
| 10 | + ociConfigurationProfile: string; |
| 11 | + |
| 12 | + digitalOceanAPIToken: string; |
| 13 | + digitalOceanConfigurationFilePath: string; |
| 14 | + |
| 15 | + customConfigurationLaunchScriptPath: string; |
| 16 | + customConfigurationLaunchScriptTimeoutMs: number; |
| 17 | +} |
| 18 | + |
| 19 | +export class CloudInstanceManagerSelector { |
| 20 | + private oracleInstanceManager: OracleInstanceManager; |
| 21 | + private digitalOceanInstanceManager: DigitalOceanInstanceManager; |
| 22 | + private customInstanceManager: CustomInstanceManager; |
| 23 | + |
| 24 | + constructor(options: CloudInstanceManagerSelectorOptions) { |
| 25 | + if (options.cloudProviders.includes('oracle')) { |
| 26 | + this.oracleInstanceManager = new OracleInstanceManager({ |
| 27 | + isDryRun: options.isDryRun, |
| 28 | + ociConfigurationFilePath: options.ociConfigurationFilePath, |
| 29 | + ociConfigurationProfile: options.ociConfigurationProfile, |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + if (options.cloudProviders.includes('custom')) { |
| 34 | + this.customInstanceManager = new CustomInstanceManager({ |
| 35 | + isDryRun: options.isDryRun, |
| 36 | + customConfigurationLaunchScriptPath: options.customConfigurationLaunchScriptPath, |
| 37 | + customConfigurationLaunchScriptTimeoutMs: options.customConfigurationLaunchScriptTimeoutMs, |
| 38 | + }); |
| 39 | + } |
| 40 | + if (options.cloudProviders.includes('digitalocean')) { |
| 41 | + this.digitalOceanInstanceManager = new DigitalOceanInstanceManager({ |
| 42 | + isDryRun: options.isDryRun, |
| 43 | + digitalOceanAPIToken: options.digitalOceanAPIToken, |
| 44 | + digitalOceanConfigurationFilePath: options.digitalOceanConfigurationFilePath, |
| 45 | + }); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + selectInstanceManager(cloud: string): CloudInstanceManager { |
| 50 | + switch (cloud) { |
| 51 | + case 'oracle': |
| 52 | + return this.oracleInstanceManager; |
| 53 | + case 'digitalocean': |
| 54 | + return this.digitalOceanInstanceManager; |
| 55 | + case 'custom': |
| 56 | + return this.customInstanceManager; |
| 57 | + default: |
| 58 | + return null; |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments