Example #1
0
    def _create_in_db(context, values, policies=None, members=None,
                      metadata=None):
        try:
            group = api_models.InstanceGroup()
            group.update(values)
            group.save(context.session)
        except db_exc.DBDuplicateEntry:
            raise exception.InstanceGroupIdExists(group_uuid=values['uuid'])

        if policies:
            group._policies = _instance_group_policies_add(context, group,
                                                           policies)
        else:
            group._policies = []

        if members:
            group._members = _instance_group_members_add(context, group,
                                                         members)
        else:
            group._members = []

        if metadata:
            group._metadata = _instance_group_metadata_add(context, group,
                                                         metadata)
        else:
            group._metadata = []

        return group
Example #2
0
    def _create_in_db(context, values, policies=None, members=None,
                      policy=None, rules=None):
        try:
            group = api_models.InstanceGroup()
            group.update(values)
            group.save(context.session)
        except db_exc.DBDuplicateEntry:
            raise exception.InstanceGroupIdExists(group_uuid=values['uuid'])

        if policies:
            db_policy = api_models.InstanceGroupPolicy(
                group_id=group['id'], policy=policies[0], rules=None)
            group._policies = [db_policy]
            group.rules = None
        elif policy:
            db_rules = jsonutils.dumps(rules or {})
            db_policy = api_models.InstanceGroupPolicy(
                group_id=group['id'], policy=policy,
                rules=db_rules)
            group._policies = [db_policy]
        else:
            group._policies = []

        if group._policies:
            group.save(context.session)

        if members:
            group._members = _instance_group_members_add(context, group,
                                                         members)
        else:
            group._members = []

        return group