mirror of https://github.com/rancher/ui.git
amazon driver updates
This commit is contained in:
parent
487e5779db
commit
dc4fa0bd26
|
|
@ -1,3 +1,10 @@
|
|||
<section>
|
||||
{{add-host allowCustom=(not app.isCaas) model=model driver=driver completed=(action 'completed') goBack=(action 'goBack') cancel=(action 'goBack')}}
|
||||
{{add-host
|
||||
allowCustom=false
|
||||
model=model
|
||||
driver=driver
|
||||
completed=(action 'completed')
|
||||
goBack=(action 'goBack')
|
||||
cancel=(action 'goBack')
|
||||
}}
|
||||
</section>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<section>
|
||||
{{add-host
|
||||
allowCustom=(not app.isCaas)
|
||||
allowCustom=false
|
||||
model=model
|
||||
driver=driver
|
||||
completed=(action 'completed')
|
||||
|
|
|
|||
|
|
@ -1,34 +1,13 @@
|
|||
import $ from 'jquery';
|
||||
import { scheduleOnce } from '@ember/runloop';
|
||||
import EmberObject, { computed } from '@ember/object';
|
||||
import EmberObject, { computed, get, set, setProperties } from '@ember/object';
|
||||
import { alias, equal, gte } from '@ember/object/computed';
|
||||
import { inject as service } from '@ember/service';
|
||||
import Component from '@ember/component';
|
||||
import Driver from 'shared/mixins/host-driver';
|
||||
import layout from './template';
|
||||
|
||||
let RANCHER_TAG = 'rancher-ui';
|
||||
let RANCHER_GROUP = 'rancher-machine';
|
||||
let RANCHER_INGRESS_RULES = [
|
||||
{ FromPort: 6443, ToPort: 6443, CidrIp: '0.0.0.0/0', IpProtocol: 'tcp' }, // Rancher Cluster manager
|
||||
{ FromPort: -1, ToPort: -1, CidrIp: '0.0.0.0/0', IpProtocol: 'icmp' }, // MTU Path discovery (shouldiblockicmp.com)
|
||||
|
||||
// Docker-machine creates these ports if we don't,
|
||||
// but explodes with race conditions if you try to deploy 2 hosts simultaneously and they both want to create it.
|
||||
// So we'll just have the UI create them up front.
|
||||
{ FromPort: 22, ToPort: 22, CidrIp: '0.0.0.0/0', IpProtocol: 'tcp' }, // SSH, to install Docker
|
||||
{ FromPort: 2376, ToPort: 2376, CidrIp: '0.0.0.0/0', IpProtocol: 'tcp' }, // Docker Remote API, for no good reason
|
||||
];
|
||||
|
||||
let RANCHER_INTERNAL_RULES = [
|
||||
// : 2379,2380 (etcd), 10251 (Scheduler), 10252 (Controller), 10250 (kubelet), 10256 (kubeproxy), 6443 (kubeapi)
|
||||
// 8472/udp (flannel)
|
||||
{ FromPort: 2379, ToPort: 2380, IpProtocol: 'tcp' }, // etcd
|
||||
{ FromPort: 6443, ToPort: 6443, IpProtocol: 'tcp' }, // cluster manager
|
||||
{ FromPort: 4789, ToPort: 4789, IpProtocol: 'udp' }, // vxlan
|
||||
{ FromPort: 8472, ToPort: 8472, IpProtocol: 'udp' }, // flannel
|
||||
{ FromPort: 10250, ToPort: 10256, IpProtocol: 'tcp' }, // kubelet, scheduler, controller, federation, ingress, readonly kublelet, kubeproxy
|
||||
];
|
||||
let RANCHER_GROUP = 'rancher-nodes';
|
||||
|
||||
let INSTANCE_TYPES = [
|
||||
{group: 'T2 - Burstable', name: 't2.nano'},
|
||||
|
|
@ -195,19 +174,19 @@ export default Component.extend(Driver, {
|
|||
isGteStep7 : gte('step',7),
|
||||
|
||||
bootstrap: function() {
|
||||
let pref = this.get('prefs.amazonec2')||{};
|
||||
let config = this.get('globalStore').createRecord({
|
||||
let pref = get(this, 'prefs.amazonec2')||{};
|
||||
let config = get(this, 'globalStore').createRecord({
|
||||
type : 'amazonec2Config',
|
||||
region : 'us-west-2',
|
||||
instanceType : 't2.micro',
|
||||
securityGroup : ['rancher-machine',],
|
||||
securityGroup : '',
|
||||
zone : 'a',
|
||||
rootSize : '16',
|
||||
accessKey : pref.accessKey||'',
|
||||
secretKey : pref.secretKey||'',
|
||||
});
|
||||
|
||||
this.set('model', this.get('globalStore').createRecord({
|
||||
set(this, 'model', get(this, 'globalStore').createRecord({
|
||||
type: 'machineTemplate',
|
||||
driver: 'amazonec2',
|
||||
amazonec2Config: config
|
||||
|
|
@ -217,30 +196,32 @@ export default Component.extend(Driver, {
|
|||
validate() {
|
||||
let errors = [];
|
||||
|
||||
if ( !this.get('model.name') ) {
|
||||
if ( !get(this, 'model.name') ) {
|
||||
errors.push('Name is required');
|
||||
}
|
||||
|
||||
this.set('errors', errors);
|
||||
set(this, 'errors', errors);
|
||||
return errors.length === 0;
|
||||
},
|
||||
|
||||
init: function() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.set('editing', false);
|
||||
this.set('clients', EmberObject.create());
|
||||
this.set('allSubnets', []);
|
||||
setProperties(this, {
|
||||
editing: false,
|
||||
clients: EmberObject.create(),
|
||||
allSubnets: []
|
||||
})
|
||||
|
||||
let cur = this.get('amazonec2Config.securityGroup');
|
||||
let cur = get(this, 'amazonec2Config.securityGroup');
|
||||
|
||||
if ( cur.length === 1 && cur[0] === RANCHER_GROUP ) {
|
||||
this.setProperties({
|
||||
if ( cur === '' ) { // TODO 2.0 should this be null 403 Vince/Wes/Daishan
|
||||
setProperties(this, {
|
||||
whichSecurityGroup : 'default',
|
||||
selectedSecurityGroup : null,
|
||||
});
|
||||
} else {
|
||||
this.setProperties({
|
||||
setProperties(this, {
|
||||
whichSecurityGroup : 'custom',
|
||||
selectedSecurityGroup : cur,
|
||||
});
|
||||
|
|
@ -248,7 +229,7 @@ export default Component.extend(Driver, {
|
|||
},
|
||||
|
||||
willDestroyElement: function() {
|
||||
this.setProperties({
|
||||
setProperties(this, {
|
||||
step : 1,
|
||||
machineId : null,
|
||||
clients : null,
|
||||
|
|
@ -267,17 +248,19 @@ export default Component.extend(Driver, {
|
|||
actions: {
|
||||
awsLogin: function() {
|
||||
let self = this;
|
||||
this.set('errors',null);
|
||||
this.set('step',2);
|
||||
|
||||
this.set('amazonec2Config.accessKey', (this.get('amazonec2Config.accessKey')||'').trim());
|
||||
this.set('amazonec2Config.secretKey', (this.get('amazonec2Config.secretKey')||'').trim());
|
||||
setProperties(this, {
|
||||
'errors':null,
|
||||
'step':2,
|
||||
'amazonec2Config.accessKey': (get(this, 'amazonec2Config.accessKey')||'').trim(),
|
||||
'amazonec2Config.secretKey': (get(this, 'amazonec2Config.secretKey')||'').trim(),
|
||||
});
|
||||
|
||||
let subnets = [];
|
||||
let rName = this.get('amazonec2Config.region');
|
||||
let rName = get(this, 'amazonec2Config.region');
|
||||
let ec2 = new AWS.EC2({
|
||||
accessKeyId : this.get('amazonec2Config.accessKey'),
|
||||
secretAccessKey : this.get('amazonec2Config.secretKey'),
|
||||
accessKeyId : get(this, 'amazonec2Config.accessKey'),
|
||||
secretAccessKey : get(this, 'amazonec2Config.secretKey'),
|
||||
region : rName,
|
||||
});
|
||||
|
||||
|
|
@ -288,8 +271,10 @@ export default Component.extend(Driver, {
|
|||
if ( err ) {
|
||||
let errors = self.get('errors')||[];
|
||||
errors.pushObject(err);
|
||||
this.set('errors', errors);
|
||||
this.set('step', 1);
|
||||
setProperties(this, {
|
||||
'errors': errors,
|
||||
'step': 1
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -302,12 +287,14 @@ export default Component.extend(Driver, {
|
|||
if ( err ) {
|
||||
let errors = self.get('errors')||[];
|
||||
errors.pushObject(err);
|
||||
this.set('errors', errors);
|
||||
this.set('step', 1);
|
||||
setProperties(this, {
|
||||
'errors': errors,
|
||||
'step': 1
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.get('clients').set(rName, ec2);
|
||||
get(this, 'clients').set(rName, ec2);
|
||||
|
||||
data.Subnets.forEach((subnet) => {
|
||||
if ( (subnet.State||'').toLowerCase() !== 'available' )
|
||||
|
|
@ -327,39 +314,43 @@ export default Component.extend(Driver, {
|
|||
}));
|
||||
});
|
||||
|
||||
this.set('allSubnets', subnets);
|
||||
this.set('step', 3);
|
||||
setProperties(this, {
|
||||
'allSubnets': subnets,
|
||||
'step': 3
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
selectSubnet: function() {
|
||||
this.set('errors',null);
|
||||
set(this, 'errors',null);
|
||||
|
||||
if ( !this.get('selectedZone') ) {
|
||||
this.set('errors', ['Select an Availability Zone']);
|
||||
if ( !get(this, 'selectedZone') ) {
|
||||
set(this, 'errors', ['Select an Availability Zone']);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !this.get('selectedSubnet') ) {
|
||||
this.set('errors', ['Select a VPC or Subnet']);
|
||||
if ( !get(this, 'selectedSubnet') ) {
|
||||
set(this, 'errors', ['Select a VPC or Subnet']);
|
||||
return;
|
||||
}
|
||||
|
||||
this.set('step', 4);
|
||||
set(this, 'step', 4);
|
||||
|
||||
let ec2 = this.get('clients').get(this.get('amazonec2Config.region'));
|
||||
let filter = {Name: 'vpc-id', Values: [ this.get('amazonec2Config.vpcId')]};
|
||||
let ec2 = get(this, 'clients').get(get(this, 'amazonec2Config.region'));
|
||||
let filter = {Name: 'vpc-id', Values: [ get(this, 'amazonec2Config.vpcId')]};
|
||||
|
||||
ec2.describeSecurityGroups({Filters: [filter]}, (err, data) => {
|
||||
if ( err ) {
|
||||
this.set('errors',[err]);
|
||||
this.set('step', 3);
|
||||
setProperties(this, {
|
||||
'errors': [err],
|
||||
'step': 3
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let groups = [];
|
||||
let defaultGroup = null;
|
||||
|
||||
data.SecurityGroups.forEach((group) => {
|
||||
let tags = {};
|
||||
|
|
@ -377,20 +368,17 @@ export default Component.extend(Driver, {
|
|||
id : group.GroupId,
|
||||
name : group.GroupName,
|
||||
description : group.Description,
|
||||
isDefault : group.GroupName === this.get('defaultSecurityGroupName'),
|
||||
isRancher : (typeof tags[RANCHER_TAG] !== 'undefined')
|
||||
};
|
||||
|
||||
groups.push(obj);
|
||||
|
||||
if ( obj.isDefault && !defaultGroup) {
|
||||
defaultGroup = obj;
|
||||
}
|
||||
});
|
||||
|
||||
this.set('step', 5);
|
||||
this.set('allSecurityGroups', groups);
|
||||
this.set('defaultSecurityGroup', defaultGroup);
|
||||
setProperties(this, {
|
||||
'allSecurityGroups': groups,
|
||||
'step': 5
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -402,83 +390,29 @@ export default Component.extend(Driver, {
|
|||
return selectedOptions.push(cap.value);
|
||||
});
|
||||
|
||||
this.set('selectedSecurityGroup', selectedOptions);
|
||||
set(this, 'selectedSecurityGroup', selectedOptions);
|
||||
},
|
||||
|
||||
selectSecurityGroup: function() {
|
||||
this.set('errors',null);
|
||||
set(this, 'errors',null);
|
||||
|
||||
let self = this;
|
||||
let ec2 = this.get('clients').get(this.get('amazonec2Config.region'));
|
||||
|
||||
if ( this.get('isCustomSecurityGroup') ) {
|
||||
this.set('amazonec2Config.securityGroup', this.get('selectedSecurityGroup'));
|
||||
if ( get(this, 'isCustomSecurityGroup') ) {
|
||||
set(this, 'amazonec2Config.securityGroup', get(this, 'selectedSecurityGroup'));
|
||||
done();
|
||||
} else {
|
||||
this.set('step', 6);
|
||||
this.set('amazonec2Config.securityGroup', [this.get('defaultSecurityGroupName')]);
|
||||
let group = this.get('defaultSecurityGroup');
|
||||
if ( group ) {
|
||||
if ( group.isRancher ) {
|
||||
this.set('amazonec2Config.securityGroup', group.name);
|
||||
done();
|
||||
} else {
|
||||
addRules(group.id, done);
|
||||
}
|
||||
} else {
|
||||
ec2.createSecurityGroup({
|
||||
GroupName : this.get('defaultSecurityGroupName'),
|
||||
Description : `${this.get('settings.appName')} default security group`,
|
||||
VpcId : this.get('amazonec2Config.vpcId'),
|
||||
}, function(err, data) {
|
||||
if ( err ) {
|
||||
return done(err);
|
||||
} else {
|
||||
return addRules(data.GroupId, done);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function addRules(groupId, cb) {
|
||||
async.each(RANCHER_INGRESS_RULES, function(item, cb) {
|
||||
let params = JSON.parse(JSON.stringify(item)); // Don't change the original
|
||||
params.GroupId = groupId;
|
||||
ec2.authorizeSecurityGroupIngress(params, cb);
|
||||
}, function(err) {
|
||||
if ( err ) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
async.each(RANCHER_INTERNAL_RULES, function(item, cb) {
|
||||
let ipPermission = JSON.parse(JSON.stringify(item)); // Don't change the original
|
||||
ipPermission.UserIdGroupPairs = [
|
||||
{GroupId: groupId}
|
||||
];
|
||||
|
||||
let params = {
|
||||
GroupId: groupId,
|
||||
IpPermissions: [ipPermission],
|
||||
}
|
||||
|
||||
params.GroupId = groupId;
|
||||
ec2.authorizeSecurityGroupIngress(params, cb);
|
||||
}, function(err) {
|
||||
if ( err ) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
ec2.createTags({
|
||||
Resources : [groupId],
|
||||
Tags : [ {Key : RANCHER_TAG, Value : self.get('app.version') }]
|
||||
}, cb);
|
||||
});
|
||||
setProperties(this, {
|
||||
'amazonec2Config.securityGroup': '',
|
||||
'step': 6
|
||||
});
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
function done(err) {
|
||||
if ( err ) {
|
||||
this.set('errors', [err]);
|
||||
set(this, 'errors', [err]);
|
||||
self.set('step', 5);
|
||||
} else {
|
||||
self.set('step', 7);
|
||||
|
|
@ -489,7 +423,7 @@ export default Component.extend(Driver, {
|
|||
|
||||
selectedZone: computed('amazonec2Config.{region,zone}', {
|
||||
get: function() {
|
||||
let config = this.get('amazonec2Config');
|
||||
let config = get(this, 'amazonec2Config');
|
||||
if ( config.get('region') && config.get('zone') ) {
|
||||
return config.get('region') + config.get('zone');
|
||||
} else {
|
||||
|
|
@ -498,15 +432,15 @@ export default Component.extend(Driver, {
|
|||
},
|
||||
|
||||
set: function(key, val) {
|
||||
let config = this.get('amazonec2Config');
|
||||
let config = get(this, 'amazonec2Config');
|
||||
config.setProperties({
|
||||
region : val.substr(0, val.length - 1),
|
||||
zone : val.substr(val.length - 1),
|
||||
});
|
||||
|
||||
let selectedSubnet = this.get('selectedSubnet');
|
||||
let selectedSubnet = get(this, 'selectedSubnet');
|
||||
|
||||
if ( this.get('subnetChoices').filterBy('value', selectedSubnet).length === 0 ) {
|
||||
if ( get(this, 'subnetChoices').filterBy('value', selectedSubnet).length === 0 ) {
|
||||
config.setProperties({
|
||||
region : val.substr(0, val.length - 1),
|
||||
zone : val.substr(val.length - 1),
|
||||
|
|
@ -524,9 +458,9 @@ export default Component.extend(Driver, {
|
|||
}),
|
||||
|
||||
zoneChoices: function() {
|
||||
const choices = (this.get('allSubnets')||[]).map((subnet) => {return subnet.get('zone');}).sort().uniq();
|
||||
const choices = (get(this, 'allSubnets')||[]).map((subnet) => {return subnet.get('zone');}).sort().uniq();
|
||||
if ( choices.length ) {
|
||||
this.set('selectedZone', choices[0]);
|
||||
set(this, 'selectedZone', choices[0]);
|
||||
}
|
||||
return choices;
|
||||
}.property('allSubnets.@each.{zone}'),
|
||||
|
|
@ -535,7 +469,7 @@ export default Component.extend(Driver, {
|
|||
let out = [];
|
||||
let seenVpcs = [];
|
||||
|
||||
(this.get('allSubnets')||[]).filterBy('zone', this.get('selectedZone')).forEach((subnet) => {
|
||||
(get(this, 'allSubnets')||[]).filterBy('zone', get(this, 'selectedZone')).forEach((subnet) => {
|
||||
let vpcName = subnet.get('vpcName');
|
||||
let vpcId = subnet.get('vpcId');
|
||||
let vpcTags = subnet.get('vpcTags');
|
||||
|
|
@ -568,7 +502,7 @@ export default Component.extend(Driver, {
|
|||
|
||||
selectedSubnet: computed('amazonec2Config.{subnetId,vpcId}', {
|
||||
set: function(key, val) {
|
||||
let config = this.get('amazonec2Config');
|
||||
let config = get(this, 'amazonec2Config');
|
||||
if ( arguments.length > 1 ) {
|
||||
if ( val && val.length ) {
|
||||
if ( val.indexOf('vpc-') === 0 ) {
|
||||
|
|
@ -595,12 +529,12 @@ export default Component.extend(Driver, {
|
|||
},
|
||||
|
||||
get: function() {
|
||||
let config = this.get('amazonec2Config');
|
||||
let config = get(this, 'amazonec2Config');
|
||||
return config.get('subnetId') || config.get('vpcId');
|
||||
},
|
||||
}),
|
||||
|
||||
subnetById: function(id) {
|
||||
return (this.get('allSubnets')||[]).filterBy('subnetId',id)[0];
|
||||
return (get(this, 'allSubnets')||[]).filterBy('subnetId',id)[0];
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -191,11 +191,7 @@
|
|||
<div class="radio pt-10">
|
||||
<label>
|
||||
{{radio-button selection=whichSecurityGroup value="default"}}
|
||||
{{#if defaultSecurityGroup}}
|
||||
{{t 'machine.driverAmazon.securityGroup.defaultExisting' groupName=defaultSecurityGroupName htmlSafe=true}}
|
||||
{{else}}
|
||||
{{t 'machine.driverAmazon.securityGroup.defaultCreate' groupName=defaultSecurityGroupName htmlSafe=true}}
|
||||
{{/if}}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
|
@ -216,13 +212,6 @@
|
|||
<option value={{choice.name}} selected={{array-includes selectedSecurityGroup choice.name}}>{{choice.name}} ({{choice.id}})</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
|
||||
<p style="m-0 mt-10">{{t 'machine.driverAmazon.needs.label' appName=settings.appName}}</p>
|
||||
<ul>
|
||||
<li>{{t 'machine.driverAmazon.needs.item1' appName=settings.appName htmlSafe=true}}</li>
|
||||
<li>{{t 'machine.driverAmazon.needs.item2' appName=settings.appName htmlSafe=true}}</li>
|
||||
<li>{{t 'machine.driverAmazon.needs.item3' appName=settings.appName htmlSafe=true}}</li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<div>
|
||||
|
|
@ -233,7 +222,7 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
{{else}}
|
||||
{{amazonec2Config.securityGroup}}
|
||||
{{defaultSecurityGroupName}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
}}
|
||||
{{else if (eq mode 'add')}}
|
||||
{{add-host
|
||||
allowCustom=(not app.isCaas)
|
||||
allowCustom=false
|
||||
model=addHostModel.model
|
||||
driver=driver
|
||||
cluster=cluster
|
||||
|
|
|
|||
|
|
@ -3243,7 +3243,7 @@ machine:
|
|||
securityGroup:
|
||||
label: Security Group
|
||||
choose: Choose an existing group
|
||||
defaultExisting: "Standard: Use the existing <code>{groupName}</code> group"
|
||||
defaultExisting: "Standard: Use the existing <code>rancher-nodes</code> group"
|
||||
defaultCreate: "Standard: Automatically create a <code>{groupName}</code> group"
|
||||
custom: "Custom: Choose an existing group"
|
||||
updating: Updating Security Group...
|
||||
|
|
|
|||
Loading…
Reference in New Issue