Skip to content

Commit fa333f7

Browse files
Dev 19397 create maas raid (#91), Added orchestration action plugin to create the MaaS RAID
* User yogeshmhaskule93 updated the files in this branch on 2022-02-09 12:02:22.240441. * User yogeshmhaskule93 updated the files in this branch on 2022-02-09 12:14:08.875681. * User yogeshmhaskule93 updated the files in this branch on 2022-02-09 12:17:26.854841.
1 parent 8bf06c8 commit fa333f7

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"action_input_default_values": [
3+
{
4+
"label": "Filesystem Mount Point",
5+
"name": "filesystem_mount_point_a141",
6+
"value": "/data"
7+
}
8+
],
9+
"base_action_name": "Create MaaS RAID",
10+
"continue_on_failure": false,
11+
"description": "",
12+
"enabled": true,
13+
"hook_point": "During Resource Provisioning",
14+
"icon": "maas-logo.png",
15+
"id": "HPA-mzo7uyom",
16+
"last_updated": "2022-02-09",
17+
"name": "Create MaaS RAID",
18+
"run_on_statuses": "",
19+
"run_seq": 1
20+
}
9.11 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"action_inputs": [
3+
{
4+
"allow_multiple": false,
5+
"available_all_servers": false,
6+
"description": null,
7+
"field_dependency_controlling_set": [],
8+
"field_dependency_dependent_set": [],
9+
"global_options": [],
10+
"hide_if_default_value": false,
11+
"id": "CF-bsmk0qui",
12+
"label": "Filesystem Mount Point",
13+
"name": "filesystem_mount_point",
14+
"placeholder": null,
15+
"relevant_osfamilies": [],
16+
"required": true,
17+
"show_as_attribute": false,
18+
"show_on_servers": false,
19+
"type": "STR",
20+
"value_pattern_string": null
21+
}
22+
],
23+
"description": "",
24+
"id": "OHK-zzqe5lkv",
25+
"last_updated": "2022-02-09",
26+
"max_retries": 0,
27+
"name": "Create MaaS RAID",
28+
"resource_technologies": [],
29+
"script_filename": "Sub File for Hook of Create MaaS RAID Script.py",
30+
"shared": false,
31+
"target_os_families": [],
32+
"type": "CloudBolt Plug-in"
33+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""
2+
This is a MAAS-specific sample of plug-in code for a 'During Resource Provisioning' Action.
3+
Please see the Plugin Actions documentation for more examples of plug-in code:
4+
https://docs.cloudbolt.io/articles/#!cloudbolt-latest-docs/cloudbolt-plug-ins
5+
"""
6+
import json
7+
import uuid
8+
9+
from common.methods import set_progress
10+
from infrastructure.models import Server
11+
from resourcehandlers.maas.models import MaasResourceHandler
12+
13+
14+
def run(job, *args, **kwargs):
15+
set_progress("This will show up in the job details page in the CB UI, and in the job log")
16+
mount_point = "{{ filesystem_mount_point }}"
17+
18+
# machine is a MAAS-specific object, only available within the MaasWrapper
19+
machine = kwargs.get('machine', None)
20+
21+
#server_id is the ID of the Cloudbolt Server being provisioned
22+
server_id = kwargs.get('server_id', None)
23+
cb_server = Server.objects.get(pk=server_id)
24+
25+
# maas_machine_type = True when create virtual machine else False
26+
if cb_server.maas_machine_type:
27+
set_progress("Provisioning a RAID is not valid for the virtual machine on a MAAS LXD host")
28+
return "SUCCESS", "The MaaS during-provisioning plugin has completed.", ""
29+
30+
if machine:
31+
maas_id = machine['system_id']
32+
set_progress("Configuring RAID on MAAS machine {}".format(maas_id))
33+
else:
34+
return "FAILURE", "", "Missing required MAAS machine info."
35+
36+
wrapper = kwargs.get('wrapper', None)
37+
if wrapper:
38+
vm = wrapper.get_vm('unused', maas_id)
39+
machine = wrapper.driver.get_machine(maas_id)
40+
else:
41+
return "FAILURE", "", "Invalid (None) wrapper passed to plugin"
42+
43+
fstype = "ext4"
44+
# remove any existing RAID configurations
45+
raids = wrapper.maas_api_request("GET", "nodes/{}/raids/".format(maas_id))
46+
47+
# We need to move to machine in ready state to delete the existig raid, you can't delete raid if machine in allocated state
48+
rel = wrapper.maas_api_request("POST", "machines/{}/?op=release".format(maas_id), data = {"comment" : "making in ready state" })
49+
50+
if raids:
51+
for raid in raids:
52+
set_progress("Deleting RAID volume: {}".format(raid['name']))
53+
wrapper.maas_api_request("DELETE", "nodes/{}/raid/{}/".format(maas_id, raid['id']))
54+
55+
# get unused physical disks
56+
all_disks = wrapper.maas_api_request("GET", "nodes/{}/blockdevices/".format(maas_id))
57+
disks = [str(disk['id']) for disk in all_disks if disk['used_for'] == 'Unused' and disk['type'] == 'physical']
58+
set_progress("MaaS machine has {} associated disks, of which {} are unused physical disks.".format(len(all_disks), len(disks)))
59+
60+
if len(disks)>=2:
61+
set_progress("Creating a RAID-1 array md0 for the machine using all unused disks: {}".format(','.join([disk['name'] for disk in all_disks if disk['used_for'] == 'Unused' and disk['type'] == 'physical'])))
62+
data={
63+
"name": "md0",
64+
"uuid": uuid.uuid4(),
65+
"level": 'raid-1',
66+
"block_devices": disks,
67+
"partitions": [],
68+
"spare_devices": [],
69+
"spare_partitions": [],
70+
}
71+
72+
resp = wrapper.maas_api_request("POST", "nodes/{}/raids/".format(maas_id), data= data)
73+
block_device_id = resp["virtual_device"]["id"]
74+
75+
set_progress("Formatting filesystem: block_device_id={}, fstype={}".format(block_device_id, fstype))
76+
formatdata ={
77+
'fstype': fstype,
78+
'uuid': uuid.uuid4()
79+
}
80+
formatres = wrapper.maas_api_request("POST", 'nodes/{}/blockdevices/{}/?op=format'.format(maas_id, block_device_id), data = formatdata)
81+
82+
set_progress("Configuring mount point: block_device_id={}, mount_point={}".format(block_device_id, mount_point))
83+
mountdata={
84+
"mount_point": mount_point,
85+
"mount_options": "",
86+
}
87+
mountres = wrapper.maas_api_request("POST", 'nodes/{}/blockdevices/{}/?op=mount'.format(maas_id, block_device_id), data = mountdata)
88+
allocated_machines = wrapper.maas_api_request("POST", "machines/?op=allocate", data = {'system_id' : maas_id})
89+
set_progress('Reallocation of MaaS Machine: {}'.format(maas_id))
90+
91+
return "SUCCESS", "Finished configuring RAID for MaaS machine", ""
92+
else:
93+
return "FAILURE", "", "Failed to create RAID during-provisioning because only {} disk, It should be have more than 2 disks".format(disks)
6.73 KB
Loading

0 commit comments

Comments
 (0)