4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import React, {Component} from 'react';
20 import ReactDOM from 'react-dom';
21 import SelectOption from 'widgets/form_controls/selectOption.jsx';
22 import imgAdd from '../../node_modules/open-iconic/svg/plus.svg'
23 import imgRemove from '../../node_modules/open-iconic/svg/trash.svg'
24 import TextInput from 'widgets/form_controls/textInput.jsx';
25 import './instantiateInputParams.scss';
27 export default class InstantiateInputParams extends Component {
31 nsConfigHTML = (props) => {
33 <div className="configure-nsd_section">
34 <div className="inputControls">
35 <TextInput label="Instance Name" type="text" pattern="^[a-zA-Z0-9_]*$" style={{textAlign:'left'}} onChange={props.updateName} value={props.name}/>
37 !isOpenMano(props.ro) ?
39 <label>Select VIM Account
40 <SelectOption options={constructCloudAccountOptions(props.cloudAccounts)} onChange={props.nsFn.updateSelectedCloudAccount} />
46 isOpenMano(props.ro) ?
47 dataCentersHTML(props.dataCenters[props.ro.name],
48 props.nsFn.updateSelectedDataCenter)
55 vnfCloudAccountsHTML = (props) => {
57 let dataCenters = props.dataCenters;
59 <div className="configure-nsd_section">
60 <h3 className="launchpadCard_title">NS/VNF ACCOUNT PLACEMENTS</h3>
64 nsd['constituent-vnfd'] && nsd['constituent-vnfd'].map(function(v, i) {
65 let defaultValue = false;
66 if(props.vnfdCloudAccounts && props.vnfdCloudAccounts.hasOwnProperty(v['member-vnf-index'])) {
67 defaultValue = props.vnfdCloudAccounts[v['member-vnf-index']]
70 <div className="inputControls" key={i}>
71 <h4 className="inputControls-title">VNFD: {v.name}</h4>
73 !isOpenMano(props.ro) ?
75 <label>Select VIM Account
76 <SelectOption options={constructCloudAccountOptions(props.cloudAccounts)} initial={true} onChange={props.vnfFn.updateSelectedCloudAccount.bind(null, v['member-vnf-index'])} defaultValue={defaultValue} />
82 isOpenMano(props.ro) ?
84 props.dataCenters[props.ro.name],
85 props.vnfFn.updateSelectedDataCenter.bind(null, v['member-vnf-index']), true)
89 (props.configAgentAccounts && props.configAgentAccounts.length > 0) ?
90 <label>Select Config Agent Account
91 <SelectOption options={props.configAgentAccounts && props.configAgentAccounts.map(function(c) {
96 })} initial={true} onChange={props.vnfFn.updateSelectedConfigAgent(v['member-vnf-index'])} defaultValue={false} />
106 inputParametersHTML = (props) => {
107 let inputParameters = props.inputParameters;
108 return inputParameters && inputParameters.map(function(input, i) {
110 <div className="configure-nsd_section" key={i}>
111 <h3 className="launchpadCard_title">Input Parameters</h3>
112 <div className="inputControls">
113 <TextInput label={ input.label || input.xpath } type="text" onChange={props.updateInputParam.bind(self, i)} />
119 nsPlacementGroupsHTML = (props) => {
120 let nsPlacementGroups = props.nsPlacementGroups;
121 let displayPlacementGroups = props.displayPlacementGroups;
122 if (nsPlacementGroups && nsPlacementGroups.length > 0 && displayPlacementGroups) {
124 <div className="configure-nsd_section">
125 <h3 className="launchpadCard_title">NS Placement Groups</h3>
127 nsPlacementGroups.map(function(input, i) {
129 <div key={i} className="configure-nsd_section-info">
130 <div className="placementGroup_description">
131 <div className="placementGroup_description-name">
132 <strong>{input.name}</strong> contains: {
133 input['member-vnfd'].map((m,i) => {
142 <div><em>{input.requirement}</em></div>
143 <div><strong>Strategy:</strong> {input.strategy}</div>
146 <span> Availability Zone <span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span> </span>
147 <div style={{display:'none'}}>
148 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, 'availability-zone')} />
149 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
153 <span> Affinity/Anti-affinity Server Group<span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span></span>
154 <div style={{display:'none'}}>
155 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, 'server-group')} />
156 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
159 <div className="host-aggregate">
161 <span> Host Aggregates <span onClick={props.nsFn.addHostAggregate.bind(self, i)} className="addInput" ><img src={imgAdd} />Add</span></span>
163 input['host-aggregate'].length > 0 ?
164 input['host-aggregate'].map((h,j) => {
165 let key = h.key || '';
166 let value = h.value || '';
169 <div className="input_group" key={j}>
170 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, j, 'key')} placeholder="KEY" value={key} />
171 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, j, 'value')} placeholder="VALUE" value={value} />
172 <span onClick={props.nsFn.removeHostAggregate.bind(self, i, j)} className="removeInput"><img src={imgRemove} />Remove</span>
187 vnfPlacementGroupsHTML = (props) => {
188 let vnfPlacementGroups = props.vnfPlacementGroups;
189 let displayPlacementGroups = props.displayPlacementGroups;
190 if (vnfPlacementGroups && vnfPlacementGroups.length > 0 && displayPlacementGroups) {
191 return vnfPlacementGroups.map(function(input, i) {
193 <div className="configure-nsd_section" key={i}>
194 <h3 className="launchpadCard_title">{input['vnf-name']} VNF Placement Group</h3>
195 <div className="configure-nsd_section-info">
196 <div className="placementGroup_description">
197 <div className="placementGroup_description-name">
198 <strong>{input.name}</strong> contains: {
199 input['member-vdus'].map((m,i) => {
200 let s = m['member-vdu-ref'];
202 s = ', ' + m['member-vdu-ref']
208 <div><em>{input.requirement}</em></div>
209 <div><strong>Strategy</strong>: {input.strategy}</div>
212 <span> Availability Zone <span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span></span>
213 <div style={{display:'none'}}>
214 <TextInput type="text" onChange={props.vnfFn.placementGroupUpdate.bind(self, i, 'availability-zone')} />
215 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
219 <span> Affinity/Anti-affinity Server Group<span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span></span>
220 <div style={{display:'none'}}>
221 <TextInput type="text" onChange={props.vnfFn.placementGroupUpdate.bind(self, i, 'server-group')} />
222 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
225 <div className="host-aggregate">
227 <span> Host Aggregates <span onClick={props.vnfFn.addHostAggregate.bind(self, i)} className="addInput"><img src={imgAdd} />Add</span></span>
229 input['host-aggregate'].length > 0 ?
230 input['host-aggregate'].map((h,j) => {
231 let key = h.key || '';
232 let value = h.value || '';
235 <div className="input_group" key={j}>
236 <TextInput type="text" onChange={props.vnfFn.hostAggregateUpdate.bind(self, i, j, 'key')} placeholder="KEY" value={key} />
237 <TextInput type="text" onChange={props.vnfFn.hostAggregateUpdate.bind(self, i, j, 'value')} placeholder="VALUE" value={value} />
238 <span onClick={props.vnfFn.removeHostAggregate.bind(self, i, j)} className="removeInput"><img src={imgRemove} />Remove</span>
252 vldsHTML = (props) => {
254 let ipProfileList = props.ipProfileList;
255 let vlds = props.vlds;
257 <div className="configure-nsd_section">
258 <h3 className="launchpadCard_title">VLDs</h3>
259 {vlds && vlds.map(function(v, i) {
260 let currentType = v.type;
261 let isVIM = (currentType == 'vim-network-name');
262 let isUnknown = (currentType == 'unknown') || ((currentType != 'vim-network-name') && (currentType != 'ip-profile-ref'));
264 <div key={self.props.nsd.id + '-' + i} className="inputControls">
265 <h4 className="inputControls-title">VLD: {v['short-name'] ? v['short-name'] : v['name']}</h4>
266 <div className="inputControls-radioGroup">
267 <label className="inputControls-radio" style={{display: ipProfileList ? 'flex' : 'none'}}>
268 <input type="radio" name={'vld-' + i } onChange={self.props.vldFn.updateType(i)} checked={!isVIM && !isUnknown} value='ip-profile-ref' />
271 <label className="inputControls-radio">
272 <input type="radio" name={'vld-' + i } onChange={self.props.vldFn.updateType(i)} checked={isVIM && !isUnknown} value='vim-network-name' />
275 <label className="inputControls-radio">
276 <input type="radio" name={'vld-' + i } onChange={self.props.vldFn.updateType(i)} checked={isUnknown} value='unknown' />
281 isUnknown ? null : isVIM ?
282 <TextInput label="Network Name" onChange={self.props.vldFn.updateValue(i, currentType)} value={v[currentType]} /> :
285 label="IP PROFILE NAME"
286 options={ipProfileList && ipProfileList.map(function(ip) {
293 v['ip-profile-ref'] ? false : true
295 defaultValue={v['ip-profile-ref']}
296 onChange={self.props.vldFn.updateValue(i, currentType)}>
307 ipProfilesHTML = (props) => {
308 let vldHasIPprofile = false;
309 props.vlds && props.vlds.map(function(v){
310 if(v.type == 'ip-profile-ref') {
311 vldHasIPprofile = true;
314 let ipProfileList = props.ipProfileList;
315 return ipProfileList && vldHasIPprofile &&
317 <div className="configure-nsd_section">
318 <h3 className="launchpadCard_title">IP Profiles</h3>
321 ipProfileList && ipProfileList.map(function(ip, j) {
322 let ipl = ip['ip-profile-params'];
324 <div className="inputControls" key={j}>
325 <div className="inputControls-title" >
328 <div className="inputControls-radioGroup">
329 <label className="inputControls-radio">
330 <input type="radio" name={'ip-profile-' + j } onChange={props.ipProfileFn.updateVersion(j)} checked={ipl['ip-version'] == 'ipv4'} value='ipv4' />
333 <label className="inputControls-radio">
334 <input type="radio" name={'ip-profile-' + j } onChange={props.ipProfileFn.updateVersion(j)} checked={ipl['ip-version'] == 'ipv6'} value='ipv6' />
337 <label className="inputControls-radio">
338 <input type="radio" name={'ip-profile-' + j } onChange={props.ipProfileFn.updateVersion(j)} checked={ipl['ip-version'] == 'unknown'} value='unknown' />
343 label="subnet address"
344 onChange={props.ipProfileFn.updateProfile(j, 'subnet-address')}
345 value={ipl['subnet-address']}
348 label="gateway address"
349 onChange={props.ipProfileFn.updateProfile(j, 'gateway-address')}
350 value={ipl['gateway-address']}
353 label="security group"
354 onChange={props.ipProfileFn.updateProfile(j, 'security-group')}
355 value={ipl['security-group']}
358 label="subnet prefix pool"
359 onChange={props.ipProfileFn.updateProfile(j, 'subnet-prefix-pool')}
360 value={ipl['subnet-prefix-pool']}
363 <div style={{display:'flex'}}>
364 DNS SERVERS <span onClick={props.dnsFn.addDNS(j)} className="addInput"><img src={imgAdd} />Add</span>
367 ipl['dns-server'] && ipl['dns-server'].map(function(dns, k) {
369 <div key={k} style={{display:'flex'}}>
371 onChange={props.ipProfileFn.updateProfile(j,k)}
372 value={ipl['dns-server'][k]}
374 <span onClick={props.dnsFn.removeDNS(j,k)} className="removeInput">
375 <img src={imgRemove} />Remove</span>
381 <div className="inputControls-radioGroup">
382 <label className="inputControls-radio">
385 name={'ip-profile-dhcp' + j }
386 onChange={props.ipProfileFn.updateDHCP(j, 'enabled')}
387 checked={ipl.hasOwnProperty('dhcp-params') && ipl['dhcp-params'].enabled}
391 <label className="inputControls-radio">
393 name={'ip-profile-dhcp' + j }
394 onChange={props.ipProfileFn.updateDHCP(j, 'enabled')}
395 checked={!ipl.hasOwnProperty('dhcp-params') || !ipl['dhcp-params'].enabled}
401 (ipl['dhcp-params'] && ipl['dhcp-params'].enabled) ? dhcpHTML(props, ipl, j) : null
408 function dhcpHTML(props, ipl, j){
411 label="DHCP Start Address"
412 onChange={props.ipProfileFn.updateDHCP(j, 'start-address')}
413 value={ipl['dhcp-params'] && ipl['dhcp-params']['start-address']}
417 onChange={props.ipProfileFn.updateDHCP(j, 'count')}
418 value={ipl['dhcp-params'] && ipl['dhcp-params']['count']}
424 sshKeysHTML = (props) => {
425 let sshKeysList = props.sshKeysList;
426 let sshKeysRef = props.sshKeysRef;
427 if(sshKeysList && sshKeysList.length > 0) {
429 <div className="configure-nsd_section">
430 <h3 className="launchpadCard_title">SSH Authorized Keys</h3>
433 sshKeysRef.map(function(ref, i) {
434 let keyref = JSON.stringify(ref)
436 <div key={keyref.name + '-' + i} className="inputControls inputControls-sshkeys">
441 options={sshKeysList && sshKeysList.map(function(k) {
447 ref="keyPairSelection"
449 defaultValue={keyref.name || sshKeysList[0].name}
450 onChange={props.sshFn.updateKeyRef(i)}>
455 <span onClick={props.sshFn.updateKeyRef(i, true)} className="removeInput">
456 <img src={imgRemove} />
464 <div className="inputControls inputControls-sshkeys ">
465 <label style={{display: 'flex', 'flexDirection': 'row'}}>
467 <span onClick={props.sshFn.updateKeyRef().bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
477 usersHTML = (props) => {
478 let usersFn = props.usersFn;
479 let sshKeysList = props.sshKeysList;
480 let usersList = props.usersList && props.usersList.map(function(u, i) {
481 let sshKeysRef = u['ssh-authorized-key'];
483 <div className="input_group input_group-users" key={i}>
484 <div className="inputControls">
485 <div style={{fontWeight: 'bold', display: 'flex'}}>USER <span onClick={usersFn.remove(i)} className="removeInput"><img src={imgRemove} />Remove</span></div>
486 <TextInput onChange={usersFn.update(i, 'name')} label="USERNAME" value={i.name} />
487 <TextInput onChange={usersFn.update(i, 'user-info')} label="REAL NAME" value={i.gecos} />
489 sshKeysRef.map(function(ref, j) {
490 let keyref = JSON.stringify(ref)
492 <div key={keyref.name + '-' + i + '-' + j} className="inputControls inputControls-sshkeys">
497 options={sshKeysList && sshKeysList.map(function(k) {
503 ref="keyPairSelection"
506 onChange={usersFn.updateSSHkeyRef(i, j)}>
511 sshKeysRef.length > 0 ?
513 <span onClick={usersFn.updateSSHkeyRef(i, j, true)} className="removeInput">
514 <img src={imgRemove} />
525 <div className="inputControls inputControls-sshkeys ">
526 <label style={{display: 'flex', 'flexDirection': 'row', 'alignItems': 'center'}}>
528 <span onClick={usersFn.updateSSHkeyRef(i).bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
539 <div className="configure-nsd_section">
540 <h3 className="launchpadCard_title">USERS</h3>
542 <div className="inputControls inputControls-sshkeys inputControls-addUser ">
543 <span onClick={usersFn.add(sshKeysList)} className="addInput">
553 const props = this.props;
558 <div className="instantiateInputParams">
561 this.nsConfigHTML(props)
565 this.vnfCloudAccountsHTML(props)
569 this.inputParametersHTML(props)
573 this.nsPlacementGroupsHTML(props)
576 //VNF PLACEMENTGROUPS
577 this.vnfPlacementGroupsHTML(props)
584 //IP PROFILE CONFIGURATION
585 this.ipProfilesHTML(props)
588 //SSH KEY ASSIGNMENTS
589 this.sshKeysHTML(props)
593 this.usersHTML(props)
600 function showInput(e){
601 let target = e.target;
602 if(target.parentElement.classList.contains("addInput")) {
603 target = target.parentElement;
605 target.style.display = 'none';
606 target.parentElement.nextElementSibling.style.display = 'flex';
607 // e.target.parentElement.nextElementSibling.children[1].style.display = 'initial';
609 function hideInput(e){
610 let target = e.target;
611 if(target.parentElement.classList.contains("removeInput")) {
612 target = target.parentElement;
614 target.parentElement.style.display = 'none';
615 target.parentElement.previousElementSibling.children[1].style.display = 'inline';
616 target.previousSibling.value = '';
619 function removeDNS(){}
620 function constructCloudAccountOptions(cloudAccounts){
621 let CloudAccountOptions = cloudAccounts && cloudAccounts.map(function(ca, index) {
627 return CloudAccountOptions;
629 function dataCentersHTML(dataCenters, onChange, initial) {
630 //Build DataCenter options
631 //Relook at this, why is it an object?
632 let DataCenterOptions = [];
633 DataCenterOptions = dataCenters && dataCenters.map(function(dc, index) {
639 if (dataCenters && dataCenters.length > 0) {
641 <label>Select Data Center
642 <SelectOption initial={!!initial} options={DataCenterOptions} onChange={onChange} />
647 function isOpenMano(account) {
650 if (a.constructor.name == 'String') {
653 return a['account-type'] == 'openmano';
658 function updateNewSshKeyRefSelection(e) {
660 newRefSelection: e.target.value
663 function resetRef() {
665 newRefSelection: null
668 InstantiateInputParams.defaultProps = {