def flavor_create(request, instance): flavor = nova.flavor_create(request, name="flavor-%08d" % instance.id, memory=instance.memory, vcpu=instance.cpu, disk=instance.sys_disk, is_public=False) print flavor return flavor
def flavor_create(instance): assert instance def _generate_name(instance): name = u"%s.cpu-%s-ram-%s-disk-%s" % (settings.OS_NAME_PREFIX, instance.cpu, instance.memory, instance.sys_disk) return name def _get_flavor_by_name(instance, name): rc = create_rc_by_instance(instance) flavor = None try: flavors = nova.flavor_list(rc) except Exception: flavors = [] raise if flavors is not None: for f in flavors: if f.name == name: flavor = f break return flavor LOG.info(u"Flavor create start, [%s].", instance) begin = datetime.datetime.now() rc = create_rc_by_instance(instance) name = _generate_name(instance) flavor = _get_flavor_by_name(instance, name) if flavor is None: try: LOG.info(u"Flavor not exist, create new, [%s][%s].", instance, name) flavor = nova.flavor_create(rc, memory=instance.memory, name=name, vcpu=instance.cpu, disk=instance.sys_disk, is_public=True) except nova.nova_exceptions.Conflict: LOG.info(u"Flavor name conflict, [%s][%s].", instance, name) flavor = _get_flavor_by_name(instance, name) except: raise end = datetime.datetime.now() LOG.info(u"Flavor create end, [%s][%s], apply [%s] seconds.", instance, name, (end - begin).seconds) return flavor
def flavor_create(instance=None): rc = create_rc_by_instance(instance) try: flavor = nova.flavor_create(rc, name="flavor-%04d%04d" % ( instance.user.id, instance.id), memory=instance.memory, vcpu=instance.cpu, disk=instance.sys_disk, is_public=False) return flavor except Exception as e: LOG.exception(e) return False
def flavor_create(instance): assert instance def _generate_name(instance): name = u"%s.cpu-%s-ram-%s-disk-%s" % (settings.OS_NAME_PREFIX, instance.cpu, instance.memory, instance.sys_disk) return name def _get_flavor_by_name(instance, name): rc = create_rc_by_instance(instance) flavor = None try: flavors = nova.flavor_list(rc) except Exception: flavors = [] raise if flavors is not None: for f in flavors: if f.name == name: flavor = f break return flavor LOG.info(u"Flavor create start, [%s].", instance) begin = datetime.datetime.now() rc = create_rc_by_instance(instance) name = _generate_name(instance) flavor = _get_flavor_by_name(instance, name) if flavor is None: try: LOG.info(u"Flavor not exist, create new, [%s][%s].", instance, name) flavor = nova.flavor_create(rc, memory=instance.memory, name=name, vcpu=instance.cpu, disk=instance.sys_disk, is_public=True) except nova.nova_exceptions.Conflict: LOG.info(u"Flavor name conflict, [%s][%s].", instance, name) flavor = _get_flavor_by_name(instance, name) except: raise end = datetime.datetime.now() LOG.info(u"Flavor create end, [%s][%s], apply [%s] seconds.", instance, name, (end-begin).seconds) return flavor