Exemplo n.º 1
0
class Server():
    def __init__(self):
        config = ConfigParser.ConfigParser()
        config.read('launcher.cfg')
        rimu_api_key = config.get('Main','RIMU_API_KEY')
        self.master_image = config.get('Main','MASTER_IMAGE')
        self.server_size = config.get('Main','SERVER_SIZE')
        self.domain = config.get('Main','DOMAIN')

        self.hostname = socket.gethostname()

        self.cloud = RimuHostingNodeDriver(rimu_api_key)
        self.all_nodes = self.cloud.list_nodes()

    def checkChildren(self):
        for child_hostname in [self.hostname+'A', self.hostname+'B']:
            child_instance_id = None
            child_fqdn = '%s.%s' % (child_hostname, self.domain)
            try:
                child_instance_id = self.getInstanceId(child_fqdn)
                self.monitor(child_fqdn)
            except Exception,e:
                print "%s not responding to monitor, restarting. Exception: %s" % (child_fqdn, e)
                try:
                    if child_instance_id != None: 
                        self.destroy(child_instance_id)
                    node = self.create(child_fqdn, self.master_image, self.server_size)
                    reportDNS(child_fqdn, node.ipaddress)
                except Exception,ex:
                    self.sendNotification(child_fqdn, ex)
                    raise ex
Exemplo n.º 2
0
class RimuHostingTest(unittest.TestCase, TestCaseMixin):
    def setUp(self):
        RimuHostingNodeDriver.connectionCls.conn_classes = (None,
                                                            RimuHostingMockHttp)
        self.driver = RimuHostingNodeDriver('foo')

    def test_list_nodes(self):
        nodes = self.driver.list_nodes()
        self.assertEqual(len(nodes),1)
        node = nodes[0]
        self.assertEqual(node.public_ip[0], "1.2.3.4")
        self.assertEqual(node.public_ip[1], "1.2.3.5")
        self.assertEqual(node.extra['order_oid'], 88833465)
        self.assertEqual(node.id, "order-88833465-api-ivan-net-nz")

    def test_list_sizes(self):
        sizes = self.driver.list_sizes()
        self.assertEqual(len(sizes),1)
        size = sizes[0]
        self.assertEqual(size.ram,950)
        self.assertEqual(size.disk,20)
        self.assertEqual(size.bandwidth,75)
        self.assertEqual(size.price,32.54)

    def test_list_images(self):
        images = self.driver.list_images()
        self.assertEqual(len(images),6)
        image = images[0]
        self.assertEqual(image.name,"Debian 5.0 (aka Lenny, RimuHosting"\
                         " recommended distro)")
        self.assertEqual(image.id, "lenny")

    def test_reboot_node(self):
        # Raises exception on failure
        node = self.driver.list_nodes()[0]
        self.driver.reboot_node(node)

    def test_destroy_node(self):
        # Raises exception on failure
        node = self.driver.list_nodes()[0]
        self.driver.destroy_node(node)

    def test_create_node(self):
        # Raises exception on failure
        size = self.driver.list_sizes()[0]
        image = self.driver.list_images()[0]
        self.driver.create_node(name="api.ivan.net.nz", image=image, size=size)