aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-04 15:49:09 +0100
committerache <ache@ache.one>2019-02-04 15:49:09 +0100
commit0fba3a76bd85ddde23cd442b9e0bc16612dc3f8a (patch)
tree73753bb69a942d278fa589041c3c1f33a27995e6
parentMerge tethapp and autoDHCP (diff)
Ovh reboot
-rw-r--r--inotify.c62
-rw-r--r--ipv6.sh6
-rw-r--r--ovh_reboot.py43
3 files changed, 111 insertions, 0 deletions
diff --git a/inotify.c b/inotify.c
new file mode 100644
index 0000000..5ef0bf2
--- /dev/null
+++ b/inotify.c
@@ -0,0 +1,62 @@
+/*This is the sample program to notify us for the file creation and file deletion takes place in “/tmp” directory*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/inotify.h>
+#include <unistd.h>
+#include <string.h>
+
+#define EVENT_SIZE ( sizeof (struct inotify_event) )
+#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
+
+int main(void) {
+ int length, i = 0;
+ int fd;
+ int wd;
+ char buffer[EVENT_BUF_LEN];
+
+ /*creating the INOTIFY instance*/
+ fd = inotify_init();
+
+ /*checking for error*/
+ if ( fd < 0 ) {
+ perror( "inotify_init" );
+ }
+
+ /*adding the “/tmp” directory into watch list. Here, the suggestion is to validate the existence of the directory before adding into monitoring list.*/
+ wd = inotify_add_watch( fd, "/home/ache/.tmp", IN_CREATE );
+
+ /*actually read return the list of change events happens. Here, read the change event one by one and process it accordingly.*/
+ while ( 1 ) {
+ read( fd, buffer, EVENT_BUF_LEN );
+ struct inotify_event *event = buffer + i;
+ if ( event->len ) {
+ if ( event->mask & IN_CREATE ) {
+ if ( event->mask & IN_ISDIR ) {
+ printf( "New directory %s created.\n", event->name );
+ }
+ else {
+ printf( "New file %s created.\n", event->name );
+ if( strcmp(event->name, "fox") == 0 ) {
+ sleep(2);
+ puts("🦊");
+ break;
+ char filename[512] = "/home/ache/.tmp";
+ char filename_out[512] = "/tmp/";
+ strcat(filename, event->name);
+ strcat(filename_out, event->name);
+ rename(filename, filename_out);
+ }
+ }
+ }
+ }
+ }
+ /*removing the “/tmp” directory from the watch list.*/
+ inotify_rm_watch( fd, wd );
+
+ /*closing the INOTIFY instance*/
+ close( fd );
+
+ return EXIT_SUCCESS;
+}
diff --git a/ipv6.sh b/ipv6.sh
new file mode 100644
index 0000000..e97a614
--- /dev/null
+++ b/ipv6.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+ip -6 a f dev eth0
+ip -6 a a 2001:41d0:601:1100::11dc/128 dev eth0
+ip -6 r a 2001:41d0:601:1100::1 dev eth0
+ip -6 r a default via 2001:41d0:601::1 dev eth0
diff --git a/ovh_reboot.py b/ovh_reboot.py
new file mode 100644
index 0000000..5ee3fff
--- /dev/null
+++ b/ovh_reboot.py
@@ -0,0 +1,43 @@
+'''
+First, install the latest release of Python wrapper: $ pip install ovh
+'''
+
+import json
+import ovh
+
+def main():
+ """ Software to reboot a VPS from OVH using the OVH API
+ Intend to be used as an example
+ """
+ # Instanciate an OVH Client.
+ # You can generate new credentials with full access to your account on
+ # the token creation page
+ with open("~/.ovh_auth", "r") as f_file:
+ auth = f_file.read().strip().split(';')
+ client = ovh.Client(
+ endpoint=auth[0], # Endpoint of API OVH Europe
+ application_key=auth[1], # Application Key
+ application_secret=auth[2], # Application Secret
+ consumer_key=auth[3], # Consumer Key
+ )
+
+ result = client.get('/vps')
+ print(json.dumps(result, indent=4))
+
+ ## ache.one
+ result = client.post('/vps/vps446497.ovh.net/reboot')
+ print(json.dumps(result, indent=4))
+
+ ## mail.ache.one
+ #result = client.post('/vps/vps514854.ovh.net/reboot')
+ #print(json.dumps(result, indent=4))
+
+ ## Useless test about task percentage
+ #result = client.get('/vps/vps446497.ovh.net/tasks',
+ # type='rebootVm', # Filter the value of type property (=) (type: vps.TaskTypeEnum)
+ #)
+ #print(json.dumps(result, indent=4))
+
+
+if __name__ == '__main__':
+ main()