Class: Fog::Compute::Ecloud::Mock

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/ecloud/requests/compute/get_organizations.rb,
lib/fog/ecloud/compute.rb,
lib/fog/ecloud/requests/compute/get_row.rb,
lib/fog/ecloud/requests/compute/get_node.rb,
lib/fog/ecloud/requests/compute/get_rows.rb,
lib/fog/ecloud/requests/compute/get_task.rb,
lib/fog/ecloud/requests/compute/get_group.rb,
lib/fog/ecloud/requests/compute/get_nodes.rb,
lib/fog/ecloud/requests/compute/get_groups.rb,
lib/fog/ecloud/requests/compute/get_layout.rb,
lib/fog/ecloud/requests/compute/get_server.rb,
lib/fog/ecloud/requests/compute/get_layouts.rb,
lib/fog/ecloud/requests/compute/get_network.rb,
lib/fog/ecloud/requests/compute/get_servers.rb,
lib/fog/ecloud/requests/compute/get_ssh_key.rb,
lib/fog/ecloud/requests/compute/rows_delete.rb,
lib/fog/ecloud/requests/compute/get_networks.rb,
lib/fog/ecloud/requests/compute/get_ssh_keys.rb,
lib/fog/ecloud/requests/compute/get_template.rb,
lib/fog/ecloud/requests/compute/get_public_ip.rb,
lib/fog/ecloud/requests/compute/get_templates.rb,
lib/fog/ecloud/requests/compute/groups_delete.rb,
lib/fog/ecloud/requests/compute/get_ip_address.rb,
lib/fog/ecloud/requests/compute/get_public_ips.rb,
lib/fog/ecloud/requests/compute/get_environment.rb,
lib/fog/ecloud/requests/compute/get_compute_pool.rb,
lib/fog/ecloud/requests/compute/get_organization.rb,
lib/fog/ecloud/requests/compute/get_compute_pools.rb,
lib/fog/ecloud/requests/compute/get_detached_disk.rb,
lib/fog/ecloud/requests/compute/get_detached_disks.rb,
lib/fog/ecloud/requests/compute/node_service_create.rb,
lib/fog/ecloud/requests/compute/node_service_delete.rb,
lib/fog/ecloud/requests/compute/get_internet_service.rb,
lib/fog/ecloud/requests/compute/get_operating_system.rb,
lib/fog/ecloud/requests/compute/get_internet_services.rb,
lib/fog/ecloud/requests/compute/get_admin_organization.rb,
lib/fog/ecloud/requests/compute/virtual_machine_delete.rb,
lib/fog/ecloud/requests/compute/virtual_machine_import.rb,
lib/fog/ecloud/requests/compute/internet_service_create.rb,
lib/fog/ecloud/requests/compute/internet_service_delete.rb,
lib/fog/ecloud/requests/compute/get_hardware_configuration.rb,
lib/fog/ecloud/requests/compute/get_hardware_configurations.rb,
lib/fog/ecloud/requests/compute/virtual_machine_attach_disk.rb,
lib/fog/ecloud/requests/compute/virtual_machine_detach_disk.rb,
lib/fog/ecloud/requests/compute/get_operating_system_families.rb,
lib/fog/ecloud/requests/compute/get_virtual_machine_assigned_ips.rb,
lib/fog/ecloud/requests/compute/virtual_machine_edit_assigned_ips.rb,
lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb,
lib/fog/ecloud/requests/compute/virtual_machine_edit_hardware_configuration.rb

Overview

Real

Instance Attribute Summary

Attributes included from Shared

#base_path, #versions_uri

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared

#build_compute_pool_body_edit, #build_node_service_body_edit, #build_request_body, #build_request_body_attach_disk, #build_request_body_copy, #build_request_body_detach_disk, #build_request_body_edit, #build_request_body_edit_assigned_ips, #build_request_body_identical, #build_request_body_import, #default_organization_uri, #id_from_uri, #validate_create_server_options, #validate_create_server_options_copy, #validate_create_server_options_identical, #validate_data, #validate_edit_compute_pool_options, #validate_edit_internet_service_options, #validate_edit_node_service_options, #validate_edit_server_options, #validate_import_server_options, #validate_internet_service_data, #validate_node_service_data, #validate_upload_file_options

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



792
793
794
795
# File 'lib/fog/ecloud/compute.rb', line 792

def initialize(options={})
  @base_path = '/cloudapi/ecloud'
  @ecloud_api_key = options[:ecloud]
end

Class Method Details

.dataObject



414
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
541
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
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
# File 'lib/fog/ecloud/compute.rb', line 414

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = begin
                  compute_pool_id            = Fog.credentials[:ecloud_compute_pool_id]  || Fog::Mock.random_numbers(3).to_i
                  environment_id             = Fog.credentials[:ecloud_environment_id]   || Fog::Mock.random_numbers(3).to_i
                  public_ip_id               = Fog.credentials[:ecloud_public_ip_id]     || Fog::Mock.random_numbers(6).to_i
                  internet_service_id        = Fog::Mock.random_numbers(6).to_i
                  node_service_id            = Fog::Mock.random_numbers(6).to_i
                  environment_name           = Fog.credentials[:ecloud_environment_name] || Fog::Mock.random_letters(12)
                  location_id                = Fog::Mock.random_numbers(4).to_i
                  network_id                 = Fog.credentials[:ecloud_network_id]       || Fog::Mock.random_numbers(6).to_i
                  network_ip                 = Fog::Ecloud.ip_address
                  public_ip                  = Fog.credentials[:ecloud_public_ip_name]   || Fog::Ecloud.ip_address
                  ip_address_id              = Fog::Ecloud.ip_address
                  ip_address2_id             = Fog::Ecloud.ip_address
                  operating_system_id        = Fog::Mock.random_numbers(7).to_i
                  operating_system_family_id = Fog::Mock.random_numbers(7).to_i
                  organization_id            = Fog::Mock.random_numbers(7).to_i
                  organization_name          = Fog::Mock.random_letters(7)
                  template_id                = Fog.credentials[:ecloud_template_id]      || Fog::Mock.random_numbers(7).to_i
                  ssh_key_id                 = Fog.credentials[:ecloud_ssh_key_id]       || Fog::Mock.random_numbers(4).to_i
                  ssh_key_name               = Fog.credentials[:ecloud_ssh_key_name]     || "root"

                  environment = {
                    :id   => environment_id,
                    :href => "/cloudapi/ecloud/environments/#{environment_id}",
                    :name => environment_name,
                    :type => "application/vnd.tmrk.cloud.environment"
                  }

                  organization = {
                    :href => "/cloudapi/ecloud/organizations/#{organization_id}",
                    :type => "application/vnd.tmrk.cloud.organization",
                    :name => organization_name,
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(environment, :href, :name, :type),
                        {
                          :href => "/cloudapi/ecloud/admin/organizations/#{organization_id}",
                          :name => organization_name,
                          :type => "application/vnd.tmrk.cloud.admin.organization",
                          :rel  => "alternate",
                        },
                        {
                          :href => "/cloudapi/ecloud/devicetags/organizations/#{organization_id}",
                          :type => "application/vnd.tmrk.cloud.deviceTag; type=collection",
                          :rel  => "down",
                        },
                        {
                          :href => "/cloudapi/ecloud/alerts/organizations/#{organization_id}",
                          :type => "application/vnd.tmrk.cloud.alertLog",
                          :rel  => "down",
                        },
                      ],
                    },
                    :Locations => {
                      :Location => [
                        {
                          :href => "/cloudapi/ecloud/locations/#{location_id}",
                          :name => organization_name,
                          :Catalog => {
                            :href => "/cloudapi/ecloud/admin/catalog/organizations/#{organization_id}/locations/#{location_id}",
                          :type => "application/vnd.tmrk.cloud.admin.catalogEntry; type=collection"
                          },
                          :Environments => { :Environment => [environment] }
                        }
                      ]
                    }
                  }
                  environment.merge!(
                    :Links => {
                      :Link => [ Fog::Ecloud.keep(organization, :href, :name, :type), ]
                    }
                  )

                  admin_organization = {
                    :id    => organization_id,
                    :href  => "/cloudapi/ecloud/admin/organizations/#{organization_id}",
                    :type  => "application/vnd.tmrk.cloud.admin.organization",
                    :name  => organization_name,
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(organization, :href, :type, :name)
                      ],
                    },
                    :organization_id => organization_id,
                  }

                  compute_pool = {
                    :id             => compute_pool_id,
                    :href           => "/cloudapi/ecloud/computepools/#{compute_pool_id}",
                    :name           => Fog::Mock.random_letters(12),
                    :type           => "application/vnd.tmrk.cloud.computePool",
                    :environment_id => environment_id,
                    :Links          => {
                      :Link => [
                        Fog::Ecloud.keep(organization, :href, :name, :type),
                        Fog::Ecloud.keep(environment, :href, :name, :type),
                      ]
                    }
                  }

                  public_ip = {
                    :id             => public_ip_id,
                    :href           => "/cloudapi/ecloud/publicips/#{public_ip_id}",
                    :name           => public_ip,
                    :type           => "application/vnd.tmrk.cloud.publicIp",
                    :IpType         => "none",
                    :environment_id => environment_id,
                    :Links          => {
                      :Link => [
                        Fog::Ecloud.keep(environment, :href, :name, :type),
                      ],
                    },
                    :InternetServices => {
                      :InternetService => [
                      ],
                    },
                  }

                  internet_service = {
                    :id           => internet_service_id,
                    :href         => "/cloudapi/ecloud/internetservices/#{internet_service_id}",
                    :name         => Fog::Mock.random_letters(6),
                    :type         => "application/vnd.tmrk.cloud.internetService",
                    :public_ip_id => public_ip_id,
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(public_ip, :href, :name, :type),
                      ],
                    },
                    :NodeServices => {
                      :NodeService => [
                      ]
                    },
                  }

                  node_service = {
                    :id                  => node_service_id,
                    :href                => "/cloudapi/ecloud/nodeservices/#{node_service_id}",
                    :name                => Fog::Mock.random_letters(6),
                    :type                => "application/vnd.tmrk.cloud.nodeService",
                    :internet_service_id => internet_service_id,
                    :Links               => {
                      :Link => [
                        Fog::Ecloud.keep(internet_service, :href, :name, :type)
                      ],
                    },
                  }

                  internet_service[:NodeServices][:NodeService].push(node_service)
                  public_ip[:InternetServices][:InternetService].push(internet_service)

                  network = {
                    :id               => network_id,
                    :href             => "/cloudapi/ecloud/networks/#{network_id}",
                    :name             => "#{network_ip}/#{Fog::Mock.random_numbers(2)}",
                    :type             => "application/vnd.tmrk.cloud.network",
                    :Address          => network_ip,
                    :NetworkType      => "Dmz",
                    :BroadcastAddress => network_ip,
                    :GatewayAddress   => network_ip,
                    :environment_id   => environment_id,
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(environment, :href, :name, :type),
                      ]
                    },
                    :IpAddresses => {
                      :IpAddress => [],
                    },
                  }

                  ip_address = {
                      :id         => ip_address_id,
                      :href       => "/cloudapi/ecloud/ipaddresses/networks/#{network_id}/#{ip_address_id}",
                      :name       => ip_address_id,
                      :type       => "application/vnd.tmrk.cloud.ipAddress",
                      :network_id => network_id,
                      :Links      => {
                        :Link     => [ Fog::Ecloud.keep(network, :href, :name, :type), ],
                      },
                      :Reserved   => "false",
                      :Host       => nil,
                      :DetectedOn => nil,
                  }

                  ip_address2 = ip_address.dup.merge(:id => ip_address2_id, :href => "/cloudapi/ecloud/ipaddresses/networks/#{network_id}/#{ip_address2_id}", :name => ip_address2_id)

                  network[:IpAddresses][:IpAddress].push(ip_address).push(ip_address2)

                  short_name = "solaris10_64guest"
                  operating_system = {
                    :short_name      => short_name,
                    :compute_pool_id => compute_pool_id,
                    :href            => "/cloudapi/ecloud/operatingsystems/#{short_name}/computepools/#{compute_pool_id}",
                    :name            => "Sun Solaris 10 (64-bit)",
                    :type            => "application/vnd.tmrk.cloud.operatingSystem",
                    :FamilyName      => "Solaris",
                    :Links           => {
                      :Link => Fog::Ecloud.keep(compute_pool, :href, :name, :type),
                    },
                    :ConfigurationOptions => {
                      :Processor => {
                        :Minimum    => "1",
                        :Maximum    => "8",
                        :StepFactor => "1"
                      },
                      :Memory => {
                        :MinimumSize => {
                          :Unit  => "MB",
                          :Value => "800"
                        },
                        :MaximumSize => {
                          :Unit  => "MB",
                          :Value => "16384"
                        },
                        :StepFactor => {
                          :Unit  => "MB",
                          :Value => "4"
                        }
                      },
                      :Disk => {
                        :Minimum => "1",
                        :Maximum => "15",
                        :SystemDisk => {
                          :ResourceCapacityRange => {
                            :MinimumSize => {
                              :Unit => "GB",
                              :Value => "1"
                            },
                            :MaximumSize => {
                              :Unit => "GB",
                              :Value => "512"
                            },
                            :StepFactor => {
                              :Unit => "GB",
                              :Value => "1"}
                          },
                          :MonthlyCost => "0"
                        },
                        :DataDisk => {
                          :ResourceCapacityRange => {
                            :MinimumSize => {
                              :Unit => "GB",
                              :Value => "1"
                            },
                            :MaximumSize => {
                              :Unit => "GB",
                              :Value => "512"
                            },
                            :StepFactor => {
                              :Unit  => "GB",
                              :Value => "1"
                            }
                          },
                          :MonthlyCost => "0"
                        }
                      },
                      :NetworkAdapter=> {
                        :Minimum    => "1",
                        :Maximum    => "4",
                        :StepFactor => "1"
                      }
                    }
                  }

                  template = {
                    :id              => template_id,
                    :href            => "/cloudapi/ecloud/templates/#{template_id}/computepools/#{compute_pool_id}",
                    :type            => "application/vnd.tmrk.cloud.template",
                    :name            => "Sun Solaris 10 (x64)",
                    :compute_pool_id => compute_pool_id,
                    :OperatingSystem => Fog::Ecloud.keep(operating_system, :href, :name, :type),
                    :Memory => {
                      :MinimumSize => {
                        :Unit  => "MB",
                        :Value => "800"
                      },
                      :MaximumSize => {
                        :Unit  => "MB",
                        :Value => "16384"
                      },
                      :StepFactor => {
                        :Unit  => "MB",
                        :Value => "4"
                      }
                    },
                    :Storage => {
                      :Size => {
                        :Unit  => "GB",
                        :Value => "7"
                      }
                    },
                    :NetworkAdapters => "1",
                    :Links           => {
                      :Link => [
                        Fog::Ecloud.keep(compute_pool, :href, :name, :type),
                      ]
                    }
                  }

                  operating_system_family = {
                    :id                    => operating_system_family_id,
                    :compute_pool_id       => compute_pool_id,
                    :OperatingSystemFamily => {
                      :Name             => "Linux",
                      :OperatingSystems => {
                        :OperatingSystem => [Fog::Ecloud.keep(operating_system, :href, :name, :type)],
                      }
                    },
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(compute_pool, :href, :name, :type),
                      ]
                    }
                  }

                  ssh_key = {
                    :id                    => ssh_key_id,
                    :href                  => "/cloudapi/ecloud/admin/sshKeys/#{ssh_key_id}",
                    :name                  => ssh_key_name,
                    :admin_organization_id => organization_id,
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(admin_organization, :href, :name, :type),
                        Fog::Ecloud.keep(organization, :href, :name, :type),
                      ]
                    },
                    :Default => "true",
                    :FingerPrint => Fog::Ecloud.mac_address
                  }

                  layout = {
                    :id => environment_id,
                    :href => "/cloudapi/ecloud/layout/environments/#{environment_id}",
                    :type => "application/vnd.tmrk.cloud.deviceLayout",
                    :Links => {
                      :Link => [
                        Fog::Ecloud.keep(environment, :name, :href, :type),
                      ],
                    },
                    :Rows => {
                      :Row => [
                      ],
                    },
                    :environment_id => environment_id
                  }

                  {
                    :compute_pools             => {compute_pool_id            => compute_pool},
                    :environments              => {environment_id             => environment},
                    :public_ips                => {public_ip_id               => public_ip},
                    :internet_services         => {internet_service_id        => internet_service},
                    :node_services             => {node_service_id            => node_service},
                    :networks                  => {network_id                 => network},
                    :organizations             => {organization_id            => organization},
                    :admin_organizations       => {organization_id            => admin_organization},
                    :operating_systems         => {operating_system_id        => operating_system},
                    :operating_system_families => {operating_system_family_id => operating_system_family},
                    :servers                   => {},
                    :tasks                     => {},
                    :templates                 => {template_id                => template},
                    :ssh_keys                  => {ssh_key_id                 => ssh_key},
                    :detached_disks            => {},
                    :template_href             => (Fog.credentials[:ecloud_template_href] || "/cloudapi/ecloud/templates/#{template_id}/computepools/#{compute_pool_id}"),
                    :rows                      => {},
                    :groups                    => {},
                    :layouts                   => {environment_id             => layout},
                  }
                end
  end
