| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2020 TATA ELXSI |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the 'License'); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in) |
| 17 | */ |
| 18 | /** |
| 19 | * @file Info VIM Page |
| 20 | */ |
| 21 | import { Component, Injector, OnInit } from '@angular/core'; |
| 22 | import { ActivatedRoute, Router } from '@angular/router'; |
| 23 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
| 24 | import { ERRORDATA } from 'CommonModel'; |
| 25 | import { DataService } from 'DataService'; |
| 26 | import { environment } from 'environment'; |
| 27 | import * as HttpStatus from 'http-status-codes'; |
| 28 | import { RestService } from 'RestService'; |
| 29 | import { isNullOrUndefined } from 'util'; |
| 30 | import { CONFIG, VimAccountDetails, VIMData } from 'VimAccountModel'; |
| 31 | |
| 32 | /** |
| 33 | * Creating component |
| 34 | * @Component InfoVimComponent.html as template url |
| 35 | */ |
| 36 | @Component({ |
| 37 | selector: 'app-info-vim', |
| 38 | templateUrl: './InfoVimComponent.html', |
| 39 | styleUrls: ['./InfoVimComponent.scss'] |
| 40 | }) |
| 41 | /** Exporting a class @exports InfoVimComponent */ |
| 42 | export class InfoVimComponent implements OnInit { |
| 43 | /** To inject services @public */ |
| 44 | public injector: Injector; |
| 45 | |
| 46 | /** vimAccountDetails to populate in InfoVIM Page @private */ |
| 47 | public vimAccountDetails: VimAccountDetails; |
| 48 | |
| 49 | /** Information Top Left @public */ |
| 50 | public configParams: {}[] = []; |
| 51 | |
| 52 | /** Showing more details of collapase */ |
| 53 | public isCollapsed: boolean = true; |
| 54 | |
| 55 | /** Contains vim details @public */ |
| 56 | public vimDetails: {}[]; |
| 57 | |
| 58 | /** Check the Projects loading results @public */ |
| 59 | public isLoadingResults: boolean = false; |
| 60 | |
| 61 | /** Give the message for the loading @public */ |
| 62 | public message: string = 'PLEASEWAIT'; |
| 63 | |
| 64 | /** variables contains paramsID @private */ |
| 65 | private paramsID: string; |
| 66 | |
| 67 | /** Instance of the rest service @private */ |
| 68 | private restService: RestService; |
| 69 | |
| 70 | /** Holds the instance of router class @private */ |
| 71 | private router: Router; |
| 72 | |
| 73 | /** dataService to pass the data from one component to another @private */ |
| 74 | private dataService: DataService; |
| 75 | |
| 76 | /** vimId to populate in InfoVIM Page @private */ |
| 77 | private vimId: string; |
| 78 | |
| 79 | /** Holds teh instance of AuthService class of type AuthService @private */ |
| 80 | private activatedRoute: ActivatedRoute; |
| 81 | |
| 82 | /** Utilizes modal service for any modal operations @private */ |
| 83 | private modalService: NgbModal; |
| 84 | |
| 85 | constructor(injector: Injector) { |
| 86 | this.injector = injector; |
| 87 | this.restService = this.injector.get(RestService); |
| 88 | this.dataService = this.injector.get(DataService); |
| 89 | this.activatedRoute = this.injector.get(ActivatedRoute); |
| 90 | this.modalService = this.injector.get(NgbModal); |
| 91 | this.router = this.injector.get(Router); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Lifecyle Hooks the trigger before component is instantiate |
| 96 | */ |
| 97 | public ngOnInit(): void { |
| 98 | // tslint:disable-next-line:no-backbone-get-set-outside-model |
| 99 | this.paramsID = this.activatedRoute.snapshot.paramMap.get('id'); |
| 100 | this.dataService.currentMessage.subscribe((data: VIMData) => { |
| 101 | this.vimId = data.identifier; |
| 102 | }); |
| 103 | this.generateData(); |
| 104 | } |
| 105 | |
| 106 | /** Routing to VIM Account Details Page @public */ |
| 107 | public onVimAccountBack(): void { |
| 108 | this.router.navigate(['vim/details']).catch(() => { |
| 109 | // Error Cached |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | /** Generate Data function @public */ |
| 114 | public generateData(): void { |
| 115 | this.isLoadingResults = true; |
| 116 | this.restService.getResource(environment.VIMACCOUNTS_URL + '/' + this.paramsID) |
| 117 | .subscribe((vimAccountsData: VimAccountDetails) => { |
| 118 | this.showDetails(vimAccountsData); |
| 119 | if (vimAccountsData.config !== undefined) { |
| 120 | if (vimAccountsData.vim_type === 'openstack') { |
| 121 | this.showOpenstackConfig(vimAccountsData.config); |
| 122 | } else if (vimAccountsData.vim_type === 'aws') { |
| 123 | this.awsConfig(vimAccountsData.config); |
| 124 | } else if (vimAccountsData.vim_type === 'openvim' || vimAccountsData.vim_type === 'opennebula') { |
| 125 | this.openVIMOpenNebulaConfig(vimAccountsData.config); |
| 126 | } else if (vimAccountsData.vim_type === 'vmware') { |
| 127 | this.vmwareConfig(vimAccountsData.config); |
| 128 | } else if (vimAccountsData.vim_type === 'azure') { |
| 129 | this.azureConfig(vimAccountsData.config); |
| 130 | } |
| 131 | } |
| 132 | this.isLoadingResults = false; |
| 133 | }, (error: ERRORDATA) => { |
| 134 | this.isLoadingResults = false; |
| 135 | if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) { |
| 136 | this.router.navigateByUrl('404', { skipLocationChange: true }).catch(); |
| 137 | } else { |
| 138 | this.restService.handleError(error, 'get'); |
| 139 | } |
| 140 | }); |
| 141 | } |
| 142 | |
| 143 | /** show general vim detailed information @public */ |
| 144 | public showDetails(vimAccountsData: VimAccountDetails): void { |
| 145 | this.vimDetails = [ |
| 146 | { |
| 147 | title: 'PAGE.VIMDETAILS.NAME', |
| 148 | value: vimAccountsData.name |
| 149 | }, |
| 150 | { |
| 151 | title: 'PAGE.VIMDETAILS.VIMUSERNAME', |
| 152 | value: vimAccountsData.vim_user |
| 153 | }, |
| 154 | { |
| 155 | title: 'PAGE.VIMDETAILS.VIMURL', |
| 156 | value: vimAccountsData.vim_url |
| 157 | }, |
| 158 | { |
| 159 | title: 'PAGE.VIMDETAILS.VIMTYPE', |
| 160 | value: vimAccountsData.vim_type |
| 161 | }, |
| 162 | { |
| 163 | title: 'PAGE.VIMDETAILS.TENANTNAME', |
| 164 | value: vimAccountsData.vim_tenant_name |
| 165 | }, |
| 166 | { |
| 167 | title: 'PAGE.VIMDETAILS.DESCRIPTION', |
| 168 | value: vimAccountsData.description |
| 169 | }, |
| 170 | { |
| 171 | title: 'PAGE.VIMDETAILS.SCHEMATYPE', |
| 172 | value: vimAccountsData.schema_type |
| 173 | }, |
| 174 | { |
| 175 | title: 'PAGE.VIMDETAILS.SCHEMAVERSION', |
| 176 | value: vimAccountsData.schema_version |
| 177 | } |
| 178 | ]; |
| 179 | } |
| 180 | |
| 181 | /** Openstack Config @public */ |
| 182 | public showOpenstackConfig(config: CONFIG): void { |
| 183 | if (!isNullOrUndefined(config)) { |
| 184 | Object.keys(config).forEach((key: string) => { |
| 185 | if (Array.isArray(config[key])) { |
| 186 | config[key] = JSON.stringify(config[key]); |
| 187 | } |
| 188 | }); |
| 189 | } |
| 190 | let location: string = config.location; |
| 191 | if (!isNullOrUndefined(location)) { |
| 192 | const locationArr: string[] = config.location.split(','); |
| 193 | if (Array.isArray(locationArr)) { |
| 194 | location = locationArr[0]; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | this.configParams = [ |
| 199 | { |
| 200 | title: 'PAGE.VIMDETAILS.SDNCONTROLLER', |
| 201 | value: config.sdn_controller |
| 202 | }, |
| 203 | { |
| 204 | title: 'PAGE.VIMDETAILS.SDNPORTMAPPING', |
| 205 | value: config.sdn_port_mapping |
| 206 | }, |
| 207 | { |
| 208 | title: 'PAGE.VIMDETAILS.VIMNETWORKNAME', |
| 209 | value: config.vim_network_name |
| 210 | }, |
| 211 | { |
| 212 | title: 'PAGE.VIMDETAILS.SECURITYGROUPS', |
| 213 | value: config.security_groups |
| 214 | }, |
| 215 | { |
| 216 | title: 'PAGE.VIMDETAILS.AVAILABILITYZONE', |
| 217 | value: config.availabilityZone |
| 218 | }, |
| 219 | { |
| 220 | title: 'PAGE.VIMDETAILS.REGIONALNAME', |
| 221 | value: config.region_name |
| 222 | }, |
| 223 | { |
| 224 | title: 'PAGE.VIMDETAILS.INSECURE', |
| 225 | value: config.insecure |
| 226 | }, |
| 227 | { |
| 228 | title: 'PAGE.VIMDETAILS.USEEXISTINGFLAVOURS', |
| 229 | value: config.use_existing_flavors |
| 230 | }, |
| 231 | { |
| 232 | title: 'PAGE.VIMDETAILS.USEINTERNALENDPOINT', |
| 233 | value: config.use_internal_endpoint |
| 234 | }, |
| 235 | { |
| 236 | title: 'PAGE.VIMDETAILS.ADDITIONALCONFIG', |
| 237 | value: config.additional_conf |
| 238 | }, |
| 239 | { |
| 240 | title: 'PAGE.VIMDETAILS.APIVERSION', |
| 241 | value: config.APIversion |
| 242 | }, |
| 243 | { |
| 244 | title: 'PAGE.VIMDETAILS.PROJECTDOMAINID', |
| 245 | value: config.project_domain_id |
| 246 | }, |
| 247 | { |
| 248 | title: 'PAGE.VIMDETAILS.PROJECTDOMAINNAME', |
| 249 | value: config.project_domain_name |
| 250 | }, |
| 251 | { |
| 252 | title: 'PAGE.VIMDETAILS.USERDOMAINID', |
| 253 | value: config.user_domain_id |
| 254 | }, |
| 255 | { |
| 256 | title: 'PAGE.VIMDETAILS.USERDOMAINUSER', |
| 257 | value: config.user_domain_name |
| 258 | }, |
| 259 | { |
| 260 | title: 'PAGE.VIMDETAILS.KEYPAIR', |
| 261 | value: config.keypair |
| 262 | }, |
| 263 | { |
| 264 | title: 'PAGE.VIMDETAILS.DATAPLANEPHYSICALNET', |
| 265 | value: config.dataplane_physical_net |
| 266 | }, |
| 267 | { |
| 268 | title: 'PAGE.VIMDETAILS.USEFLOATINGIP', |
| 269 | value: config.use_floating_ip |
| 270 | }, |
| 271 | { |
| 272 | title: 'PAGE.VIMDETAILS.MICROVERSION', |
| 273 | value: config.microversion |
| 274 | }, |
| 275 | { |
| 276 | title: 'PAGE.VIMDETAILS.VIMLOCATION', |
| 277 | value: location |
| 278 | } |
| 279 | ]; |
| 280 | } |
| 281 | |
| 282 | /** AWS Config @public */ |
| 283 | public awsConfig(config: CONFIG): void { |
| 284 | this.configParams = [ |
| 285 | { |
| 286 | title: 'PAGE.VIMDETAILS.SDNCONTROLLER', |
| 287 | value: config.sdn_controller |
| 288 | }, |
| 289 | { |
| 290 | title: 'PAGE.VIMDETAILS.VPCCIDRBLOCK', |
| 291 | value: config.vpc_cidr_block |
| 292 | }, |
| 293 | { |
| 294 | title: 'PAGE.VIMDETAILS.SDNPORTMAPPING', |
| 295 | value: config.sdn_port_mapping |
| 296 | }, |
| 297 | { |
| 298 | title: 'PAGE.VIMDETAILS.SECURITYGROUPS', |
| 299 | value: config.security_groups |
| 300 | }, |
| 301 | { |
| 302 | title: 'PAGE.VIMDETAILS.VIMNETWORKNAME', |
| 303 | value: config.vim_network_name |
| 304 | }, |
| 305 | { |
| 306 | title: 'PAGE.VIMDETAILS.KEYPAIR', |
| 307 | value: config.keypair |
| 308 | }, |
| 309 | { |
| 310 | title: 'PAGE.VIMDETAILS.REGIONALNAME', |
| 311 | value: config.region_name |
| 312 | }, |
| 313 | { |
| 314 | title: 'PAGE.VIMDETAILS.FLAVORIINFO', |
| 315 | value: config.flavor_info |
| 316 | }, |
| 317 | { |
| 318 | title: 'PAGE.VIMDETAILS.ADDITIONALCONFIG', |
| 319 | value: config.additional_conf |
| 320 | } |
| 321 | ]; |
| 322 | } |
| 323 | |
| 324 | /** Open vim and open nebula config @public */ |
| 325 | public openVIMOpenNebulaConfig(config: CONFIG): void { |
| 326 | this.configParams = [ |
| 327 | { |
| 328 | title: 'PAGE.VIMDETAILS.SDNCONTROLLER', |
| 329 | value: config.sdn_controller |
| 330 | }, |
| 331 | { |
| 332 | title: 'PAGE.VIMDETAILS.SDNPORTMAPPING', |
| 333 | value: config.sdn_port_mapping |
| 334 | }, |
| 335 | { |
| 336 | title: 'PAGE.VIMDETAILS.VIMNETWORKNAME', |
| 337 | value: config.vim_network_name |
| 338 | }, |
| 339 | { |
| 340 | title: 'PAGE.VIMDETAILS.ADDITIONALCONFIG', |
| 341 | value: config.additional_conf |
| 342 | } |
| 343 | ]; |
| 344 | } |
| 345 | |
| 346 | /** vmware config @public */ |
| 347 | public vmwareConfig(config: CONFIG): void { |
| 348 | this.configParams = [ |
| 349 | { |
| 350 | title: 'PAGE.VIMDETAILS.SDNCONTROLLER', |
| 351 | value: config.sdn_controller |
| 352 | }, |
| 353 | { |
| 354 | title: 'PAGE.VIMDETAILS.ORGNAME', |
| 355 | value: config.orgname |
| 356 | }, |
| 357 | { |
| 358 | title: 'PAGE.VIMDETAILS.SDNPORTMAPPING', |
| 359 | value: config.sdn_port_mapping |
| 360 | }, |
| 361 | { |
| 362 | title: 'PAGE.VIMDETAILS.VCENTERIP', |
| 363 | value: config.vcenter_ip |
| 364 | }, |
| 365 | { |
| 366 | title: 'PAGE.VIMDETAILS.VIMNETWORKNAME', |
| 367 | value: config.vim_network_name |
| 368 | }, |
| 369 | { |
| 370 | title: 'PAGE.VIMDETAILS.VCENTERPORT', |
| 371 | value: config.vcenter_port |
| 372 | }, |
| 373 | { |
| 374 | title: 'PAGE.VIMDETAILS.ADMINUSERNAME', |
| 375 | value: config.admin_username |
| 376 | }, |
| 377 | { |
| 378 | title: 'PAGE.VIMDETAILS.VCENTERUSER', |
| 379 | value: config.vcenter_user |
| 380 | }, |
| 381 | { |
| 382 | title: 'PAGE.VIMDETAILS.ADMINPASSWORD', |
| 383 | value: config.admin_password |
| 384 | }, |
| 385 | { |
| 386 | title: 'PAGE.VIMDETAILS.VCENTERPASSWORD', |
| 387 | value: config.vcenter_password |
| 388 | }, |
| 389 | { |
| 390 | title: 'PAGE.VIMDETAILS.NSXMANAGER', |
| 391 | value: config.nsx_manager |
| 392 | }, |
| 393 | { |
| 394 | title: 'PAGE.VIMDETAILS.VROPSSITE', |
| 395 | value: config.vrops_site |
| 396 | }, |
| 397 | { |
| 398 | title: 'PAGE.VIMDETAILS.NSXUSER', |
| 399 | value: config.nsx_user |
| 400 | }, |
| 401 | { |
| 402 | title: 'PAGE.VIMDETAILS.VROPSUSER', |
| 403 | value: config.vrops_user |
| 404 | }, |
| 405 | { |
| 406 | title: 'PAGE.VIMDETAILS.NSXPASSWORD', |
| 407 | value: config.nsx_password |
| 408 | }, |
| 409 | { |
| 410 | title: 'PAGE.VIMDETAILS.VROPSPASSWORD', |
| 411 | value: config.vrops_password |
| 412 | }, |
| 413 | { |
| 414 | title: 'PAGE.VIMDETAILS.ADDITIONALCONFIG', |
| 415 | value: config.additional_conf |
| 416 | } |
| 417 | ]; |
| 418 | } |
| 419 | |
| 420 | /** Azure Config @public */ |
| 421 | public azureConfig(config: CONFIG): void { |
| 422 | this.configParams = [ |
| 423 | { |
| 424 | title: 'PAGE.VIMDETAILS.SUBSCRIPTIONID', |
| 425 | value: config.subscription_id |
| 426 | }, |
| 427 | { |
| 428 | title: 'PAGE.VIMDETAILS.REGIONALNAME', |
| 429 | value: config.region_name |
| 430 | }, |
| 431 | { |
| 432 | title: 'PAGE.VIMDETAILS.RESOURCEGROUP', |
| 433 | value: config.resource_group |
| 434 | }, |
| 435 | { |
| 436 | title: 'PAGE.VIMDETAILS.VNETNAME', |
| 437 | value: config.vnet_name |
| 438 | }, |
| 439 | { |
| 440 | title: 'PAGE.VIMDETAILS.FLAVORSPATTERN', |
| 441 | value: config.flavors_pattern |
| 442 | } |
| 443 | ]; |
| 444 | } |
| 445 | } |