當前位置: 首頁>>代碼示例>>Python>>正文


Python Node.memory方法代碼示例

本文整理匯總了Python中model.Node.memory方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.memory方法的具體用法?Python Node.memory怎麽用?Python Node.memory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在model.Node的用法示例。


在下文中一共展示了Node.memory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_node

# 需要導入模塊: from model import Node [as 別名]
# 或者: from model.Node import memory [as 別名]
def parse_node(environment, data):
    if data.has_key('name'):
        name = data['name']
    elif data.has_key('node'):
        name = data['node']
    else:
        raise ConfigError, "Unnamed node"

    node = Node(name)
    if data.has_key('cpu'):
        node.cpu = data['cpu']
    if data.has_key('memory'):
        node.memory = data['memory']

    if data.has_key('vnc'):
        node.vnc = data['vnc']

    if data.has_key('cdrom'):
        isopath = data['cdrom']
        if not isinstance(isopath, (str,)):
            raise ConfigError, "It must be string containing path to iso image file"

        node.cdrom = Cdrom(isopath)

    if data.has_key('disk'):
        disks_data = data['disk']
        if type(disks_data) != list:
            disks_data = (disks_data,)

        for disk_data in disks_data:
            if type(disk_data) == str:
                try:
                    size = parse_size(disk_data)
                    node.disks.append(Disk(size=size))
                except ValueError:
                    path = disk_data
                    node.disks.append(Disk(path=path))
            elif isinstance(disk_data, dict):
                node.disks.append(Disk(**disk_data))
            else:
                raise ConfigError, "Unknown disk config: %s" % str(disk_data)

    if data.has_key('networks'):
        networks_data = data['networks']
        if type(networks_data) != list:
            networks_data = (networks_data,)

        for network_data in networks_data:
            if type(network_data) == str:
                network = None
                for n in environment.networks:
                    if n.name == network_data:
                        network = n
                        break

                        # Inline networks
                        # if network is None:
                        #     network = parse_network(environment, {'name': network_data})
                        #     self.networks.append(network)

            # TODO: add support for specifying additional network interface params (e.g. mac address)

            if network is None:
                raise ConfigError, "Unknown network %s" % network_data

            node.interfaces.append(Interface(network))

    if data.has_key('boot'):
        boot_data = data['boot']
        if type(boot_data) != list:
            boot_data = list(boot_data)

        for boot in boot_data:
            if not boot in ('disk', 'network', 'cdrom'):
                raise ConfigError, "Unknown boot option: %s" % boot
            node.boot.append(boot)
    else:
        if len(node.disks) > 0:
            node.boot.append('disk')
        if node.cdrom:
            node.boot.append('cdrom')
        if len(node.interfaces) > 0:
            node.boot.append('network')

    for existing_node in environment.nodes:
        if existing_node.name == node.name:
            raise ConfigError, "Node with given name already exists: %s" % node.name

    environment.nodes.append(node)
開發者ID:akolinko,項目名稱:product,代碼行數:91,代碼來源:yaml_config_loader.py


注:本文中的model.Node.memory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。