end

.resetObject



788
789
790
# File 'lib/fog/ecloud/compute.rb', line 788

def self.reset
  @data = nil
end

Instance Method Details

#dataObject



797
798
799
# File 'lib/fog/ecloud/compute.rb', line 797

def data
  self.class.data[@ecloud_api_key]
end

#deep_copy(o) ⇒ Object



819
820
821
# File 'lib/fog/ecloud/compute.rb', line 819

def deep_copy(o)
  Marshal.load(Marshal.dump(o))
end

#get_admin_organization(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/ecloud/requests/compute/get_admin_organization.rb', line 9

def get_admin_organization(uri)
  organization_id = id_from_uri(uri)
  admin_organization    = self.data[:admin_organizations][organization_id]

  if admin_organization
    body = Fog::Ecloud.slice(admin_organization, :id, :organization_id)

    response(:body => body)
  else response(:status => 404) # ?
  end
end

#get_compute_pool(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_compute_pool.rb', line 9

def get_compute_pool(uri)
  compute_pool_id = id_from_uri(uri)
  compute_pool = self.data[:compute_pools][compute_pool_id]

  if compute_pool
    response(:body => Fog::Ecloud.slice(compute_pool, :id, :environment))
  else response(:status => 404) # ?
  end
end

#get_compute_pools(uri) ⇒ Object

/cloudapi/ecloud/computepools/environments/534



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/ecloud/requests/compute/get_compute_pools.rb', line 9

def get_compute_pools(uri) # /cloudapi/ecloud/computepools/environments/534
  environment_id = id_from_uri(uri)
  environment    = self.data[:environments][environment_id]

  compute_pools  = self.data[:compute_pools].values.select{|cp| cp[:environment_id] == environment_id}

  compute_pools = compute_pools.map{|cp| Fog::Ecloud.slice(cp, :id, :environment_id)}

  compute_pool_response = {:ComputePool => (compute_pools.size > 1 ? compute_pools : compute_pools.first)} # GAH
  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.computePool; type=collection",
    :Links => {
      :Link => environment,
    }
  }.merge(compute_pool_response)

  response(:body => body)
end

#get_detached_disk(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_detached_disk.rb', line 9

def get_detached_disk(uri)
  detached_disk_id = id_from_uri(uri)
  detached_disk    = self.data[:detached_disks][detached_disk_id]

  if detached_disk
    response(:body => Fog::Ecloud.slice(detached_disk, :id, :compute_pool_id))
  else raise Fog::Errors::NotFound
  end
end

#get_detached_disks(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/ecloud/requests/compute/get_detached_disks.rb', line 9

def get_detached_disks(uri)
  compute_pool_id = id_from_uri(uri)
  compute_pool    = self.data[:compute_pools][compute_pool_id]

  detached_disks  = self.data[:detached_disks].values.select{|cp| cp[:compute_pool_id] == compute_pool_id}

  detached_disks = detached_disks.map{|dd| Fog::Ecloud.slice(dd, :id, :compute_pool_id)}

  detached_disk_response = {:DetachedDisk => (detached_disks.size > 1 ? detached_disks : detached_disks.first)} # GAH
  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.detachedDisk; type=collection",
    :Links => {
      :Link => Fog::Ecloud.keep(compute_pool, :name, :href, :type),
    }
  }.merge(detached_disk_response)

  response(:body => body)
end

#get_environment(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/ecloud/requests/compute/get_environment.rb', line 9

def get_environment(uri)
  environment_id = id_from_uri(uri)
  organizations = self.data[:organizations].values
  environment = nil
  catch(:found) do
    organizations.each do |organization|
      organization[:Locations][:Location].each do |location|
        environment = location[:Environments][:Environment].find{|e| e[:id] == environment_id}
        throw :found if environment
      end
    end
  end
  if environment
    body = environment.dup
    body.delete(:id)
    response(:body => body)
  else response(:status => 404) # ?
  end
end

#get_group(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_group.rb', line 9

def get_group(uri)
  group_id = id_from_uri(uri)
  group = self.data[:groups][group_id]

  response(:body =>  group)
end

#get_groups(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_groups.rb', line 9

def get_groups(uri)
  row_id = id_from_uri(uri)
  row = self.data[:rows][row_id]

  response(:body =>  row)
end

#get_hardware_configuration(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/ecloud/requests/compute/get_hardware_configuration.rb', line 9

def get_hardware_configuration(uri)
  server_id = uri.match(/(\d+)/)[1]

  server = self.data[:servers][server_id.to_i]
  server_hardware_configuration = server[:HardwareConfiguration]

  new_hardware_configuration = {
    :href           => server_hardware_configuration[:href],
    :type           => server_hardware_configuration[:type],
    :ProcessorCount => server_hardware_configuration[:ProcessorCount],
    :Memory         => server_hardware_configuration[:Memory],
    :Disks          => server_hardware_configuration[:Disks],
    :Nics           => server_hardware_configuration[:Nics],
  }

  response(:body => {:HardwareConfiguration => new_hardware_configuration})
end

#get_hardware_configurations(uri) ⇒ Object



9
10
# File 'lib/fog/ecloud/requests/compute/get_hardware_configurations.rb', line 9

def get_hardware_configurations(uri)
end

#get_internet_service(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_internet_service.rb', line 9

def get_internet_service(uri)
  internet_service_id = id_from_uri(uri)
  internet_service    = self.data[:internet_services][internet_service_id.to_i]

  if internet_service
    response(:body => Fog::Ecloud.slice(internet_service, :id, :public_ip))
  else raise Fog::Errors::NotFound
  end
end

#get_internet_services(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_internet_services.rb', line 9

def get_internet_services(uri)
  public_ip_id = id_from_uri(uri)
  public_ip    = self.data[:public_ips][public_ip_id]

  response(:body => Fog::Ecloud.slice(public_ip, :environment_id))
end

#get_ip_address(uri) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/fog/ecloud/requests/compute/get_ip_address.rb', line 9

def get_ip_address(uri)
  network_id, ip_address_id = uri.match(/\/networks\/(\d+)\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/).captures
  ip_address = self.data[:networks][network_id.to_i][:IpAddresses][:IpAddress].find{|ip| ip[:name] == ip_address_id }.dup
  if ip_address
    response(:body => ip_address)
  else response(:status => 404) # ?
  end
end

#get_layout(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_layout.rb', line 9

def get_layout(uri)
  environment_id = id_from_uri(uri)
  layout = self.data[:layouts][environment_id]

  response(:body =>  layout)
end

#get_layouts(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_layouts.rb', line 9

def get_layouts(uri)
  environment_id = id_from_uri(uri)
  layout = self.data[:layouts][environment_id]

  response(:body =>  layout)
end

#get_network(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_network.rb', line 9

def get_network(uri)
  network_id = id_from_uri(uri)
  network    = self.data[:networks][network_id].dup

  if network
    response(:body => Fog::Ecloud.slice(network, :id, :environment_id))
  else response(:status => 404) # ?
  end
end

#get_networks(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/ecloud/requests/compute/get_networks.rb', line 9

def get_networks(uri)
  environment_id = id_from_uri(uri)
  environment = self.data[:environments][environment_id]

  networks = self.data[:networks].values.select{|n| n[:environment_id] == environment_id}.dup
  networks = networks.map{|n| Fog::Ecloud.slice(n, :environment, :id)}

  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.network; type=collection",
    :Links => {
      :Link => Fog::Ecloud.keep(environment, :name, :href, :type)
    },
    :Network => (networks.size > 1 ? networks : networks.first),
  }

  response(:body =>  body)
end

#get_node(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_node.rb', line 9

def get_node(uri)
  node_service_id = id_from_uri(uri)
  node_service    = self.data[:node_services][node_service_id.to_i]

  if node_service
    response(:body => Fog::Ecloud.slice(node_service, :id, :internet_service_id))
  else raise Fog::Errors::NotFound
  end
end

#get_nodes(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_nodes.rb', line 9

def get_nodes(uri)
  internet_service_id = id_from_uri(uri)
  internet_service    = self.data[:internet_services][internet_service_id]

  response(:body => internet_service)
end

#get_operating_system(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/ecloud/requests/compute/get_operating_system.rb', line 9

def get_operating_system(uri)
  os_name, compute_pool_id = uri.match(/operatingsystems\/(.*)\/computepools\/(\d+)$/).captures
  compute_pool_id          = compute_pool_id.to_i

  operating_systems = self.data[:operating_systems].values.select{|os| os[:compute_pool_id] == compute_pool_id}
  operating_system = operating_systems.find{|os| os[:short_name] == os_name}

  if operating_system
    response(:body => Fog::Ecloud.slice(operating_system, :id, :compute_pool_id, :short_name))
  else response(:status => 404) # ?
  end
end

#get_operating_system_families(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/ecloud/requests/compute/get_operating_system_families.rb', line 9

def get_operating_system_families(uri)
  compute_pool_id = id_from_uri(uri)
  compute_pool    = self.data[:compute_pools][compute_pool_id]

  operating_system_families = self.data[:operating_system_families].values.select{|osf| osf[:compute_pool_id] == compute_pool_id}
  operating_system_families = operating_system_families.map{|osf| Fog::Ecloud.slice(osf, :id, :compute_pool_id)}.map{|osf| osf[:OperatingSystemFamily]}

  operating_system_family_response = {:OperatingSystemFamily => (operating_system_families.size > 1 ? operating_system_families : operating_system_families.first)} # GAH
  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.operatingSystemFamily; type=collection",
    :Links => {
      :Link => compute_pool,
    }
  }.merge(operating_system_family_response)

  response(:body => body)
end

#get_organization(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/ecloud/requests/compute/get_organization.rb', line 9

def get_organization(uri)
  organization_id = id_from_uri(uri)
  organization    = self.data[:organizations][organization_id]

  body = {
    :xmlns_i => "http://www.w3.org/2001/XMLSchema-instance",
    :href    => "/cloudapi/ecloud/organizations/",
    :type    => "application/vnd.tmrk.cloud.organization; type=collection"
  }.merge(organization)

  response(:body => body)
end

#get_organizations(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/ecloud/requests/compute/get_organizations.rb', line 9

def get_organizations(uri)
  organizations = self.data[:organizations].values.dup
  organizations.each{|org| org.delete(:id)}
  body = {
    :xmlns_i => "http://www.w3.org/2001/XMLSchema-instance",
    :href    => "/cloudapi/ecloud/organizations/",
    :type    => "application/vnd.tmrk.cloud.organization; type=collection"
  }.merge(:Organization => (organizations.size > 1 ? organizations : organizations.first))

  response(:body => body)
end

#get_public_ip(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_public_ip.rb', line 9

def get_public_ip(uri)
  public_ip_id = id_from_uri(uri)
  public_ip    = self.data[:public_ips][public_ip_id]

  if public_ip
    response(:body => Fog::Ecloud.slice(public_ip, :id, :environment_id))
  else raise Fog::Errors::NotFound
  end
