def __init__(self, name): super(PeerComplete, self).__init__( name, (EntitySubscriberComplete( name, 'peer', lambda o: o['name'] if o['type'] == 'freenas' else None), RpcComplete(name, 'system.general.get_config', lambda o: o['hostname'])))
def __init__(self, name, context): super(SerialPortNamespace, self).__init__(name, context) self.config_call = 'system.advanced.get_config' self.update_call = 'system.advanced.update' self.add_property(descr='Enable Serial Console', name='serial_console', usage=_("""\ Can be set to yes or no. Only set to yes, if the system has an active serial port and you want to access the system using that serial port."""), get='serial_console', type=ValueType.BOOLEAN) self.add_property(descr='Serial Console Port', name='serial_port', usage=_("""\ Use set or edit to specify the serial port to use for console access."""), get='serial_port', set='serial_port', complete=RpcComplete('serial_port=', 'system.device.get_devices', lambda o: o['name'], call_args=('serial_port', ))) self.add_property(descr='Serial Port Speed', name='serial_speed', usage=_("""\ Use set to specify the speed of the serial port used for console access."""), get='serial_speed', set='serial_speed', enum=[ '110', '300', '600', '1200', '2400', '4800', '9600', '14400', '19200', '38400', '57600', '115200' ], type=ValueType.NUMBER)
def __init__(self, name, context): super(SystemNamespace, self).__init__(name, context) self.context = context self.config_call = 'system.general.get_config' self.update_task = 'system.general.update' self.add_property( descr='Time zone', name='timezone', usage=_("""\ Use set or edit to change the timezone. Type timezones to see the list of valid timezones."""), get='timezone', ) self.add_property( descr='Hostname', name='hostname', usage=_("""\ Use set or edit to change the system's hostname. The hostname must include the domain name. If the network does not use a domain name add .local to the end of the hostname.."""), get='hostname' ) self.add_property( descr='Description', name='description', get='description' ) self.add_property( descr='Tags', name='tags', get='tags', type=ValueType.SET ) self.add_property( descr='Syslog Server', name='syslog_server', usage=_("""\ Use set or edit to set the IP address or hostname:optional_port_number of remote syslog server to send logs to. If set, log entries will be written to both the log namespace and the remote server."""), get='syslog_server' ) self.add_property( descr='Language', name='language', usage=_("""\ Use set or edit to change the localization to the two-letter ISO 3166 country code."""), get='language' ) self.add_property( descr='Console Keymap', name='console_keymap', usage=_("""\ Use set or edit to change the console keyboard layout."""), get='console_keymap', complete=RpcComplete( 'console_keymap=', 'system.general.keymaps', lambda i: i[0] ) ) self.extra_commands = { 'status': StatusCommand(), 'version': VersionCommand(), 'packages': PackagesCommand(), 'timezones': TimezonesCommand(), 'info': InfoCommand(), 'reboot': RebootCommand(), 'shutdown': ShutdownCommand() }
def __init__(self, name, context): super(AdvancedNamespace, self).__init__(name, context) self.context = context self.config_call = 'system.advanced.get_config' self.update_task = 'system.advanced.update' def set_periodic_notify_user(obj, v): if v in range(1, 1000): raise ValueError(_('Invalid value, please specify value outside of range (1..999)')) else: obj['periodic_notify_user'] = v self.add_property( descr='Enable Console CLI', name='console_cli', usage=_("""\ Can be set to yes or no. When set to yes, the system will boot into a login prompt instead of the CLI. You can still start the CLI by typing cli after a successful login."""), get='console_cli', type=ValueType.BOOLEAN ) self.add_property( descr='Enable Console Screensaver', name='console_screensaver', usage=_("""\ Can be set to yes or no. When set to yes, a screensaver will start after a period of CLI inactivity."""), get='console_screensaver', type=ValueType.BOOLEAN ) self.add_property( descr='Enable Serial Console', name='serial_console', usage=_("""\ Can be set to yes or no. Only set to yes, if the system has an active serial port and you want to access the system using that serial port."""), get='serial_console', type=ValueType.BOOLEAN ) self.add_property( descr='Serial Console Port', name='serial_port', usage=_("""\ Use set or edit to specify the serial port to use for console access."""), get='serial_port', set='serial_port', complete=RpcComplete( 'serial_port=', 'system.device.get_devices', lambda o: o['name'], call_args=('serial_port',) ) ) self.add_property( descr='Serial Port Speed', name='serial_speed', usage=_("""\ Use set to specify the speed of the serial port used for console access."""), get='serial_speed', set='serial_speed', enum=['110', '300', '600', '1200', '2400', '4800', '9600', '14400', '19200', '38400', '57600', '115200'], type=ValueType.NUMBER ) self.add_property( descr='Enable powerd', name='powerd', usage=_("""\ Can be set to yes or no. When set to yes, enables powerd(8) which monitors the system state and sets the CPU frequency accordingly."""), get='powerd', type=ValueType.BOOLEAN ) self.add_property( descr='Default swap on drives', name='swapondrive', usage=_("""\ Non-zero number representing the default swap size, for each formatted disk, in GiB."""), set=set_swapondrive, get=lambda o: o['swapondrive'] * 1024 * 1024 * 1024, type=ValueType.SIZE ) self.add_property( descr='Enable Debug Kernel', name='debugkernel', usage=_("""\ Can be set to yes or no. When set to yes, the next boot will boot into a debug version of the kernel which can be useful when troubleshooting."""), get='debugkernel', type=ValueType.BOOLEAN ) self.add_property( descr='Enable Debug UI', name='debugui', usage=_("""\ Can be set to yes or no. When set to yes, debug ui will appear on port 8180 on your machine. Requires a reboot."""), get='debugui', type=ValueType.BOOLEAN ) self.add_property( descr='Automatically upload crash dumps to iXsystems', name='uploadcrash', usage=_("""\ Can be set to yes or no. When set to yes, kernel crash dumps and telemetry (some system statatistics and syslog messages) are automatically sent to the FreeNAS development team for diagnosis."""), get='uploadcrash', type=ValueType.BOOLEAN ) self.add_property( descr='Message of the day', name='motd', usage=_("""\ Use set or edit to modify the message to be seen when a user logs in over SSH. When using set, enclose the message between double quotes"""), get='motd', ) self.add_property( descr='Periodic Notify User UID', name='periodic_notify_user', usage=_("""\ Set to the number representing the UID of the user to receive security output emails. This output runs nightly, but only sends an email when the system reboots or encounters an error."""), get='periodic_notify_user', set=set_periodic_notify_user, type=ValueType.NUMBER ) self.add_property( descr='Home directory root', name='home_directory_root', get='home_directory_root', usage=_("""Parent directory for directory service users' homes""") ) self.add_property( descr='Remote Graphite servers', name='graphite_servers', get='graphite_servers', type=ValueType.SET ) self.add_property( descr='FreeNAS peer token lifetime', name='freenas_token_lifetime', get='freenas_token_lifetime', type=ValueType.NUMBER, usage=_("""\ Period of validity of one time authentication tokens used by peers of a type 'freenas'. This value is expressed in seconds."""), ) self.extra_commands = { 'resume_migration': ResumeMigrationCommand(self) }
def complete(self, context, **kwargs): return [ RpcComplete('token=', 'peer.freenas.get_auth_codes', lambda c: c['code']) ]
def __init__(self, name, context): super(VMNamespace, self).__init__(name, context) self.entity_subscriber_name = 'vm' self.create_task = 'vm.create' self.update_task = 'vm.update' self.delete_task = 'vm.delete' self.required_props = ['name', 'volume'] self.primary_key_name = 'name' self.localdoc['CreateEntityCommand'] = ("""\ Usage: create <name> volume=<volume> <property>=<value> ... Examples: create myvm volume=myvolume create myfreebsd volume=myvolume template=freebsd-11-zfs Creates a virtual machine. For a list of properties, see 'help properties'. For a list of templates see '/ vm template show'""") self.entity_localdoc['SetEntityCommand'] = ("""\ Usage: set <property>=<value> ... Examples: set memsize=2GB set cores=4 set guest_type=freebsd64 set bootloader=GRUB Sets a virtual machine property. For a list of properties, see 'help properties'.""") self.entity_localdoc['DeleteEntityCommand'] = ("""\ Usage: delete Deletes the specified virtual machine.""") self.localdoc['ListCommand'] = ("""\ Usage: show Lists all virtual machines. Optionally, filter or sort by property. Use 'help properties' to list available properties. Examples: show show | search name == foo""") def set_memsize(o, v): set(o, 'config.memsize', int(v / 1024 / 1024)) self.skeleton_entity = { 'devices': [], 'config': {} } self.add_property( descr='VM Name', name='name', get='name', list=True, usage=_("Name of the VM") ) self.add_property( descr='Template name', name='template', get='template.name', complete=RpcComplete('template=', 'vm.template.query', lambda i: get(i, 'template.name')), usage=_("Name of the template used to create the VM from") ) self.add_property( descr='State', name='state', get='status.state', set=None, usage=_("The current state of the VM [RUNNING|STOPPED]") ) self.add_property( descr='Volume', name='volume', get='target', createsetable=True, usersetable=False, complete=EntitySubscriberComplete('volume=', 'volume', lambda i: i['id']), usage=_("The volume on which the VM is stored") ) self.add_property( descr='Description', name='description', get='description', list=False, usage=_("Its a description D'OH!") ) self.add_property( descr='Memory size (MB)', name='memsize', get=lambda o: get(o, 'config.memsize') * 1024 * 1024, set=set_memsize, list=True, type=ValueType.SIZE, usage=_("Size of the Memory allocated to the VM") ) self.add_property( descr='CPU cores', name='cores', get='config.ncpus', list=True, type=ValueType.NUMBER, usage=_("Number of cpu cores assigned to the VM") ) self.add_property( descr='Start on boot', name='autostart', get='config.autostart', type=ValueType.BOOLEAN, usage=_("Property that controls whether the VM is autostarted on System Boot up") ) self.add_property( descr='Boot device', name='boot_device', get='config.boot_device', list=False, usage=_("The device from the devices namespace from which to boot from"), complete=RpcComplete( 'boot_device=', 'vm.query', lambda o: [i['name'] for i in o['devices'] if i['type'] in ('DISK', 'CDROM')] ) ) self.add_property( descr='Boot directory (for GRUB)', name='boot_directory', get='config.boot_directory', list=False, usage=_("The directory in VM's dataset under the files directory that contains grub.cfg") ) self.add_property( descr='Boot partition (for GRUB)', name='boot_partition', get='config.boot_partition', list=False, usage=_("The partition on the os's boot device to boot from (i.e. msdos1 for the first partition of a BIOS partition layout)") ) self.add_property( descr='Bootloader type', name='bootloader', get='config.bootloader', list=False, enum=['BHYVELOAD', 'GRUB', 'UEFI', 'UEFI_CSM'], usage=_("Type of Bootloader"), ) self.add_property( descr='Guest type', name='guest_type', get='guest_type', list=False, enum=[ 'linux64', 'freebsd32', 'freebsd64', 'netbsd64', 'openbsd32', 'openbsd64', 'windows64', 'solaris64', 'other' ], usage=_("Type of the guest os (i.e. freebsd32, windows64, linux64, etc.)") ) self.add_property( descr='Cloud-init data', name='cloud_init', get='config.cloud_init', list=False, usage=_("Bread goes in, Toast comes out. You can't explain that (or this!)") ) self.add_property( descr='Enabled', name='enabled', get='enabled', list=True, type=ValueType.BOOLEAN, usage=_("Enables/Disables the VM") ) self.add_property( descr='Immutable', name='immutable', get='immutable', list=False, usersetable=False, type=ValueType.BOOLEAN, usage=_("Sets VM as immutable") ) self.add_property( descr='Readme', name='readme', get='config.readme', set='config.readme', list=False, type=ValueType.TEXT_FILE, usage=_("Information about this VM including instructions on how to login, username and password, etc.") ) self.add_property( descr='NAT IP address', name='nat_ip', get='status.nat_lease.client_ip', set=None, list=False, condition=lambda o: get(o, 'status.state') != 'STOPPED' and get(o, 'status.nat_lease'), usage=_("Displays the natted IP address of the VM (if any)") ) self.add_property( descr='VM tools available', name='vm_tools_available', get='status.vm_tools_available', set=None, list=False, condition=lambda o: get(o, 'status.state') != 'STOPPED', usage=_("Shows whether freenas-vm-tools are running on the VM"), type=ValueType.BOOLEAN ) self.add_property( descr='Guest health', name='health', get='status.health', set=None, list=False, condition=lambda o: get(o, 'status.state') != 'STOPPED', usage=_("Shows guest health status") ) self.primary_key = self.get_mapping('name') self.entity_namespaces = self.get_entity_namespaces self.entity_commands = self.get_entity_commands self.extra_commands = { 'import': ImportVMCommand(self) }