Ejemplo n.º 1
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'))
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def setup_riak(nodes_num=None, hosts_mapping=False):

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

    resources = cr.create('nodes', 'templates/nodes', {'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 = cr.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)
Ejemplo n.º 4
0
def create_virtual_resource(vr_name, template):
    template_resources = template['resources']
    template_events = template.get('events', {})

    created_resources = create_resources(template_resources)
    events = parse_events(template_events)
    for event in events:
        add_event(event)
    return created_resources
Ejemplo n.º 5
0
def create_virtual_resource(vr_name, template, tags=None):
    template_resources = template.get('resources', [])
    template_events = template.get('events', [])
    resources_to_update = template.get('updates', [])

    created_resources = create_resources(template_resources, tags=tags)
    events = parse_events(template_events)
    for event in events:
        add_event(event)
    update_resources(resources_to_update)
    return created_resources
Ejemplo n.º 6
0
    def add_react(self, action_state, resource, action):
        """Add single orch React from self to resource.

        resource = resources.take(0)
        resource.add_react('run/success', some_resource, 'run')
        """

        action_state = self.action_state_parse(action_state)

        add_event(
            controls.React(self.resource.name, action_state['action'],
                           action_state['state'], resource.resource.name,
                           action))
Ejemplo n.º 7
0
def apply_composer_file(base_path, vr_name, template, tags=None):
    template_resources = template.get('resources', [])
    template_events = template.get('events', [])
    resources_to_update = template.get('updates', [])

    created_resources = create_resources(
        base_path,
        template_resources,
        tags=tags
    )
    events = parse_events(template_events)
    for event in events:
        add_event(event)
    update_resources(resources_to_update)
    return created_resources
Ejemplo n.º 8
0
def apply_composer_file(base_path, vr_name, template, tags=None):
    template_resources = template.get('resources', [])
    template_events = template.get('events', [])
    resources_to_update = template.get('updates', [])

    created_resources = create_resources(
        base_path,
        template_resources,
        tags=tags
    )
    events = parse_events(template_events)
    for event in events:
        add_event(event)
    update_resources(resources_to_update)
    return created_resources
Ejemplo n.º 9
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'))
Ejemplo n.º 10
0
    def add_react(self, action_state, resource, action):
        """Add single orch React from self to resource.

        resource = resources.take(0)
        resource.add_react('run/success', some_resource, 'run')
        """

        action_state = self.action_state_parse(action_state)

        add_event(
            controls.React(
                self.resource.name,
                action_state['action'],
                action_state['state'],
                resource.resource.name,
                action
            )
        )
Ejemplo n.º 11
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'))
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
def setup_nodes(num=1):
    kube_nodes = []
    etcd = rs.load('etcd')
    kubernetes_master = rs.load('k8s-master')
    calico_master = rs.load('calico-master')
    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',
             'netmask': '255.255.255.0',
             'ipaddr': '192.168.%d.1' % (i + 1),
             'onboot': 'yes',
             'bootproto': 'static',
             'type': 'Bridge'})['kube-node-%d-iface' % j]
        kube_node.connect(iface_node, {})

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

        add_event(Dep(calico_master.name, 'run', 'success', calico_node.name, 'run'))

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

        calico_node.connect(calico_node, {
            'etcd_authority': 'etcd_authority_internal'
        })

        etcd.connect(calico_node, {'listen_client_url': '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': '--network-plugin=calico',
        })['kubelet-node-%d' % j]

        kube_node.connect(kubelet, {'name': 'kubelet_hostname'})
        kubernetes_master.connect(kubelet, {'master_address': 'master_api'})
        calico_node.connect(kubelet, {'etcd_authority_internal': 'etcd_authority'})

        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'
            })
Ejemplo n.º 16
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'})
Ejemplo n.º 17
0
def setup_riak():
    db.clear()
    signals.Connections.clear()

    nodes = vr.create('nodes', 'templates/riak_nodes.yml', {})
    node1, node2, node3 = nodes

    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,
                       '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):
        signals.connect(nodes[i], riak)

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

    hosts_services = []
    for i, riak in enumerate(riak_services):
        num = i + 1
        hosts_file = vr.create('hosts_file%d' % num,
                               'resources/hosts_file', {})[0]
        hosts_services.append(hosts_file)
        signals.connect(nodes[i], hosts_file)

    for riak in riak_services:
        for hosts_file in hosts_services:
            signals.connect(riak, hosts_file,
                            {'riak_hostname': 'hosts_names', 'ip': 'hosts_ips'},
                            events=False)

    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, errors)

    if has_errors:
        print "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)

    print 'Use solar changes process & orch'
    sys.exit(0)
