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

Inherits:
Object
  • Object
show all
Includes:
Shared, Ecloud::MockDataClasses
Defined in:
lib/fog/ecloud/compute.rb,
lib/fog/ecloud/requests/compute/login.rb,
lib/fog/ecloud/requests/compute/get_vdc.rb,
lib/fog/ecloud/requests/compute/add_node.rb,
lib/fog/ecloud/requests/compute/get_node.rb,
lib/fog/ecloud/requests/compute/get_vapp.rb,
lib/fog/ecloud/requests/compute/power_on.rb,
lib/fog/ecloud/requests/compute/get_nodes.rb,
lib/fog/ecloud/requests/compute/power_off.rb,
lib/fog/ecloud/requests/compute/delete_node.rb,
lib/fog/ecloud/requests/compute/delete_vapp.rb,
lib/fog/ecloud/requests/compute/get_catalog.rb,
lib/fog/ecloud/requests/compute/get_network.rb,
lib/fog/ecloud/requests/compute/get_versions.rb,
lib/fog/ecloud/requests/compute/get_public_ip.rb,
lib/fog/ecloud/requests/compute/configure_node.rb,
lib/fog/ecloud/requests/compute/configure_vapp.rb,
lib/fog/ecloud/requests/compute/get_network_ip.rb,
lib/fog/ecloud/requests/compute/get_public_ips.rb,
lib/fog/ecloud/requests/compute/get_network_ips.rb,
lib/fog/ecloud/requests/compute/get_catalog_item.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/add_internet_service.rb,
lib/fog/ecloud/requests/compute/configure_network_ip.rb,
lib/fog/ecloud/requests/compute/get_internet_services.rb,
lib/fog/ecloud/requests/compute/get_network_extensions.rb,
lib/fog/ecloud/requests/compute/delete_internet_service.rb,
lib/fog/ecloud/requests/compute/get_customization_options.rb,
lib/fog/ecloud/requests/compute/instantiate_vapp_template.rb,
lib/fog/ecloud/requests/compute/configure_internet_service.rb,
lib/fog/ecloud/requests/compute/add_backup_internet_service.rb

Instance Attribute Summary

Attributes included from Shared

#versions_uri

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared

#default_organization_uri, #do_login, #ecloud_xmlns, #ensure_monitor_defaults!, #ensure_unparsed, #supported_versions, #validate_backup_internet_service_data, #validate_internet_service_data, #validate_internet_service_monitor, #xmlns

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



1072
1073
1074
1075
1076
1077
# File 'lib/fog/ecloud/compute.rb', line 1072

def initialize(options = {})
  require 'builder'
  require 'fog/core/parser'

  @versions_uri = URI.parse('https://vcloud.fakey.com/api/versions')
end

Class Method Details

.base_urlObject



957
958
959
# File 'lib/fog/ecloud/compute.rb', line 957

def self.base_url
  "https://fakey.com/api/v0.8b-ext2.6"
end

.data(base_url = self.base_url) ⇒ Object



961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# File 'lib/fog/ecloud/compute.rb', line 961

def self.data( base_url = self.base_url )
  @mock_data ||= MockData.new.tap do |vcloud_mock_data|
    vcloud_mock_data.versions.clear
    vcloud_mock_data.versions << MockVersion.new(:version => "v0.8b-ext2.6", :supported => true)

    vcloud_mock_data.organizations << MockOrganization.new(:name => "Boom Inc.").tap do |mock_organization|
      mock_organization.vdcs << MockVdc.new(:name => "Boomstick").tap do |mock_vdc|
        mock_vdc.catalog.items << MockCatalogItem.new(:name => "Item 0").tap do |mock_catalog_item|
          mock_catalog_item.disks << MockVirtualMachineDisk.new(:size => 25 * 1024)
        end
        mock_vdc.catalog.items << MockCatalogItem.new(:name => "Item 1").tap do |mock_catalog_item|
          mock_catalog_item.disks << MockVirtualMachineDisk.new(:size => 25 * 1024)
        end
        mock_vdc.catalog.items << MockCatalogItem.new(:name => "Item 2").tap do |mock_catalog_item|
          mock_catalog_item.disks << MockVirtualMachineDisk.new(:size => 25 * 1024)
        end

        mock_vdc.networks << MockNetwork.new({ :subnet => "1.2.3.0/24" }, mock_vdc)
        mock_vdc.networks << MockNetwork.new({ :subnet => "4.5.6.0/24" }, mock_vdc)

        mock_vdc.virtual_machines << MockVirtualMachine.new({ :name => "Broom 1", :ip => "1.2.3.3" }, mock_vdc)
        mock_vdc.virtual_machines << MockVirtualMachine.new({ :name => "Broom 2", :ip => "1.2.3.4" }, mock_vdc)
        mock_vdc.virtual_machines << MockVirtualMachine.new({ :name => "Email!", :ip => "1.2.3.10" }, mock_vdc)
      end

      mock_organization.vdcs << MockVdc.new(:name => "Rock-n-Roll", :storage_allocated => 150, :storage_used => 40, :cpu_allocated => 1000, :memory_allocated => 2048).tap do |mock_vdc|
        mock_vdc.networks << MockNetwork.new({ :subnet => "7.8.9.0/24" }, mock_vdc)

        mock_vdc.virtual_machines << MockVirtualMachine.new({ :name => "Master Blaster", :ip => "7.8.9.10" }, mock_vdc)
      end
    end

    vcloud_mock_data.organizations.detect {|o| o.name == "Boom Inc." }.tap do |mock_organization|
      mock_organization.vdcs.detect {|v| v.name == "Boomstick" }.tap do |mock_vdc|
        mock_vdc.public_ip_collection.items << MockPublicIp.new(:name => "99.1.2.3").tap do |mock_public_ip|
          mock_public_ip.internet_service_collection.items << MockPublicIpInternetService.new({
                                                                                                :protocol => "HTTP",
                                                                                                :port => 80,
                                                                                                :name => "Web Site",
                                                                                                :description => "Web Servers",
                                                                                                :redirect_url => "http://fakey.com"
                                                                                              }, mock_public_ip.internet_service_collection
                                                                                              ).tap do |mock_public_ip_service|
            mock_public_ip_service.node_collection.items << MockPublicIpInternetServiceNode.new({:ip_address => "1.2.3.5", :name => "Test Node 1", :description => "web 1"}, mock_public_ip_service.node_collection)
            mock_public_ip_service.node_collection.items << MockPublicIpInternetServiceNode.new({:ip_address => "1.2.3.6", :name => "Test Node 2", :description => "web 2"}, mock_public_ip_service.node_collection)
            mock_public_ip_service.node_collection.items << MockPublicIpInternetServiceNode.new({:ip_address => "1.2.3.7", :name => "Test Node 3", :description => "web 3"}, mock_public_ip_service.node_collection)
          end

          mock_public_ip.internet_service_collection.items << MockPublicIpInternetService.new({
                                                                                                :protocol => "TCP",
                                                                                                :port => 7000,
                                                                                                :name => "An SSH Map",
                                                                                                :description => "SSH 1"
                                                                                              }, mock_public_ip.internet_service_collection
                                                                                              ).tap do |mock_public_ip_service|
            mock_public_ip_service.node_collection.items << MockPublicIpInternetServiceNode.new({ :ip_address => "1.2.3.5", :port => 22, :name => "SSH", :description => "web ssh" }, mock_public_ip_service.node_collection)
          end
        end

        mock_vdc.public_ip_collection.items << MockPublicIp.new(:name => "99.1.2.4").tap do |mock_public_ip|
          mock_public_ip.internet_service_collection.items << MockPublicIpInternetService.new({
                                                                                                :protocol => "HTTP",
                                                                                                :port => 80,
                                                                                                :name => "Web Site",
                                                                                                :description => "Web Servers",
                                                                                                :redirect_url => "http://fakey.com"
                                                                                              }, mock_public_ip.internet_service_collection
                                                                                              )

          mock_public_ip.internet_service_collection.items << MockPublicIpInternetService.new({
                                                                                                :protocol => "TCP",
                                                                                                :port => 7000,
                                                                                                :name => "An SSH Map",
                                                                                                :description => "SSH 2"
                                                                                              }, mock_public_ip.internet_service_collection
                                                                                              )
        end

        mock_vdc.public_ip_collection.items << MockPublicIp.new(:name => "99.1.9.7")

        mock_vdc.internet_service_collection.backup_internet_services << MockBackupInternetService.new({ :port => 10000, :protocol => "TCP"}, self)
      end

      mock_organization.vdcs.detect {|v| v.name == "Rock-n-Roll" }.tap do |mock_vdc|
        mock_vdc.public_ip_collection.items << MockPublicIp.new(:name => "99.99.99.99")
      end
    end

    vcloud_mock_data.organizations.each do |organization|
      organization.vdcs.each do |vdc|
        vdc.networks.each do |network|
          network[:rnat] = vdc.public_ip_collection.items.first.name
        end
        vdc.virtual_machines.each do |virtual_machine|
          virtual_machine.disks << MockVirtualMachineDisk.new(:size => 25 * 1024)
          virtual_machine.disks << MockVirtualMachineDisk.new(:size => 50 * 1024)
        end
      end
    end
  end
end

.data_resetObject



1067
1068
1069
1070
# File 'lib/fog/ecloud/compute.rb', line 1067

def self.data_reset
  Fog::Logger.deprecation("#{self} => #data_reset is deprecated, use #reset instead [light_black](#{caller.first})[/]")
  self.reset
end

.resetObject



1063
1064
1065
# File 'lib/fog/ecloud/compute.rb', line 1063

def self.reset
  @mock_data = nil
end

Instance Method Details

#add_backup_internet_service(internet_services_uri, service_data) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fog/ecloud/requests/compute/add_backup_internet_service.rb', line 62

def add_backup_internet_service(internet_services_uri, service_data)
  validate_backup_internet_service_data(service_data)

  internet_services_uri = ensure_unparsed(internet_services_uri)

  if vdc_internet_service_collection = mock_data.vdc_internet_service_collection_from_href(internet_services_uri)
    new_backup_internet_service = MockBackupInternetService.new(service_data, vdc_internet_service_collection.backup_internet_services)
    vdc_internet_service_collection.backup_internet_services << new_backup_internet_service
    xml = generate_backup_internet_service_added_response(new_backup_internet_service)

    mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#add_internet_service(internet_services_uri, service_data) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/fog/ecloud/requests/compute/add_internet_service.rb', line 131

def add_internet_service(internet_services_uri, service_data)
  validate_internet_service_data(service_data)

  internet_services_uri = ensure_unparsed(internet_services_uri)

  if public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri)
    new_public_ip_internet_service = MockPublicIpInternetService.new(service_data, public_ip_internet_service_collection)
    public_ip_internet_service_collection.items << new_public_ip_internet_service
    xml = generate_internet_service(Builder::XmlMarkup.new, new_public_ip_internet_service, true)

    mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#add_node(nodes_uri, node_data) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/fog/ecloud/requests/compute/add_node.rb', line 49

def add_node(nodes_uri, node_data)
  validate_node_data(node_data)
  if node_collection = mock_data.public_ip_internet_service_node_collection_from_href(ensure_unparsed(nodes_uri))
    new_node = MockPublicIpInternetServiceNode.new(node_data, node_collection)
    node_collection.items << new_node
    mock_it 200, mock_node_service_response(new_node), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#configure_internet_service(internet_service_uri, service_data, ip_address_data) ⇒ Object



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

def configure_internet_service(internet_service_uri, service_data, ip_address_data)
  service_data = service_data.dup

  validate_internet_service_data(service_data, true)

  if monitor = service_data[:monitor]
    validate_internet_service_monitor(monitor)
    ensure_monitor_defaults!(monitor)
  end

  validate_public_ip_address_data(ip_address_data)

  internet_service_uri = ensure_unparsed(internet_service_uri)

  backup_service_uri = service_data.delete(:backup_service_uri)
  backup_service = backup_service_uri && mock_data.backup_internet_service_from_href(backup_service_uri)

  xml = nil

  if (public_ip_internet_service = mock_data.public_ip_internet_service_from_href(internet_service_uri)) &&
      (backup_service_uri.nil? || backup_service)
    public_ip_internet_service.update(service_data.reject {|k, v| [:id, :href].include?(k) })
    public_ip_internet_service[:backup_service] = backup_service
    xml = generate_internet_service(Builder::XmlMarkup.new, public_ip_internet_service, true)
  end

  if xml
    mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#configure_network_ip(network_ip_uri, network_ip_data) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/ecloud/requests/compute/configure_network_ip.rb', line 49

def configure_network_ip(network_ip_uri, network_ip_data)
  validate_network_ip_data(network_ip_data)

  if network_ip = mock_data.network_ip_from_href(network_ip_uri)
    network_ip[:rnat] = network_ip_data[:rnat]

    builder = Builder::XmlMarkup.new
    xml = network_ip_response(builder, network_ip, ecloud_xmlns)

    mock_it 200, xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.ip+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#configure_node(node_uri, node_data) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/ecloud/requests/compute/configure_node.rb', line 40

