def find_compatible_virtual_datacenter(context, template): """ Find a virtual datacenter compatible with the given template. """ template_type = template.getDiskFormatType() cloud = context.getCloudService() for type in HypervisorType.values(): if type.isCompatible(template_type): vdc = cloud.findVirtualDatacenter(VirtualDatacenterPredicates.type(type)) if vdc: return vdc
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
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
def create_cloud_compute(config, context, dc): """ Creates the default cloud compute entities """ log.info("### Configuring the cloud ###") cloud = CloudCompute(context) # Create it into the 'abiquo' enterprise, to make it easier to use admin = context.getAdministrationService() enterprise = admin.findEnterprise(EnterprisePredicates.name("Abiquo")) vdc = cloud.create_virtual_datacenter(dc, enterprise, HypervisorType.valueOf(config.get("machine", "type")), config.get("virtual datacenter", "name"), config.get("private network", "name"), config.get("private network", "address"), config.getint("private network", "mask"), config.get("private network", "gateway")) vapp = cloud.create_virtual_appliance(vdc, config.get("virtual appliance", "name")) cloud.refresh_template_repository(enterprise, dc) template = find_smallest_template(context, vdc) if template: cloud.create_virtual_machine(vapp, template) return vdc
def create_infrastructure_compute(config, context): """ Creates the default infrastructure compute entities.. """ log.info("### Configuring infrastructure ###") comp = InfrastructureCompute(context) dc = comp.create_datacenter(config.get("datacenter", "name"), config.get("datacenter", "location")) rack = comp.create_rack(dc, config.get("rack", "name"), config.getint("rack", "vlan-min"), config.getint("rack", "vlan-max"), config.getint("rack", "nrsq")) sections = filter(lambda s: s.startswith("machine"), config.sections()) for section in sections: comp.create_machine(rack, HypervisorType.valueOf(config.get(section, "type")), config.get(section, "address"), config.get(section, "user"), config.get(section, "password"), config.get(section, "datastore"), config.get(section, "vswitch")) return dc
def create_cloud_compute(config, context, dc): """ Creates the default cloud compute entities """ log.info("### Configuring the cloud ###") cloud = CloudCompute(context) # Create it into the 'abiquo' enterprise, to make it easier to use admin = context.getAdministrationService() enterprise = admin.findEnterprise(EnterprisePredicates.name("Abiquo")) vdc = cloud.create_virtual_datacenter( dc, enterprise, HypervisorType.valueOf(config.get("machine", "type")), config.get("virtual datacenter", "name"), config.get("private network", "name"), config.get("private network", "address"), config.getint("private network", "mask"), config.get("private network", "gateway")) vapp = cloud.create_virtual_appliance( vdc, config.get("virtual appliance", "name")) cloud.refresh_template_repository(enterprise, dc) template = find_smallest_template(context, vdc) if template: cloud.create_virtual_machine(vapp, template) return vdc
def create_infrastructure_compute(config, context): """ Creates the default infrastructure compute entities. """ log.info("### Configuring infrastructure ###") comp = InfrastructureCompute(context) rs_address = config.get("datacenter", "rs") \ if config.has_option("datacenter", "rs") \ else context.getApiContext().getEndpoint().getHost() dc = comp.create_datacenter(config.get("datacenter", "name"), config.get("datacenter", "location"), rs_address) rack = comp.create_rack(dc, config.get("rack", "name"), config.getint("rack", "vlan-min"), config.getint("rack", "vlan-max"), config.getint("rack", "nrsq")) sections = filter(lambda s: s.startswith("machine"), config.sections()) for section in sections: comp.create_machine( rack, HypervisorType.valueOf(config.get(section, "type")), config.get(section, "address"), config.get(section, "user"), config.get(section, "password"), config.get(section, "datastore"), config.get(section, "vswitch")) return dc
return else: raise ex rack = Rack.builder(api_context, dc).name('rack').build() rack.save() log.debug("New datacenter 'kahuna' created.") else: rack = dc.findRack(RackPredicates.name('rack')) if not rack: rack = Rack.builder(api_context, dc).name('rack').build() rack.save() log.debug("Datacenter 'kahuna' found") # discover machine if hypervisor: hypTypes = [HypervisorType.valueOf(hypervisor)] else: hypTypes = HypervisorType.values() machine = None for hyp in hypTypes: try: log.debug("Trying hypervisor %s" % hyp.name()) machine = dc.discoverSingleMachine(host, hyp, user, psswd) break except (AbiquoException, HttpResponseException), ex: if ex.hasError("NC-3") or ex.hasError("RS-2"): print ex.getMessage().replace("\n", "") return log.debug(ex.getMessage().replace("\n", ""))
dc.delete() return else: raise ex rack = Rack.builder(context,dc).name('rack').build() rack.save() log.debug("New datacenter 'kahuna' created.") else: rack = dc.findRack(RackPredicates.name('rack')) if not rack: rack = Rack.builder(context,dc).name('rack').build() rack.save() log.debug("Datacenter 'kahuna' found") # discover machine hypTypes = [HypervisorType.valueOf(hypervisor)] if hypervisor else HypervisorType.values() machine = None for hyp in hypTypes: try: log.debug("Trying hypervisor %s" % hyp.name()) machine = dc.discoverSingleMachine(host, hyp, user, psswd) break except (AbiquoException, HttpResponseException), ex: if ex.hasError("NC-3") or ex.hasError("RS-2"): print ex.getMessage().replace("\n","") return log.debug(ex.getMessage().replace("\n","")) if not machine: print "Not machine found in %s" % host