/*
*
* 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, {Component} from 'react';
import ReactDOM from 'react-dom';
import SelectOption from 'widgets/form_controls/selectOption.jsx';
import imgAdd from '../../node_modules/open-iconic/svg/plus.svg'
import imgRemove from '../../node_modules/open-iconic/svg/trash.svg'
import TextInput from 'widgets/form_controls/textInput.jsx';
import './instantiateInputParams.scss';
export default class InstantiateInputParams extends Component {
constructor(props) {
super(props);
}
nsConfigHTML = (props) => {
return (
{
!isOpenMano(props.ro) ?
(
Select VIM Account
)
: null
}
{
isOpenMano(props.ro) ?
dataCentersHTML(props.dataCenters[props.ro.name],
props.nsFn.updateSelectedDataCenter)
: null
}
)
}
vnfCloudAccountsHTML = (props) => {
let nsd = props.nsd;
let dataCenters = props.dataCenters;
return (
NS/VNF ACCOUNT PLACEMENTS
{
//selectedNSDid
nsd['constituent-vnfd'] && nsd['constituent-vnfd'].map(function(v, i) {
let defaultValue = false;
if(props.vnfdCloudAccounts && props.vnfdCloudAccounts.hasOwnProperty(v['member-vnf-index'])) {
defaultValue = props.vnfdCloudAccounts[v['member-vnf-index']]
}
return (
VNFD: {v.name}
{
!isOpenMano(props.ro) ?
(
Select VIM Account
)
: null
}
{
isOpenMano(props.ro) ?
dataCentersHTML(
props.dataCenters[props.ro.name],
props.vnfFn.updateSelectedDataCenter.bind(null, v['member-vnf-index']), true)
: null
}
{
(props.configAgentAccounts && props.configAgentAccounts.length > 0) ?
Select Config Agent Account
: null
}
)
})
}
)
}
inputParametersHTML = (props) => {
let inputParameters = props.inputParameters;
const handleChange = (i, event) => props.updateInputParam(i, event.target.value);
return inputParameters && inputParameters.map(function(input, i) {
return (
)
})
}
nsPlacementGroupsHTML = (props) => {
let nsPlacementGroups = props.nsPlacementGroups;
let displayPlacementGroups = props.displayPlacementGroups;
if (nsPlacementGroups && nsPlacementGroups.length > 0 && displayPlacementGroups) {
return (
NS Placement Groups
{
nsPlacementGroups.map(function(input, i) {
return (
);
})
}
);
}
}
vnfPlacementGroupsHTML = (props) => {
let vnfPlacementGroups = props.vnfPlacementGroups;
let displayPlacementGroups = props.displayPlacementGroups;
if (vnfPlacementGroups && vnfPlacementGroups.length > 0 && displayPlacementGroups) {
return vnfPlacementGroups.map(function(input, i) {
return (
{input['vnf-name']} VNF Placement Group
);
});
}
}
vldsHTML = (props) => {
let self = this;
let ipProfileList = props.ipProfileList;
let vlds = props.vlds;
return vlds && (
VLDs
{vlds && vlds.map(function(v, i) {
let currentType = v.type;
let isVIM = (currentType == 'vim-network-name');
let isUnknown = (currentType == 'none') || ((currentType != 'vim-network-name') && (currentType != 'ip-profile-ref'));
return (
)
})}
);
}
ipProfilesHTML = (props) => {
let vldHasIPprofile = false;
props.vlds && props.vlds.map(function(v){
if(v.type == 'ip-profile-ref') {
vldHasIPprofile = true;
}
})
let ipProfileList = props.ipProfileList;
return ipProfileList && vldHasIPprofile &&
(
IP Profiles
{
//IP Config
ipProfileList && ipProfileList.map(function(ip, j) {
let ipl = ip['ip-profile-params'];
return (
)
})
}
);
function dhcpHTML(props, ipl, j){
return (
);
}
}
sshKeysHTML = (props) => {
let sshKeysList = props.sshKeysList;
let sshKeysRef = props.sshKeysRef;
if(sshKeysList && sshKeysList.length > 0) {
return (
SSH Authorized Keys
{
sshKeysRef.map(function(ref, i) {
let keyref = JSON.stringify(ref)
return (
Remove
)
})
}
SSH KEY PAIR
ADD
);
}
}
usersHTML = (props) => {
let usersFn = props.usersFn;
let sshKeysList = props.sshKeysList;
let usersList = props.usersList && props.usersList.map(function(u, i) {
let sshKeysRef = u['ssh-authorized-key'];
return (
USER
Remove
{
sshKeysRef.map(function(ref, j) {
let keyref = JSON.stringify(ref)
return (
{
sshKeysRef.length > 0 ?
Remove
: null
}
)
})
}
SSH KEY PAIR
ADD
)
});
return (
USERS
{usersList}
ADD USER
)
}
render() {
const props = this.props;
let html;
let self = this;
html = (
{
//NS NAMEA AND CLOUD
this.nsConfigHTML(props)
}
{
//VNF VIM ACCOUNTS
this.vnfCloudAccountsHTML(props)
}
{
//INPUT PARAMETERS
this.inputParametersHTML(props)
}
{
//NS PLACEMENTGROUPS
this.nsPlacementGroupsHTML(props)
}
{
//VNF PLACEMENTGROUPS
this.vnfPlacementGroupsHTML(props)
}
{
//VLD CONFIGURATION
this.vldsHTML(props)
}
{
//IP PROFILE CONFIGURATION
this.ipProfilesHTML(props)
}
{
//SSH KEY ASSIGNMENTS
this.sshKeysHTML(props)
}
{
//USER MANAGEMENT
this.usersHTML(props)
}
)
return html;
}
}
function showInput(e){
let target = e.target;
if(target.parentElement.classList.contains("addInput")) {
target = target.parentElement;
}
target.style.display = 'none';
target.parentElement.nextElementSibling.style.display = 'flex';
// e.target.parentElement.nextElementSibling.children[1].style.display = 'initial';
}
function hideInput(e){
let target = e.target;
if(target.parentElement.classList.contains("removeInput")) {
target = target.parentElement;
}
target.parentElement.style.display = 'none';
target.parentElement.previousElementSibling.children[1].style.display = 'inline';
target.previousSibling.value = '';
}
function addDNS(){}
function removeDNS(){}
function constructCloudAccountOptions(cloudAccounts){
let CloudAccountOptions = cloudAccounts && cloudAccounts.map(function(ca, index) {
return {
label: ca.name,
value: ca
}
});
return CloudAccountOptions;
}
function dataCentersHTML(dataCenters, onChange, initial) {
//Build DataCenter options
//Relook at this, why is it an object?
let DataCenterOptions = [];
DataCenterOptions = dataCenters && dataCenters.map(function(dc, index) {
return {
label: dc.name,
value: dc.uuid
}
});
if (dataCenters && dataCenters.length > 0) {
return (
Select Data Center
)
}
}
function isOpenMano(account) {
if (account) {
let a = account;
if (a.constructor.name == 'String') {
a = JSON.parse(a);
}
return a['account-type'] == 'openmano';
} else {
return false;
}
}
function updateNewSshKeyRefSelection(e) {
this.setState({
newRefSelection: e.target.value
})
}
function resetRef() {
this.setState({
newRefSelection: null
})
}
InstantiateInputParams.defaultProps = {
data: [],
sshKeysList: [],
sshKeysRef: [],
users: {}
}