def configure_node(node_uri, node_data)
  validate_node_data(node_data, true)

  if node = mock_data.public_ip_internet_service_node_from_href(ensure_unparsed(node_uri))
    node.update(node_data)
    #if node_data[:enabled] 
    #  node.enabled = (node_data[:enabled] == "true") ? true : false
    #end
    mock_it 200, mock_node_service_response(node), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#configure_vapp(vapp_uri, vapp_data) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/fog/ecloud/requests/compute/configure_vapp.rb', line 114

def configure_vapp(vapp_uri, vapp_data)
  validate_vapp_data(vapp_data)

  if vapp = mock_data.virtual_machine_from_href(vapp_uri)
    vapp_data.each do |key, value|
      case key
      when :cpus, :memory
        vapp[key] = value
      when :disks
        addresses_to_delete = vapp.disks.map {|d| d.address } - value.map {|d| d[:number] }
        addresses_to_delete.each do |address_to_delete|
          vapp.disks.delete(vapp.disks.at_address(address_to_delete))
        end

        current_addresses = vapp.disks.map {|d| d.address }
        disks_to_add = value.find_all {|d| !current_addresses.include?(d[:number]) }
        disks_to_add.each do |disk_to_add|
          vapp.disks << MockVirtualMachineDisk.new(:size => disk_to_add[:size] / 1024, :address => disk_to_add[:number])
        end
      end
    end

    mock_it 200, '', { "Location" => mock_data.base_url + "/some_tasks/1234" }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#delete_internet_service(service_uri) ⇒ Object



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

def delete_internet_service(service_uri)
  if public_ip_internet_service = mock_data.public_ip_internet_service_from_href(service_uri)
    public_ip_internet_service._parent.items.delete(public_ip_internet_service)

    mock_it 200, '', { }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#delete_node(node_uri) ⇒ Object



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

def delete_node(node_uri)
  if node = mock_data.public_ip_internet_service_node_from_href(ensure_unparsed(node_uri))
    node._parent.items.delete(node)
    mock_it 200, '', {}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#delete_vapp(vapp_uri) ⇒ Object



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

def delete_vapp(vapp_uri)
  if virtual_machine = mock_data.virtual_machine_from_href(vapp_uri)
    vdc = virtual_machine._parent

    if vdc.internet_service_collection.items.detect {|is| is.node_collection.items.any? {|isn| isn.ip_address == virtual_machine.ip } } ||
        virtual_machine.status != 2 ||
        virtual_machine.network_ip.rnat_set?
      mock_it 202, '', {}
    else
      vdc.virtual_machines.delete(virtual_machine)
      mock_it 202, '', { "Location" => mock_data.base_url + "/some_tasks/1234" }
    end
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_catalog(catalog_uri) ⇒ Object



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

def get_catalog(catalog_uri)
  catalog_uri = ensure_unparsed(catalog_uri)
  xml = nil

  if catalog = mock_data.catalog_from_href(catalog_uri)
    builder = Builder::XmlMarkup.new

    xml = builder.Catalog(xmlns.merge(
                                      :type => "application/vnd.vmware.vcloud.catalog+xml",
                                      :href => catalog.href,
                                      :name => catalog.name
                          )) do |xml|
      xml.CatalogItems do |xml|
        catalog.items.each do |catalog_item|
          xml.CatalogItem(
                          :type => "application/vnd.vmware.vcloud.catalogItem+xml",
                          :href => catalog_item.href,
                          :name => catalog_item.name
                          )
        end
      end
    end
  end

  if xml
    mock_it 200,
      xml, { 'Content-Type' => 'application/vnd.vmware.vcloud.catalog+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_catalog_item(catalog_item_uri) ⇒ Object



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

def get_catalog_item(catalog_item_uri)
  if catalog_item = mock_data.catalog_item_from_href(catalog_item_uri)
    builder = Builder::XmlMarkup.new

    xml = builder.CatalogItem(xmlns.merge(:href => catalog_item.href, :name => catalog_item.name)) do
      builder.Link(
                   :rel => "down",
                   :href => catalog_item.customization.href,
                   :type => "application/vnd.tmrk.ecloud.catalogItemCustomizationParameters+xml",
                   :name => catalog_item.customization.name
                   )

      builder.Entity(
                     :href => catalog_item.vapp_template.href,
                     :type => "application/vnd.vmware.vcloud.vAppTemplate+xml",
                     :name => catalog_item.vapp_template.name
                     )

      builder.Property(0, :key => "LicensingCost")
    end
  end

  if xml
    mock_it 200, xml, {'Content-Type' => 'application/vnd.vmware.vcloud.catalogItem+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_compute_pool(compute_pool_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/ecloud/requests/compute/get_compute_pool.rb', line 15

def get_compute_pool(compute_pool_uri)
  compute_pool_uri = ensure_unparsed(compute_pool_uri)

  if compute_pool = mock_data.compute_pool_from_href(compute_pool_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200,
      xml.ComputePool(:xmlns => "urn:tmrk:eCloudExtensions-2.8", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
        xml.Id compute_pool.object_id
        xml.Href compute_pool.href
        xml.Name compute_pool.name
        xml.State compute_pool.state
        xml.IsDefault compute_pool.is_default
      }, { 'Content-Type' => 'application/vnd.tmrk.ecloud.computePoolsList+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_compute_pools(compute_pools_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/ecloud/requests/compute/get_compute_pools.rb', line 15

def get_compute_pools(compute_pools_uri)
  compute_pools_uri = ensure_unparsed(compute_pools_uri)

  if compute_pool_collection = mock_data.compute_pool_collection_from_href(compute_pools_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200,
      xml.ComputePools {
        compute_pool_collection.items.each do |cp|
          xml.ComputePool {
            xml.Id cp.object_id
            xml.Href cp.href
            xml.Name cp.name
            xml.State cp.state
            xml.IsDefault cp.is_default
          }
        end
      }, { 'Content-Type' => 'application/vnd.tmrk.ecloud.computePoolsList+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_customization_options(options_uri) ⇒ Object



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

def get_customization_options(options_uri)
  builder = Builder::XmlMarkup.new
  xml = builder.CustomizationParameters(xmlns) do
    builder.CustomizeNetwork "true"
    builder.CustomizePassword "false"
  end

  mock_it 200, xml, "Content-Type" => "application/vnd.tmrk.ecloud.catalogItemCustomizationParameters+xml"
end

#get_internet_services(internet_services_uri) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/ecloud/requests/compute/get_internet_services.rb', line 17

def get_internet_services(internet_services_uri)
  internet_services_uri = ensure_unparsed(internet_services_uri)
  xml = nil

  if vdc_internet_service_collection = mock_data.vdc_internet_service_collection_from_href(internet_services_uri)
    xml = generate_internet_services(vdc_internet_service_collection.items)
  elsif public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri)
    xml = generate_internet_services(public_ip_internet_service_collection.items)
  end

  if xml
    mock_it 200,
      xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.internetServicesList+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_network(network_uri) ⇒ Object



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

def get_network(network_uri)
  network_uri = ensure_unparsed(network_uri)

  if network = mock_data.network_from_href(network_uri)
    builder = Builder::XmlMarkup.new
    xml = builder.Network(xmlns.merge(:href => network.href, :name => network.name, :type => "application/vnd.vmware.vcloud.network+xml")) {
      builder.Link(:rel => "down", :href => network.ip_collection.href, :type => "application/xml", :name => network.ip_collection.name)
      builder.Link(:rel => "down", :href => network.extensions.href, :type => "application/xml", :name => network.name)
      builder.Configuration {
        builder.Gateway(network.gateway)
        builder.Netmask(network.netmask)
      }
      if network.features
        builder.Features {
          network.features.each do |feature|
            builder.tag!(feature[:type], feature[:value])
          end
        }
      end
    }

    mock_it 200, xml, { "Content-Type" => "application/vnd.vmware.vcloud.network+xml" }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_network_extensions(network_extension_uri) ⇒ Object



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/get_network_extensions.rb', line 11

def get_network_extensions(network_extension_uri)
  if network_extension = mock_data.network_extension_from_href(ensure_unparsed(network_extension_uri))
    xml = Builder::XmlMarkup.new
    mock_it 200, xml.Network(ecloud_xmlns) {
      xml.Address network_extension.address
      xml.RnatAddress network_extension.rnat
      xml.Href network_extension.href
      xml.Id network_extension.object_id
      xml.Name network_extension.name
      xml.GatewayAddress network_extension.gateway
      xml.BroadcastAddress network_extension.broadcast
      xml.NetworkType network_extension.type
      xml.Vlan network_extension.vlan
      xml.FriendlyName network_extension.friendly_name
    }, { 'Content-Type' => "application/vnd.tmrk.ecloud.network+xml" }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_network_ip(network_ip_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/ecloud/requests/compute/get_network_ip.rb', line 15

def get_network_ip(network_ip_uri)
  if network_ip = mock_data.network_ip_from_href(network_ip_uri)
    builder = Builder::XmlMarkup.new
    xml = network_ip_response(builder, network_ip, ecloud_xmlns)

    mock_it 200, xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.ip+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_network_ips(network_ips_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/ecloud/requests/compute/get_network_ips.rb', line 15

def get_network_ips(network_ips_uri)
  network_ips_uri = ensure_unparsed(network_ips_uri)

  if network_ip_collection = mock_data.network_ip_collection_from_href(network_ips_uri)
    builder = Builder::XmlMarkup.new
    xml = builder.IpAddresses do
      network_ip_collection.ordered_ips.each do |network_ip|
        network_ip_response(builder, network_ip)
      end
    end

    mock_it 200, xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.ipAddressesList+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_node(node_uri) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/ecloud/requests/compute/get_node.rb', line 27

def get_node(node_uri)
  node_uri = ensure_unparsed(node_uri)

  if public_ip_internet_service_node = mock_data.public_ip_internet_service_node_from_href(node_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200, mock_node_service_response(public_ip_internet_service_node), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_nodes(nodes_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/ecloud/requests/compute/get_nodes.rb', line 15

def get_nodes(nodes_uri)
  nodes_uri = ensure_unparsed(nodes_uri)

  if public_ip_internet_service_node_collection = mock_data.public_ip_internet_service_node_collection_from_href(nodes_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200,
      xml.NodeServices(ecloud_xmlns) {
        public_ip_internet_service_node_collection.items.each do |node|
          xml.NodeService {
            xml.Id node.object_id
            xml.Href node.href
            xml.Name node.name
            xml.IpAddress node.ip_address
            xml.Port node.port
            xml.Enabled node.enabled
            xml.Description node.description
          }
        end
      }, { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_organization(organization_uri) ⇒ Object



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_organization.rb', line 11

def get_organization(organization_uri)
  #
  # Based off of:
  # http://support.theenterprisecloud.com/kb/default.asp?id=540&Lang=1&SID=
  #
  # vCloud API Guide v0.9 - Page 26
  #
  organization_uri = ensure_unparsed(organization_uri)
  if organization = mock_data.organization_from_href(organization_uri)
    xml = Builder::XmlMarkup.new

    mock_it 200,
      xml.Org(xmlns.merge(:href => organization.href, :name => organization.name)) {

        organization.vdcs.each do |vdc|
          xml.Link(:rel => "down",
                   :href => vdc.href,
                   :type => "application/vnd.vmware.vcloud.vdc+xml",
                   :name => vdc.name)
          xml.Link(:rel => "down",
                   :href => vdc.catalog.href,
                   :type => "application/vnd.vmware.vcloud.catalog+xml",
                   :name => vdc.catalog.name)
          xml.Link(:rel => "down",
                   :href => vdc.task_list.href,
                   :type => "application/vnd.vmware.vcloud.tasksList+xml",
                   :name => vdc.task_list.name)
        end
      },
      {'Content-Type' => "application/vnd.vmware.vcloud.org+xml" }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_public_ip(public_ip_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/ecloud/requests/compute/get_public_ip.rb', line 15

def get_public_ip(public_ip_uri)
  public_ip_uri = ensure_unparsed(public_ip_uri)

  if public_ip = mock_data.public_ip_from_href(public_ip_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200,
      xml.PublicIp(:xmlns => "urn:tmrk:eCloudExtensions-2.0", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
        xml.Id public_ip.object_id
        xml.Href public_ip.href
        xml.Name public_ip.name
      }, { 'Content-Type' => 'application/vnd.tmrk.ecloud.publicIp+xml' }
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_public_ips(public_ips_uri) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/ecloud/requests/compute/get_public_ips.rb', line 15

def get_public_ips(public_ips_uri)
  public_ips_uri = ensure_unparsed(public_ips_uri)

  if public_ip_collection = mock_data.public_ip_collection_from_href(public_ips_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200,
      xml.PublicIPAddresses {
        public_ip_collection.items.each do |ip|
          xml.PublicIPAddress {
            xml.Id ip.object_id
            xml.Href ip.href
            xml.Name ip.name
          }
        end
      }, { 'Content-Type' => 'application/vnd.tmrk.ecloud.publicIpsList+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_vapp(vapp_uri) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/ecloud/requests/compute/get_vapp.rb', line 18

def get_vapp(vapp_uri)
  xml = nil

  if vapp = mock_data.virtual_machine_from_href(vapp_uri)
    if vapps_to_return_as_creating[vapp.name]
      xml = generate_instantiate_vapp_template_response(vapp)
    else
      xml = generate_get_vapp_response(vapp)
    end
  end

  if xml
    mock_it 200, xml, "Content-Type" => "application/vnd.vmware.vcloud.vApp+xml"
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_vdc(vdc_uri) ⇒ 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fog/ecloud/requests/compute/get_vdc.rb', line 14

def get_vdc(vdc_uri)
  vdc_uri = ensure_unparsed(vdc_uri)

  if vdc = mock_data.vdc_from_href(vdc_uri)
    xml = Builder::XmlMarkup.new
    mock_it 200,
    xml.Vdc(xmlns.merge(:href => vdc.href, :name => vdc.name)) {
      xml.Link(:rel => "down",
               :href => vdc.catalog.href,
               :type => "application/vnd.vmware.vcloud.catalog+xml",
               :name => vdc.catalog.name)
      xml.Link(:rel => "down",
               :href => vdc.public_ip_collection.href,
               :type => "application/vnd.tmrk.ecloud.publicIpsList+xml",
               :name => vdc.public_ip_collection.name)
      xml.Link(:rel => "down",
               :href => vdc.internet_service_collection.href,
               :type => "application/vnd.tmrk.ecloud.internetServicesList+xml",
               :name => vdc.internet_service_collection.name)
      xml.Link(:rel => "down",
               :href => vdc.firewall_acls.href,
               :type => "application/vnd.tmrk.ecloud.firewallAclsList+xml",
               :name => vdc.firewall_acls.name)
      xml.Description("")
      xml.StorageCapacity {
        xml.Units("bytes * 10^9")
        xml.Allocated(vdc.storage_allocated)
        xml.Used(vdc.storage_used)
      }
      xml.ComputeCapacity {
        xml.Cpu {
          xml.Units("hz * 10^6")
          xml.Allocated(vdc.cpu_allocated)
        }
        xml.Memory {
          xml.Units("bytes * 2^20")
          xml.Allocated(vdc.memory_allocated)
        }
        xml.DeployedVmsQuota {
          xml.Limit("-1")
          xml.Used("-1")
        }
        xml.InstantiatedVmsQuota {
          xml.Limit("-1")
          xml.Used("-1")
        }
      }
      xml.ResourceEntities {
        vdc.virtual_machines.each do |virtual_machine|
          xml.ResourceEntity(:href => virtual_machine.href,
                             :type => "application/vnd.vmware.vcloud.vApp+xml",
                             :name => virtual_machine.name)
        end
      }
      xml.AvailableNetworks {
        vdc.networks.each do |network|
          xml.Network(:href => network.href,
                      :type => "application/vnd.vmware.vcloud.network+xml",
                      :name => network.name)
        end
      }
    }, { 'Content-Type' => 'application/vnd.vmware.vcloud.vdc+xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#get_versions(versions_uri) ⇒ Object



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

def get_versions(versions_uri)
  #
  # Based off of:
  # http://support.theenterprisecloud.com/kb/default.asp?id=535&Lang=1&SID=
  # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/02-get-versions.aspx
  # vCloud API Guide v0.9 - Page 89
  #
  xml = Builder::XmlMarkup.new

  mock_it 200,
    xml.SupportedVersions( xmlns.merge("xmlns" => "http://www.vmware.com/vcloud/versions")) {

      mock_data.versions.select {|version| version.supported }.each do |version|
        xml.VersionInfo {
          xml.Version(version.version)
          xml.LoginUrl(version.)
        }
      end
    }

end

#instantiate_vapp_template(catalog_item_uri, options = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fog/ecloud/requests/compute/instantiate_vapp_template.rb', line 104

def instantiate_vapp_template(catalog_item_uri, options = {})
  validate_instantiate_vapp_template_options(catalog_item_uri, options)
  catalog_item = mock_data.catalog_item_from_href(catalog_item_uri)

  xml = nil
  if vdc = mock_data.vdc_from_href(options[:vdc_uri])
    if network = mock_data.network_from_href(options[:network_uri])
      new_vm = MockVirtualMachine.new({ :name => options[:name], :ip => network.random_ip, :cpus => options[:cpus], :memory => options[:memory] }, vdc)
      new_vm.disks.push(*catalog_item.disks.dup)
      vdc.virtual_machines << new_vm

      xml = generate_instantiate_vapp_template_response(new_vm)
    end
  end

  if xml
    mock_it 200, xml, {'Content-Type' => 'application/xml'}
  else
    mock_error 200, "401 Unauthorized"
  end
end

#loginObject



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/login.rb', line 24

def 
  #
  # Based off of:
  # http://support.theenterprisecloud.com/kb/default.asp?id=536&Lang=1&SID=
  # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/01-get-login-token.aspx
  # vCloud API Guide v0.9 - Page 17
  #
  xml = Builder::XmlMarkup.new

  mock_it 200,
    xml.OrgList(xmlns) {
        mock_data.organizations.each do |organization|
          xml.Org( :type => "application/vnd.vmware.vcloud.org+xml", :href => organization.href, :name => organization.name )
        end
      },
      { 'Set-Cookie' => 'vcloud-token=fc020a05-21d7-4f33-9b2a-25d8cd05a44e; path=/',
        'Content-Type' => 'application/vnd.vmware.vcloud.orgslist+xml' }

end

#mock_dataObject



1079
1080
1081
# File 'lib/fog/ecloud/compute.rb', line 1079

def mock_data
  Fog::Compute::Ecloud::Mock.data
end

#mock_error(expected, status, body = '', headers = {}) ⇒ Object

Raises:

  • (Excon::Errors::Unauthorized)


1083
1084
1085
# File 'lib/fog/ecloud/compute.rb', line 1083

def mock_error(expected, status, body='', headers={})
  raise Excon::Errors::Unauthorized.new("Expected(#{expected}) <=> Actual(#{status})")
end

#mock_it(status, mock_data, mock_headers = {}) ⇒ Object



1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
# File 'lib/fog/ecloud/compute.rb', line 1087

def mock_it(status, mock_data, mock_headers = {})
  response = Excon::Response.new

  #Parse the response body into a hash
  if mock_data.empty?
    response.body = mock_data
  else
    document = Fog::ToHashDocument.new
    parser = Nokogiri::XML::SAX::PushParser.new(document)
    parser << mock_data
    parser.finish
    response.body = document.body
  end

  response.status = status
  response.headers = mock_headers
  response
end

#mock_node_service_response(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/ecloud/requests/compute/get_node.rb', line 14

def mock_node_service_response(node)
  xml = Builder::XmlMarkup.new
  xml.NodeService(ecloud_xmlns) {
    xml.Id(node.object_id)
    xml.Href(node.href)
    xml.Name(node.name)
    xml.IpAddress(node.ip_address)
    xml.Port(node.port)
    xml.Enabled(node.enabled)
    xml.Description(node.description)
  }
end

#network_ip_response(builder, network_ip, xmlns = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/ecloud/requests/compute/get_network_ip.rb', line 26

def network_ip_response(builder, network_ip, xmlns = {})
  builder.IpAddress(xmlns) do
    builder.Id network_ip.object_id
    builder.Href network_ip.href
    builder.Name network_ip.name

    builder.Status network_ip.status
    if network_ip.used_by
      builder.Server network_ip.used_by.name
    end

    builder.RnatAddress(network_ip.rnat)
  end
end

#power_off(vapp_uri) ⇒ Object



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

def power_off(vapp_uri)
  if vapp = mock_data.virtual_machine_from_href(vapp_uri)
    vapp.power_off!

    builder = Builder::XmlMarkup.new
    mock_it 200, builder.Task(xmlns)
  else
    mock_error 200, "401 Unauthorized"
  end
end

#power_on(vapp_uri) ⇒ Object



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

def power_on(vapp_uri)
  if vapp = mock_data.virtual_machine_from_href(vapp_uri)
    vapp.power_on!

    builder = Builder::XmlMarkup.new
    mock_it 200, builder.Task(xmlns)
  else
    mock_error 200, "401 Unauthorized"
  end
end

#return_vapp_as_creating!(name) ⇒ Object



10
11
12
# File 'lib/fog/ecloud/requests/compute/get_vapp.rb', line 10

def return_vapp_as_creating!(name)
  vapps_to_return_as_creating[name] = true
end

#vapps_to_return_as_creatingObject



14
15
16
# File 'lib/fog/ecloud/requests/compute/get_vapp.rb', line 14

def vapps_to_return_as_creating
  @vapps_to_return_as_creating ||= {}
end