-
Notifications
You must be signed in to change notification settings - Fork 7
/
miq-db-init
executable file
·70 lines (51 loc) · 3.93 KB
/
miq-db-init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
system('swi-pg-run')
# Load Rails
ENV['RAILS_ENV'] = ARGV[0] || 'development'
MIQ_DIR = ENV["HOME"] + '/utery/manageiq'
require MIQ_DIR + '/config/environment'
$id = 0
def ems_ref
"whatever-#{$id += 1}"
end
ActiveRecord::Base.transaction do
all_tables = [NetworkRouter, CloudSubnet, ManageIQ::Providers::Openstack::CloudManager::Flavor, ManageIQ::Providers::Openstack::CloudManager::CloudVolumeBackup,
ManageIQ::Providers::Openstack::CloudManager::CloudVolume, ManageIQ::Providers::Openstack::CloudManager::AvailabilityZone, ManageIQ::Providers::Openstack::CloudManager::Vm,
Service, ServiceTemplateCatalog, ManageIQ::Providers::Openstack::NetworkManager::CloudNetwork, ManageIQ::Providers::Openstack::CloudManager::CloudTenant,
ManageIQ::Providers::Openstack::CloudManager]
all_tables.each do |table|
table.destroy_all
puts("Deleted: " + table.name)
end
# cloud provider
ems = ManageIQ::Providers::Openstack::CloudManager.create!(:name => "Openstack cloud", :hostname => '127.0.0.1', :zone_id => MiqServer.my_server.zone.id)
ems_network = ManageIQ::Providers::Openstack::NetworkManager.last
# cloud tenant
cloud_tenant = ManageIQ::Providers::Openstack::CloudManager::CloudTenant.create!(:name => "cloud tenant", :ems_id => ems_network.id, :ems_ref => ems_ref)
cloud_tenant_two = ManageIQ::Providers::Openstack::CloudManager::CloudTenant.create!(:name => "cloud tenant two", :ems_id => ems.id, :ems_ref => ems_ref)
# cloud network
cloud_network = ManageIQ::Providers::Openstack::NetworkManager::CloudNetwork.create!(:name => 'cloud network', :ems_id => ems_network.id, :cloud_tenant_id => cloud_tenant.id, :ems_ref => ems_ref, :external_facing => true)
# create service
user = User.find_by(:name => 'Administrator')
miq_group = MiqGroup.find_by(:description => "EvmGroup-super_administrator")
tenant = Tenant.all.first
service_template = ServiceTemplateCatalog.create!(:name => 'new', :description => 'new one', :tenant_id => tenant.id)
service = Service.create!(:name => 'some-name', :description => 'jojo', :service_template_id => service_template.id , :options => {:dialog=>{"dialog_text_box_1"=>"something"}}, :display => true, :evm_owner_id => user.id, :miq_group_id => miq_group.id, :tenant_id=> tenant.id)
# cloud vm
cloud_vm = ManageIQ::Providers::Openstack::CloudManager::Vm.create!(:ems_id => ems.id, :name => "vm", :vendor => 'openstack', :location => 'file://whatever', :raw_power_state => 'SHUTOFF', :ems_ref => ems_ref, :cloud_tenant_id => cloud_tenant.id)
# availability zone
availability_zone = ManageIQ::Providers::Openstack::CloudManager::AvailabilityZone.create!(:name => 'Zone', :ems_id => ems.id, :ems_ref => ems_ref)
# cloud volume
cloud_volume = ManageIQ::Providers::Openstack::CloudManager::CloudVolume.create!(:name => 'Cloud Volume', :ems_id => ems_network.id, :availability_zone_id => availability_zone.id, :cloud_tenant_id => cloud_tenant.id, :ems_ref => ems_ref)
# cloud volume backup
cloud_volume_backup = ManageIQ::Providers::Openstack::CloudManager::CloudVolumeBackup.create!(:ems_id => ems_network.id, :name => 'Cloud Volume Backup', :cloud_volume_id => cloud_volume.id, :availability_zone_id => availability_zone.id, :ems_ref => ems_ref)
# flavor
flavor = ManageIQ::Providers::Openstack::CloudManager::Flavor.create!(:name => 'flavor', :ems_id => ems.id, :enabled => true, :memory => 1048576, :description => 'flavor', :ems_ref => ems_ref)
# subnet for network router
cloud_subnet = CloudSubnet.create(:name => "Subnet", :cloud_network_id => cloud_network.id, :ems_ref => ems_ref)
cloud_subnet_two = CloudSubnet.create(:name => "Subnet Two", :cloud_network_id => cloud_network.id, :ems_ref => ems_ref)
# network router
network_router = NetworkRouter.create(:name => 'Network Router', :ems_ref => ems_ref, :ems_id => ems_network.id, :cloud_network_id => cloud_network.id, :cloud_tenant_id => cloud_tenant_two.id)
end
# done
puts "OK"