Class: Fog::Vcloud::Terremark::Ecloud::Mock

Inherits:
Mock
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/vcloud/terremark/ecloud.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb,
lib/fog/vcloud/terremark/ecloud/requests/add_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_task.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_on.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_nodes.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_off.rb,
lib/fog/vcloud/terremark/ecloud/requests/clone_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/delete_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_catalog.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_reset.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_public_ip.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_task_list.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_shutdown.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_catalog_item.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_firewall_acl.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_firewall_acls.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_vapp_template.rb,
lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb,
lib/fog/vcloud/terremark/ecloud/requests/delete_internet_service.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_customization_options.rb,
lib/fog/vcloud/terremark/ecloud/requests/instantiate_vapp_template.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb,
lib/fog/vcloud/terremark/ecloud/requests/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

#ecloud_xmlns, #validate_backup_internet_service_data, #validate_internet_service_data, #validate_internet_service_monitor

Methods inherited from Mock

#get_organization, #get_versions, #login, #mock_error, #mock_it

Methods included from Shared

#default_organization_uri, #do_login, #ensure_unparsed, #supported_versions, #xmlns

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



83
84
# File 'lib/fog/vcloud/terremark/ecloud.rb', line 83

def initialize(options={})
end

Class Method Details

.base_urlObject



86
87
88
# File 'lib/fog/vcloud/terremark/ecloud.rb', line 86

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

.data(base_url = self.base_url) ⇒ Object



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
# File 'lib/fog/vcloud/terremark/ecloud.rb', line 95

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

    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



90
91
92
93
# File 'lib/fog/vcloud/terremark/ecloud.rb', line 90

def self.data_reset
  @mock_data = nil
  Fog::Vcloud::Mock.data_reset
end

Instance Method Details

#add_backup_internet_service(internet_services_uri, service_data) ⇒ Object



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

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb', line 120

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



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

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

#clone_vapp(vdc_uri, vapp_uri, customization_data) ⇒ Object



42
43
44
45
# File 'lib/fog/vcloud/terremark/ecloud/requests/clone_vapp.rb', line 42

def clone_vapp(vdc_uri, vapp_uri, customization_data)
  validate_customization_data(customization_data)
  Fog::Mock.not_implemented
end

#configure_internet_service(internet_service_uri, service_data, ip_address_data) ⇒ Object



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

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

  validate_internet_service_data(service_data, true)

  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(network_uri, network_data) ⇒ Object



46
47
48
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb', line 46

def configure_network(network_uri, network_data)
  Fog::Mock.not_implemented
end

#configure_network_ip(network_ip_uri, network_ip_data) ⇒ Object



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

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



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

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



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
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb', line 115

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



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

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



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

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



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

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



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

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



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/vcloud/terremark/ecloud/requests/get_catalog_item.rb', line 17

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_customization_options(options_uri) ⇒ Object



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

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_firewall_acl(firewall_acl_uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_firewall_acl.rb', line 11

def get_firewall_acl(firewall_acl_uri)
  Fog::Mock.not_implemented
end

#get_firewall_acls(firewall_acls_uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_firewall_acls.rb', line 11

def get_firewall_acls(firewall_acls_uri)
  Fog::Mock.not_implemented
end

#get_internet_services(internet_services_uri) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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



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/vcloud/terremark/ecloud/requests/get_nodes.rb', line 16

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_public_ip(public_ip_uri) ⇒ Object



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

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



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

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_task(task__uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_task.rb', line 11

def get_task(task__uri)
  Fog::Mock.not_implemented
end

#get_task_list(task_list_uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_task_list.rb', line 11

def get_task_list(task_list_uri)
  Fog::Mock.not_implemented
end

#get_vapp(vapp_uri) ⇒ Object



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

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_vapp_template(templace_uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_vapp_template.rb', line 11

def get_vapp_template(templace_uri)
  Fog::Mock.not_implemented
end

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

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

#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/vcloud/terremark/ecloud/requests/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

#mock_dataObject



170
171
172
# File 'lib/fog/vcloud/terremark/ecloud.rb', line 170

def mock_data
  Fog::Vcloud::Terremark::Ecloud::Mock.data
end

#mock_node_service_response(node) ⇒ Object



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

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



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

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



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

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



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

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

#power_reset(reset_uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/power_reset.rb', line 11

def power_reset(reset_uri)
  Fog::Mock.not_implemented
end

#power_shutdown(shutdown_uri) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/power_shutdown.rb', line 11

def power_shutdown(shutdown_uri)
  Fog::Mock.not_implemented
end

#return_vapp_as_creating!(name) ⇒ Object



11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb', line 11

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

#vapps_to_return_as_creatingObject



15
16
17
# File 'lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb', line 15

def vapps_to_return_as_creating
  @vapps_to_return_as_creating ||= {}
end