├── README ├── Automate └── RedHatConsulting_Satellite6 │ ├── Integration │ ├── Satellite │ │ ├── Operations │ │ │ ├── Methods.class │ │ │ │ ├── __methods__ │ │ │ │ │ ├── release_ip_address.rb │ │ │ │ │ ├── acquire_ip_address.rb │ │ │ │ │ ├── set_user_data.yaml │ │ │ │ │ ├── update_satellite.yaml │ │ │ │ │ ├── acquire_ip_address.yaml │ │ │ │ │ ├── release_ip_address.yaml │ │ │ │ │ ├── unregister_satellite.yaml │ │ │ │ │ ├── register_satellite.yaml │ │ │ │ │ ├── check_satellite_build_completed.yaml │ │ │ │ │ ├── check_satellite_build_completed.rb │ │ │ │ │ ├── unregister_satellite.rb │ │ │ │ │ ├── set_user_data.rb │ │ │ │ │ └── update_satellite.rb │ │ │ │ ├── setuserdata.yaml │ │ │ │ ├── updatesatellite.yaml │ │ │ │ ├── acquireipaddress.yaml │ │ │ │ ├── registersatellite.yaml │ │ │ │ ├── unregistersatellite.yaml │ │ │ │ ├── releaseipaddress.yaml │ │ │ │ ├── checksatellitebuildcompleted.yaml │ │ │ │ └── __class__.yaml │ │ │ └── __namespace__.yaml │ │ ├── __namespace__.yaml │ │ ├── Configuration.class │ │ │ ├── default.yaml │ │ │ ├── __methods__ │ │ │ │ ├── get_satellite_configuration.yaml │ │ │ │ └── get_satellite_configuration.rb │ │ │ └── __class__.yaml │ │ ├── StdLib.class │ │ │ ├── __class__.yaml │ │ │ └── __methods__ │ │ │ │ ├── satellitecore.yaml │ │ │ │ └── satellitecore.rb │ │ └── DynamicDialogs.class │ │ │ ├── get_locations.yaml │ │ │ ├── get_hostgroups.yaml │ │ │ ├── get_organizations.yaml │ │ │ ├── __methods__ │ │ │ ├── get_hostgroups.yaml │ │ │ ├── get_locations.yaml │ │ │ ├── get_organizations.yaml │ │ │ ├── get_locations_by_tag_path.yaml │ │ │ ├── get_lifecycle_environments.yaml │ │ │ ├── get_locations_filtered_by_tags.yaml │ │ │ ├── get_templates_based_on_selected_os_and_location_and_environment.yaml │ │ │ ├── get_domains_by_location.yaml │ │ │ ├── get_lifecycle_environments_filtered_by_tags.yaml │ │ │ ├── get_organizations.rb │ │ │ ├── get_locations.rb │ │ │ ├── get_lifecycle_environments.rb │ │ │ ├── get_hostgroups.rb │ │ │ ├── get_locations_filtered_by_tags.rb │ │ │ ├── get_locations_by_tag_path.rb │ │ │ ├── get_domains_by_location.rb │ │ │ ├── get_lifecycle_environments_filtered_by_tags.rb │ │ │ └── get_templates_based_on_selected_os_and_location_and_environment.rb │ │ │ ├── get_locations_by_tag_path.yaml │ │ │ ├── get_lifecycle_environments.yaml │ │ │ ├── get_location_0_domains.yaml │ │ │ ├── get_location_1_domains.yaml │ │ │ ├── get_location_2_domains.yaml │ │ │ ├── get_location_3_domains.yaml │ │ │ ├── get_locations_filtered_by_tags.yaml │ │ │ ├── get_lifecycle_environments_filtered_by_tags.yaml │ │ │ ├── get_lifecycle_environment_names_filtered_by_tags.yaml │ │ │ ├── get_templates_based_on_selected_os_and_location_and_environment.yaml │ │ │ └── __class__.yaml │ └── __namespace__.yaml │ ├── Cloud │ ├── VM │ │ ├── __namespace__.yaml │ │ ├── Retirement │ │ │ ├── __namespace__.yaml │ │ │ └── StateMachines │ │ │ │ ├── __namespace__.yaml │ │ │ │ └── VMRetirement.class │ │ │ │ ├── default.yaml │ │ │ │ └── __class__.yaml │ │ └── Provisioning │ │ │ ├── __namespace__.yaml │ │ │ └── StateMachines │ │ │ ├── __namespace__.yaml │ │ │ └── VMProvision_VM.class │ │ │ └── satellite.yaml │ └── __namespace__.yaml │ ├── Service │ ├── __namespace__.yaml │ └── Provisioning │ │ ├── __namespace__.yaml │ │ └── StateMachines │ │ ├── __namespace__.yaml │ │ ├── Methods.class │ │ ├── set_satellite_options.yaml │ │ ├── __methods__ │ │ │ ├── set_satellite_options.yaml │ │ │ ├── set_custom_provision_type.yaml │ │ │ ├── set_custom_provision_task_options.yaml │ │ │ ├── set_custom_provision_type.rb │ │ │ ├── set_satellite_options.rb │ │ │ └── set_custom_provision_task_options.rb │ │ ├── set_custom_provision_type.yaml │ │ └── __class__.yaml │ │ └── ServiceProvision_Template.class │ │ ├── satellite_catalogiteminitialization.yaml │ │ └── __class__.yaml │ ├── Infrastructure │ ├── VM │ │ ├── __namespace__.yaml │ │ ├── Provisioning │ │ │ ├── __namespace__.yaml │ │ │ └── StateMachines │ │ │ │ ├── __namespace__.yaml │ │ │ │ ├── Methods.class │ │ │ │ ├── __methods__ │ │ │ │ │ ├── process_telemetry_data.yaml │ │ │ │ │ └── process_telemetry_data.rb │ │ │ │ └── __class__.yaml │ │ │ │ └── VMProvision_VM.class │ │ │ │ └── satellite.yaml │ │ └── Retirement │ │ │ ├── __namespace__.yaml │ │ │ └── StateMachines │ │ │ ├── __namespace__.yaml │ │ │ └── VMRetirement.class │ │ │ ├── default.yaml │ │ │ └── __class__.yaml │ ├── Network │ │ ├── __namespace__.yaml │ │ └── DDIProviders.class │ │ │ ├── satellite.yaml │ │ │ └── __class__.yaml │ └── __namespace__.yaml │ └── __domain__.yaml ├── .gitignore ├── README.md ├── Catalogs ├── v5.9 │ └── Hybrid_Cloud_VMs.yml └── v5.8 │ └── Hybrid_Cloud_VMs.yml └── INSTALL.md /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/release_ip_address.rb: -------------------------------------------------------------------------------- 1 | $evm.log(:info, "No-op. Satellite will handle releasing the IP address and updating DNS.") 2 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/acquire_ip_address.rb: -------------------------------------------------------------------------------- 1 | $evm.log(:info, "No-op. Satellite will handle aquiring an IP address and registering with DNS.") 2 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: VM 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Cloud 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Service 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: VM 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Integration 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Retirement/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Retirement 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/Network/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Network 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Infrastructure 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Satellite 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Provisioning 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Provisioning/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Provisioning 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Provisioning 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Retirement/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Retirement 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Configuration.class/default.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: default 8 | inherits: 9 | description: 10 | fields: [] 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: Operations 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Retirement/StateMachines/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: StateMachines 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: StateMachines 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Provisioning/StateMachines/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: StateMachines 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: StateMachines 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Retirement/StateMachines/__namespace__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: namespace 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: StateMachines 7 | description: 8 | display_name: 9 | priority: 10 | enabled: 11 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/StdLib.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: 7 | display_name: 8 | name: StdLib 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: [] 14 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_locations.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_locations 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_locations 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/setuserdata.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: SetUserData 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: set_user_data 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_hostgroups.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_hostgroups 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_hostgroups 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_organizations.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_organizations 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_organizations 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/updatesatellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: UpdateSatellite 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: update_satellite 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/acquireipaddress.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: AcquireIPAddress 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: acquire_ip_address 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/registersatellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: RegisterSatellite 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: register_satellite 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_hostgroups.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_hostgroups 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_locations.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_locations 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_organizations.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_organizations 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/unregistersatellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: UnregisterSatellite 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: unregister_satellite 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/set_satellite_options.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: set_satellite_options 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: set_satellite_options 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_locations_by_tag_path.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_locations_by_tag_path 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_locations_by_tag_path 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/set_user_data.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: set_user_data 7 | display_name: SetUserData 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/releaseipaddress.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: ReleaseIPAddress 8 | inherits: 9 | description: release_ip_address 10 | fields: 11 | - execute: 12 | value: release_ip_address 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_locations_by_tag_path.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_locations_by_tag_path 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_lifecycle_environments.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_lifecycle_environments 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_lifecycle_environments 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_satellite_options.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: set_satellite_options 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/set_custom_provision_type.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: set_custom_provision_type 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: set_custom_provision_type 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Configuration.class/__methods__/get_satellite_configuration.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_satellite_configuration 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_lifecycle_environments.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_lifecycle_environments 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/update_satellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: update_satellite 7 | display_name: UpdateSatellite 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_locations_filtered_by_tags.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_locations_filtered_by_tags 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_location_0_domains.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_location_0_domains 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_domains_by_location(location_index => 0) 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_location_1_domains.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_location_1_domains 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_domains_by_location(location_index => 1) 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_location_2_domains.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_location_2_domains 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_domains_by_location(location_index => 2) 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_location_3_domains.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_location_3_domains 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_domains_by_location(location_index => 3) 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_locations_filtered_by_tags.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_locations_filtered_by_tags 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_locations_filtered_by_tags 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/acquire_ip_address.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: acquire_ip_address 7 | display_name: AcquireIPAddress 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/release_ip_address.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: release_ip_address 7 | display_name: ReleaseIPAddress 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/checksatellitebuildcompleted.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: CheckSatelliteBuildCompleted 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: check_satellite_build_completed 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_custom_provision_type.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: set_custom_provision_type 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/unregister_satellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: unregister_satellite 7 | display_name: UnregisterSatellite 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_custom_provision_task_options.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: set_custom_provision_task_options 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/process_telemetry_data.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: process_telemetry_data 7 | display_name: ProcessTelemetryData 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: [] 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/register_satellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: register_satellite 7 | display_name: RegisterSatellite 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | options: {} 13 | inputs: [] 14 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/__domain__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: domain 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: RedHatConsulting_Satellite6 7 | description: ManageIQ Automate Domain for integrating with Red Hat Satellite 6 8 | developed by Red Hat Consulting 9 | display_name: Red Hat Satellite 6 10 | enabled: true 11 | source: user 12 | top_level_namespace: 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_lifecycle_environments_filtered_by_tags.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_lifecycle_environments_filtered_by_tags 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_lifecycle_environments_filtered_by_tags 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/check_satellite_build_completed.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: check_satellite_build_completed 7 | display_name: CheckSatelliteBuildCompleted 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | options: {} 13 | inputs: [] 14 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/StdLib.class/__methods__/satellitecore.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: SatelliteCore 7 | display_name: Satellite Core Methods 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | embedded_methods: 13 | - "/StdLib/Core/Core" 14 | options: {} 15 | inputs: [] 16 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_lifecycle_environment_names_filtered_by_tags.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_lifecycle_environment_names_filtered_by_tags 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_lifecycle_environments_filtered_by_tags( return_key => 'name' ) 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | ~* 4 | .~* 5 | .bundle 6 | .config 7 | .idea 8 | .idea/* 9 | */.idea 10 | */.idea/* 11 | **/.idea 12 | **/.idea/* 13 | coverage 14 | InstalledFiles 15 | lib/bundler/man 16 | pkg 17 | rdoc 18 | spec/reports 19 | test/tmp 20 | test/version_tmp 21 | tmp 22 | asciidoc/images/icons/* 23 | log/* 24 | .manifest.yaml 25 | 26 | # YARD artifacts 27 | .yardoc 28 | _yardoc 29 | doc/ 30 | 31 | # Emacs temporary files 32 | *# 33 | .#* 34 | 35 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/get_templates_based_on_selected_os_and_location_and_environment.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: get_templates_based_on_selected_os_and_location_and_environment 8 | inherits: 9 | description: 10 | fields: 11 | - execute: 12 | value: get_templates_based_on_selected_os_and_location_and_environment 13 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/Network/DDIProviders.class/satellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: satellite 8 | inherits: 9 | description: 10 | fields: 11 | - AcquireIPAddress: 12 | value: "/Integration/Satellite/Operations/Methods/AcquireIPAddress" 13 | - ReleaseIPAddress: 14 | value: "/Integration/Satellite/Operations/Methods/ReleaseIPAddress" 15 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_templates_based_on_selected_os_and_location_and_environment.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_templates_based_on_selected_os_and_location_and_environment 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | embedded_methods: 13 | - "/StdLib/Core/Core" 14 | options: {} 15 | inputs: [] 16 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Retirement/StateMachines/VMRetirement.class/default.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: Default 8 | inherits: 9 | description: 10 | fields: 11 | - RemoveFromProvider: 12 | value: "/Cloud/VM/Retirement/StateMachines/Methods/RemoveFromProvider" 13 | - CheckRemovedFromProvider: 14 | value: "/Cloud/VM/Retirement/StateMachines/Methods/CheckRemovedFromProvider" 15 | - DeleteFromVMDB: 16 | value: "#/Cloud/VM/Retirement/StateMachines/Methods/DeleteFromVMDB" 17 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Configuration.class/__methods__/get_satellite_configuration.rb: -------------------------------------------------------------------------------- 1 | # Get the required Satellite configuration from configured Foreman provider 2 | # 3 | # @return satellite_server 4 | # @return satellite_username 5 | # @return satellite_password 6 | @DEBUG = false 7 | 8 | begin 9 | satellite_provider = $evm.vmdb(:ManageIQ_Providers_Foreman_Provider).first 10 | 11 | if !satellite_provider.nil? 12 | $evm.object['satellite_username'] = satellite_provider.object_send(:authentication_userid) 13 | $evm.object['satellite_password'] = satellite_provider.object_send(:authentication_password) 14 | $evm.object['satellite_server'] = satellite_provider.url 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: 7 | display_name: 8 | name: Methods 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: method 16 | name: execute 17 | display_name: '' 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: 30 | on_exit: 31 | on_error: 32 | max_retries: 33 | max_time: 34 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: 7 | display_name: 8 | name: Methods 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: method 16 | name: execute 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: 30 | on_exit: 31 | on_error: 32 | max_retries: 33 | max_time: 34 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: 7 | display_name: 8 | name: DynamicDialogs 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: method 16 | name: execute 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: 30 | on_exit: 31 | on_error: 32 | max_retries: 33 | max_time: 34 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_domains_by_location.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_domains_by_location 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | inputs: 13 | - field: 14 | aetype: 15 | name: location_index 16 | display_name: 17 | datatype: integer 18 | priority: 1 19 | owner: 20 | default_value: 21 | substitute: false 22 | message: create 23 | visibility: 24 | collect: 25 | scope: 26 | description: 27 | condition: 28 | on_entry: 29 | on_exit: 30 | on_error: 31 | max_retries: 32 | max_time: 33 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_lifecycle_environments_filtered_by_tags.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: method 3 | version: 1.0 4 | object: 5 | attributes: 6 | name: get_lifecycle_environments_filtered_by_tags 7 | display_name: 8 | description: 9 | scope: instance 10 | language: ruby 11 | location: inline 12 | embedded_methods: 13 | - "/StdLib/Core/Core" 14 | options: {} 15 | inputs: 16 | - field: 17 | aetype: 18 | name: return_key 19 | display_name: 20 | datatype: 21 | priority: 1 22 | owner: 23 | default_value: id 24 | substitute: false 25 | message: create 26 | visibility: 27 | collect: 28 | scope: 29 | description: 30 | condition: 31 | on_entry: 32 | on_exit: 33 | on_error: 34 | max_retries: 35 | max_time: 36 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Retirement/StateMachines/VMRetirement.class/default.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: Default 8 | inherits: 9 | description: 10 | fields: 11 | - ReleaseIPAddress: 12 | value: "/Infrastructure/Network/Operations/Methods/ReleaseIPAddress" 13 | collect: "/released_ip_address = released_ip_address" 14 | - RemoveFromProvider: 15 | value: "/Infrastructure/VM/Retirement/StateMachines/Methods/RemoveFromProvider" 16 | - CheckRemovedFromProvider: 17 | value: "/Infrastructure/VM/Retirement/StateMachines/Methods/CheckRemovedFromProvider" 18 | - UnregisterSatellite: 19 | value: "/Integration/Satellite/Operations/Methods/UnregisterSatellite" 20 | on_entry: update_retirement_status(status => 'Unregistering from Satellite'') 21 | on_exit: update_retirement_status(status => 'Unregistered from Satellite'') 22 | on_error: update_retirement_status(status => 'Failed Unregistering from Satellite'') 23 | - DeleteFromVMDB: 24 | value: "#/Infrastructure/VM/Retirement/StateMachines/Methods/DeleteFromVMDB" 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # miq-RedHat-Satellite6 2 | ManageIQ Automate Domain for integrating with Red Hat Satellite 6 developed by Red Hat Consulting. 3 | 4 | # Table of Contents 5 | * [miq-RedHat-Satellite6](#miq-redhat-satellite6) 6 | * [Table of Contents](#table-of-contents) 7 | * [Features](#features) 8 | * [Dependencies](#dependencies) 9 | * [Other Datastores](#other-datastores) 10 | * [Install](#install) 11 | * [Contributors](#contributors) 12 | 13 | # Features 14 | The high level features of this ManageIQ extension. 15 | 16 | * Satellite 6 PXE & Kickstart based provisioning Service and VM state machines 17 | * Register VM to Satellite 6 18 | * VM retirment including unregister VM from Satellite 6 19 | * Satellite 6 dynamic dialogs 20 | * hostgroups 21 | * lifecycle environments 22 | * locations 23 | * organizaitons 24 | 25 | # Dependencies 26 | Dependencies of this ManageIQ extensions. 27 | 28 | ## Other Datastores 29 | These ManageIQ atuomate domains must also be installed for this datastore to function. 30 | 31 | * [RedHatConsulting_Utilities](https://github.com/rhtconsulting/miq-Utilities) 32 | 33 | # Install 34 | 0. Install dependencies 35 | 1. Automate -> Import/Export 36 | 2. Import Datastore via git 37 | 3. Git URL: `https://github.com/rhtconsulting/miq-RedHat-Satellite6.git` 38 | 4. Submit 39 | 5. Select Branc/Tag to syncronize with 40 | 6. Submit 41 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/Network/DDIProviders.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: DNS, DHCP, and/or IPAM (DDI) providers and their supported operations. 7 | display_name: 8 | name: DDIProviders 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: relationship 16 | name: AcquireIPAddress 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: acquire_ip_address 24 | visibility: 25 | collect: "/acquired_ip_address = acquired_ip_address" 26 | scope: 27 | description: 28 | condition: 29 | on_entry: 30 | on_exit: 31 | on_error: 32 | max_retries: 33 | max_time: 34 | - field: 35 | aetype: relationship 36 | name: ReleaseIPAddress 37 | display_name: 38 | datatype: string 39 | priority: 2 40 | owner: 41 | default_value: 42 | substitute: true 43 | message: release_ip_address 44 | visibility: 45 | collect: "/released_ip_address = release_ip_address" 46 | scope: 47 | description: 48 | condition: 49 | on_entry: 50 | on_exit: 51 | on_error: 52 | max_retries: 53 | max_time: 54 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_custom_provision_type.rb: -------------------------------------------------------------------------------- 1 | # NOTE: DEPRECATED!!!!! 2 | # 3 | # 4 | # Sets :custom_provision_type option on all of the miq_provision_request objects associated with the current service_template_provision_task. 5 | # 6 | # EXPECTED 7 | # EVM ROOT 8 | # service_template_provision_task - set to VM to get LDAP entries for 9 | # 10 | # SETS 11 | # each miq_provision_request 12 | # :custom_provision_type - Custom provisining type to use for the miq_provision_request 13 | # 14 | @DEBUG = false 15 | 16 | VM_PROVISION_TYPE = 'satellite' 17 | 18 | # Log an error and exit. 19 | # 20 | # @param msg Message to error with 21 | def error(msg) 22 | $evm.log(:error, msg) 23 | $evm.root['ae_result'] = 'error' 24 | $evm.root['ae_reason'] = msg.to_s 25 | exit MIQ_STOP 26 | end 27 | 28 | begin 29 | $evm.log(:info, "START - set_custom_provision_type") if @DEBUG 30 | 31 | task = $evm.root['service_template_provision_task'] 32 | error("$evm.root['service_template_provision_task'] not found") if task.nil? 33 | 34 | task.miq_request_tasks.each do |service_provision_task| 35 | service_provision_task.miq_request_tasks.each do |vm_provision_task| 36 | vm_provision_task.set_option(:custom_provision_type, VM_PROVISION_TYPE) 37 | $evm.log(:info, "{ vm_provision_task => #{vm_provision_task}, vm_provision_task.get_option(:custom_provision_type) => '#{vm_provision_task.get_option(:custom_provision_type)}' }") if @DEBUG 38 | end 39 | end 40 | 41 | $evm.log(:info, "END - set_custom_provision_type") if @DEBUG 42 | end 43 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Provisioning/StateMachines/VMProvision_VM.class/satellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: Provision VM using Satellite 7 | name: satellite 8 | inherits: 9 | description: 10 | fields: 11 | - PreProvision_2: 12 | value: "/Integration/Satellite/Operations/Methods/RegisterSatellite" 13 | on_entry: update_provision_status(status => 'Creating Satellite Host Entry') 14 | on_exit: update_provision_status(status => 'Created Satellite Host Entry') 15 | on_error: 'update_provision_status(status => ''Error creating Satellite Host 16 | Entry: ${/#ae_reason}'')' 17 | - PreProvision_3: 18 | value: "/Integration/Satellite/Operations/Methods/SetUserData" 19 | on_entry: update_provision_status(status => 'Setting User Data') 20 | on_exit: update_provision_status(status => 'Set User Data') 21 | on_error: 'update_provision_status(status => ''Error Setting User Data: ${/#ae_reason}'')' 22 | - Provision: 23 | value: "/Cloud/VM/Provisioning/StateMachines/Methods/Provision" 24 | - CheckProvisioned: 25 | value: "/Cloud/VM/Provisioning/StateMachines/Methods/CheckProvisioned" 26 | - PostVMClone_1: 27 | value: "/Integration/Satellite/Operations/Methods/UpdateSatellite" 28 | on_entry: update_provision_status(status => 'Update Satellite Host Record') 29 | on_exit: update_provision_status(status => 'Updated Satellite Host Record') 30 | on_error: 'update_provision_status(status => ''Failed to update Satellite Host 31 | Record: ${/#ae_reason}'')' 32 | - CheckBuildCompleted: 33 | value: "/Integration/Satellite/Operations/Methods/CheckSatelliteBuildCompleted" 34 | on_entry: update_provision_status(status => 'Waiting for VM Satellite Build 35 | to Complete') 36 | on_exit: update_provision_status(status => 'Waiting for VM Satellite Build to 37 | Complete') 38 | on_error: 'update_provision_status(status => ''Failed waiting for VM Satellite 39 | Build to Complete: ${/#ae_reason}'')' 40 | - PostBuildCompleted_5: 41 | value: "/AutomationManagement/AnsibleTower/Operations/OptionalJobTemplate/Default" 42 | on_entry: update_provision_status(status => 'Running Ansible Tower Job') 43 | on_exit: update_provision_status(status => 'Running Ansible Tower Job') 44 | on_error: 'update_provision_status(status => ''Error running Ansible Tower Job: 45 | ${/#ae_reason}'')' 46 | -------------------------------------------------------------------------------- /Catalogs/v5.9/Hybrid_Cloud_VMs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - Hybrid Cloud VMs: 3 | name: Hybrid Cloud VMs 4 | description: Service catalogs to deploy VMs across a hybrid cloud. 5 | tenant_name: My Company 6 | template: 7 | - name: Hybrid Cloud | RHEL 8 | description: Provision RHEL across the hybrid cloud 9 | type: 10 | display: true 11 | service_type: atomic 12 | prov_type: generic 13 | provision_cost: 14 | long_description: '' 15 | tenant_name: My Company 16 | options: {} 17 | service_template_catalog_name: Hybrid Cloud VMs 18 | resource_actions: 19 | - action: Provision 20 | ae_namespace: RedHatConsulting_Utilities/Service/Provisioning/StateMachines 21 | ae_class: ServiceProvision_Template 22 | ae_instance: Generic_CatalogItemInitialization 23 | ae_message: 24 | ae_attributes: 25 | :service_action: Provision 26 | dialog_label: Satellite Provisioning 27 | - action: Retirement 28 | ae_namespace: Service/Retirement/StateMachines 29 | ae_class: ServiceRetirement 30 | ae_instance: Default 31 | ae_message: 32 | ae_attributes: 33 | :service_action: Retirement 34 | dialog_label: Satellite Provisioning 35 | custom_buttons: [] 36 | custom_button_sets: [] 37 | - name: Hybrid Cloud | Apache HTTPD 38 | description: Provision Apache HTTPD across the hybrid cloud 39 | type: 40 | display: true 41 | service_type: atomic 42 | prov_type: generic 43 | provision_cost: 44 | long_description: '' 45 | tenant_name: My Company 46 | options: {} 47 | service_template_catalog_name: Hybrid Cloud VMs 48 | resource_actions: 49 | - action: Provision 50 | ae_namespace: RedHatConsulting_Utilities/Service/Provisioning/StateMachines 51 | ae_class: ServiceProvision_Template 52 | ae_instance: Generic_CatalogItemInitialization 53 | ae_message: 54 | ae_attributes: 55 | :service_action: Provision 56 | dialog_label: Satellite Provisioning (Apache HTTPD) 57 | - action: Retirement 58 | ae_namespace: Service/Retirement/StateMachines 59 | ae_class: ServiceRetirement 60 | ae_instance: Default 61 | ae_message: 62 | ae_attributes: 63 | :service_action: Retirement 64 | dialog_label: Satellite Provisioning (Apache HTTPD) 65 | custom_buttons: [] 66 | custom_button_sets: [] 67 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_organizations.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Organizations from Satellite. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | # Log an error and exit. 8 | # 9 | # @param msg Message to error with 10 | def error(msg) 11 | $evm.log(:error, msg) 12 | $evm.root['ae_result'] = 'error' 13 | $evm.root['ae_reason'] = msg.to_s 14 | exit MIQ_STOP 15 | end 16 | 17 | # Gets an ApiPie binding to the Satellite API. 18 | # 19 | # @return ApipieBindings to the Satellite API 20 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 21 | def get_satellite_api() 22 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 23 | error("Satellite Configuration not found") if satellite_config.nil? 24 | 25 | satellite_server = satellite_config['satellite_server'] 26 | satellite_username = satellite_config['satellite_username'] 27 | satellite_password = satellite_config.decrypt('satellite_password') 28 | 29 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 30 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 31 | 32 | error("Satellite Server configuration not found") if satellite_server.nil? 33 | error("Satellite User configuration not found") if satellite_username.nil? 34 | error("Satellite Password configuration not found") if satellite_password.nil? 35 | 36 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 37 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 38 | return satellite_api 39 | end 40 | 41 | begin 42 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 43 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 44 | 45 | satellite_api = get_satellite_api() 46 | 47 | organization_index = satellite_api.resource(:organizations).call(:index) 48 | $evm.log(:info, "organization_index = #{organization_index}") if @DEBUG 49 | 50 | dialog_field = $evm.object 51 | dialog_field["sort_by"] = "value" 52 | dialog_field["sort_order"] = "ascending" 53 | dialog_field["data_type"] = "integer" 54 | dialog_field["required"] = true 55 | dialog_field['default_value'] = organization_index['results'][0]['id'] 56 | dialog_field["values"] = Hash[ *organization_index['results'].collect { |item| [item['id'], item['name']] }.flatten ] 57 | end 58 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_locations.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Locations from Satellite. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | # Log an error and exit. 8 | # 9 | # @param msg Message to error with 10 | def error(msg) 11 | $evm.log(:error, msg) 12 | $evm.root['ae_result'] = 'error' 13 | $evm.root['ae_reason'] = msg.to_s 14 | exit MIQ_STOP 15 | end 16 | 17 | # Gets an ApiPie binding to the Satellite API. 18 | # 19 | # @return ApipieBindings to the Satellite API 20 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 21 | def get_satellite_api() 22 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 23 | error("Satellite Configuration not found") if satellite_config.nil? 24 | 25 | satellite_server = satellite_config['satellite_server'] 26 | satellite_username = satellite_config['satellite_username'] 27 | satellite_password = satellite_config.decrypt('satellite_password') 28 | 29 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 30 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 31 | 32 | error("Satellite Server configuration not found") if satellite_server.nil? 33 | error("Satellite User configuration not found") if satellite_username.nil? 34 | error("Satellite Password configuration not found") if satellite_password.nil? 35 | 36 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 37 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 38 | return satellite_api 39 | end 40 | 41 | begin 42 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 43 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 44 | 45 | satellite_api = get_satellite_api() 46 | error('Could not get Satellite API') if satellite_api.nil? 47 | 48 | location_index = satellite_api.resource(:locations).call(:index) 49 | $evm.log(:info, "location_index => #{location_index}") if @DEBUG 50 | 51 | $evm.log(:info, "default value id => #{location_index['results'][0]['id']}") if @DEBUG 52 | 53 | dialog_field = $evm.object 54 | dialog_field["sort_by"] = "value" 55 | dialog_field["sort_order"] = "ascending" 56 | dialog_field["data_type"] = "integer" 57 | dialog_field["required"] = true 58 | dialog_field['default_value'] = location_index['results'][0]['id'] 59 | dialog_field["values"] = Hash[ *location_index['results'].collect { |item| [item['id'], item['title']] }.flatten ] 60 | end 61 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_lifecycle_environments.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Lifecycle Enviornments from a Satellite Organization. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | # Log an error and exit. 8 | # 9 | # @param msg Message to error with 10 | def error(msg) 11 | $evm.log(:error, msg) 12 | $evm.root['ae_result'] = 'error' 13 | $evm.root['ae_reason'] = msg.to_s 14 | exit MIQ_STOP 15 | end 16 | 17 | # Gets an ApiPie binding to the Satellite API. 18 | # 19 | # @return ApipieBindings to the Satellite API 20 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 21 | def get_satellite_api() 22 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 23 | error("Satellite Configuration not found") if satellite_config.nil? 24 | 25 | satellite_server = satellite_config['satellite_server'] 26 | satellite_username = satellite_config['satellite_username'] 27 | satellite_password = satellite_config.decrypt('satellite_password') 28 | 29 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 30 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 31 | 32 | error("Satellite Server configuration not found") if satellite_server.nil? 33 | error("Satellite User configuration not found") if satellite_username.nil? 34 | error("Satellite Password configuration not found") if satellite_password.nil? 35 | 36 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 37 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 38 | return satellite_api 39 | end 40 | 41 | begin 42 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 43 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 44 | 45 | satellite_api = get_satellite_api() 46 | 47 | satellite_organization_id = $evm.root['dialog_satellite_organization_id'] 48 | $evm.log(:info, "satellite_organization_id = #{satellite_organization_id}") if @DEBUG 49 | 50 | if !satellite_organization_id.length.zero? 51 | environments_index = satellite_api.resource(:lifecycle_environments).call(:index,{:organization_id => satellite_organization_id}) 52 | $evm.log(:info, "environments_index = #{environments_index}") if @DEBUG 53 | dialog_field_values = Hash[ *environments_index['results'].collect { |item| [item['id'], item['name']] }.flatten ] 54 | else 55 | dialog_field_values = {} 56 | end 57 | 58 | dialog_field = $evm.object 59 | dialog_field["sort_by"] = "value" 60 | dialog_field["sort_order"] = "ascending" 61 | dialog_field["data_type"] = "integer" 62 | dialog_field["required"] = true 63 | dialog_field["values"] = dialog_field_values 64 | end 65 | -------------------------------------------------------------------------------- /Catalogs/v5.8/Hybrid_Cloud_VMs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - Hybrid Cloud VMs: 3 | name: Hybrid Cloud VMs 4 | description: 5 | template: 6 | - name: RHEL 7 | description: Provision RHEL across the hybrid cloud 8 | type: 9 | display: true 10 | service_type: atomic 11 | prov_type: generic 12 | provision_cost: 13 | long_description: '' 14 | options: {} 15 | service_template_catalog_name: Hybrid Cloud VMs 16 | resource_actions: 17 | - action: Provision 18 | ae_namespace: Service/Provisioning/StateMachines 19 | ae_class: ServiceProvision_Template 20 | ae_instance: Generic_CatalogItemInitialization 21 | ae_message: 22 | ae_attributes: 23 | :service_action: Provision 24 | dialog_label: Satellite Provisioning 25 | - action: Retirement 26 | ae_namespace: Service/Retirement/StateMachines 27 | ae_class: ServiceRetirement 28 | ae_instance: Default 29 | ae_message: 30 | ae_attributes: 31 | :service_action: Retirement 32 | dialog_label: Satellite Provisioning 33 | custom_buttons: 34 | - description: Provision new VMs to Service 35 | applies_to_exp: 36 | options: 37 | :button_image: 10 38 | :display: true 39 | :open_url: false 40 | :display_for: single 41 | :submit_how: one 42 | userid: admin 43 | wait_for_complete: 44 | name: Add VMs 45 | visibility: 46 | :roles: 47 | - _ALL_ 48 | custom_button_sets: [] 49 | - name: Apache HTTPD 50 | description: Provision Apache HTTPD across the hybrid cloud 51 | type: 52 | display: true 53 | service_type: atomic 54 | prov_type: generic 55 | provision_cost: 56 | long_description: '' 57 | options: {} 58 | service_template_catalog_name: Hybrid Cloud VMs 59 | resource_actions: 60 | - action: Retirement 61 | ae_namespace: Service/Retirement/StateMachines 62 | ae_class: ServiceRetirement 63 | ae_instance: Default 64 | ae_message: 65 | ae_attributes: 66 | :service_action: Retirement 67 | dialog_label: Satellite Provisioning (Apache HTTPD) 68 | - action: Provision 69 | ae_namespace: Service/Provisioning/StateMachines 70 | ae_class: ServiceProvision_Template 71 | ae_instance: Generic_CatalogItemInitialization 72 | ae_message: 73 | ae_attributes: 74 | :service_action: Provision 75 | dialog_label: Satellite Provisioning (Apache HTTPD) 76 | custom_buttons: 77 | - description: Provision new VMs to Service 78 | applies_to_exp: 79 | options: 80 | :button_image: 10 81 | :display: true 82 | :open_url: false 83 | :display_for: single 84 | :submit_how: one 85 | userid: admin 86 | wait_for_complete: 87 | name: Add VMs 88 | visibility: 89 | :roles: 90 | - _ALL_ 91 | custom_button_sets: [] 92 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/ServiceProvision_Template.class/satellite_catalogiteminitialization.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: 7 | name: Satellite_CatalogItemInitialization 8 | inherits: 9 | description: 10 | fields: 11 | - sequencer: 12 | value: "/Service/Provisioning/StateMachines/Methods/GroupSequenceCheck" 13 | on_entry: update_serviceprovision_status(status => 'Processing Group Sequence 14 | Check') 15 | on_exit: update_serviceprovision_status(status => 'Processed Group Sequence 16 | Check') 17 | on_error: 'update_serviceprovision_status(status => ''Failed Group Sequence 18 | Check: ${/#ae_reason}'')' 19 | - pre1: 20 | value: "/Service/Provisioning/StateMachines/Methods/DialogParser" 21 | on_entry: update_serviceprovision_status(status => 'Processing Dialog') 22 | on_exit: update_serviceprovision_status(status => 'Processed Dialog') 23 | on_error: 'update_serviceprovision_status(status => ''Failed Processing Dialog: 24 | ${/#ae_reason}'')' 25 | - pre2: 26 | value: "/Service/Provisioning/StateMachines/Methods/CatalogItemInitialization" 27 | on_entry: update_serviceprovision_status(status => 'Processing Catalog Item 28 | Initialization') 29 | on_exit: update_serviceprovision_status(status => 'Processed Catalog Item Initialization') 30 | on_error: 'update_serviceprovision_status(status => ''Failed Catalog Item Initialization: 31 | ${/#ae_reason}'')' 32 | - pre3: 33 | value: "/Service/Provisioning/StateMachines/Methods/set_custom_provision_type" 34 | on_entry: update_serviceprovision_status(status => 'Setting Custom Provision 35 | Type') 36 | on_exit: update_serviceprovision_status(status => 'Set Custom Provision Type') 37 | on_error: 'update_serviceprovision_status(status => ''Failed Setting Custom 38 | Provision Type: ${/#ae_reason}'')' 39 | - pre4: 40 | value: "/Service/Provisioning/StateMachines/Methods/set_satellite_options" 41 | on_entry: update_serviceprovision_status(status => 'Setting Satellite Options') 42 | on_exit: update_serviceprovision_status(status => 'Set Satellite Options') 43 | on_error: 'update_serviceprovision_status(status => ''Failed Setting Satellite 44 | Options: ${/#ae_reason}'')' 45 | - pre5: 46 | value: "/Service/Provisioning/Naming/set_vm_names" 47 | on_entry: update_serviceprovision_status(status => 'Setting VM Names') 48 | on_exit: update_serviceprovision_status(status => 'Set VM Names') 49 | on_error: 'update_serviceprovision_status(status => ''Failed Setting VM Names: 50 | ${/#ae_reason}'')' 51 | - post5: 52 | value: "/Service/Provisioning/StateMachines/Methods/ProcessTelemetryData" 53 | on_entry: update_serviceprovision_status(status => 'Processing Telemetry Data') 54 | on_exit: update_serviceprovision_status(status => 'Finished Processing Telemetry 55 | Data') 56 | on_error: update_serviceprovision_status(status => 'Error Processing Telemetry 57 | Data') 58 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Configuration.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: 7 | display_name: 8 | name: Configuration 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: attribute 16 | name: satellite_server 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: 30 | on_exit: 31 | on_error: 32 | max_retries: 33 | max_time: 34 | - field: 35 | aetype: attribute 36 | name: satellite_username 37 | display_name: 38 | datatype: string 39 | priority: 2 40 | owner: 41 | default_value: 42 | substitute: true 43 | message: create 44 | visibility: 45 | collect: 46 | scope: 47 | description: 48 | condition: 49 | on_entry: 50 | on_exit: 51 | on_error: 52 | max_retries: 53 | max_time: 54 | - field: 55 | aetype: attribute 56 | name: satellite_password 57 | display_name: 58 | datatype: password 59 | priority: 3 60 | owner: 61 | default_value: 62 | substitute: true 63 | message: create 64 | visibility: 65 | collect: 66 | scope: 67 | description: 68 | condition: 69 | on_entry: 70 | on_exit: 71 | on_error: 72 | max_retries: 73 | max_time: 74 | - field: 75 | aetype: attribute 76 | name: satellite_owner_group 77 | display_name: 78 | datatype: string 79 | priority: 4 80 | owner: 81 | default_value: Automated Provisioning 82 | substitute: true 83 | message: create 84 | visibility: 85 | collect: 86 | scope: 87 | description: Satellite user group to own provisioned VMs. Assuming Satellite 88 | 6.3 or above and create_users snippit enabled in provisioning tempaltes then 89 | this will decide which SSH keys get deployed to newly provisioned hosts. 90 | condition: 91 | on_entry: 92 | on_exit: 93 | on_error: 94 | max_retries: 95 | max_time: 96 | - field: 97 | aetype: method 98 | name: get_satellite_configuration 99 | display_name: 100 | datatype: string 101 | priority: 5 102 | owner: 103 | default_value: get_satellite_configuration 104 | substitute: true 105 | message: create 106 | visibility: 107 | collect: "/satellite_server = satellite_server; /satellite_username = satellite_username; 108 | /satellite_password = satellite_password" 109 | scope: 110 | description: 111 | condition: 112 | on_entry: 113 | on_exit: 114 | on_error: 115 | max_retries: 116 | max_time: 117 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/check_satellite_build_completed.rb: -------------------------------------------------------------------------------- 1 | # Waits for the build status of the VM being provisioned to be 'Installed' 2 | # 3 | # EXPECTED 4 | # EVM ROOT 5 | # miq_provision - VM Provisining request to create the Satellite host record for. 6 | # required options: 7 | # :satellite_host_id - Satellite Host ID to check the build status for 8 | # 9 | @DEBUG = false 10 | 11 | require 'apipie-bindings' 12 | 13 | # Log an error and exit. 14 | # 15 | # @param msg Message to error with 16 | def error(msg) 17 | $evm.log(:error, msg) 18 | $evm.root['ae_result'] = 'error' 19 | $evm.root['ae_reason'] = msg.to_s 20 | exit MIQ_STOP 21 | end 22 | 23 | # Gets an ApiPie binding to the Satellite API. 24 | # 25 | # @return ApipieBindings to the Satellite API 26 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 27 | def get_satellite_api() 28 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 29 | error("Satellite Configuration not found") if satellite_config.nil? 30 | 31 | satellite_server = satellite_config['satellite_server'] 32 | satellite_username = satellite_config['satellite_username'] 33 | satellite_password = satellite_config.decrypt('satellite_password') 34 | 35 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 36 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 37 | 38 | error("Satellite Server configuration not found") if satellite_server.nil? 39 | error("Satellite User configuration not found") if satellite_username.nil? 40 | error("Satellite Password configuration not found") if satellite_password.nil? 41 | 42 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 43 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 44 | return satellite_api 45 | end 46 | 47 | begin 48 | # Get provisioning object 49 | prov = $evm.root['miq_provision'] 50 | error('Provisioning request not found') if prov.nil? 51 | $evm.log(:info, "Provision:<#{prov.id}> Request:<#{prov.miq_provision_request.id}> Type:<#{prov.type}>") 52 | $evm.log(:info, "prov.attributes => {") if @DEBUG 53 | prov.attributes.sort.each { |k,v| $evm.log(:info, "\t#{k} => #{v}") } if @DEBUG 54 | $evm.log(:info, "}") if @DEBUG 55 | 56 | # get the satellite host id 57 | satellite_host_id = prov.get_option(:satellite_host_id) 58 | error("Could not find 'satellite_host_id' on the miq_provision: #{prov}") if satellite_host_id.nil? 59 | $evm.log(:info, "satellite_host_id => '#{satellite_host_id}'") if @DEBUG 60 | 61 | # get the current build status 62 | satellite_api = get_satellite_api() 63 | satellite_build_status = satellite_api.resource(:hosts).call(:get_status, { :id => satellite_host_id, :type => 'build' }) 64 | status_label = satellite_build_status['status_label'] 65 | 66 | # Until the status is installed keep retrying 67 | $evm.log(:info, "Current VM Satellite Build state: { :status_label => '#{status_label}', :satellite_host_id => '#{satellite_host_id}' }") 68 | unless status_label == 'Installed' 69 | $evm.root['ae_result'] = 'retry' 70 | $evm.root['ae_retry_interval'] = '30.seconds' 71 | else 72 | $evm.root['ae_result'] = 'ok' 73 | end 74 | rescue => err 75 | $evm.log(:error, "Error checking build status: #{err.message}") 76 | $evm.root['ae_result'] = 'retry' 77 | $evm.root['ae_retry_interval'] = '30.seconds' 78 | end 79 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/VMProvision_VM.class/satellite.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: instance 3 | version: 1.0 4 | object: 5 | attributes: 6 | display_name: Provision VM using Satellite 7 | name: satellite 8 | inherits: 9 | description: Provisions a new VM using Satellite PXE with the ability to add disks 10 | pre-kickstart and post-kickstart 11 | fields: 12 | - PreProvision_2: 13 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/set_network" 14 | on_entry: update_provision_status(status => 'Setting Network') 15 | on_exit: update_provision_status(status => 'Setting Network') 16 | on_error: 'update_provision_status(status => ''Error setting network: ${/#ae_reason}'')' 17 | - Provision: 18 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/Provision" 19 | - CheckProvisioned: 20 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/CheckProvisioned" 21 | - AddToService: 22 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/AddVMToService" 23 | - AcquireIPAddress: 24 | value: "/Infrastructure/Network/Operations/Methods/AcquireIPAddress?network_name_parameter_name=destination_network" 25 | - PostVMClone_1: 26 | value: "/Integration/Satellite/Operations/Methods/RegisterSatellite" 27 | on_entry: update_provision_status(status => 'Creating Satellite Host Entry') 28 | on_exit: update_provision_status(status => 'Created Satellite Host Entry') 29 | on_error: 'update_provision_status(status => ''Error creating Satellite Host 30 | Entry: ${/#ae_reason}'')' 31 | - PostVMClone_2: 32 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/AddDisksToVM_PreKickstart" 33 | on_entry: update_provision_status(status => 'Add additional disks pre kickstart') 34 | on_exit: update_provision_status(status => 'Added additional disks pre kickstart') 35 | on_error: 'update_provision_status(status => ''Error adding additional disks 36 | pre kickstart: ${/#ae_reason}'')' 37 | - StartVM: 38 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/StartVM" 39 | - CheckBuildCompleted: 40 | value: "/Integration/Satellite/Operations/Methods/CheckSatelliteBuildCompleted" 41 | on_entry: update_provision_status(status => 'Waiting for VM Satellite Build 42 | to Complete') 43 | on_exit: update_provision_status(status => 'Waiting for VM Satellite Build to 44 | Complete') 45 | on_error: 'update_provision_status(status => ''Error waiting for VM Satellite 46 | Build to Complete: ${/#ae_reason}'')' 47 | - PostBuildCompleted_1: 48 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/WaitForVMIPAddresses" 49 | on_entry: update_provision_status(status => 'Wait for VM IP Addresses') 50 | on_exit: update_provision_status(status => 'Wait for VM IP Addresses') 51 | on_error: 'update_provision_status(status => ''Error waiting for VM IP Addresses: 52 | ${/#ae_reason}'')' 53 | - PostBuildCompleted_2: 54 | value: "/Infrastructure/VM/Provisioning/StateMachines/Methods/AddDisksToVM_PostKickstart" 55 | on_entry: update_provision_status(status => 'Add additional disks post kickstart') 56 | on_exit: update_provision_status(status => 'Added additional disks post kickstart') 57 | on_error: 'update_provision_status(status => ''Error adding additional disks 58 | post kickstart: ${/#ae_reason}'')' 59 | - PostBuildCompleted_5: 60 | value: "/AutomationManagement/AnsibleTower/Operations/OptionalJobTemplate/Default" 61 | on_entry: update_provision_status(status => 'Running Ansible Tower Job') 62 | on_exit: update_provision_status(status => 'Running Ansible Tower Job') 63 | on_error: 'update_provision_status(status => ''Error running Ansible Tower Job: 64 | ${/#ae_reason}'')' 65 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_satellite_options.rb: -------------------------------------------------------------------------------- 1 | # NOTE: DEPRECATED!!!!! 2 | # 3 | # 4 | # This method is intended to set provision options related to Satellite based provisioning on the VM Provision tasks 5 | # associated with the current service_template_provision_task. 6 | # 7 | # This function may not need to do anything if all required Satellite options are set via a custom service dialog. 8 | # 9 | # Required Provision Options to be set by either this method or custom service dialog options: 10 | # satellite_organization_id 11 | # satellite_location_id 12 | # satellite_hostgroup_id 13 | # 14 | # NOTE: Intended to be overriden by implimentors. 15 | # 16 | @DEBUG = false 17 | 18 | require 'apipie-bindings' 19 | 20 | # Log an error and exit. 21 | # 22 | # @param msg Message to error with 23 | def error(msg) 24 | $evm.log(:error, msg) 25 | $evm.root['ae_result'] = 'error' 26 | $evm.root['ae_reason'] = msg.to_s 27 | exit MIQ_STOP 28 | end 29 | 30 | # Gets an ApiPie binding to the Satellite API. 31 | # 32 | # @return ApipieBindings to the Satellite API 33 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 34 | def get_satellite_api() 35 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 36 | error("Satellite Configuration not found") if satellite_config.nil? 37 | 38 | satellite_server = satellite_config['satellite_server'] 39 | satellite_username = satellite_config['satellite_username'] 40 | satellite_password = satellite_config.decrypt('satellite_password') 41 | 42 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 43 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 44 | 45 | error("Satellite Server configuration not found") if satellite_server.nil? 46 | error("Satellite User configuration not found") if satellite_username.nil? 47 | error("Satellite Password configuration not found") if satellite_password.nil? 48 | 49 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 50 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 51 | return satellite_api 52 | end 53 | 54 | begin 55 | $evm.log(:info, "START - set_satellite_options") if @DEBUG 56 | 57 | satellite_api = get_satellite_api() 58 | 59 | task = $evm.root['service_template_provision_task'] 60 | error("$evm.root['service_template_provision_task'] not found") if task.nil? 61 | 62 | # determine :satellite_domain_id 63 | domain_name = task.get_option(:dialog)['dialog_domain_name'] 64 | error("Required :domain_name option is not set on current ServiceTemplateProvisionTask") if domain_name.nil? 65 | $evm.log(:info, "domain_name => '#{domain_name}'") if @DEBUG 66 | satellite_domains = satellite_api.resource(:domains).call(:index)['results'] 67 | satellite_domain = satellite_domains.find { |satellite_domain| satellite_domain['name'] == domain_name } 68 | error("Could not find Satellite Domain with name: '#{domain_name}'") if satellite_domain.nil? 69 | 70 | # Set satellite options 71 | task.miq_request_tasks.each do |service_provision_task| 72 | service_provision_task.miq_request_tasks.each do |vm_provision_task| 73 | # Set :satellite_domain_id option 74 | vm_provision_task.set_option(:satellite_domain_id, satellite_domain['id']) 75 | $evm.log(:info, "{ vm_provision_task_id => '#{task.id}', :satellite_domain_id => '#{vm_provision_task.get_option(:satellite_domain_id)}' }") if @DEBUG 76 | 77 | # !!!!! IMPLIMENTOR TODO: Impliment business logic here !!!!!! 78 | $evm.log(:info, "Default implimentation does not do anything, intended to be overwritten by implimentor in a higher domain. { service_provision_task => #{service_provision_task} }") 79 | #satellite_hostgroup_id = 80 | #vm_provision_task.set_option(:satellite_hostgroup_id, satellite_hostgroup_id) 81 | #$evm.log(:info, "{ vm_provision_task_id => #{vm_provision_task.id}, vm_provision_task.get_option(:satellite_hostgroup_id) => '#{vm_provision_task.get_option(:satellite_hostgroup_id)}' }") 82 | end 83 | end 84 | 85 | $evm.log(:info, "END - set_satellite_options") if @DEBUG 86 | end 87 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_hostgroups.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Hostgroups from Satellite. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | # Log an error and exit. 8 | # 9 | # @param msg Message to error with 10 | def error(msg) 11 | $evm.log(:error, msg) 12 | $evm.root['ae_result'] = 'error' 13 | $evm.root['ae_reason'] = msg.to_s 14 | exit MIQ_STOP 15 | end 16 | 17 | # Gets an ApiPie binding to the Satellite API. 18 | # 19 | # @return ApipieBindings to the Satellite API 20 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 21 | def get_satellite_api() 22 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 23 | error("Satellite Configuration not found") if satellite_config.nil? 24 | 25 | satellite_server = satellite_config['satellite_server'] 26 | satellite_username = satellite_config['satellite_username'] 27 | satellite_password = satellite_config.decrypt('satellite_password') 28 | 29 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 30 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 31 | 32 | error("Satellite Server configuration not found") if satellite_server.nil? 33 | error("Satellite User configuration not found") if satellite_username.nil? 34 | error("Satellite Password configuration not found") if satellite_password.nil? 35 | 36 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 37 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 38 | return satellite_api 39 | end 40 | 41 | ENVIRONMENT_NAME_DIALOG_OPTION = 'dialog_satellite_environment_name' 42 | ENVIRONMENT_ID_DIALOG_OPTION = 'dialog_satellite_environment_id' 43 | def get_environment_name() 44 | # determine environment 45 | satellite_environment_name = $evm.root[ENVIRONMENT_NAME_DIALOG_OPTION] 46 | satellite_environment_id = $evm.root[ENVIRONMENT_ID_DIALOG_OPTION] 47 | # return nil if the dialog elements have not been selected yet 48 | return nil if satellite_environment_name.blank? and satellite_environment_id.blank? 49 | return nil if satellite_environment_name == '!' or satellite_environment_id == '!' 50 | 51 | # if the satellite enviornment name is actually an ID 52 | # else if satellite envirnonment name not given check for satellite environment id 53 | if satellite_environment_name =~ /^[0-9]+$/ 54 | satellite_environment_id = satellite_environment_name.to_i 55 | end 56 | 57 | if !satellite_environment_id.blank? 58 | $evm.log(:info, "satellite_environment_id => #{satellite_environment_id}") if @DEBUG 59 | satellite_api = get_satellite_api() 60 | begin 61 | satellite_environment = satellite_api.resource(:lifecycle_environments).call(:show, {:id => satellite_environment_id}) 62 | satellite_environment_name = satellite_environment['name'] 63 | rescue => e 64 | error("Error invoking Satellite API: #{e.to_s}") 65 | end 66 | end 67 | $evm.log(:error, "One of must be specified.") if satellite_environment_name.blank? 68 | return satellite_environment_name 69 | end 70 | 71 | begin 72 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 73 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 74 | 75 | satellite_api = get_satellite_api() 76 | 77 | satellite_environment_name = get_environment_name() 78 | $evm.log(:info, "satellite_environment_name => #{satellite_environment_name}") if @DEBUG 79 | 80 | 81 | hostgroups_search_string = "" 82 | if !satellite_environment_name.blank? 83 | hostgroups_search_string = "lifecycle_environment = #{satellite_environment_name}" 84 | end 85 | $evm.log(:info, "hostgroups_search_string => #{hostgroups_search_string}") if @DEBUG 86 | 87 | hostgroups_index = satellite_api.resource(:hostgroups).call(:index, {:search => hostgroups_search_string}) 88 | $evm.log(:info, "hostgroups_index = #{hostgroups_index}") if @DEBUG 89 | 90 | dialog_field = $evm.object 91 | dialog_field["sort_by"] = "description" 92 | dialog_field["sort_order"] = "ascending" 93 | dialog_field["data_type"] = "integer" 94 | dialog_field["required"] = true 95 | dialog_field["values"] = Hash[ *hostgroups_index['results'].collect { |item| [item['id'], item['title']] }.flatten ] 96 | end 97 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__methods__/process_telemetry_data.rb: -------------------------------------------------------------------------------- 1 | # Uses time data captured during the VM provisioning process to set custom attributes 2 | # on the VM about the times taken to perform steps of the provisioning process. 3 | # 4 | # Parameters: 5 | # ROOT 6 | # * miq_provision 7 | # 8 | @DEBUG = false 9 | 10 | PROVISIONING_TELEMETRY_PREFIX = "Provisioning_Telemetry" 11 | 12 | # Converts duration of seconds to HH:MM:SS 13 | # 14 | # @param seconds Number of seconds passed 15 | # 16 | # @return duration converted to HH:MM:SS 17 | def seconds_to_time(seconds) 18 | seconds = seconds.round 19 | return [seconds / 3600, seconds / 60 % 60, seconds % 60].map { |t| t.to_s.rjust(2,'0') }.join(':') 20 | end 21 | 22 | # Get the duration between two times. 23 | # 24 | # @return Duration in HH:MM:SS between to times, or Unknown, if any time is nil 25 | def get_duration(start_time, end_time) 26 | $evm.log(:info, "get_duration: START: { :start_time => #{start_time}, :end_time => #{:end_time} }") if @DEBUG 27 | duration = 'Unknown' 28 | 29 | start_time = $evm.get_state_var(start_time) if start_time.class == Symbol 30 | end_time = $evm.get_state_var(end_time) if end_time.class == Symbol 31 | 32 | if start_time && end_time 33 | duration = seconds_to_time(end_time.in_time_zone("UTC") - start_time.in_time_zone("UTC")) 34 | 35 | else 36 | duration = 'Unknown' 37 | end 38 | 39 | $evm.log(:info, "get_duration: END: { :duration => #{duration}, :start_time => #{start_time}, :end_time => #{:end_time} }") if @DEBUG 40 | return duration 41 | end 42 | 43 | # Set VM custom attribute with provisioning telemetry data 44 | def set_provisioning_telemetry_custom_attribute(vm, description, value) 45 | vm.custom_set("#{PROVISIONING_TELEMETRY_PREFIX}_#{description}".gsub('[ :].*', '_'), value) 46 | end 47 | 48 | begin 49 | # Get vm from miq_provision object 50 | prov = $evm.root['miq_provision'] 51 | vm = prov.vm 52 | error("VM not found") if vm.nil? 53 | 54 | # determine how long different steps took 55 | now = Time.now 56 | duration_task_queue = get_duration(prov.created_on, :vm_provisioning_telemetry_on_entry_CustomizeRequest) 57 | duration_vm_provisioning = get_duration(:vm_provisioning_telemetry_on_entry_CustomizeRequest, now) 58 | duration_vm_clone = get_duration(:vm_provisioning_telemetry_on_entry_Provision, :vm_provisioning_telemetry_on_exit_CheckProvisioned) 59 | duration_wait_for_vm_mac_addresses = get_duration(:vm_provisioning_telemetry_on_entry_WaitForVMMACAddresses, :vm_provisioning_telemetry_on_exit_WaitForVMMACAddresses) 60 | duration_start_vm = get_duration(:vm_provisioning_telemetry_on_entry_StartVM, :vm_provisioning_telemetry_on_exit_StartVM) 61 | duration_wait_for_vm_ip_addresses = get_duration(:vm_provisioning_telemetry_on_entry_PostSatelliteBuildCompleted_1, :vm_provisioning_telemetry_on_exit_PostSatelliteBuildCompleted_1) 62 | 63 | # NOTE: Satellite 6 specific 64 | duration_wait_for_satellite_build_completed = get_duration(:vm_provisioning_telemetry_on_exit_StartVM, :vm_provisioning_telemetry_on_exit_CheckSatelliteBuildCompleted) 65 | 66 | set_provisioning_telemetry_custom_attribute(vm, 'Time_Request_Created', prov.created_on.localtime) 67 | set_provisioning_telemetry_custom_attribute(vm, 'Time_Request_Completed', now) 68 | set_provisioning_telemetry_custom_attribute(vm, 'Hour_Request_Created', prov.created_on.localtime.hour) 69 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_Task_Queue', duration_task_queue) 70 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_Total_VM_Provisioning', duration_vm_provisioning) 71 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_VM_Clone', duration_vm_clone) 72 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_Wait_for_VM_MAC_Addresses', duration_wait_for_vm_mac_addresses) 73 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_Start_VM', duration_start_vm) 74 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_Wait_for_VM_IP_Addresses', duration_wait_for_vm_ip_addresses) 75 | 76 | # NOTE: Satellite 6 specific 77 | set_provisioning_telemetry_custom_attribute(vm, 'Duration_Wait_for_Satellite_Build_To_Complete', duration_wait_for_satellite_build_completed) 78 | end 79 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/StdLib.class/__methods__/satellitecore.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Description: Collection of Core Methods to use when interacting with Red Hat Satellite 6 3 | # 4 | 5 | module RedHatConsulting_Satellite6 6 | module StdLib 7 | module SatelliteCore 8 | 9 | require 'apipie-bindings' 10 | include RedHatConsulting_Utilities::StdLib::Core 11 | 12 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 13 | 14 | def initialize( handle = $evm) 15 | @handle = handle 16 | @DEBUG = false 17 | end 18 | 19 | # Gets an ApiPie binding to the Satellite API. 20 | # 21 | # @return ApipieBindings to the Satellite API 22 | def get_satellite_api() 23 | satellite_config = @handle.instantiate(SATELLITE_CONFIG_URI) 24 | error("Satellite Configuration not found") if satellite_config.nil? 25 | 26 | satellite_server = satellite_config['satellite_server'] 27 | satellite_username = satellite_config['satellite_username'] 28 | satellite_password = satellite_config.decrypt('satellite_password') 29 | 30 | log(:info, "satellite_server = #{satellite_server}") if @DEBUG 31 | log(:info, "satellite_username = #{satellite_username}") if @DEBUG 32 | 33 | error("Satellite Server configuration not found") if satellite_server.nil? 34 | error("Satellite User configuration not found") if satellite_username.nil? 35 | error("Satellite Password configuration not found") if satellite_password.nil? 36 | 37 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 38 | log(:info, "satellite_api = #{satellite_api}") if @DEBUG 39 | return satellite_api 40 | 41 | end 42 | 43 | # Get the Satellite host record for a given host name 44 | # 45 | # @param satellite_api ApipieBinding Sattellite API object 46 | # @param name String Name of the host to find the Satelilte host record for 47 | # 48 | # @return Hash Satellite host record for the given host name returned from Satellite API 49 | def get_satellite_host_record(satellite_api, name) 50 | satellite_host_record = nil 51 | begin 52 | satellite_index_result = satellite_api.resource(:hosts).call(:index, {:search => "name=#{name}"}) 53 | if !satellite_index_result['results'].empty? 54 | satellite_host_record = satellite_index_result['results'].first 55 | 56 | # get the full record 57 | satellite_host_record = satellite_api.resource(:hosts).call(:show, {:id => satellite_host_record['id']}) 58 | 59 | # NOTE: hopefully this never happens 60 | # warn if found more then one result 61 | if satellite_index_result['results'].length > 1 62 | log(:warn, "More then one Satellite host record found for Host <#{name}>, using first one.") 63 | end 64 | end 65 | rescue RestClient::UnprocessableEntity => e 66 | error("Error finding Satellite host record for Host <#{name}>. Received an UnprocessableEntity error from Satellite. Check /var/log/foreman/production.log on Satellite for more info.") 67 | rescue Exception => e 68 | error("Error finding Satellite host record for Host <#{name}>: #{e.message}") 69 | end 70 | 71 | return satellite_host_record 72 | end 73 | 74 | # Get the Satellite Lifecycle environment name 75 | # 76 | # @param env_input Satellite Environment ID 77 | # 78 | # @return Satellite environment name 79 | def get_satellite_environment_name_from_id( satellite_environment_id ) 80 | log(:info, "satellite_environment_id => #{satellite_environment_id}") if @DEBUG 81 | # if the environement ID is really a name return 82 | return satellite_environment_id unless satellite_environment_id =~ /^[0-9]+$/ 83 | satellite_api = get_satellite_api() 84 | begin 85 | satellite_environment = satellite_api.resource(:lifecycle_environments).call(:show, {:id => satellite_environment_id}) 86 | satellite_environment_name = satellite_environment['name'] 87 | rescue => e 88 | error("Error determining Satellite Environment Name from ID: #{e.to_s}") 89 | end 90 | return satellite_environment_name 91 | end 92 | 93 | end 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/unregister_satellite.rb: -------------------------------------------------------------------------------- 1 | # Removes the Satellite Host Requred associated with the given VMs FQDN. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | # Log an error and exit. 8 | # 9 | # @param msg Message to error with 10 | def error(msg) 11 | $evm.log(:error, msg) 12 | $evm.root['ae_result'] = 'error' 13 | $evm.root['ae_reason'] = msg.to_s 14 | exit MIQ_STOP 15 | end 16 | 17 | # Notify and log a warning message. 18 | # 19 | # @param msg Message to warn with 20 | def warn(msg) 21 | $evm.create_notification(:level => 'warning', :message => msg) 22 | $evm.log(:warn, msg) 23 | end 24 | 25 | # Gets an ApiPie binding to the Satellite API. 26 | # 27 | # @return ApipieBindings to the Satellite API 28 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 29 | def get_satellite_api() 30 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 31 | error("Satellite Configuration not found") if satellite_config.nil? 32 | 33 | satellite_server = satellite_config['satellite_server'] 34 | satellite_username = satellite_config['satellite_username'] 35 | satellite_password = satellite_config.decrypt('satellite_password') 36 | 37 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 38 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 39 | 40 | error("Satellite Server configuration not found") if satellite_server.nil? 41 | error("Satellite User configuration not found") if satellite_username.nil? 42 | error("Satellite Password configuration not found") if satellite_password.nil? 43 | 44 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 45 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 46 | return satellite_api 47 | end 48 | 49 | # Get the Satellite host record for a given host name 50 | # 51 | # @param satellite_api ApipieBinding Sattellite API object 52 | # @param name String Name of the host to find the Satelilte host record for 53 | # 54 | # @return Hash Satellite host record for the given host name returned from Satellite API 55 | def get_satellite_host_record(satellite_api, name) 56 | satellite_host_record = nil 57 | begin 58 | satellite_index_result = satellite_api.resource(:hosts).call(:index, {:search => "name=#{name}"}) 59 | if !satellite_index_result['results'].empty? 60 | satellite_host_record = satellite_index_result['results'][0] 61 | 62 | # NOTE: hopefully this never happens 63 | # warn if found more then one result 64 | if satellite_index_result['results'].length > 1 65 | $evm.log(:warn, "More then one Satellite host record found for Host <#{name}>, using first one.") 66 | end 67 | end 68 | rescue RestClient::UnprocessableEntity => e 69 | error("Error finding Satellite host record for Host <#{name}>. Received an UnprocessableEntity error from Satellite. Check /var/log/foreman/production.log on Satellite for more info.") 70 | rescue Exception => e 71 | error("Error finding Satellite host record for Host <#{name}>: #{e.message}") 72 | end 73 | 74 | return satellite_host_record 75 | end 76 | 77 | begin 78 | vm = $evm.root['vm'] 79 | error('VM not found') if vm.nil? 80 | $evm.log(:info, "vm => #{vm}") if @DEBUG 81 | 82 | # get the satellite host record id 83 | satellite_api = get_satellite_api() 84 | satellite_host_record = get_satellite_host_record(satellite_api, vm.name) 85 | 86 | # if a satellite host record is found, then retire it 87 | # else just ignore 88 | if !satellite_host_record.blank? 89 | satellite_host_id = satellite_host_record['id'] 90 | $evm.log(:info, "satellite_host_id => '#{satellite_host_id}'") if @DEBUG 91 | 92 | begin 93 | $evm.log(:info, "Unregister Satellite Host Record <#{satellite_host_id}> for Host <#{vm.name}>") 94 | result = satellite_api.resource(:hosts).call(:destroy, { :id => satellite_host_id}) 95 | $evm.log(:info, "Unregistered Satellite Host Record <#{satellite_host_id}> for Host <#{vm.name}>") 96 | rescue RestClient::NotFound 97 | warn("No Satellite Host Record <#{satellite_host_id}> to unregister for Host <#{vm.name}>") 98 | rescue => e 99 | warn("Unexpected error when unregistering Satellite Host Record <#{satellite_host_id}> to unregister for Host <#{vm.name}>: #{e.message}") 100 | end 101 | else 102 | $evm.log(:info, "No Satellite Host Record to unregister found for Host <#{vm.name}>. Skipping and ignoring.") 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Provisioning/StateMachines/Methods.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: 7 | display_name: 8 | name: Methods 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: relationship 16 | name: common_rel1 17 | display_name: '' 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: "*" 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: 30 | on_exit: 31 | on_error: 32 | max_retries: 33 | max_time: 34 | - field: 35 | aetype: method 36 | name: common_meth1 37 | display_name: '' 38 | datatype: string 39 | priority: 2 40 | owner: 41 | default_value: 42 | substitute: true 43 | message: "*" 44 | visibility: 45 | collect: 46 | scope: 47 | description: 48 | condition: 49 | on_entry: 50 | on_exit: 51 | on_error: 52 | max_retries: 53 | max_time: 54 | - field: 55 | aetype: relationship 56 | name: rel1 57 | display_name: '' 58 | datatype: string 59 | priority: 3 60 | owner: 61 | default_value: 62 | substitute: true 63 | message: create 64 | visibility: 65 | collect: 66 | scope: 67 | description: 68 | condition: 69 | on_entry: 70 | on_exit: 71 | on_error: 72 | max_retries: 73 | max_time: 74 | - field: 75 | aetype: method 76 | name: execute 77 | display_name: '' 78 | datatype: string 79 | priority: 4 80 | owner: 81 | default_value: 82 | substitute: true 83 | message: create 84 | visibility: 85 | collect: 86 | scope: 87 | description: 88 | condition: 89 | on_entry: 90 | on_exit: 91 | on_error: 92 | max_retries: 93 | max_time: 94 | - field: 95 | aetype: relationship 96 | name: vmware_rel1 97 | display_name: '' 98 | datatype: string 99 | priority: 5 100 | owner: 101 | default_value: 102 | substitute: true 103 | message: vmware 104 | visibility: 105 | collect: 106 | scope: 107 | description: 108 | condition: 109 | on_entry: 110 | on_exit: 111 | on_error: 112 | max_retries: 113 | max_time: 114 | - field: 115 | aetype: method 116 | name: vmware_meth1 117 | display_name: '' 118 | datatype: string 119 | priority: 6 120 | owner: 121 | default_value: 122 | substitute: true 123 | message: vmware 124 | visibility: 125 | collect: 126 | scope: 127 | description: 128 | condition: 129 | on_entry: 130 | on_exit: 131 | on_error: 132 | max_retries: 133 | max_time: 134 | - field: 135 | aetype: relationship 136 | name: redhat_rel1 137 | display_name: '' 138 | datatype: string 139 | priority: 7 140 | owner: 141 | default_value: 142 | substitute: true 143 | message: redhat 144 | visibility: 145 | collect: 146 | scope: 147 | description: 148 | condition: 149 | on_entry: 150 | on_exit: 151 | on_error: 152 | max_retries: 153 | max_time: 154 | - field: 155 | aetype: method 156 | name: redhat_meth1 157 | display_name: '' 158 | datatype: string 159 | priority: 8 160 | owner: 161 | default_value: 162 | substitute: true 163 | message: redhat 164 | visibility: 165 | collect: 166 | scope: 167 | description: 168 | condition: 169 | on_entry: 170 | on_exit: 171 | on_error: 172 | max_retries: 173 | max_time: 174 | - field: 175 | aetype: relationship 176 | name: microsoft_rel1 177 | display_name: 178 | datatype: string 179 | priority: 9 180 | owner: 181 | default_value: 182 | substitute: true 183 | message: microsoft 184 | visibility: 185 | collect: 186 | scope: 187 | description: 188 | condition: 189 | on_entry: 190 | on_exit: 191 | on_error: 192 | max_retries: 193 | max_time: 194 | - field: 195 | aetype: method 196 | name: microsoft_meth1 197 | display_name: 198 | datatype: string 199 | priority: 10 200 | owner: 201 | default_value: 202 | substitute: true 203 | message: microsoft 204 | visibility: 205 | collect: 206 | scope: 207 | description: 208 | condition: 209 | on_entry: 210 | on_exit: 211 | on_error: 212 | max_retries: 213 | max_time: 214 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_locations_filtered_by_tags.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Locations from a Satellite Organization 2 | # filtered by tags on the providers available. 3 | # 4 | @DEBUG = false 5 | 6 | require 'apipie-bindings' 7 | 8 | TAG_CATEGORY = 'location' 9 | 10 | # Log an error and exit. 11 | # 12 | # @param msg Message to error with 13 | def error(msg) 14 | $evm.log(:error, msg) 15 | $evm.root['ae_result'] = 'error' 16 | $evm.root['ae_reason'] = msg.to_s 17 | exit MIQ_STOP 18 | end 19 | 20 | # Gets all of the Tags in a given Tag Category 21 | # 22 | # @param category Tag Category to get all of the Tags for 23 | # 24 | # @return Hash of Tag names mapped to Tag descriptions 25 | # 26 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html#_getting_the_list_of_tags_in_a_category 27 | def get_category_tags(category) 28 | classification = $evm.vmdb(:classification).find_by_name(category) 29 | tags = {} 30 | $evm.vmdb(:classification).where(:parent_id => classification.id).each do |tag| 31 | tags[tag.name] = tag.description 32 | end 33 | 34 | return tags 35 | end 36 | 37 | # Create a Tag in a given Category if it does not already exist 38 | # 39 | # @param category Tag Category to create the Tag in 40 | # @param tag Tag to create in the given Tag Category 41 | # 42 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html 43 | def create_tag(category, tag) 44 | create_tag_category(category) 45 | tag_name = to_tag_name(tag) 46 | unless $evm.execute('tag_exists?', category, tag_name) 47 | $evm.execute('tag_create', 48 | category, 49 | :name => tag_name, 50 | :description => tag) 51 | end 52 | end 53 | 54 | # Create a Tag Category if it does not already exist 55 | # 56 | # @param category Tag Category to create 57 | # @param description Tag Category description. 58 | # Optional 59 | # Defaults to the `category` 60 | # @param single_value True if a resource can only have one tag from this category, 61 | # False if a resource can have multiple tags from this category. 62 | # Optional. 63 | # Defaults to `false` 64 | # 65 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html 66 | def create_tag_category(category, description = nil, single_value = false) 67 | category_name = to_tag_name(category) 68 | unless $evm.execute('category_exists?', category_name) 69 | $evm.execute('category_create', 70 | :name => category_name, 71 | :single_value => single_value, 72 | :perf_by_tag => false, 73 | :description => description || category) 74 | end 75 | end 76 | 77 | # Takes a string and makes it a valid tag name 78 | # 79 | # @param str String to turn into a valid Tag name 80 | # 81 | # @return Given string transformed into a valid Tag name 82 | def to_tag_name(str) 83 | return str.downcase.gsub(/[^a-z0-9_]+/,'_') 84 | end 85 | 86 | # Gets an ApiPie binding to the Satellite API. 87 | # 88 | # @return ApipieBindings to the Satellite API 89 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 90 | def get_satellite_api() 91 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 92 | error("Satellite Configuration not found") if satellite_config.nil? 93 | 94 | satellite_server = satellite_config['satellite_server'] 95 | satellite_username = satellite_config['satellite_username'] 96 | satellite_password = satellite_config.decrypt('satellite_password') 97 | 98 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 99 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 100 | 101 | error("Satellite Server configuration not found") if satellite_server.nil? 102 | error("Satellite User configuration not found") if satellite_username.nil? 103 | error("Satellite Password configuration not found") if satellite_password.nil? 104 | 105 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 106 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 107 | return satellite_api 108 | end 109 | 110 | begin 111 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 112 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 113 | 114 | satellite_api = get_satellite_api() 115 | 116 | location_index = satellite_api.resource(:locations).call(:index) 117 | $evm.log(:info, "location_index => #{location_index}") if @DEBUG 118 | dialog_field_values = Hash[ *location_index['results'].collect { |item| [item['id'], item['title']] }.flatten ] 119 | 120 | $evm.log(:info, "dialog_field_values pre filtering: #{dialog_field_values}") if @DEBUG 121 | dialog_field_values.each do |id, name| 122 | create_tag(TAG_CATEGORY, name) 123 | end 124 | 125 | providers = $evm.vmdb(:ems).all 126 | dialog_field_values.delete_if do |id, name| 127 | provider_tagged = false 128 | tag_name = to_tag_name(name) 129 | 130 | providers.each do |provider| 131 | provider_tagged = provider.tagged_with?(TAG_CATEGORY, tag_name) 132 | $evm.log(:info, "Provider '#{provider.name}' tagged with: #{TAG_CATEGORY} => #{tag_name}") if @DEBUG && provider_tagged 133 | break if provider_tagged 134 | end 135 | $evm.log(:info, "No provider tagged with: #{TAG_CATEGORY} => #{tag_name}") if @DEBUG && !provider_tagged 136 | 137 | !provider_tagged 138 | end 139 | 140 | $evm.log(:info, "dialog_field_values post filtering: #{dialog_field_values}") if @DEBUG 141 | 142 | dialog_field = $evm.object 143 | dialog_field["sort_by"] = "value" 144 | dialog_field["sort_order"] = "ascending" 145 | dialog_field["data_type"] = "integer" 146 | dialog_field["required"] = true 147 | dialog_field["values"] = dialog_field_values 148 | end 149 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/Methods.class/__methods__/set_custom_provision_task_options.rb: -------------------------------------------------------------------------------- 1 | # IMPLIMENTORS: intended to be overwritten. 2 | # 3 | # Sets additional dialog options on the given serivce. 4 | # 5 | @DEBUG = false 6 | 7 | require 'apipie-bindings' 8 | 9 | # IMPLIMENTORS: intended to be overwritten 10 | # 11 | # @param dialog_options Hash Dialog options set by user when creating the service. 12 | # 13 | # @return Hash of custom vm_fields to set on any vm provisioning requests created for the service being created 14 | def get_custom_vm_fields(dialog_options) 15 | custom_vm_fields = { 16 | :vm_auto_start => false, 17 | :vm_name => 'changeme' 18 | } 19 | 20 | return custom_vm_fields 21 | end 22 | 23 | # IMPLIMENTORS: intended to be overwritten 24 | # 25 | # @param dialog_options Hash Dialog options set by user when creating the service. 26 | # 27 | # @return Hash of custom custom additional_values (ws_values) to set on any vm provisioning requests created for the service being created 28 | def get_custom_additional_values(dialog_options) 29 | # set base custom additional values 30 | custom_additional_values = { 31 | :custom_request_type => 'satellite' 32 | } 33 | 34 | # ensure satellite_domain_id is set 35 | dialog_satellite_domain_id = dialog_options[:satellite_domain_id] 36 | if !dialog_satellite_domain_id.blank? 37 | custom_additional_values[:satellite_domain_id] = dialog_satellite_domain_id 38 | end 39 | 40 | # ensure satellite_location_id is set 41 | # NOTE: 42 | # if not provided then will rely on register_satellite to determine it based 43 | # on a location tag on the provider that owns the template being provisioned 44 | dialog_satellite_location_id = dialog_options[:satellite_location_id] 45 | if !dialog_satellite_location_id.blank? 46 | custom_additional_values[:satellite_location_id] = dialog_satellite_location_id 47 | end 48 | 49 | # ensure satellite_hostgroup_id is set 50 | dialog_satellite_hostgroup_id = dialog_options[:satellite_hostgroup_id] 51 | if !dialog_satellite_hostgroup_id.nil? 52 | custom_additional_values[:satellite_hostgroup_id] = dialog_satellite_hostgroup_id 53 | else 54 | satellite_api ||= get_satellite_api() 55 | error("satellite_hostgroup_id dialog option must be set.") 56 | end 57 | 58 | return custom_additional_values 59 | end 60 | 61 | # Gets an ApiPie binding to the Satellite API. 62 | # 63 | # @return ApipieBindings to the Satellite API 64 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 65 | def get_satellite_api() 66 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 67 | error("Satellite Configuration not found") if satellite_config.nil? 68 | 69 | satellite_server = satellite_config['satellite_server'] 70 | satellite_username = satellite_config['satellite_username'] 71 | satellite_password = satellite_config.decrypt('satellite_password') 72 | 73 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 74 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 75 | 76 | error("Satellite Server configuration not found") if satellite_server.nil? 77 | error("Satellite User configuration not found") if satellite_username.nil? 78 | error("Satellite Password configuration not found") if satellite_password.nil? 79 | 80 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 81 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 82 | return satellite_api 83 | end 84 | 85 | # IMPLIMENTORS: do not modify 86 | def dump_object(object_string, object) 87 | $evm.log("info", "Listing #{object_string} Attributes:") 88 | object.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 89 | $evm.log("info", "===========================================") 90 | end 91 | 92 | # IMPLIMENTORS: do not modify 93 | def dump_current 94 | $evm.log("info", "Listing Current Object Attributes:") 95 | $evm.current.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 96 | $evm.log("info", "===========================================") 97 | end 98 | 99 | # IMPLIMENTORS: do not modify 100 | def dump_root 101 | $evm.log("info", "Listing Root Object Attributes:") 102 | $evm.root.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 103 | $evm.log("info", "===========================================") 104 | end 105 | 106 | # IMPLIMENTORS: do not modify 107 | def error(msg) 108 | $evm.root['ae_result'] = 'error' 109 | $evm.root['ae_reason'] = msg 110 | $evm.log(:error, msg) 111 | exit MIQ_OK 112 | end 113 | 114 | # IMPLIMENTORS: do not modify 115 | def yaml_data(task, option) 116 | task.get_option(option).nil? ? nil : YAML.load(task.get_option(option)) 117 | end 118 | 119 | # IMPLIMENTORS: do not modify 120 | begin 121 | dump_current() if @DEBUG 122 | dump_root() if @DEBUG 123 | 124 | # get options and tags 125 | $evm.log(:info, "$evm.root['vmdb_object_type'] => '#{$evm.root['vmdb_object_type']}'.") if @DEBUG 126 | case $evm.root['vmdb_object_type'] 127 | when 'service_template_provision_task' 128 | task = $evm.root['service_template_provision_task'] 129 | dump_object("service_template_provision_task", task) if @DEBUG 130 | 131 | dialog_options = yaml_data(task, :parsed_dialog_options) 132 | dialog_options = dialog_options[0] if !dialog_options[0].nil? 133 | else 134 | error("Can not handle vmdb_object_type: #{$evm.root['vmdb_object_type']}") 135 | end 136 | $evm.log(:info, "dialog_options => #{dialog_options}") if @DEBUG 137 | 138 | # get the custom options 139 | custom_vm_fields = get_custom_vm_fields(dialog_options) 140 | custom_additional_values = get_custom_additional_values(dialog_options) 141 | 142 | # set the custom options on the task 143 | task.set_option(:custom_vm_fields, custom_vm_fields) 144 | task.set_option(:custom_additional_values, custom_additional_values) 145 | $evm.log(:info, "Set :custom_vm_fields => #{custom_vm_fields}") if @DEBUG 146 | $evm.log(:info, "Set :custom_additional_values => #{custom_additional_values}") if @DEBUG 147 | 148 | # TODO: move me somewhere else 149 | task.set_option(:target_name, dialog_options[:service_name]) 150 | task.set_option(:description, dialog_options[:service_name]) 151 | end 152 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_locations_by_tag_path.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Locations from a Satellite Organization 2 | # filtered by tags on the providers available. 3 | # 4 | @DEBUG = false 5 | 6 | require 'apipie-bindings' 7 | 8 | TAG_CATEGORY = 'location' 9 | 10 | # Log an error and exit. 11 | # 12 | # @param msg Message to error with 13 | def error(msg) 14 | $evm.log(:error, msg) 15 | $evm.root['ae_result'] = 'error' 16 | $evm.root['ae_reason'] = msg.to_s 17 | exit MIQ_STOP 18 | end 19 | 20 | # Gets all of the Tags in a given Tag Category 21 | # 22 | # @param category Tag Category to get all of the Tags for 23 | # 24 | # @return Hash of Tag names mapped to Tag descriptions 25 | # 26 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html#_getting_the_list_of_tags_in_a_category 27 | def get_category_tags(category) 28 | classification = $evm.vmdb(:classification).find_by_name(category) 29 | tags = {} 30 | $evm.vmdb(:classification).where(:parent_id => classification.id).each do |tag| 31 | tags[tag.name] = tag.description 32 | end 33 | 34 | return tags 35 | end 36 | 37 | 38 | # Create a Tag in a given Category if it does not already exist 39 | # 40 | # @param category Tag Category to create the Tag in 41 | # @param tag Tag to create in the given Tag Category 42 | # 43 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html 44 | def create_tag(category, tag) 45 | create_tag_category(category) 46 | tag_name = to_tag_name(tag) 47 | unless $evm.execute('tag_exists?', category, tag_name) 48 | $evm.execute('tag_create', 49 | category, 50 | :name => tag_name, 51 | :description => tag) 52 | end 53 | 54 | return "#{category}/#{tag_name}" 55 | end 56 | 57 | # Create a Tag Category if it does not already exist 58 | # 59 | # @param category Tag Category to create 60 | # @param description Tag Category description. 61 | # Optional 62 | # Defaults to the `category` 63 | # @param single_value True if a resource can only have one tag from this category, 64 | # False if a resource can have multiple tags from this category. 65 | # Optional. 66 | # Defaults to `false` 67 | # 68 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html 69 | def create_tag_category(category, description = nil, single_value = false) 70 | category_name = to_tag_name(category) 71 | unless $evm.execute('category_exists?', category_name) 72 | $evm.execute('category_create', 73 | :name => category_name, 74 | :single_value => single_value, 75 | :perf_by_tag => false, 76 | :description => description || category) 77 | end 78 | end 79 | 80 | # Takes a string and makes it a valid tag name 81 | # 82 | # @param str String to turn into a valid Tag name 83 | # 84 | # @return Given string transformed into a valid Tag name 85 | def to_tag_name(str) 86 | return str.downcase.gsub(/[^a-z0-9_]+/,'_') 87 | end 88 | 89 | # Gets an ApiPie binding to the Satellite API. 90 | # 91 | # @return ApipieBindings to the Satellite API 92 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 93 | def get_satellite_api() 94 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 95 | error("Satellite Configuration not found") if satellite_config.nil? 96 | 97 | satellite_server = satellite_config['satellite_server'] 98 | satellite_username = satellite_config['satellite_username'] 99 | satellite_password = satellite_config.decrypt('satellite_password') 100 | 101 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 102 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 103 | 104 | error("Satellite Server configuration not found") if satellite_server.nil? 105 | error("Satellite User configuration not found") if satellite_username.nil? 106 | error("Satellite Password configuration not found") if satellite_password.nil? 107 | 108 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 109 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 110 | return satellite_api 111 | end 112 | 113 | # @param visible_and_required Boolean true if the dialog element is visible and required, false if hidden 114 | # @param values Hash Values for the dialog element 115 | # @param default_value String 116 | def return_dialog_element(visible_and_required, values, default_value = "") 117 | # create dialog element 118 | dialog_field = $evm.object 119 | dialog_field['data_type'] = "string" 120 | dialog_field['visible'] = visible_and_required 121 | dialog_field['required'] = visible_and_required 122 | dialog_field['values'] = values 123 | dialog_field['default_value'] = default_value 124 | dialog_field['required'] = true 125 | $evm.log(:info, "dialog_field['values'] => #{dialog_field['values']}") if @DEBUG 126 | 127 | exit MIQ_OK 128 | end 129 | 130 | begin 131 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 132 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 133 | 134 | satellite_api = get_satellite_api() 135 | 136 | location_index = satellite_api.resource(:locations).call(:index) 137 | $evm.log(:info, "location_index => #{location_index}") if @DEBUG 138 | locations = Hash[ *location_index['results'].collect { |item| [item['id'], item['title']] }.flatten ] 139 | 140 | $evm.log(:info, "locations pre filtering: #{locations}") if @DEBUG 141 | dialog_field_values = {} 142 | locations.each do |location_id, location_name| 143 | tag_path = create_tag(TAG_CATEGORY, location_name) 144 | dialog_field_values[tag_path] = location_name 145 | end 146 | 147 | # remove location tags that are not tagged on a provider 148 | providers = $evm.vmdb(:ems).all 149 | dialog_field_values.delete_if do |id, name| 150 | provider_tagged = false 151 | tag_name = to_tag_name(name) 152 | 153 | providers.each do |provider| 154 | provider_tagged = provider.tagged_with?(TAG_CATEGORY, tag_name) 155 | $evm.log(:info, "Provider '#{provider.name}' tagged with: #{TAG_CATEGORY} => #{tag_name}") if @DEBUG && provider_tagged 156 | break if provider_tagged 157 | end 158 | $evm.log(:info, "No provider tagged with: #{TAG_CATEGORY} => #{tag_name}") if @DEBUG && !provider_tagged 159 | 160 | !provider_tagged 161 | end 162 | 163 | return_dialog_element(true, dialog_field_values) 164 | end 165 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_domains_by_location.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Domains from Satellite based on selected Location. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | def dump_object(object_string, object) 8 | $evm.log("info", "Listing #{object_string} Attributes:") 9 | object.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 10 | $evm.log("info", "===========================================") 11 | end 12 | 13 | def dump_current 14 | $evm.log("info", "Listing Current Object Attributes:") 15 | $evm.current.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 16 | $evm.log("info", "===========================================") 17 | end 18 | 19 | def dump_root 20 | $evm.log("info", "Listing Root Object Attributes:") 21 | $evm.root.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 22 | $evm.log("info", "===========================================") 23 | end 24 | 25 | # Log an error and exit. 26 | # 27 | # @param msg Message to error with 28 | def error(msg) 29 | $evm.log(:error, msg) 30 | $evm.root['ae_result'] = 'error' 31 | $evm.root['ae_reason'] = msg.to_s 32 | exit MIQ_STOP 33 | end 34 | 35 | # There are many ways to attempt to pass parameters in Automate. 36 | # This function checks all of them in priorty order as well as checking for symbol or string. 37 | # 38 | # Order: 39 | # 1. Inputs 40 | # 2. Current 41 | # 3. Object 42 | # 4. Root 43 | # 5. State 44 | # 45 | # @return Value for the given parameter or nil if none is found 46 | def get_param(param) 47 | # check if inputs has been set for given param 48 | param_value ||= $evm.inputs[param.to_sym] 49 | param_value ||= $evm.inputs[param.to_s] 50 | 51 | # else check if current has been set for given param 52 | param_value ||= $evm.current[param.to_sym] 53 | param_value ||= $evm.current[param.to_s] 54 | 55 | # else cehck if current has been set for given param 56 | param_value ||= $evm.object[param.to_sym] 57 | param_value ||= $evm.object[param.to_s] 58 | 59 | # else check if param on root has been set for given param 60 | param_value ||= $evm.root[param.to_sym] 61 | param_value ||= $evm.root[param.to_s] 62 | 63 | # check if state has been set for given param 64 | param_value ||= $evm.get_state_var(param.to_sym) 65 | param_value ||= $evm.get_state_var(param.to_s) 66 | 67 | $evm.log(:info, "{ '#{param}' => '#{param_value}' }") if @DEBUG 68 | return param_value 69 | end 70 | 71 | # Gets an ApiPie binding to the Satellite API. 72 | # 73 | # @return ApipieBindings to the Satellite API 74 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 75 | def get_satellite_api() 76 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 77 | error("Satellite Configuration not found") if satellite_config.nil? 78 | 79 | satellite_server = satellite_config['satellite_server'] 80 | satellite_username = satellite_config['satellite_username'] 81 | satellite_password = satellite_config.decrypt('satellite_password') 82 | 83 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 84 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 85 | 86 | error("Satellite Server configuration not found") if satellite_server.nil? 87 | error("Satellite User configuration not found") if satellite_username.nil? 88 | error("Satellite Password configuration not found") if satellite_password.nil? 89 | 90 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 91 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 92 | return satellite_api 93 | end 94 | 95 | # Takes a string and makes it a valid tag name 96 | # 97 | # @param str String to turn into a valid Tag name 98 | # 99 | # @return Given string transformed into a valid Tag name 100 | def to_tag_name(str) 101 | return str.downcase.gsub(/[^a-z0-9_]+/,'_') 102 | end 103 | 104 | # @param visible_and_required Boolean true if the dialog element is visible and required, false if hidden 105 | # @param values Hash Values for the dialog element 106 | # @param default_value String 107 | def return_dialog_element(visible_and_required, values, default_value = nil) 108 | # create dialog element 109 | dialog_field = $evm.object 110 | dialog_field['data_type'] = "string" 111 | dialog_field['visible'] = visible_and_required 112 | dialog_field['required'] = visible_and_required 113 | dialog_field['values'] = values 114 | dialog_field['default_value'] = default_value 115 | $evm.log(:info, "dialog_field['values'] => #{dialog_field['values']}") if @DEBUG 116 | 117 | exit MIQ_OK 118 | end 119 | 120 | begin 121 | dump_root() if @DEBUG 122 | dump_current() if @DEBUG 123 | 124 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 125 | exit MIQ_OK unless $evm.root['vmdb_object_type'] 126 | 127 | # get the location tags 128 | location_tags = get_param(:dialog_location_tags) 129 | location_tags = location_tags.delete_if { |location_tag| location_tag.nil? || location_tag == "NaN" } if !location_tags.blank? 130 | $evm.log(:info, "location_tags => #{location_tags}") if @DEBUG 131 | 132 | # if no location tags selected then hide dialog element 133 | return_dialog_element(false, {}) if location_tags.empty? 134 | 135 | # verify a locaiton is selected for the given index 136 | location_index = get_param(:location_index) 137 | return_dialog_element(false, {}) if location_index >= location_tags.length 138 | $evm.log(:info, "location_index => #{location_index}") if @DEBUG 139 | 140 | # get the location tag 141 | location_tag_name = location_tags[location_index] 142 | $evm.log(:info, "location_tag_name => #{location_tag_name}") if @DEBUG 143 | location_tag = $evm.vmdb(:classification).find_by_name(location_tag_name) 144 | 145 | # get satellite API 146 | satellite_api = get_satellite_api() 147 | error('Could not get Satellite API') if satellite_api.nil? 148 | 149 | # get the satellite location 150 | location_index = satellite_api.resource(:locations).call(:index) 151 | $evm.log(:info, "location_index => #{location_index}") if @DEBUG 152 | satellite_location = location_index['results'].find { |location| to_tag_name(location['title']) == location_tag.name } 153 | return_dialog_element(true, { nil => "ERROR: Could not find Satellite Location for Location Tag <#{location_tag.description}>" }) if satellite_location.blank? 154 | $evm.log(:info, "satellite_location => #{satellite_location}") if @DEBUG 155 | 156 | # get the domains for the selected location 157 | domains_index = satellite_api.resource(:domains).call(:index, { :location_id => satellite_location['id'] }) 158 | $evm.log(:info, "domains_index => #{domains_index}") if @DEBUG 159 | return_dialog_element(true, { nil => "ERROR: Could not find Satellite Domains for Satellite Location <#{satellite_location['title']}>" }) if domains_index['results'].empty? 160 | 161 | # return results 162 | return_dialog_element( 163 | true, 164 | Hash[ *domains_index['results'].collect { |item| [item['name'], "#{item['name']} (#{location_tag.description})" ] }.flatten ], 165 | domains_index['results'][0]['name'] 166 | ) 167 | end 168 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_lifecycle_environments_filtered_by_tags.rb: -------------------------------------------------------------------------------- 1 | # Populates a dynamic drop down with the Lifecycle Enviornments from a Satellite Organization 2 | # filtered by tags on the providers available. 3 | # 4 | # Inputs: 5 | # - return_key - string - determines if hash returned from dialog element provides name or ID. e.g { id => name } or { name => name } 6 | # - acceptable values - 'name' or 'id' 7 | # - default value - 'id' 8 | 9 | require 'apipie-bindings' 10 | 11 | module RedHatConsulting_Satellite6 12 | module Automate 13 | module Integration 14 | module Satellite 15 | module DynamicDialogs 16 | class GetLifecycleEnvironmentsFilteredByTags 17 | include RedHatConsulting_Utilities::StdLib::Core 18 | 19 | TAG_CATEGORY = 'environment' 20 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 21 | 22 | def initialize(handle = $evm) 23 | @handle = handle 24 | @DEBUG = false 25 | end 26 | 27 | def main 28 | 29 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 30 | exit MIQ_OK unless @handle.root['vmdb_object_type'] 31 | 32 | satellite_api = get_satellite_api() 33 | 34 | satellite_organization_id = @handle.root['dialog_satellite_organization_id'] 35 | log(:info, "satellite_organization_id = #{satellite_organization_id}") if @DEBUG 36 | 37 | param_return_key = get_param(:return_key) 38 | log(:info, "Method input return_key => <#{param_return_key}>") if @DEBUG 39 | return_key = param_return_key.downcase == 'name' ? 'name' : 'id' rescue 'id' 40 | log(:info, "Returning Dialog element values based on <#{return_key}>") if @DEBUG 41 | 42 | if !satellite_organization_id.length.zero? 43 | environments_index = satellite_api.resource(:lifecycle_environments).call(:index,{:organization_id => satellite_organization_id}) 44 | log(:info, "environments_index = #{environments_index}") if @DEBUG 45 | dialog_field_values = Hash[ *environments_index['results'].collect { |item| [item[return_key], item['name']] }.flatten ] 46 | log(:info, "Environment dialog_field_values = #{dialog_field_values}") if @DEBUG 47 | else 48 | dialog_field_values = {} 49 | end 50 | 51 | log(:info, "dialog_field_values pre filtering: #{dialog_field_values}") if @DEBUG 52 | dialog_field_values.each do | key, name| 53 | create_tag(TAG_CATEGORY, name) 54 | end 55 | 56 | providers = @handle.vmdb(:ems).all 57 | dialog_field_values.delete_if do |id, name| 58 | provider_tagged = false 59 | tag_name = to_tag_name(name) 60 | 61 | providers.each do |provider| 62 | provider_tagged = provider.tagged_with?(TAG_CATEGORY, tag_name) 63 | log(:info, "Provider '#{provider.name}' tagged with: #{TAG_CATEGORY} => #{tag_name}") if @DEBUG && provider_tagged 64 | break if provider_tagged 65 | end 66 | log(:info, "No provider tagged with: #{TAG_CATEGORY} => #{tag_name}") if @DEBUG && !provider_tagged 67 | !provider_tagged 68 | end 69 | log(:info, "dialog_field_values post filtering: #{dialog_field_values}") if @DEBUG 70 | 71 | 72 | dialog_field_values['!'] = '--- Select Environment From List ---' 73 | dialog_field = @handle.object 74 | dialog_field["sort_by"] = "value" 75 | dialog_field["sort_order"] = "ascending" 76 | dialog_field["data_type"] = "string" 77 | dialog_field["required"] = true 78 | dialog_field["values"] = dialog_field_values 79 | 80 | exit MIQ_OK 81 | 82 | end 83 | 84 | # Gets all of the Tags in a given Tag Category 85 | # 86 | # @param category Tag Category to get all of the Tags for 87 | # 88 | # @return Hash of Tag names mapped to Tag descriptions 89 | # 90 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html#_getting_the_list_of_tags_in_a_category 91 | def get_category_tags(category) 92 | classification = @handle.vmdb(:classification).find_by_name(category) 93 | tags = {} 94 | @handle.vmdb(:classification).where(:parent_id => classification.id).each do |tag| 95 | tags[tag.name] = tag.description 96 | end 97 | 98 | return tags 99 | end 100 | 101 | # Create a Tag in a given Category if it does not already exist 102 | # 103 | # @param category Tag Category to create the Tag in 104 | # @param tag Tag to create in the given Tag Category 105 | # 106 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html 107 | def create_tag(category, tag) 108 | create_tag_category(category) 109 | tag_name = to_tag_name(tag) 110 | unless @handle.execute('tag_exists?', category, tag_name) 111 | @handle.execute('tag_create', 112 | category, 113 | :name => tag_name, 114 | :description => tag) 115 | end 116 | end 117 | 118 | # Create a Tag Category if it does not already exist 119 | # 120 | # @param category Tag Category to create 121 | # @param description Tag Category description. 122 | # Optional 123 | # Defaults to the `category` 124 | # @param single_value True if a resource can only have one tag from this category, 125 | # False if a resource can have multiple tags from this category. 126 | # Optional. 127 | # Defaults to `false` 128 | # 129 | # @source https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/using_tags_from_automate/chapter.html 130 | def create_tag_category(category, description = nil, single_value = false) 131 | category_name = to_tag_name(category) 132 | unless @handle.execute('category_exists?', category_name) 133 | @handle.execute('category_create', 134 | :name => category_name, 135 | :single_value => single_value, 136 | :perf_by_tag => false, 137 | :description => description || category) 138 | end 139 | end 140 | 141 | # Takes a string and makes it a valid tag name 142 | # 143 | # @param str String to turn into a valid Tag name 144 | # 145 | # @return Given string transformed into a valid Tag name 146 | def to_tag_name(str) 147 | return str.downcase.gsub(/[^a-z0-9_]+/,'_') 148 | end 149 | 150 | # Gets an ApiPie binding to the Satellite API. 151 | # 152 | # @return ApipieBindings to the Satellite API 153 | def get_satellite_api() 154 | satellite_config = @handle.instantiate(SATELLITE_CONFIG_URI) 155 | error("Satellite Configuration not found") if satellite_config.nil? 156 | 157 | satellite_server = satellite_config['satellite_server'] 158 | satellite_username = satellite_config['satellite_username'] 159 | satellite_password = satellite_config.decrypt('satellite_password') 160 | 161 | log(:info, "satellite_server = #{satellite_server}") if @DEBUG 162 | log(:info, "satellite_username = #{satellite_username}") if @DEBUG 163 | 164 | error("Satellite Server configuration not found") if satellite_server.nil? 165 | error("Satellite User configuration not found") if satellite_username.nil? 166 | error("Satellite Password configuration not found") if satellite_password.nil? 167 | 168 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 169 | log(:info, "satellite_api = #{satellite_api}") if @DEBUG 170 | return satellite_api 171 | end 172 | 173 | end 174 | end 175 | end 176 | end 177 | end 178 | end 179 | 180 | if __FILE__ == $PROGRAM_NAME 181 | RedHatConsulting_Satellite6::Automate::Integration::Satellite::DynamicDialogs::GetLifecycleEnvironmentsFilteredByTags.new.main 182 | end 183 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/set_user_data.rb: -------------------------------------------------------------------------------- 1 | # Sets the MiqProvision#options[:clone_options][:user_data] field. This allows a custom user data to be pased instead of using a Customization Template. 2 | # 3 | @DEBUG = false 4 | 5 | require 'apipie-bindings' 6 | 7 | def dump_object(object_string, object) 8 | $evm.log("info", "Listing #{object_string} Attributes:") 9 | object.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 10 | $evm.log("info", "===========================================") 11 | end 12 | 13 | def dump_current 14 | $evm.log("info", "Listing Current Object Attributes:") 15 | $evm.current.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 16 | $evm.log("info", "===========================================") 17 | end 18 | 19 | def dump_root 20 | $evm.log("info", "Listing Root Object Attributes:") 21 | $evm.root.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 22 | $evm.log("info", "===========================================") 23 | end 24 | 25 | # Notify and log a message. 26 | # 27 | # @param level Symbol Level of the notification and log message 28 | # @param message String Message to notify and log 29 | # @param subject ActiveRecord::Base Subject of the notification 30 | def notify(level, message, subject) 31 | $evm.create_notification(:level => level, :message => message, :subject => subject) 32 | log_level = case level 33 | when :warning 34 | :warn 35 | else 36 | level 37 | end 38 | $evm.log(log_level, message) 39 | end 40 | 41 | # Log an error and exit. 42 | # 43 | # @param msg Message to error with 44 | def error(msg) 45 | $evm.log(:error, msg) 46 | $evm.root['ae_result'] = 'error' 47 | $evm.root['ae_reason'] = msg.to_s 48 | exit MIQ_STOP 49 | end 50 | 51 | # There are many ways to attempt to pass parameters in Automate. 52 | # This function checks all of them in priorty order as well as checking for symbol or string. 53 | # 54 | # Order: 55 | # 1. Inputs 56 | # 2. Current 57 | # 3. Object 58 | # 4. Root 59 | # 5. State 60 | # 61 | # @return Value for the given parameter or nil if none is found 62 | def get_param(param) 63 | # check if inputs has been set for given param 64 | param_value ||= $evm.inputs[param.to_sym] 65 | param_value ||= $evm.inputs[param.to_s] 66 | 67 | # else check if current has been set for given param 68 | param_value ||= $evm.current[param.to_sym] 69 | param_value ||= $evm.current[param.to_s] 70 | 71 | # else cehck if current has been set for given param 72 | param_value ||= $evm.object[param.to_sym] 73 | param_value ||= $evm.object[param.to_s] 74 | 75 | # else check if param on root has been set for given param 76 | param_value ||= $evm.root[param.to_sym] 77 | param_value ||= $evm.root[param.to_s] 78 | 79 | # check if state has been set for given param 80 | param_value ||= $evm.get_state_var(param.to_sym) 81 | param_value ||= $evm.get_state_var(param.to_s) 82 | 83 | $evm.log(:info, "{ '#{param}' => '#{param_value}' }") if @DEBUG 84 | return param_value 85 | end 86 | 87 | # Function for getting the current VM and associated options based on the vmdb_object_type. 88 | # 89 | # Supported vmdb_object_types 90 | # * miq_provision 91 | # * vm 92 | # * automation_task 93 | # 94 | # @return vm,options 95 | def get_vm_and_options() 96 | $evm.log(:info, "$evm.root['vmdb_object_type'] => '#{$evm.root['vmdb_object_type']}'.") 97 | case $evm.root['vmdb_object_type'] 98 | when 'miq_provision' 99 | # get root object 100 | $evm.log(:info, "Get VM and dialog attributes from $evm.root['miq_provision']") if @DEBUG 101 | miq_provision = $evm.root['miq_provision'] 102 | dump_object('miq_provision', miq_provision) if @DEBUG 103 | 104 | # get VM 105 | vm = miq_provision.vm 106 | 107 | # get options 108 | options = miq_provision.options 109 | #merge the ws_values, dialog, top level options into one list to make it easier to search 110 | options = options.merge(options[:ws_values]) if options[:ws_values] 111 | options = options.merge(options[:dialog]) if options[:dialog] 112 | when 'vm' 113 | # get root objet & VM 114 | $evm.log(:info, "Get VM from paramater and dialog attributes form $evm.root") if @DEBUG 115 | vm = get_param(:vm) 116 | dump_object('vm', vm) if @DEBUG 117 | 118 | # get options 119 | options = $evm.root.attributes 120 | #merge the ws_values, dialog, top level options into one list to make it easier to search 121 | options = options.merge(options[:ws_values]) if options[:ws_values] 122 | options = options.merge(options[:dialog]) if options[:dialog] 123 | when 'automation_task' 124 | # get root objet 125 | $evm.log(:info, "Get VM from paramater and dialog attributes form $evm.root") if @DEBUG 126 | automation_task = $evm.root['automation_task'] 127 | dump_object('automation_task', automation_task) if @DEBUG 128 | 129 | # get VM 130 | vm = get_param(:vm) 131 | 132 | # get options 133 | options = get_param(:options) 134 | options = JSON.load(options) if options && options.class == String 135 | options = options.symbolize_keys if options 136 | #merge the ws_values, dialog, top level options into one list to make it easier to search 137 | options = options.merge(options[:ws_values]) if options[:ws_values] 138 | options = options.merge(options[:dialog]) if options[:dialog] 139 | else 140 | error("Can not handle vmdb_object_type: #{$evm.root['vmdb_object_type']}") 141 | end 142 | 143 | # standerdize the option keys 144 | options = options.symbolize_keys() 145 | 146 | return vm,options 147 | end 148 | 149 | # Gets an ApiPie binding to the Satellite API. 150 | # 151 | # @return ApipieBindings to the Satellite API 152 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 153 | def get_satellite_api() 154 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 155 | error("Satellite Configuration not found") if satellite_config.nil? 156 | 157 | satellite_server = satellite_config['satellite_server'] 158 | satellite_username = satellite_config['satellite_username'] 159 | satellite_password = satellite_config.decrypt('satellite_password') 160 | 161 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 162 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 163 | 164 | error("Satellite Server configuration not found") if satellite_server.nil? 165 | error("Satellite User configuration not found") if satellite_username.nil? 166 | error("Satellite Password configuration not found") if satellite_password.nil? 167 | 168 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 169 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 170 | return satellite_api 171 | end 172 | 173 | # Get the Satellite host record for a given host name 174 | # 175 | # @param satellite_api ApipieBinding Sattellite API object 176 | # @param name String Name of the host to find the Satelilte host record for 177 | # 178 | # @return Hash Satellite host record for the given host name returned from Satellite API 179 | def get_satellite_host_record(satellite_api, name) 180 | begin 181 | satellite_index_result = satellite_api.resource(:hosts).call(:index, {:search => "name=#{name}"}) 182 | if !satellite_index_result['results'].empty? 183 | satellite_host_record = satellite_index_result['results'][0] 184 | 185 | # NOTE: hopefully this never happens 186 | # warn if found more then one result 187 | if satellite_index_result['results'].length > 1 188 | $evm.log(:warn, "More then one Satellite host record found for Host <#{name}>, using first one.") 189 | end 190 | else 191 | error("Could not find Satellite host entry for Host <#{name}>") 192 | end 193 | rescue RestClient::UnprocessableEntity => e 194 | error("Error finding Satellite host record for Host <#{name}>. Received an UnprocessableEntity error from Satellite. Check /var/log/foreman/production.log on Satellite for more info.") 195 | rescue Exception => e 196 | error("Error finding Satellite host record for Host <#{name}>: #{e.message}") 197 | end 198 | 199 | return satellite_host_record 200 | end 201 | 202 | begin 203 | satellite_api = get_satellite_api() 204 | vm,options = get_vm_and_options() 205 | vm_name = vm ? vm.name : (options[:vm_target_name] || options[:vm_target_hostname] || options[:vm_name]) 206 | 207 | miq_provision = $evm.root['miq_provision'] 208 | error('Expected provisioning request not found') if miq_provision.nil? 209 | 210 | # find the satellite host record 211 | satellite_host_record = get_satellite_host_record(satellite_api, vm_name) 212 | 213 | # find the satellite host record user data template 214 | begin 215 | satellite_host_user_data_template_result = satellite_api.resource(:hosts).call(:template, {:id => satellite_host_record['id'], :kind => 'user_data'}) 216 | $evm.log(:info, "satellite_host_user_data_template_result => #{satellite_host_user_data_template_result}") if @DEBUG 217 | rescue RestClient::UnprocessableEntity => e 218 | error("Error finding Satellite host user_data template for Satelite host record <#{satellite_host_record['id']}> for VM <#{vm_name}>. Received an UnprocessableEntity error from Satellite. Check /var/log/foreman/production.log on Satellite for more info.") 219 | rescue Exception => e 220 | error("Error finding Satellite host user_data template for Satelite host record <#{satellite_host_record['id']}> for VM <#{vm_name}>: #{e.message}") 221 | end 222 | 223 | # set the user data clone option 224 | clone_options = miq_provision.get_option(:clone_options) || {} 225 | clone_options[:user_data] = Base64.encode64(satellite_host_user_data_template_result['template']) 226 | miq_provision.set_option(:clone_options, clone_options) 227 | $evm.log(:info, "miq_provision.get_option(:clone_options)[:user_data] => #{miq_provision.get_option(:clone_options)[:user_data]}") 228 | end 229 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Service/Provisioning/StateMachines/ServiceProvision_Template.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: Service Provision State Machine 7 | display_name: 8 | name: ServiceProvision_Template 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: state 16 | name: sequencer 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: update_serviceprovision_status(status => 'Processing Sequencer') 30 | on_exit: update_serviceprovision_status(status => 'Processed Sequencer') 31 | on_error: update_serviceprovision_status(status => 'Error Processing Sequencer') 32 | max_retries: '100' 33 | max_time: 34 | - field: 35 | aetype: state 36 | name: pre1 37 | display_name: 38 | datatype: string 39 | priority: 2 40 | owner: 41 | default_value: 42 | substitute: true 43 | message: create 44 | visibility: 45 | collect: 46 | scope: 47 | description: 48 | condition: 49 | on_entry: update_serviceprovision_status(status => 'Processing Pre1') 50 | on_exit: update_serviceprovision_status(status => 'Processed Pre1') 51 | on_error: update_serviceprovision_status(status => 'Error Processing Pre1') 52 | max_retries: '100' 53 | max_time: 54 | - field: 55 | aetype: state 56 | name: pre2 57 | display_name: 58 | datatype: string 59 | priority: 3 60 | owner: 61 | default_value: 62 | substitute: true 63 | message: create 64 | visibility: 65 | collect: 66 | scope: 67 | description: 68 | condition: 69 | on_entry: update_serviceprovision_status(status => 'Processing Pre2') 70 | on_exit: update_serviceprovision_status(status => 'Processed Pre2') 71 | on_error: update_serviceprovision_status(status => 'Error Processing Pre2') 72 | max_retries: '100' 73 | max_time: 74 | - field: 75 | aetype: state 76 | name: pre3 77 | display_name: 78 | datatype: string 79 | priority: 4 80 | owner: 81 | default_value: 82 | substitute: true 83 | message: create 84 | visibility: 85 | collect: 86 | scope: 87 | description: 88 | condition: 89 | on_entry: update_serviceprovision_status(status => 'Processing Pre3') 90 | on_exit: update_serviceprovision_status(status => 'Processed Pre3') 91 | on_error: update_serviceprovision_status(status => 'Error Processing Pre3') 92 | max_retries: '100' 93 | max_time: 94 | - field: 95 | aetype: state 96 | name: pre4 97 | display_name: 98 | datatype: string 99 | priority: 5 100 | owner: 101 | default_value: 102 | substitute: true 103 | message: create 104 | visibility: 105 | collect: 106 | scope: 107 | description: 108 | condition: 109 | on_entry: update_serviceprovision_status(status => 'Processing Pre4') 110 | on_exit: update_serviceprovision_status(status => 'Processed Pre4') 111 | on_error: update_serviceprovision_status(status => 'Error Processing Pre4') 112 | max_retries: '100' 113 | max_time: 114 | - field: 115 | aetype: state 116 | name: pre5 117 | display_name: 118 | datatype: string 119 | priority: 6 120 | owner: 121 | default_value: 122 | substitute: true 123 | message: create 124 | visibility: 125 | collect: 126 | scope: 127 | description: 128 | condition: 129 | on_entry: update_serviceprovision_status(status => 'Processing Pre5') 130 | on_exit: update_serviceprovision_status(status => 'Processed Pre5') 131 | on_error: update_serviceprovision_status(status => 'Error Processing Pre5') 132 | max_retries: '100' 133 | max_time: 134 | - field: 135 | aetype: state 136 | name: pre6 137 | display_name: 138 | datatype: string 139 | priority: 7 140 | owner: 141 | default_value: 142 | substitute: true 143 | message: create 144 | visibility: 145 | collect: 146 | scope: 147 | description: 148 | condition: 149 | on_entry: 150 | on_exit: 151 | on_error: 152 | max_retries: 153 | max_time: 154 | - field: 155 | aetype: state 156 | name: pre7 157 | display_name: 158 | datatype: string 159 | priority: 8 160 | owner: 161 | default_value: 162 | substitute: true 163 | message: create 164 | visibility: 165 | collect: 166 | scope: 167 | description: 168 | condition: 169 | on_entry: 170 | on_exit: 171 | on_error: 172 | max_retries: 173 | max_time: 174 | - field: 175 | aetype: state 176 | name: configurechilddialog 177 | display_name: 178 | datatype: string 179 | priority: 9 180 | owner: 181 | default_value: 182 | substitute: true 183 | message: create 184 | visibility: 185 | collect: 186 | scope: 187 | description: 188 | condition: 189 | on_entry: 190 | on_exit: 191 | on_error: 192 | max_retries: 193 | max_time: 194 | - field: 195 | aetype: state 196 | name: provision 197 | display_name: 198 | datatype: string 199 | priority: 10 200 | owner: 201 | default_value: "/Service/Provisioning/StateMachines/Methods/Provision" 202 | substitute: true 203 | message: create 204 | visibility: 205 | collect: 206 | scope: 207 | description: 208 | condition: 209 | on_entry: update_serviceprovision_status(status => 'Creating Service') 210 | on_exit: update_serviceprovision_status(status => 'Creating Service') 211 | on_error: update_serviceprovision_status(status => 'Error Creating Service') 212 | max_retries: '100' 213 | max_time: 214 | - field: 215 | aetype: state 216 | name: checkprovisioned 217 | display_name: 218 | datatype: string 219 | priority: 11 220 | owner: 221 | default_value: "/Service/Provisioning/StateMachines/Methods/CheckProvisioned" 222 | substitute: true 223 | message: create 224 | visibility: 225 | collect: 226 | scope: 227 | description: 228 | condition: 229 | on_entry: 230 | on_exit: update_serviceprovision_status(status => 'Creating Service') 231 | on_error: update_serviceprovision_status(status => '${/#ae_reason}') 232 | max_retries: '100' 233 | max_time: 234 | - field: 235 | aetype: state 236 | name: post1 237 | display_name: 238 | datatype: string 239 | priority: 12 240 | owner: 241 | default_value: 242 | substitute: true 243 | message: create 244 | visibility: 245 | collect: 246 | scope: 247 | description: 248 | condition: 249 | on_entry: '' 250 | on_exit: '' 251 | on_error: '' 252 | max_retries: '' 253 | max_time: 254 | - field: 255 | aetype: state 256 | name: post2 257 | display_name: 258 | datatype: string 259 | priority: 13 260 | owner: 261 | default_value: 262 | substitute: true 263 | message: create 264 | visibility: 265 | collect: 266 | scope: 267 | description: 268 | condition: 269 | on_entry: '' 270 | on_exit: '' 271 | on_error: '' 272 | max_retries: 273 | max_time: 274 | - field: 275 | aetype: state 276 | name: post3 277 | display_name: 278 | datatype: string 279 | priority: 14 280 | owner: 281 | default_value: 282 | substitute: true 283 | message: create 284 | visibility: 285 | collect: 286 | scope: 287 | description: 288 | condition: 289 | on_entry: '' 290 | on_exit: '' 291 | on_error: '' 292 | max_retries: 293 | max_time: 294 | - field: 295 | aetype: state 296 | name: post4 297 | display_name: 298 | datatype: string 299 | priority: 15 300 | owner: 301 | default_value: 302 | substitute: true 303 | message: create 304 | visibility: 305 | collect: 306 | scope: 307 | description: 308 | condition: 309 | on_entry: '' 310 | on_exit: '' 311 | on_error: '' 312 | max_retries: 313 | max_time: 314 | - field: 315 | aetype: state 316 | name: post5 317 | display_name: 318 | datatype: string 319 | priority: 16 320 | owner: 321 | default_value: 322 | substitute: true 323 | message: create 324 | visibility: 325 | collect: 326 | scope: 327 | description: 328 | condition: 329 | on_entry: '' 330 | on_exit: '' 331 | on_error: '' 332 | max_retries: 333 | max_time: 334 | - field: 335 | aetype: state 336 | name: EmailOwner 337 | display_name: 338 | datatype: string 339 | priority: 17 340 | owner: 341 | default_value: "/Service/Provisioning/Email/ServiceProvision_complete?event=service_provisioned" 342 | substitute: true 343 | message: create 344 | visibility: 345 | collect: 346 | scope: 347 | description: 348 | condition: 349 | on_entry: update_serviceprovision_status(status => 'Emailing Owner') 350 | on_exit: update_serviceprovision_status(status => 'Emailed Owner') 351 | on_error: update_serviceprovision_status(status => 'Error Emailing Owner') 352 | max_retries: '100' 353 | max_time: 354 | - field: 355 | aetype: state 356 | name: Finished 357 | display_name: 358 | datatype: string 359 | priority: 18 360 | owner: 361 | default_value: "/System/CommonMethods/StateMachineMethods/service_provision_finished" 362 | substitute: true 363 | message: create 364 | visibility: 365 | collect: 366 | scope: 367 | description: 368 | condition: 369 | on_entry: 370 | on_exit: 371 | on_error: 372 | max_retries: '100' 373 | max_time: 374 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/Operations/Methods.class/__methods__/update_satellite.rb: -------------------------------------------------------------------------------- 1 | # Update the Satellite Host Record based on current VM information. 2 | # * MAC 3 | # * IP 4 | # 5 | @DEBUG = false 6 | 7 | require 'apipie-bindings' 8 | 9 | def dump_object(object_string, object) 10 | $evm.log("info", "Listing #{object_string} Attributes:") 11 | object.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 12 | $evm.log("info", "===========================================") 13 | end 14 | 15 | def dump_current 16 | $evm.log("info", "Listing Current Object Attributes:") 17 | $evm.current.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 18 | $evm.log("info", "===========================================") 19 | end 20 | 21 | def dump_root 22 | $evm.log("info", "Listing Root Object Attributes:") 23 | $evm.root.attributes.sort.each { |k, v| $evm.log("info", "\t#{k}: #{v}") } 24 | $evm.log("info", "===========================================") 25 | end 26 | 27 | # Log an error and exit. 28 | # 29 | # @param msg Message to error with 30 | def error(msg) 31 | $evm.log(:error, msg) 32 | $evm.root['ae_result'] = 'error' 33 | $evm.root['ae_reason'] = msg.to_s 34 | exit MIQ_STOP 35 | end 36 | 37 | # Notify and log a warning message. 38 | # 39 | # @param msg Message to warn with 40 | def warn(msg) 41 | $evm.create_notification(:level => 'warning', :message => msg) 42 | $evm.log(:warn, msg) 43 | end 44 | 45 | # There are many ways to attempt to pass parameters in Automate. 46 | # This function checks all of them in priorty order as well as checking for symbol or string. 47 | # 48 | # Order: 49 | # 1. Inputs 50 | # 2. Current 51 | # 3. Object 52 | # 4. Root 53 | # 5. State 54 | # 55 | # @return Value for the given parameter or nil if none is found 56 | def get_param(param) 57 | # check if inputs has been set for given param 58 | param_value ||= $evm.inputs[param.to_sym] 59 | param_value ||= $evm.inputs[param.to_s] 60 | 61 | # else check if current has been set for given param 62 | param_value ||= $evm.current[param.to_sym] 63 | param_value ||= $evm.current[param.to_s] 64 | 65 | # else cehck if current has been set for given param 66 | param_value ||= $evm.object[param.to_sym] 67 | param_value ||= $evm.object[param.to_s] 68 | 69 | # else check if param on root has been set for given param 70 | param_value ||= $evm.root[param.to_sym] 71 | param_value ||= $evm.root[param.to_s] 72 | 73 | # check if state has been set for given param 74 | param_value ||= $evm.get_state_var(param.to_sym) 75 | param_value ||= $evm.get_state_var(param.to_s) 76 | 77 | $evm.log(:info, "{ '#{param}' => '#{param_value}' }") if @DEBUG 78 | return param_value 79 | end 80 | 81 | # Function for getting the current VM and associated options based on the vmdb_object_type. 82 | # 83 | # Supported vmdb_object_types 84 | # * miq_provision 85 | # * vm 86 | # * automation_task 87 | # 88 | # @return vm,options 89 | def get_vm_and_options() 90 | $evm.log(:info, "$evm.root['vmdb_object_type'] => '#{$evm.root['vmdb_object_type']}'.") 91 | case $evm.root['vmdb_object_type'] 92 | when 'miq_provision' 93 | # get root object 94 | $evm.log(:info, "Get VM and dialog attributes from $evm.root['miq_provision']") if @DEBUG 95 | miq_provision = $evm.root['miq_provision'] 96 | dump_object('miq_provision', miq_provision) if @DEBUG 97 | 98 | # get VM 99 | vm = miq_provision.vm 100 | 101 | # get options 102 | options = miq_provision.options 103 | #merge the ws_values, dialog, top level options into one list to make it easier to search 104 | options = options.merge(options[:ws_values]) if options[:ws_values] 105 | options = options.merge(options[:dialog]) if options[:dialog] 106 | when 'vm' 107 | # get root objet & VM 108 | $evm.log(:info, "Get VM from paramater and dialog attributes form $evm.root") if @DEBUG 109 | vm = get_param(:vm) 110 | dump_object('vm', vm) if @DEBUG 111 | 112 | # get options 113 | options = $evm.root.attributes 114 | #merge the ws_values, dialog, top level options into one list to make it easier to search 115 | options = options.merge(options[:ws_values]) if options[:ws_values] 116 | options = options.merge(options[:dialog]) if options[:dialog] 117 | when 'automation_task' 118 | # get root objet 119 | $evm.log(:info, "Get VM from paramater and dialog attributes form $evm.root") if @DEBUG 120 | automation_task = $evm.root['automation_task'] 121 | dump_object('automation_task', automation_task) if @DEBUG 122 | 123 | # get VM 124 | vm = get_param(:vm) 125 | 126 | # get options 127 | options = get_param(:options) 128 | options = JSON.load(options) if options && options.class == String 129 | options = options.symbolize_keys if options 130 | #merge the ws_values, dialog, top level options into one list to make it easier to search 131 | options = options.merge(options[:ws_values]) if options[:ws_values] 132 | options = options.merge(options[:dialog]) if options[:dialog] 133 | else 134 | error("Can not handle vmdb_object_type: #{$evm.root['vmdb_object_type']}") 135 | end 136 | 137 | # standerdize the option keys 138 | options = options.symbolize_keys() 139 | 140 | return vm,options 141 | end 142 | 143 | # Gets an ApiPie binding to the Satellite API. 144 | # 145 | # @return ApipieBindings to the Satellite API 146 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 147 | def get_satellite_api() 148 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 149 | error("Satellite Configuration not found") if satellite_config.nil? 150 | 151 | satellite_server = satellite_config['satellite_server'] 152 | satellite_username = satellite_config['satellite_username'] 153 | satellite_password = satellite_config.decrypt('satellite_password') 154 | 155 | $evm.log(:info, "satellite_server = #{satellite_server}") if @DEBUG 156 | $evm.log(:info, "satellite_username = #{satellite_username}") if @DEBUG 157 | 158 | error("Satellite Server configuration not found") if satellite_server.nil? 159 | error("Satellite User configuration not found") if satellite_username.nil? 160 | error("Satellite Password configuration not found") if satellite_password.nil? 161 | 162 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 163 | $evm.log(:info, "satellite_api = #{satellite_api}") if @DEBUG 164 | return satellite_api 165 | end 166 | 167 | # Get the Satellite host record for a given host name 168 | # 169 | # @param satellite_api ApipieBinding Sattellite API object 170 | # @param name String Name of the host to find the Satelilte host record for 171 | # 172 | # @return Hash Satellite host record for the given host name returned from Satellite API 173 | def get_satellite_host_record(satellite_api, name) 174 | satellite_host_record = nil 175 | begin 176 | satellite_index_result = satellite_api.resource(:hosts).call(:index, {:search => "name=#{name}"}) 177 | if !satellite_index_result['results'].empty? 178 | satellite_host_record = satellite_index_result['results'].first 179 | 180 | # get the full record 181 | satellite_host_record = satellite_api.resource(:hosts).call(:show, {:id => satellite_host_record['id']}) 182 | 183 | # NOTE: hopefully this never happens 184 | # warn if found more then one result 185 | if satellite_index_result['results'].length > 1 186 | $evm.log(:warn, "More then one Satellite host record found for Host <#{name}>, using first one.") 187 | end 188 | end 189 | rescue RestClient::UnprocessableEntity => e 190 | error("Error finding Satellite host record for Host <#{name}>. Received an UnprocessableEntity error from Satellite. Check /var/log/foreman/production.log on Satellite for more info.") 191 | rescue Exception => e 192 | error("Error finding Satellite host record for Host <#{name}>: #{e.message}") 193 | end 194 | 195 | return satellite_host_record 196 | end 197 | 198 | begin 199 | # get the VM 200 | vm,options = get_vm_and_options() 201 | error('VM not found') if vm.nil? 202 | $evm.log(:info, "vm => #{vm}") if @DEBUG 203 | 204 | # get the satellite host record id 205 | satellite_api = get_satellite_api() 206 | satellite_host_record = get_satellite_host_record(satellite_api, vm.name) 207 | 208 | # if a satellite host record is found, then check if it needs to be updated 209 | # else just ignore 210 | if !satellite_host_record.blank? 211 | satellite_host_ip = satellite_host_record['ip'] 212 | satellite_host_mac = satellite_host_record['mac'] 213 | satellite_host_interfaces = satellite_host_record['interfaces'] 214 | 215 | # if Satellite Host record does not have IP or MAC and isn't already managed, then update the host record 216 | if (satellite_host_ip.blank? || satellite_host_mac.blank?) && !satellite_host_interfaces.first['managed'] 217 | # NOTE: assume use first IP and MAC 218 | vm_mac_address = vm.mac_addresses.first 219 | vm_ip_address = vm.ipaddresses.first 220 | new_satellite_host_record = { 221 | :mac => vm_mac_address, 222 | :ip => vm_ip_address, 223 | :interfaces_attributes => satellite_host_interfaces.clone 224 | } 225 | 226 | # update interface so it is managed 227 | # NOTE: making assumptionn to update first interface 228 | new_satellite_host_record[:interfaces_attributes][0][:mac] = vm_mac_address 229 | new_satellite_host_record[:interfaces_attributes][0][:ip] = vm_ip_address 230 | new_satellite_host_record[:interfaces_attributes][0][:managed] = true 231 | 232 | # update the host record 233 | satellite_host_id = satellite_host_record['id'] 234 | $evm.log(:info, "satellite_host_id => '#{satellite_host_id}'") if @DEBUG 235 | begin 236 | $evm.log(:info, "Update Satellite Host Record <#{satellite_host_id}> for Host <#{vm.name}>: #{new_satellite_host_record}") 237 | result = satellite_api.resource(:hosts).call(:update, { :id => satellite_host_id, :host => new_satellite_host_record}) 238 | $evm.log(:info, "Update Satellite Host Record <#{satellite_host_id}> for Host <#{vm.name}>: #{result}") 239 | rescue RestClient::NotFound 240 | warn("No Satellite Host Record <#{satellite_host_id}> to update for Host <#{vm.name}>.") 241 | rescue => e 242 | warn("Unexpected error when unregistering Satellite Host Record <#{satellite_host_id}> to unregister for Host <#{vm.name}>: #{e.message}") 243 | end 244 | end 245 | else 246 | $evm.log(:info, "No Satellite Host Record to udpate found for Host <#{vm.name}>. Skipping and ignoring.") 247 | end 248 | end 249 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Infrastructure/VM/Retirement/StateMachines/VMRetirement.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: VMRetirement 7 | display_name: 8 | name: VMRetirement 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: state 16 | name: StartRetirement 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: "/Infrastructure/VM/Retirement/StateMachines/Methods/StartRetirement" 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: update_retirement_status(status => 'Starting Retirement') 30 | on_exit: update_retirement_status(status => 'Started Retirement') 31 | on_error: update_retirement_status(status => 'Error Starting Retirement') 32 | max_retries: '100' 33 | max_time: 34 | - field: 35 | aetype: state 36 | name: PreRetirement 37 | display_name: 38 | datatype: string 39 | priority: 2 40 | owner: 41 | default_value: "/Infrastructure/VM/Retirement/StateMachines/Methods/PreRetirement#${/#vm.vendor}" 42 | substitute: true 43 | message: create 44 | visibility: 45 | collect: 46 | scope: 47 | description: 48 | condition: 49 | on_entry: update_retirement_status(status => 'Starting PreRetirement') 50 | on_exit: update_retirement_status(status => 'PreRetirement succesful') 51 | on_error: update_retirement_status(status => 'Error in PreRetirement') 52 | max_retries: '100' 53 | max_time: 54 | - field: 55 | aetype: state 56 | name: CheckPreRetirement 57 | display_name: 58 | datatype: string 59 | priority: 3 60 | owner: 61 | default_value: "/Infrastructure/VM/Retirement/StateMachines/Methods/CheckPreRetirement#${/#vm.vendor}" 62 | substitute: true 63 | message: create 64 | visibility: 65 | collect: 66 | scope: 67 | description: 68 | condition: 69 | on_entry: update_retirement_status(status => 'Starting CheckPreRetirement') 70 | on_exit: update_retirement_status(status => 'CheckPreRetirement successful') 71 | on_error: update_retirement_status(status => 'Error in CheckPreRetirement') 72 | max_retries: '100' 73 | max_time: 74 | - field: 75 | aetype: state 76 | name: UnregisterDHCP 77 | display_name: 78 | datatype: string 79 | priority: 4 80 | owner: 81 | default_value: 82 | substitute: true 83 | message: create 84 | visibility: 85 | collect: 86 | scope: 87 | description: 88 | condition: 89 | on_entry: '' 90 | on_exit: '' 91 | on_error: '' 92 | max_retries: '100' 93 | max_time: 94 | - field: 95 | aetype: state 96 | name: UnregisterAD 97 | display_name: 98 | datatype: string 99 | priority: 5 100 | owner: 101 | default_value: 102 | substitute: true 103 | message: create 104 | visibility: 105 | collect: 106 | scope: 107 | description: 108 | condition: 109 | on_entry: '' 110 | on_exit: '' 111 | on_error: '' 112 | max_retries: '100' 113 | max_time: 114 | - field: 115 | aetype: state 116 | name: UnregisterDNS 117 | display_name: 118 | datatype: string 119 | priority: 6 120 | owner: 121 | default_value: 122 | substitute: true 123 | message: create 124 | visibility: 125 | collect: 126 | scope: 127 | description: 128 | condition: 129 | on_entry: '' 130 | on_exit: '' 131 | on_error: '' 132 | max_retries: '100' 133 | max_time: 134 | - field: 135 | aetype: state 136 | name: ReleaseMACAddress 137 | display_name: 138 | datatype: string 139 | priority: 7 140 | owner: 141 | default_value: 142 | substitute: true 143 | message: create 144 | visibility: 145 | collect: 146 | scope: 147 | description: 148 | condition: 149 | on_entry: '' 150 | on_exit: '' 151 | on_error: '' 152 | max_retries: '100' 153 | max_time: 154 | - field: 155 | aetype: state 156 | name: ReleaseIPAddress 157 | display_name: 158 | datatype: string 159 | priority: 8 160 | owner: 161 | default_value: 162 | substitute: true 163 | message: create 164 | visibility: 165 | collect: 166 | scope: 167 | description: 168 | condition: 169 | on_entry: update_retirement_status(status => 'Releasing IP Address') 170 | on_exit: update_retirement_status(status => 'Released IP Address') 171 | on_error: update_retirement_status(status => 'Error Releasing IP Address') 172 | max_retries: '100' 173 | max_time: 174 | - field: 175 | aetype: state 176 | name: PreDeleteFromProvider 177 | display_name: 178 | datatype: string 179 | priority: 9 180 | owner: 181 | default_value: "#/Infrastructure/VM/Retirement/StateMachines/Methods/PreDeleteFromProvider" 182 | substitute: true 183 | message: create 184 | visibility: 185 | collect: 186 | scope: 187 | description: 188 | condition: 189 | on_entry: '' 190 | on_exit: '' 191 | on_error: '' 192 | max_retries: '100' 193 | max_time: 194 | - field: 195 | aetype: state 196 | name: RemoveFromProvider 197 | display_name: 198 | datatype: string 199 | priority: 10 200 | owner: 201 | default_value: "/Infrastructure/VM/Retirement/StateMachines/Methods/RemoveFromProvider" 202 | substitute: true 203 | message: create 204 | visibility: 205 | collect: 206 | scope: 207 | description: 208 | condition: 209 | on_entry: update_retirement_status(status => 'Removing from Provider') 210 | on_exit: update_retirement_status(status => 'Removed from Provider') 211 | on_error: update_retirement_status(status => 'Error Removing from Provider') 212 | max_retries: '100' 213 | max_time: 214 | - field: 215 | aetype: state 216 | name: CheckRemovedFromProvider 217 | display_name: 218 | datatype: string 219 | priority: 11 220 | owner: 221 | default_value: "/Infrastructure/VM/Retirement/StateMachines/Methods/CheckDeletedFromProvider" 222 | substitute: true 223 | message: create 224 | visibility: 225 | collect: 226 | scope: 227 | description: 228 | condition: 229 | on_entry: update_retirement_status(status => 'Checking Removal from Provider') 230 | on_exit: update_retirement_status(status => 'Checked Removal from Provider') 231 | on_error: update_retirement_status(status => 'Error Checking Removal from Provider') 232 | max_retries: '100' 233 | max_time: 234 | - field: 235 | aetype: state 236 | name: UnregisterSatellite 237 | display_name: 238 | datatype: string 239 | priority: 12 240 | owner: 241 | default_value: "/Integration/Satellite/Operations/Methods/UnregisterSatellite" 242 | substitute: true 243 | message: create 244 | visibility: 245 | collect: 246 | scope: 247 | description: 248 | condition: 249 | on_entry: update_retirement_status(status => 'Unregistering from Satellite'') 250 | on_exit: update_retirement_status(status => 'Unregistered from Satellite'') 251 | on_error: update_retirement_status(status => 'Failed Unregistering from Satellite'') 252 | max_retries: '100' 253 | max_time: 254 | - field: 255 | aetype: state 256 | name: DeactivateCMDB 257 | display_name: 258 | datatype: string 259 | priority: 13 260 | owner: 261 | default_value: "#/Integration/LDAP/StateMachines/UpdateLDAPEntryAttributes/Default" 262 | substitute: true 263 | message: create 264 | visibility: 265 | collect: 266 | scope: 267 | description: 268 | condition: 269 | on_entry: update_retirement_status(status => 'Updating LDAP Retirement Status') 270 | on_exit: update_retirement_status(status => 'Updated LDAP Retirement Status') 271 | on_error: update_retirement_status(status => 'Failed to Update LDAP Retirement 272 | Status') 273 | max_retries: '100' 274 | max_time: 275 | - field: 276 | aetype: state 277 | name: FinishRetirement 278 | display_name: 279 | datatype: string 280 | priority: 14 281 | owner: 282 | default_value: "/Infrastructure/VM/Retirement/StateMachines/Methods/FinishRetirement" 283 | substitute: true 284 | message: create 285 | visibility: 286 | collect: 287 | scope: 288 | description: 289 | condition: 290 | on_entry: update_retirement_status(status => 'Finishing Retirement') 291 | on_exit: update_retirement_status(status => 'Finished Retirement') 292 | on_error: update_retirement_status(status => 'Error Finishing Retirement') 293 | max_retries: '100' 294 | max_time: 295 | - field: 296 | aetype: state 297 | name: PreDeleteEmailOwner 298 | display_name: 299 | datatype: string 300 | priority: 15 301 | owner: 302 | default_value: "#/Infrastructure/VM/Retirement/Email/vm_retirement_emails?event=vm_entered_retirement" 303 | substitute: true 304 | message: create 305 | visibility: 306 | collect: 307 | scope: 308 | description: 309 | condition: 310 | on_entry: '' 311 | on_exit: '' 312 | on_error: '' 313 | max_retries: '100' 314 | max_time: 315 | - field: 316 | aetype: state 317 | name: EmailOwner 318 | display_name: 319 | datatype: string 320 | priority: 16 321 | owner: 322 | default_value: "/Infrastructure/VM/Retirement/Email/vm_retirement_emails?event=vm_retired" 323 | substitute: true 324 | message: create 325 | visibility: 326 | collect: 327 | scope: 328 | description: 329 | condition: 330 | on_entry: update_retirement_status(status => 'Emailing VM Owner') 331 | on_exit: update_retirement_status(status => 'Emailed VM Owner') 332 | on_error: update_retirement_status(status => 'Error Emailing VM Owner') 333 | max_retries: '100' 334 | max_time: 335 | - field: 336 | aetype: state 337 | name: DeleteFromVMDB 338 | display_name: 339 | datatype: string 340 | priority: 17 341 | owner: 342 | default_value: "#/Infrastructure/VM/Retirement/StateMachines/Methods/DeleteFromVMDB" 343 | substitute: true 344 | message: create 345 | visibility: 346 | collect: 347 | scope: 348 | description: 349 | condition: 350 | on_entry: '' 351 | on_exit: '' 352 | on_error: '' 353 | max_retries: '100' 354 | max_time: 355 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Hybrid Cloud Automated Provisioning Realized with Red Hat CloudForms 2 | 3 | 4 | ## (Outline and Documentation Links) 5 | 6 | 7 | # Abstract: 8 | 9 | If you follow the below steps on greed field, configured, Red Hat CloudForms appliance(s), Hybrid Cloud Provisioning with Infrastructure Providers (RHEV, vCenter), Cloud Providers (AWS), a Configuration Management Provider (Satellite) and an Automation Provider (Ansible Tower) becomes a reality. Simply follow the steps listed below and "it just works". 10 | 11 | 12 | # Assumptions: 13 | 14 | 15 | 16 | * Red Hat CloudForms 4.5/4.6 up and running… 17 | * Red Hat Satellite 6 configured… 18 | * Ansible Tower setup (for post install configuration)... 19 | * Cloud/Infra Providers and networking are in place. 20 | 21 | 22 | # Additional Requirements: 23 | 24 | 25 | 26 | * Each user, including the admin user, making provisioning requests must have an email address configured. Provisioning requests will fail if initiated by any user without a configured email address. The [General Configuration](https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.5/html/general_configuration/configuration) document explains the process of creating users and editing users. 27 | 28 | 29 | # Configure Providers: 30 | 31 | 32 | 33 | * Add Infrastructure, Cloud, Configuration and Automation Providers as prescribed in [Managing Providers](https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.5/html/managing_providers) 34 | 35 | 36 | ## Connect Infrastructure Providers: 37 | 38 | 39 | 40 | * Connect VMware vCenter 41 | * Connect RHEV 42 | 43 | 44 | ## Connect Cloud Providers: 45 | 46 | 47 | 48 | * Connect AWS Provider 49 | 50 | 51 | ## Add Configuration Management Provider: 52 | 53 | 54 | 55 | * Add Red Hat Satellite Provider 56 | 57 | 58 | ## Connect Automation Provider: 59 | 60 | 61 | 62 | * Connect Ansible Tower Provider 63 | 64 | 65 | # General Configuration: 66 | 67 | 68 | 69 | * The Git Repositories Owner Role is disabled by default on a newly installed CloudForms appliance. This role will need to be enabled in order to import the upstream Automate Domains. Follow the guidelines in [General Configuration](https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.5/html/general_configuration/configuration) in order to complete these steps. 70 | 71 | 72 | ## Enable and configure Git Repositories Owner Server Role: 73 | * Enable 'Git Repositories Owner' Server Role 74 | * Promote 'Git Repositories Owner' Role to Primary if necessary 75 | * Start the 'Git Repositories Role' if necessary 76 | 77 | 78 | # Automate Domains: 79 | 80 | 81 | ## Configuration Domain: 82 | 83 | 84 | 85 | * [Understanding the Automate Model - Creating a Domain](https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.5/html/scripting_actions_in_cloudforms/understanding-the-automate-model#creating-a-domain) covers the steps required to create a domain within the Automate model. The recommendation is to create a domain with a name of Configuration but the name of the domain is inconsequential. The ordering of the domains is important and that will be covered later in this document. 86 | 87 | ### Create Configuration Domain: 88 | 89 | * Create Configuration Domain and Enable 90 | 91 | ### Network Configuration: 92 | 93 | * Override RedHatConsulting_Utilities/Infrastructure/Network/Configuration by copying the instance into your new configuration domain. 94 | * Add a new instance for each provisioning and destination VLAN 95 | * I.e. 96 | * Name: ovirtmgmt 97 | * (network purpose): [provisioning, destination] 98 | * (network_address_space): 10.10.10.0/24 99 | * (network_gateway): 10.10.10.1 100 | * (network_nameservers: [10.10.10.2,10.10.10.3] 101 | * (network_ddi_provider): satellite 102 | 103 | ### Email Configuration: 104 | 105 | * In order to modify the from email address, override each of the following and change from_email_address value: 106 | * Copy the following instances into your Configuration domain from RedHatConsulting_Utilities/Infrastructure/VM/Provisioning/Email 107 | * MiqProvision_Complete 108 | * MiqProvision_Update 109 | * MiqProvisionRequest_Approved 110 | * MiqProvisionRequest_Denied 111 | * MiqProvisionRequest_Pending 112 | * Copy the following instance into your Configuration domain from RedHatConsulting_Utilities/Infrastructure/VM/Retirement/Email 113 | * Vm_retirement_emails 114 | * In order to stop Reconfigure notifications, override and blank all values in the following Instances 115 | * Copy the following into your Configuration domain 116 | * ManageIQ/Infrastructure/VM/Reconfigure/Email/VmReconfigureRequestApproved 117 | * Copy the following instance into your Configuration domain 118 | * ManageIQ/Infrastructure/VM/Reconfigure/Email/VmReconfigureTaskComplete 119 | 120 | 121 | ## Import Upstream Domains: 122 | 123 | 124 | 125 | * [Understanding the Automate Model - Importing a Domain](https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.5/html/scripting_actions_in_cloudforms/understanding-the-automate-model#importing-a-domain) explains how to import the required Automate domains. The relevant repositories with links are included below. In order to control release, you may want to choose a specific branch or tag. 126 | 127 | ### Import Automate Domains from RedHatOfficial Github: 128 | 129 | * Import miq-RedHat-Satellite6 130 | * [https://github.com/RedHatOfficial/miq-RedHat-Satellite6.git](https://github.com/RedHatOfficial/miq-RedHat-Satellite6.git) 131 | * Import miq-Utilities 132 | * [https://github.com/RedHatOfficial/miq-Utilities.git](https://github.com/RedHatOfficial/miq-Utilities.git) 133 | 134 | 135 | ## Automate Domain Priority: 136 | 137 | * [Understanding the Automate Model - Changing Priority Order of Domains](https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.5/html/scripting_actions_in_cloudforms/understanding-the-automate-model#changing-priority-order-of-domains) explains the process required in order to properly configure the priority of Automate Domains. The following is the necessary priority required for this configuration. 138 | 139 | ### Configure Automate Domain Priority: 140 | 141 | * Configuration 142 | * RedHatConsulting_Satellite6 143 | * RedHatConsulting_Utilities 144 | 145 | # Service Dialogs and Catalogs: 146 | 147 | * A pre-configured catalog and associated service dialog are provided as part of the miq-RedHat-Satellite6 project on Github. Complete the following steps to import these items. 148 | 149 | 150 | ## Install cfme-rhconsulting-scripts per instructions: 151 | 152 | 153 | 154 | * [https://github.com/rhtconsulting/cfme-rhconsulting-scripts#install](https://github.com/rhtconsulting/cfme-rhconsulting-scripts#install) 155 | 156 | 157 | ## Import Service Dialog and Catalog Items: 158 | 159 | 160 | 161 | * Clone miq-RedHat-Satellite6 repository 162 | * `git clone https://github.com/RedHatOfficial/miq-RedHat-Satellite6.git` 163 | * Import Service Dialog 164 | * `miqimport service_dialogs miq-RedHat-Satellite6/Dialogs/` 165 | * Import Catalog 166 | * `miqimport service_catalogs miq-RedHat-Satellite6/Catalogs/` 167 | 168 | 169 | # Tagging: 170 | 171 | 172 | ## Tag Categories: 173 | 174 | 175 | ### Environment Tag Category 176 | 177 | * Delete environment Tag Category 178 | * Recreate environment Tag Category 179 | * Name: environment 180 | * Description: Environment 181 | * Long Description: Environment 182 | * Show in Console: Yes 183 | * Single Value: No 184 | 185 | ### Operating System Tag Category 186 | 187 | * Create os Tag Category 188 | * Name: os 189 | * Description: Operating System 190 | * Long Description: Operating System 191 | * Show in Console: Yes 192 | * Single Value: Yes 193 | 194 | ## Tags: 195 | 196 | 197 | 198 | * In order to auto-populate some of the tags, you can simply open the service dialog at this point. Once the dialog has opened, simply close the dialog and continue with tagging. This will create the appropriate environment and location tags based on your Satellite configuration. 199 | 200 | ### Operating System Tags: 201 | 202 | * Create Tag for each Operating System Supported 203 | * i.e. name: rhel6, description: RHEL 6 204 | * i.e. name: rhel7, description: RHEL 7 205 | 206 | ### Infrastructure Provider Tags: 207 | 208 | * Infrastructure Providers require a multitude of tags based on your organization's configuration and design. The providers being used for automated provisioning need the following tags applied appropriate to your organization's goals. 209 | * Location Tags 210 | * Tag each Provider with appropriate location tag 211 | * Environment Tags 212 | * Tag each Provider with appropriate environment tag(s) 213 | * Provisioning Scope: All 214 | * Tag Hosts as appropriate 215 | * Tag Datastores as appropriate 216 | * Tag Templates 217 | * Navigate to Compute / Infrastructure / Virtual Machines 218 | * Select Templates 219 | * Select the template(s) to be tagged 220 | * Select Policy / Edit Tags 221 | * Apply appropriate Operating System Tag 222 | * Save 223 | 224 | 225 | ### Cloud Provider Tags: 226 | 227 | 228 | 229 | * The following example lists the steps necessary to tag and utilize a public image. 230 | * Tagging of AWS Images 231 | * Public_images_filters (Advanced Settings) 232 | * If you wanted to download public images and filter the images downloaded, you could make the following modifications to your Advanced Settings of your appliance(s). This example limits public images to the current RHEL 7 image. 233 | * Change 234 | 235 | :ec2: 236 | :get_public_images: false 237 | :public_images_filters: 238 | - :name: image-type 239 | :values: 240 | - machine 241 | 242 | * To 243 | 244 | :ec2: 245 | :get_public_images: true 246 | :public_images_filters: 247 | - :name: image-id 248 | :values: 249 | - ami-6871a115 250 | 251 | 252 | * Tag the Image 253 | * Navigate to Compute / Clouds / Instances / Images by Provider 254 | * Select the image(s) to be tagged 255 | * Select Policy / Edit Tags 256 | * Apply appropriate Operating System Tag 257 | * Save 258 | 259 | 260 | # The Proof is in the Pudding… 261 | 262 | 263 | 264 | * Now is the time to test your configuration. Ensure you have your logs open in case of configuration errors. 265 | * Open the Service Dialog 266 | * If any script errors exist, refer to logs to determine the issue 267 | * Populate the Dialog 268 | * The lower portion of the form will change as entries are populated. Use this box to verify your selections. 269 | * Submit the Order 270 | * Watch the Requests and the Logs 271 | * Rejoice as you see your Hybrid Cloud Automated Provisioning Realized 272 | * Do a little dance 273 | * Tell all of your friends 274 | * Get involved! 275 | * Submit issues against the upstream projects 276 | * Pull Requests 277 | * Pull Requests 278 | * Pull Requests 279 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Cloud/VM/Retirement/StateMachines/VMRetirement.class/__class__.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | object_type: class 3 | version: 1.0 4 | object: 5 | attributes: 6 | description: VMRetirement 7 | display_name: 8 | name: VMRetirement 9 | type: 10 | inherits: 11 | visibility: 12 | owner: 13 | schema: 14 | - field: 15 | aetype: state 16 | name: StartRetirement 17 | display_name: 18 | datatype: string 19 | priority: 1 20 | owner: 21 | default_value: "/Cloud/VM/Retirement/StateMachines/Methods/StartRetirement" 22 | substitute: true 23 | message: create 24 | visibility: 25 | collect: 26 | scope: 27 | description: 28 | condition: 29 | on_entry: update_retirement_status(status => 'Starting Retirement') 30 | on_exit: update_retirement_status(status => 'Started Retirement') 31 | on_error: update_retirement_status(status => 'Error Starting Retirement') 32 | max_retries: '100' 33 | max_time: 34 | - field: 35 | aetype: state 36 | name: PreRetirement 37 | display_name: 38 | datatype: string 39 | priority: 2 40 | owner: 41 | default_value: "/Cloud/VM/Retirement/StateMachines/Methods/PreRetirement#${/#vm.vendor}" 42 | substitute: true 43 | message: create 44 | visibility: 45 | collect: 46 | scope: 47 | description: 48 | condition: 49 | on_entry: update_retirement_status(status => 'PreRetirement') 50 | on_exit: update_retirement_status(status => 'PreRetirement Successful') 51 | on_error: update_retirement_status(status => 'Error in PreRetirement') 52 | max_retries: '100' 53 | max_time: 54 | - field: 55 | aetype: state 56 | name: CheckPreRetirement 57 | display_name: 58 | datatype: string 59 | priority: 3 60 | owner: 61 | default_value: "/Cloud/VM/Retirement/StateMachines/Methods/CheckPreRetirement#${/#vm.vendor}" 62 | substitute: true 63 | message: create 64 | visibility: 65 | collect: 66 | scope: 67 | description: 68 | condition: 69 | on_entry: update_retirement_status(status => 'Check PreRetirement') 70 | on_exit: update_retirement_status(status => 'CheckPreRetirement successful') 71 | on_error: update_retirement_status(status => 'Error in CheckPreRetirement') 72 | max_retries: '100' 73 | max_time: 74 | - field: 75 | aetype: state 76 | name: DeactivateCMDB 77 | display_name: 78 | datatype: string 79 | priority: 4 80 | owner: 81 | default_value: 82 | substitute: true 83 | message: create 84 | visibility: 85 | collect: 86 | scope: 87 | description: 88 | condition: 89 | on_entry: update_retirement_status(status => 'Deactivating from CMDB') 90 | on_exit: update_retirement_status(status => 'Deactivated from CMDB') 91 | on_error: update_retirement_status(status => 'Error Deactivating from CMDB') 92 | max_retries: '100' 93 | max_time: 94 | - field: 95 | aetype: state 96 | name: UnregisterAD 97 | display_name: 98 | datatype: string 99 | priority: 5 100 | owner: 101 | default_value: 102 | substitute: true 103 | message: create 104 | visibility: 105 | collect: 106 | scope: 107 | description: 108 | condition: 109 | on_entry: update_retirement_status(status => 'Unregistering from AD') 110 | on_exit: update_retirement_status(status => 'Unregistered from AD') 111 | on_error: update_retirement_status(status => 'Error Unregistering from AD') 112 | max_retries: '100' 113 | max_time: 114 | - field: 115 | aetype: state 116 | name: UnregisterDHCP 117 | display_name: 118 | datatype: string 119 | priority: 6 120 | owner: 121 | default_value: 122 | substitute: true 123 | message: create 124 | visibility: 125 | collect: 126 | scope: 127 | description: 128 | condition: 129 | on_entry: update_retirement_status(status => 'Unregistering from DHCP') 130 | on_exit: update_retirement_status(status => 'Unregistered from DHCP') 131 | on_error: update_retirement_status(status => 'Error Unregistering from DHCP') 132 | max_retries: '100' 133 | max_time: 134 | - field: 135 | aetype: state 136 | name: UnregisterDNS 137 | display_name: 138 | datatype: string 139 | priority: 7 140 | owner: 141 | default_value: 142 | substitute: true 143 | message: create 144 | visibility: 145 | collect: 146 | scope: 147 | description: 148 | condition: 149 | on_entry: update_retirement_status(status => 'Unregistering from DNS') 150 | on_exit: update_retirement_status(status => 'Unregistered from DNS') 151 | on_error: update_retirement_status(status => 'Error Unregistering from DNS') 152 | max_retries: '100' 153 | max_time: 154 | - field: 155 | aetype: state 156 | name: ReleaseMACAddress 157 | display_name: 158 | datatype: string 159 | priority: 8 160 | owner: 161 | default_value: 162 | substitute: true 163 | message: create 164 | visibility: 165 | collect: 166 | scope: 167 | description: 168 | condition: 169 | on_entry: update_retirement_status(status => 'Releasing MAC Address') 170 | on_exit: update_retirement_status(status => 'Released MAC Address') 171 | on_error: update_retirement_status(status => 'Error Releasing MAC Address') 172 | max_retries: '100' 173 | max_time: 174 | - field: 175 | aetype: state 176 | name: PreDeleteFromProvider 177 | display_name: 178 | datatype: string 179 | priority: 9 180 | owner: 181 | default_value: "#/Cloud/VM/Retirement/StateMachines/Methods/PreDeleteFromProvider" 182 | substitute: true 183 | message: create 184 | visibility: 185 | collect: 186 | scope: 187 | description: 188 | condition: 189 | on_entry: update_retirement_status(status => 'Executing PreDelete from Provider') 190 | on_exit: update_retirement_status(status => 'Executed PreDelete from Provider') 191 | on_error: update_retirement_status(status => 'Error Executing PreDelete from 192 | Provider') 193 | max_retries: '100' 194 | max_time: 195 | - field: 196 | aetype: state 197 | name: ReleaseIPAddress 198 | display_name: 199 | datatype: string 200 | priority: 10 201 | owner: 202 | default_value: 203 | substitute: true 204 | message: create 205 | visibility: 206 | collect: 207 | scope: 208 | description: 209 | condition: 210 | on_entry: update_retirement_status(status => 'Releasing IP Address') 211 | on_exit: update_retirement_status(status => 'Released IP Address') 212 | on_error: update_retirement_status(status => 'Error Releasing IP Address') 213 | max_retries: '100' 214 | max_time: 215 | - field: 216 | aetype: state 217 | name: RemoveFromProvider 218 | display_name: 219 | datatype: string 220 | priority: 11 221 | owner: 222 | default_value: "/Cloud/VM/Retirement/StateMachines/Methods/RemoveFromProvider" 223 | substitute: true 224 | message: create 225 | visibility: 226 | collect: 227 | scope: 228 | description: 229 | condition: 230 | on_entry: update_retirement_status(status => 'Removing from Provider') 231 | on_exit: update_retirement_status(status => 'Removed from Provider') 232 | on_error: update_retirement_status(status => 'Error Removing from Provider') 233 | max_retries: '100' 234 | max_time: 235 | - field: 236 | aetype: state 237 | name: UnregisterSatellite 238 | display_name: 239 | datatype: string 240 | priority: 12 241 | owner: 242 | default_value: "/Integration/Satellite/Operations/Methods/UnregisterSatellite" 243 | substitute: true 244 | message: create 245 | visibility: 246 | collect: 247 | scope: 248 | description: 249 | condition: 250 | on_entry: update_retirement_status(status => 'Unregistering from Satellite'') 251 | on_exit: update_retirement_status(status => 'Unregistered from Satellite'') 252 | on_error: update_retirement_status(status => 'Failed Unregistering from Satellite'') 253 | max_retries: 254 | max_time: 255 | - field: 256 | aetype: state 257 | name: PreDeleteEmailOwner 258 | display_name: 259 | datatype: string 260 | priority: 13 261 | owner: 262 | default_value: "#/Cloud/VM/Retirement/Email/vm_retirement_emails?event=vm_entered_retirement" 263 | substitute: true 264 | message: create 265 | visibility: 266 | collect: 267 | scope: 268 | description: 269 | condition: 270 | on_entry: update_retirement_status(status => 'Notifying VM Owner') 271 | on_exit: update_retirement_status(status => 'Notified VM Owner') 272 | on_error: update_retirement_status(status => 'Error Notifying VM Owner') 273 | max_retries: '100' 274 | max_time: 275 | - field: 276 | aetype: state 277 | name: EmailOwner 278 | display_name: 279 | datatype: string 280 | priority: 14 281 | owner: 282 | default_value: "/Cloud/VM/Retirement/Email/vm_retirement_emails?event=vm_retired" 283 | substitute: true 284 | message: create 285 | visibility: 286 | collect: 287 | scope: 288 | description: 289 | condition: 290 | on_entry: update_retirement_status(status => 'Emailing VM Owner') 291 | on_exit: update_retirement_status(status => 'Emailed VM Owner') 292 | on_error: update_retirement_status(status => 'Error Emailing VM Owner') 293 | max_retries: '100' 294 | max_time: 295 | - field: 296 | aetype: state 297 | name: CheckRemovedFromProvider 298 | display_name: 299 | datatype: string 300 | priority: 15 301 | owner: 302 | default_value: "/Cloud/VM/Retirement/StateMachines/Methods/CheckRemovedFromProvider" 303 | substitute: true 304 | message: create 305 | visibility: 306 | collect: 307 | scope: 308 | description: 309 | condition: 310 | on_entry: update_retirement_status(status => 'Checking Removal from Provider') 311 | on_exit: update_retirement_status(status => 'Checked Removal from Provider') 312 | on_error: update_retirement_status(status => 'Error Checking Removal from Provider') 313 | max_retries: '100' 314 | max_time: 315 | - field: 316 | aetype: state 317 | name: FinishRetirement 318 | display_name: 319 | datatype: string 320 | priority: 16 321 | owner: 322 | default_value: "/Cloud/VM/Retirement/StateMachines/Methods/FinishRetirement" 323 | substitute: true 324 | message: create 325 | visibility: 326 | collect: 327 | scope: 328 | description: 329 | condition: 330 | on_entry: update_retirement_status(status => 'Finishing Retirement') 331 | on_exit: update_retirement_status(status => 'Finished Retirement') 332 | on_error: update_retirement_status(status => 'Error Finishing Retirement') 333 | max_retries: '100' 334 | max_time: 335 | - field: 336 | aetype: state 337 | name: DeleteFromVMDB 338 | display_name: 339 | datatype: string 340 | priority: 17 341 | owner: 342 | default_value: "#/Cloud/VM/Retirement/StateMachines/Methods/DeleteFromVMDB" 343 | substitute: true 344 | message: create 345 | visibility: 346 | collect: 347 | scope: 348 | description: 349 | condition: 350 | on_entry: update_retirement_status(status => 'Removing from VMDB') 351 | on_exit: update_retirement_status(status => 'Removed from VMDB') 352 | on_error: update_retirement_status(status => 'Error Removing from VMDB') 353 | max_retries: '100' 354 | max_time: 355 | -------------------------------------------------------------------------------- /Automate/RedHatConsulting_Satellite6/Integration/Satellite/DynamicDialogs.class/__methods__/get_templates_based_on_selected_os_and_location_and_environment.rb: -------------------------------------------------------------------------------- 1 | # Creates a dialog element with a yaml dump of information about a valid template for each 2 | # selected destination location for the selected OS version and Environment. 3 | # 4 | # Parameters 5 | # dialog_os_tag 6 | # dialog_location_tags 7 | # dialog_satellite_environment_name or dialog_satellite_environment_id 8 | 9 | require 'yaml' 10 | require 'apipie-bindings' 11 | 12 | module RedHatConsulting_Satellite6 13 | module Automate 14 | module Integration 15 | module Satellite 16 | module DynamicDialogs 17 | class GetTemplatesBasedOnSelectedOsAndLocationAndEnvironment 18 | include RedHatConsulting_Utilities::StdLib::Core 19 | 20 | SATELLITE_CONFIG_URI = 'Integration/Satellite/Configuration/default' 21 | OS_TAG_DIALOG_OPTION = 'dialog_os_tag' 22 | LOCATION_TAGS_DIALOG_OPTION = 'dialog_location_tags' 23 | ENVIRONMENT_NAME_DIALOG_OPTION = 'dialog_satellite_environment_name' 24 | ENVIRONMENT_ID_DIALOG_OPTION = 'dialog_satellite_environment_id' 25 | ENVIRONMENT_TAG_CATEGORY = 'environment' 26 | 27 | def initialize(handle = $evm) 28 | @handle = handle 29 | @DEBUG = false 30 | end 31 | 32 | def main 33 | dump_root() if @DEBUG 34 | 35 | # If there isn't a vmdb_object_type yet just exit. The method will be recalled with an vmdb_object_type 36 | exit MIQ_OK unless @handle.root['vmdb_object_type'] 37 | 38 | # get parameters 39 | os_tag = @handle.root[OS_TAG_DIALOG_OPTION] 40 | location_tags = @handle.root[LOCATION_TAGS_DIALOG_OPTION] || [] 41 | environment_name = get_environment_name() 42 | log(:info, "os_tag => #{os_tag}") if @DEBUG 43 | log(:info, "location_tags => #{location_tags}") if @DEBUG 44 | log(:info, "environment_tag_name => #{environment_tag_name}") if @DEBUG 45 | 46 | invalid_selection = false 47 | value = [] 48 | 49 | # invalid if no os template tag(s) selected 50 | if os_tag.blank? 51 | invalid_selection = true 52 | value << "OS must be selected to determine valid destination providers." 53 | end 54 | 55 | # invalid if no environment is selected 56 | if environment_name.blank? 57 | invalid_selection = true 58 | value << "Environment must be selected to determine valid destination providers." 59 | else 60 | environment_tag_name = "#{ENVIRONMENT_TAG_CATEGORY}/#{to_tag_name(environment_name)}" 61 | log(:info, "environment_tag_name => #{environment_tag_name}") if @DEBUG 62 | end 63 | 64 | # invalid if no location tags selected 65 | location_tags.delete("null") 66 | location_tags.delete("[]") 67 | if location_tags.empty? 68 | invalid_selection = true 69 | value << "Destination location(s) must be selected to determine valid destination providers." 70 | end 71 | 72 | # find appropriatlly tagged providers 73 | providers_by_tag = {} 74 | if !invalid_selection 75 | environment_tag_path = "/managed/#{environment_tag_name}" 76 | environment_tag = @handle.vmdb(:classification).find_by_name(environment_tag_name) 77 | log(:info, "environment_tag_name => '#{environment_tag_name}', tag => #{environment_tag}") if @DEBUG 78 | 79 | environment_tagged_providers = @handle.vmdb(:ext_management_system).find_tagged_with(:all => environment_tag_path, :ns => "*") 80 | if environment_tagged_providers.empty? 81 | invalid_selection = true 82 | value << "Could Not Find Destination Provider with Tags <#{environment_tag.parent.description}: #{environment_tag.description}>." unless environment_tag.blank? 83 | value << "Invalid environment Tag provided: <#{environment_tag_name}>" if environment_tag.blank? 84 | end 85 | 86 | if @DEBUG 87 | log(:info, "There are [#{environment_tagged_providers.length}] provider(s) tagged with #{environment_tag_name}:") 88 | environment_tagged_providers.each do |provider| 89 | log(:info, "\tProvider tagged with #{environment_tag_name}: #{provider.name}") 90 | end 91 | end 92 | 93 | end 94 | 95 | if !invalid_selection 96 | location_tags.each do |location_tag_name| 97 | location_tag_path = "/managed/#{location_tag_name}" 98 | log(:info, "location_tag_path => #{location_tag_path}") if @DEBUG 99 | 100 | location_tagged_providers = @handle.vmdb(:ext_management_system).find_tagged_with(:all => location_tag_path, :ns => "*") 101 | 102 | if @DEBUG 103 | log(:info, "There are [#{location_tagged_providers.length}] provider(s) tagged with #{location_tag_name}:") 104 | location_tagged_providers.each do |provider| 105 | log(:info, "\tProvider tagged with #{location_tag_name}: #{provider.name}") 106 | end 107 | end 108 | 109 | # get intersection of providers with location tag and providers with environment tag 110 | tagged_providers = location_tagged_providers.reject { |provider| !provider.tagged_with?(ENVIRONMENT_TAG_CATEGORY, to_tag_name(environment_name)) } 111 | 112 | if @DEBUG 113 | log(:info, "There are [#{tagged_providers.length}] provider(s) tagged with both #{location_tag_name} and #{environment_tag_name}:") 114 | tagged_providers.each do |provider| 115 | log(:info, "\tProvider location and environment: #{provider.name}") 116 | end 117 | end 118 | 119 | 120 | if tagged_providers.empty? 121 | location_tag = @handle.vmdb(:classification).find_by_name(location_tag_name) 122 | log(:info, "location_tag_name => '#{location_tag_name}', tag => #{location_tag}") if @DEBUG 123 | invalid_selection = true 124 | value << "Could not find Provider with Tags <#{location_tag.parent.description}: #{location_tag.description}>" unless location_tag.blank? 125 | value << "Invalid location Tag provided: <#{location_tag_name}>" if location_tag.blank? 126 | else 127 | providers_by_tag[location_tag_name] = tagged_providers 128 | end 129 | end 130 | log(:info, "providers_by_tag => #{providers_by_tag}") if @DEBUG 131 | end 132 | 133 | if !invalid_selection 134 | # ensure there are templates tagged with the correct OS 135 | tagged_templates = @handle.vmdb(:VmOrTemplate).find_tagged_with(:all => "/managed/#{os_tag}", :ns => "*") 136 | tagged_templates.select! { |tagged_template| tagged_template.template } 137 | log(:info, "tagged_templates => #{tagged_templates}") if @DEBUG 138 | if tagged_templates.empty? 139 | template_tag = @handle.vmdb(:classification).find_by_name(os_tag) 140 | invalid_selection = true 141 | value << "Could not find any Templates with Tag <#{template_tag.parent.description}: #{template_tag.description}>" 142 | end 143 | 144 | # sort templates tagged with the correct OS by the correctly tagged provider they line up with 145 | templates_by_provider_tag = {} 146 | tagged_templates.each do |tagged_template| 147 | template_provider = tagged_template.ext_management_system 148 | providers_by_tag.each do |location_tag_name, providers| 149 | if providers.collect {|provider| provider.id}.include?(template_provider.id) 150 | templates_by_provider_tag[location_tag_name] ||= [] 151 | templates_by_provider_tag[location_tag_name] << tagged_template 152 | end 153 | end 154 | end 155 | log(:info, "templates_by_provider_tag => #{templates_by_provider_tag}") if @DEBUG 156 | 157 | # determine the selected templates 158 | selected_templates = [] 159 | location_tags.each do |location_tag_name| 160 | provider_tag = @handle.vmdb(:classification).find_by_name(location_tag_name) 161 | template_tag = @handle.vmdb(:classification).find_by_name(os_tag) 162 | if templates_by_provider_tag[location_tag_name].blank? 163 | invalid_selection = true 164 | value << "Could not find Template with Tag <#{template_tag.parent.description}: #{template_tag.description}> on a Provider with Tag <#{provider_tag.parent.description}: #{provider_tag.description}>" 165 | else 166 | # NOTE: just choose the first valid one and warn if there was more then one valid selection 167 | selected_templates << templates_by_provider_tag[location_tag_name].first 168 | log(:warn, "More then one valid Template available with Tag <#{template_tag.parent.description}: #{template_tag.description}> " + 169 | "on a Provider with Tag <#{provider_tag.parent.description}: #{provider_tag.description}>") if templates_by_provider_tag[location_tag_name].length > 1 170 | end 171 | end 172 | end 173 | 174 | # if invalid selection prepend a note as such 175 | # else valid selection, list selected providers 176 | if invalid_selection 177 | value.map! { |v| " * #{v}" } 178 | value.unshift('INVALID SELECTION') 179 | value = value.join("\n") 180 | else 181 | value = [] 182 | selected_templates.each do |selected_template| 183 | # add the provider options 184 | value << { 185 | :provider => selected_template.ext_management_system.name, 186 | :name => selected_template.name, 187 | :guid => selected_template.guid 188 | } 189 | end 190 | value = value.to_yaml 191 | end 192 | 193 | # create dialog element 194 | dialog_field = @handle.object 195 | dialog_field["data_type"] = "string" 196 | dialog_field['read_only'] = true 197 | dialog_field['value'] = value 198 | log(:info, "value => #{value}") if @DEBUG 199 | end 200 | 201 | 202 | # Takes a string and makes it a valid tag name 203 | # 204 | # @param str String to turn into a valid Tag name 205 | # 206 | # @return Given string transformed into a valid Tag name 207 | def to_tag_name(str) 208 | return str.downcase.gsub(/[^a-z0-9_]+/,'_') 209 | end 210 | 211 | def get_environment_name() 212 | # determine environment 213 | satellite_environment_name = @handle.root[ENVIRONMENT_NAME_DIALOG_OPTION] 214 | satellite_environment_id = @handle.root[ENVIRONMENT_ID_DIALOG_OPTION] 215 | # return nil if the dialog elements have not been selected yet 216 | return nil if satellite_environment_name.blank? and satellite_environment_id.blank? 217 | return nil if satellite_environment_name == '!' or satellite_environment_id == '!' 218 | 219 | # if the satellite enviornment name is actually an ID 220 | # else if satellite envirnonment name not given check for satellite environment id 221 | if satellite_environment_name =~ /^[0-9]+$/ 222 | satellite_environment_id = satellite_environment_name.to_i 223 | end 224 | 225 | if !satellite_environment_id.blank? 226 | log(:info, "satellite_environment_id => #{satellite_environment_id}") if @DEBUG 227 | satellite_api = get_satellite_api() 228 | begin 229 | satellite_environment = satellite_api.resource(:lifecycle_environments).call(:show, {:id => satellite_environment_id}) 230 | satellite_environment_name = satellite_environment['name'] 231 | rescue => e 232 | error("Error invoking Satellite API: #{e.to_s}") 233 | end 234 | end 235 | log(:error, "One of must be specified.") if satellite_environment_name.blank? 236 | return satellite_environment_name 237 | end 238 | 239 | def get_satellite_api() 240 | satellite_config = $evm.instantiate(SATELLITE_CONFIG_URI) 241 | error("Satellite Configuration not found") if satellite_config.nil? 242 | 243 | satellite_server = satellite_config['satellite_server'] 244 | satellite_username = satellite_config['satellite_username'] 245 | satellite_password = satellite_config.decrypt('satellite_password') 246 | 247 | log(:info, "satellite_server = #{satellite_server}") if @DEBUG 248 | log(:info, "satellite_username = #{satellite_username}") if @DEBUG 249 | 250 | error("Satellite Server configuration not found") if satellite_server.nil? 251 | error("Satellite User configuration not found") if satellite_username.nil? 252 | error("Satellite Password configuration not found") if satellite_password.nil? 253 | 254 | satellite_api = ApipieBindings::API.new({:uri => satellite_server, :username => satellite_username, :password => satellite_password, :api_version => 2, :apidoc_cache_dir => "/tmp/foreman" }, {:verify_ssl => false}) 255 | log(:info, "satellite_api = #{satellite_api}") if @DEBUG 256 | return satellite_api 257 | end 258 | 259 | end 260 | end 261 | end 262 | end 263 | end 264 | end 265 | 266 | if __FILE__ == $PROGRAM_NAME 267 | RedHatConsulting_Satellite6::Automate::Integration::Satellite::DynamicDialogs::GetTemplatesBasedOnSelectedOsAndLocationAndEnvironment.new.main 268 | end 269 | --------------------------------------------------------------------------------