Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 1 | export function getSips() { |
| 2 | |
| 3 | return new Promise((resolve, reject) => { |
| 4 | fetch(`/dcs/operations/tapi-common:get-service-interface-point-list`, { |
| 5 | method: 'POST', |
| 6 | headers: { |
| 7 | "Content-Type": "application/json", |
| 8 | }, |
| 9 | body: "{}" |
| 10 | }) |
| 11 | .then(res => { |
| 12 | if (res.ok) { |
| 13 | res.json().then(data => resolve(data["tapi-common:output"]["sip"])) |
| 14 | } else { |
| 15 | reject(res.text()) |
| 16 | } |
| 17 | }) |
| 18 | .catch(err => { |
| 19 | console.error(err) |
| 20 | }) |
| 21 | }) |
| 22 | } |
| 23 | |
| 24 | export function getSipDetail(uuid) { |
| 25 | |
| 26 | return new Promise((resolve, reject) => { |
| 27 | fetch(`/dcs/data/tapi-common:context/service-interface-point=${uuid}`, { |
| 28 | method: 'GET', |
| 29 | }) |
| 30 | .then(res => { |
| 31 | if (res.ok) { |
| 32 | res.json().then(data => resolve(data["tapi-common:service-interface-point"][0])) |
| 33 | } else { |
| 34 | reject(res.text()) |
| 35 | } |
| 36 | }) |
| 37 | .catch(err => { |
| 38 | console.error(err) |
| 39 | }) |
| 40 | }) |
| 41 | } |
| 42 | |
| 43 | |
| 44 | export function getConnectivityServices() { |
| 45 | |
| 46 | return new Promise((resolve, reject) => { |
| 47 | fetch(`/dcs/operations/tapi-connectivity:get-connectivity-service-list`, { |
| 48 | method: 'POST', |
| 49 | headers: { |
| 50 | "Content-Type": "application/json", |
| 51 | }, |
| 52 | body: '{}' |
| 53 | }) |
| 54 | .then(res => { |
| 55 | console.log(res) |
| 56 | if (res.ok) { |
| 57 | res.json().then(data => resolve(data["tapi-connectivity:output"]["service"])) |
| 58 | } else { |
| 59 | reject(res.text()) |
| 60 | } |
| 61 | }) |
| 62 | .catch(err => { |
| 63 | console.error(err) |
| 64 | }) |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | |
| 69 | export function createConnectivityService(sip1, sip2) { |
| 70 | |
| 71 | return new Promise((resolve, reject) => { |
| 72 | fetch(`/dcs/operations/tapi-connectivity:create-connectivity-service`, { |
| 73 | method: 'POST', |
| 74 | headers: { |
| 75 | "Content-Type": "application/json", |
| 76 | }, |
| 77 | body: getCreateRequestBody(sip1, sip2) |
| 78 | }) |
| 79 | .then(res => { |
| 80 | console.log(res) |
| 81 | if (res.ok) { |
| 82 | res.json().then(data => resolve(data["tapi-connectivity:output"]["service"])) |
| 83 | } else { |
| 84 | reject(res.text()) |
| 85 | } |
| 86 | }) |
| 87 | .catch(err => { |
| 88 | console.error(err) |
| 89 | }) |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | |
| 94 | export function deleteConnectivityServices(uuid) { |
| 95 | |
| 96 | return new Promise((resolve, reject) => { |
| 97 | fetch(`/dcs/operations/tapi-connectivity:delete-connectivity-service`, { |
| 98 | method: 'POST', |
| 99 | headers: { |
| 100 | "Content-Type": "application/json", |
| 101 | }, |
| 102 | body: getDeleteRequestBody(uuid) |
| 103 | }) |
| 104 | .then(res => { |
| 105 | console.log(res) |
| 106 | if (res.ok) { |
| 107 | resolve() |
| 108 | } else { |
| 109 | reject(res.text()) |
| 110 | } |
| 111 | }) |
| 112 | .catch(err => { |
| 113 | console.error(err) |
| 114 | }) |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | |
| 119 | function getCreateRequestBody(sip1, sip2){ |
| 120 | return `{ |
| 121 | "tapi-connectivity:input": |
| 122 | { |
| 123 | "end-point" : [ |
| 124 | { |
| 125 | "local-id": "id1", |
| 126 | "service-interface-point": { |
| 127 | "service-interface-point-uuid" : "${sip1}" |
| 128 | } |
| 129 | } |
| 130 | , |
| 131 | { |
| 132 | "local-id": "id2", |
| 133 | "service-interface-point": { |
| 134 | "service-interface-point-uuid" : "${sip2}" |
| 135 | } |
| 136 | } |
| 137 | ] |
| 138 | } |
| 139 | }` |
| 140 | } |
| 141 | |
| 142 | function getDeleteRequestBody(uuid){ |
| 143 | return `{ |
| 144 | "tapi-connectivity:input": |
| 145 | { |
| 146 | "service-id-or-name" : "${uuid}" |
| 147 | } |
| 148 | }` |
| 149 | } |