Bartek Grzybowski | fbbdbec | 2019-09-25 16:37:05 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 2 | |
| 3 | import logging |
| 4 | from vcpecommon import * |
| 5 | import csar_parser |
| 6 | |
| 7 | |
| 8 | def insert_customer_service_to_sdnc(vcpecommon): |
| 9 | """ |
| 10 | INSERT INTO SERVICE_MODEL (`service_uuid`, `model_yaml`,`invariant_uuid`,`version`,`name`,`description`,`type`,`category`,`ecomp_naming`,`service_instance_name_prefix`,`filename`,`naming_policy`) values ('7e319b6f-e710-440e-bbd2-63c1004949ef', null, 'a99ace8a-6e3b-447d-b2ff-4614e4234eea',null,'vCPEService', 'vCPEService', 'Service','Network L1-3', 'N', 'vCPEService', 'vCpeResCust110701/service-Vcperescust110701-template.yml',null); |
| 11 | INSERT INTO ALLOTTED_RESOURCE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`,`naming_policy`,`ecomp_generated_naming`,`depending_service`,`role`,`type`,`service_dependency`,`allotted_resource_type`) VALUES ( '7e40b664-d7bf-47ad-8f7c-615631d53cd7', NULL, 'f51b0aae-e24a-4cff-b190-fe3daf3d15ee', 'f3137496-1605-40e9-b6df-64aa0f8e91a0', '1.0', NULL,'Y',NULL,NULL,'TunnelXConnect',NULL, 'TunnelXConnect'); |
| 12 | INSERT INTO ALLOTTED_RESOURCE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`,`naming_policy`,`ecomp_generated_naming`,`depending_service`,`role`,`type`,`service_dependency`,`allotted_resource_type`) VALUES ( 'e46097e1-6a0c-4cf3-a7e5-c39ed407e65e', NULL, 'aa60f6ba-541b-48d6-a5ff-3b0e1f0ad9bf', '0e157d52-b945-422f-b3a8-ab685c2be079', '1.0', NULL,'Y',NULL,NULL,'BRG',NULL, 'TunnelXConnect'); |
| 13 | INSERT INTO VF_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`,`name`,`naming_policy`,`ecomp_generated_naming`,`avail_zone_max_count`,`nf_function`,`nf_code`,`nf_type`,`nf_role`,`vendor`,`vendor_version`) VALUES ( '3768afa5-cf9e-4071-bb25-3a2e2628dd87', NULL, '5f56893b-d026-4672-b785-7f5ffeb498c6', '7cf28b23-5719-485b-9ab4-dae1a2fa0e07', '1.0', 'vspvgw111601',NULL,'Y',1,NULL,NULL,NULL,NULL,'vCPE','1.0'); |
| 14 | INSERT INTO VF_MODULE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`,`vf_module_type`,`availability_zone_count`,`ecomp_generated_vm_assignments`) VALUES ( '17a9c7d1-6f8e-4930-aa83-0d323585184f', NULL, 'd772ddd1-7623-40b4-a2a5-ec287916cb51', '6e1a0652-f5e9-4caa-bff8-39bf0c8589a3', '1.0', 'Base',NULL,NULL); |
| 15 | |
| 16 | :return: |
| 17 | """ |
| 18 | logger = logging.getLogger('__name__') |
| 19 | logger.info('Inserting customer service data to SDNC DB') |
| 20 | csar_file = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 21 | parser = csar_parser.CsarParser() |
| 22 | parser.parse_csar(csar_file) |
| 23 | cmds = [] |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 24 | |
| 25 | if False: |
| 26 | cmds.append("INSERT INTO SERVICE_MODEL (`service_uuid`, `model_yaml`,`invariant_uuid`,`version`,`name`," \ |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 27 | "`description`,`type`,`category`,`ecomp_naming`,`service_instance_name_prefix`,`filename`," \ |
| 28 | "`naming_policy`) values ('{0}', null, '{1}',null,'{2}', 'vCPEService', 'Service','Network L1-3'," \ |
| 29 | "'N', 'vCPEService', '{3}/{4}',null);".format(parser.svc_model['modelVersionId'], |
| 30 | parser.svc_model['modelInvariantId'], |
| 31 | parser.svc_model['modelName'], |
| 32 | parser.svc_model['modelName'], |
| 33 | parser.svc_model['modelName'])) |
| 34 | |
| 35 | for model in parser.vnf_models: |
| 36 | if 'tunnel' in model['modelCustomizationName'].lower() or 'brg' in model['modelCustomizationName'].lower(): |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 37 | if False: |
| 38 | cmds.append("INSERT INTO ALLOTTED_RESOURCE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`," \ |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 39 | "`uuid`,`version`,`naming_policy`,`ecomp_generated_naming`,`depending_service`,`role`,`type`," \ |
| 40 | "`service_dependency`,`allotted_resource_type`) VALUES ('{0}',NULL,'{1}','{2}','1.0'," \ |
| 41 | "NULL,'Y', NULL,NULL,'TunnelXConnect'," \ |
| 42 | "NULL, 'TunnelXConnect');".format(model['modelCustomizationId'], model['modelInvariantId'], |
| 43 | model['modelVersionId'])) |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 44 | cmds.append("UPDATE ALLOTTED_RESOURCE_MODEL SET `ecomp_generated_naming`='Y' " \ |
| 45 | "WHERE `customization_uuid`='{0}'".format(model['modelCustomizationId'])) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 46 | else: |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 47 | if False: |
| 48 | cmds.append("INSERT INTO VF_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`," \ |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 49 | "`name`,`naming_policy`,`ecomp_generated_naming`,`avail_zone_max_count`,`nf_function`," \ |
| 50 | "`nf_code`,`nf_type`,`nf_role`,`vendor`,`vendor_version`) VALUES ('{0}',NULL,'{1}','{2}'," \ |
| 51 | "'1.0', '{3}',NULL,'Y',1,NULL,NULL,NULL,NULL,'vCPE'," \ |
| 52 | "'1.0');".format(model['modelCustomizationId'], model['modelInvariantId'], |
| 53 | model['modelVersionId'], model['modelCustomizationName'].split()[0])) |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 54 | cmds.append("UPDATE VF_MODEL SET `ecomp_generated_naming`='Y' " \ |
| 55 | "WHERE `customization_uuid`='{0}'".format(model['modelCustomizationId'])) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 56 | |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 57 | if False: |
| 58 | model = parser.vfmodule_models[0] |
| 59 | cmds.append("INSERT INTO VF_MODULE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`," \ |
| 60 | "`vf_module_type`,`availability_zone_count`,`ecomp_generated_vm_assignments`) VALUES ('{0}', NULL," \ |
| 61 | "'{1}', '{2}', '1.0', 'Base',NULL,NULL)" \ |
| 62 | ";".format(model['modelCustomizationId'], model['modelInvariantId'], model['modelVersionId'])) |
| 63 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 64 | print('\n'.join(cmds)) |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 65 | vcpecommon.execute_cmds_sdnc_db(cmds) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 66 | |
| 67 | |
| 68 | def insert_customer_service_to_so(vcpecommon): |
Yang Xu | 1b31a1d | 2019-06-26 01:50:15 -0400 | [diff] [blame] | 69 | logger = logging.getLogger(__name__) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 70 | cmds = [] |
Bartek Grzybowski | ba8a72f | 2019-11-22 15:02:21 +0100 | [diff] [blame^] | 71 | csar_file = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 72 | parser = csar_parser.CsarParser() |
| 73 | parser.parse_csar(csar_file) |
| 74 | cmds.append("INSERT IGNORE INTO service_recipe (ACTION, VERSION_STR, DESCRIPTION, ORCHESTRATION_URI, " \ |
| 75 | "SERVICE_PARAM_XSD, RECIPE_TIMEOUT, SERVICE_TIMEOUT_INTERIM, CREATION_TIMESTAMP, " \ |
| 76 | "SERVICE_MODEL_UUID) VALUES ('createInstance','1','{0}'," \ |
| 77 | "'/mso/async/services/CreateVcpeResCustService',NULL,181,NULL, NOW()," \ |
| 78 | "'{1}');".format(parser.svc_model['modelName'], parser.svc_model['modelVersionId'])) |
| 79 | if vcpecommon.oom_mode: |
| 80 | logger.info('Inserting vcpe customer service workflow entry into SO catalogdb') |
| 81 | vcpecommon.execute_cmds_so_db(cmds) |
| 82 | else: |
| 83 | logger.info('\n\nManually run a command from Rancher node to insert vcpe' |
| 84 | 'customer service workflow entry in SO catalogdb:\n' |
| 85 | '\nkubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0' |
| 86 | ' -- mysql -uroot -psecretpassword catalogdb -e ' |
| 87 | '"'.format(vcpecommon.onap_namespace, |
| 88 | vcpecommon.onap_environment) + '\n'.join(cmds) + '"') |
Bartek Grzybowski | 9018a84 | 2019-10-16 15:28:23 +0200 | [diff] [blame] | 89 | |
| 90 | def insert_sdnc_ip_pool(vcpecommon): |
| 91 | logger = logging.getLogger(__name__) |
| 92 | logger.info('Inserting SDNC ip pool to SDNC DB') |
| 93 | cmds = [] |
| 94 | # Get the VGWs network address |
| 95 | vgw_net = '.'.join(vcpecommon.preload_network_config['mux_gw'][0].split('.')[:3]) |
| 96 | row_values = [] |
| 97 | # Prepare single INSERT statement with all IP values |
| 98 | for ip in range(22,250): |
| 99 | row_values.append("('', 'VGW', 'AVAILABLE','{0}.{1}')".format(vgw_net,ip)) |
Bartek Grzybowski | ab9b1d5 | 2019-10-24 12:49:04 +0200 | [diff] [blame] | 100 | cmds.append("INSERT IGNORE INTO IPV4_ADDRESS_POOL VALUES" + ', '.join(row_values) + ';') |
Bartek Grzybowski | 9018a84 | 2019-10-16 15:28:23 +0200 | [diff] [blame] | 101 | vcpecommon.execute_cmds_mariadb(cmds) |