예제 #1
0
파일: api.py 프로젝트: dimuha-rs/adcm
def add_host(proto, provider, fqdn, desc='', lock=False):
    check_proto_type(proto, 'host')
    check_license(proto.bundle)
    if proto.bundle != provider.prototype.bundle:
        msg = 'Host prototype bundle #{} does not match with host provider bundle #{}'
        err('FOREIGN_HOST',
            msg.format(proto.bundle.id, provider.prototype.bundle.id))
    spec, _, conf, attr = get_prototype_config(proto)
    event = Event()
    with transaction.atomic():
        obj_conf = init_object_config(spec, conf, attr)
        host = Host(prototype=proto,
                    provider=provider,
                    fqdn=fqdn,
                    config=obj_conf,
                    description=desc)
        host.save()
        if lock:
            host.stack = ['created']
            set_object_state(host, config.Job.LOCKED, event)
        process_file_type(host, spec, conf)
        cm.issue.save_issue(host)
    event.send_state()
    cm.status_api.post_event('create', 'host', host.id, 'provider',
                             str(provider.id))
    cm.status_api.load_service_map()
    return host
예제 #2
0
def add_service_to_cluster(cluster, proto):
    check_proto_type(proto, 'service')
    check_license(proto.bundle)
    if not proto.shared:
        if cluster.prototype.bundle != proto.bundle:
            msg = '{} does not belong to bundle "{}" {}'
            err(
                'SERVICE_CONFLICT',
                msg.format(proto_ref(proto), cluster.prototype.bundle.name,
                           cluster.prototype.version),
            )
    with transaction.atomic():
        cs = ClusterObject.objects.create(cluster=cluster, prototype=proto)
        obj_conf = init_object_config(proto, cs)
        cs.config = obj_conf
        cs.save()
        add_components_to_service(cluster, cs)
        cm.issue.update_hierarchy_issues(cs)
        rbac.models.re_apply_object_policy(cluster)
    cm.status_api.post_event('add', 'service', cs.id, 'cluster',
                             str(cluster.id))
    load_service_map()
    log.info(
        f'service #{cs.id} {cs.prototype.name} is added to cluster #{cluster.id} {cluster.name}'
    )
    return cs
예제 #3
0
def init_adcm(bundle):
    proto = Prototype.objects.get(type='adcm', bundle=bundle)
    with transaction.atomic():
        adcm = ADCM.objects.create(prototype=proto, name='ADCM')
        obj_conf = init_object_config(proto, adcm)
        adcm.config = obj_conf
        adcm.save()
    log.info('init adcm object version %s OK', proto.version)
    return adcm
예제 #4
0
파일: bundle.py 프로젝트: dimuha-rs/adcm
def init_adcm(bundle):
    proto = Prototype.objects.get(type='adcm', bundle=bundle)
    spec, _, conf, attr = get_prototype_config(proto)
    with transaction.atomic():
        obj_conf = init_object_config(spec, conf, attr)
        adcm = ADCM(prototype=proto, name='ADCM', config=obj_conf)
        adcm.save()
    log.info('init adcm object version %s OK', proto.version)
    return adcm
예제 #5
0
def add_components_to_service(cluster, service):
    for comp in Prototype.objects.filter(type='component',
                                         parent=service.prototype):
        sc = ServiceComponent.objects.create(cluster=cluster,
                                             service=service,
                                             prototype=comp)
        obj_conf = init_object_config(comp, sc)
        sc.config = obj_conf
        sc.save()
        cm.issue.update_hierarchy_issues(sc)
예제 #6
0
파일: api.py 프로젝트: dimuha-rs/adcm
def add_components_to_service(cluster, service):
    for comp in Prototype.objects.filter(type='component',
                                         parent=service.prototype):
        spec, _, conf, attr = get_prototype_config(comp)
        obj_conf = init_object_config(spec, conf, attr)
        sc = ServiceComponent(cluster=cluster,
                              service=service,
                              prototype=comp,
                              config=obj_conf)
        sc.save()
예제 #7
0
def add_cluster(proto, name, desc=''):
    check_proto_type(proto, 'cluster')
    check_license(proto.bundle)
    with transaction.atomic():
        cluster = Cluster.objects.create(prototype=proto,
                                         name=name,
                                         description=desc)
        obj_conf = init_object_config(proto, cluster)
        cluster.config = obj_conf
        cluster.save()
        cm.issue.update_hierarchy_issues(cluster)
    cm.status_api.post_event('create', 'cluster', cluster.id)
    load_service_map()
    log.info(f'cluster #{cluster.id} {cluster.name} is added')
    return cluster
