Skip to content

Commit

Permalink
[lsw] add netplan if config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-BaPtiste Besselat committed Nov 21, 2019
1 parent 515a48e commit b0b809f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/clj/com/linkfluence/inventory/leaseweb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[chime :refer [chime-at]]
[clj-time.core :as t]
[clj-time.periodic :refer [periodic-seq]]
[clojure.spec.alpha :as spec])
[clojure.spec.alpha :as spec]
[clj-yaml.core :as yaml])
(:import [java.io File]
[java.util.concurrent LinkedBlockingQueue]))

Expand Down Expand Up @@ -60,14 +61,16 @@
(defn load-inventory!
[]
;;default use s3
(when-not @test
(when-let [inventory (store/load-map (assoc (:store @lsw-conf) :key (str (:key (:store @lsw-conf)) "-inventory")))]
(reset! lsw-inventory inventory)))
(reset! lsw-inventory inventory))))

(defn load-pscheme!
[]
;;default use s3
(when-not @test
(when-let [pscheme (store/load-map (assoc (:store @lsw-conf) :key (str (:key (:store @lsw-conf)) "-pscheme")))]
(reset! lsw-pscheme pscheme)))
(reset! lsw-pscheme pscheme))))

(defn save-pscheme
"Save on both local file and s3"
Expand Down Expand Up @@ -241,6 +244,23 @@
(str "ifconfig " ifname " up")
"sleep 20"])

(defn- configure-netplan-if
[ifname server-id n]
(let [nfile (str "/etc/netplan/02-" ifname ".yaml")
netplan-conf {:network {
:version 2
:ethernets {
(keyword ifname) {
:dhcp4 "no"
:addresses [
(str
(get-available-address server-id)
(net/get-cidr (:network n) (:netmask n)))
]}}}}]
[(str "echo \"" (yaml/generate-string netplan-conf)"\" > " nfile)
(str "netplan try")
"sleep 20"]))

(defn- configure-red-hat-if
[ifname server-id n]
[(str "echo \"DEVICE=" ifname "\" >> /etc/sysconfig/network-scripts/ifcfg-" ifname)
Expand All @@ -260,6 +280,7 @@
(condp = (get @lsw-conf :base-distrib :debian)
:debian (configure-debian-if ifname server-id n)
:red-hat (configure-red-hat-if ifname server-id n)
:netplan (configure-netplan-if ifname server-id n)
[]))

(defn- choose-if
Expand Down
7 changes: 7 additions & 0 deletions src/clj/com/linkfluence/inventory/net.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
([network netmask address]
(.isInRange (get-subnet-info network netmask) address)))

(defn get-cidr
[network netmask]
(str "/"
(last (.split
(.getCidrSignature (get-subnet-info network netmask))
"/"))))

(defn get-broadcast-addr
([cidr-address]
(.getBroadcastAddress (get-subnet-info cidr-address)))
Expand Down

0 comments on commit b0b809f

Please sign in to comment.