GUI Slave UPS Support

Status
Not open for further replies.

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403
I give you my little side project I've been stupidly working on for far too many weeks, GUI Slave UPS Support. It was a mistake to ever start it. Still I'm happy it's finished or I'm finished with it at least. The backend is solid. I didn't see a way around the change to notifier.py, but perhaps there is a better way. The GUI is a bit ugly, but functions. Before you ask why I did that dumb thing with the GUI, it's because I have no idea what I am doing. I consider it a minor miracle with how long I was lost in the weeds that I ever made it back at all. Milhouse did a fair job identifying the backend issues in this [thread=3086]thread[/thread].




William, any & all questions, comments, critiques and/or criticisms from you would be most welcome. It has passed my testing and now I'm expecting someone from the community to test it. In particular someone with a slave setup, but I suppose an additional master setup test would be useful as well.

To Install:
Requirements: 8.3.1-RELEASE (r13452)
  1. Backup current settings and optionally use your alternate USB stick with a separate install.
  2. Download View attachment slaveUPS.zip : Extract slaveUPS.sh, slaveUPS.sql and slaveUPS.patch to NAS.
  3. chmod 700 slaveUPS.sh
  4. ./slaveUPS.sh
  5. Configure UPS Service.

Details for those who are interested in the particulars or name begins with W.

I didn't see an intelligent way to avoid schema changes for the table services_ups. Two columns are added ups_monuser - varchar(30) default upsmon and ups_modemaster - boolean default 1.
Field ups_monuser: In a slave setup we need to fit in with what's existing which means we need to be able to set the user as well as the password.
Field ups_modemaster: specifies master setup, default, or slave setup.
We can simply reuse ups_identifier allowing '@' and ':' characters on the slave form to be able to specify the remote UPS hostname/IP & port.

A slave setup only needs upsmon configured & running and in our case upssched configured. Ideally, upslog service would be optional if we don't want the traffic.

Backend:
ix-ups
Assorted changes to nut .conf files.
For slave mode we don't generate ups.conf, upsd.conf or upsd.users. The upsd daemon isn't even started in a slave setup.

rc.conf.local
Conditionally enable nut service based on ups_modemaster.​

Notifier:
notifier.py
Which leads to the somewhat ugly, yet functional, change to notifier.py. Updates __service2daemon["ups"] to ("upsmon", "/var/db/nut/upsmon.pid") for slave setup. I'm open to a better way to accomplish this. For the UPS service, in a master setup it should depend on upsd while a slave setup needs to depend on upsmon instead.​

GUI:
The GUI ... might be better to just toss all of it and do it more intelligently. Still what I have functions and I've spent nearly all the time on the GUI as it is. Wound up using a proxy UPS class for the slave setup. That's what can happen when you start flailing around.

ups_edit templates
Add Slave/Master button which takes you to the opposing form.

core.html
Launches appropriate form based on the db.

forms.py
Automatically save ups_modemaster based on which form you are on and added slave form.

models.py
Renamed master pass field and added UPSMON User field.

nav.py
Blacklisted UPS & UPSSlave. UPSnav launches appropriate form based on the value of notifier__service2daemon["ups"].​

I am planning on trying my hand at the migration for the db changes, but I haven't looked at any migrations yet. Other than that I intend to be done with this. This will also be my retirement from any future GUI work. I don't like it.

Like I said if you have a question just ask. I can likely explain it. I will submit patches to Ticket #807 after additional testing.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
I just want to clarify this because I'm not 100% sure. Does this go in the jail or on the actual FreeNAS USB?
 

William Grzybowski

Wizard
iXsystems
Joined
May 27, 2011
Messages
1,754
Thats really cool paleoN, thanks for your work!
I'll take a closer look tomorrow and let you know what I think and perhaps merge the code to the repo.

PS: Consider PM me next time, It was luck to see this post.

I just want to clarify this because I'm not 100% sure. Does this go in the jail or on the actual FreeNAS USB?

In the USB.
 

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403
PS: Consider PM me next time, It was luck to see this post.
No worries. ;) I would have sent you a PM if you hadn't seen it today.

Also, updated the first post with some screenshots. It was pointed out to me that such is useful with GUI changes!
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
Excellent stuff. Was just about to upgrade to 8.3.1 and apply my network UPS hack but will hold off applying the hack if there is any chance of this being implemented.

Just a comment on the two forms, Master and Slave - is this strictly necessary?

Most of the UPS fields are common to both, with only three unique to Master, and one to Slave. Is it possible to have a check box, eg. "UPS is connected remotely" (to signify Master [local] or Slave [remote], the default being unticked, ie. local/Master) and then enable (or make visible) those fields needed for a Master connection, and when ticked, enable the Slave field.

The only Master specific fields are the Driver, Port and Aux Params. I would suggest that for Slave, the host address is a separate field and not mixed in with identifier, in which case the only unique field for Slave is the host address. If these Master/Slave specific fields could be made to appear/disappear according to the local/remote checkbox, I think you could use a single form for both Master and Slave, and it would be much easier (for the user) to comprehend.
 

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403
Sorry, I did not really use your patches :(
I used a different approach, used just ix-ups as a reference.
That's fine. I didn't really like the GUI part anyway. Adding the additional 'upsmon': key to __service2daemon is cleaner. Thought there must have been a better way.

After a quick look through the commits, I'll note that ups_remotepwd doesn't need to be a separate db field unless you want complete separation or your thinking ahead. The password is used in all the same places in the config files. Same with ups_remoteuser. I assume there you wanted to avoid having the user the option to change the default of upsmon. Changing it does work for a master setup, but of course there's no real reason to change it. I'll take a closer look at it tomorrow.

Just a comment on the two forms, Master and Slave - is this strictly necessary?
Not at all. I simply couldn't figure out how to do it. William went a different way which uses a single form.
 

William Grzybowski

Wizard
iXsystems
Joined
May 27, 2011
Messages
1,754
Committed some more fixes, tested installing nut with dummy-ups driver in my main pc e using freenas as slave, seems to be working.

Nightly builds will be back in a few days so you can test it.
 

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403
Committed some more fixes, tested installing nut with dummy-ups driver in my main pc e using freenas as slave, seems to be working.
Tried this out on 8.3.1.

Filling out a slave setup first and clicking OK didn't do anything. When I switched back to master there was a validation error for the port field, serial/USB. Setting that and switching back to slave allowed me to save & start the UPS service without any other settings.

The remote port I was using in the screenshot was a sample non-default port. NUT actually uses 3493 by default. AFAIK, specifying the remote port would be unusual for most setups if occasionally necessary. If you don't specify the port, NUT uses the compiled in default, i.e. 3493. Perhaps make this an advanced field in the future?

The other thing is the ordering. It would be nice to have Identifier as the second field on both forms.

Everything else appears to be correct. Will test a bit more later.
 

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403
The other thing is the ordering. It would be nice to have Identifier as the second field on both forms.

Everything else appears to be correct. Will test a bit more later.
Tested up to the latest commits, [92f09301], and AFAICT everything works correctly.

This is what I meant re: Identifier by the way:
Code:
--- models.py	2013-04-03 22:10:51.468750000 -0700
+++ models.py.01	2013-04-03 22:16:16.597916624 -0700
@@ -969,6 +969,12 @@
         ),
         verbose_name=_("UPS Mode")
     )
+    ups_identifier = models.CharField(
+            max_length=120,
+            verbose_name=_("Identifier"),
+            help_text=_("This name is used to uniquely identify your UPS on "
+                "this system.")
+            )
     ups_remotehost = models.CharField(
         max_length=50,
         blank=True,
@@ -989,12 +995,6 @@
         blank=True,
         verbose_name=_("Remote Password")
     )
-    ups_identifier = models.CharField(
-            max_length=120,
-            verbose_name=_("Identifier"),
-            help_text=_("This name is used to uniquely identify your UPS on "
-                "this system.")
-            )
     ups_driver = models.CharField(
             max_length=120,
             verbose_name=_("Driver"),
It makes more sense to me that way on the Slave form as well as when switching back & forth.

Also, it seems a bit wasteful to have two db password fields for what's really the same thing. That being the upsmon user, whatever it happens to be named, password. But I won't mention it again.


Excellent stuff. Was just about to upgrade to 8.3.1 and apply my network UPS hack but will hold off applying the hack if there is any chance of this being implemented.
Milhouse, I don't have a proper slave setup so if you could further test this it would be useful.
 

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403
Submitted 2 small patches to Ticket #807.

ix-ups : One reference to now defunct ups_masterpwd field removed.

forms.py : ups_monuser has the same requirements as ups_monpwd, no spaces or '#'.
 

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403

paleoN

Wizard
Joined
Apr 22, 2012
Messages
1,403

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
Unfortunately I've not been able to devote much time recently to FreeNAS testing (busy with other projects) - will try again later this week.
 
Status
Not open for further replies.
Top