|
#coding:utf-8
class OS:
#描述操作系统对象
def __init__(self, os_name):
self.os_name = os_name
def start_install(self):
print("start install os:{0}".format(self.os_name))
class Host:
#描述主机对象
def __init__(self, host_id, brand, cpu, ram, disk):
self.host_id = host_id
self.brand = brand
self.cpu = cpu
self.ram = ram
self.disk = disk
self.os_type = None
def power_off(self):
print("host id:{0} Shutdown..".format(self.host_id))
def power_on(self):
print("host id:{0} Boot..".format(self.host_id))
def install_os(self, os_name):
#服务器(host)可以安装操作系统
os = OS(os_name)
os.start_install()
self.os_type = os.os_name
class DataCenter:
#描述数据中心对象
def __init__(self):
self.hosts_list = []
def add_host(self, host_id, brand, cpu, ram, disk):
#数据中心里可以添加服务器(host)
host = Host(host_id, brand, cpu, ram, disk)
self.hosts_list.append(host)
def search_host(self, host_id):
for host in self.hosts_list:
if host.host_id == host_id:
return host
return False
if __name__ == '__main__':
dc = DataCenter()
dc.add_host(201, "IBM", "16个", "128GB", "9TB")
host = dc.hosts_list[0]
print(host.host_id, host.brand, host.cpu, host.ram, host.disk )
print(host.os_type)
host.install_os("ubuntu14.04")
print(host.os_type)
host.power_on()
host.power_off()
search_host_ret = dc.search_host(201)
print(search_host_ret.disk) |
|
|