Skip to content

Commit

Permalink
[UI] region and authUrl computing (#39)
Browse files Browse the repository at this point in the history
[UI] region and authUrl computing

Added regions support

Reviewed-by: Artem Lifshits
  • Loading branch information
anton-sidelnikov committed Mar 18, 2024
1 parent 39c9952 commit a612f96
Show file tree
Hide file tree
Showing 5 changed files with 6,018 additions and 14,908 deletions.
8 changes: 4 additions & 4 deletions component/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const appjson = 'application/json;charset=utf-8'
const authURL = 'https://iam.eu-de.otc.t-systems.com/v3'

const defaultDNS = ['100.125.4.25', '8.8.8.8']

Expand Down Expand Up @@ -84,9 +83,10 @@ function authData(username, password, domainName, projectName) {
/**
* Create new client object
* @param region
* @param authUrl
* @return {OpenTelekomCloudClient}
*/
function otcClient(region) {
function otcClient(region, authUrl) {
return {
vpcEndpoint: '',
novaEndpoint: '',
Expand All @@ -109,7 +109,7 @@ function otcClient(region) {
console.log('Authorizing client: ' + json)

return $.post({
url: `${viaProxy(authURL)}/auth/tokens`,
url: `${viaProxy(authUrl)}/auth/tokens`,
contentType: appjson,
data: json,
}).then((response, _, jqXHR) => {
Expand Down Expand Up @@ -335,7 +335,7 @@ function otcClient(region) {
listProjects() {
return $.get({
headers: this.commonHeaders,
url: `${viaProxy(authURL)}/auth/projects`
url: `${viaProxy(authUrl)}/auth/projects`
}).then(data => {
return resolve(data.projects)
}).catch(e => {
Expand Down
87 changes: 73 additions & 14 deletions component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ const defaultRadix = 10
const defaultBase = 1024
/*!!!!!!!!!!!GLOBAL CONST END!!!!!!!!!!!*/

const diskTypes = ['SATA', 'SAS', 'SSD']

const availabilityZones = [
const regions = ['eu-de', 'eu-nl', 'eu-ch2']
const diskTypesAll = ['SATA', 'SAS', 'SSD']
const diskTypesCH = ['SAS', 'SSD']
const availabilityZonesDE = [
'eu-de-01',
'eu-de-02',
'eu-de-03',
]
const availabilityZonesNL = [
'eu-nl-01',
'eu-nl-02',
'eu-nl-03',
]
const availabilityZonesCH = [
'eu-ch2a',
'eu-ch2b',
]

const ubuntuRegex = new RegExp('_[Uu]buntu_')

Expand All @@ -44,6 +54,41 @@ function a2f(src) {
return src.map((v) => ({ label: v, value: v }))
}

/**
* Return proper availability zones based on region
* @param region {string}
* @returns {string[]}
*/
function azs(region) {
let availabilityZones
if (region === 'eu-de'){
availabilityZones = availabilityZonesDE
}
if (region === 'eu-nl'){
availabilityZones = availabilityZonesNL
}
if (region === 'eu-ch2'){
availabilityZones = availabilityZonesCH
}
return availabilityZones
}

/**
* Return proper disk types based on region
* @param region {string}
* @returns {string[]}
*/
function diskTypesList(region) {
let disks
if (region === 'eu-de' || region === 'eu-nl') {
disks = diskTypesAll
}
if (region === 'eu-ch2'){
disks = diskTypesCH
}
return disks
}

const languages = {
"en-us": {
"machine": {
Expand Down Expand Up @@ -71,6 +116,7 @@ const languages = {
"osPassword": "Password",
"osUserDomainName": "Domain Name",
"osProjectName": "Project Name",
"osRegionName": "Region Name",
"availableZone": {
"header": "Availability",
"label": {
Expand Down Expand Up @@ -115,8 +161,6 @@ const languages = {
}
}

const region = 'eu-de'

export default Ember.Component.extend(NodeDriver, {
driverName: '%%DRIVERNAME%%',
config: alias('model.%%DRIVERNAME%%Config'),
Expand All @@ -127,7 +171,7 @@ export default Ember.Component.extend(NodeDriver, {
_prevStep: 1,
errors: [],
intl: service(),
volumeTypes: a2f(diskTypes),
volumeTypes: [],
itemsLoading: false,
flavors: [],
images: [],
Expand Down Expand Up @@ -161,11 +205,11 @@ export default Ember.Component.extend(NodeDriver, {
bootstrap: function () {
let config = get(this, 'globalStore').createRecord({
type: '%%DRIVERNAME%%Config',
region: 'eu-de',
region: regions[0],
username: '',
password: '',
domainName: '',
projectName: 'eu-de',
projectName: '',
availabilityZone: '',
vpcId: '',
subnetId: '',
Expand All @@ -183,7 +227,7 @@ export default Ember.Component.extend(NodeDriver, {
get(this, 'intl.locale')
this.loadLanguage(lang)

set(this, 'otc', otcClient(region))
// set(this, 'otc', otcClient(config.region, authURL))

console.log(`Config: ${JSON.stringify(config)}`)
},
Expand Down Expand Up @@ -291,7 +335,21 @@ export default Ember.Component.extend(NodeDriver, {
)
set(this, 'authFieldsMissing', missing)
}),

authUrlChange: observer('config.region', function () {
const regionName = String(get(this, 'config.region'))
let authURL = 'https://iam.' + regionName + '.otc.t-systems.com/v3'
if (regionName === 'eu-ch2'){
authURL = 'https://iam-pub.' + regionName + '.sc.otc.t-systems.com/v3'
}
set(this, 'config.authUrl', authURL)
set(this, 'otc', otcClient(regionName, authURL))
}),
regionChoices: a2f(regions),
azChoices: computed('config.region', function () {
const r = String(get(this, 'config.region'))
console.log(`Region changed to ${r}. Checking available az choices... `)
return a2f(azs(r))
}),
projectChoices: [],
projectChoicesUpdate: observer('config.username', 'config.password', 'config.domainName', function () {
if (!(
Expand Down Expand Up @@ -375,8 +433,6 @@ export default Ember.Component.extend(NodeDriver, {
})
}),

azChoices: a2f(availabilityZones),

imageChoices: computed('authSuccess', function () {
if (!get(this, 'authSuccess')) {
return []
Expand Down Expand Up @@ -449,8 +505,11 @@ export default Ember.Component.extend(NodeDriver, {
set(this, 'config.sshUser', 'linux')
}
}),

volumeTypeChoices: a2f(diskTypes),
volumeTypeChoices: computed('config.region', function () {
const r = String(get(this, 'config.region'))
console.log(`Region changed to ${r}. Checking available disk types choices... `)
return a2f(diskTypesList(r))
}),

version: '%%DRIVERVERSION%%',

Expand Down
16 changes: 16 additions & 0 deletions component/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
<div class="over-hr r-mt20 r-mb20">
<span>{{t 'machine.driverOtc.access'}}</span>
</div>
<div class="row r-mb10">
<div class="col-sm-12 col-md-2 form-label">
<label class="form-control-static">{{t 'machine.driverOtc.osRegionName'}}</label>
</div>
<div class="col-sm-12 col-md-4">
{{#if (eq step 1)}}
{{new-select class="form-control"
name="region-name"
content=regionChoices
value=config.region
}}
{{else}}
<div class="form-control-static text-muted text-italic">{{config.projectName}}</div>
{{/if}}
</div>
</div>
<div class="row r-mb10">
<div class="col-sm-12 col-md-2 form-label">
<label class="form-control-static">{{t 'machine.driverOtc.osUserDomainName'}}</label>
Expand Down
Loading

0 comments on commit a612f96

Please sign in to comment.