# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # libcloud.org licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import unittest import exceptions from libcloud.drivers.vcloud import TerremarkDriver from libcloud.drivers.vcloud import VCloudNodeDriver from libcloud.base import Node, NodeImage, NodeSize from libcloud.types import NodeState from test import MockHttp, TestCaseMixin import httplib from secrets import TERREMARK_USER, TERREMARK_SECRET class TerremarkTests(unittest.TestCase, TestCaseMixin): def setUp(self): VCloudNodeDriver.connectionCls.host = "test" VCloudNodeDriver.connectionCls.conn_classes = (None, TerremarkMockHttp) TerremarkMockHttp.type = None self.driver = TerremarkDriver(TERREMARK_USER, TERREMARK_SECRET) def test_list_images(self): ret = self.driver.list_images() self.assertEqual(ret[0].id,'https://services.vcloudexpress.terremark.com/api/v0.8/vAppTemplate/5') def test_list_sizes(self): ret = self.driver.list_sizes() self.assertEqual(ret[0].ram, 512) def test_create_node(self): image = self.driver.list_images()[0] size = self.driver.list_sizes()[0] node = self.driver.create_node( name='testerpart2', image=image, size=size, vdc='https://services.vcloudexpress.terremark.com/api/v0.8/vdc/224', network='https://services.vcloudexpress.terremark.com/api/v0.8/network/725', cpus=2, ) self.assertTrue(isinstance(node, Node)) self.assertEqual(node.id, 'https://services.vcloudexpress.terremark.com/api/v0.8/vapp/14031') self.assertEqual(node.name, 'testerpart2') def test_list_nodes(self): ret = self.driver.list_nodes() node = ret[0] self.assertEqual(node.id, 'https://services.vcloudexpress.terremark.com/api/v0.8/vapp/14031') self.assertEqual(node.name, 'testerpart2') self.assertEqual(node.state, NodeState.RUNNING) self.assertEqual(node.public_ip, []) self.assertEqual(node.private_ip, ['10.112.78.69']) def test_reboot_node(self): node = self.driver.list_nodes()[0] ret = self.driver.reboot_node(node) self.assertTrue(ret) def test_destroy_node(self): node = self.driver.list_nodes()[0] ret = self.driver.destroy_node(node) self.assertTrue(ret) class TerremarkMockHttp(MockHttp): def _api_v0_8_login(self, method, url, body, headers): headers['set-cookie'] = 'vcloud-token=testtoken' body = """ """ return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _api_v0_8_org_240(self, method, url, body, headers): body = """ """ return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _api_v0_8_vdc_224(self, method, url, body, headers): body = """ """ return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _api_v0_8_vdc_224_catalog(self, method, url, body, headers): body = """ """ return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _api_v0_8_catalogItem_5(self, method, url, body, headers): body = """ 0 """ return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _api_v0_8_vdc_224_action_instantiateVAppTemplate(self, method, url, body, headers): body = """ """ return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _api_v0_8_vapp_14031_action_deploy(self, method, url, body, headers): body = """ """ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]) def _api_v0_8_task_10496(self, method, url, body, headers): body = """ """ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]) def _api_v0_8_vapp_14031_power_action_powerOn(self, method, url, body, headers): body = """ """ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]) def _api_v0_8_vapp_14031(self, method, url, body, headers): if method == 'GET': body = """ 10.112.78.69 The kind of installed guest operating system Red Hat Enterprise Linux 5 (32-bit) Virtual Hardware Virtual Hardware Family 0 testerpart2 vmx-07
hertz * 10^6 Number of Virtual CPUs 2 virtual CPU(s) 1 3 2 count
byte * 2^20 Memory Size 512MB of memory 2 4 512 byte * 2^20
0
SCSI Controller SCSI Controller 0 3 lsilogic 6
0 Hard Disk 1 10485760 9 3 17 10485760 """ elif method == 'DELETE': body = '' return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]) def _api_v0_8_vapp_14031_power_action_reset(self, method, url, body, headers): body = """ """ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]) def _api_v0_8_vapp_14031_power_action_poweroff(self, method, url, body, headers): body = """ """ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]) def _api_v0_8_task_11001(self, method, url, body, headers): body = """ """ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED])