1#!/usr/local/bin/python3.8 2# -*- coding:utf-8 -*- 3 4# Copyright(C) 2020 Inspur Inc. All Rights Reserved. 5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 7from __future__ import (absolute_import, division, print_function) 8 9__metaclass__ = type 10 11DOCUMENTATION = ''' 12--- 13module: edit_media_instance 14version_added: "0.1.0" 15author: 16 - WangBaoshan (@ISIB-group) 17short_description: Set Virtual Media Instance 18description: 19 - Set Virtual Media Instance on Inspur server. 20options: 21 num_fd: 22 description: 23 - Select the number of floppy devices that support for Virtual Media redirection. 24 choices: [0, 1, 2, 3, 4] 25 type: int 26 num_cd: 27 description: 28 - Select the number of CD/DVD devices that support for Virtual Media redirection. 29 choices: [0, 1, 2, 3, 4] 30 type: int 31 num_hd: 32 description: 33 - Select the number of harddisk devices that support for Virtual Media redirection. 34 choices: [0, 1, 2, 3, 4] 35 type: int 36 kvm_num_fd: 37 description: 38 - Select the number of Remote KVM floppy devices that support for Virtual Media redirection. 39 choices: [0, 1, 2, 3, 4] 40 type: int 41 kvm_num_cd: 42 description: 43 - Select the number of Remote KVM CD/DVD devices that support for virtual Media redirection, 44 - The max support number of html5 KVM is 2 and java KVM is 4. 45 choices: [0, 1, 2, 3, 4] 46 type: int 47 kvm_num_hd: 48 description: 49 - Select the number of Remote KVM Hard disk devices to support for Virtual Media redirection. 50 choices: [0, 1, 2, 3, 4] 51 type: int 52 sd_media: 53 description: 54 - Check this option to enable SD Media support in BMC. 55 choices: ['Enable', 'Disable'] 56 type: str 57 secure_channel: 58 description: 59 - Check this option to enable encrypt media recirection packets. 60 choices: ['Enable', 'Disable'] 61 type: str 62 power_save_mode: 63 description: 64 - Check this option to enable Power Save Mode in BMC. 65 choices: ['Enable', 'Disable'] 66 type: str 67extends_documentation_fragment: 68 - inspur.sm.ism 69''' 70 71EXAMPLES = ''' 72- name: Media instance test 73 hosts: ism 74 connection: local 75 gather_facts: no 76 vars: 77 ism: 78 host: "{{ ansible_ssh_host }}" 79 username: "{{ username }}" 80 password: "{{ password }}" 81 82 tasks: 83 84 - name: "Set media instance" 85 inspur.sm.edit_media_instance: 86 num_fd: 1 87 num_cd: 1 88 num_hd: 1 89 kvm_num_fd: 1 90 kvm_num_cd: 1 91 kvm_num_hd: 1 92 sd_media: "Enable" 93 secure_channel: "Enable" 94 power_save_mode: "Enable" 95 provider: "{{ ism }}" 96''' 97 98RETURN = ''' 99message: 100 description: Messages returned after module execution. 101 returned: always 102 type: str 103state: 104 description: Status after module execution. 105 returned: always 106 type: str 107changed: 108 description: Check to see if a change was made on the device. 109 returned: always 110 type: bool 111''' 112 113from ansible.module_utils.basic import AnsibleModule 114from ansible_collections.inspur.sm.plugins.module_utils.ism import (ism_argument_spec, get_connection) 115 116 117class Instance(object): 118 def __init__(self, argument_spec): 119 self.spec = argument_spec 120 self.module = None 121 self.init_module() 122 self.results = dict() 123 124 def init_module(self): 125 """Init module object""" 126 127 self.module = AnsibleModule( 128 argument_spec=self.spec, supports_check_mode=False) 129 130 def run_command(self): 131 self.module.params['subcommand'] = 'setmediainstance' 132 self.results = get_connection(self.module) 133 if self.results['State'] == 'Success': 134 self.results['changed'] = True 135 136 def show_result(self): 137 """Show result""" 138 self.module.exit_json(**self.results) 139 140 def work(self): 141 """Worker""" 142 self.run_command() 143 self.show_result() 144 145 146def main(): 147 argument_spec = dict( 148 num_fd=dict(type='int', required=False, choices=[0, 1, 2, 3, 4]), 149 num_cd=dict(type='int', required=False, choices=[0, 1, 2, 3, 4]), 150 num_hd=dict(type='int', required=False, choices=[0, 1, 2, 3, 4]), 151 kvm_num_fd=dict(type='int', required=False, choices=[0, 1, 2, 3, 4]), 152 kvm_num_cd=dict(type='int', required=False, choices=[0, 1, 2, 3, 4]), 153 kvm_num_hd=dict(type='int', required=False, choices=[0, 1, 2, 3, 4]), 154 sd_media=dict(type='str', required=False, choices=['Enable', 'Disable']), 155 secure_channel=dict(type='str', required=False, choices=['Enable', 'Disable']), 156 power_save_mode=dict(type='str', required=False, choices=['Enable', 'Disable']), 157 ) 158 argument_spec.update(ism_argument_spec) 159 instance_obj = Instance(argument_spec) 160 instance_obj.work() 161 162 163if __name__ == '__main__': 164 main() 165