本文整理汇总了Python中core.models.Instance.save方法的典型用法代码示例。如果您正苦于以下问题:Python Instance.save方法的具体用法?Python Instance.save怎么用?Python Instance.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Instance
的用法示例。
在下文中一共展示了Instance.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_container
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def manage_container(self):
from core.models import Instance, Flavor
if self.deleted:
return
if (self.instance is not None) and (self.instance.image != self.image):
self.instance.delete()
self.instance = None
if self.instance is None:
if not self.provider_service.slices.count():
raise XOSConfigurationError("The VCPE service has no slices")
flavors = Flavor.objects.filter(name="m1.small")
if not flavors:
raise XOSConfigurationError("No m1.small flavor")
node =self.pick_node()
instance = Instance(slice = self.provider_service.slices.all()[0],
node = node,
image = self.image,
creator = self.creator,
deployment = node.site_deployment.deployment,
flavor = flavors[0])
instance.save()
try:
self.instance = instance
super(TenantWithContainer, self).save()
except:
instance.delete()
raise
示例2: adjust_scale
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def adjust_scale(self, slice_hint, scale, max_per_node=None, exclusive_slices=[]):
# late import to get around order-of-imports constraint in __init__.py
from core.models import Instance
slices = [x for x in self.slices.all() if slice_hint in x.name]
for slice in slices:
while slice.instances.all().count() > scale:
s = slice.instances.all()[0]
# print "drop instance", s
s.delete()
while slice.instances.all().count() < scale:
node = self.pick_node(slice, max_per_node, exclusive_slices)
if not node:
# no more available nodes
break
image = slice.default_image
if not image:
raise XOSConfigurationError(
"No default_image for slice %s" % slice.name)
flavor = slice.default_flavor
if not flavor:
raise XOSConfigurationError(
"No default_flavor for slice %s" % slice.name)
s = Instance(slice=slice,
node=node,
creator=slice.creator,
image=image,
flavor=flavor,
deployment=node.site_deployment.deployment)
s.save()
示例3: save_site_allocation
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def save_site_allocation(self, noAct = False, reset=False):
print "save_site_allocation, reset=",reset
if (not self._site_allocation):
# Must be a instance that was just created, and has not site_allocation
# field.
return
all_slice_instances = self.instances.all()
for site_name in self._site_allocation.keys():
desired_allocation = self._site_allocation[site_name]
# make a list of the instances for this site
instances = []
for instance in all_slice_instances:
if instance.node.site_deployment.site.name == site_name:
instances.append(instance)
# delete extra instances
while (reset and len(instances)>0) or (len(instances) > desired_allocation):
instance = instances.pop()
if (not noAct):
print "deleting instance", instance
instance.delete()
else:
print "would delete instance", instance
# add more instances
if (len(instances) < desired_allocation):
site = Site.objects.get(name = site_name)
nodes = self.get_node_allocation([site])
if (not nodes):
raise APIException(detail="no nodes in site %s" % site_name)
while (len(instances) < desired_allocation):
# pick the least allocated node
nodes = sorted(nodes, key=attrgetter("instanceCount"))
node = nodes[0]
instance = Instance(name=node.name,
slice=self,
node=node,
image = self.default_image,
flavor = self.default_flavor,
creator = self.creator,
deployment = node.site_deployment.deployment)
instance.caller = self.caller
instances.append(instance)
if (not noAct):
print "added instance", instance
instance.save()
else:
print "would add instance", instance
node.instanceCount = node.instanceCount + 1
示例4: create
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def create(self, name = None, index = None):
xos_args = self.get_xos_args(name=name, index=index)
instance = Instance(**xos_args)
instance.caller = self.user
instance.no_sync = True
instance.save()
self.deferred_sync.append(instance)
self.info("Created Instance '%s' on node '%s' using flavor '%s' and image '%s'" %
(str(instance), str(instance.node), str(instance.flavor), str(instance.image)))
示例5: add_instance
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def add_instance(auth, fields):
user = authenticate(username=auth.get('username'),
password=auth.get('password'))
images = _get_images(fields.get('image'))
slices = _get_slices(fields.get('slice'))
deployment_networks = _get_deployment_networks(fields.get('deploymentNetwork'))
nodes = _get_nodes(fields.get('node'))
if images: fields['image'] = images[0]
if slices: fields['slice'] = slices[0]
if deployment_networks: fields['deploymentNetwork'] = deployment_networks[0]
if nodes: fields['node'] = nodes[0]
instance = Instance(**fields)
auth['tenant'] = instance.slice.name
instance.os_manager = OpenStackManager(auth=auth, caller = user)
instance.save()
return instance
示例6: handle_container_on_metal
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def handle_container_on_metal(instance):
from core.models import Instance, Flavor, Port, Image
print "MODEL POLICY: instance", instance, "handle container_on_metal"
if instance.deleted:
return
if (instance.isolation in ["container"]) and (instance.slice.network not in ["host", "bridged"]):
# Our current docker-on-metal network strategy requires that there be some
# VM on the server that connects to the networks, so that
# the containers can piggyback off of that configuration.
if not Instance.objects.filter(slice=instance.slice, node=instance.node, isolation="vm").exists():
flavors = Flavor.objects.filter(name="m1.small")
if not flavors:
raise XOSConfigurationError("No m1.small flavor")
images = Image.objects.filter(kind="vm")
companion_instance = Instance(slice = instance.slice,
node = instance.node,
image = images[0],
creator = instance.creator,
deployment = instance.node.site_deployment.deployment,
flavor = flavors[0])
companion_instance.save()
print "MODEL POLICY: instance", instance, "created companion", companion_instance
# Add the ports for the container
for network in instance.slice.networks.all():
# hmmm... The NAT ports never become ready, because sync_ports never
# instantiates them. Need to think about this.
print "MODEL POLICY: instance", instance, "handling network", network
if (network.name.endswith("-nat")):
continue
if not Port.objects.filter(network=network, instance=instance).exists():
port = Port(network = network, instance=instance)
port.save()
print "MODEL POLICY: instance", instance, "created port", port
示例7: make_new_instance
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import save [as 别名]
def make_new_instance(self):
from core.models import Instance, Flavor
flavors = Flavor.objects.filter(name="m1.small")
if not flavors:
raise XOSConfigurationError("No m1.small flavor")
(node, parent) = LeastLoadedNodeScheduler(self.slice).pick()
instance = Instance(slice=self.slice,
node=node,
image=self.image,
creator=self.slice.creator,
deployment=node.site_deployment.deployment,
flavor=flavors[0],
isolation="vm",
parent=parent)
instance.save()
# We rely on a special naming convention to identify the VMs that will
# hole containers.
instance.name = "%s-outer-%s" % (instance.slice.name, instance.id)
instance.save()
return instance