示例#1
0
def add_default_events(emitter, receiver):
    events_to_add = [
        Dep(emitter.name, 'run', 'success', receiver.name, 'run'),
        Dep(emitter.name, 'update', 'success', receiver.name, 'update'),
        Dep(receiver.name, 'remove', 'success', emitter.name, 'remove')
    ]
    add_events(emitter.name, events_to_add)
示例#2
0
def setup_slave_node(config, user_config, kubernetes_master, calico_master,
                     internal_network, i):
    j = i + 1
    kube_node = cr.create(
        'kube-node-%d' % j, 'k8s/node', {
            'name': 'kube-node-%d' % j,
            'ip': get_free_slave_ip(user_config['ips']),
            'ssh_user': user_config['username'],
            'ssh_password': user_config['password'],
            'ssh_key': user_config['ssh_key']
        })['kube-node-%d' % j]

    iface_node = cr.create(
        'kube-node-%d-iface' % j, 'k8s/virt_iface', {
            'name': 'cbr0',
            'ipaddr': str(internal_network + 256 * j + 1),
            'onboot': 'yes',
            'bootproto': 'static',
            'type': 'Bridge'
        })['kube-node-%d-iface' % j]
    kube_node.connect(iface_node, {})

    config.connect(iface_node, {'netmask': 'netmask'})

    calico_node = cr.create('calico-node-%d' % j, 'k8s/calico', {})[0]

    kube_node.connect(calico_node, {'ip': 'ip'})
    config.connect(calico_node, {'calico_version': 'version'})

    calico_master.connect(calico_node, {'etcd_authority': 'etcd_authority'})
    calico_node.connect(calico_node,
                        {'etcd_authority': 'etcd_authority_internal'})
    calico_cni = cr.create('calico-cni-node-%d' % j, 'k8s/cni', {})[0]
    calico_node.connect(calico_cni,
                        {'etcd_authority_internal': 'etcd_authority'})

    docker = cr.create('kube-docker-%d' % j,
                       'k8s/docker')['kube-docker-%d' % j]

    kube_node.connect(docker, {})
    iface_node.connect(docker, {'name': 'iface'})

    kubelet = cr.create('kubelet-node-%d' % j, 'k8s/kubelet', {
        'kubelet_args': '--v=5',
    })['kubelet-node-%d' % j]

    kube_node.connect(kubelet, {'name': 'kubelet_hostname'})
    kubernetes_master.connect(kubelet, {'master_address': 'master_api'})
    config.connect(
        kubelet, {
            'cluster_domain': 'cluster_domain',
            'cluster_dns': 'cluster_dns',
            'k8s_version': 'k8s_version'
        })

    add_event(Dep(docker.name, 'run', 'success', calico_node.name, 'run'))
    add_event(Dep(docker.name, 'run', 'success', kubelet.name, 'run'))
    add_event(Dep(calico_node.name, 'run', 'success', kubelet.name, 'run'))
    return kube_node
示例#3
0
def setup_master():
    config = cr.create('kube-config', 'k8s/global_config', {
        'cluster_dns': '10.254.0.10',
        'cluster_domain': 'cluster.local'
    })[0]
    master = cr.create(
        'kube-node-master', 'k8s/node', {
            'name': 'kube-node-master',
            'ip': '10.0.0.3',
            'ssh_user': '******',
            'ssh_password': '******',
            'ssh_key': None
        })['kube-node-master']
    # etcd = cr.create('etcd', 'k8s/etcd', {'listen_client_port': 4001})['etcd']
    # master.connect(etcd, {'name': 'listen_client_host'})
    # etcd.connect(etcd, {'listen_client_host': 'listen_client_url',
    #                     'listen_client_port': 'listen_client_url'})
    #                     # 'listen_client_port_events': 'listen_client_url_events',
    #                     # 'listen_client_host': 'listen_client_url_events'})

    master.connect(config, {})
    docker = cr.create('kube-docker-master',
                       'k8s/docker')['kube-docker-master']
    master.connect(docker, {})

    kubelet = cr.create('kubelet-master',
                        'k8s/kubelet_master')['kubelet-master']

    calico = cr.create('calico-master', 'k8s/calico_master',
                       {'options': "--nat-outgoing --ipip"})['calico-master']
    master.connect(calico, {'ip': ['ip', 'etcd_host']})
    config.connect(calico, {'network': 'network', 'prefix': 'prefix'})
    calico.connect(
        calico, {
            'etcd_host': 'etcd_authority',
            'etcd_port': 'etcd_authority',
            'etcd_authority': 'etcd_authority_internal'
        })
    config.connect(kubelet,
                   {'service_cluster_ip_range': "service_cluster_ip_range"})
    master.connect(kubelet, {'name': 'master_host'})
    kubelet.connect(kubelet, {
        'master_host': 'master_address',
        'master_port': 'master_address'
    })

    add_event(Dep(docker.name, 'run', 'success', kubelet.name, 'run'))
    add_event(Dep(kubelet.name, 'run', 'success', calico.name, 'run'))
