Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- sean's nutty attempt to learn Haskell - June 2009
- -------------------------------
- -- basic types
- -------------------------------
- -- machine essentials
- type CpuCount = String
- type RamSize = String
- type BusType = String
- -- for physical servers
- type MakeModel = String
- -- Mac will be in the format DE:EA:AD:BE:EE:EF
- -- figure out how to enforce a regex
- type Mac = String
- type Vlan = String
- -- Network related types
- type Hostname = String
- type Ipv4Addr = String
- type Ipv4Mask = String
- type Ipv4Gate = String
- type Ipv6Addr = String
- type Ipv6Mask = String
- type Ipv6Gate = String
- type DnsServer = String
- type DnsDomainName = String --
- type SearchDomain = String
- type TftpServerIp = String -- should be [Ipv4Addr] or [Ipv6Addr]
- type BootFile = String -- is requested by dhcp
- -- Disk related types
- type DiskPath = String
- type DiskDriver = String -- file, ioemu, phys, etc
- type DiskDeviceType = String -- disk, cdrom, usb
- type DiskSize = String -- think of a base... gigs?
- type VirtType = String -- xen, kvm, vmware, virtualbox
- type ServerID = String
- type InstanceID = String
- -------------------------------
- -- typclasses
- -------------------------------
- data Disk = Disk {
- diskSize :: DiskSize,
- diskPath :: DiskPath,
- diskDeviceType :: DiskDeviceType,
- diskDriver :: DiskDriver
- } deriving (Show)
- -- typeclass for network interface cards
- data Nic = Nic {
- mac :: Mac
- } deriving (Show)
- -- typeclass for busses. xen, usb, sas, scsi, ata, pci, etc
- data Bus = Bus {
- busType :: BusType,
- disks :: [Disk],
- nics::[Nic]
- } deriving (Show)
- -- Ipv4Info datatype contains information that might be delivered via DHCP
- data Ipv4Info = Ipv4Info {
- ipv4Addr :: Ipv4Addr,
- ipv4Mask :: Ipv4Mask,
- ipv4Gate :: Ipv4Gate
- } deriving (Show)
- -- Ipv6Info datatype contains information that might be delivered via DHCP
- data Ipv6Info = Ipv6Info {
- ipv6Addr :: Ipv6Addr,
- ipv6Mask :: Ipv6Mask,
- ipv6Gate :: Ipv6Gate
- } deriving (Show)
- -- DnsInfo class contains information that might be delivered via DHCP.
- Note that we're purposely limiting ourselves to one SearchDomain.
- The rationale for this is not all operatins systems correctly parse a list
- of search domains supplied by dhcp.
- data DnsInfo = DnsInfo {
- dnsServers :: [DnsServer],
- dnsDomainName :: DnsDomainName,
- dnsSearchDomain :: SearchDomain
- } deriving (Show)
- -- PxeInfo stuff
- data PxeInfo = PxeInfo {
- tftpServers :: [TftpServerIp],
- bootFile :: BootFile
- } deriving (Show)
- data NetworkInfo = NetworkInfo {
- hostName :: Hostname,
- ipv4Info :: Ipv4Info,
- ipv6Info :: Ipv6Info,
- dnsInfo :: DnsInfo,
- pxeInfo :: PxeInfo
- } deriving (Show)
- -- MachineInfo datatype contains all the information common to both physical
- servers and virtual machines.
- data MachineInfo = MachineInfo {
- cpuCount :: CpuCount,
- ramSize :: RamSize,
- busses :: [Bus]
- } deriving (Show)
- data HostInfo = HostInfo {
- machineInfo :: MachineInfo,
- networkInfo :: NetworkInfo
- } deriving (Show)
- -- servers are "physical" machines
- data ServerInfo = ServerInfo {
- serverID :: ServerID,
- makeModel :: MakeModel,
- serverHostinfo :: HostInfo
- } deriving (Show)
- -- instances are "virtual" machines
- data InstanceInfo = InstanceInfo {
- instanceID :: InstanceID,
- virtType :: VirtType,
- instanceHostinfo :: HostInfo
- } deriving (Show)
- -------------------------------
- -- let's make some components
- -------------------------------
- -- define some disks
- lvmdisk1 = Disk {
- diskSize = "100",
- diskPath = "/dev/xen_vg/instance1000-disk",
- diskDriver = "phys",
- diskDeviceType = "disk"
- }
- diskimage1 = Disk {
- diskSize = "100",
- diskPath = "/mnt/storage/disks/instance1000.img",
- diskDriver = "file",
- diskDeviceType = "disk"
- }
- diskimage2 = Disk {
- diskSize = "100",
- diskPath = "/mnt/storage/disks/instance1001.img",
- diskDriver = "file",
- diskDeviceType = "disk"
- }
- diag_iso1 = Disk {
- diskSize = "100",
- diskPath = "/mnt/storage/isp/diagnostic.iso",
- diskDriver = "file",
- diskDeviceType = "cdrom"
- }
- -- define some nics
- nicA = Nic { mac = "00:00:00:00:00:01" }
- nicB = Nic { mac = "00:00:00:00:00:02" }
- nicC = Nic { mac = "00:00:00:00:00:03" }
- nicD = Nic { mac = "00:00:00:00:00:04" }
- nicE = Nic { mac = "00:00:00:00:00:05" }
- nicF = Nic { mac = "00:00:00:00:00:06" }
- -- the disks on the bus go round and round
- bus1 = Bus {
- busType = "xen",
- disks = [ diskimage1, diag_iso1 ],
- nics = [ nicA, nicB ]
- }
- bus2 = Bus {
- busType = "xen",
- disks = [ diskimage2, diag_iso1 ],
- nics = [ nicC, nicD ]
- }
- -- Lets build some machines
- machineInfo1 = MachineInfo {
- cpuCount = "2",
- ramSize = "2048", -- megabytes?
- busses = [bus1]
- }
- machineInfo2 = MachineInfo {
- cpuCount = "2",
- ramSize = "2048", -- megabytes?
- busses = [bus2]
- }
- ipv4conf1 = Ipv4Info {
- ipv4Addr = "192.168.0.10",
- ipv4Mask = "255.255.255.0",
- ipv4Gate = "192.168.1.1"
- }
- ipv6conf1 = Ipv6Info {
- ipv6Addr = "ipv6 network address",
- ipv6Mask = "ipv6 network mask",
- ipv6Gate = "ipv6 default gateway"
- }
- -- pxe info function
- dnsconf1 = DnsInfo {
- dnsServers = [ "192.168.1.1" ],
- dnsDomainName = "bar.lan",
- dnsSearchDomain = "bar.lan"
- }
- -- pxe info function
- pxeconf1 = PxeInfo {
- tftpServers = ["192.168.0.2"],
- bootFile = "pxe/pxelinux.0"
- }
- -- Lets build some networkInfo functions
- networkInfo1 = NetworkInfo {
- hostName = "host1",
- ipv4Info = ipv4conf1,
- ipv6Info = ipv6conf1,
- dnsInfo = dnsconf1,
- pxeInfo = pxeconf1
- }
- networkInfo2 = NetworkInfo {
- hostName = "host2",
- ipv4Info = Ipv4Info {
- ipv4Addr = "192.168.0.11",
- ipv4Mask = "255.255.255.0",
- ipv4Gate = "192.168.1.1"
- },
- ipv6Info = Ipv6Info {
- ipv6Addr = "ipv6 network address",
- ipv6Mask = "ipv6 network mask",
- ipv6Gate = "ipv6 default gateway"
- },
- dnsInfo = dnsconf1,
- pxeInfo = pxeconf1
- }
- -------------------------------
- -- Lets build some hosts
- -------------------------------
- host1 = HostInfo {
- machineInfo = machineInfo1,
- networkInfo = networkInfo1
- }
- host2 = HostInfo {
- machineInfo = machineInfo2,
- networkInfo = networkInfo2
- }
- -- function host3 is an example of how to define an host in one definition
- host3 = HostInfo {
- machineInfo = MachineInfo {
- cpuCount = "2",
- ramSize = "2048",
- busses = [
- Bus {
- busType = "xen",
- disks = [
- Disk {
- diskSize = "100",
- diskPath = "/mnt/storage/disks/instance1002.img",
- diskDeviceType = "file",
- diskDriver = "disk"
- },
- diag_iso1
- ],
- nics = [
- Nic { mac = "00:00:00:00:00:05" },
- Nic { mac = "00:00:00:00:00:06" }
- ]
- }
- ]
- },
- networkInfo = NetworkInfo {
- hostName = "host2",
- ipv4Info = Ipv4Info {
- ipv4Addr = "192.168.0.11",
- ipv4Mask = "255.255.255.0",
- ipv4Gate = "192.168.1.1"
- },
- ipv6Info = Ipv6Info {
- ipv6Addr = "ipv6 network address",
- ipv6Mask = "ipv6 network mask",
- ipv6Gate = "ipv6 default gateway"
- },
- dnsInfo = DnsInfo {
- dnsServers = [ "192.168.1.1" ],
- dnsDomainName = "bar.lan",
- dnsSearchDomain = "bar.lan"
- },
- pxeInfo = PxeInfo {
- tftpServers = ["192.168.0.2"],
- bootFile = "pxe/pxelinux.0"
- }
- }
- }
- -------------------------------
- --- instances and servers -
- -------------------------------
- instance1 = InstanceInfo {
- instanceID = "00001",
- virtType = "xen",
- instanceHostinfo = host1
- }
- server1 = ServerInfo {
- serverID = "00001",
- makeModel = "Dell 5100",
- serverHostinfo = host2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement