def setup_take_backup_action(self): veeam_backup_hook = { 'name': "Take Veeam Backup", 'description': "Takes backup of this server.", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/veeam/take_backup.py', } create_hook(**veeam_backup_hook)
def setup_restore_backup_to_azure_action(self): veeam_restore_backup_hook = { 'name': "Restore Veeam Backup To Azure", 'description': "Restores a server backup", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/veeam/restore_backup_to_azure.py', } create_hook(**veeam_restore_backup_hook)
def setup_veeam_install_agent_action(self): veeam_agent_hook = { 'name': "Install Veeam Agent", 'description': "Installs Veeam agent on Server", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/veeam/install_agent.py' } create_hook(**veeam_agent_hook)
def setup_data_dog_uninstall_agent_action(self): solar_winds_hook = { 'name': "UnInstall Datadog Agent", 'description': "UnInstalls Datadog Agent on a Server", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/data_dog/uninstall_agent.py', } create_hook(**solar_winds_hook)
def setup_new_relic_install_agent_action(self): new_relic_hook = { 'name': "Install New Relic Agent", 'description': "Installs New Relic Agent on a Server", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/new_relic/install_agent.py', } create_hook(**new_relic_hook)
def setup_cloud_endure_install_agent_action(self): cloud_endure_hook = { 'name': "Install CloudEndure Agent", 'description': "Installs CloudEndure Agent on a Server", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/cloudendure/install_agent.py', } create_hook(**cloud_endure_hook)
def setup_solar_winds_install_agent_action(self): solar_winds_hook = { 'name': "Install SolarWinds Agent", 'description': "Installs SolarWinds Agent on a Server", 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/solar_winds/install_agent.py', } create_hook(**solar_winds_hook)
def get_or_create_delete_snapshot_server_action(self): from c2_wrapper import create_hook delete_snapshot = { "name": "tintri_delete_snapshot", "description": "Server Action to delete a Tintri snapshot.", "hook_point": "server_actions", "enabled": False, "module": os.path.join(settings.PROSERV_DIR, "xui/tintri/actions/delete_snapshot.py"), "hook_point_attributes": { "label": "Delete Tintri Snapshot", "extra_classes": "fas fa-trash", "dialog_message": "Delete VM snapshot from Tintri.", }, "inputs": [{ "name": "snapshot_uuid", "label": "UUID", "description": "The UUID of the snapshot being deleted.", "type": "STR", "namespace": "action_inputs", }], } hook = create_hook(**delete_snapshot) sa = hook.serveraction_set.first() sa.condition = hook sa.save() return sa
def get_or_create_clone_from_snapshot_server_action(self): from c2_wrapper import create_hook clone_from_snapshot = { "name": "tintri_clone_from_snapshot", "description": "Server Action to create a server from a Tintri snapshot.", "hook_point": "server_actions", "enabled": False, "module": os.path.join(settings.PROSERV_DIR, "xui/tintri/actions/clone_from_snapshot.py"), "hook_point_attributes": { "label": "Clone from Tintri Snapshot", "extra_classes": "fas fa-clone", "dialog_message": "Create new snapshot of a vmware VM in Tintri.", }, "inputs": [{ "name": "new_server_name", "label": "New Server Label", "description": "Name to give the resulting VM", "type": "STR", "namespace": "action_inputs", }], } hook = create_hook(**clone_from_snapshot) sa = hook.serveraction_set.first() sa.condition = hook sa.save() return sa
def get_or_create_take_snapshot_server_action(self): from c2_wrapper import create_hook take_snapshot = { "name": "tintri_create_snapshot", "description": "Server Action to create snapshot in Tintri.", "hook_point": "server_actions", "enabled": False, "module": os.path.join(settings.PROSERV_DIR, "xui/tintri/actions/create_snapshot.py"), "hook_point_attributes": { "label": "Take Tintri Snapshot", "extra_classes": "fas fa-camera", "dialog_message": "Create new snapshot of a vmware VM in Tintri.", }, "inputs": [{ "name": "snapshot_duration", "label": "Duration", "description": "Duration (in minutes)", "type": "INT", "namespace": "action_inputs", }], } hook = create_hook(**take_snapshot) sa = hook.serveraction_set.first() sa.condition = hook sa.save() return sa
def setup_aws_iam_policies(): from c2_wrapper import create_hook from initialize.create_objects import create_recurring_job get_iam_policies_action = { 'label': 'AWS IAM Policy Caching', 'name': 'aws_iam_policy_caching', 'description': ("Fetches and stores all IAM Policies associated with " "a given AWS Resource Handler."), 'hook_point': None, 'module': '/var/opt/cloudbolt/proserv/xui/iam_policies/aws_iam_policy_caching.py', 'enabled': True, } create_hook(**get_iam_policies_action) get_iam_policies_recurring_job = { 'name': 'AWS IAM Policy Caching', 'type': 'recurring_action', 'hook_name': 'AWS IAM Policy Caching', 'description': ('Fetches and stores the IAM Policies for all configured AWS Resource Handlers. These ' 'policy lists are stored in /var/opt/cloudbolt/iam_policies/.'), 'schedule': '0 23 * * *', 'enabled': True, } create_recurring_job(get_iam_policies_recurring_job)
def get_or_create_required_objects(): """ Creates the related objects (parameters, Recurring Job) that are needed to support this UI Extension, if needed. If they already exist, just gets them and returns whatever's needed """ CustomField.objects.get_or_create( name='scheduled_snapshot_schedule', type='STR', defaults={ 'label': 'Schedule for Snapshots', 'description': ('Cron-style timing to take a snapshot of a Server. Only intended for use with the Scheduled ' 'Snapshots UI Extension and its associated "Take Scheduled Snapshots" Recurring Job' ) }) CustomField.objects.get_or_create( name='scheduled_snapshot_maximum', type='INT', defaults={ 'label': 'Maximum # of Snapshots', 'description': ('The number of scheduled snapshots to take of a Server before beginning to delete ' 'the oldest. Optionally overrides the default set on the Recurring Job. Only intended ' 'for use with the Scheduled Snapshots UI Extension and its associated "Take Scheduled ' 'Snapshots" Recurring Job') }) from c2_wrapper import create_hook from initialize.create_objects import create_recurring_job # Use the existing helper methods, but only if the objects don't already exist action = CloudBoltHook.objects.filter( name="Take Scheduled Snapshots").first() if not action: rec_job_action_dict = { "name": "Take Scheduled Snapshots", "description": "Plug-in to support the Recurring Job that takes snapshots that have been scheduled", "hook_point": None, "module": os.path.join( settings.PROSERV_DIR, "xui/scheduled_snapshots/actions/take_scheduled_snapshots.py"), "inputs": [{ "name": "snapshot_maximum", "label": "Maximum # of Snapshots", "description": ("The number of scheduled snapshots to take of a Server before beginning to delete " "the oldest. Can be overridden by the value set on a specific Server" ), "type": "INT", "namespace": "action_inputs", }], } create_hook(**rec_job_action_dict) rec_job = RecurringJob.objects.filter( name="Take Scheduled Snapshots").first() if not rec_job: rec_job_dict = { "name": "Take Scheduled Snapshots", "enabled": True, "description": ("This Recurring Job enables scheduling snapshots to be taken of Servers automatically at a " "certain time of day. To use this feature, go to a Server's details page and configure a " "snapshot schedule and potentially override the maximum # of snapshots on the Scheduled " "Snapshots tab added by the UI Extension to supported Servers." "When the action runs it will look for Servers with a schedule set that indicates a snapshot " "should be taken during that hour, then generate a snapshot for each. It will also check " "whether each such Server has reached its maximum # of snapshots, either as set on that " "individual Server or per the default on this Recurring Job, and, if so, delete the oldest " "snapshot known to CloudBolt in order to respect that maximum. " "CloudBolt will use its own server time to judge whether it is the right time to take a " "snapshot, so make sure you know what time it is on the CB server and that the timezone is right. " "Also note that this Recurring Job is expected to be run " "every hour on the hour. If it is run on a different schedule, that will impact " "when snapshots are taken. The snapshot will only happen if the job runs " "during the hour when a snapshot is scheduled."), "type": "recurring_action", "hook_name": "Take Scheduled Snapshots", # Once/hour at the beginning of the hour "schedule": "0 * * * *", } rec_job = create_recurring_job(rec_job_dict) return rec_job