Example #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
Example #2
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
Example #3
0
 def create_virtual_datacenter(self, datacenter, enterprise, type,
         name, netname, netaddress, netmask, netgateway):
     """ Creates a new virtual datacenter """
     log.info("Creating virtual datacenter %s of type %s..." % (name, type))
     network = PrivateNetwork.builder(self.__context) \
               .name(netname) \
               .address(netaddress) \
               .mask(netmask) \
               .gateway(netgateway) \
               .build()
     vdc = VirtualDatacenter \
           .builder(self.__context, datacenter, enterprise) \
           .name(name) \
           .hypervisorType(type) \
           .network(network) \
           .build()
     vdc.save()
     return vdc
 def create_virtual_datacenter(self, datacenter, enterprise, type, name,
                               netname, netaddress, netmask, netgateway):
     """ Creates a new virtual datacenter """
     log.info("Creating virtual datacenter %s of type %s..." % (name, type))
     network = PrivateNetwork.builder(self.__context) \
               .name(netname) \
               .address(netaddress) \
               .mask(netmask) \
               .gateway(netgateway) \
               .build()
     vdc = VirtualDatacenter \
           .builder(self.__context, datacenter, enterprise) \
           .name(name) \
           .hypervisorType(type) \
           .network(network) \
           .build()
     vdc.save()
     return vdc