You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by zr...@apache.org on 2021/07/30 19:05:41 UTC

[trafficcontrol] branch master updated: updating all APi 1.x endpoints to 2.0 for compatibility (#6059)

This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f17e2e  updating all APi 1.x endpoints to 2.0 for compatibility (#6059)
9f17e2e is described below

commit 9f17e2e3decd9981b8acd5172411797dc84531e6
Author: Ashish P <as...@cable.comcast.com>
AuthorDate: Fri Jul 30 13:05:30 2021 -0600

    updating all APi 1.x endpoints to 2.0 for compatibility (#6059)
    
    * updating all APi 1.x endpoints to 2.0 for compatibility
    
    * updating changelog
    
    * update to API v1 endpoint in snapshot
    
    * fixing compatibility issues
    
    * forcing domainName delegation to be lowercase
    
    * Types are pre-loaded in API 2.0 and up, update playbooks accordingly
    
    * update to TC_LOCfrom INFRA_LOC
    
    * more updates for TC_LOC
    
    * adding service address
    
    * Syntax issue on boolean
    
    * Server create object update with ipIsService
    
    * ipIsService changes in update server playbook
    
    * update to snapshot endpoint
    
    * Using default types var as empty array
---
 CHANGELOG.md                                               |  1 +
 infrastructure/ansible/influxdb_relay.yml                  |  4 ++--
 .../ansible/roles/dataset_loader/defaults/main.yml         | 14 ++++----------
 .../roles/dataset_loader/profile.parameter.conversion.md   |  2 +-
 .../ansible/roles/dataset_loader/tasks/dataset_loader.yml  | 10 +++++++---
 .../ansible/roles/dataset_loader/tasks/ds_loader.yml       |  2 +-
 .../roles/dataset_loader/tasks/update_mso_servers.yml      |  2 ++
 .../ansible/roles/dataset_loader/templates/server.j2       |  2 ++
 infrastructure/ansible/roles/to_api/tasks/login.yml        |  2 +-
 .../ansible/roles/to_api/tasks/queue_updates.yml           |  4 ++--
 .../ansible/roles/to_api/tasks/set_server_status.yml       |  4 ++--
 infrastructure/ansible/roles/to_api/tasks/snapshot.yml     |  2 +-
 .../ansible/roles/traffic_portal/defaults/main.yml         |  2 +-
 infrastructure/ansible/sample.lab/ansible/vars.yml         |  2 +-
 14 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 136564d..7ea2306 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,6 +59,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Enhanced ort integration test for reload states
 - Added a new field to Delivery Services - `tlsVersions` - that explicitly lists the TLS versions that may be used to retrieve their content from Cache Servers.
 - Updated T3C changes in Ansible playbooks 
+- Updated all endpoints in infrastructure code to use API version 2.0
 
 ### Fixed
 - [#5690](https://github.com/apache/trafficcontrol/issues/5690) - Fixed github action for added/modified db migration file.
diff --git a/infrastructure/ansible/influxdb_relay.yml b/infrastructure/ansible/influxdb_relay.yml
index f216590..aa4b04f 100644
--- a/infrastructure/ansible/influxdb_relay.yml
+++ b/infrastructure/ansible/influxdb_relay.yml
@@ -31,7 +31,7 @@
 
     - name: Get TO Cookie
       uri:
-        url: "{{ to_url }}/api/1.3/user/login"
+        url: "{{ to_url }}/api/{{ to_api_version }}/user/login"
         method: POST
         body: '{ "u":"{{ tm_traffic_ops_username }}", "p":"{{ tmonitor_passwd }}" }'
         headers:
@@ -46,7 +46,7 @@
 
     - name: Get All Servers
       uri:
-        url: "{{ to_url }}/api/1.3/servers"
+        url: "{{ to_url }}/api/{{ to_api_version }}/servers"
         method: GET
         validate_certs: no
         follow_redirects: all
diff --git a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml
index 7ab36b3..12c2ee0 100644
--- a/infrastructure/ansible/roles/dataset_loader/defaults/main.yml
+++ b/infrastructure/ansible/roles/dataset_loader/defaults/main.yml
@@ -24,7 +24,7 @@ dl_sf_url: https://czf.kabletown.invalid
 dl_to_user:
 dl_to_user_password:
 # TrafficOps API version to use
-dl_to_api_version: 1.3
+dl_to_api_version: 2.0
 dl_target_api_url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}"
 # URL for the CZF file
 dl_shallow_czf_url: "{{ dl_sf_url }}/czf.json"
@@ -72,13 +72,7 @@ dl_ds_default_cdns:
 
 # TO Types
 dl_ds_merged_types: "{{ dl_ds_default_types }}"
-dl_ds_default_types:
-  - name: TR_LOC
-    description: Traffic Router Logical Location
-    useInTable: cachegroup
-  - name: INFRA_LOC
-    description: Generic Infrastructure Logical Location
-    useInTable: cachegroup
+dl_ds_default_types: []
 
 # The mapping of components from inventory hostvars to TO types
 dl_ds_merged_type_ansible_component_map: "{{ dl_ds_default_type_ansible_component_map }}"
@@ -125,7 +119,7 @@ dl_ds_default_cachegroups:
     parentCachegroup:
     secondaryParentCachegroup:
     localizationMethods:
-    type: INFRA_LOC
+    type: TC_LOC
     fallbackToClosest:
   - name: multi-site-org-east
     shortName: msoe
@@ -738,7 +732,7 @@ dl_ds_default_profile_cdntemplates:
         secure: 0
       - name: federationmapping.polling.url
         configFile: CRConfig.json
-        value: https://${toHostname}/api/1.4/federations/all.json
+        value: https://${toHostname}/api/{{ dl_to_api_version }}/federations/all
         secure: 0
       - name: geolocation.polling.interval
         configFile: CRConfig.json
diff --git a/infrastructure/ansible/roles/dataset_loader/profile.parameter.conversion.md b/infrastructure/ansible/roles/dataset_loader/profile.parameter.conversion.md
index 5a3e4fa..82d7483 100644
--- a/infrastructure/ansible/roles/dataset_loader/profile.parameter.conversion.md
+++ b/infrastructure/ansible/roles/dataset_loader/profile.parameter.conversion.md
@@ -20,7 +20,7 @@
 
 1. Install `jq`
 2. Install `ruby`
-3. Curl to get the response of https://{{ TO_BASE_URL }}/api/1.3/profiles/name/{{ TARGET_PROFILE }}/parameters and save that to a file named `profile.parameters.json`
+3. Curl to get the response of https://{{ TO_BASE_URL }}/api/{{ dl_to_api_version }}/profiles/name/{{ TARGET_PROFILE }}/parameters and save that to a file named `profile.parameters.json`
 4. `jq -r '[.[] | sort_by(.configFile,.name,.value)[] | {name: .name,configFile: .configFile,value: .value,secure: (if .secure then 1 else 0 end)}]' profile.parameters.json > profile.parameters.filtered.json`
 5. `ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))' < profile.parameters.filtered.json > profile.parameters.yml`
 6. Transplant into appropriate ansible var file
diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml
index 918539b..c842fd8 100644
--- a/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml
+++ b/infrastructure/ansible/roles/dataset_loader/tasks/dataset_loader.yml
@@ -52,7 +52,7 @@
     name: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].name | default(cdnDelegationPrimary) }}"
     domainName: "{{ cdnDelegationPrimary }}.{{ (groups['traffic_ops'] | first).split('.')[1:] | join('.') | lower }}"
     dnssecEnabled: "{{ dl_ds_merged_cdns[cdnDelegationPrimary].dnssecEnabled | default(false) | lower }}"
