|
1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
3
|
|
|
# this work for additional information regarding copyright ownership. |
|
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
6
|
|
|
# the License. You may obtain a copy of the License at |
|
7
|
|
|
# |
|
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
|
# |
|
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
|
# See the License for the specific language governing permissions and |
|
14
|
|
|
# limitations under the License. |
|
15
|
|
|
|
|
16
|
|
|
from lib.icsp import ICSPBaseActions |
|
17
|
|
|
import json |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class Apply(ICSPBaseActions): |
|
21
|
|
|
def run(self, buildplan_uris, server_data, connection_details): |
|
22
|
|
|
if connection_details: |
|
23
|
|
|
self.setConnection(connection_details) |
|
24
|
|
|
self.getSessionID() |
|
25
|
|
|
|
|
26
|
|
|
# Prepare Endpoint within ICSP API |
|
27
|
|
|
endpoint = "/rest/os-deployment-jobs" |
|
28
|
|
|
|
|
29
|
|
|
# Prepare Pesonality Data data collection |
|
30
|
|
|
pload = {} |
|
31
|
|
|
pload['osbpUris'] = [] |
|
32
|
|
|
pload['failMode'] = None |
|
33
|
|
|
pload['serverData'] = [] |
|
34
|
|
|
|
|
35
|
|
|
for plan in buildplan_uris: |
|
36
|
|
|
# Confirm input are integers |
|
37
|
|
|
try: |
|
38
|
|
|
isinstance(plan, int) |
|
39
|
|
|
except: |
|
40
|
|
|
raise ValueError("Build plans must be \ |
|
41
|
|
|
Integers (comma seperated)") |
|
42
|
|
|
|
|
43
|
|
|
pload["osbpUris"].append("/rest/os-deployment-build-plans/%s" |
|
44
|
|
|
% plan) |
|
45
|
|
|
|
|
46
|
|
|
for server in server_data: |
|
47
|
|
|
data = {} |
|
48
|
|
|
pdata = {} |
|
49
|
|
|
data['serverUri'] = "/rest/os-deployment-servers/%s" % server |
|
50
|
|
|
|
|
51
|
|
|
# Prepare server personality Data |
|
52
|
|
|
# Initially not including network data Although |
|
53
|
|
|
# this can be included later |
|
54
|
|
|
# TODO extend variable values to include IP configuration |
|
55
|
|
|
|
|
56
|
|
|
if "hostname" in server_data[server]: |
|
57
|
|
|
pdata['hostName'] = server_data[server]['hostname'] |
|
58
|
|
|
if "domain" in server_data[server]: |
|
59
|
|
|
pdata['domain'] = server_data[server]['domain'] |
|
60
|
|
|
if "workgroup" in server_data[server]: |
|
61
|
|
|
pdata['workgroup'] = server_data[server]['workgroup'] |
|
62
|
|
|
data['personalityData'] = pdata |
|
63
|
|
|
|
|
64
|
|
|
pload['serverData'].append(data) |
|
65
|
|
|
|
|
66
|
|
|
payload = json.dumps(pload) |
|
67
|
|
|
try: |
|
68
|
|
|
results = self.icspPOST(endpoint, payload) |
|
69
|
|
|
except Exception as e: |
|
70
|
|
|
raise Exception("Error: %s" % e) |
|
71
|
|
|
|
|
72
|
|
|
return {"jobid": int(results['uri'].rsplit("/")[-1])} |
|
73
|
|
|
|