Advertisement
Guest User

Untitled

a guest
May 9th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. -- sean's nutty attempt to learn Haskell - June 2009
  2.  
  3. -------------------------------
  4. -- basic types
  5. -------------------------------
  6.  
  7. -- machine essentials
  8. type CpuCount = String
  9. type RamSize = String
  10. type BusType = String
  11.  
  12. -- for physical servers
  13. type MakeModel = String
  14.  
  15. -- Mac will be in the format DE:EA:AD:BE:EE:EF
  16. -- figure out how to enforce a regex
  17. type Mac = String
  18. type Vlan = String
  19.  
  20. -- Network related types
  21. type Hostname = String
  22. type Ipv4Addr = String
  23. type Ipv4Mask = String
  24. type Ipv4Gate = String
  25. type Ipv6Addr = String
  26. type Ipv6Mask = String
  27. type Ipv6Gate = String
  28. type DnsServer = String
  29. type DnsDomainName = String --
  30. type SearchDomain = String
  31. type TftpServerIp = String -- should be [Ipv4Addr] or [Ipv6Addr]
  32. type BootFile = String -- is requested by dhcp
  33.  
  34. -- Disk related types
  35. type DiskPath = String
  36. type DiskDriver = String -- file, ioemu, phys, etc
  37. type DiskDeviceType = String -- disk, cdrom, usb
  38. type DiskSize = String -- think of a base... gigs?
  39.  
  40. type VirtType = String -- xen, kvm, vmware, virtualbox
  41. type ServerID = String
  42. type InstanceID = String
  43.  
  44. -------------------------------
  45. -- typclasses
  46. -------------------------------
  47. data Disk = Disk {
  48. diskSize :: DiskSize,
  49. diskPath :: DiskPath,
  50. diskDeviceType :: DiskDeviceType,
  51. diskDriver :: DiskDriver
  52. } deriving (Show)
  53.  
  54. -- typeclass for network interface cards
  55. data Nic = Nic {
  56. mac :: Mac
  57. } deriving (Show)
  58.  
  59. -- typeclass for busses. xen, usb, sas, scsi, ata, pci, etc
  60. data Bus = Bus {
  61. busType :: BusType,
  62. disks :: [Disk],
  63. nics::[Nic]
  64. } deriving (Show)
  65.  
  66. -- Ipv4Info datatype contains information that might be delivered via DHCP
  67. data Ipv4Info = Ipv4Info {
  68. ipv4Addr :: Ipv4Addr,
  69. ipv4Mask :: Ipv4Mask,
  70. ipv4Gate :: Ipv4Gate
  71. } deriving (Show)
  72.  
  73. -- Ipv6Info datatype contains information that might be delivered via DHCP
  74. data Ipv6Info = Ipv6Info {
  75. ipv6Addr :: Ipv6Addr,
  76. ipv6Mask :: Ipv6Mask,
  77. ipv6Gate :: Ipv6Gate
  78. } deriving (Show)
  79.  
  80. -- DnsInfo class contains information that might be delivered via DHCP.
  81. Note that we're purposely limiting ourselves to one SearchDomain.
  82. The rationale for this is not all operatins systems correctly parse a list
  83. of search domains supplied by dhcp.
  84. data DnsInfo = DnsInfo {
  85. dnsServers :: [DnsServer],
  86. dnsDomainName :: DnsDomainName,
  87. dnsSearchDomain :: SearchDomain
  88. } deriving (Show)
  89.  
  90. -- PxeInfo stuff
  91. data PxeInfo = PxeInfo {
  92. tftpServers :: [TftpServerIp],
  93. bootFile :: BootFile
  94. } deriving (Show)
  95.  
  96. data NetworkInfo = NetworkInfo {
  97. hostName :: Hostname,
  98. ipv4Info :: Ipv4Info,
  99. ipv6Info :: Ipv6Info,
  100. dnsInfo :: DnsInfo,
  101. pxeInfo :: PxeInfo
  102. } deriving (Show)
  103.  
  104. -- MachineInfo datatype contains all the information common to both physical
  105. servers and virtual machines.
  106. data MachineInfo = MachineInfo {
  107. cpuCount :: CpuCount,
  108. ramSize :: RamSize,
  109. busses :: [Bus]
  110. } deriving (Show)
  111.  
  112. data HostInfo = HostInfo {
  113. machineInfo :: MachineInfo,
  114. networkInfo :: NetworkInfo
  115. } deriving (Show)
  116.  
  117. -- servers are "physical" machines
  118. data ServerInfo = ServerInfo {
  119. serverID :: ServerID,
  120. makeModel :: MakeModel,
  121. serverHostinfo :: HostInfo
  122. } deriving (Show)
  123.  
  124. -- instances are "virtual" machines
  125. data InstanceInfo = InstanceInfo {
  126. instanceID :: InstanceID,
  127. virtType :: VirtType,
  128. instanceHostinfo :: HostInfo
  129. } deriving (Show)
  130.  
  131.  
  132. -------------------------------
  133. -- let's make some components
  134. -------------------------------
  135.  
  136. -- define some disks
  137. lvmdisk1 = Disk {
  138. diskSize = "100",
  139. diskPath = "/dev/xen_vg/instance1000-disk",
  140. diskDriver = "phys",
  141. diskDeviceType = "disk"
  142. }
  143.  
  144. diskimage1 = Disk {
  145. diskSize = "100",
  146. diskPath = "/mnt/storage/disks/instance1000.img",
  147. diskDriver = "file",
  148. diskDeviceType = "disk"
  149. }
  150.  
  151. diskimage2 = Disk {
  152. diskSize = "100",
  153. diskPath = "/mnt/storage/disks/instance1001.img",
  154. diskDriver = "file",
  155. diskDeviceType = "disk"
  156. }
  157.  
  158.  
  159. diag_iso1 = Disk {
  160. diskSize = "100",
  161. diskPath = "/mnt/storage/isp/diagnostic.iso",
  162. diskDriver = "file",
  163. diskDeviceType = "cdrom"
  164. }
  165.  
  166. -- define some nics
  167. nicA = Nic { mac = "00:00:00:00:00:01" }
  168. nicB = Nic { mac = "00:00:00:00:00:02" }
  169. nicC = Nic { mac = "00:00:00:00:00:03" }
  170. nicD = Nic { mac = "00:00:00:00:00:04" }
  171. nicE = Nic { mac = "00:00:00:00:00:05" }
  172. nicF = Nic { mac = "00:00:00:00:00:06" }
  173.  
  174. -- the disks on the bus go round and round
  175. bus1 = Bus {
  176. busType = "xen",
  177. disks = [ diskimage1, diag_iso1 ],
  178. nics = [ nicA, nicB ]
  179. }
  180.  
  181. bus2 = Bus {
  182. busType = "xen",
  183. disks = [ diskimage2, diag_iso1 ],
  184. nics = [ nicC, nicD ]
  185. }
  186.  
  187. -- Lets build some machines
  188. machineInfo1 = MachineInfo {
  189. cpuCount = "2",
  190. ramSize = "2048", -- megabytes?
  191. busses = [bus1]
  192. }
  193.  
  194. machineInfo2 = MachineInfo {
  195. cpuCount = "2",
  196. ramSize = "2048", -- megabytes?
  197. busses = [bus2]
  198. }
  199.  
  200.  
  201. ipv4conf1 = Ipv4Info {
  202. ipv4Addr = "192.168.0.10",
  203. ipv4Mask = "255.255.255.0",
  204. ipv4Gate = "192.168.1.1"
  205. }
  206.  
  207. ipv6conf1 = Ipv6Info {
  208. ipv6Addr = "ipv6 network address",
  209. ipv6Mask = "ipv6 network mask",
  210. ipv6Gate = "ipv6 default gateway"
  211. }
  212.  
  213. -- pxe info function
  214. dnsconf1 = DnsInfo {
  215. dnsServers = [ "192.168.1.1" ],
  216. dnsDomainName = "bar.lan",
  217. dnsSearchDomain = "bar.lan"
  218. }
  219.  
  220. -- pxe info function
  221. pxeconf1 = PxeInfo {
  222. tftpServers = ["192.168.0.2"],
  223. bootFile = "pxe/pxelinux.0"
  224. }
  225.  
  226. -- Lets build some networkInfo functions
  227.  
  228. networkInfo1 = NetworkInfo {
  229. hostName = "host1",
  230. ipv4Info = ipv4conf1,
  231. ipv6Info = ipv6conf1,
  232. dnsInfo = dnsconf1,
  233. pxeInfo = pxeconf1
  234. }
  235.  
  236. networkInfo2 = NetworkInfo {
  237. hostName = "host2",
  238.  
  239. ipv4Info = Ipv4Info {
  240. ipv4Addr = "192.168.0.11",
  241. ipv4Mask = "255.255.255.0",
  242. ipv4Gate = "192.168.1.1"
  243. },
  244.  
  245. ipv6Info = Ipv6Info {
  246. ipv6Addr = "ipv6 network address",
  247. ipv6Mask = "ipv6 network mask",
  248. ipv6Gate = "ipv6 default gateway"
  249. },
  250.  
  251. dnsInfo = dnsconf1,
  252. pxeInfo = pxeconf1
  253. }
  254.  
  255.  
  256. -------------------------------
  257. -- Lets build some hosts
  258. -------------------------------
  259.  
  260. host1 = HostInfo {
  261. machineInfo = machineInfo1,
  262. networkInfo = networkInfo1
  263. }
  264.  
  265. host2 = HostInfo {
  266. machineInfo = machineInfo2,
  267. networkInfo = networkInfo2
  268. }
  269.  
  270. -- function host3 is an example of how to define an host in one definition
  271. host3 = HostInfo {
  272. machineInfo = MachineInfo {
  273. cpuCount = "2",
  274. ramSize = "2048",
  275.  
  276. busses = [
  277. Bus {
  278. busType = "xen",
  279.  
  280. disks = [
  281. Disk {
  282. diskSize = "100",
  283. diskPath = "/mnt/storage/disks/instance1002.img",
  284. diskDeviceType = "file",
  285. diskDriver = "disk"
  286. },
  287. diag_iso1
  288. ],
  289. nics = [
  290. Nic { mac = "00:00:00:00:00:05" },
  291. Nic { mac = "00:00:00:00:00:06" }
  292. ]
  293. }
  294. ]
  295. },
  296.  
  297. networkInfo = NetworkInfo {
  298. hostName = "host2",
  299.  
  300. ipv4Info = Ipv4Info {
  301. ipv4Addr = "192.168.0.11",
  302. ipv4Mask = "255.255.255.0",
  303. ipv4Gate = "192.168.1.1"
  304. },
  305.  
  306. ipv6Info = Ipv6Info {
  307. ipv6Addr = "ipv6 network address",
  308. ipv6Mask = "ipv6 network mask",
  309. ipv6Gate = "ipv6 default gateway"
  310. },
  311.  
  312. dnsInfo = DnsInfo {
  313. dnsServers = [ "192.168.1.1" ],
  314. dnsDomainName = "bar.lan",
  315. dnsSearchDomain = "bar.lan"
  316. },
  317.  
  318. pxeInfo = PxeInfo {
  319. tftpServers = ["192.168.0.2"],
  320. bootFile = "pxe/pxelinux.0"
  321. }
  322. }
  323. }
  324.  
  325. -------------------------------
  326. --- instances and servers -
  327. -------------------------------
  328.  
  329. instance1 = InstanceInfo {
  330. instanceID = "00001",
  331. virtType = "xen",
  332. instanceHostinfo = host1
  333. }
  334.  
  335. server1 = ServerInfo {
  336. serverID = "00001",
  337. makeModel = "Dell 5100",
  338. serverHostinfo = host2
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement