RIFT-14837: DNS Servers can now update
[osm/UI.git] / skyquake / plugins / launchpad / src / instantiate / instantiateInputParams.jsx
index 17d5f8d..164403c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,11 +33,20 @@ export default class InstantiateInputParams extends Component {
       <div className="configure-nsd_section">
         <div className="inputControls">
             <TextInput label="Instance Name" type="text" pattern="^[a-zA-Z0-9_]*$" style={{textAlign:'left'}} onChange={props.updateName} value={props.name}/>
-          <label>Select VIM Account
-            <SelectOption options={constructCloudAccountOptions(props.cloudAccounts)} onChange={props.nsFn.updateSelectedCloudAccount} />
-          </label>
           {
-            isOpenMano(props.selectedCloudAccount) ? this.dataCentersHTML(props.dataCenters[selectedCloudAccount.name], props.nsFn.updateSelectedDataCenter) : null
+            !isOpenMano(props.ro) ?
+              (
+                <label>Select VIM Account
+                  <SelectOption options={constructCloudAccountOptions(props.cloudAccounts)} onChange={props.nsFn.updateSelectedCloudAccount} />
+                </label>
+              )
+            : null
+          }
+          {
+            isOpenMano(props.ro) ?
+              dataCentersHTML(props.dataCenters[props.ro.name],
+                              props.nsFn.updateSelectedDataCenter)
+              : null
           }
         </div>
       </div>
@@ -60,11 +69,21 @@ export default class InstantiateInputParams extends Component {
                 return (
                     <div className="inputControls" key={i}>
                     <h4 className="inputControls-title">VNFD: {v.name}</h4>
-                      <label>Select VIM Account
-                        <SelectOption options={constructCloudAccountOptions(props.cloudAccounts)} initial={true} onChange={props.vnfFn.updateSelectedCloudAccount.bind(v['member-vnf-index'])} defaultValue={defaultValue} />
-                      </label>
+                  {
+                    !isOpenMano(props.ro) ?
+                      (
+                        <label>Select VIM Account
+                          <SelectOption options={constructCloudAccountOptions(props.cloudAccounts)} initial={true} onChange={props.vnfFn.updateSelectedCloudAccount.bind(null, v['member-vnf-index'])} defaultValue={defaultValue} />
+                        </label>
+                      )
+                    : null
+                  }
                       {
-                        isOpenMano(defaultValue) ? dataCentersHTML(dataCenters[defaultValue.account.name], props.vnfFn.updateSelectedDataCenter(v['member-vnf-index'])) : 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) ?
@@ -286,8 +305,14 @@ export default class InstantiateInputParams extends Component {
     );
   }
   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 &&
+    return ipProfileList && vldHasIPprofile &&
       (
       <div className="configure-nsd_section">
         <h3 className="launchpadCard_title">IP Profiles</h3>
@@ -329,6 +354,11 @@ export default class InstantiateInputParams extends Component {
                     onChange={props.ipProfileFn.updateProfile(j, 'security-group')}
                     value={ipl['security-group']}
                     />
+                  <TextInput
+                    label="subnet prefix pool"
+                    onChange={props.ipProfileFn.updateProfile(j, 'subnet-prefix-pool')}
+                    value={ipl['subnet-prefix-pool']}
+                    />
                     <label>
                       <div style={{display:'flex'}}>
                         DNS SERVERS <span onClick={props.dnsFn.addDNS(j)} className="addInput"><img src={imgAdd} />Add</span>
@@ -338,8 +368,8 @@ export default class InstantiateInputParams extends Component {
                           return (
                             <div key={k} style={{display:'flex'}}>
                               <TextInput
-                                  onChange={props.ipProfileFn.updateProfile(j,k)}
-                                  value={ipl['dns-server'][k]}
+                                  onChange={props.dnsFn.updateDNS(j,k)}
+                                  value={ipl['dns-server'][k].address}
                                   />
                               <span onClick={props.dnsFn.removeDNS(j,k)} className="removeInput">
                                 <img src={imgRemove} />Remove</span>
@@ -378,12 +408,12 @@ export default class InstantiateInputParams extends Component {
     function dhcpHTML(props, ipl, j){
       return (<div>
                   <TextInput
-                    label="DCHP Start Address"
+                    label="DHCP Start Address"
                     onChange={props.ipProfileFn.updateDHCP(j, 'start-address')}
                     value={ipl['dhcp-params'] && ipl['dhcp-params']['start-address']}
                     />
                   <TextInput
-                    label="DCHP Count"
+                    label="DHCP Count"
                     onChange={props.ipProfileFn.updateDHCP(j, 'count')}
                     value={ipl['dhcp-params'] && ipl['dhcp-params']['count']}
                     />
@@ -401,8 +431,9 @@ export default class InstantiateInputParams extends Component {
 
             {
               sshKeysRef.map(function(ref, i) {
+                let keyref = JSON.stringify(ref)
                 return (
-                  <div key={i} className="inputControls inputControls-sshkeys">
+                  <div key={keyref.name + '-' + i} className="inputControls inputControls-sshkeys">
                     <label>
                       <div>
                       <SelectOption
@@ -415,13 +446,13 @@ export default class InstantiateInputParams extends Component {
                         })}
                         ref="keyPairSelection"
                         initial={false}
-                        defaultValue={sshKeysList[0].name}
-                        onChange={self.props.updateSshKeyRef(i)}>
+                        defaultValue={keyref.name || sshKeysList[0].name}
+                        onChange={props.sshFn.updateKeyRef(i)}>
                       </SelectOption>
                       </div>
                     </label>
                     <label>
-                      <span onClick={self.props.updateSshKeyRef(i, true)} className="removeInput">
+                      <span onClick={props.sshFn.updateKeyRef(i, true)} className="removeInput">
                         <img src={imgRemove} />
                         Remove
                       </span>
@@ -433,7 +464,7 @@ export default class InstantiateInputParams extends Component {
             <div className="inputControls inputControls-sshkeys ">
               <label style={{display: 'flex', 'flexDirection': 'row'}}>
               SSH KEY PAIR
-                <span onClick={self.props.updateSshKeyRef().bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
+                <span onClick={props.sshFn.updateKeyRef().bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
                   <img src={imgAdd} />
                   ADD
                 </span>
@@ -445,14 +476,61 @@ export default class InstantiateInputParams extends Component {
   }
   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 (
         <div className="input_group input_group-users" key={i}>
           <div className="inputControls">
           <div style={{fontWeight: 'bold', display: 'flex'}}>USER <span onClick={usersFn.remove(i)} className="removeInput"><img src={imgRemove} />Remove</span></div>
             <TextInput onChange={usersFn.update(i, 'name')} label="USERNAME" value={i.name} />
-            <TextInput onChange={usersFn.update(i, 'gecos')} label="REAL NAME" value={i.gecos} />
-            <TextInput onChange={usersFn.update(i, 'passwd')} type="password" label="PASSWORD" value={i.passwd} />
+            <TextInput onChange={usersFn.update(i, 'user-info')} label="REAL NAME" value={i.gecos} />
+            {
+              sshKeysRef.map(function(ref, j) {
+                let keyref = JSON.stringify(ref)
+                return (
+                  <div key={keyref.name + '-' + i + '-' + j} className="inputControls inputControls-sshkeys">
+                    <label>
+                      <div>
+                      <SelectOption
+                        label="Key Pair"
+                        options={sshKeysList && sshKeysList.map(function(k) {
+                          return {
+                            label: k.name,
+                            value: k
+                          }
+                        })}
+                        ref="keyPairSelection"
+                        initial={false}
+                        defaultValue={ref}
+                        onChange={usersFn.updateSSHkeyRef(i, j)}>
+                      </SelectOption>
+                      </div>
+                    </label>
+                    {
+                      sshKeysRef.length > 0 ?
+                        <label>
+                          <span onClick={usersFn.updateSSHkeyRef(i, j, true)} className="removeInput">
+                            <img src={imgRemove} />
+                            Remove
+                          </span>
+                        </label>
+                      : null
+                    }
+
+                  </div>
+                )
+              })
+            }
+              <div className="inputControls inputControls-sshkeys ">
+                <label style={{display: 'flex', 'flexDirection': 'row', 'alignItems': 'center'}}>
+                SSH KEY PAIR
+                  <span onClick={usersFn.updateSSHkeyRef(i).bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
+                    <img src={imgAdd} />
+                    ADD
+                  </span>
+                </label>
+              </div>
           </div>
         </div>
       )
@@ -461,9 +539,9 @@ export default class InstantiateInputParams extends Component {
       <div className="configure-nsd_section">
         <h3 className="launchpadCard_title">USERS</h3>
         {usersList}
-        <div className="inputControls inputControls-sshkeys ">
-            <span onClick={usersFn.add} className="addInput">
-              <img src={imgAdd} onClick={usersFn.add} />
+        <div className="inputControls inputControls-sshkeys inputControls-addUser ">
+            <span onClick={usersFn.add(sshKeysList)} className="addInput">
+              <img src={imgAdd} />
               ADD USER
             </span>
         </div>
@@ -548,25 +626,20 @@ function constructCloudAccountOptions(cloudAccounts){
   });
   return CloudAccountOptions;
 }
-function dataCentersHTML(state, onChange) {
+function dataCentersHTML(dataCenters, onChange, initial) {
   //Build DataCenter options
   //Relook at this, why is it an object?
-  let dataCenters = state.dataCenters || [];
-  let DataCenterOptions = {};
-  if(dataCenters){
-    for (let d in dataCenters) {
-      DataCenterOptions[d] = dataCenters[d].map(function(dc, index) {
-        return {
-          label: dc.name,
-          value: dc.uuid
-        }
-      });
+  let DataCenterOptions = [];
+  DataCenterOptions = dataCenters && dataCenters.map(function(dc, index) {
+    return {
+      label: dc.name,
+      value: dc.uuid
     }
-  }
-  if (dataCenters.length > 0) {
+  });
+  if (dataCenters && dataCenters.length > 0) {
     return (
       <label>Select Data Center
-        <SelectOption options={DataCenterOptions} onChange={onChange} />
+        <SelectOption initial={!!initial} options={DataCenterOptions} onChange={onChange} />
       </label>
     )
   }
@@ -577,9 +650,6 @@ function isOpenMano(account) {
     if (a.constructor.name == 'String') {
       a = JSON.parse(a);
     }
-    if(a.hasOwnProperty('account')) {
-      a = a.account;
-    }
     return a['account-type'] == 'openmano';
   } else {
     return false;