Ejemplo n.º 18
0
def setup_riak():
    db.clear()

    nodes = vr.create('nodes', 'templates/riak_nodes.yaml', {})
    node1, node2, node3 = nodes

    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,
                       '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):
        signals.connect(nodes[i], riak)

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

    hosts_services = []
    for i, riak in enumerate(riak_services):
        num = i + 1
        hosts_file = vr.create('hosts_file%d' % num,
                               'resources/hosts_file', {})[0]
        hosts_services.append(hosts_file)
        signals.connect(nodes[i], hosts_file)

    for riak in riak_services:
        for hosts_file in hosts_services:
            signals.connect(riak, hosts_file,
                            {'riak_hostname': 'hosts:name',
                             'ip': 'hosts:ip'},
                            events=False)

    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)
Ejemplo n.º 19
0
with open('/vagrant/tmp/keys/ssh_public') as fp:
    master_key = fp.read().strip()

# Dnsmasq resources
for node in nodes_list:
    node = NodeAdapter(node)
    node_resource = next(n for n in node_resources
                         if n.name.endswith('node_{0}'.format(node.node_id)))

    node_resource.update({
        'partitioning': node.partitioning,
        'master_key': master_key,
        'repos': node.repos,
    })

    dnsmasq = vr.create('dnsmasq_{0}'.format(node.node_id),
                        'resources/dnsmasq', {})[0]
    master_node.connect(dnsmasq)
    node_resource.connect(dnsmasq, {'admin_mac': 'exclude_mac_pxe'})

    event = React(node_resource.name, 'run', 'success', node_resource.name,
                  'provision')
    add_event(event)
    event = React(node_resource.name, 'provision', 'success', dnsmasq.name,
                  'exclude_mac_pxe')
    add_event(event)
    event = React(dnsmasq.name, 'exclude_mac_pxe', 'success',
                  node_resource.name, 'reboot')
    add_event(event)
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
def add(etype, parent_node, parent_action, state, depend_node, depend_action):
    ev = evapi.create_event(locals())
    evapi.add_event(ev)
Ejemplo n.º 22
0
def add(etype, parent_node, parent_action, state, depend_node, depend_action):
    ev = evapi.create_event(locals())
    evapi.add_event(ev)
Ejemplo n.º 23
0
def setup_riak():
    nodes = rs.load_all(startswith="node")
    hosts_services = rs.load_all(startswith="hosts_file")
    node1, node2, node3 = nodes[:3]

    riak_services = []
    ips = "10.0.0.%d"
    for i in xrange(3):
        num = i + 1
        r = cr.create(
            "riak_service%d" % num,
            "resources/riak_node",
            {
                "riak_self_name": "riak%d" % num,
                "storage_backend": "leveldb",
                "riak_hostname": "riak_server%d.solar" % num,
            },
        )[0]
        r.connect(r, {"riak_self_name": "riak_name", "riak_hostname": "riak_name"})
        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_file_node_node1", "run", "success", "riak_service1", "run"),
        Dep("hosts_file_node_node2", "run", "success", "riak_service2", "run"),
        Dep("hosts_file_node_node3", "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)
Ejemplo n.º 24
0
def test_single_event(events_example):
    r = orm.DBResource(id='e1', name='e1', base_path='x')
    r.save()
    evapi.add_events('e1', events_example[:2])
    evapi.add_event(events_example[2])
    assert set(evapi.all_events('e1')) == set(events_example)
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
    master_key = fp.read().strip()

# Dnsmasq resources
for node in nodes_list:
    node = NodeAdapter(node)
    node_resource = next(n for n in node_resources
                         if n.name.endswith('node_{0}'.format(node.node_id)))

    node_resource.update(
        {
            'partitioning': node.partitioning,
            'master_key': master_key,
            'repos': node.repos,
        }
    )

    dnsmasq = cr.create('dnsmasq_{0}'.format(node.node_id),
                        'resources/dnsmasq', {})[0]
    master_node.connect(dnsmasq)
    node_resource.connect(dnsmasq, {'admin_mac': 'exclude_mac_pxe'})

    event = React(node_resource.name, 'run', 'success', node_resource.name,
                  'provision')
    add_event(event)
    event = React(node_resource.name, 'provision', 'success', dnsmasq.name,
                  'exclude_mac_pxe')
    add_event(event)
    event = React(dnsmasq.name, 'exclude_mac_pxe', 'success',
                  node_resource.name, 'reboot')
    add_event(event)
Ejemplo n.º 27
0
def test_single_event(events_example):
    r = Resource.from_dict(dict(key='e1', name='e1', base_path='x'))
    r.save()
    evapi.add_events('e1', events_example[:2])
    evapi.add_event(events_example[2])
    assert set(evapi.all_events('e1')) == set(events_example)
Ejemplo n.º 28
0
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})[0]
        r.connect(r, {'riak_self_name': 'riak_name',
                      'riak_hostname': 'riak_name'})
        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)
Ejemplo n.º 29
0
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)