示例#4
0
def test_parse_events(good_events):
    events = [Dep(parent='service1', parent_action='run',
                  child='config1', child_action='run',
                  state='success'),
              React(parent='config1', parent_action='run',
                    child='service1', child_action='apply_config',
                    state='success')]
    parsed = cr.parse_events(good_events)
    assert events == parsed
示例#5
0
def setup_master(config, user_config):
    master = cr.create(
        'kube-node-master', 'k8s/node', {
            'name': 'kube-node-master',
            'ip': user_config['ip'],
            'ssh_user': user_config['username'],
            'ssh_password': user_config['password'],
            'ssh_key': user_config['ssh_key']
        })['kube-node-master']

    master.connect(config, {})
    docker = cr.create('kube-docker-master',
                       'k8s/docker')['kube-docker-master']
    master.connect(docker, {})

    kubelet = cr.create('kubelet-master',
                        'k8s/kubelet_master')['kubelet-master']
    config.connect(kubelet, {'k8s_version': 'k8s_version'})

    calico = cr.create('calico-master', 'k8s/calico_master',
                       {'options': "--nat-outgoing --ipip"})['calico-master']
    master.connect(calico, {'ip': ['ip', 'etcd_host']})
    config.connect(calico, {
        'network': 'network',
        'prefix': 'prefix',
        'calico_version': 'version'
    })
    calico.connect(
        calico, {
            'etcd_host': 'etcd_authority',
            'etcd_port': 'etcd_authority',
            'etcd_authority': 'etcd_authority_internal'
        })
    config.connect(kubelet,
                   {'service_cluster_ip_range': "service_cluster_ip_range"})
    master.connect(kubelet, {'name': 'master_host'})
    kubelet.connect(kubelet, {
        'master_host': 'master_address',
        'master_port': 'master_address'
    })

    add_event(Dep(docker.name, 'run', 'success', kubelet.name, 'run'))
    add_event(Dep(kubelet.name, 'run', 'success', calico.name, 'run'))
示例#6
0
文件: api.py 项目: cvieri/solar
def create_event(event_dict):
    etype = event_dict['etype']
    kwargs = {'child': event_dict['child'],
              'parent': event_dict['parent'],
              'child_action': event_dict['child_action'],
              'parent_action': event_dict['parent_action'],
              'state': event_dict['state']}
    if etype == React.etype:
        return React(**kwargs)
    elif etype == Dep.etype:
        return Dep(**kwargs)
    else:
        raise Exception('No support for type %s', etype)
示例#7
0
def parse_events(template_events):
    parsed_events = []
    events = extend_events(template_events)
    for event in events:
        event_type = event['type']
        parent, parent_action = event['parent_action'].split('.')
        child, child_action = event['depend_action'].split('.')
        state = event['state']
        if event_type == Dep.etype:
            event = Dep(parent, parent_action, state, child, child_action)
        elif event_type == React.etype:
            event = React(parent, parent_action, state, child, child_action)
        else:
            raise Exception('Invalid event type: {0}'.format(event_type))
        parsed_events.append(event)
    return parsed_events
示例#8
0
def setup_nodes(num=1):
    kube_nodes = []
    kubernetes_master = rs.load('kubelet-master')
    calico_master = rs.load('calico-master')
    config = rs.load('kube-config')
    for i in xrange(num):
        j = i + 1
        kube_node = cr.create(
            'kube-node-%d' % j, 'k8s/node', {
                'name': 'kube-node-%d' % j,
                'ip': '10.0.0.%d' % (3 + j),
                'ssh_user': '******',
                'ssh_password': '******',
                'ssh_key': None
            })['kube-node-%d' % j]

        iface_node = cr.create(
            'kube-node-%d-iface' % j,
            'k8s/virt_iface',
            {
                'name': 'cbr0',
                'ipaddr': '172.20.%d.1' %
                (i + 1),  # TODO(jnowak) support config for it
                'onboot': 'yes',
                'bootproto': 'static',
                'type': 'Bridge'
            })['kube-node-%d-iface' % j]
        kube_node.connect(iface_node, {})

        config.connect(iface_node, {'netmask': 'netmask'})

        calico_node = cr.create('calico-node-%d' % j, 'k8s/calico', {})[0]

        kube_node.connect(calico_node, {'ip': 'ip'})
        calico_master.connect(calico_node,
                              {'etcd_authority': 'etcd_authority'})
        calico_node.connect(calico_node,
                            {'etcd_authority': 'etcd_authority_internal'})
        calico_cni = cr.create('calico-cni-node-%d' % j, 'k8s/cni', {})[0]
        calico_node.connect(calico_cni,
                            {'etcd_authority_internal': 'etcd_authority'})

        docker = cr.create('kube-docker-%d' % j,
                           'k8s/docker')['kube-docker-%d' % j]

        kube_node.connect(docker, {})
        iface_node.connect(docker, {'name': 'iface'})

        kubelet = cr.create('kubelet-node-%d' % j, 'k8s/kubelet', {
            'kubelet_args': '--v=5',
        })['kubelet-node-%d' % j]

        kube_node.connect(kubelet, {'name': 'kubelet_hostname'})
        kubernetes_master.connect(kubelet, {'master_address': 'master_api'})
        config.connect(kubelet, {
            'cluster_domain': 'cluster_domain',
            'cluster_dns': 'cluster_dns'
        })

        add_event(Dep(docker.name, 'run', 'success', calico_node.name, 'run'))
        add_event(Dep(docker.name, 'run', 'success', kubelet.name, 'run'))
        add_event(Dep(calico_node.name, 'run', 'success', kubelet.name, 'run'))

        kube_nodes.append(kube_node)
    kube_master = rs.load('kube-node-master')
    all_nodes = kube_nodes[:] + [kube_master]
    hosts_files = rs.load_all(startswith='hosts_file_node_kube-')
    for node in all_nodes:
        for host_file in hosts_files:
            node.connect(host_file, {'name': 'hosts:name', 'ip': 'hosts:ip'})
示例#9
0
def add_dep(parent, dep, actions, state='success'):
    for act in actions:
        d = Dep(parent, act, state=state, child=dep, child_action=act)
        add_event(d)
        log.debug('Added event: %s', d)
