コード例 #1
0
def test_infra_ops():
    global CREATED_SERVERS
    global CREATED_TAGS

    CREATED_TAGS = TAGS

    manager = CloudManager(USERNAME, PASSWORD, timeout=120)

    try:
        auth = manager.authenticate()
        assert True
    except Exception:
        assert False

    all_servers = create_cluster(manager, CLUSTER)

    # collect & populate servers from CLUSTER
    cluster_servers = []
    for name in CLUSTER:
        server = CLUSTER[name]
        server.populate()
        cluster_servers.append(server)

    CREATED_SERVERS = cluster_servers

    # assert all_servers contain cluster_servers
    for cs in cluster_servers:
        assert cs.state == 'started'

        found = False
        for server in all_servers:
            if server.uuid == cs.uuid:
                found = True

        if not found:
            raise Exception('server {0} not found in all_servers'.format(
                cs.uuid))

    # assert servers' states
    # TODO(elnygren): add more assertions here

    # web2 non default IP configuration
    web2 = CLUSTER['web2']
    assert len(web2.ip_addresses) == 1
    assert web2.ip_addresses[0].family == 'IPv6'

    test_server = CLUSTER['web1']

    test_server.populate()
    test_server._wait_for_state_change(['started'])
    test_server.stop()
    test_server._wait_for_state_change(['stopped'])

    # contain appropriate asserts
    firewall_test(manager, FIREWALL_RULES, test_server)
    server_test(manager, test_server)
    tag_servers_test(manager, TAGS, CLUSTER)
コード例 #2
0
def test_infra_ops():
    global CREATED_SERVERS
    global CREATED_TAGS

    CREATED_TAGS = TAGS

    manager = CloudManager(USERNAME, PASSWORD, timeout=120)

    try:
        auth = manager.authenticate()
        assert True
    except Exception:
        assert False

    all_servers = create_cluster(manager, CLUSTER)

    # collect & populate servers from CLUSTER
    cluster_servers = []
    for name in CLUSTER:
        server = CLUSTER[name]
        server.populate()
        cluster_servers.append(server)


    CREATED_SERVERS = cluster_servers

    # assert all_servers contain cluster_servers
    for cs in cluster_servers:
        assert cs.state == 'started'

        found = False
        for server in all_servers:
            if server.uuid == cs.uuid:
                found = True

        if not found:
            raise Exception('server {} not found in all_servers'.format(cs.uuid))

    # assert servers' states
    # TODO(elnygren): add more assertions here

    # web2 non default IP configuration
    web2 = CLUSTER['web2']
    assert len(web2.ip_addresses) == 1
    assert web2.ip_addresses[0].family == 'IPv6'



    test_server = CLUSTER['web1']
    test_server.stop()
    test_server._wait_for_state_change(['stopped'])

    # contain appropriate asserts
    firewall_test(manager, FIREWALL_RULES, test_server)
    server_test(manager, test_server)
    tag_servers_test(manager, TAGS, CLUSTER)
コード例 #3
0
def test_infra_ops():
    global CREATED_SERVERS
    global CREATED_TAGS

    CREATED_TAGS = TAGS

    manager = CloudManager(USERNAME, PASSWORD, timeout=120)

    try:
        auth = manager.authenticate()
        assert True
    except Exception:
        assert False

    all_servers = create_cluster(manager, CLUSTER)

    # collect & populate servers from CLUSTER
    cluster_servers = []
    for name in CLUSTER:
        server = CLUSTER[name]
        server.populate()
        cluster_servers.append(server)

    CREATED_SERVERS = cluster_servers

    # assert all_servers contain cluster_servers
    for cs in cluster_servers:
        assert cs.state == 'started'

        found = False
        for server in all_servers:
            if server.uuid == cs.uuid:
                found = True

        if not found:
            raise Exception('server {} not found in all_servers'.format(
                cs.uuid))

    test_server = CLUSTER['web1']
    test_server.stop()
    test_server._wait_for_state_change(['stopped'])

    # contain appropriate asserts
    firewall_test(manager, FIREWALL_RULES, test_server)
    server_test(manager, test_server)
    tag_servers_test(manager, TAGS, CLUSTER)
コード例 #4
0
#!/usr/bin/env python3
#
# Destroy a populated instance at UpCloud by IP address.
#
# pip3 install --user upcloud-api
# chmod 0700 ./upcloud_destroy_server.py
# ./upcloud_destroy_server.py IP-ADDRESS

import sys
from upcloud_api import CloudManager


# EDIT here
manager = CloudManager('USERNAME', 'PASSWORD')

manager.authenticate()

populated_server = manager.get_server_by_ip(sys.argv[1])
populated_server.stop_and_destroy()
コード例 #5
0
class UpCloudAPI(AbstractCloudAPI):

    name = 'upcloud'

    def __init__(self, config):
        super().__init__(max_nodes=config.getint(
            'clouds', 'upcloud_max_nodes', fallback=None))
        self.client = CloudManager(config.get('clouds', 'upcloud_login'),
                                   config.get('clouds', 'upcloud_pass'))
        self.client.authenticate()
        self.config = config

    def init_key(self):
        super().init_key()
        self.login_user = login_user_block(username=self.config.get(
            'remote', 'user'),
                                           ssh_keys=[self.public_key],
                                           create_password=False)

    def create_node(self):
        assert self.ssh_custom_key

        server = self.client.create_server(
            Server(core_number=8,
                   memory_amount=4096,
                   hostname=self.get_rnd_name('node'),
                   zone=ZONE.London,
                   storage_devices=[Storage(os='Debian 10.0', size=40)],
                   login_user=self.login_user))
        ip = server.get_public_ip()
        logging.info('CREATED %s' % ip)
        logging.info('WAITING FOR START...')
        time.sleep(30)

        # warm up
        for _ in range(10):
            ssh_conn = SSH_Connection(host=ip,
                                      user=self.config.get('remote', 'user'),
                                      connect_kwargs=self.ssh_custom_key)
            try:
                ssh_conn.run('whoami', hide=True)
            except:
                time.sleep(5)
            else:
                break

        return ip

    def delete_node(self, ip):
        for server in self.client.get_servers():
            if server.get_public_ip() == ip:
                server.stop()
                logging.info('WAITING FOR STOP...')
                time.sleep(20)
                while True:
                    try:
                        server.destroy()
                    except:
                        time.sleep(5)
                    else:
                        break
                for storage in server.storage_devices:
                    storage.destroy()
                logging.info('DELETED %s' % ip)
                break
        else:
            logging.info('NODE %s NOT DELETED AS UNKNOWN' % ip)