end

#get_public_ips(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/ecloud/requests/compute/get_public_ips.rb', line 9

def get_public_ips(uri)
  environment_id = id_from_uri(uri)
  environment    = self.data[:environments][environment_id]

  public_ips  = self.data[:public_ips].values.select{|cp| cp[:environment_id] == environment_id}

  public_ips = public_ips.map{|pi| Fog::Ecloud.slice(pi, :id, :environment_id)}

  public_ip_response = {:PublicIp => (public_ips.size > 1 ? public_ips : public_ips.first)} # GAH
  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.publicIp; type=collection",
    :Links => {
      :Link => environment,
    }
  }.merge(public_ip_response)

  response(:body => body)
end

#get_row(uri) ⇒ Object



9
10
11
12
13
14
# File 'lib/fog/ecloud/requests/compute/get_row.rb', line 9

def get_row(uri)
  row_id = id_from_uri(uri)
  row = self.data[:rows][row_id]

  response(:body =>  row)
end

#get_server(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_server.rb', line 9

def get_server(uri)
  server_id = uri.match(/(\d+)/)
  server_id = server_id.nil? ? nil : server_id[1].to_i
  server = self.data[:servers][server_id]
  if server
    response(:body => Fog::Ecloud.slice(server, :id, :compute_pool_id))
  else raise Fog::Errors::NotFound
  end
end

#get_servers(uri) ⇒ Object



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
# File 'lib/fog/ecloud/requests/compute/get_servers.rb', line 8

def get_servers(uri)
  if uri =~ /layoutgroups/i
    group_id        = id_from_uri(uri)
    group           = self.data[:groups][group_id]
    servers         = group[:VirtualMachines][:VirtualMachine]
    compute_pool_id = servers.first[:compute_pool_id] unless servers.empty?
    compute_pool    = self.data[:compute_pools][compute_pool_id] unless compute_pool_id.nil?
  elsif uri =~ /computepool/i
    compute_pool_id = id_from_uri(uri)
    compute_pool    = self.data[:compute_pools][compute_pool_id]
    servers = self.data[:servers].values.select{|cp| cp[:compute_pool_id] == compute_pool_id}
    servers = servers.map{|server| Fog::Ecloud.slice(server, :id, :compute_pool_id)}
  end

  links = if compute_pool.nil?
            []
          else
            [Fog::Ecloud.keep(compute_pool, :name, :href, :type),]
          end

  server_response = {:VirtualMachine => (servers.size > 1 ? servers : servers.first)} # GAH
  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.virtualMachine; type=collection",
    :Links => {
      :Link => links
    }
  }.merge(server_response)

  response(:body => body)
end

#get_ssh_key(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_ssh_key.rb', line 9

def get_ssh_key(uri)
  ssh_key_id = id_from_uri(uri).to_i
  ssh_key    = self.data[:ssh_keys][ssh_key_id.to_i]

  if ssh_key
    response(:body => Fog::Ecloud.slice(ssh_key, :id, :admin_organization))
  else response(:status => 404) # ?
  end
end

#get_ssh_keys(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/ecloud/requests/compute/get_ssh_keys.rb', line 9

def get_ssh_keys(uri)
  organization_id = id_from_uri(uri)
  organization    = self.data[:organizations][organization_id]

  ssh_keys = self.data[:ssh_keys].values.select{|key| key[:admin_organization_id] == organization_id}
  ssh_keys = ssh_keys.map{|key| Fog::Ecloud.slice(key, :id, :admin_organization)}

  ssh_key_response = {:SshKey => (ssh_keys.size > 1 ? ssh_keys : ssh_keys.first)} # GAH
  body = {
    :href  => "/cloudapi/ecloud/admin/organizations/#{organization_id}/sshKeys",
    :type  => "application/vnd.tmrk.cloud.sshKey; type=collection",
    :Links => {
      :Link => organization,
    },
  }.merge(ssh_key_response)

  response(:body => body)
end

#get_task(uri) ⇒ Object



8
9
# File 'lib/fog/ecloud/requests/compute/get_task.rb', line 8

def get_task(uri)
end

#get_template(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/get_template.rb', line 9

def get_template(uri)
  template_id, compute_pool_id = uri.match(/(\d+).*\/(\d+)$/).captures
  template    = self.data[:templates][template_id.to_i]

  if template
    response(:body => Fog::Ecloud.slice(template, :id, :environment))
  else response(:status => 404) # ?
  end
end

#get_templates(uri) ⇒ Object

/cloudapi/ecloud/computepools/compute_pools/534



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
# File 'lib/fog/ecloud/requests/compute/get_templates.rb', line 9

def get_templates(uri) # /cloudapi/ecloud/computepools/compute_pools/534
  compute_pool_id = id_from_uri(uri)
  compute_pool    = self.data[:compute_pools][compute_pool_id]

  templates = self.data[:templates].values.select{|template| template[:compute_pool_id] == compute_pool_id}
  templates = templates.map{|template| Fog::Ecloud.slice(template, :id, :compute_pool)}

  template_response = {:Template => (templates.size > 1 ? templates : templates.first)} # GAH
  body = {
    :href  => uri,
    :type  => "application/vnd.tmrk.cloud.template; type=collection",
    :Links => {
      :Link => compute_pool,
    },
    :Families => {
      :Family => {
        :Name => "Standard Templates",
        :Categories => {
          :Category => [
            {
              :Name => "OS Only",
              :OperatingSystems => {
                :OperatingSystem => {
                  :Name => "Linux",
                  :Templates => template_response,
                }
              }
            }
          ]
        }
      }
    }
  }

  response(:body => body)
end

#get_virtual_machine_assigned_ips(virtual_machine_id) ⇒ Object



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
# File 'lib/fog/ecloud/requests/compute/get_virtual_machine_assigned_ips.rb', line 14

def get_virtual_machine_assigned_ips(virtual_machine_id)
  server         = self.data[:servers][virtual_machine_id.to_i]
  compute_pool   = self.data[:compute_pools][server[:compute_pool_id]]
  environment_id = compute_pool[:environment_id]
  environment    = self.data[:environments][environment_id]

  networks = self.data[:networks].values.select{|n| n[:environment_id] == environment_id}
  networks = networks.map{|n| deep_copy(Fog::Ecloud.slice(n, :environment, :id))}

  networks.each do |network|
    address = network[:IpAddresses][:IpAddress].map{|ia| ia[:name]}
    network[:IpAddresses][:IpAddress] = address.first
  end

  body = {
    :href  => "/cloudapi/ecloud/virtualMachines/#{virtual_machine_id}/assignedIps",
    :type  => "application/vnd.tmrk.cloud.network",
    :Links => {
      :Link => Fog::Ecloud.keep(environment, :name, :href, :type)
    },
    :Networks => {:Network => (networks.size > 1 ? networks : networks.first)},
  }

  response(:body =>  body)
end

#groups_delete(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/ecloud/requests/compute/groups_delete.rb', line 9

def groups_delete(uri)
  group_id = id_from_uri(uri)
  self.data[:groups].delete(group_id)
  self.data[:rows].values.each do |row|
    row[:Groups][:Group].delete_if { |g| g[:id] == group_id }
  end
  self.data[:layouts].values.each do |layout|
    layout[:Rows][:Row].each do |row|
      row[:Groups][:Group].delete_if { |g| g[:id] == group_id }
    end
  end

  response(:body =>  nil, :status => 204)
end

#internet_service_create(service_data) ⇒ Object



67
68
69
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
95
96
97
98
# File 'lib/fog/ecloud/requests/compute/internet_service_create.rb', line 67

def internet_service_create(service_data)
  validate_internet_service_data(service_data)
  public_ip_id = service_data[:uri].match(/(\d+)/)[1]
  public_ip    = self.data[:public_ips][public_ip_id.to_i].dup
  service_id   = Fog::Mock.random_numbers(6).to_i
  service = {
    :href => "/cloudapi/ecloud/internetServices/#{service_id}",
    :name => service_data[:name],
    :type => "application/vnd.tmrk.cloud.internetService",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(public_ip, :href, :name, :type),
      ],
    },
    :Protocol    => service_data[:protocol],
    :Port        => service_data[:port],
    :Enabled     => service_data[:enabled],
    :Description => service_data[:description],
    :PublicIp    => Fog::Ecloud.keep(public_ip, :href, :name, :type),
    :Persistence => {
      :Type => service_data[:persistence][:type],
    },
  }

  internet_service_response = response(:body => service)

  service.merge!(:public_ip => public_ip)

  self.data[:internet_services][service_id] = service

  internet_service_response
end

#internet_service_delete(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/ecloud/requests/compute/internet_service_delete.rb', line 9

def internet_service_delete(uri)
  service_id = id_from_uri(uri)

  service = self.data[:internet_services][service_id].dup
  self.data[:internet_services].delete(service_id)

  task_id = Fog::Mock.random_numbers(10).to_i
  task = {
    :id            => task_id,
    :href          => "/cloudapi/ecloud/tasks/#{task_id}",
    :type          => "application/vnd.tmrk.cloud.task",
    :Operation     => "Delete Service",
    :Status        => "Complete",
    :ImpactedItem  => Fog::Ecloud.keep(service, :name, :href, :type),
    :StartTime     => Time.now.iso8601,
    :CompletedTime => Time.now.iso8601,
    :InitiatedBy   => {},
  }
  self.data[:tasks][task_id] = task
  response(:body => task)
end

#node_service_create(service_data) ⇒ Object



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
82
83
84
85
86
87
88
89
# File 'lib/fog/ecloud/requests/compute/node_service_create.rb', line 45

def node_service_create(service_data)
  validate_node_service_data(service_data)

  internet_service_id = service_data[:uri].match(/(\d+)/)[1]
  internet_service    = self.data[:internet_services][internet_service_id.to_i].dup
  network_id, ip_address_name     = service_data[:ip_address].match(/\/(\d+)\/(.*)$/).captures
  network = self.data[:networks][network_id.to_i]
  ip_addresses = network[:IpAddresses][:IpAddress]
  ip_addresses = ip_addresses.is_a?(Array) ? ip_addresses : [ip_addresses]
  ip_address = ip_addresses.find { |ip| ip[:name] == ip_address_name }

  service_id   = Fog::Mock.random_numbers(6).to_i
  service = {
    :href => "/cloudapi/ecloud/nodeservices/#{service_id}",
    :name => service_data[:name],
    :type => "application/vnd.tmrk.cloud.nodeService",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(internet_service, :href, :name, :type),
      ],
    },
    :Protocol    => service_data[:protocol],
    :Port        => service_data[:port],
    :Enabled     => service_data[:enabled],
    :Description => service_data[:description],
    :IpAddress   => {
      :href => ip_address[:href],
      :name => ip_address[:name],
      :type => ip_address[:type],
      :Network => {
        :href => network[:href],
        :name => network[:name],
        :type => network[:type],
      },
    },
  }

  node_service_response = response(:body => service)

  service.merge!(:internet_service => internet_service)

  self.data[:node_services][service_id] = service

  node_service_response
end

#node_service_delete(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/ecloud/requests/compute/node_service_delete.rb', line 9

def node_service_delete(uri)
  service_id = id_from_uri(uri)

  service = self.data[:node_services][service_id].dup
  self.data[:node_services].delete(service_id)

  task_id = Fog::Mock.random_numbers(10).to_i
  task = {
    :id            => task_id,
    :href          => "/cloudapi/ecloud/tasks/#{task_id}",
    :type          => "application/vnd.tmrk.cloud.task",
    :Operation     => "Delete Node Service",
    :Status        => "Complete",
    :ImpactedItem  => Fog::Ecloud.keep(service, :name, :href, :type),
    :StartTime     => Time.now.iso8601,
    :CompletedTime => Time.now.iso8601,
    :InitiatedBy   => {},
  }
  self.data[:tasks][task_id] = task
  response(:body => task)
end

#reset_dataObject



801
802
803
# File 'lib/fog/ecloud/compute.rb', line 801

def reset_data
  self.class.data.delete(@ecloud_api_key)
end

#response(params = {}) ⇒ Object



805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/fog/ecloud/compute.rb', line 805

def response(params={})
  body    = params[:body]
  headers = {
    "Content-Type" => "application/xml"
  }.merge(params[:headers] || {})
  status  = params[:status] || 200

  response = Excon::Response.new(:body => body, :headers => headers, :status => status)
  if params.key?(:expects) && ![*params[:expects]].include?(response.status)
    raise(Excon::Errors.status_error(params, response))
  else response
  end
end

#rows_delete(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/rows_delete.rb', line 9

def rows_delete(uri)
  row_id = id_from_uri(uri)
  self.data[:rows].delete(row_id)
  self.data[:layouts].values.each do |layout|
    layout[:Rows][:Row].delete_if { |r| r[:id] == row_id }
  end

  response(:body =>  nil, :status => 204)
end

#virtual_machine_attach_disk(href, options) ⇒ Object



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
# File 'lib/fog/ecloud/requests/compute/virtual_machine_attach_disk.rb', line 30

def virtual_machine_attach_disk(href, options)
  server_id        = href.match(/(\d+)/)[1].to_i
  server           = self.data[:servers][server_id]
  compute_pool_id  = server[:compute_pool_id]
  compute_pool     = self.data[:compute_pools][compute_pool_id]
  detached_disk_id = options[:href].match(/(\d+)/)[1].to_i
  detached_disk    = self.data[:detached_disks][detached_disk_id]
  new_index        = (server[:HardwareConfiguration][:Disks][:Disk].map { |h| h[:Index].to_i }.sort.last + 1).to_s
  detached_disk[:Index] = new_index
  server[:HardwareConfiguration][:Disks][:Disk] << Fog::Ecloud.keep(detached_disk, :Index, :Size, :Name)

  self.data[:detached_disks].delete(detached_disk_id)

  task_id = Fog::Mock.random_numbers(10).to_i
  task = {
    :id            => task_id,
    :href          => "/cloudapi/ecloud/tasks/#{task_id}",
    :type          => "application/vnd.tmrk.cloud.task",
    :Operation     => "Attach Disk",
    :Status        => "Complete",
    :ImpactedItem  => Fog::Ecloud.keep(server, :href, :type),
    :StartTime     => Time.now.iso8601,
    :CompletedTime => Time.now.iso8601,
    :InitiatedBy   => {},
  }
  self.data[:tasks][task_id] = task
  response(:body => task)
