コード例 #1
0
def get_virtual_datacenter_for_template(context, template):
    """ Get a virtual datacenter where the given template can be deployed """
    datacenter = template.getDatacenter()
    api_context = context.getApiContext()
    vdcs = find_compatible_virtual_datacenters(context,
                                               template.getDiskFormatType(),
                                               datacenter)
    pattern = "Kahuna-%s-" + api_context.getIdentity()
    vdcs = filter(
        lambda vdc: vdc.getName() ==
        (pattern % vdc.getHypervisorType().name()), vdcs)

    if len(vdcs) == 0:
        log.debug("No default virtual datacenter was found. Creating it...")

        admin = context.getAdministrationService()
        enterprise = admin.getCurrentEnterprise()

        network = PrivateNetwork.builder(api_context) \
            .name("Kahuna-" + api_context.getIdentity()) \
            .gateway("192.168.1.1") \
            .address("192.168.1.0") \
            .mask(24) \
            .build()
        vdc = VirtualDatacenter.builder(api_context, datacenter, enterprise) \
            .network(network) \
            .build()

        for type in HypervisorType.values():
            if type.isCompatible(template.getDiskFormatType()):
                try:
                    log.debug(("Trying to create virtual "
                               "datacenter of type %s") % type.name())
                    vdc.setName(pattern % type.name())
                    vdc.setHypervisorType(type)
                    vdc.save()
                    return vdc
                except AbiquoException, ex:
                    # Just catch the error thrown when no hypervisors of
                    # the given type are available in the datacenter
                    if ex.hasError("VDC-1"):
                        # Check if we can create a VDC with other
                        # compatible type
                        continue
                    else:
                        raise ex
        return None
コード例 #2
0
ファイル: helper.py プロジェクト: abelboldu/kahuna
def get_virtual_datacenter_for_template(context, template):
    """ Get a virtual datacenter where the given template can be deployed """
    datacenter = template.getDatacenter()
    api_context = context.getApiContext()
    vdcs = find_compatible_virtual_datacenters(context,
            template.getDiskFormatType(), datacenter)
    pattern = "Kahuna-%s-" + api_context.getIdentity()
    vdcs = filter(lambda vdc: vdc.getName() ==
            (pattern % vdc.getHypervisorType().name()), vdcs)

    if len(vdcs) == 0:
        log.debug("No default virtual datacenter was found. Creating it...")

        admin = context.getAdministrationService()
        enterprise = admin.getCurrentEnterprise()

        network = PrivateNetwork.builder(api_context) \
            .name("Kahuna-" + api_context.getIdentity()) \
            .gateway("192.168.1.1") \
            .address("192.168.1.0") \
            .mask(24) \
            .build()
        vdc = VirtualDatacenter.builder(api_context, datacenter, enterprise) \
            .network(network) \
            .build()

        for type in HypervisorType.values():
            if type.isCompatible(template.getDiskFormatType()):
                try:
                    log.debug(("Trying to create virtual "
                        "datacenter of type %s") % type.name())
                    vdc.setName(pattern % type.name())
                    vdc.setHypervisorType(type)
                    vdc.save()
                    return vdc
                except AbiquoException, ex:
                    # Just catch the error thrown when no hypervisors of
                    # the given type are available in the datacenter
                    if ex.hasError("VDC-1"):
                        # Check if we can create a VDC with other
                        # compatible type
                        continue
                    else:
                        raise ex
        return None