Revision 0069a20c

b/snf-cyclades-app/synnefo/api/management/commands/port-create.py
39 39

  
40 40
from synnefo.db.models import Network, NetworkInterface, SecurityGroup
41 41
from synnefo.api import util
42
from synnefo.management.common import get_network, get_vm
42 43
from synnefo.logic import ports
43 44

  
44 45

  
......
55 56
            default=None,
56 57
            help="Name of port"),
57 58
        make_option(
58
            '--owner',
59
            dest='owner',
60
            default=None,
61
            help="The owner of the port"),
62
        make_option(
63 59
            '--network',
64 60
            dest='network',
65 61
            default=None,
......
86 82
        device = options['device_id']
87 83
        #assume giving security groups comma separated
88 84
        security_groups = options['security-groups']
89
        userid = options["owner"]
90 85

  
91 86
        if not name:
92 87
            name=""
......
95 90
            raise CommandError("network is required")
96 91
        if not device:
97 92
            raise CommandError("device is required")
98
        if not userid:
99
            raise CommandError("owner is required")
100 93

  
101 94
        #get the network
102
        network = util.get_network(network, userid, non_deleted=True)
95
        network = get_network(network)
103 96

  
104 97
        #get the vm
105
        vm = util.get_vm(device, userid)
98
        vm = get_vm(device)
106 99

  
107 100
        #validate security groups
108 101
        sg_list = []
......
112 105
                sg = util.get_security_group(int(gid))
113 106
                sg_list.append(sg)
114 107

  
115
        new_port = ports.create(userid, network, vm, security_groups=sg_list)
108
        new_port = ports.create(network, vm, security_groups=sg_list)
116 109
        self.stdout.write("Created port '%s' in DB.\n" % new_port)
b/snf-cyclades-app/synnefo/api/management/commands/port-list.py
77 77
    }
78 78

  
79 79
    fields = ["id", "name", "user.uuid", "mac_address", "network",
80
               "fixed_ips"]
80
               "device_id", "fixed_ips"]
b/snf-cyclades-app/synnefo/api/management/commands/port-remove.py
1
# Copyright 2011-2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions
5
# are met:
6
#
7
#   1. Redistributions of source code must retain the above copyright
8
#      notice, this list of conditions and the following disclaimer.
9
#
10
#  2. Redistributions in binary form must reproduce the above copyright
11
#     notice, this list of conditions and the following disclaimer in the
12
#     documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
# The views and conclusions contained in the software and documentation are
27
# those of the authors and should not be interpreted as representing official
28
# policies, either expressed or implied, of GRNET S.A.
29
#
30

  
31
from django.core.management.base import BaseCommand, CommandError
32
from synnefo.logic import ports
33
from synnefo.api.util import get_port
34
from synnefo.management.common  import convert_api_faults
35

  
36
class Command(BaseCommand):
37
    can_import_settings = True
38
    help = "Remove a port from the Database and from the VMs attached to"
39

  
40
    @convert_api_faults
41
    def handle(self, *args, **options):
42
        if len(args) < 1:
43
            raise CommandError("Please provide a port ID")
44

  
45
        port = get_port(args[0], None)
46

  
47
        ports.delete(port)
48

  
49
        self.stdout.write("Successfully removed port\n")
b/snf-cyclades-app/synnefo/api/ports.py
132 132
            sg = util.get_security_group(int(gid))
133 133
            sg_list.append(sg)
134 134

  
135
    new_port = ports.create(user_id, network, vm, security_groups=sg_list)
135
    new_port = ports.create(network, vm, security_groups=sg_list)
136 136

  
137 137
    response = render_port(request, port_to_dict(new_port), status=201)
138 138

  
b/snf-cyclades-app/synnefo/api/util.py
235 235
        if for_update:
236 236
            objects = objects.select_for_update()
237 237

  
238
        port = objects.get(network__userid=user_id, id=port_id)
238
        if not user_id:
239
            port = objects.get(id=port_id)
240
        else:
241
            port = objects.get(network__userid=user_id, id=port_id)
239 242

  
240 243
        if (port.device_owner != "vm") and for_update:
241 244
            raise faults.BadRequest('Can not update non vm port')
b/snf-cyclades-app/synnefo/logic/ports.py
55 55
    return decorator
56 56

  
57 57
@transaction.commit_on_success
58
def create(userid, network, machine, name="", security_groups=None,
58
def create(network, machine, name="", security_groups=None,
59 59
           device_owner='vm'):
60 60

  
61 61
    if network.state != 'ACTIVE':
......
65 65
    port = NetworkInterface.objects.create(name=name,
66 66
                                           network=network,
67 67
                                           machine=machine,
68
                                           userid=machine.userid,
68 69
                                           device_owner=device_owner,
69 70
                                           state="BUILDING")
70 71
    #add the security groups if any
......
76 77
        IPAddress.objects.create(subnet=subn,
77 78
                                 network=network,
78 79
                                 nic=port,
79
                                 userid=userid,
80
                                 userid=machine.userid,
80 81
                                 # FIXME
81 82
                                 address="192.168.0." + str(subn.id))
82 83

  
......
86 87
    #quotas.issue_and_accept_commission(new_port)
87 88

  
88 89
    return port
90

  
91
@transaction.commit_on_success
92
def delete(port):
93
    port.ips.all().delete()
94
    port.delete()

Also available in: Unified diff