}
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>
)
<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>
usersFn = () => {
let self = this;
return {
- add: function() {
- console.log('adding user')
- let newUser = {
- name: '',
- gecos: '',
- passwd: ''
+ add: function(sshKeysList) {
+ return function(e) {
+ let newUser = {
+ name: '',
+ 'user-info': '',
+ 'ssh-authorized-key': [sshKeysList[0].name]
+ }
+ let usersList = self.usersList;
+ usersList.push(newUser);
+ self.setState({
+ usersList: usersList
+ })
}
- let usersList = self.usersList;
- usersList.push(newUser);
- self.setState({
- usersList: usersList
- })
},
remove: function(i) {
return function() {
usersList: self.usersList
})
}
+ },
+ updateSSHkeyRef: function(i, j, remove){
+ return function(e) {
+ let usersList = _.cloneDeep(self.usersList)
+ let keys = usersList[i]['ssh-authorized-key'];
+ if(!remove) {
+ let keyRef = JSON.parse(e.target.value).name;
+ if(!isNaN(j)) {
+ keys.splice(j, 1);
+ }
+ keys.push(keyRef);
+ } else {
+ keys.splice(j, 1);
+ }
+ usersList[i]['ssh-authorized-key'] = keys;
+ self.setState({
+ usersList: usersList
+ })
+ }
}
}
}
"nsd": nsdPayload
}
- if (this.state.ro['account-type'] == 'openmano') {
+ if (this.state.ro && this.state.ro['account-type'] == 'openmano') {
payload['om-datacenter'] = this.state.dataCenterID;
} else {
payload["cloud-account"] = this.state.selectedCloudAccount.name;
return {'key-pair-ref': JSON.parse(k).name};
});
//Add Users
- payload['user'] = this.state.usersList;
+ payload['user'] = addKeyPairRefToUsers(this.state.usersList);
// console.log(payload)
this.launchNSR({
'nsr': [payload]
}
+function addKeyPairRefToUsers(list) {
+ return list.map(function(u) {
+ return {
+ name: u.name,
+ 'user-info': u['user-info'],
+ 'ssh-authorized-key': u['ssh-authorized-key'].map(function(k) {
+ return {
+ 'key-pair-ref' : k
+ }
+ })
+ }
+ })
+}
function getMockSLA(id) {
console.log('Getting mock SLA Data for id: ' + id);