end

#virtual_machine_create_from_template(template_uri, options) ⇒ Object



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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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
# File 'lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb', line 116

def virtual_machine_create_from_template(template_uri, options)
  options                      = validate_create_server_options(template_uri, options)
  server_id                    = Fog::Mock.random_numbers(7).to_i
  row_id                       = Fog::Mock.random_numbers(6).to_i
  group_id                     = Fog::Mock.random_numbers(6).to_i
  template_id, compute_pool_id = template_uri.match(/\/templates\/(\d+)\/computepools\/(\d+)$/).captures
  compute_pool                 = self.data[:compute_pools][compute_pool_id.to_i].dup
  environment                  = self.data[:environments][compute_pool[:environment_id]]
  layout                       = self.data[:layouts][environment[:id]]
  networks                     = options[:network_uri]
  nics                         = networks.each_with_index.map do |network, i|
    {
      :UnitNumber => i.to_s,
      :Name       => "Network adapter #{i}",
      :MacAddress => Fog::Ecloud.mac_address,
      :Network    => Fog::Ecloud.keep(network, :name, :href, :type),
    }
  end

  links = [Fog::Ecloud.keep(compute_pool, :name, :href, :type), Fog::Ecloud.keep(environment, :name, :href, :type)]
  networks.each do |network|
    links << Fog::Ecloud.keep(network, :name, :href, :type)
    network_id = id_from_uri(network[:href])
    ip = self.data[:networks][network_id][:IpAddresses][:IpAddress].find { |ip| ip[:id] = network[:ip] }
    ip[:DetectedOn] = {:href => "/cloudapi/ecloud/networkhosts/#{server_id}", :name => options[:name], :type => "application/vnd.tmrk.cloud.networkHost"}
    ip[:Host]       = {:href => "/cloudapi/ecloud/networkhosts/#{server_id}", :name => options[:name], :type => "application/vnd.tmrk.cloud.networkHost"}
  end

  server = {
    :href                  => "/cloudapi/ecloud/virtualmachines/#{server_id}",
    :name                  => options[:name],
    :type                  => "application/vnd.tmrk.cloud.virtualMachine",
    :Description           => options[:description],
    :Status                => "Deployed",
    :HardwareConfiguration => {
      :href => "/cloudapi/ecloud/virtualmachines/#{server_id}/hardwareconfiguration",
      :type => "application/vnd.tmrk.cloud.virtualMachineHardware",
      :Links => {
        :Link => {
          :href => "/cloudapi/ecloud/virtualmachines/#{server_id}",
          :name => options[:name],
          :type => "application/vnd.tmrk.cloud.virtualMachine",
          :rel  => "up",
        }
      },
      :ProcessorCount => options[:cpus],
      :Memory => {
        :Unit  => "MB",
        :Value => options[:memory],
      },
      :Disks => {
        :Disk => [{
          :Index => "0",
          :Name  => "Hard Disk 1",
          :Size  => {
            :Unit  => "GB",
            :Value => "25",
          },
        }],
      },
      :Nics => {
        :Nic => nics,
      },
    },
    :IpAddresses => {
      :AssignedIpAddresses => {
        :Networks => {
          :Network => self.data[:networks].dup.values,
        }
      }
    },
    :Links => { :Link => links },
  }

  row = {
    :id => row_id,
    :name => options[:row],
    :href => "/cloudapi/ecloud/layoutrows/#{row_id}",
    :type => "application/vnd.tmrk.cloud.layoutRow",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(environment, :name, :href, :type)
      ],
    },
    :Index => 0,
    :Groups => {
      :Group => [
      ],
    },
    :environment_id => environment[:id],
  }

  group = {
    :id => group_id,
    :name => options[:group],
    :href => "/cloudapi/ecloud/layoutgroups/#{group_id}",
    :type => "application/vnd.tmrk.cloud.layoutGroup",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(row, :name, :href, :type),
      ],
    },
    :Index => 0,
    :VirtualMachines => {
      :VirtualMachine => [
        server,
      ],
    },
    :row_id => row_id,
  }
  row[:Groups][:Group].push(group)
  layout[:Rows][:Row].push(row)

  server.merge!(:OperatingSystem => options[:operating_system].merge(:type => "application/vnd.tmrk.cloud.operatingSystem")) if options[:operating_system]

  server_response = response(:body =>  server)

  server.merge!(:compute_pool_id => compute_pool[:id])

  self.data[:servers][server_id] = server
  self.data[:rows][row_id]       = row
  self.data[:groups][group_id]   = group

  server_response
end

#virtual_machine_delete(uri) ⇒ Object



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
# File 'lib/fog/ecloud/requests/compute/virtual_machine_delete.rb', line 9

def virtual_machine_delete(uri)
  server_id = id_from_uri(uri)

  server = self.data[:servers][server_id]
  self.data[:servers].delete(server_id)
  self.data[:groups].values.each do |group|
    group[:VirtualMachines][:VirtualMachine].delete_if { |s| s[:name] == server[:name] }
  end
  self.data[:networks].values.each do |network|
    network[:IpAddresses][:IpAddress].each do |ip|
      unless ip[:Host].nil?
        ip[:Host] = nil if ip[:Host][:name] == server[:name]
      end
      unless ip[:DetectedOn].nil?
        ip[:DetectedOn] = nil if ip[:DetectedOn][:name] == server[:name]
      end
    end
  end
  task_id = Fog::Mock.random_numbers(10)
  task = {
    :id            => task_id,
    :href          => "/cloudapi/ecloud/tasks/#{task_id}",
    :type          => "application/vnd.tmrk.cloud.task",
    :Operation     => "Delete Server",
    :Status        => "Complete",
    :ImpactedItem  => Fog::Ecloud.keep(server, :name, :href, :type),
    :StartTime     => Time.now.iso8601,
    :CompletedTime => Time.now.iso8601,
    :InitiatedBy   => {},
  }
  self.data[:tasks][task_id] = task

  response(:body =>  task)
end

#virtual_machine_detach_disk(href, options) ⇒ Object



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
# File 'lib/fog/ecloud/requests/compute/virtual_machine_detach_disk.rb', line 31

def virtual_machine_detach_disk(href, options)
  server_id        = href.match(/(\d+)/)[1].to_i
  server           = self.data[:servers][server_id]
  compute_pool_id  = server[:compute_pool_id]
  compute_pool     = self.data[:compute_pools][compute_pool_id]
  detached_disk_id = Fog::Mock.random_numbers(6).to_i
  detached_disk    = {
    :id              => detached_disk_id,
    :href            => "/cloudapi/ecloud/detacheddisks/#{detached_disk_id}",
    :name            => options[:name],
    :type            => "application/vnd.tmrk.cloud.detachedDisk",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(compute_pool, :href, :name, :type),
      ],
    },
    :Description => options[:description],
    :LastKnownVirtualMachineConfiguration => Fog::Ecloud.keep(server, :name, :ProcessorCount, :Memory, :OperatingSystem),
    :Type => "Data",
    :Size => {
      :Unit  => "GB",
      :Value => options[:disk][:Size][:Value],
    },
    :Status => "Available",
  }

  server[:HardwareConfiguration][:Disks][:Disk].delete_if { |disk| disk[:Index] == options[:disk][:Index] }

  detached_disk_response = response(:body => detached_disk)

  detached_disk.merge!(:compute_pool_id => compute_pool_id)

  self.data[:detached_disks][detached_disk_id] = detached_disk

  detached_disk_response
end

#virtual_machine_edit_assigned_ips(href, options) ⇒ Object



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
# File 'lib/fog/ecloud/requests/compute/virtual_machine_edit_assigned_ips.rb', line 38

def virtual_machine_edit_assigned_ips(href, options)
  server_id       = href.match(/(\d+)/)[1].to_i
  server          = self.data[:servers][server_id]
  options.each do |network|
    network_id     = id_from_uri(network[:href])
    network        = self.data[:networks][network_id]
    options.each.each do |net|
      net[:ips].each do |ip|
        ip = network[:IpAddresses][:IpAddress].find { |iph| iph[:name] == ip }
        ip[:Host] = {
          :href => "/clouapi/ecloud/networkhosts/#{server_id}",
          :name => server[:name],
          :type => "application/vnd.tmrk.cloud.networkHost"
        }
        ip[:DetectedOn] = {
          :href => "/clouapi/ecloud/networkhosts/#{server_id}",
          :name => server[:name],
          :type => "application/vnd.tmrk.cloud.networkHost"
        }
      end
    end
  end

  task_id = Fog::Mock.random_numbers(10)
  task = {
    :id            => task_id,
    :href          => "/cloudapi/ecloud/tasks/#{task_id}",
    :type          => "application/vnd.tmrk.cloud.task",
    :Operation     => "Delete Server",
    :Status        => "Complete",
    :ImpactedItem  => Fog::Ecloud.keep(server, :name, :href, :type),
    :StartTime     => Time.now.iso8601,
    :CompletedTime => Time.now.iso8601,
    :InitiatedBy   => {},
  }
  self.data[:tasks][task_id] = task

  response(:body =>  task)
end

#virtual_machine_edit_hardware_configuration(vm_uri, data) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/ecloud/requests/compute/virtual_machine_edit_hardware_configuration.rb', line 52

def virtual_machine_edit_hardware_configuration(vm_uri, data)
  server_id = vm_uri.match(/(\d+)/)[1]

  server  = self.data[:servers][server_id.to_i]
  task_id = Fog::Mock.random_numbers(10)
  task = {
    :id            => task_id,
    :href          => "/cloudapi/ecloud/tasks/#{task_id}",
    :type          => "application/vnd.tmrk.cloud.task",
    :Operation     => "Configure Server",
    :Status        => "Complete",
    :ImpactedItem  => Fog::Ecloud.keep(server, :name, :href, :type),
    :StartTime     => Time.now.iso8601,
    :CompletedTime => Time.now.iso8601,
    :InitiatedBy   => {},
  }
  self.data[:tasks][task_id] = task

  response(:body =>  task)
end

#virtual_machine_import(template_uri, options) ⇒ Object



64
65
66
67
68
69
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
95
96
97
98
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/fog/ecloud/requests/compute/virtual_machine_import.rb', line 64

def virtual_machine_import(template_uri, options)
  options         = validate_import_server_options(template_uri, options)

  compute_pool_id = options[:uri].match(/computePools\/(\d+)/)[1].to_i
  compute_pool    = self.data[:compute_pools][compute_pool_id].dup
  environment     = self.data[:environments][compute_pool[:environment_id]]
  networks        = options[:network_uri].map{|nuri| self.data[:networks][id_from_uri(nuri)].dup}
  server_id       = Fog::Mock.random_numbers(6).to_i
  row_id          = Fog::Mock.random_numbers(6).to_i
  group_id        = Fog::Mock.random_numbers(6).to_i
  nics            = networks.each_with_index.map do |network, i|
    {
      :UnitNumber => i.to_s,
      :Name       => "Network adapter #{i}",
      :MacAddress => Fog::Ecloud.mac_address,
      :Network    => Fog::Ecloud.keep(network, :name, :href, :type)
    }
  end

  links = [Fog::Ecloud.keep(compute_pool, :name, :href, :type), Fog::Ecloud.keep(environment, :name, :href, :type)]
  networks.each{|network| links << Fog::Ecloud.keep(network, :name, :href, :type)}
  server = {
    :href        => "/cloudapi/ecloud/virtualmachines/#{server_id}",
    :name        => options[:name],
    :type        => "application/vnd.tmrk.cloud.virtualMachine",
    :Description => options[:description],
    :Status      => "Deployed",
    :PoweredOn   => "false",
    :HardwareConfiguration => {
      :href => "/cloudapi/ecloud/virtualmachines/#{server_id}/hardwareconfiguration",
      :type => "application/vnd.tmrk.cloud.virtualMachineHardware",
      :Links => {
        :Link => {
          :href => "/cloudapi/ecloud/virtualmachines/#{server_id}",
          :name => options[:name],
          :type => "application/vnd.tmrk.cloud.virtualMachine",
          :rel  => "up"
        }
      },
      :ProcessorCount => options[:cpus],
      :Memory => {
        :Unit  => "MB",
        :Value => options[:memory],
      },
      :Disks => { # Default drive
        :Disk => [{
          :Index => "0",
          :Name  => "Hard Disk 1",
          :Size  => {
            :Unit  => "GB",
            :Value => "25"
          },
        }],
      },
      :Nics => {
        :Nic => nics,
      },
    },
    :Links => { :Link => links },
  }

  row = {
    :id => row_id,
    :name => options[:row],
    :href => "/cloudapi/ecloud/layoutrows/#{row_id}",
    :type => "application/vnd.tmrk.cloud.layoutRow",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(environment, :name, :href, :type)
      ],
    },
    :Index => 0,
    :Groups => {
      :Group => [
      ],
    },
    :environment_id => environment[:id],
  }

  group = {
    :id => group_id,
    :name => options[:group],
    :href => "/cloudapi/ecloud/layoutgroups/#{group_id}",
    :type => "application/vnd.tmrk.cloud.layoutGroup",
    :Links => {
      :Link => [
        Fog::Ecloud.keep(row, :name, :href, :type),
      ],
    },
    :Index => 0,
    :VirtualMachines => {
      :VirtualMachine => [
        server,
      ],
    },
    :row_id => row_id,
  }
  row[:Groups][:Group].push(group)
  layout[:Rows][:Row].push(row)

  server.merge!(:OperatingSystem => options[:operating_system].merge(:type => "application/vnd.tmrk.cloud.operatingSystem")) if options[:operating_system]

  server_response = response(:body =>  server)

  server.merge!(:compute_pool_id => compute_pool_id)

  self.data[:servers][server_id] = server
  self.data[:rows][row_id]       = row
  self.data[:groups][group_id]   = group

  server_response
end