MigrationNetworks.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React, { Component, PropTypes } from 'react';
  15. import withStyles from 'isomorphic-style-loader/lib/withStyles';
  16. import Table from '../Table';
  17. import s from './MigrationNetworks.scss';
  18. const title = 'Migration Networks';
  19. class MigrationNetworks extends Component {
  20. static contextTypes = {
  21. onSetTitle: PropTypes.func.isRequired,
  22. };
  23. static propTypes = {
  24. migration: PropTypes.object
  25. }
  26. constructor(props) {
  27. super(props)
  28. this.headers = [
  29. { label: "Source Network", key: 'source_network' },
  30. { label: "Connected VMs", key: 'connected_vms' },
  31. { label: "Destination Network", key: 'destination_network' },
  32. { label: "Destination Type", key: 'destination_type' }
  33. ]
  34. this.listItems = []
  35. this.processProps(props)
  36. }
  37. componentWillMount() {
  38. this.context.onSetTitle(title);
  39. }
  40. getConnectedVms(networkId) {
  41. let vms = []
  42. for (let instanceName in this.props.migration.info) {
  43. let instance = this.props.migration.info[instanceName]
  44. if (instance.export_info.devices.nics.length) {
  45. instance.export_info.devices.nics.forEach(nic => {
  46. if (nic.network_name == networkId) {
  47. vms.push(instanceName)
  48. }
  49. })
  50. }
  51. }
  52. return vms
  53. }
  54. processProps(props) {
  55. if (props.migration && props.migration.destination_environment) {
  56. for (let i in props.migration.destination_environment.network_map) {
  57. let newItem = {
  58. source_network: i,
  59. connected_vms: this.getConnectedVms(i),
  60. destination_network: props.migration.destination_environment.network_map[i],
  61. destination_type: "Existing network"
  62. }
  63. this.listItems.push(newItem)
  64. }
  65. }
  66. }
  67. render() {
  68. if (this.listItems.length) {
  69. return (
  70. <div className={s.root}>
  71. <div className={s.container}>
  72. <Table headerItems={this.headers} listItems={this.listItems} />
  73. </div>
  74. </div>
  75. );
  76. } else {
  77. return (<div className="no-results">No networks mapped</div>)
  78. }
  79. }
  80. }
  81. export default withStyles(MigrationNetworks, s);