示例#10
0
def setup_riak(nodes_num=None, hosts_mapping=False):

    if nodes_num is None:
        nodes_num = NODES
    db.clear()

    resources = vr.create('nodes', 'templates/nodes.yaml',
                          {'count': nodes_num})
    nodes = [x for x in resources if x.name.startswith('node')]
    hosts_services = [x for x in resources if x.name.startswith('hosts_file')]

    riak_services = []
    ips = '10.0.0.%d'
    for i in xrange(nodes_num):
        num = i + 1
        r = vr.create(
            'riak_service%d' % num, 'resources/riak_node', {
                'riak_self_name': 'riak%d' % num,
                'riak_hostname': 'riak_server%d.solar' % num,
                'riak_name': 'riak%d@riak_server%d.solar' % (num, num)
            })[0]
        riak_services.append(r)

    for i, riak in enumerate(riak_services):
        nodes[i].connect(riak)

    for i, riak in enumerate(riak_services[1:]):
        riak_services[0].connect(riak, {'riak_name': 'join_to'})

    if hosts_mapping:
        for riak in riak_services:
            for hosts_file in hosts_services:
                riak.connect_with_events(hosts_file, {
                    'riak_hostname': 'hosts:name',
                    'ip': 'hosts:ip'
                })

    res_errors = resource.validate_resources()
    for r, error in res_errors:
        click.echo('ERROR: %s: %s' % (r.name, error))
    has_errors = False

    if has_errors:
        click.echo("ERRORS")
        sys.exit(1)

    events = []
    for x in xrange(nodes_num):
        i = x + 1
        if hosts_mapping:
            events.append(
                Dep('hosts_file%d' % i, 'run', 'success', 'riak_service%d' % i,
                    'run'))
        if i >= 2:
            events.append(
                React('riak_service%d' % i, 'run', 'success',
                      'riak_service%d' % i, 'join'))
        events.append(
            React('riak_service%d' % i, 'join', 'success', 'riak_service1',
                  'commit'))

    for event in events:
        add_event(event)

    click.echo('Use solar changes process & orch')
    sys.exit(0)
示例#11
0
文件: riaks.py 项目: cvieri/solar
def setup_riak():

    ModelMeta.remove_all()
    resources = vr.create('nodes', 'templates/nodes.yaml', {'count': 3})
    nodes = [x for x in resources if x.name.startswith('node')]
    hosts_services = [x for x in resources if x.name.startswith('hosts_file')]
    node1, node2, node3 = nodes
    hosts_services = [x for x in resources if x.name.startswith('hosts_file')]

    riak_services = []
    ips = '10.0.0.%d'
    for i in xrange(3):
        num = i + 1
        r = vr.create('riak_service%d' % num,
                      'resources/riak_node',
                      {'riak_self_name': 'riak%d' % num,
                       'storage_backend': 'leveldb',
                       'riak_hostname': 'riak_server%d.solar' % num,
                       'riak_name': 'riak%d@riak_server%d.solar' % (num, num)})[0]
        riak_services.append(r)

    for i, riak in enumerate(riak_services):
        nodes[i].connect(riak)

    for i, riak in enumerate(riak_services[1:]):
        riak_services[0].connect(riak, {'riak_name': 'join_to'})

    for riak in riak_services:
        for hosts_file in hosts_services:
            riak.connect_with_events(hosts_file,
                {'riak_hostname': 'hosts:name',
                 'ip': 'hosts:ip'})

    Resource.save_all_lazy()
    errors = resource.validate_resources()
    for r, error in errors:
        click.echo('ERROR: %s: %s' % (r.name, error))
    has_errors = False

    if errors:
        click.echo("ERRORS")
        sys.exit(1)

    events = [
        Dep('hosts_file1', 'run', 'success', 'riak_service1', 'run'),
        Dep('hosts_file2', 'run', 'success', 'riak_service2', 'run'),
        Dep('hosts_file3', 'run', 'success', 'riak_service3', 'run'),

        React('riak_service2', 'run', 'success', 'riak_service2', 'join'),
        React('riak_service3', 'run', 'success', 'riak_service3', 'join'),

        # Dep('riak_service1', 'run', 'success', 'riak_service2', 'join'),
        # Dep('riak_service1', 'run', 'success', 'riak_service3', 'join'),

        # React('riak_service2', 'join', 'error', 'riak_service2', 'leave'),
        # React('riak_service3', 'join', 'error', 'riak_service3', 'leave'),

        React('riak_service2', 'leave', 'success', 'riak_service2', 'join'),
        React('riak_service3', 'leave', 'success', 'riak_service3', 'join'),

        # React('riak_service2', 'leave', 'success', 'riak_service1', 'commit_leave'),
        # React('riak_service3', 'leave', 'success', 'riak_service1', 'commit_leave'),

        # Dep('riak_service1', 'commit_leave', 'success', 'riak_service2', 'join'),
        # Dep('riak_service1', 'commit_leave', 'success', 'riak_service3', 'join'),

        React('riak_service3', 'join', 'success', 'riak_service1', 'commit'),
        React('riak_service2', 'join', 'success', 'riak_service1', 'commit')
    ]

    for event in events:
        add_event(event)

    click.echo('Use solar changes process & orch')
    sys.exit(0)
示例#12
0
文件: riaks.py 项目: cvieri/solar
def setup_haproxies():
    hps = []
    hpc = []
    hpsc_http = []
    hpsc_pb = []
    for i in xrange(3):
        num = i + 1
        hps.append(vr.create('haproxy_service%d' % num,
                             'resources/haproxy_service',
                             {})[0])
        hpc.append(vr.create('haproxy_config%d' % num,
                             'resources/haproxy_config',
                             {})[0])
        hpsc_http.append(vr.create('haproxy_service_config_http%d' % num,
                                   'resources/haproxy_service_config',
                                   {'listen_port': 8098,
                                    'protocol': 'http',
                                    'name': 'riak_haproxy_http%d' % num})[0])
        hpsc_pb.append(vr.create('haproxy_service_config_pb%d' % num,
                                 'resources/haproxy_service_config',
                                 {'listen_port': 8087,
                                  'protocol': 'tcp',
                                  'name': 'riak_haproxy_pb%d' % num})[0])

    riak1 = resource.load('riak_service1')
    riak2 = resource.load('riak_service2')
    riak3 = resource.load('riak_service3')
    riaks = [riak1, riak2, riak3]

    for single_hpsc in hpsc_http:
        for riak in riaks:
            riak.connect(single_hpsc, {
                'riak_hostname': 'backends:server',
                'riak_port_http': 'backends:port'})

    for single_hpsc in hpsc_pb:
        for riak in riaks:
            riak.connect(single_hpsc,
                {'riak_hostname': 'backends:server',
                 'riak_port_pb': 'backends:port'})

    # haproxy config to haproxy service

    for single_hpc, single_hpsc in zip(hpc, hpsc_http):
        single_hpsc.connect(single_hpc, {"backends": "config:backends",
                                                  "listen_port": "config:listen_port",
                                                  "protocol": "config:protocol",
                                                  "name": "config:name"})

    for single_hpc, single_hpsc in zip(hpc, hpsc_pb):
        single_hpsc.connect(single_hpc, {"backends": "config:backends",
                                                  "listen_port": "config:listen_port",
                                                  "protocol": "config:protocol",
                                                  "name": "config:name"})


    # assign haproxy services to each node

    node1 = resource.load('node1')
    node2 = resource.load('node2')
    node3 = resource.load('node3')
    nodes = [node1, node2, node3]

    for single_node, single_hps in zip(nodes, hps):
        single_node.connect(single_hps)

    for single_node, single_hpc in zip(nodes, hpc):
        single_node.connect(single_hpc)

    has_errors = False
    for r in locals().values():

        # TODO: handle list
        if not isinstance(r, resource.Resource):
            continue

        # print 'Validating {}'.format(r.name)
        local_errors = validation.validate_resource(r)
        if local_errors:
            has_errors = True
            print 'ERROR: %s: %s' % (r.name, local_errors)

    if has_errors:
        print "ERRORS"
        sys.exit(1)

    events = []
    for node, single_hps, single_hpc in zip(nodes, hps, hpc):
        # r = React(node.name, 'run', 'success', single_hps.name, 'install')
        d = Dep(single_hps.name, 'run', 'success', single_hpc.name, 'run')
        e1 = React(single_hpc.name, 'run', 'success', single_hps.name, 'apply_config')
        e2 = React(single_hpc.name, 'update', 'success', single_hps.name, 'apply_config')
        # events.extend([r, d, e1, e2])
        events.extend([d, e1, e2])

    for event in events:
        add_event(event)