-    cdn_query: "response[?starts_with(domainName,`{{ cdnDelegationPrimary }}`) == `true`].id | [0]"
+    cdn_query: "response[?starts_with(domainName,`{{ cdnDelegationPrimary | lower }}`) == `true`].id | [0]"
     error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]"
   register: update_cdn_out
   failed_when: (update_cdn_out.status == 400 and update_cdn_out.json | to_json | from_json | json_query(error_query) | length != 0) or (update_cdn_out.status > 400 and update_cdn_out.status < 600)
@@ -172,7 +172,7 @@
   with_items: "{{ dl_ds_merged_cachegroups | json_query(type_filter) }}"
   vars:
     type_query: "response[?name == '{{ item.type | default('EDGE_LOC') }}'].id | [0]"
-    type_filter: "[?type == 'INFRA_LOC']"
+    type_filter: "[?type == 'TC_LOC']"
     error_query: "alerts[?level=='error'].text[?!contains(@,'already exists')]"
   register: create_cachegroup_out
   failed_when: (create_cachegroup_out.status == 400 and create_cachegroup_out.json | to_json | from_json | json_query(error_query) | length != 0) or (create_cachegroup_out.status > 400 and create_cachegroup_out.status < 600 and create_cachegroup_out.status != 500)
@@ -703,9 +703,11 @@
     updPending: True
     interfaceName: "{{ hostvars[item].ansible_default_ipv4.interface | default('eth0') }}"
     ipAddress: "{{ hostvars[item].ansible_default_ipv4.address | default(hostvars[item].ansible_host) }}"
