Esempio n. 1
0
 def attribute_default(self, tenant, attrs, name, default):
     if name in attrs:
         value = attrs[name]
     else:
         value = default
         logger.info("saving default value %s for attribute %s" % (value, name))
         ta = TenantAttribute(tenant=tenant, name=name, value=value)
         ta.save()
     return value
Esempio n. 2
0
 def attribute_default(self, tenant, attrs, name, default):
     if name in attrs:
         value = attrs[name]
     else:
         value = default
         logger.info("saving default value %s for attribute %s" %
                     (value, name))
         ta = TenantAttribute(tenant=tenant, name=name, value=value)
         ta.save()
     return value
Esempio n. 3
0
 def save_tenant_attribute(self, tenant, name, value):
     tas = TenantAttribute.objects.filter(tenant=tenant, name=name)
     if tas:
         ta = tas[0]
         if ta.value != value:
             logger.info("updating %s with attribute" % name)
             ta.value = value
             ta.save()
     else:
         logger.info("saving autogenerated config %s" % name)
         ta = TenantAttribute(tenant=tenant, name=name, value=value)
         ta.save()
Esempio n. 4
0
 def set_tenant_attr(self, obj, prop_name, value):
     value = self.try_intrinsic_function(value)
     if value:
         attrs = TenantAttribute.objects.filter(tenant=obj, name=prop_name)
         if attrs:
             attr = attrs[0]
             if attr.value != value:
                 self.info("updating attribute %s" % prop_name)
                 attr.value = value
                 attr.save()
         else:
             self.info("adding attribute %s" % prop_name)
             ta = TenantAttribute(tenant=obj, name=prop_name, value=value)
             ta.save()
Esempio n. 5
0
 def set_tenant_attr(self, obj, prop_name, value):
     value = self.try_intrinsic_function(value)
     if value:
         attrs = TenantAttribute.objects.filter(tenant=obj, name=prop_name)
         if attrs:
             attr = attrs[0]
             if attr.value != value:
                 self.info("updating attribute %s" % prop_name)
                 attr.value = value
                 attr.save()
         else:
             self.info("adding attribute %s" % prop_name)
             ta = TenantAttribute(tenant=obj, name=prop_name, value=value)
             ta.save()
Esempio n. 6
0
    def write_configs(self, o):
        o.config_fns = []
        o.rest_configs = []
        o.component_configs = []
        o.files_dir = self.get_files_dir(o)

        if not os.path.exists(o.files_dir):
            os.makedirs(o.files_dir)

        # Combine the service attributes with the tenant attributes. Tenant
        # attribute can override service attributes.
        attrs = o.provider_service.serviceattribute_dict
        attrs.update(o.tenantattribute_dict)

        ordered_attrs = attrs.keys()

        onos = self.get_onos_service(o)
        if onos.node_key:
            file(os.path.join(o.files_dir, "node_key"),
                 "w").write(onos.node_key)
            o.node_key_fn = "node_key"
        else:
            o.node_key_fn = None

        o.early_rest_configs = []
        if ("cordvtn" in o.dependencies) and (not self.is_no_container(o)):
            # For VTN, since it's running in a docker host container, we need
            # to make sure it configures the cluster using the right ip addresses.
            # NOTE: rest_onos/v1/cluster/configuration/ will reboot the cluster and
            #   must go first.
            name = "rest_onos/v1/cluster/configuration/"
            value = self.get_cluster_configuration(o)
            fn = name[5:].replace("/", "_")
            endpoint = name[5:]
            file(os.path.join(o.files_dir, fn), "w").write(" " + value)
            o.early_rest_configs.append({"endpoint": endpoint, "fn": fn})

        # Generate config files and save them to the appropriate tenant attributes
        configs = []
        for key, value in attrs.iteritems():
            if key == "autogenerate" and value:
                for config in value.split(','):
                    configs.append(config.strip())

        for label in configs:
            config = None
            value = None
            if label == "vtn-network-cfg":
                # Generate the VTN config file... where should this live?
                config = "rest_onos/v1/network/configuration/"
                value = self.get_vtn_config(o, attrs)
            elif label == "volt-network-cfg":
                config = "rest_onos/v1/network/configuration/"
                value = self.get_volt_network_config(o, attrs)
            elif label == "volt-component-cfg":
                config = "component_config"
                value = self.get_volt_component_config(o, attrs)
            elif label == "vrouter-network-cfg":
                config = "rest_onos/v1/network/configuration/"
                value = self.get_vrouter_network_config(o, attrs)

            if config:
                tas = TenantAttribute.objects.filter(tenant=o, name=config)
                if tas:
                    ta = tas[0]
                    if ta.value != value:
                        logger.info("updating %s with autogenerated config" %
                                    config)
                        ta.value = value
                        ta.save()
                        attrs[config] = value
                else:
                    logger.info("saving autogenerated config %s" % config)
                    ta = TenantAttribute(tenant=o, name=config, value=value)
                    ta.save()
                    attrs[config] = value

        for name in attrs.keys():
            value = attrs[name]
            if name.startswith("config_"):
                fn = name[7:]  # .replace("_json",".json")
                o.config_fns.append(fn)
                file(os.path.join(o.files_dir, fn), "w").write(value)
            if name.startswith("rest_"):
                fn = name[5:].replace("/", "_")
                endpoint = name[5:]
                # Ansible goes out of it's way to make our life difficult. If
                # 'lookup' sees a file that it thinks contains json, then it'll
                # insist on parsing and return a json object. We just want
                # a string, so prepend a space and then strip the space off
                # later.
                file(os.path.join(o.files_dir, fn), "w").write(" " + value)
                o.rest_configs.append({"endpoint": endpoint, "fn": fn})
            if name.startswith("component_config"):
                components = json.loads(value, object_pairs_hook=OrderedDict)
                for component in components.keys():
                    config = components[component]
                    for key in config.keys():
                        config_val = config[key]
                        found = re.findall('<(.+?)>', config_val)
                        for x in found:
                            #Get value corresponding to that string
                            val = self.get_dynamic_parameter_value(o, x)
                            if val:
                                config_val = re.sub('<' + x + '>', val,
                                                    config_val)
                            #TODO: else raise an exception?
                        o.component_configs.append({
                            "component":
                            component,
                            "config_params":
                            "'{\"" + key + "\":\"" + config_val + "\"}'"
                        })
