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
def process_config_and_attr(obj, conf, attr=None, spec=None): if not spec: spec, _, _, _ = get_prototype_config(obj.prototype) new_conf = process_config(obj, spec, conf) if attr: for key, val in attr.items(): if 'active' in val and not val['active']: new_conf[key] = None return new_conf
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
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()
def process_config_and_attr(obj, conf, attr=None, spec=None): if not spec: if isinstance(obj, GroupConfig): prototype = obj.object.prototype else: prototype = obj.prototype spec, _, _, _ = get_prototype_config(prototype) new_conf = process_config(obj, spec, conf) if attr: for key, val in attr.items(): if 'active' in val and not val['active']: new_conf[key] = None return new_conf
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
def check_action_config(action, obj, conf, attr): proto = action.prototype spec, flat_spec, _, _ = adcm_config.get_prototype_config(proto, action) if not spec: return None, None if not conf: err('TASK_ERROR', 'action config is required') obj_conf = None if obj.config: cl = ConfigLog.objects.get(obj_ref=obj.config, id=obj.config.current) obj_conf = cl.config adcm_config.check_attr(proto, attr, flat_spec) adcm_config.process_variant(obj, spec, obj_conf) new_conf = adcm_config.check_config_spec(proto, action, spec, flat_spec, conf, None, attr) return new_conf, spec
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
def check_action_config(action: Action, obj: ADCMEntity, conf: dict, attr: dict) -> Tuple[dict, dict]: proto = action.prototype spec, flat_spec, _, _ = adcm_config.get_prototype_config(proto, action) if not spec: return {}, {} if not conf: err('TASK_ERROR', 'action config is required') obj_conf = None if obj.config: cl = ConfigLog.objects.get(obj_ref=obj.config, id=obj.config.current) obj_conf = cl.config adcm_config.check_attr(proto, action, attr, flat_spec) variant.process_variant(obj, spec, obj_conf) new_conf = adcm_config.check_config_spec(proto, action, spec, flat_spec, conf, None, attr) return new_conf, spec
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