+    ipIsService: true
     ipNetmask: "{{ hostvars[item].ansible_default_ipv4.netmask | default('255.255.255.0') }}"
     ipGateway: "{{ hostvars[item].ansible_default_ipv4.gateway | default('127.0.0.0') }}"
     ip6Address: "{{ hostvars[item].ansible_default_ipv6.address | default(omit) }}"
+    ip6IsService: true
     ip6Gateway: "{{ hostvars[item].ansible_default_ipv6.gateway | default(omit) }}"
     interfaceMtu: "{{ hostvars[item].ansible_default_ipv4.mtu | default('9000') }}"
     tcpPort: "{{ (dl_ds_merged_servers[item] | default(dl_ds_merged_servers['server.kabletown.invalid'])).tcpPort | default(omit) }}"
@@ -772,10 +774,12 @@
     cdnId: "{{ cdn_id }}"
     updPending: True
     interfaceName: "eth0"
+    ipIsService: true
     ipAddress: "{{ hostvars[item].ansible_host }}"
     ipNetmask: "255.255.255.0"
     ipGateway: "127.0.0.0"
     ip6Address: "{{ omit }}"
+    ip6IsService: true
     ip6Gateway: "{{ omit }}"
     interfaceMtu: "9000"
     tcpPort: "{{ (dl_ds_merged_servers[item] | default(dl_ds_merged_servers['server.kabletown.invalid'])).tcpPort | default(omit) }}"
@@ -966,7 +970,7 @@
 
 - name: Snapshot all CDNs
   uri:
-    url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/snapshot/{{ item.name }}"
+    url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/snapshot?cdn={{ item.name }}"
     method: PUT
   with_items: "{{ get_all_cdns.json.response[1:] }}"
   register: snapshot_out
diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/ds_loader.yml b/infrastructure/ansible/roles/dataset_loader/tasks/ds_loader.yml
index 6539a47..fcc095b 100644
--- a/infrastructure/ansible/roles/dataset_loader/tasks/ds_loader.yml
+++ b/infrastructure/ansible/roles/dataset_loader/tasks/ds_loader.yml
@@ -122,7 +122,7 @@
 
 - name: you have to call get once for Riak/TO to work right before you can add certs
   uri:
-    url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/name/{{ Target_cdn_name }}/sslkeys.json"
+    url: "{{ dl_to_url }}/api/{{ dl_to_api_version }}/cdns/name/{{ Target_cdn_name }}/sslkeys"
     method: GET
 
 - name: Assign Servers to Delivery Services - Grove
