-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1110440
commit 45eb64a
Showing
9 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@endeavorb2b/rancher2api", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"description": "Rancher2 API library", | ||
"main": "src/index.js", | ||
"author": "solocommand <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { validate, post } = require('../common'); | ||
|
||
module.exports = async ({ | ||
uri, | ||
token, | ||
projectId, | ||
namespaceId, | ||
name, | ||
targetWorkloadIds, | ||
}) => { | ||
validate({ | ||
uri, | ||
token, | ||
projectId, | ||
namespaceId, | ||
name, | ||
targetWorkloadIds, | ||
}); | ||
const url = `${uri}/project/${projectId}/services`; | ||
const payload = { | ||
name, | ||
namespaceId, | ||
projectId, | ||
targetWorkloadIds, | ||
}; | ||
const { id, name: Name } = await post(url, token, payload); | ||
return { id, name: Name }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const create = require('./create'); | ||
const list = require('./list'); | ||
|
||
module.exports = { | ||
create, | ||
list, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { validate, get } = require('../common'); | ||
|
||
module.exports = async ({ uri, token, projectId }) => { | ||
validate({ uri, token, projectId }); | ||
const url = `${uri}/projects/${projectId}/services`; | ||
const { data } = await get(url, token); | ||
return data.map(({ id, name }) => ({ id, name })); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { list, create } = require('../src/service'); | ||
|
||
const { log } = console; | ||
|
||
module.exports = async (uri, token, projectId, namespaceId, workloads) => { | ||
try { | ||
log('Listing services'); | ||
const services = await list({ | ||
uri, | ||
token, | ||
projectId, | ||
}); | ||
// log(services); | ||
log('found', services.length, 'services!', services.map(n => n.id)); | ||
|
||
return Promise.all(workloads.map((workload) => { | ||
const filtered = services.filter(svc => svc.name === workload.name); | ||
if (filtered.length) { | ||
log(`Found service ${workload.name}`); | ||
return filtered[0]; | ||
} | ||
|
||
log(`Creating service ${workload.name} ${workload.id}`); | ||
return create({ | ||
uri, | ||
token, | ||
projectId, | ||
namespaceId, | ||
name: workload.name, | ||
targetWorkloadIds: [workload.id], | ||
}); | ||
})); | ||
|
||
// | ||
} catch (e) { | ||
log(e); | ||
process.exit(1); | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters