| 1 | # | ||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||
| 3 | # | ||
| 4 | |||
| 5 | # | ||
| 6 | # Some of the code is based on Net::Amazon::EC2 | ||
| 7 | # | ||
| 8 | |||
| 9 | package Rex::Cloud::Amazon; | ||
| 10 | |||
| 11 | use v5.14.4; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | our $VERSION = '1.16.1'; # VERSION | ||
| 15 | |||
| 16 | use Rex::Logger; | ||
| 17 | use Rex::Cloud::Base; | ||
| 18 | use AWS::Signature4; | ||
| 19 | use HTTP::Request::Common; | ||
| 20 | use Digest::HMAC_SHA1; | ||
| 21 | use base qw(Rex::Cloud::Base); | ||
| 22 | use LWP::UserAgent; | ||
| 23 | use XML::Simple; | ||
| 24 | use Carp; | ||
| 25 | |||
| 26 | BEGIN { | ||
| 27 | use Rex::Require; | ||
| 28 | HTTP::Date->use(qw(time2isoz)); | ||
| 29 | MIME::Base64->use(qw(encode_base64 decode_base64)); | ||
| 30 | } | ||
| 31 | |||
| 32 | use Data::Dumper; | ||
| 33 | |||
| 34 | sub new { | ||
| 35 | my $that = shift; | ||
| 36 | my $proto = ref($that) || $that; | ||
| 37 | my $self = {@_}; | ||
| 38 | |||
| 39 | bless( $self, $proto ); | ||
| 40 | |||
| 41 | #$self->{"__version"} = "2009-11-30"; | ||
| 42 | $self->{"__version"} = "2011-05-15"; | ||
| 43 | $self->{"__signature_version"} = 1; | ||
| 44 | $self->{"__endpoint"} = "us-east-1.ec2.amazonaws.com"; | ||
| 45 | |||
| 46 | Rex::Logger::debug( | ||
| 47 | "Creating new Amazon Object, with endpoint: " . $self->{"__endpoint"} ); | ||
| 48 | Rex::Logger::debug( "Using API Version: " . $self->{"__version"} ); | ||
| 49 | |||
| 50 | return $self; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub signer { | ||
| 54 | my ($self) = @_; | ||
| 55 | return AWS::Signature4->new( | ||
| 56 | -access_key => $self->{__access_key}, | ||
| 57 | -secret_key => $self->{__secret_access_key} | ||
| 58 | ); | ||
| 59 | } | ||
| 60 | |||
| 61 | sub set_auth { | ||
| 62 | my ( $self, $access_key, $secret_access_key ) = @_; | ||
| 63 | |||
| 64 | $self->{"__access_key"} = $access_key; | ||
| 65 | $self->{"__secret_access_key"} = $secret_access_key; | ||
| 66 | } | ||
| 67 | |||
| 68 | sub set_endpoint { | ||
| 69 | my ( $self, $endpoint ) = @_; | ||
| 70 | Rex::Logger::debug("Setting new endpoint to $endpoint"); | ||
| 71 | $self->{'__endpoint'} = $endpoint; | ||
| 72 | } | ||
| 73 | |||
| 74 | sub timestamp { | ||
| 75 | my $t = time2isoz(); | ||
| 76 | chop($t); | ||
| 77 | $t .= ".000Z"; | ||
| 78 | $t =~ s/\s+/T/g; | ||
| 79 | return $t; | ||
| 80 | } | ||
| 81 | |||
| 82 | sub run_instance { | ||
| 83 | my ( $self, %data ) = @_; | ||
| 84 | |||
| 85 | Rex::Logger::debug("Trying to start a new Amazon instance with data:"); | ||
| 86 | Rex::Logger::debug( " $_ -> " . ( $data{$_} ? $data{$_} : "undef" ) ) | ||
| 87 | for keys %data; | ||
| 88 | |||
| 89 | my $security_groups; | ||
| 90 | |||
| 91 | if ( ref( $data{security_group} ) eq "ARRAY" ) { | ||
| 92 | $security_groups = $data{security_group}; | ||
| 93 | } | ||
| 94 | elsif ( exists $data{security_groups} ) { | ||
| 95 | $security_groups = $data{security_groups}; | ||
| 96 | } | ||
| 97 | else { | ||
| 98 | $security_groups = $data{security_group}; | ||
| 99 | } | ||
| 100 | |||
| 101 | my %security_group = (); | ||
| 102 | if ( ref($security_groups) eq "ARRAY" ) { | ||
| 103 | my $i = 0; | ||
| 104 | for my $sg ( @{$security_groups} ) { | ||
| 105 | $security_group{"SecurityGroup.$i"} = $sg; | ||
| 106 | $i++; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | elsif ( !exists $data{options}->{SubnetId} ) { | ||
| 110 | $security_group{SecurityGroup} = $security_groups || "default"; | ||
| 111 | } | ||
| 112 | |||
| 113 | my %more_options = %{ $data{options} || {} }; | ||
| 114 | |||
| 115 | my $xml = $self->_request( | ||
| 116 | "RunInstances", | ||
| 117 | ImageId => $data{"image_id"}, | ||
| 118 | MinCount => 1, | ||
| 119 | MaxCount => 1, | ||
| 120 | KeyName => $data{"key"}, | ||
| 121 | InstanceType => $data{"type"} || "m1.small", | ||
| 122 | "Placement.AvailabilityZone" => $data{"zone"} || "", | ||
| 123 | %security_group, | ||
| 124 | %more_options, | ||
| 125 | ); | ||
| 126 | |||
| 127 | my $ref = $self->_xml($xml); | ||
| 128 | |||
| 129 | if ( exists $data{"name"} ) { | ||
| 130 | $self->add_tag( | ||
| 131 | id => $ref->{"instancesSet"}->{"item"}->{"instanceId"}, | ||
| 132 | name => "Name", | ||
| 133 | value => $data{"name"} | ||
| 134 | ); | ||
| 135 | } | ||
| 136 | |||
| 137 | my ($info) = | ||
| 138 | grep { $_->{"id"} eq $ref->{"instancesSet"}->{"item"}->{"instanceId"} } | ||
| 139 | $self->list_instances(); | ||
| 140 | |||
| 141 | while ( $info->{"state"} ne "running" ) { | ||
| 142 | Rex::Logger::debug("Waiting for instance to be created..."); | ||
| 143 | ($info) = | ||
| 144 | grep { $_->{"id"} eq $ref->{"instancesSet"}->{"item"}->{"instanceId"} } | ||
| 145 | $self->list_instances(); | ||
| 146 | sleep 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | if ( exists $data{"volume"} ) { | ||
| 150 | $self->attach_volume( | ||
| 151 | volume_id => $data{"volume"}, | ||
| 152 | instance_id => $ref->{"instancesSet"}->{"item"}->{"instanceId"}, | ||
| 153 | name => "/dev/sdh", # default for new instances | ||
| 154 | ); | ||
| 155 | } | ||
| 156 | |||
| 157 | return $info; | ||
| 158 | } | ||
| 159 | |||
| 160 | sub attach_volume { | ||
| 161 | my ( $self, %data ) = @_; | ||
| 162 | |||
| 163 | Rex::Logger::debug("Trying to attach a new volume"); | ||
| 164 | |||
| 165 | $self->_request( | ||
| 166 | "AttachVolume", | ||
| 167 | VolumeId => $data{"volume_id"}, | ||
| 168 | InstanceId => $data{"instance_id"}, | ||
| 169 | Device => $data{"name"} || "/dev/sdh" | ||
| 170 | ); | ||
| 171 | } | ||
| 172 | |||
| 173 | sub detach_volume { | ||
| 174 | my ( $self, %data ) = @_; | ||
| 175 | |||
| 176 | Rex::Logger::debug("Trying to detach a volume"); | ||
| 177 | |||
| 178 | $self->_request( "DetachVolume", VolumeId => $data{"volume_id"}, ); | ||
| 179 | } | ||
| 180 | |||
| 181 | sub delete_volume { | ||
| 182 | my ( $self, %data ) = @_; | ||
| 183 | |||
| 184 | Rex::Logger::debug("Trying to delete a volume"); | ||
| 185 | |||
| 186 | $self->_request( "DeleteVolume", VolumeId => $data{"volume_id"}, ); | ||
| 187 | } | ||
| 188 | |||
| 189 | sub terminate_instance { | ||
| 190 | my ( $self, %data ) = @_; | ||
| 191 | |||
| 192 | Rex::Logger::debug("Trying to terminate an instance"); | ||
| 193 | |||
| 194 | $self->_request( "TerminateInstances", | ||
| 195 | "InstanceId.1" => $data{"instance_id"} ); | ||
| 196 | } | ||
| 197 | |||
| 198 | sub start_instance { | ||
| 199 | my ( $self, %data ) = @_; | ||
| 200 | |||
| 201 | Rex::Logger::debug("Trying to start an instance"); | ||
| 202 | |||
| 203 | $self->_request( "StartInstances", "InstanceId.1" => $data{instance_id} ); | ||
| 204 | |||
| 205 | my ($info) = | ||
| 206 | grep { $_->{"id"} eq $data{"instance_id"} } $self->list_instances(); | ||
| 207 | |||
| 208 | while ( $info->{"state"} ne "running" ) { | ||
| 209 | Rex::Logger::debug("Waiting for instance to be started..."); | ||
| 210 | ($info) = | ||
| 211 | grep { $_->{"id"} eq $data{"instance_id"} } $self->list_instances(); | ||
| 212 | sleep 5; | ||
| 213 | } | ||
| 214 | |||
| 215 | } | ||
| 216 | |||
| 217 | sub stop_instance { | ||
| 218 | my ( $self, %data ) = @_; | ||
| 219 | |||
| 220 | Rex::Logger::debug("Trying to stop an instance"); | ||
| 221 | |||
| 222 | $self->_request( "StopInstances", "InstanceId.1" => $data{instance_id} ); | ||
| 223 | |||
| 224 | my ($info) = | ||
| 225 | grep { $_->{"id"} eq $data{"instance_id"} } $self->list_instances(); | ||
| 226 | |||
| 227 | while ( $info->{"state"} ne "stopped" ) { | ||
| 228 | Rex::Logger::debug("Waiting for instance to be stopped..."); | ||
| 229 | ($info) = | ||
| 230 | grep { $_->{"id"} eq $data{"instance_id"} } $self->list_instances(); | ||
| 231 | sleep 5; | ||
| 232 | } | ||
| 233 | |||
| 234 | } | ||
| 235 | |||
| 236 | sub add_tag { | ||
| 237 | my ( $self, %data ) = @_; | ||
| 238 | |||
| 239 | Rex::Logger::debug( "Adding a new tag: " | ||
| 240 | . $data{id} . " -> " | ||
| 241 | . $data{name} . " -> " | ||
| 242 | . $data{value} ); | ||
| 243 | |||
| 244 | $self->_request( | ||
| 245 | "CreateTags", | ||
| 246 | "ResourceId.1" => $data{"id"}, | ||
| 247 | "Tag.1.Key" => $data{"name"}, | ||
| 248 | "Tag.1.Value" => $data{"value"} | ||
| 249 | ); | ||
| 250 | } | ||
| 251 | |||
| 252 | sub create_volume { | ||
| 253 | my ( $self, %data ) = @_; | ||
| 254 | |||
| 255 | Rex::Logger::debug("Creating a new volume"); | ||
| 256 | |||
| 257 | my $xml = $self->_request( | ||
| 258 | "CreateVolume", | ||
| 259 | "Size" => $data{"size"} || 1, | ||
| 260 | "AvailabilityZone" => $data{"zone"}, | ||
| 261 | ); | ||
| 262 | |||
| 263 | my $ref = $self->_xml($xml); | ||
| 264 | |||
| 265 | return $ref->{"volumeId"}; | ||
| 266 | |||
| 267 | my ($info) = grep { $_->{"id"} eq $ref->{"volumeId"} } $self->list_volumes(); | ||
| 268 | |||
| 269 | while ( $info->{"status"} ne "available" ) { | ||
| 270 | Rex::Logger::debug("Waiting for volume to become ready..."); | ||
| 271 | ($info) = grep { $_->{"id"} eq $ref->{"volumeId"} } $self->list_volumes(); | ||
| 272 | sleep 1; | ||
| 273 | } | ||
| 274 | |||
| 275 | } | ||
| 276 | |||
| 277 | sub list_volumes { | ||
| 278 | my ($self) = @_; | ||
| 279 | |||
| 280 | my $xml = $self->_request("DescribeVolumes"); | ||
| 281 | my $ref = $self->_xml($xml); | ||
| 282 | |||
| 283 | return unless ($ref); | ||
| 284 | return unless ( exists $ref->{"volumeSet"}->{"item"} ); | ||
| 285 | if ( ref( $ref->{"volumeSet"}->{"item"} ) eq "HASH" ) { | ||
| 286 | $ref->{"volumeSet"}->{"item"} = [ $ref->{"volumeSet"}->{"item"} ]; | ||
| 287 | } | ||
| 288 | |||
| 289 | my @volumes; | ||
| 290 | for my $vol ( @{ $ref->{"volumeSet"}->{"item"} } ) { | ||
| 291 | push( | ||
| 292 | @volumes, | ||
| 293 | { | ||
| 294 | id => $vol->{"volumeId"}, | ||
| 295 | status => $vol->{"status"}, | ||
| 296 | zone => $vol->{"availabilityZone"}, | ||
| 297 | size => $vol->{"size"}, | ||
| 298 | attached_to => $vol->{"attachmentSet"}->{"item"}->{"instanceId"}, | ||
| 299 | } | ||
| 300 | ); | ||
| 301 | } | ||
| 302 | |||
| 303 | return @volumes; | ||
| 304 | } | ||
| 305 | |||
| 306 | sub _make_instance_map { | ||
| 307 | my ( $self, $instance_set ) = @_; | ||
| 308 | return ( | ||
| 309 | ip => $_[1]->{"ipAddress"}, | ||
| 310 | id => $_[1]->{"instanceId"}, | ||
| 311 | image_id => $_[1]->{"imageId"}, | ||
| 312 | architecture => $_[1]->{"architecture"}, | ||
| 313 | type => $_[1]->{"instanceType"}, | ||
| 314 | dns_name => $_[1]->{"dnsName"}, | ||
| 315 | state => $_[1]->{"instanceState"}->{"name"}, | ||
| 316 | launch_time => $_[1]->{"launchTime"}, | ||
| 317 | ( | ||
| 318 | name => exists( $instance_set->{"tagSet"}->{"item"}->{"value"} ) | ||
| 319 | ? $instance_set->{"tagSet"}->{"item"}->{"value"} | ||
| 320 | : $instance_set->{"tagSet"}->{"item"}->{"Name"}->{"value"} | ||
| 321 | ), | ||
| 322 | private_ip => $_[1]->{"privateIpAddress"}, | ||
| 323 | ( | ||
| 324 | security_group => ref $_[1]->{"groupSet"}->{"item"} eq 'ARRAY' ? join ',', | ||
| 325 | map { $_->{groupName} } @{ $_[1]->{"groupSet"}->{"item"} } | ||
| 326 | : $_[1]->{"groupSet"}->{"item"}->{"groupName"} | ||
| 327 | ), | ||
| 328 | ( | ||
| 329 | security_groups => ref $_[1]->{"groupSet"}->{"item"} eq 'ARRAY' | ||
| 330 | ? [ map { $_->{groupName} } @{ $_[1]->{"groupSet"}->{"item"} } ] | ||
| 331 | : [ $_[1]->{"groupSet"}->{"item"}->{"groupName"} ] | ||
| 332 | ), | ||
| 333 | ( | ||
| 334 | tags => { | ||
| 335 | map { | ||
| 336 | if ( ref $instance_set->{"tagSet"}->{"item"}->{$_} eq 'HASH' ) { | ||
| 337 | $_ => $instance_set->{"tagSet"}->{"item"}->{$_}->{value}; | ||
| 338 | } | ||
| 339 | else { | ||
| 340 | $instance_set->{"tagSet"}->{"item"}->{key} => | ||
| 341 | $instance_set->{"tagSet"}->{"item"}->{value}; | ||
| 342 | } | ||
| 343 | } keys %{ $instance_set->{"tagSet"}->{"item"} } | ||
| 344 | } | ||
| 345 | ), | ||
| 346 | ); | ||
| 347 | } | ||
| 348 | |||
| 349 | sub list_instances { | ||
| 350 | my ($self) = @_; | ||
| 351 | |||
| 352 | my @ret; | ||
| 353 | |||
| 354 | my $xml = $self->_request("DescribeInstances"); | ||
| 355 | my $ref = $self->_xml($xml); | ||
| 356 | |||
| 357 | return unless ($ref); | ||
| 358 | return unless ( exists $ref->{"reservationSet"} ); | ||
| 359 | return unless ( exists $ref->{"reservationSet"}->{"item"} ); | ||
| 360 | |||
| 361 | if ( ref $ref->{"reservationSet"}->{"item"} eq "HASH" ) { | ||
| 362 | |||
| 363 | # if only one instance is returned, turn it to an array | ||
| 364 | $ref->{"reservationSet"}->{"item"} = [ $ref->{"reservationSet"}->{"item"} ]; | ||
| 365 | } | ||
| 366 | |||
| 367 | for my $instance_set ( @{ $ref->{"reservationSet"}->{"item"} } ) { | ||
| 368 | |||
| 369 | # push(@ret, $instance_set); | ||
| 370 | my $isi = $instance_set->{"instancesSet"}->{"item"}; | ||
| 371 | if ( ref $isi eq 'HASH' ) { | ||
| 372 | push( @ret, { $self->_make_instance_map($isi) } ); | ||
| 373 | } | ||
| 374 | elsif ( ref $isi eq 'ARRAY' ) { | ||
| 375 | for my $iset (@$isi) { | ||
| 376 | push( @ret, { $self->_make_instance_map($iset) } ); | ||
| 377 | } | ||
| 378 | } | ||
| 379 | } | ||
| 380 | |||
| 381 | return @ret; | ||
| 382 | } | ||
| 383 | |||
| 384 | sub list_running_instances { | ||
| 385 | my ($self) = @_; | ||
| 386 | |||
| 387 | return grep { $_->{"state"} eq "running" } $self->list_instances(); | ||
| 388 | } | ||
| 389 | |||
| 390 | sub get_regions { | ||
| 391 | my ($self) = @_; | ||
| 392 | |||
| 393 | my $content = $self->_request("DescribeRegions"); | ||
| 394 | my %items = | ||
| 395 | ( $content =~ | ||
| 396 | m/<regionName>([^<]+)<\/regionName>\s+<regionEndpoint>([^<]+)<\/regionEndpoint>/gsim | ||
| 397 | ); | ||
| 398 | |||
| 399 | return %items; | ||
| 400 | } | ||
| 401 | |||
| 402 | sub get_availability_zones { | ||
| 403 | my ($self) = @_; | ||
| 404 | |||
| 405 | my $xml = $self->_request("DescribeAvailabilityZones"); | ||
| 406 | my $ref = $self->_xml($xml); | ||
| 407 | |||
| 408 | my @zones; | ||
| 409 | for my $item ( @{ $ref->{"availabilityZoneInfo"}->{"item"} } ) { | ||
| 410 | push( | ||
| 411 | @zones, | ||
| 412 | { | ||
| 413 | zone_name => $item->{"zoneName"}, | ||
| 414 | region_name => $item->{"regionName"}, | ||
| 415 | zone_state => $item->{"zoneState"}, | ||
| 416 | } | ||
| 417 | ); | ||
| 418 | } | ||
| 419 | |||
| 420 | return @zones; | ||
| 421 | } | ||
| 422 | |||
| 423 | sub _request { | ||
| 424 | my ( $self, $action, %args ) = @_; | ||
| 425 | |||
| 426 | my $ua = LWP::UserAgent->new; | ||
| 427 | $ua->timeout(300); | ||
| 428 | $ua->env_proxy; | ||
| 429 | my %param = $self->_sign( $action, %args ); | ||
| 430 | |||
| 431 | Rex::Logger::debug( "Sending request to: https://" . $self->{'__endpoint'} ); | ||
| 432 | Rex::Logger::debug( " $_ -> " . $param{$_} ) for keys %param; | ||
| 433 | |||
| 434 | my $req = POST( "https://" . $self->{__endpoint}, [%param] ); | ||
| 435 | $self->signer->sign($req); | ||
| 436 | |||
| 437 | #my $res = $ua->post( "https://" . $self->{'__endpoint'}, \%param ); | ||
| 438 | my $res = $ua->request($req); | ||
| 439 | |||
| 440 | if ( $res->code >= 500 ) { | ||
| 441 | Rex::Logger::info( "Error on request", "warn" ); | ||
| 442 | Rex::Logger::debug( $res->content ); | ||
| 443 | return; | ||
| 444 | } | ||
| 445 | |||
| 446 | else { | ||
| 447 | my $ret; | ||
| 448 | eval { | ||
| 449 | no warnings; | ||
| 450 | $ret = $res->content; | ||
| 451 | Rex::Logger::debug($ret); | ||
| 452 | use warnings; | ||
| 453 | }; | ||
| 454 | |||
| 455 | return $ret; | ||
| 456 | } | ||
| 457 | } | ||
| 458 | |||
| 459 | sub _sign { | ||
| 460 | my ( $self, $action, %o_args ) = @_; | ||
| 461 | |||
| 462 | my %args; | ||
| 463 | for my $key ( keys %o_args ) { | ||
| 464 | next unless $key; | ||
| 465 | next unless $o_args{$key}; | ||
| 466 | |||
| 467 | $args{$key} = $o_args{$key}; | ||
| 468 | } | ||
| 469 | |||
| 470 | $args{Action} = $action; | ||
| 471 | $args{Version} = $self->{__version}; | ||
| 472 | |||
| 473 | return %args; | ||
| 474 | |||
| 475 | my %sign_hash = ( | ||
| 476 | AWSAccessKeyId => $self->{"__access_key"}, | ||
| 477 | Action => $action, | ||
| 478 | Timestamp => $self->timestamp(), | ||
| 479 | Version => $self->{"__version"}, | ||
| 480 | SignatureVersion => $self->{"__signature_version"}, | ||
| 481 | %args | ||
| 482 | ); | ||
| 483 | |||
| 484 | my $sign_this; | ||
| 485 | foreach my $key ( sort { lc($a) cmp lc($b) } keys %sign_hash ) { | ||
| 486 | $sign_this .= $key . $sign_hash{$key}; | ||
| 487 | } | ||
| 488 | |||
| 489 | Rex::Logger::debug("Signed: $sign_this"); | ||
| 490 | |||
| 491 | my $encoded = $self->_hash($sign_this); | ||
| 492 | |||
| 493 | my %params = ( | ||
| 494 | Action => $action, | ||
| 495 | SignatureVersion => $self->{"__signature_version"}, | ||
| 496 | AWSAccessKeyId => $self->{"__access_key"}, | ||
| 497 | Timestamp => $self->timestamp(), | ||
| 498 | Version => $self->{"__version"}, | ||
| 499 | Signature => $encoded, | ||
| 500 | %args | ||
| 501 | ); | ||
| 502 | |||
| 503 | return %params; | ||
| 504 | } | ||
| 505 | |||
| 506 | sub _hash { | ||
| 507 | my ( $self, $query_string ) = @_; | ||
| 508 | |||
| 509 | my $hashed = Digest::HMAC_SHA1->new( $self->{"__secret_access_key"} ); | ||
| 510 | $hashed->add($query_string); | ||
| 511 | |||
| 512 | return encode_base64( $hashed->digest, "" ); | ||
| 513 | } | ||
| 514 | |||
| 515 | sub _xml { | ||
| 516 | my ( $self, $xml ) = @_; | ||
| 517 | |||
| 518 | my $x = XML::Simple->new; | ||
| 519 | my $res = $x->XMLin($xml); | ||
| 520 | if ( defined $res->{"Errors"} ) { | ||
| 521 | if ( ref( $res->{"Errors"} ) ne "ARRAY" ) { | ||
| 522 | $res->{"Errors"} = [ $res->{"Errors"} ]; | ||
| 523 | } | ||
| 524 | |||
| 525 | my @error_msg = (); | ||
| 526 | for my $error ( @{ $res->{"Errors"} } ) { | ||
| 527 | push( @error_msg, | ||
| 528 | $error->{"Error"}->{"Message"} | ||
| 529 | . " (Code: " | ||
| 530 | . $error->{"Error"}->{"Code"} | ||
| 531 | . ")" ); | ||
| 532 | } | ||
| 533 | |||
| 534 | confess( join( "\n", @error_msg ) ); | ||
| 535 | } | ||
| 536 | |||
| 537 | return $res; | ||
| 538 | } | ||
| 539 | |||
| 540 | 1; |