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 const handleChange = (i, event) => props.updateInputParam(i, event.target.value);
109 return inputParameters && inputParameters.map(function(input, i) {
111 <div className="configure-nsd_section" key={i}>
112 <h3 className="launchpadCard_title">Input Parameters</h3>
113 <div className="inputControls">
114 <TextInput label={ input.label || input.xpath } type="text" onChange={handleChange.bind(this, i)} />
120 nsPlacementGroupsHTML = (props) => {
121 let nsPlacementGroups = props.nsPlacementGroups;
122 let displayPlacementGroups = props.displayPlacementGroups;
123 if (nsPlacementGroups && nsPlacementGroups.length > 0 && displayPlacementGroups) {
125 <div className="configure-nsd_section">
126 <h3 className="launchpadCard_title">NS Placement Groups</h3>
128 nsPlacementGroups.map(function(input, i) {
130 <div key={i} className="configure-nsd_section-info">
131 <div className="placementGroup_description">
132 <div className="placementGroup_description-name">
133 <strong>{input.name}</strong> contains: {
134 input['member-vnfd'].map((m,i) => {
143 <div><em>{input.requirement}</em></div>
144 <div><strong>Strategy:</strong> {input.strategy}</div>
147 <span> Availability Zone <span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span> </span>
148 <div style={{display:'none'}}>
149 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, 'availability-zone')} />
150 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
154 <span> Affinity/Anti-affinity Server Group<span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span></span>
155 <div style={{display:'none'}}>
156 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, 'server-group')} />
157 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
160 <div className="host-aggregate">
162 <span> Host Aggregates <span onClick={props.nsFn.addHostAggregate.bind(self, i)} className="addInput" ><img src={imgAdd} />Add</span></span>
164 input['host-aggregate'].length > 0 ?
165 input['host-aggregate'].map((h,j) => {
166 let key = h.key || '';
167 let value = h.value || '';
170 <div className="input_group" key={j}>
171 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, j, 'key')} placeholder="KEY" value={key} />
172 <TextInput type="text" onChange={props.nsFn.placementGroupUpdate.bind(self, i, j, 'value')} placeholder="VALUE" value={value} />
173 <span onClick={props.nsFn.removeHostAggregate.bind(self, i, j)} className="removeInput"><img src={imgRemove} />Remove</span>
188 vnfPlacementGroupsHTML = (props) => {
189 let vnfPlacementGroups = props.vnfPlacementGroups;
190 let displayPlacementGroups = props.displayPlacementGroups;
191 if (vnfPlacementGroups && vnfPlacementGroups.length > 0 && displayPlacementGroups) {
192 return vnfPlacementGroups.map(function(input, i) {
194 <div className="configure-nsd_section" key={i}>
195 <h3 className="launchpadCard_title">{input['vnf-name']} VNF Placement Group</h3>
196 <div className="configure-nsd_section-info">
197 <div className="placementGroup_description">
198 <div className="placementGroup_description-name">
199 <strong>{input.name}</strong> contains: {
200 input['member-vdus'].map((m,i) => {
201 let s = m['member-vdu-ref'];
203 s = ', ' + m['member-vdu-ref']
209 <div><em>{input.requirement}</em></div>
210 <div><strong>Strategy</strong>: {input.strategy}</div>
213 <span> Availability Zone <span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span></span>
214 <div style={{display:'none'}}>
215 <TextInput type="text" onChange={props.vnfFn.placementGroupUpdate.bind(self, i, 'availability-zone')} />
216 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
220 <span> Affinity/Anti-affinity Server Group<span onClick={showInput} className="addInput"><img src={imgAdd} />Add</span></span>
221 <div style={{display:'none'}}>
222 <TextInput type="text" onChange={props.vnfFn.placementGroupUpdate.bind(self, i, 'server-group')} />
223 <span onClick={hideInput} className="removeInput"><img src={imgRemove} />Remove</span>
226 <div className="host-aggregate">
228 <span> Host Aggregates <span onClick={props.vnfFn.addHostAggregate.bind(self, i)} className="addInput"><img src={imgAdd} />Add</span></span>
230 input['host-aggregate'].length > 0 ?
231 input['host-aggregate'].map((h,j) => {
232 let key = h.key || '';
233 let value = h.value || '';
236 <div className="input_group" key={j}>
237 <TextInput type="text" onChange={props.vnfFn.hostAggregateUpdate.bind(self, i, j, 'key')} placeholder="KEY" value={key} />
238 <TextInput type="text" onChange={props.vnfFn.hostAggregateUpdate.bind(self, i, j, 'value')} placeholder="VALUE" value={value} />
239 <span onClick={props.vnfFn.removeHostAggregate.bind(self, i, j)} className="removeInput"><img src={imgRemove} />Remove</span>
253 vldsHTML = (props) => {
255 let ipProfileList = props.ipProfileList;
256 let vlds = props.vlds;
258 <div className="configure-nsd_section">
259 <h3 className="launchpadCard_title">VLDs</h3>
260 {vlds && vlds.map(function(v, i) {
261 let currentType = v.type;
262 let isVIM = (currentType == 'vim-network-name');
263 let isUnknown = (currentType == 'none') || ((currentType != 'vim-network-name') && (currentType != 'ip-profile-ref'));
265 <div key={self.props.nsd.id + '-' + i} className="inputControls">
266 <h4 className="inputControls-title">VLD: {v['short-name'] ? v['short-name'] : v['name']}</h4>
267 <label><span>Specify VLD Parameters</span></label>
268 <div className="inputControls-radioGroup">
269 <label className="inputControls-radio" style={{display: ipProfileList ? 'flex' : 'none'}}>
270 <input type="radio" name={'vld-' + i } onChange={self.props.vldFn.updateType(i)} checked={!isVIM && !isUnknown} value='ip-profile-ref' />
273 <label className="inputControls-radio">
274 <input type="radio" name={'vld-' + i } onChange={self.props.vldFn.updateType(i)} checked={isVIM && !isUnknown} value='vim-network-name' />
277 <label className="inputControls-radio">
278 <input type="radio" name={'vld-' + i } onChange={self.props.vldFn.updateType(i)} checked={isUnknown} value='none' />
283 isUnknown ? null : isVIM ?
284 <TextInput label="Network Name" onChange={self.props.vldFn.updateValue(i, currentType)} value={v[currentType]} /> :
287 label="IP PROFILE NAME"
288 options={ipProfileList && ipProfileList.map(function(ip) {
295 v['ip-profile-ref'] ? false : true
297 defaultValue={v['ip-profile-ref']}
298 onChange={self.props.vldFn.updateValue(i, currentType)}>
309 ipProfilesHTML = (props) => {
310 let vldHasIPprofile = false;
311 props.vlds && props.vlds.map(function(v){
312 if(v.type == 'ip-profile-ref') {
313 vldHasIPprofile = true;
316 let ipProfileList = props.ipProfileList;
317 return ipProfileList && vldHasIPprofile &&
319 <div className="configure-nsd_section">
320 <h3 className="launchpadCard_title">IP Profiles</h3>
323 ipProfileList && ipProfileList.map(function(ip, j) {
324 let ipl = ip['ip-profile-params'];
326 <div className="inputControls" key={j}>
327 <div className="inputControls-title" >
330 <div className="inputControls-radioGroup">
331 <label className="inputControls-radio">
332 <input type="radio" name={'ip-profile-' + j } onChange={props.ipProfileFn.updateVersion(j)} checked={ipl['ip-version'] == 'ipv4'} value='ipv4' />
335 <label className="inputControls-radio">
336 <input type="radio" name={'ip-profile-' + j } onChange={props.ipProfileFn.updateVersion(j)} checked={ipl['ip-version'] == 'ipv6'} value='ipv6' />
339 <label className="inputControls-radio">
340 <input type="radio" name={'ip-profile-' + j } onChange={props.ipProfileFn.updateVersion(j)} checked={ipl['ip-version'] == 'unknown'} value='unknown' />
345 label="subnet address"
346 onChange={props.ipProfileFn.updateProfile(j, 'subnet-address')}
347 value={ipl['subnet-address']}
350 label="gateway address"
351 onChange={props.ipProfileFn.updateProfile(j, 'gateway-address')}
352 value={ipl['gateway-address']}
355 label="security group"
356 onChange={props.ipProfileFn.updateProfile(j, 'security-group')}
357 value={ipl['security-group']}
360 label="subnet prefix pool"
361 onChange={props.ipProfileFn.updateProfile(j, 'subnet-prefix-pool')}
362 value={ipl['subnet-prefix-pool']}
365 <div style={{display:'flex'}}>
366 DNS SERVERS <span onClick={props.dnsFn.addDNS(j)} className="addInput"><img src={imgAdd} />Add</span>
369 ipl['dns-server'] && ipl['dns-server'].map(function(dns, k) {
371 <div key={k} style={{display:'flex'}}>
373 onChange={props.dnsFn.updateDNS(j,k)}
374 value={ipl['dns-server'][k].address}
376 <span onClick={props.dnsFn.removeDNS(j,k)} className="removeInput">
377 <img src={imgRemove} />Remove</span>
383 <div className="inputControls-radioGroup">
384 <label className="inputControls-radio">
387 name={'ip-profile-dhcp' + j }
388 onChange={props.ipProfileFn.updateDHCP(j, 'enabled')}
389 checked={ipl.hasOwnProperty('dhcp-params') && ipl['dhcp-params'].enabled}
393 <label className="inputControls-radio">
395 name={'ip-profile-dhcp' + j }
396 onChange={props.ipProfileFn.updateDHCP(j, 'enabled')}
397 checked={!ipl.hasOwnProperty('dhcp-params') || !ipl['dhcp-params'].enabled}
403 (ipl['dhcp-params'] && ipl['dhcp-params'].enabled) ? dhcpHTML(props, ipl, j) : null
410 function dhcpHTML(props, ipl, j){
413 label="DHCP Start Address"
414 onChange={props.ipProfileFn.updateDHCP(j, 'start-address')}
415 value={ipl['dhcp-params'] && ipl['dhcp-params']['start-address']}
419 onChange={props.ipProfileFn.updateDHCP(j, 'count')}
420 value={ipl['dhcp-params'] && ipl['dhcp-params']['count']}
426 sshKeysHTML = (props) => {
427 let sshKeysList = props.sshKeysList;
428 let sshKeysRef = props.sshKeysRef;
429 if(sshKeysList && sshKeysList.length > 0) {
431 <div className="configure-nsd_section">
432 <h3 className="launchpadCard_title">SSH Authorized Keys</h3>
435 sshKeysRef.map(function(ref, i) {
436 let keyref = JSON.stringify(ref)
438 <div key={keyref.name + '-' + i} className="inputControls inputControls-sshkeys">
443 options={sshKeysList && sshKeysList.map(function(k) {
449 ref="keyPairSelection"
451 defaultValue={keyref.name || sshKeysList[0].name}
452 onChange={props.sshFn.updateKeyRef(i)}>
457 <span onClick={props.sshFn.updateKeyRef(i, true)} className="removeInput">
458 <img src={imgRemove} />
466 <div className="inputControls inputControls-sshkeys ">
467 <label style={{display: 'flex', 'flexDirection': 'row'}}>
469 <span onClick={props.sshFn.updateKeyRef().bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
479 usersHTML = (props) => {
480 let usersFn = props.usersFn;
481 let sshKeysList = props.sshKeysList;
482 let usersList = props.usersList && props.usersList.map(function(u, i) {
483 let sshKeysRef = u['ssh-authorized-key'];
485 <div className="input_group input_group-users" key={i}>
486 <div className="inputControls">
487 <div style={{fontWeight: 'bold', display: 'flex'}}>USER <span onClick={usersFn.remove(i)} className="removeInput"><img src={imgRemove} />Remove</span></div>
488 <TextInput onChange={usersFn.update(i, 'name')} label="USERNAME" value={i.name} />
489 <TextInput onChange={usersFn.update(i, 'user-info')} label="REAL NAME" value={i.gecos} />
491 sshKeysRef.map(function(ref, j) {
492 let keyref = JSON.stringify(ref)
494 <div key={keyref.name + '-' + i + '-' + j} className="inputControls inputControls-sshkeys">
499 options={sshKeysList && sshKeysList.map(function(k) {
505 ref="keyPairSelection"
508 onChange={usersFn.updateSSHkeyRef(i, j)}>
513 sshKeysRef.length > 0 ?
515 <span onClick={usersFn.updateSSHkeyRef(i, j, true)} className="removeInput">
516 <img src={imgRemove} />
527 <div className="inputControls inputControls-sshkeys ">
528 <label style={{display: 'flex', 'flexDirection': 'row', 'alignItems': 'center'}}>
530 <span onClick={usersFn.updateSSHkeyRef(i).bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
541 <div className="configure-nsd_section">
542 <h3 className="launchpadCard_title">USERS</h3>
544 <div className="inputControls inputControls-sshkeys inputControls-addUser ">
545 <span onClick={usersFn.add(sshKeysList)} className="addInput">
555 const props = this.props;
560 <div className="instantiateInputParams">
563 this.nsConfigHTML(props)
567 this.vnfCloudAccountsHTML(props)
571 this.inputParametersHTML(props)
575 this.nsPlacementGroupsHTML(props)
578 //VNF PLACEMENTGROUPS
579 this.vnfPlacementGroupsHTML(props)
586 //IP PROFILE CONFIGURATION
587 this.ipProfilesHTML(props)
590 //SSH KEY ASSIGNMENTS
591 this.sshKeysHTML(props)
595 this.usersHTML(props)
602 function showInput(e){
603 let target = e.target;
604 if(target.parentElement.classList.contains("addInput")) {
605 target = target.parentElement;
607 target.style.display = 'none';
608 target.parentElement.nextElementSibling.style.display = 'flex';
609 // e.target.parentElement.nextElementSibling.children[1].style.display = 'initial';
611 function hideInput(e){
612 let target = e.target;
613 if(target.parentElement.classList.contains("removeInput")) {
614 target = target.parentElement;
616 target.parentElement.style.display = 'none';
617 target.parentElement.previousElementSibling.children[1].style.display = 'inline';
618 target.previousSibling.value = '';
621 function removeDNS(){}
622 function constructCloudAccountOptions(cloudAccounts){
623 let CloudAccountOptions = cloudAccounts && cloudAccounts.map(function(ca, index) {
629 return CloudAccountOptions;
631 function dataCentersHTML(dataCenters, onChange, initial) {
632 //Build DataCenter options
633 //Relook at this, why is it an object?
634 let DataCenterOptions = [];
635 DataCenterOptions = dataCenters && dataCenters.map(function(dc, index) {
641 if (dataCenters && dataCenters.length > 0) {
643 <label>Select Data Center
644 <SelectOption initial={!!initial} options={DataCenterOptions} onChange={onChange} />
649 function isOpenMano(account) {
652 if (a.constructor.name == 'String') {
655 return a['account-type'] == 'openmano';
660 function updateNewSshKeyRefSelection(e) {
662 newRefSelection: e.target.value
665 function resetRef() {
667 newRefSelection: null
670 InstantiateInputParams.defaultProps = {