def create(name, memory, vcpus, local_gb, flavorid, swap=0, rxtx_factor=1): """Creates instance types.""" kwargs = {"memory_mb": memory, "vcpus": vcpus, "local_gb": local_gb, "swap": swap, "rxtx_factor": rxtx_factor} # ensure some attributes are integers and greater than or equal to 0 for option in kwargs: try: kwargs[option] = int(kwargs[option]) assert kwargs[option] >= 0 except (ValueError, AssertionError): msg = _("create arguments must be positive integers") raise exception.InvalidInput(reason=msg) # some value are required to be nonzero, not just positive for option in ["memory_mb", "vcpus"]: try: assert kwargs[option] > 0 except AssertionError: msg = _("create arguments must be positive integers") raise exception.InvalidInput(reason=msg) kwargs["name"] = name kwargs["flavorid"] = flavorid try: return db.instance_type_create(context.get_admin_context(), kwargs) except exception.DBError, e: LOG.exception(_("DB error: %s") % e) msg = _("Cannot create instance_type with name %(name)s and " "flavorid %(flavorid)s") % locals() raise exception.ApiError(msg)
def setUp(self): super(InstanceTypeExtraSpecsTestCase, self).setUp() self.context = context.get_admin_context() values = dict(name="cg1.4xlarge", memory_mb=22000, vcpus=8, local_gb=1690, flavorid=105) specs = dict(cpu_arch="x86_64", cpu_model="Nehalem", xpu_arch="fermi", xpus=2, xpu_model="Tesla 2050") values['extra_specs'] = specs ref = db.instance_type_create(self.context, values) self.instance_type_id = ref.id
def create(name, memory, vcpus, local_gb, flavorid, swap=0, rxtx_factor=1): """Creates instance types.""" kwargs = { 'memory_mb': memory, 'vcpus': vcpus, 'local_gb': local_gb, 'swap': swap, 'rxtx_factor': rxtx_factor, } # ensure some attributes are integers and greater than or equal to 0 for option in kwargs: try: kwargs[option] = int(kwargs[option]) assert kwargs[option] >= 0 except (ValueError, AssertionError): msg = _("create arguments must be positive integers") raise exception.InvalidInput(reason=msg) # some value are required to be nonzero, not just positive for option in ['memory_mb', 'vcpus']: try: assert kwargs[option] > 0 except AssertionError: msg = _("create arguments must be positive integers") raise exception.InvalidInput(reason=msg) kwargs['name'] = name kwargs['flavorid'] = flavorid try: return db.instance_type_create(context.get_admin_context(), kwargs) except exception.DBError, e: LOG.exception(_('DB error: %s') % e) msg = _("Cannot create instance_type with name %(name)s and " "flavorid %(flavorid)s") % locals() raise exception.ApiError(msg)