Revision 0e4ec1f5 snf-cyclades-app/synnefo/api/management/commands/port-create.py

b/snf-cyclades-app/synnefo/api/management/commands/port-create.py
61 61
            default=None,
62 62
            help='The network to attach the port to'),
63 63
        make_option(
64
            '--device',
65
            dest='device_id',
64
            '--server',
65
            dest='server_id',
66 66
            default=None,
67
            help='The VM id the port will be connected to'),
67
            help='The server id the port will be connected to'),
68
        make_option(
69
            '--router',
70
            dest='router_id',
71
            default=None,
72
            help='The router id the port will be connected to'),
68 73
        make_option(
69 74
            '--security-groups',
70 75
            dest='security-groups',
......
79 84

  
80 85
        name = options['name']
81 86
        network = options['network']
82
        device = options['device_id']
87
        server = options['server_id']
88
        router = options['router_id']
83 89
        #assume giving security groups comma separated
84 90
        security_groups = options['security-groups']
85 91

  
86 92
        if not name:
87 93
            name=""
88 94

  
95
        if (server and router) or not (server or router):
96
            raise CommandError('Please give either a server or a router id')
97

  
89 98
        if not network:
90 99
            raise CommandError("network is required")
91
        if not device:
92
            raise CommandError("device is required")
100

  
101
        if server:
102
            device = server
103
            owner = 'vm'
104
        else:
105
            device = router
106
            owner = 'router'
93 107

  
94 108
        #get the network
95 109
        network = get_network(network)
......
105 119
                sg = util.get_security_group(int(gid))
106 120
                sg_list.append(sg)
107 121

  
108
        new_port = ports.create(network, vm, security_groups=sg_list)
122
        new_port = ports.create(network, vm, name, security_groups=sg_list,
123
                                device_owner=owner)
109 124
        self.stdout.write("Created port '%s' in DB.\n" % new_port)

Also available in: Unified diff