/* * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import React from 'react'; export default class PlacementGroupsInfo extends React.Component { constructor(props) { super(props); this.state = {}; this.state.dict = {}; this.state.displayedGroup = null; } componentWillReceiveProps(props) { this.setState({ nsr: props.nsr, dict: buildPlacementGroupDictFromVDUR(props.nsr), // dict: buildPlacementGroupDict(props.nsr), }); } showDisplayGroup = (context, ref, type) => { // ref = 'Orcus'; context.setState({ displayedGroup: this.state.dict[ref] }) } render(){ let html; let vdurs = ; let details = ; return
{vdurs}{details}
; } } PlacementGroupsInfo.defaultProps = { nsr: {} } class VduPlacement extends React.Component { render() { let html; let {showDisplayGroup, nsr, ...props} = this.props; html = (

VDU Placement

Record

Placement Group

NSR: {nsr.name}
{ flattenPlacementGroupsToHTML(nsr, showDisplayGroup) }
); return html; } } function flattenPlacementGroupsToHTML(nsr, onClick) { let data = []; nsr.vnfrs && nsr.vnfrs.map(function(v, i) { let html; html = (
VNFR: {v['short-name']}
) data.push(html); v && v.vdur && v.vdur.map(function(vd, j) { let html; html = (
VDUR: {vd['name']}
    { vd['placement-groups-info'].map(function(p, k) { return
  • {p.name}
  • }) }
); data.push(html); }); }); return data; } class PlacementGroupDetails extends React.Component { render() { let html; let {displayedGroup, ...props} = this.props; let dg = displayedGroup; let dgHTML = ''; if(dg) { dgHTML = (
Name
{dg.name}
Requirement
{dg.requirement}
Strategy
{dg.strategy}
Cloud Provider
{dg['cloud-type']}
{ (dg['availability-zone'] != undefined) ?
Availability Zone
: '' } { (dg['availability-zone'] != undefined) ?
{dg['availability-zone']}
: '' } { (dg['server-group'] != undefined) ?
Affinity/Anti-Affinity Server Group
: '' } { (dg['server-group'] != undefined) ?
{dg['server-group']}
: '' } { (dg['host-aggregate'] != undefined) ?
Host Aggregates
: '' } { dg['host-aggregate'] != undefined ?
{dg['host-aggregate'].map(function(ha, h) { return
{ha['metadata-key']}:{ha['metadata-value']}
})}
: '' }
) } html = (

Placement Group Details

{dgHTML}
); return html; } } PlacementGroupDetails.defaultProps = { displayedGroup: {} } function buildPlacementGroupDictFromVDUR(data) { let d = {}; data.vnfrs.map(function(vnf) { vnf.vdur && vnf.vdur.map(function(v) { v['placement-groups-info'].map(function(p) { d[p.name] = p; }) }) }) return d; } function buildPlacementGroupDict(data) { let d = {}; let nsd = data['nsd-placement-group-maps']; let vnfd = data['vnfd-placement-group-maps']; nsd.map(function(m, i) { d[m['placement-group-ref']] = m; }); vnfd.map(function(m, i) { d[m['placement-group-ref']] = m; }); return d; }