diff --git a/infrastructure/ansible/roles/dataset_loader/tasks/update_mso_servers.yml b/infrastructure/ansible/roles/dataset_loader/tasks/update_mso_servers.yml
index 67aad06..9da7c25 100644
--- a/infrastructure/ansible/roles/dataset_loader/tasks/update_mso_servers.yml
+++ b/infrastructure/ansible/roles/dataset_loader/tasks/update_mso_servers.yml
@@ -49,10 +49,12 @@
     cdnId: "{{ item.cdnId }}"
     updPending: "{{ item.updPending }}"
     interfaceName: "{{ item.interfaceName }}"
+    ipIsService: "{{ item.ipIsService}}"
     ipAddress: "{{ item.ipAddress }}"
     ipNetmask: "{{ item.ipNetmask }}"
     ipGateway: "{{ item.ipGateway }}"
     ip6Address: "{{ item.ip6Address }}"
+    ip6IsService: "{{ item.ip6IsService }}"
     ip6Gateway: "{{ item.ip6Gateway }}"
     interfaceMtu: "{{ item.interfaceMtu }}"
     tcpPort: "{{ item.tcpPort }}"
diff --git a/infrastructure/ansible/roles/dataset_loader/templates/server.j2 b/infrastructure/ansible/roles/dataset_loader/templates/server.j2
index b4bb3f5..00abbcb 100644
--- a/infrastructure/ansible/roles/dataset_loader/templates/server.j2
+++ b/infrastructure/ansible/roles/dataset_loader/templates/server.j2
@@ -26,6 +26,7 @@
 {% endif %}
 {% if ip6Address is defined and ip6Address is not none and ip6Address != omit and ip6Address %}
   "ip6Address": "{{ ip6Address }}",
+  "ip6IsService": {{ ip6IsService }},
 {% endif %}
 {% if ip6Gateway is defined and ip6Gateway is not none and ip6Gateway != omit and ip6Gateway %}
   "ip6Gateway": "{{ ip6Gateway }}",
@@ -68,6 +69,7 @@
   "cachegroupId": {{ cachegroupId }},
   "interfaceName": "{{ interfaceName }}",
   "ipAddress": "{{ ipAddress }}",
+  "ipIsService": {{ ipIsService }},
   "ipNetmask": "{{ ipNetmask }}",
   "ipGateway": "{{ ipGateway }}",
   "interfaceMtu": {{ interfaceMtu }},
diff --git a/infrastructure/ansible/roles/to_api/tasks/login.yml b/infrastructure/ansible/roles/to_api/tasks/login.yml
index e5a9863..25ab357 100644
--- a/infrastructure/ansible/roles/to_api/tasks/login.yml
+++ b/infrastructure/ansible/roles/to_api/tasks/login.yml
@@ -14,7 +14,7 @@
 #
 - name: Get TO Cookie
   uri:
-    url: "{{ to_api_base_url }}/api/1.2/user/login"
+    url: "{{ to_api_base_url }}/api/{{ to_api_version }}/user/login"
     method: POST
     body_format: json
     body: '{ "u":"{{ to_api_login_name }}", "p":"{{ to_api_login_password }}" }'
diff --git a/infrastructure/ansible/roles/to_api/tasks/queue_updates.yml b/infrastructure/ansible/roles/to_api/tasks/queue_updates.yml
index 86a2cb6..75e1be2 100644
--- a/infrastructure/ansible/roles/to_api/tasks/queue_updates.yml
+++ b/infrastructure/ansible/roles/to_api/tasks/queue_updates.yml
@@ -17,7 +17,7 @@
 
 - name: Get cdn details
   uri:
-    url: "{{ to_api_base_url }}/api/1.2/cdns"
+    url: "{{ to_api_base_url }}/api/{{ to_api_version }}/cdns"
     method: GET
     headers:
       Cookie: "{{ hostvars.localhost.login.set_cookie }}"
@@ -29,7 +29,7 @@
 
 - name: "{{ 'Queue updates for ' + to_api_target_cdn }}"
   uri:
-    url: "{{ to_api_base_url }}/api/1.2/cdns/{{ cdns_details.json.response | selectattr('name','equalto',to_api_target_cdn) | map(attribute='id') | list | first }}/queue_update"
+    url: "{{ to_api_base_url }}/api/{{ to_api_version }}/cdns/{{ cdns_details.json.response | selectattr('name','equalto',to_api_target_cdn) | map(attribute='id') | list | first }}/queue_update"
     method: POST
     body_format: json
     headers:
diff --git a/infrastructure/ansible/roles/to_api/tasks/set_server_status.yml b/infrastructure/ansible/roles/to_api/tasks/set_server_status.yml
index 0405704..6a5aa80 100644
--- a/infrastructure/ansible/roles/to_api/tasks/set_server_status.yml
+++ b/infrastructure/ansible/roles/to_api/tasks/set_server_status.yml
@@ -17,7 +17,7 @@
 
 - name: Get server details for {{to_api_target_host}}
   uri:
-    url: "{{ to_api_base_url }}/api/1.2/servers/hostname/{{ to_api_target_host.split('.')[0] }}/details"
+    url: "{{ to_api_base_url }}/api/{{ to_api_version }}/servers/details?hostName={{ to_api_target_host.split('.')[0] }}"
     method: GET
     headers:
       Cookie: "{{ hostvars.localhost.login.set_cookie }}"
@@ -40,7 +40,7 @@
 
 - name: "{{ 'Set state of '+to_api_target_host+' to ' + to_api_desired_state }}"
   uri:
-    url: "{{ to_api_base_url }}/api/1.2/servers/{{ server_details.json.response.id }}/status"
+    url: "{{ to_api_base_url }}/api/{{ to_api_version }}/servers/{{ server_details.json.response.id }}/status"
     method: PUT
     body_format: json
     headers:
diff --git a/infrastructure/ansible/roles/to_api/tasks/snapshot.yml b/infrastructure/ansible/roles/to_api/tasks/snapshot.yml
index 56df17c..66148ee 100644
--- a/infrastructure/ansible/roles/to_api/tasks/snapshot.yml
+++ b/infrastructure/ansible/roles/to_api/tasks/snapshot.yml
@@ -64,7 +64,7 @@
 - name: "Retrieves PENDING snapshot ({{ to_api_target_cdn }})"
   delegate_to: localhost
   uri:
-    url: "{{ to_api_base_url }}/api/1.2/cdns/{{ to_api_target_cdn }}/snapshot/new"
+    url: "{{ to_api_base_url }}/api/{{ to_api_version }}/cdns/{{ to_api_target_cdn }}/snapshot/new"
     method: GET
     follow_redirects: all
     return_content: yes
diff --git a/infrastructure/ansible/roles/traffic_portal/defaults/main.yml b/infrastructure/ansible/roles/traffic_portal/defaults/main.yml
index 8384190..3e55036 100644
--- a/infrastructure/ansible/roles/traffic_portal/defaults/main.yml
+++ b/infrastructure/ansible/roles/traffic_portal/defaults/main.yml
@@ -82,7 +82,7 @@ tp_default_properties_template:
     cacheChecks:
       _comments: These are configurable properties for the cache checks view. The data
         for the cache checks view is derived from TO extensions. The extensions array
-        should include an entry for each of your extensions or you can check GET api/1.3/servers/checks
+        should include an entry for each of your extensions or you can check GET api/{{ to_api_version }}/servers/checks
         to see which checks you have configured.
       show: true
       updatePending:
diff --git a/infrastructure/ansible/sample.lab/ansible/vars.yml b/infrastructure/ansible/sample.lab/ansible/vars.yml
index 764ed6d..30036ad 100644
--- a/infrastructure/ansible/sample.lab/ansible/vars.yml
+++ b/infrastructure/ansible/sample.lab/ansible/vars.yml
@@ -25,7 +25,7 @@ grovetccfg_version: "{{ grove_version }}"
 influxdb_relay_version: adaa2ea-1
 feigner_version: 1.0.0_dev_11248-1
 ats_version: 7.1.4-2.el7
-to_api_version: "1.3"
+to_api_version: "2.0"
 
 todb_username: traffic_ops
 todb_db_name: traffic_ops