Esempio n. 7
0
    def write_configs(self, o):
        o.config_fns = []
        o.rest_configs = []
        o.component_configs = []
        o.files_dir = self.get_files_dir(o)

        if not os.path.exists(o.files_dir):
            os.makedirs(o.files_dir)

        # Combine the service attributes with the tenant attributes. Tenant
        # attribute can override service attributes.
        attrs = o.provider_service.serviceattribute_dict
        attrs.update(o.tenantattribute_dict)

        ordered_attrs = attrs.keys()

        onos = self.get_onos_service(o)
        if onos.node_key:
            file(os.path.join(o.files_dir, "node_key"),"w").write(onos.node_key)
            o.node_key_fn="node_key"
        else:
            o.node_key_fn=None

        o.early_rest_configs=[]
        if ("cordvtn" in o.dependencies) and (not self.is_no_container(o)):
            # For VTN, since it's running in a docker host container, we need
            # to make sure it configures the cluster using the right ip addresses.
            # NOTE: rest_onos/v1/cluster/configuration/ will reboot the cluster and
            #   must go first.
            name="rest_onos/v1/cluster/configuration/"
            value= self.get_cluster_configuration(o)
            fn = name[5:].replace("/","_")
            endpoint = name[5:]
            file(os.path.join(o.files_dir, fn),"w").write(" " +value)
            o.early_rest_configs.append( {"endpoint": endpoint, "fn": fn} )

        # Generate config files and save them to the appropriate tenant attributes
        autogen = []
        for key, value in attrs.iteritems():
            if key == "autogenerate" and value:
                autogen.append(value)
        for label in autogen:
            config = None
            value = None
            if label == "vtn-network-cfg":
            # Generate the VTN config file... where should this live?
                config = "rest_onos/v1/network/configuration/"
                value = self.get_vtn_config(o, attrs)
            if config:
                tas = TenantAttribute.objects.filter(tenant=o, name=config)
                if tas:
                    ta = tas[0]
                    if ta.value != value:
                        logger.info("updating %s with autogenerated config" % config)
                        ta.value = value
                        ta.save()
                        attrs[config] = value
                else:
                    logger.info("saving autogenerated config %s" % config)
                    ta = TenantAttribute(tenant=o, name=config, value=value)
                    ta.save()
                    attrs[config] = value

        for name in attrs.keys():
            value = attrs[name]
            if name.startswith("config_"):
                fn = name[7:] # .replace("_json",".json")
                o.config_fns.append(fn)
                file(os.path.join(o.files_dir, fn),"w").write(value)
            if name.startswith("rest_"):
                fn = name[5:].replace("/","_")
                endpoint = name[5:]
                # Ansible goes out of it's way to make our life difficult. If
                # 'lookup' sees a file that it thinks contains json, then it'll
                # insist on parsing and return a json object. We just want
                # a string, so prepend a space and then strip the space off
                # later.
                file(os.path.join(o.files_dir, fn),"w").write(" " +value)
                o.rest_configs.append( {"endpoint": endpoint, "fn": fn} )
            if name.startswith("component_config"):
                components = json.loads(value,object_pairs_hook=OrderedDict)
                for component in components.keys():
                    config = components[component]
                    for key in config.keys():
                         config_val = config[key]
                         found = re.findall('<(.+?)>',config_val)
                         for x in found:
                            #Get value corresponding to that string
                            val = self.get_dynamic_parameter_value(o, x)
                            if val:
	                       config_val = re.sub('<'+x+'>', val, config_val)
                            #TODO: else raise an exception?
	                 o.component_configs.append( {"component": component, "config_params": "'{\""+key+"\":\""+config_val+"\"}'"} )