Updates to Inventory object
[apex.git] / apex / overcloud / overcloud_deploy.py
index 395e623..ef916a4 100644 (file)
@@ -20,7 +20,7 @@ import time
 from apex.common import constants as con
 from apex.common.exceptions import ApexDeployException
 from apex.common import parsers
-from apex.virtual import virtual_utils as virt_utils
+from apex.virtual import utils as virt_utils
 from cryptography.hazmat.primitives import serialization as \
     crypto_serialization
 from cryptography.hazmat.primitives.asymmetric import rsa
@@ -93,34 +93,6 @@ def build_sdn_env_list(ds, sdn_map, env_list=None):
     return env_list
 
 
-def _get_node_counts(inventory):
-    """
-    Return numbers of controller and compute nodes in inventory
-
-    :param inventory: node inventory data structure
-    :return: number of controller and compute nodes in inventory
-    """
-    if not inventory:
-        raise ApexDeployException("Empty inventory")
-
-    nodes = inventory['nodes']
-    num_control = 0
-    num_compute = 0
-    for node in nodes:
-        if node['capabilities'] == 'profile:control':
-            num_control += 1
-        elif node['capabilities'] == 'profile:compute':
-            num_compute += 1
-        else:
-            # TODO(trozet) do we want to allow capabilities to not exist?
-            logging.error("Every node must include a 'capabilities' key "
-                          "tagged with either 'profile:control' or "
-                          "'profile:compute'")
-            raise ApexDeployException("Node missing capabilities "
-                                      "key: {}".format(node))
-    return num_control, num_compute
-
-
 def create_deploy_cmd(ds, ns, inv, tmp_dir,
                       virtual, env_file='opnfv-environment.yaml'):
 
@@ -129,7 +101,6 @@ def create_deploy_cmd(ds, ns, inv, tmp_dir,
     ds_opts = ds['deploy_options']
     deploy_options += build_sdn_env_list(ds_opts, SDN_FILE_MAP)
 
-    # TODO(trozet): make sure rt kvm file is in tht dir
     for k, v in OTHER_FILE_MAP.items():
         if k in ds_opts and ds_opts[k]:
             deploy_options.append(os.path.join(con.THT_ENV_DIR, v))
@@ -147,7 +118,7 @@ def create_deploy_cmd(ds, ns, inv, tmp_dir,
     else:
         deploy_options.append('baremetal-environment.yaml')
 
-    num_control, num_compute = _get_node_counts(inv)
+    num_control, num_compute = inv.get_node_counts()
     if num_control == 0 or num_compute == 0:
         logging.error("Detected 0 control or compute nodes.  Control nodes: "
                       "{}, compute nodes{}".format(num_control, num_compute))
@@ -245,6 +216,12 @@ def prep_image(ds, img, tmp_dir, root_pw=None):
         virt_cmds.append(
             {con.VIRT_RUN_CMD: "cd /usr/lib/python2.7/site-packages && patch "
                                "-p1 < neutron-patch-NSDriver.patch"})
+        if sdn is False:
+            virt_cmds.extend([
+                {con.VIRT_RUN_CMD: "yum remove -y vpp-lib"},
+                {con.VIRT_RUN_CMD: "yum install -y "
+                                   "/root/nosdn_vpp_rpms/*.rpm"}
+            ])
 
     if sdn == 'opendaylight':
         if ds_opts['odl_version'] != con.DEFAULT_ODL_VERSION:
@@ -309,8 +286,7 @@ def make_ssh_key():
         crypto_serialization.Encoding.OpenSSH,
         crypto_serialization.PublicFormat.OpenSSH
     )
-    pub_key = re.sub('ssh-rsa\s*', '', public_key.decode('utf-8'))
-    return private_key.decode('utf-8'), pub_key
+    return private_key.decode('utf-8'), public_key.decode('utf-8')
 
 
 def prep_env(ds, ns, inv, opnfv_env, net_env, tmp_dir):
@@ -371,9 +347,13 @@ def prep_env(ds, ns, inv, opnfv_env, net_env, tmp_dir):
         if 'CloudDomain' in line:
             output_line = "  CloudDomain: {}".format(ns['domain_name'])
         elif 'replace_private_key' in line:
-            output_line = "      key: '{}'".format(private_key)
+            output_line = "    private_key: |\n"
+            key_out = ''
+            for line in private_key.splitlines():
+                key_out += "      {}\n".format(line)
+            output_line += key_out
         elif 'replace_public_key' in line:
-            output_line = "      key: '{}'".format(public_key)
+            output_line = "    public_key: '{}'".format(public_key)
 
         if ds_opts['sdn_controller'] == 'opendaylight' and \
                 'odl_vpp_routing_node' in ds_opts:
@@ -402,7 +382,7 @@ def prep_env(ds, ns, inv, opnfv_env, net_env, tmp_dir):
             if 'OS::TripleO::Services::NeutronDhcpAgent' in line:
                 output_line = ''
             elif 'NeutronDhcpAgentsPerNetwork' in line:
-                num_control, num_compute = _get_node_counts(inv)
+                num_control, num_compute = inv.get_node_counts()
                 output_line = ("  NeutronDhcpAgentsPerNetwork: {}"
                                .format(num_compute))
             elif 'ComputeServices' in line:
@@ -453,17 +433,16 @@ def prep_env(ds, ns, inv, opnfv_env, net_env, tmp_dir):
                 ds_opts['dataplane'] == 'ovs_dpdk':
             print('  OS::TripleO::ComputeExtraConfigPre: '
                   './ovs-dpdk-preconfig.yaml')
-        elif perf and perf_kern_comp:
-            if 'resource_registry' in line:
-                print("resource_registry:\n"
-                      "  OS::TripleO::NodeUserData: first-boot.yaml")
-            elif 'NovaSchedulerDefaultFilters' in line:
-                print("  NovaSchedulerDefaultFilters: 'RamFilter,"
-                      "ComputeFilter,AvailabilityZoneFilter,"
-                      "ComputeCapabilitiesFilter,ImagePropertiesFilter,"
-                      "NUMATopologyFilter'")
-            else:
-                print(line)
+        elif ((perf and perf_kern_comp) or ds_opts.get('rt_kvm')) and \
+                'resource_registry' in line:
+            print("resource_registry:\n"
+                  "  OS::TripleO::NodeUserData: first-boot.yaml")
+        elif perf and perf_kern_comp and \
+                'NovaSchedulerDefaultFilters' in line:
+            print("  NovaSchedulerDefaultFilters: 'RamFilter,"
+                  "ComputeFilter,AvailabilityZoneFilter,"
+                  "ComputeCapabilitiesFilter,ImagePropertiesFilter,"
+                  "NUMATopologyFilter'")
         else:
             print(line)