コード例 #1
0
def test_cluster_from_to_list():
    input_dict = [{
        'uid': 0,
        'ip': '0.0.0.0',
        'port': 11
    }, {
        'uid': 1,
        'ip': '1.1.1.1',
        'port': 22
    }, {
        'uid': 2,
        'ip': '2.2.2.2',
        'port': 33
    }]
    cluster = Cluster.from_list(input_dict, settings)

    exported = cluster.to_list()
    assert isinstance(exported, list)
    assert exported == input_dict
    assert len(cluster.instances) == 3

    for i, instance in enumerate(cluster.instances):
        assert isinstance(instance, BareInstance)
        assert cluster.instances[i].uid == i
        assert cluster.instances[i].ip == '{0}.{0}.{0}.{0}'.format(i)
        assert cluster.instances[i].port == 11 * (i + 1)
コード例 #2
0
 def read_instances(self):
     """
     Read `.dsb/instances.yaml`
     Populates `self.cluster`
     """
     logger.debug('Reading instances from: %s' % self.instances_path)
     if os.path.exists(self.instances_path):
         with open(self.instances_path, 'r') as f:
             list_ = yaml.load(f.read())
             self.cluster = Cluster.from_list(list_, settings=self.settings)
コード例 #3
0
def test_cluster_from_to_list():
    data = [{"id": 0, "ip": "0.0.0.0"}, {"id": 1, "ip": "1.1.1.1"}, {"id": 2, "ip": "2.2.2.2"}]
    cluster = Cluster.from_list(data, settings)

    exported = cluster.to_list()
    exported_ans = [{"id": 0, "ip": "0.0.0.0"}, {"id": 1, "ip": "1.1.1.1"}, {"id": 2, "ip": "2.2.2.2"}]

    assert isinstance(exported, list)
    assert exported == exported_ans
    assert len(cluster.instances) == 3
コード例 #4
0
ファイル: project.py プロジェクト: aryanet/datasciencebox
 def read_instances(self):
     """
     Read `.dsb/instances.yaml`
     Populates `self.cluster`
     """
     logger.debug('Reading instances from: %s', self.instances_path)
     if os.path.exists(self.instances_path):
         with open(self.instances_path, 'r') as f:
             list_ = yaml.load(f.read())
             self.cluster = Cluster.from_list(list_, settings=self.settings)
コード例 #5
0
def test_cluster_from_to_list():
    input_dict = [{'uid': 0,
                   'ip': '0.0.0.0',
                   'port': 11}, {'uid': 1,
                                 'ip': '1.1.1.1',
                                 'port': 22}, {'uid': 2,
                                               'ip': '2.2.2.2',
                                               'port': 33}]
    cluster = Cluster.from_list(input_dict, settings)

    exported = cluster.to_list()
    assert isinstance(exported, list)
    assert exported == input_dict
    assert len(cluster.instances) == 3

    for i, instance in enumerate(cluster.instances):
        assert isinstance(instance, BareInstance)
        assert cluster.instances[i].uid == i
        assert cluster.instances[i].ip == '{0}.{0}.{0}.{0}'.format(i)
        assert cluster.instances[i].port == 11 * (i + 1)
コード例 #6
0
import pytest

from datasciencebox.core.project import Project
from datasciencebox.core.settings import Settings
from datasciencebox.core.cloud.cluster import Cluster

settings = Settings()
settings['USERNAME'] = '******'
settings['KEYPAIR'] = '~/.ssh/id_rsa'

_ = [{'id': 0, 'ip': '0.0.0.0'}, {'id': 1, 'ip': '1.1.1.1'}, {'id': 2, 'ip': '2.2.2.2'}]
cluster = Cluster.from_list(_, settings)

project = Project()
project.settings = settings
project.cluster = cluster