This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
kube-core.html
122 lines (114 loc) · 4.04 KB
/
kube-core.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../core-ajax/core-xhr.html">
<polymer-element name="kube-core" hidden attributes="baseurl apiver auth zone provider">
<script>
Polymer({
baseurl: 'http://localhost:8001',
apiver: 'v1beta1',
auth: '',
zone: 'europe-west1-a',
provider: 'GCE',
ready: function() {
this.xhr = document.createElement('core-xhr');
},
sshURL: function(host) {
if (this.provider === 'GCE') {
var parts = (host || '').split('.');
if (parts.length < 4) {
return null;
};
var zone = 'europe-west1-a';
return 'https://cloudssh.developers.google.com/projects/' + parts[2] +
'/zones/' + this.zone +
'/instances/' + parts[0];
}
},
newRequest: function(method, path, body) {
var args = {
url: this.baseurl + '/api/' + this.apiver + path,
method: method,
headers: {'Content-Type': 'application/json'}
};
if (body) {
args.body = JSON.stringify(body);
};
if (this.auth) {
args.headers['Authorization'] = this.auth;
};
return args;
},
doRequest: function(args, callbackFn) {
if (callbackFn) {
args.callback = function(response, xhr) {
var data = xhr.responseText;
var status = xhr.status || 0;
var isError = !(status >= 200 && status < 300);
try {
data = JSON.parse(data);
} catch (err) {
console.warn('kube-api: error parsing response:', data);
console.warn(err);
}
callbackFn(data, isError, xhr);
}
};
return this.xhr.request(args);
},
listReplicas: function(opts) {
var args = this.newRequest('GET', '/replicationControllers');
return this.doRequest(args, opts.callback);
},
getReplica: function(opts) {
var args = this.newRequest('GET', '/replicationControllers/'+opts.rid);
return this.doRequest(args, opts.callback);
},
updateReplica: function(opts, replc) {
var url = '/replicationControllers/' + opts.rid;
var args = this.newRequest('PUT', url, replc);
return this.doRequest(args, opts.callback);
},
createReplica: function(opts, replc) {
var url = '/replicationControllers';
var args = this.newRequest('POST', url, replc);
return this.doRequest(args, opts.callback);
},
removeReplica: function(opts) {
var args = this.newRequest('DELETE', '/replicationControllers/'+opts.rid);
return this.doRequest(args, opts.callback);
},
listPods: function(opts) {
var args = this.newRequest('GET', '/pods');
return this.doRequest(args, opts.callback);
},
getPod: function(opts) {
var args = this.newRequest('GET', '/pods/'+opts.pid);
return this.doRequest(args, opts.callback);
},
createPod: function(opts, pod) {
var url = '/pods';
var args = this.newRequest('POST', url, pod);
return this.doRequest(args, opts.callback);
},
removePod: function(opts) {
var args = this.newRequest('DELETE', '/pods/'+opts.pid);
return this.doRequest(args, opts.callback);
},
listServices: function(opts) {
var args = this.newRequest('GET', '/services');
return this.doRequest(args, opts.callback);
},
getService: function(opts) {
var args = this.newRequest('GET', '/services/'+opts.sid);
return this.doRequest(args, opts.callback);
},
createService: function(opts, srv) {
var args = this.newRequest('POST', '/services', srv);
return this.doRequest(args, opts.callback);
},
removeService: function(opts) {
var args = this.newRequest('DELETE', '/services/'+opts.sid);
return this.doRequest(args, opts.callback);
}
});
</script>
</polymer-element>