Class: VmShepherd::Shepherd
- Inherits:
-
Object
- Object
- VmShepherd::Shepherd
- Defined in:
- lib/vm_shepherd/shepherd.rb
Defined Under Namespace
Classes: InvalidIaas
Instance Method Summary collapse
- #clean_environment ⇒ Object
- #deploy(paths:) ⇒ Object
- #destroy ⇒ Object
-
#initialize(settings:) ⇒ Shepherd
constructor
A new instance of Shepherd.
- #prepare_environment ⇒ Object
Constructor Details
#initialize(settings:) ⇒ Shepherd
Returns a new instance of Shepherd.
6 7 8 |
# File 'lib/vm_shepherd/shepherd.rb', line 6 def initialize(settings:) @settings = settings end |
Instance Method Details
#clean_environment ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/vm_shepherd/shepherd.rb', line 136 def clean_environment unless valid_iaas_types.include?(settings.iaas_type) fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}") end case settings.iaas_type when VmShepherd::VCLOUD_IAAS_TYPE then vm_shepherd_configs(settings).each do |vm_shepherd_config| VmShepherd::VcloudManager.new( { url: vm_shepherd_config.creds.url, organization: vm_shepherd_config.creds.organization, user: vm_shepherd_config.creds.user, password: vm_shepherd_config.creds.password, }, vm_shepherd_config.vdc.name, stdout_logger, ).clean_environment(vm_shepherd_config.vapp.product_names || [], vm_shepherd_config.vapp.product_catalog) end when VmShepherd::VSPHERE_IAAS_TYPE then vm_shepherd_configs(settings).each do |vm_shepherd_config| VmShepherd::VsphereManager.new( vm_shepherd_config.vcenter_creds.ip, vm_shepherd_config.vcenter_creds.username, vm_shepherd_config.vcenter_creds.password, vm_shepherd_config.cleanup.datacenter, stdout_logger, ).clean_environment( datacenter_folders_to_clean: vm_shepherd_config.cleanup.datacenter_folders_to_clean, datastores: vm_shepherd_config.cleanup.datastores, datastore_folders_to_clean: vm_shepherd_config.cleanup.datastore_folders_to_clean, ) end when VmShepherd::AWS_IAAS_TYPE then ami_manager.clean_environment when VmShepherd::OPENSTACK_IAAS_TYPE then vm_shepherd_configs(settings).each do |vm_shepherd_config| openstack_vm_manager(vm_shepherd_config).clean_environment end end end |
#deploy(paths:) ⇒ Object
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 |
# File 'lib/vm_shepherd/shepherd.rb', line 10 def deploy(paths:) unless valid_iaas_types.include?(settings.iaas_type) fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}") end configs = vm_shepherd_configs(settings) unless configs.size == paths.size fail(ArgumentError, "mismatch in available images to deploy (needed #{configs.size}, got #{paths.size})") end configs.zip(paths).each do |vm_shepherd_config, path| case settings.iaas_type when VmShepherd::VCLOUD_IAAS_TYPE then VmShepherd::VcloudManager.new( { url: vm_shepherd_config.creds.url, organization: vm_shepherd_config.creds.organization, user: vm_shepherd_config.creds.user, password: vm_shepherd_config.creds.password, }, vm_shepherd_config.vdc.name, stdout_logger ).deploy( path, (vm_shepherd_config), ) when VmShepherd::VSPHERE_IAAS_TYPE then VmShepherd::VsphereManager.new( vm_shepherd_config.vcenter_creds.ip, vm_shepherd_config.vcenter_creds.username, vm_shepherd_config.vcenter_creds.password, vm_shepherd_config.vsphere.datacenter, stdout_logger, ).deploy( path, { ip: vm_shepherd_config.vm.ip, gateway: vm_shepherd_config.vm.gateway, netmask: vm_shepherd_config.vm.netmask, dns: vm_shepherd_config.vm.dns, ntp_servers: vm_shepherd_config.vm.ntp_servers, }, { cluster: vm_shepherd_config.vsphere.cluster, resource_pool: vm_shepherd_config.vsphere.resource_pool, datastore: vm_shepherd_config.vsphere.datastore, network: vm_shepherd_config.vsphere.network, folder: vm_shepherd_config.vsphere.folder, } ) when VmShepherd::AWS_IAAS_TYPE then ami_manager.deploy(ami_file_path: path, vm_config: vm_shepherd_config.to_h) when VmShepherd::OPENSTACK_IAAS_TYPE then openstack_vm_manager(vm_shepherd_config).deploy(path, (vm_shepherd_config)) end end end |
#destroy ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/vm_shepherd/shepherd.rb', line 103 def destroy unless valid_iaas_types.include?(settings.iaas_type) fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}") end vm_shepherd_configs(settings).each do |vm_shepherd_config| case settings.iaas_type when VmShepherd::VCLOUD_IAAS_TYPE then VmShepherd::VcloudManager.new( { url: vm_shepherd_config.creds.url, organization: vm_shepherd_config.creds.organization, user: vm_shepherd_config.creds.user, password: vm_shepherd_config.creds.password, }, vm_shepherd_config.vdc.name, stdout_logger ).destroy([vm_shepherd_config.vapp.ops_manager_name], vm_shepherd_config.vdc.catalog) when VmShepherd::VSPHERE_IAAS_TYPE then VmShepherd::VsphereManager.new( vm_shepherd_config.vcenter_creds.ip, vm_shepherd_config.vcenter_creds.username, vm_shepherd_config.vcenter_creds.password, vm_shepherd_config.vsphere.datacenter, stdout_logger, ).destroy(vm_shepherd_config.vm.ip, vm_shepherd_config.vsphere.resource_pool) when VmShepherd::AWS_IAAS_TYPE then ami_manager.destroy(vm_shepherd_config.to_h) when VmShepherd::OPENSTACK_IAAS_TYPE then openstack_vm_manager(vm_shepherd_config).destroy((vm_shepherd_config)) end end end |
#prepare_environment ⇒ Object
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 99 100 101 |
# File 'lib/vm_shepherd/shepherd.rb', line 66 def prepare_environment unless valid_iaas_types.include?(settings.iaas_type) fail(InvalidIaas, "Unknown IaaS type: #{settings.iaas_type.inspect}") end case settings.iaas_type when VmShepherd::VCLOUD_IAAS_TYPE then vm_shepherd_configs(settings).each do |vm_shepherd_config| VmShepherd::VcloudManager.new( { url: vm_shepherd_config.creds.url, organization: vm_shepherd_config.creds.organization, user: vm_shepherd_config.creds.user, password: vm_shepherd_config.creds.password, }, vm_shepherd_config.vdc.name, stdout_logger ).prepare_environment end when VmShepherd::VSPHERE_IAAS_TYPE then vm_shepherd_configs(settings).each do |vm_shepherd_config| VmShepherd::VsphereManager.new( vm_shepherd_config.vcenter_creds.ip, vm_shepherd_config.vcenter_creds.username, vm_shepherd_config.vcenter_creds.password, vm_shepherd_config.vsphere.datacenter, stdout_logger, ).prepare_environment end when VmShepherd::AWS_IAAS_TYPE then ami_manager.prepare_environment(settings.vm_shepherd.env_config.json_file) when VmShepherd::OPENSTACK_IAAS_TYPE then vm_shepherd_configs(settings).each do |vm_shepherd_config| openstack_vm_manager(vm_shepherd_config).prepare_environment end end end |