예제 #8
0
파일: api.py 프로젝트: dimuha-rs/adcm
def add_host_provider(proto, name, desc=''):
    check_proto_type(proto, 'provider')
    check_license(proto.bundle)
    spec, _, conf, attr = get_prototype_config(proto)
    with transaction.atomic():
        obj_conf = init_object_config(spec, conf, attr)
        provider = HostProvider(prototype=proto,
                                name=name,
                                config=obj_conf,
                                description=desc)
        provider.save()
        process_file_type(provider, spec, conf)
        cm.issue.save_issue(provider)
    cm.status_api.post_event('create', 'provider', provider.id)
    return provider
예제 #9
0
def add_host_provider(proto, name, desc=''):
    check_proto_type(proto, 'provider')
    check_license(proto.bundle)
    with transaction.atomic():
        provider = HostProvider.objects.create(prototype=proto,
                                               name=name,
                                               description=desc)
        obj_conf = init_object_config(proto, provider)
        provider.config = obj_conf
        provider.save()
        provider.add_to_concerns(ctx.lock)
        cm.issue.update_hierarchy_issues(provider)
    ctx.event.send_state()
    cm.status_api.post_event('create', 'provider', provider.id)
    log.info(f'host provider #{provider.id} {provider.name} is added')
    return provider
예제 #10
0
파일: api.py 프로젝트: dimuha-rs/adcm
def add_cluster(proto, name, desc=''):
    check_proto_type(proto, 'cluster')
    check_license(proto.bundle)
    spec, _, conf, attr = get_prototype_config(proto)
    with transaction.atomic():
        obj_conf = init_object_config(spec, conf, attr)
        cluster = Cluster(prototype=proto,
                          name=name,
                          config=obj_conf,
                          description=desc)
        cluster.save()
        process_file_type(cluster, spec, conf)
        cm.issue.save_issue(cluster)
    cm.status_api.post_event('create', 'cluster', cluster.id)
    cm.status_api.load_service_map()
    return cluster
예제 #11
0
파일: api.py 프로젝트: dimuha-rs/adcm
def add_service_to_cluster(cluster, proto):
    check_proto_type(proto, 'service')
    check_license(proto.bundle)
    if not proto.shared:
        if cluster.prototype.bundle != proto.bundle:
            msg = '{} does not belong to bundle "{}" {}'
            err(
                'SERVICE_CONFLICT',
                msg.format(proto_ref(proto), cluster.prototype.bundle.name,
                           cluster.prototype.version))
    spec, _, conf, attr = get_prototype_config(proto)
    with transaction.atomic():
        obj_conf = init_object_config(spec, conf, attr)
        cs = ClusterObject(cluster=cluster, prototype=proto, config=obj_conf)
        cs.save()
        add_components_to_service(cluster, cs)
        process_file_type(cs, spec, conf)
        cm.issue.save_issue(cs)
        cm.issue.save_issue(cluster)
    cm.status_api.post_event('add', 'service', cs.id, 'cluster',
                             str(cluster.id))
    cm.status_api.load_service_map()
    return cs
예제 #12
0
def add_host(proto, provider, fqdn, desc=''):
    check_proto_type(proto, 'host')
    check_license(proto.bundle)
    if proto.bundle != provider.prototype.bundle:
        msg = 'Host prototype bundle #{} does not match with host provider bundle #{}'
        err('FOREIGN_HOST',
            msg.format(proto.bundle.id, provider.prototype.bundle.id))
    with transaction.atomic():
        host = Host.objects.create(prototype=proto,
                                   provider=provider,
                                   fqdn=fqdn,
                                   description=desc)
        obj_conf = init_object_config(proto, host)
        host.config = obj_conf
        host.save()
        host.add_to_concerns(ctx.lock)
        cm.issue.update_hierarchy_issues(host)
        rbac.models.re_apply_object_policy(provider)
    ctx.event.send_state()
    cm.status_api.post_event('create', 'host', host.id, 'provider',
                             str(provider.id))
    load_service_map()
    log.info(f'host #{host.id} {host.fqdn} is added')
    return host