Please review the patch I e-mailed 10 minutes after the patch below
instead.
Somehow I hadn't saved my source file when I was done so the patch below
is missing some bits.

Regards,
Dies


> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Tuesday, 19 February 2013 3:17 PM
> To: [email protected]
> Subject: [PATCH] FGCP: added error handling to exclude resources that
> were deleted in the middle of a GET operation
> 
> From: Dies Koper <[email protected]>
> 
> ---
>  server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb | 136
> ++++++++++++----------
>  1 file changed, 77 insertions(+), 59 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
> b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
> index c8bcc7b..66bddde 100644
> --- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
> +++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
> @@ -109,8 +109,11 @@ class FgcpDriver < Deltacloud::BaseDriver
>        if xml['diskimages'] # not likely to not be so, but just in
case
>          xml['diskimages'][0]['diskimage'].each do |img|
> 
> -          # 32bit CentOS/RHEL images are refused on hwps > 16GB (i.e.
> w_high, quad_high)
> +          # This will determine image architecture using OS name.
> +          # Usually the OS name includes '64bit' or '32bit'. If not,
> +          # it will fall back to 64 bit.
>            os_arch = img['osName'][0].to_s =~ /.*32.?bit.*/ ? 'i386' :
> 'x86_64'
> +          # 32bit CentOS/RHEL images are refused on hwps > 16GB (i.e.
> w_high, quad_high)
>            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
> @@ -122,9 +125,6 @@ class FgcpDriver < Deltacloud::BaseDriver
>              :description => img['description'][0].to_s,
>              :owner_id => img['registrant'][0].to_s, # or
> 'creatorName'?
>              :state => 'AVAILABLE', #server keeps no particular state.
> If it's listed, it's available for use.
> -            # This will determine image architecture using OS name.
> -            # Usually the OS name includes '64bit' or '32bit'. If
not,
> -            # it will fall back to 64 bit.
>              :architecture => os_arch,
>              :hardware_profiles => allowed_hwps
>            ) if opts[:id].nil? or opts[:id] == img['diskimageId'][0]
> @@ -216,18 +216,24 @@ class FgcpDriver < Deltacloud::BaseDriver
>                        :limit => '[System]',
>                        :state => 'AVAILABLE' # map to state of FW/VSYS
> (reconfiguring = unavailable)?
>                      )
> -          # then retrieve and add list of network segments
> -
> 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 + ']' #
> vsys name or vsys name + network [DMZ/SECURE1/SECURE2]
> -            realms << Realm::new(
> -                        :id => vnet['networkId'][0], # vsysId or
> networkId
> -                        :name => realm_name,
> -                        #:limit => :unlimited,
> -                        :limit => '[Network]',
> -                        :state => 'AVAILABLE' # map to state of
FW/VSYS
> (reconfiguring = unavailable)?
> -                      )
> +          begin
> +            # then retrieve and add list of network segments
> +
> 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 + ']'
> # vsys name or vsys name + network [DMZ/SECURE1/SECURE2]
> +              realms << Realm::new(
> +                          :id => vnet['networkId'][0], # vsysId or
> networkId
> +                          :name => realm_name,
> +                          #:limit => :unlimited,
> +                          :limit => '[Network]',
> +                          :state => 'AVAILABLE' # map to state of
> FW/VSYS (reconfiguring = unavailable)?
> +                        )
> +            end
> +          rescue Exception => ex # cater for case where vsys was just
> destroyed since list_vsys call
> +            raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
> +            # remove earlier added vsys
> +            realms.pop
>            end
>          end
>        end
> @@ -272,20 +278,24 @@ class FgcpDriver < Deltacloud::BaseDriver
>          xml[0]['vsys'].each do |vsys|
> 
>            # use get_vsys_configuration (instead of
> get_vserver_configuration) to retrieve all vservers in one call
> -          vsys_config =
> client.get_vsys_configuration(vsys['vsysId'][0])
> -          vsys_config['vsys'][0]['vservers'][0]['vserver'].each do
> |vserver|
> -
> -            # skip firewalls - they probably don't belong here and
their
> new type ('firewall' instead of
> -            # 'economy') causes errors when trying to map to
available
> profiles)
> -            unless determine_server_type(vserver) == 'FW'
> -              # to keep the response time of this method acceptable,
> retrieve state
> -              # only if required because state is filtered on
> -              state_data = opts[:state] ?
instance_state_data(vserver,
> client) : nil
> -              # filter on state
> -              if opts[:state].nil? or opts[:state] ==
> state_data[:state]
> -                instances << convert_to_instance(client, vserver,
> state_data)
> +          begin
> +            vsys_config =
> client.get_vsys_configuration(vsys['vsysId'][0])
> +            vsys_config['vsys'][0]['vservers'][0]['vserver'].each do
> |vserver|
> +
> +              # skip firewalls - they probably don't belong here and
> their new type ('firewall' instead of
> +              # 'economy') causes errors when trying to map to
available
> profiles)
> +              unless determine_server_type(vserver) == 'FW'
> +                # to keep the response time of this method
acceptable,
> retrieve state
> +                # only if required because state is filtered on
> +                state_data = opts[:state] ?
> instance_state_data(vserver, client) : nil
> +                # filter on state
> +                if opts[:state].nil? or opts[:state] ==
> state_data[:state]
> +                  instances << convert_to_instance(client, vserver,
> state_data)
> +                end
>                end
>              end
> +          rescue Exception => ex # cater for case where vsys was just
> destroyed since list_vsys call
> +            raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
>            end
>          end
>        end
> @@ -495,24 +505,28 @@ class FgcpDriver < Deltacloud::BaseDriver
>          return [] if xml.nil?
>          xml[0]['vsys'].each do |vsys|
> 
> -          vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
> -
> -          if vdisks['vdisk']
> -            vdisks['vdisk'].each do |vdisk|
> -
> -              #state requires an additional call per volume. Only set
> if attached.
> -              #exclude system disks as they are not detachable?
> -              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.extract_vsys_id(vdisk['vdiskId'][0]),
> -                # aligning with rhevm, which returns 'system' or
'data'
> -                :kind        =>
> determine_storage_type(vdisk['vdiskId'][0]),
> -                :state       => vdisk['attachedTo'].nil? ?
> 'AVAILABLE' : 'IN-USE'
> -              )
> +          begin
> +            vdisks =
> client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
> +
> +            if vdisks['vdisk']
> +              vdisks['vdisk'].each do |vdisk|
> +
> +                #state requires an additional call per volume. Only
set
> if attached.
> +                #exclude system disks as they are not detachable?
> +                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.extract_vsys_id(vdisk['vdiskId'][0]),
> +                  # aligning with rhevm, which returns 'system' or
> 'data'
> +                  :kind        =>
> determine_storage_type(vdisk['vdiskId'][0]),
> +                  :state       => vdisk['attachedTo'].nil? ?
> 'AVAILABLE' : 'IN-USE'
> +                )
> +              end
>              end
> +          rescue Exception => ex # cater for case where vsys was just
> destroyed since list_vsys call
> +            raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
>            end
>          end
>        end
> @@ -614,23 +628,27 @@ class FgcpDriver < Deltacloud::BaseDriver
>          return [] if xml.nil?
>          xml[0]['vsys'].each do |vsys|
> 
> -          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]
> -                  )
> +          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 # cater for case where vsys was just
> destroyed since list_vsys call
> +            raise ex if not ex.message =~
> /(RESOURCE_NOT_FOUND|ERROR).*/
>            end
>          end
>        end
> --
> 1.8.0.msysgit.0
> 
> 


Reply via email to