Class: Deltacloud::Drivers::Fgcp::FgcpDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Deltacloud::Drivers::Fgcp::FgcpDriver
show all
- Defined in:
- lib/deltacloud/drivers/fgcp/fgcp_driver.rb,
lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
Constant Summary
collapse
- CERT_DIR =
ENV['FGCP_CERT_DIR'] || File::expand_path('~/.deltacloud/drivers/fgcp')
- @@MACHINE_STATE_MAP =
FGCP instance states mapped to CIMI machine states
{
'DEPLOYING' => 'CREATING',
'RUNNING' => 'STARTED',
'STOPPING' => 'STOPPING',
'STOPPED' => 'STOPPED',
'STARTING' => 'STARTING', 'FAILOVER' => 'STARTED',
'UNEXPECTED_STOP' => 'STOPPED',
'RESTORING' => 'RESTORING',
'BACKUP_ING' => 'CAPTURING',
'ERROR' => 'ERROR', 'START_ERROR' => 'STOPPED', 'STOP_ERROR' => 'STARTED', 'REGISTERING' => 'PENDING',
'CHANGE_TYPE' => 'PENDING'
}
Constants inherited
from BaseDriver
BaseDriver::MEMBER_SHOW_METHODS, BaseDriver::STATE_MACHINE_OPTS
Constants included
from Deltacloud
API_VERSION, CIMI_API_VERSION
Instance Method Summary
collapse
-
#addresses(credentials, opts = {}) ⇒ Object
-
#associate_address(credentials, opts = {}) ⇒ Object
-
#attach_storage_volume(credentials, opts = {}) ⇒ Object
-
#configured_providers ⇒ Object
following method enables region drop-down box on GUI.
-
#create_address(credentials, opts = {}) ⇒ Object
allocates (and enables) new ip in specified vsys/network.
-
#create_firewall(credentials, opts = {}) ⇒ Object
-
#create_image(credentials, opts = {}) ⇒ Object
Create a new image from the given instance, with optionally provided name and description.
-
#create_instance(credentials, image_id, opts = {}) ⇒ Object
Create a new instance, given an image id opts can include an optional name for the instance, hardware profile (hwp_id) and realm_id.
-
#create_load_balancer(credentials, opts = {}) ⇒ Object
-
#create_storage_snapshot(credentials, opts = {}) ⇒ Object
-
#create_storage_volume(credentials, opts = {}) ⇒ Object
-
#create_system(credentials, opts = {}) ⇒ Object
-
#delete_firewall(credentials, opts = {}) ⇒ Object
-
#delete_firewall_rule(credentials, opts = {}) ⇒ Object
FW rule creation not supported: fgcp backend requires a mandatory rule id to create (insert) a new rule into the existing accept/deny rules.
-
#destroy_address(credentials, opts = {}) ⇒ Object
-
#destroy_image(credentials, image_id) ⇒ Object
-
#destroy_instance(credentials, id) ⇒ Object
Destroy an instance, given its id.
-
#destroy_load_balancer(credentials, id) ⇒ Object
-
#destroy_storage_snapshot(credentials, opts = {}) ⇒ Object
-
#destroy_storage_volume(credentials, opts = {}) ⇒ Object
-
#destroy_system(credentials, id) ⇒ Object
-
#detach_storage_volume(credentials, opts = {}) ⇒ Object
-
#disassociate_address(credentials, opts = {}) ⇒ Object
-
#firewalls(credentials, opts = {}) ⇒ Object
-
#hardware_profiles(credentials, opts = nil) ⇒ Object
-
#images(credentials, opts = {}) ⇒ Object
-
#instances(credentials, opts = {}) ⇒ Object
-
#load_balancer(credentials, opts = {}) ⇒ Object
-
#load_balancers(credentials, opts = {}) ⇒ Object
-
#metric(credentials, opts = {}) ⇒ Object
-
#metrics(credentials, opts = {}) ⇒ Object
-
#providers(credentials, opts = {}) ⇒ Object
-
#realms(credentials, opts = {}) ⇒ Object
-
#run_on_instance(credentials, opts = {}) ⇒ Object
-
#start_instance(credentials, id) ⇒ Object
Start an instance, given its id.
-
#start_system(credentials, opts = {}) ⇒ Object
-
#stop_instance(credentials, id) ⇒ Object
Stop an instance, given its id.
-
#stop_system(credentials, opts = {}) ⇒ Object
-
#storage_snapshots(credentials, opts = {}) ⇒ Object
-
#storage_volumes(credentials, opts = {}) ⇒ Object
-
#system_addresses(credentials, opts = {}) ⇒ Object
-
#system_forwarding_groups(credentials, opts = {}) ⇒ Object
-
#system_machines(credentials, opts = {}) ⇒ Object
-
#system_networks(credentials, opts = {}) ⇒ Object
-
#system_templates(credentials, opts = {}) ⇒ Object
-
#system_volumes(credentials, opts = {}) ⇒ Object
-
#systems(credentials, opts = {}) ⇒ Object
-
#valid_credentials?(credentials) ⇒ Boolean
Methods inherited from BaseDriver
#address, #api_provider, #blob, #bucket, #catched_exceptions_list, constraints, define_hardware_profile, define_instance_states, driver_name, feature, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #firewall, #hardware_profile, hardware_profiles, #has_capability?, #has_feature?, has_feature?, #image, #instance, #instance_actions_for, instance_state_machine, #instance_state_machine, #key, #name, #realm, #storage_snapshot, #storage_volume, #supported_collections
Methods included from Deltacloud
[], config, configure, connect, database, default_frontend, drivers, enabled_frontends, frontend_required?, frontends, generate_routes, initialize_database, need_database?, new, require_frontend!
#collection_exists?, #collection_names, #collections
Methods included from Exceptions
exception_from_status, exceptions, included, logger, #safely
Instance Method Details
#addresses(credentials, opts = {}) ⇒ Object
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 726
def addresses(credentials, opts={})
addrs_to_instance = {}
ips_per_vsys = {}
safely do
client = new_client(credentials)
opts ||= {}
public_ips = client.list_public_ips(opts[:realm_id])['publicips']
return [] if public_ips.nil? or public_ips[0]['publicip'].nil?
public_ips[0]['publicip'].each do |ip|
if not opts[:id] or opts[:id] == ip['address'][0]
ips_per_vsys[ip['vsysId'][0]] ||= []
ips_per_vsys[ip['vsysId'][0]] << ip['address'][0]
end
end
ips_per_vsys.each_pair do |vsys_id, ips|
begin
fw_id = "#{vsys_id}-S-0001"
nat_rules = client.get_efm_configuration(fw_id, 'FW_NAT_RULE')['efm'][0]['firewall'][0]['nat'][0]['rules'][0]
rescue RuntimeError => ex
raise ex unless ex.message =~ /^(ACCESS_NOT_PERMIT).*/
end
if nat_rules and nat_rules['rule']
associated_ips = {}
nat_rules['rule'].each do |rule|
if opts[:id].nil? or opts[:id] == rule['publicIp'][0] associated_ips[rule['publicIp'][0]] = rule['privateIp'][0] if rule['privateIp']
end
end
vsys = client.get_vsys_configuration(vsys_id)
vsys['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
if determine_server_type(vserver) == 'vserver'
vnic = vserver['vnics'][0]['vnic'][0]
associated_ips.find do |pub,priv|
addrs_to_instance[pub] = vserver['vserverId'][0] if priv == vnic['privateIp'][0]
end if vnic['privateIp']
end
end
if addrs_to_instance.keys.size < associated_ips.keys.size
if slbs = client.list_efm(vsys_id, 'SLB')['efms']
slbs[0]['efm'].find do |slb|
associated_ips.find do |pub,priv|
addrs_to_instance[pub] = slb['efmId'][0] if priv == slb['slbVip'][0]
end
addrs_to_instance.keys.size < associated_ips.keys.size end
end
end
end end end
addresses = []
ips_per_vsys.values.each do |pubs|
addresses += pubs.collect do |pub|
Address.new(:id => pub, :instance_id => addrs_to_instance[pub])
end
end
addresses
end
|
#associate_address(credentials, opts = {}) ⇒ Object
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 882
def associate_address(credentials, opts={})
safely do
client = new_client(credentials)
vsys_id = client.(opts[:instance_id])
begin
client.attach_public_ip(vsys_id, opts[:id])
sleep(8)
rescue Exception => ex
raise ex unless ex.message =~ /^ALREADY_ATTACHED.*/
end
vsys_config = client.get_vsys_configuration(vsys_id)
vserver = vsys_config['vsys'][0]['vservers'][0]['vserver'].find { |e| e['vserverId'][0] == opts[:instance_id] }
case determine_server_type(vserver)
when 'vserver'
private_ip = vserver['vnics'][0]['vnic'][0]['privateIp'][0]
when 'SLB'
if slbs = client.list_efm(vsys_id, 'SLB')['efms']
private_ip = slbs[0]['efm'].find { |slb| slb['slbVip'][0] if slb['efmId'][0] == opts[:instance_id] }
end
end if vserver
fw_id = "#{vsys_id}-S-0001"
nat_rules = client.get_efm_configuration(fw_id, 'FW_NAT_RULE')['efm'][0]['firewall'][0]['nat'][0]['rules'][0]
if nat_rules and not nat_rules.empty? and nat_rules['rule'].find { |rule| rule['publicIp'][0] == opts[:id] }
nat_rules['rule'].each do |rule|
if rule['publicIp'][0] == opts[:id]
rule['privateIp'] = [ private_ip ]
rule['snapt'] = [ 'true' ]
else
rule['snapt'] = [ 'false' ]
end
end
end
new_rules = {
'configuration' => [
'firewall_nat' => [nat_rules]
]}
conf_xml_new = XmlSimple.xml_out(new_rules,
'RootName' => 'Request'
)
client.update_efm_configuration(fw_id, 'FW_NAT_RULE', conf_xml_new)
Address.new(:id => opts[:id], :instance_id => opts[:instance_id])
end
end
|
#attach_storage_volume(credentials, opts = {}) ⇒ Object
622
623
624
625
626
627
628
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 622
def attach_storage_volume(credentials, opts={})
safely do
client = new_client(credentials)
client.attach_vdisk(opts[:instance_id], opts[:id])
end
storage_volumes(credentials, opts).first
end
|
following method enables region drop-down box on GUI
1490
1491
1492
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1490
def configured_providers
Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'].keys.sort
end
|
#create_address(credentials, opts = {}) ⇒ Object
allocates (and enables) new ip in specified vsys/network
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 806
def create_address(credentials, opts={})
safely do
client = new_client(credentials)
opts ||= {}
if opts[:realm_id]
opts[:realm_id] = client.(opts[:realm_id])
else
xml = client.list_vsys['vsyss']
opts[:realm_id] = xml[0]['vsys'][0]['vsysId'][0] if xml
end
old_ips = []
xml = client.list_public_ips(opts[:realm_id])['publicips']
old_ips = xml[0]['publicip'].collect { |ip| ip['address'][0]} if xml and xml[0]['publicip']
client.allocate_public_ip(opts[:realm_id])
id = 'PENDING-xxx.xxx.xxx.xxx'
sleep(8)
10.times {
sleep(5)
xml = client.list_public_ips(opts[:realm_id])['publicips']
if xml and xml[0]['publicip'] and xml[0]['publicip'].size > old_ips.size
new_ips = xml[0]['publicip'].collect { |ip| ip['address'][0]}
new_ip = (new_ips - old_ips).first
client.attach_public_ip(opts[:realm_id], new_ip)
id = new_ip
break
end
}
Address.new(:id => id)
end
end
|
#create_firewall(credentials, opts = {}) ⇒ Object
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1096
def create_firewall(credentials, opts={})
safely do
client = new_client(credentials)
begin
vsys_id = client.create_vsys(opts['description'], opts['name'])['vsysId'][0]
rescue Exception => ex
raise ex unless ex.message =~ /Template does not exist.*/
descriptors = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect { |desc| desc['vsysdescriptorId'][0] }
raise "Descriptor [#{opts['name']}] does not exist. Specify one of [#{descriptors.join(', ')}] as firewall description"
end
fw_id = vsys_id + '-S-0001'
Firewall.new({
:id => fw_id,
:name => opts['name'],
:description => opts['description'],
:owner_id => '',
:rules => []
})
end
end
|
#create_image(credentials, opts = {}) ⇒ Object
Create a new image from the given instance, with optionally provided name and description
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 143
def create_image(credentials, opts={})
safely do
client = new_client(credentials)
if opts[:name].nil?
instance = client.get_vserver_attributes(opts[:id])
opts[:name] = instance['vserver'][0]['vserverName']
opts[:description] ||= opts[:name]
end
client.register_private_disk_image(opts[:id], opts[:name], opts[:description])
hwps = hardware_profiles(credentials)
Image.new(
:id => "PENDING-#{opts[:name]}", :name => opts[:name],
:description => opts[:description],
:state => 'PENDING',
:hardware_profiles => hwps
)
end
end
|
#create_instance(credentials, image_id, opts = {}) ⇒ Object
Create a new instance, given an image id opts can include an optional name for the instance, hardware profile (hwp_id) and realm_id
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 371
def create_instance(credentials, image_id, opts={})
name = (opts[:name] && opts[:name].length > 0)? opts[:name] : "server_#{Time.now.to_s}"
hwp = opts[:hwp_id] || 'economy'
network_id = opts[:realm_id]
safely do
client = new_client(credentials)
if not network_id
xml = client.list_vsys['vsyss']
network_id = xml ? xml[0]['vsys'][0]['vsysId'][0] + '-N-DMZ' : nil
end
if opts[:instance_count] and opts[:instance_count].to_i > 1
vservers = Array.new(opts[:instance_count].to_i) { |n|
{
'vserverName' => "#{name}_#{n+1}",
'vserverType' => hwp,
'diskImageId' => image_id,
'networkId' => network_id
}
}
new_vservers = { 'vservers' => { 'vserver' => vservers } }
vservers_xml = XmlSimple.xml_out(new_vservers,
'RootName' => 'Request',
'NoAttr' => true
)
xml = client.create_vservers(client.(network_id), vservers_xml)
vserver_ids = xml['vservers'][0]['vserver'].collect { |vserver| vserver['vserverId'][0] }
instances(credentials, {:realm_id => network_id}).select { |instance|
vserver_ids.include? instance.id
}
else
xml = client.create_vserver(name, hwp, image_id, network_id)
instances(credentials, {:id => xml['vserverId'][0]}).first
end
end
end
|
#create_load_balancer(credentials, opts = {}) ⇒ Object
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1339
def create_load_balancer(credentials, opts={})
safely do
client = new_client(credentials)
network_id = opts[:realm_id]
if not network_id
xml = client.list_vsys['vsyss']
network_id = xml ? xml[0]['vsys'][0]['vsysId'][0] + '-N-DMZ' : nil
end
efm = client.create_efm('SLB', opts[:name], network_id)
load_balancer(credentials, {:id => efm['efmId'][0]})
end
end
|
#create_storage_snapshot(credentials, opts = {}) ⇒ Object
701
702
703
704
705
706
707
708
709
710
711
712
713
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 701
def create_storage_snapshot(credentials, opts={})
safely do
client = new_client(credentials)
client.backup_vdisk(opts[:volume_id])
end
StorageSnapshot.new(
:id => "PENDING-#{opts[:volume_id]}", :state => 'CREATING',
:storage_volume_id => opts[:volume_id],
:created => Time.now.to_s
)
end
|
#create_storage_volume(credentials, opts = {}) ⇒ Object
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 542
def create_storage_volume(credentials, opts={})
opts ||= {}
opts[:name] = Time.now.to_s unless opts[:name] and not opts[:name].empty?
opts[:capacity] ||= '1' opts[:capacity] = ((opts[:capacity].to_f / 10.0).ceil * 10.0).to_s
safely do
client = new_client(credentials)
if opts[:realm_id]
opts[:realm_id] = client.(opts[:realm_id])
elsif xml = client.list_vsys['vsyss']
opts[:realm_id] = xml[0]['vsys'][0]['vsysId'][0] if xml
end
if not opts[:snapshot_id]
vdisk_id = client.create_vdisk(opts[:realm_id], opts[:name], opts[:capacity])['vdiskId'][0]
else
orig_vdisk_id, backup_id = split_snapshot_id(opts[:snapshot_id])
orig_vsys_id = client.(orig_vdisk_id)
size = client.get_vdisk_attributes(orig_vdisk_id)['vdisk'][0]['size'][0]
contract_id = client.(opts[:realm_id])
client.set_vdisk_backup_copy_key(orig_vsys_id, backup_id, [contract_id])
key = client.get_vdisk_backup_copy_key(opts[:realm_id], backup_id)['keyInfo'][0]['key'][0]
size = client.get_vdisk_attributes(orig_vdisk_id)['vdisk'][0]['size'][0]
vdisk_id = client.create_vdisk(opts[:realm_id], opts[:name], size)['vdiskId'][0]
begin
client.external_restore_vdisk(orig_vsys_id, backup_id, opts[:realm_id], vdisk_id, key)
rescue Exception => ex
raise unless ex.message =~ /ILLEGAL_STATE_DST.*/
end
Thread.new {
attempts = 0
begin
sleep 10
client.external_restore_vdisk(orig_vsys_id, backup_id, opts[:realm_id], vdisk_id, key)
rescue Exception => ex
raise unless attempts < 30 and ex.message =~ /ILLEGAL_STATE_DST.*/
attempts += 1
retry
end
}
end
StorageVolume.new(
:id => vdisk_id,
:created => Time.now.to_s,
:name => opts[:name],
:capacity => opts[:capacity],
:realm_id => client.(opts[:realm_id]),
:instance_id => nil,
:state => 'CREATING',
:kind => 'data',
:actions => []
)
end
end
|
#create_system(credentials, opts = {}) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 83
def create_system(credentials, opts={})
safely do
client = new_client(credentials)
name = opts[:name] || "system_#{Time.now.to_s}"
template = opts[:system_template]
template_id = template.id || template.href.to_s.gsub(/.*\/([^\/]+)$/, '\1')
vsys_id = client.create_vsys(template_id, name)['vsysId'][0]
opts[:id] = vsys_id
systems(credentials, opts).first
end
end
|
#delete_firewall(credentials, opts = {}) ⇒ Object
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1118
def delete_firewall(credentials, opts={})
safely do
client = new_client(credentials)
begin
opts[:id] =~ /^(.*-S-)\d\d\d\d/
fw_id = $1 + '0001'
client.stop_efm(fw_id)
rescue Exception => ex
raise ex if not ex.message =~ /ALREADY_STOPPED.*/
client.destroy_vsys(client.(opts[:id]))
return
end
Thread.new {
attempts = 0
begin
sleep 30
client.destroy_vsys(client.(opts[:id]))
rescue Exception => ex
raise unless attempts < 20 and ex.message =~ /SERVER_RUNNING.*/
attempts += 1
retry
end
}
raise 'Firewall will be deleted once it has stopped'
end
end
|
#delete_firewall_rule(credentials, opts = {}) ⇒ Object
FW rule creation not supported: fgcp backend requires a mandatory rule id to create (insert) a new rule into the existing accept/deny rules. Also, the first two digits of the five digit rule identify what from and to network segment (e.g. Internet to DMZ, or Secure2 to Secure1) the rule applies to. The current Deltacloud firewall collection API does not cover such functionality so it was deemed not suitable to implement.
def create_firewall_rule(credentials, opts={})
p opts
end
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1160
def delete_firewall_rule(credentials, opts={})
safely do
client = new_client(credentials)
conf_xml_old = <<-"eofwopxml"
<?xml version="1.0" encoding ="UTF-8"?>
<Request>
<configuration>
<firewall_policy>
</firewall_policy>
</configuration>
</Request>
eofwopxml
fw = client.get_efm_configuration(opts[:firewall], 'FW_POLICY', conf_xml_old)
rule50000_log = 'On'
fw['efm'][0]['firewall'][0]['directions'][0]['direction'].reject! do |direction|
direction['policies'][0]['policy'].reject! do |policy|
rule_id = policy['id'][0]
policy['id'][0] = rule_id[2..4]
rule50000_log = policy['log'][0] if rule_id == '50000'
if not policy['dstService'][0] == 'NONE'
policy.delete('dstType')
policy.delete('dstPort')
policy.delete('protocol')
end
rule_id == opts[:rule_id] or rule_id == '50000'
end
direction['policies'][0]['policy'].empty?
end
fw['efm'][0]['firewall'][0]['directions'][0]['direction'] << {
'policies' => [
'policy' => [
'log' => [ rule50000_log ]
]
]
}
new_rules = {
'configuration' => [
'firewall_policy' => [
'directions' => fw['efm'][0]['firewall'][0]['directions']
]
]}
conf_xml_new = XmlSimple.xml_out(new_rules,
'RootName' => 'Request'
)
conf_xml_new.gsub!(/(<(to|from)>).+(INTERNET|INTRANET)/, '\1\3')
client.update_efm_configuration(opts[:firewall], 'FW_POLICY', conf_xml_new)
end
end
|
#destroy_address(credentials, opts = {}) ⇒ Object
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 847
def destroy_address(credentials, opts={})
opts ||= {}
safely do
client = new_client(credentials)
if opts[:realm_id]
opts[:realm_id] = client.(opts[:realm_id])
else
xml = client.list_public_ips['publicips']
if xml
xml[0]['publicip'].find do |ip|
opts[:realm_id] = ip['vsysId'][0] if opts[:id] == ip['address'][0]
end
end
end
begin
client.detach_public_ip(opts[:realm_id], opts[:id])
sleep(8)
rescue Exception => ex
raise ex unless ex.message =~ /^ALREADY_DETACHED.*/
end
attempts = 0
begin
client.free_public_ip(opts[:realm_id], opts[:id])
rescue Exception => ex
raise unless attempts < 10 and ex.message =~ /^ILLEGAL_CONDITION.*/
sleep(5)
attempts += 1
retry
end
end
end
|
#destroy_image(credentials, image_id) ⇒ Object
168
169
170
171
172
173
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 168
def destroy_image(credentials, image_id)
safely do
client = new_client(credentials)
client.unregister_disk_image(image_id)
end
end
|
#destroy_instance(credentials, id) ⇒ Object
Destroy an instance, given its id.
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 415
def destroy_instance(credentials, id)
safely do
client = new_client(credentials)
vsys_id = client.(id)
if id == "#{vsys_id}-S-0001" client.destroy_vsys(vsys_id)
else
begin
client.destroy_vserver(id)
rescue Exception => ex
if not ex.message =~ /VALIDATION_ERROR.*/
raise ex
else
begin
client.destroy_efm(id)
rescue
raise ex
end
end
end
end
end
end
|
#destroy_load_balancer(credentials, id) ⇒ Object
1363
1364
1365
1366
1367
1368
1369
1370
1371
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1363
def destroy_load_balancer(credentials, id)
safely do
client = new_client(credentials)
client.destroy_efm(id)
end
end
|
#destroy_storage_snapshot(credentials, opts = {}) ⇒ Object
715
716
717
718
719
720
721
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 715
def destroy_storage_snapshot(credentials, opts={})
vdisk_id, backup_id = split_snapshot_id(opts[:id])
safely do
client = new_client(credentials)
client.destroy_vdisk_backup(client.(opts[:id]), backup_id)
end
end
|
#destroy_storage_volume(credentials, opts = {}) ⇒ Object
615
616
617
618
619
620
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 615
def destroy_storage_volume(credentials, opts={})
safely do
client = new_client(credentials)
client.destroy_vdisk(opts[:id])
end
end
|
#destroy_system(credentials, id) ⇒ Object
95
96
97
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 95
def destroy_system(credentials, id)
delete_firewall(credentials, :id => "#{id}-S-0001")
end
|
#detach_storage_volume(credentials, opts = {}) ⇒ Object
630
631
632
633
634
635
636
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 630
def detach_storage_volume(credentials, opts={})
safely do
client = new_client(credentials)
client.detach_vdisk(opts[:instance_id], opts[:id])
end
storage_volumes(credentials, opts)
end
|
#disassociate_address(credentials, opts = {}) ⇒ Object
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 941
def disassociate_address(credentials, opts={})
safely do
client = new_client(credentials)
if not opts[:realm_id]
if public_ips = client.list_public_ips['publicips']
public_ips[0]['publicip'].find do |ip|
opts[:realm_id] = ip['vsysId'][0] if opts[:id] == ip['address'][0]
end
end
end
vsys_id = client.(opts[:realm_id])
fw_id = "#{vsys_id}-S-0001"
nat_rules = client.get_efm_configuration(fw_id, 'FW_NAT_RULE')['efm'][0]['firewall'][0]['nat'][0]['rules'][0]
if nat_rules and not nat_rules.empty?
nat_rules['rule'].reject! { |rule| rule['publicIp'][0] == opts[:id] }
end
new_rules = {
'configuration' => [
'firewall_nat' => [nat_rules]
]}
conf_xml_new = XmlSimple.xml_out(new_rules,
'RootName' => 'Request'
)
client.update_efm_configuration(fw_id, 'FW_NAT_RULE', conf_xml_new)
end
end
|
#firewalls(credentials, opts = {}) ⇒ Object
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 981
def firewalls(credentials, opts={})
firewalls = []
fw_name = 'Firewall'
safely do
client = new_client(credentials)
if opts and opts[:id]
rules = []
configuration_xml = <<-"eofwpxml"
<?xml version="1.0" encoding ="UTF-8"?>
<Request>
<configuration>
<firewall_policy>
</firewall_policy>
</configuration>
</Request>
eofwpxml
begin
fw = client.get_efm_configuration(opts[:id], 'FW_POLICY', configuration_xml)
rescue Exception => ex
return [] if ex.message =~ /RESOURCE_NOT_FOUND/
raise
end
fw_name = fw['efm'][0]['efmName'][0] fw_owner_id = fw['efm'][0]['creator'][0]
rule50000_log = true
if fw['efm'][0]['firewall'][0]['directions'] and fw['efm'][0]['firewall'][0]['directions'][0]['direction']
fw['efm'][0]['firewall'][0]['directions'][0]['direction'].each do |direction|
direction['policies'][0]['policy'].each do |policy|
sources = []
['src', 'dst'].each do |e|
if policy[e] and policy[e][0] and not policy[e][0].empty?
ip_address_type = policy["#{e}Type"][0]
address = policy[e][0]
address.sub!('any', '0.0.0.0/0') if ip_address_type == 'IP'
address += '/32' if ip_address_type == 'IP' and not address =~ /.*\/.*/
sources << {
:type => 'address',
:family => 'ipv4',
:address => address.split('/').first,
:prefix => ip_address_type == 'IP' ? address.split('/').last : nil
}
end
end
ingress = policy['id'][0] =~ /[13].*/ ? 'ingress' : 'egress'
rules << FirewallRule.new({
:id => policy['id'][0],
:rule_action => policy['action'][0].downcase,
:log_rule => policy['log'][0] == 'On',
:allow_protocol => policy['protocol'][0],
:port_from => policy['srcPort'] ? policy['srcPort'][0] : nil, :port_to => policy['dstPort'] ? policy['dstPort'][0] : nil, :direction => ingress,
:sources => sources
}) unless policy['id'][0] == '50000'
rule50000_log = (policy['log'][0] == 'On') if policy['id'][0] == '50000'
end
end
end
source_any = {
:type => 'address',
:family => 'ipv4',
:address => '0.0.0.0',
:prefix => '0'
}
rules << FirewallRule.new({
:id => '50000',
:rule_action => 'deny',
:log_rule => rule50000_log,
:sources => [source_any]
})
vsys = client.get_vsys_attributes(client.(opts[:id]))['vsys'][0]
firewalls << Firewall.new({
:id => opts[:id],
:name => fw_name,
:description => "#{vsys['vsysName'][0]} [#{vsys['baseDescriptor'][0]}]",
:owner_id => fw_owner_id,
:rules => rules
})
else
xml = client.list_vsys['vsyss']
return [] if xml.nil?
firewalls = xml[0]['vsys'].collect do |vsys|
Firewall.new({
:id => vsys['vsysId'][0] + '-S-0001',
:name => fw_name,
:description => "#{vsys['vsysName'][0]} [#{vsys['baseDescriptor'][0]}]",
:rules => [],
:owner_id => vsys['creator'][0]
})
end
end
end
firewalls
end
|
#hardware_profiles(credentials, opts = nil) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 70
def hardware_profiles(credentials, opts=nil)
safely do
client = new_client(credentials)
xml = client.list_server_types
@hardware_profiles = []
if xml['servertypes']
xml['servertypes'][0]['servertype'].each do |type|
arch = type['cpu'][0]['cpuArch'][0] cpu = type['cpu'][0]['cpuPerf'][0].to_f * type['cpu'][0]['numOfCpu'][0].to_i
@hardware_profiles << ::Deltacloud::HardwareProfile.new(type['name'][0]) {
cpu cpu.to_f == cpu.to_f.floor ? cpu.to_i : cpu.to_f memory (type['memory'][0]['memorySize'][0].to_f * 1024) architecture (arch == 'IA') ? 'x86_64' : arch
}
end
end
end
filter_hardware_profiles(@hardware_profiles, opts)
end
|
#images(credentials, opts = {}) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 99
def images(credentials, opts={})
images = []
safely do
client = new_client(credentials)
xml = client.list_disk_images
hwps = hardware_profiles(credentials)
if xml['diskimages'] xml['diskimages'][0]['diskimage'].each do |img|
os_arch = img['osName'][0].to_s =~ /.*32.?bit.*/ ? 'i386' : 'x86_64'
os_centos_rhel = img['osName'][0] =~ /(CentOS|Red Hat).*/
allowed_hwps = hwps.select do |hwp|
hwp.memory.default.to_i < 16000 or os_arch == 'x86_64' or not os_centos_rhel
end
images << Image.new(
:id => img['diskimageId'][0],
:name => img['diskimageName'][0].to_s,
:description => img['description'][0].to_s,
:owner_id => img['registrant'][0].to_s, :state => 'AVAILABLE', :architecture => os_arch,
:hardware_profiles => allowed_hwps
) if opts[:id].nil? or opts[:id] == img['diskimageId'][0]
end
end
end
images = filter_on( images, :id, opts )
images = filter_on( images, :architecture, opts )
images = filter_on( images, :owner_id, opts )
images.sort_by{|e| [e.owner_id, e.architecture, e.name, e.description]}
end
|
#instances(credentials, opts = {}) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 248
def instances(credentials, opts={})
instances = []
safely do
client = new_client(credentials)
if opts and opts[:id] or opts[:realm_id]
vsys_id = client.(opts[:id] || opts[:realm_id])
vsys_config = client.get_vsys_configuration(vsys_id)
vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
network_id = vserver['vnics'][0]['vnic'][0]['networkId'][0]
if vsys_id == opts[:realm_id] or vserver['vserverId'][0] == opts[:id] or network_id == opts[:realm_id]
unless opts[:realm_id] and determine_server_type(vserver) == 'FW'
state_data = instance_state_data(vserver, client)
if opts[:state].nil? or opts[:state] == state_data[:state]
instance = convert_to_instance(client, vserver, state_data)
add_instance_details(instance, client, vserver)
instances << instance
end
end
end
end
elsif xml = client.list_vsys['vsyss']
return [] if xml.nil?
xml[0]['vsys'].each do |vsys|
begin
vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
unless determine_server_type(vserver) == 'FW'
state_data = opts[:state] ? instance_state_data(vserver, client) : nil
if opts[:state].nil? or opts[:state] == state_data[:state]
instances << convert_to_instance(client, vserver, state_data)
end
end
end
rescue Exception => ex raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
end
end
end
end
instances = filter_on( instances, :state, opts )
filter_on( instances, :id, opts )
end
|
#load_balancer(credentials, opts = {}) ⇒ Object
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1270
def load_balancer(credentials, opts={})
balancer = nil
safely do
client = new_client(credentials)
vsys_id = client.(opts[:id])
vsys_config = client.get_vsys_configuration(vsys_id)
vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
if vserver['vserverId'][0] == opts[:id]
vserver['vnics'][0]['vnic'][0]['networkId'][0] =~ /^.*\b(\w+)$/
realm_name = vsys_id + ' [' + $1 + ']' realm = Realm::new(
:id => vserver['vnics'][0]['vnic'][0]['networkId'][0],
:name => realm_name,
:limit => '[Network]',
:state => 'AVAILABLE' )
balancer = LoadBalancer.new({
:id => vserver['vserverId'][0],
:realms => [realm],
:listeners => [],
:instances => [],
:public_addresses => []
})
begin
slb_rule = client.get_efm_configuration(opts[:id], 'SLB_RULE')
if slb_rule['efm'][0]['loadbalancer'][0]['groups']
slb_rule['efm'][0]['loadbalancer'][0]['groups'][0]['group'].each do |group|
group['targets'][0]['target'].each do |server|
balancer.instances << Instance::new(
:id => server['serverId'][0],
:name => server['serverName'][0],
:realm_id => realm,
:private_addresses => [InstanceAddress.new(server['ipAddress'][0])]
)
balancer.add_listener({
:protocol => slb_rule['efm'][0]['loadbalancer'][0]['groups'][0]['group'][0]['protocol'][0],
:load_balancer_port => slb_rule['efm'][0]['loadbalancer'][0]['groups'][0]['group'][0]['port1'][0],
:instance_port => server['port1'][0]
})
end
end
end
slb_vip = slb_rule['efm'][0]['slbVip'][0]
opts[:id] =~ /^(.*-S-)\d\d\d\d/
fw_id = $1 + '0001'
nat_rules = client.get_efm_configuration(fw_id, 'FW_NAT_RULE')['efm'][0]['firewall'][0]['nat'][0]['rules'][0]
if nat_rules and not nat_rules.empty?
nat_rules['rule'].each do |rule|
balancer.public_addresses << InstanceAddress.new(rule['publicIp'][0]) if rule['privateIp'] and rule['privateIp'][0] == slb_vip
end
end
rescue Exception => ex
raise ex unless ex.message =~ /(ACCESS_NOT_PERMIT|ILLEGAL_STATE).*/
end
end
end
end
balancer
end
|
#load_balancers(credentials, opts = {}) ⇒ Object
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1229
def load_balancers(credentials, opts={})
balancers = []
safely do
client = new_client(credentials)
xml = client.list_vsys['vsyss']
return [] if xml.nil?
begin
xml[0]['vsys'].each do |vsys|
vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
if determine_server_type(vserver) == 'SLB'
vserver['vnics'][0]['vnic'][0]['networkId'][0] =~ /^.*\b(\w+)$/
realm_name = vsys['vsysId'][0] + ' [' + $1 + ']' realm = Realm::new(
:id => vserver['vnics'][0]['vnic'][0]['networkId'][0],
:name => realm_name,
:limit => '[Network]',
:state => 'AVAILABLE' )
balancer = LoadBalancer.new({
:id => vserver['vserverId'][0],
:realms => [realm],
:listeners => [],
:instances => [],
:public_addresses => []
})
balancers << balancer
end
end
end
rescue Exception => ex raise ex if not ex.message =~ /(RESOURCE_NOT_FOUND).*/
end
end
balancers
end
|
#metric(credentials, opts = {}) ⇒ Object
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1429
def metric(credentials, opts={})
safely do
client = new_client(credentials)
begin
perf = client.get_performance_information(opts[:id], 'hour')
rescue Exception => ex
return nil if ex.message =~ /RESOURCE_NOT_FOUND/
raise
end
metric = Metric.new(
:id => opts[:id],
:entity => perf['serverName'][0],
:properties => []
)
unless perf['performanceinfos'].nil? or perf['performanceinfos'][0].nil? or perf['performanceinfos'][0]['performanceinfo'].nil?
perf['performanceinfos'][0]['performanceinfo'].each do |sample|
timestamp = Time.at(sample['recordTime'][0].to_i / 1000)
sample.each do |measure|
measure_name = measure[0]
unless measure_name == 'recordTime'
unit = metric_unit_for(measure_name)
average = (unit == 'Percent') ? measure[1][0].to_f * 100 : measure[1][0]
properties = metric.add_property(measure_name).properties
property = properties.find { |p| p.name == measure_name }
property.values ||= []
property.values << {
:average => average,
:timestamp => timestamp,
:unit => unit
}
end
end
metric.properties.sort! {|a,b| a.name <=> b.name}
end
end
metric
end
end
|
#metrics(credentials, opts = {}) ⇒ Object
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1373
def metrics(credentials, opts={})
opts ||= {}
metrics_arr = []
safely do
client = new_client(credentials)
realms = []
if opts[:id]
metrics_arr << Metric.new(
:id => opts[:id],
:entity => client.get_vserver_attributes(opts[:id])['vserver'][0]['vserverName'][0]
)
elsif opts[:realm_id]
realms << opts[:realm_id]
else
xml = client.list_vsys['vsyss']
realms = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] } if xml
end
realms.each do |realm_id|
begin
xml = client.list_vservers(client.(realm_id))['vservers']
if xml and xml[0]['vserver']
xml[0]['vserver'].each do |vserver|
metrics_arr << Metric.new(
:id => vserver['vserverId'][0],
:entity => vserver['vserverName'][0]
)
end
end
rescue Exception => ex raise ex if not ex.message =~ /(RESOURCE_NOT_FOUND).*/
end
end
metrics_arr.each do |metric|
@@METRIC_NAMES.each do |name|
metric.add_property(name)
end
metric.properties.sort! {|a,b| a.name <=> b.name}
end
end
metrics_arr
end
|
#providers(credentials, opts = {}) ⇒ Object
Providers
output of this method is used to list regions (id, url) under /api/drivers/fgcp
1479
1480
1481
1482
1483
1484
1485
1486
1487
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 1479
def providers(credentials, opts={})
configured_providers.collect do |region|
Provider.new(
:id => "fgcp-#{region}",
:name => "Fujitsu Global Cloud Platform - #{region.upcase}",
:url => Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'][region]
)
end
end
|
#realms(credentials, opts = {}) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 178
def realms(credentials, opts={})
realms = []
safely do
client = new_client(credentials)
if opts and opts[:id]
vsys_id = client.(opts[:id])
begin
vsys = client.get_vsys_attributes(vsys_id)['vsys'][0]
rescue Exception => ex
return [] if ex.message =~ /VALIDATION_ERROR.*A wrong value is set/
raise
end
realm_name = vsys['vsysName'][0]
limit = '[System]'
if opts[:id] != vsys_id opts[:id] =~ /^.*\b(\w+)$/
realm_name += ' [' + $1 + ']' limit = '[Network]'
end
realms << Realm::new(
:id => opts[:id],
:name => realm_name,
:limit => limit,
:state => 'AVAILABLE' )
elsif xml = client.list_vsys['vsyss']
return [] if xml.nil?
xml[0]['vsys'].each do |vsys|
realms << Realm::new(
:id => vsys['vsysId'][0], :name => vsys['vsysName'][0], :limit => '[System]',
:state => 'AVAILABLE' )
begin
client.get_vsys_configuration(vsys['vsysId'][0])['vsys'][0]['vnets'][0]['vnet'].each do |vnet|
vnet['networkId'][0] =~ /^.*\b(\w+)$/
realm_name = vsys['vsysName'][0].to_s + ' [' + $1 + ']' realms << Realm::new(
:id => vnet['networkId'][0], :name => realm_name,
:limit => '[Network]',
:state => 'AVAILABLE' )
end
rescue Exception => ex raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
realms.pop
end
end
end
end
filter_on(realms, :id, opts)
end
|
#run_on_instance(credentials, opts = {}) ⇒ Object
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 442
def run_on_instance(credentials, opts={})
target = instance(credentials, opts)
safely do
param = {}
param[:port] = opts[:port] || '22'
param[:ip] = opts[:ip] || target.public_addresses.first.address
param[:credentials] = { :username => target.username }
if opts[:private_key] and opts[:private_key].length > 1
param[:private_key] = opts[:private_key]
else
password = (opts[:password] and opts[:password].length > 0) ? opts[:password] : target.password
param[:credentials].merge!({ :password => password })
end
Deltacloud::Runner.execute(opts[:cmd], param)
end
end
|
#start_instance(credentials, id) ⇒ Object
Start an instance, given its id.
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 309
def start_instance(credentials, id)
safely do
client = new_client(credentials)
if id =~ /^.*-S-0001/ client.start_efm(id)
else
begin
client.start_vserver(id)
rescue Exception => ex
if not ex.message =~ /VALIDATION_ERROR.*/
raise ex
else
begin
client.start_efm(id)
rescue
raise ex
end
end
end
end
end
instances(credentials, {:id => id}).first
end
|
#start_system(credentials, opts = {}) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 99
def start_system(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:id]
xml = client.list_vservers(vsys_id)['vservers']
return unless xml and xml[0]['vserver']
xml[0]['vserver'].each do |vserver|
begin
client.start_vserver(vserver['vserverId'][0])
rescue Exception => ex
raise ex if not ex.message =~ /(ALREADY_STARTED|ILLEGAL_STATE).*/
end
end
end
end
|
#stop_instance(credentials, id) ⇒ Object
Stop an instance, given its id.
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 337
def stop_instance(credentials, id)
safely do
client = new_client(credentials)
if id =~ /^.*-S-0001/ client.stop_efm(id)
else
begin
client.stop_vserver(id)
rescue Exception => ex
if not ex.message =~ /VALIDATION_ERROR.*/
raise ex
else
begin
client.stop_efm(id)
rescue
raise ex
end
end
end
end
end
instances(credentials, {:id => id}).first
end
|
#stop_system(credentials, opts = {}) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 119
def stop_system(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:id]
xml = client.list_vservers(vsys_id)['vservers']
return unless xml and xml[0]['vserver']
xml[0]['vserver'].each do |vserver|
begin
client.stop_vserver(vserver['vserverId'][0])
rescue Exception => ex
raise ex if not ex.message =~ /(ALREADY_STOPPED|ILLEGAL_STATE).*/
end
end
end
end
|
#storage_snapshots(credentials, opts = {}) ⇒ Object
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 641
def storage_snapshots(credentials, opts={})
snapshots = []
safely do
client = new_client(credentials)
if opts and opts[:id]
vdisk_id, backup_id = split_snapshot_id(opts[:id])
begin
if backups = client.list_vdisk_backup(vdisk_id)['backups']
backups[0]['backup'].each do |backup|
snapshots << StorageSnapshot.new(
:id => opts[:id],
:state => 'AVAILABLE',
:storage_volume_id => vdisk_id,
:created => backup['backupTime'][0]
) if backup_id = backup['backupId'][0]
end
end
rescue Exception => ex
return [] if ex.message =~ /RESOURCE_NOT_FOUND/
raise
end
elsif xml = client.list_vsys['vsyss']
return [] if xml.nil?
xml[0]['vsys'].each do |vsys|
begin
vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
if vdisks['vdisk']
vdisks['vdisk'].each do |vdisk|
backups = client.list_vdisk_backup(vdisk['vdiskId'][0])
if backups['backups'] and backups['backups'][0]['backup']
backups['backups'][0]['backup'].each do |backup|
snapshots << StorageSnapshot.new(
:id => generate_snapshot_id(vdisk['vdiskId'][0], backup['backupId'][0]),
:state => 'AVAILABLE',
:storage_volume_id => vdisk['vdiskId'][0],
:created => backup['backupTime'][0]
)
end
end
end
end
rescue Exception => ex raise ex if not ex.message =~ /(RESOURCE_NOT_FOUND|ERROR).*/
end
end
end
end
snapshots
end
|
#storage_volumes(credentials, opts = {}) ⇒ Object
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 464
def storage_volumes(credentials, opts={})
volumes = []
safely do
client = new_client(credentials)
if opts and opts[:id]
begin
vdisk = client.get_vdisk_attributes(opts[:id])['vdisk'][0]
rescue Exception => ex
return [] if ex.message =~ /VALIDATION_ERROR.*t exist./
return [] if ex.message =~ /VALIDATION_ERROR.*A wrong value is set/
raise
end
state = client.get_vdisk_status(opts[:id])['vdiskStatus'][0]
actions = []
case state
when 'NORMAL'
if vdisk['attachedTo'].nil?
state = 'AVAILABLE'
actions = [:attach, :destroy]
else
state = 'IN-USE'
actions = [:detach]
end
when 'DEPLOYING'
state = 'CREATING'
when 'BACKUP_ING'
state = 'CAPTURING'
end
volumes << StorageVolume.new(
:id => opts[:id],
:name => vdisk['vdiskName'][0],
:capacity => vdisk['size'][0],
:instance_id => vdisk['attachedTo'].nil? ? nil : vdisk['attachedTo'][0],
:state => state,
:actions => actions,
:kind => determine_storage_type(opts[:id]),
:realm_id => client.(opts[:id])
)
elsif xml = client.list_vsys['vsyss']
return [] if xml.nil?
xml[0]['vsys'].each do |vsys|
begin
vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
if vdisks['vdisk']
vdisks['vdisk'].each do |vdisk|
kind = determine_storage_type(vdisk['vdiskId'][0])
volumes << StorageVolume.new(
:id => vdisk['vdiskId'][0],
:name => vdisk['vdiskName'][0],
:capacity => vdisk['size'][0],
:instance_id => vdisk['attachedTo'].nil? ? nil : vdisk['attachedTo'][0],
:realm_id => client.(vdisk['vdiskId'][0]),
:kind => kind,
:state => vdisk['attachedTo'].nil? ? 'AVAILABLE' : 'IN-USE'
) unless kind == 'system'
end
end
rescue Exception => ex raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
end
end
end
end
volumes
end
|
#system_addresses(credentials, opts = {}) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 203
def system_addresses(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:system_id]
xml = client.list_public_ips(vsys_id)['publicips']
return [] unless xml and xml[0]['publicip']
addresses = xml[0]['publicip'].collect do |ip|
address = ip['address'][0]
CIMI::Model::SystemAddress.new(
:id => context.system_address_url(:id => vsys_id, :ent_id => address),
:name => "Public IP address allocated to system #{ip['vsysId'][0]}",
:address => { :href => context.address_url(address)}
) unless opts[:id] and opts[:id] != address
end
addresses.compact
end
end
|
#system_forwarding_groups(credentials, opts = {}) ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 225
def system_forwarding_groups(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:system_id]
vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
group_id = "#{vsys_id}-INTRA"
groups = []
groups << CIMI::Model::SystemForwardingGroup.new(
:id => context.system_forwarding_group_url(:id => vsys_id, :ent_id => group_id),
:name => "Routing group of system #{vsys['vsysName'][0]}",
:forwarding_group => { :href => context.forwarding_group_url(group_id)}
) unless vsys['vnets'][0]['vnet'].size <= 1 or (opts[:id] and opts[:id] != group_id)
groups
end
end
|
#system_machines(credentials, opts = {}) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 139
def system_machines(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:system_id]
xml = client.list_vservers(vsys_id)['vservers']
return [] unless xml and xml[0]['vserver']
machines = xml[0]['vserver'].collect do |vserver|
vserver_id = vserver['vserverId'][0]
CIMI::Model::SystemMachine.new(
:id => context.system_machine_url(:id => vsys_id, :ent_id => vserver_id),
:name => vserver['vserverName'][0],
:machine => { :href => context.machine_url(vserver_id)}
) unless opts[:id] and opts[:id] != vserver_id
end
machines.compact
end
end
|
#system_networks(credentials, opts = {}) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 181
def system_networks(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:system_id]
vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
networks = vsys['vnets'][0]['vnet'].collect do |vnet|
network_id = vnet['networkId'][0]
network_id =~ /.*-(\w)$/
CIMI::Model::SystemNetwork.new(
:id => context.system_network_url(:id => vsys_id, :ent_id => network_id),
:name => "#{$1} for system #{vsys['vsysName'][0]}",
:network => { :href => context.network_url(network_id)}
) unless opts[:id] and opts[:id] != network_id
end
networks.compact
end
end
|
#system_templates(credentials, opts = {}) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 244
def system_templates(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect do |desc|
conf = client.get_vsys_descriptor_configuration(desc['vsysdescriptorId'][0])['vsysdescriptor'][0]
components = conf['vservers'][0]['vserver'].collect do |vserver|
next if vserver['vserverType'][0] == 'firewall'
volume_templates = vserver['vdisks'][0]['vdisk'].collect do |vdisk|
CIMI::Model::VolumeTemplateWithLocation.new(
:volume_config => CIMI::Model::VolumeConfiguration.new(:capacity => vdisk['size'][0].to_i * 1024 * 1024)
)
end if vserver['vdisks']
{
:name => desc['vsysdescriptorName'][0],
:description => '',
:type => "http://schemas.dmtf.org/cimi/1/Machine",
:machine_template => CIMI::Model::MachineTemplate.new(
:name => vserver['vserverName'][0],
:description => '',
:machine_config => CIMI::Service::MachineConfiguration.find(vserver['vserverType'][0], context),
:machine_image => { :href => context.machine_image_url(vserver['diskimageId'][0]) },
:volume_templates => volume_templates
)
}
end
if conf['vsysdescriptorId'][0] =~ /(1|2|3)-tier Skeleton/
tiers = ['DMZ', 'Secure1', 'Secure2']
components += 1.upto($1.to_i).collect do |n|
{
:name => tiers[n],
:description => "Network tier #{n}",
:type => "http://schemas.dmtf.org/cimi/1/Network",
:network_template => CIMI::Model::NetworkTemplate.new(
:name => 'Private network',
:description => '',
:network_config => CIMI::Model::NetworkConfiguration.new(
:network_type => 'PRIVATE',
:class_of_service => 'BRONZE'
)
)
}
end
end
CIMI::Model::SystemTemplate.new(
:id => desc['vsysdescriptorId'][0],
:name => desc['vsysdescriptorName'][0],
:description => desc['description'][0],
:component_descriptors => components.compact
)
end
templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id]
templates
end
end
|
#system_volumes(credentials, opts = {}) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 160
def system_volumes(credentials, opts={})
safely do
client = new_client(credentials)
context = opts[:env]
vsys_id = opts[:system_id]
xml = client.list_vdisk(vsys_id)['vdisks']
return [] unless xml and xml[0]['vdisk']
volumes = xml[0]['vdisk'].collect do |vdisk|
vdisk_id = vdisk['vdiskId'][0]
CIMI::Model::SystemVolume.new(
:id => context.system_volume_url(:id => vsys_id, :ent_id => vdisk_id),
:name => vdisk['vdiskName'][0],
:volume => { :href => context.volume_url(vdisk_id)}
) unless (opts[:id] and opts[:id] != vdisk_id) or determine_storage_type(vdisk_id) == 'system'
end
volumes.compact
end
end
|
#systems(credentials, opts = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb', line 29
def systems(credentials, opts={})
safely do
client = new_client(credentials)
xml = client.list_vsys['vsyss']
return [] if xml.nil?
context = opts[:env]
systems = xml[0]['vsys'].collect do |vsys|
vsys_id = vsys['vsysId'][0]
vsys_description_el = vsys['description']
CIMI::Model::System.new(
:id => vsys_id,
:name => vsys['vsysName'][0],
:description => vsys_description_el ? vsys_description_el[0] : nil,
:machines => { :href => context.system_machines_url(vsys_id) },
:volumes => { :href => context.system_volumes_url(vsys_id) },
:networks => { :href => context.system_networks_url(vsys_id) },
:addresses => { :href => context.system_addresses_url(vsys_id) },
:operations => []
)
end
systems = systems.select { |s| opts[:id] == s[:id] } if opts[:id]
systems.each do |system|
vservers = client.list_vservers(system[:id])['vservers'][0]['vserver']
if vservers.nil?
system[:state] = client.get_vsys_status(system[:id])['vsysStatus'][0] == 'DEPLOYING' ? 'CREATING' : 'MIXED'
else
vservers.each do |vserver|
state = @@MACHINE_STATE_MAP[client.get_vserver_status(vserver['vserverId'][0])['vserverStatus'][0]]
system[:state] ||= state
system[:operations] << { :href => context.system_url("#{system[:id]}/start"), :rel => "http://schemas.dmtf.org/cimi/1/action/start" } if state == 'STOPPED'
system[:operations] << { :href => context.system_url("#{system[:id]}/stop"), :rel => "http://schemas.dmtf.org/cimi/1/action/stop" } if state == 'STARTED'
if system[:state] != state
system[:state] = 'MIXED'
system[:operations] << { :href => context.system_url("#{system[:id]}/start"), :rel => "http://schemas.dmtf.org/cimi/1/action/start" }
system[:operations] << { :href => context.system_url("#{system[:id]}/stop"), :rel => "http://schemas.dmtf.org/cimi/1/action/stop" }
break
end
end
system[:operations].uniq!
end
system[:state] = 'DELETING' if ((vservers.nil? and system[:state] != 'CREATING') or system[:state] == 'STOPPED') and
['STOPPED', 'STOPPING'].include? client.get_efm_status("#{system[:id]}-S-0001")['efmStatus'][0]
system[:operations] << { :href => context.system_url(system[:id]), :rel => "delete" } if system[:state] == 'STOPPED'
end
systems
end
end
|
#valid_credentials?(credentials) ⇒ Boolean
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/deltacloud/drivers/fgcp/fgcp_driver.rb', line 40
def valid_credentials?(credentials)
begin
client = new_client(credentials)
client.list_server_types
rescue
return false
end
true
end
|