Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit ca9f988

Browse files
authored
Merge pull request #222 from LexicForLXD/fix/diverses
fix: update container name closes #221
2 parents 2451d72 + 7feb697 commit ca9f988

13 files changed

Lines changed: 321 additions & 194 deletions

app/config/services.yml

Lines changed: 114 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,119 @@
11
# Learn more about services, parameters and containers at
22
# https://symfony.com/doc/current/service_container.html
33
parameters:
4-
#parameter_name: value
4+
#parameter_name: value
55

66
services:
7-
# default configuration for services in *this* file
8-
_defaults:
9-
# automatically injects dependencies in your services
10-
autowire: true
11-
# automatically registers your services as commands, event subscribers, etc.
12-
autoconfigure: true
13-
# this means you cannot fetch services directly from the container via $container->get()
14-
# if you need to do this, you can override this setting on individual services
15-
public: false
16-
17-
# makes classes in src/AppBundle available to be used as services
18-
# this creates a service per class whose id is the fully-qualified class name
19-
AppBundle\:
20-
resource: '../../src/AppBundle/*'
21-
# you can exclude directories or files
22-
# but if a service is unused, it's removed anyway
23-
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
24-
25-
# controllers are imported separately to make sure they're public
26-
# and have a tag that allows actions to type-hint services
27-
AppBundle\Controller\:
28-
resource: '../../src/AppBundle/Controller'
29-
public: true
30-
tags: ['controller.service_arguments']
31-
32-
jms_serializer.naming_strategy:
33-
alias: jms_serializer.identical_property_naming_strategy
34-
35-
# add more services, or override services that need manual wiring
36-
# AppBundle\Service\ExampleService:
37-
# arguments:
38-
# $someArgument: 'some_value'
39-
40-
AppBundle\Worker\:
41-
resource: '../../src/AppBundle/Worker'
42-
public: true
43-
tags:
44-
- {name: "dtc_queue.worker"}
45-
46-
47-
AppBundle\Service\LxdApi\:
48-
resource: '../../src/AppBundle/Service/LxdApi'
49-
arguments:
50-
$cert_location: '%cert_location%'
51-
$cert_key_location: '%cert_key_location%'
52-
$cert_passphrase: '%cert_passphrase%'
53-
54-
55-
AppBundle\Service\SSH\:
56-
resource: '../../src/AppBundle/Service/SSH'
57-
arguments:
58-
$ssh_location: '%ssh_location%'
59-
$ssh_key_location: '%ssh_key_location%'
60-
$ssh_user: '%ssh_user%'
61-
$ssh_passphrase: '%ssh_passphrase%'
62-
63-
AppBundle\Service\Restore\:
64-
resource: '../../src/AppBundle/Service/Restore'
65-
arguments:
66-
$ssh_location: '%ssh_location%'
67-
$ssh_key_location: '%ssh_key_location%'
68-
$ssh_user: '%ssh_user%'
69-
$ssh_passphrase: '%ssh_passphrase%'
70-
71-
AppBundle\Service\Backup\:
72-
resource: '../../src/AppBundle/Service/Backup'
73-
arguments:
74-
$ssh_location: '%ssh_location%'
75-
$ssh_key_location: '%ssh_key_location%'
76-
$ssh_user: '%ssh_user%'
77-
$ssh_passphrase: '%ssh_passphrase%'
78-
79-
AppBundle\Service\Profile\:
80-
resource: '../../src/AppBundle/Service/Profile'
81-
public: true
82-
arguments: [ "@doctrine.orm.entity_manager" ]
83-
84-
AppBundle\Service\Nagios\:
85-
resource: '../../src/AppBundle/Service/Nagios'
86-
arguments:
87-
$nagiosUsername: '%nagiosUsername%'
88-
$nagiosPassword: '%nagiosPassword%'
89-
90-
91-
platform.user.manager:
92-
class: Doctrine\ORM\EntityManager
93-
factory: ['@doctrine','getManagerForClass']
94-
arguments: ['AppBundle\Entity\User']
95-
platform.user.repository:
96-
class: AppBundle\Repository\UserRepository
97-
factory: ['@platform.user.manager','getRepository']
98-
arguments: ['AppBundle\Entity\User']
99-
platform.user.provider:
100-
class: AppBundle\Provider\UserProvider
101-
arguments: ['@platform.user.repository']
102-
103-
httpful_connection_exception.listener:
104-
class: AppBundle\EventListener\HttpfulConnectionExceptionListener
105-
tags:
106-
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
107-
108-
element_not_found_exception.listener:
109-
class: AppBundle\EventListener\ElementNotFoundExceptionListener
110-
tags:
111-
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
112-
113-
wrong_input_exception.listener:
114-
class: AppBundle\EventListener\WrongInputExceptionListener
115-
tags:
116-
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
117-
wrong_input_array_exception.listener:
118-
class: AppBundle\EventListener\WrongInputExceptionArrayListener
119-
tags:
120-
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
121-
122-
forbidden_exception.listener:
123-
class: AppBundle\EventListener\ForbiddenExceptionListener
124-
tags:
125-
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
126-
127-
runtime_exception.listener:
128-
class: AppBundle\EventListener\RuntimeExceptionListener
129-
tags:
130-
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
131-
132-
133-
Doctrine\ORM\EntityRepository:
134-
alias: platform.user.repository
135-
136-
dtc_grid.command.source.list:
137-
class: Dtc\GridBundle\Command\SourceListCommand
138-
tags:
139-
- { name: 'console.command' }
140-
dtc_grid.command.source.generate:
141-
class: Dtc\GridBundle\Command\GenerateGridSourceCommand
142-
tags:
143-
- { name: 'console.command' }
7+
# default configuration for services in *this* file
8+
_defaults:
9+
# automatically injects dependencies in your services
10+
autowire: true
11+
# automatically registers your services as commands, event subscribers, etc.
12+
autoconfigure: true
13+
# this means you cannot fetch services directly from the container via $container->get()
14+
# if you need to do this, you can override this setting on individual services
15+
public: false
16+
17+
# makes classes in src/AppBundle available to be used as services
18+
# this creates a service per class whose id is the fully-qualified class name
19+
AppBundle\:
20+
resource: "../../src/AppBundle/*"
21+
# you can exclude directories or files
22+
# but if a service is unused, it's removed anyway
23+
exclude: "../../src/AppBundle/{Entity,Repository,Tests}"
24+
25+
# controllers are imported separately to make sure they're public
26+
# and have a tag that allows actions to type-hint services
27+
AppBundle\Controller\:
28+
resource: "../../src/AppBundle/Controller"
29+
public: true
30+
tags: ["controller.service_arguments"]
31+
32+
jms_serializer.naming_strategy:
33+
alias: jms_serializer.identical_property_naming_strategy
34+
35+
# add more services, or override services that need manual wiring
36+
# AppBundle\Service\ExampleService:
37+
# arguments:
38+
# $someArgument: 'some_value'
39+
40+
AppBundle\Worker\:
41+
resource: "../../src/AppBundle/Worker"
42+
public: true
43+
tags:
44+
- { name: "dtc_queue.worker" }
45+
46+
AppBundle\Service\LxdApi\:
47+
resource: "../../src/AppBundle/Service/LxdApi"
48+
arguments:
49+
$cert_location: "%cert_location%"
50+
$cert_key_location: "%cert_key_location%"
51+
$cert_passphrase: "%cert_passphrase%"
52+
53+
AppBundle\Service\SSH\:
54+
resource: "../../src/AppBundle/Service/SSH"
55+
arguments:
56+
$ssh_location: "%ssh_location%"
57+
$ssh_key_location: "%ssh_key_location%"
58+
$ssh_user: "%ssh_user%"
59+
$ssh_passphrase: "%ssh_passphrase%"
60+
61+
AppBundle\Service\Restore\:
62+
resource: "../../src/AppBundle/Service/Restore"
63+
arguments:
64+
$ssh_location: "%ssh_location%"
65+
$ssh_key_location: "%ssh_key_location%"
66+
$ssh_user: "%ssh_user%"
67+
$ssh_passphrase: "%ssh_passphrase%"
68+
69+
AppBundle\Service\Backup\:
70+
resource: "../../src/AppBundle/Service/Backup"
71+
arguments:
72+
$ssh_location: "%ssh_location%"
73+
$ssh_key_location: "%ssh_key_location%"
74+
$ssh_user: "%ssh_user%"
75+
$ssh_passphrase: "%ssh_passphrase%"
76+
77+
AppBundle\Service\Profile\:
78+
resource: "../../src/AppBundle/Service/Profile"
79+
public: true
80+
arguments: ["@doctrine.orm.entity_manager"]
81+
82+
AppBundle\Service\Nagios\:
83+
resource: "../../src/AppBundle/Service/Nagios"
84+
arguments:
85+
$nagiosUsername: "%nagiosUsername%"
86+
$nagiosPassword: "%nagiosPassword%"
87+
88+
platform.user.manager:
89+
class: Doctrine\ORM\EntityManager
90+
factory: ["@doctrine", "getManagerForClass"]
91+
arguments: ['AppBundle\Entity\User']
92+
platform.user.repository:
93+
class: AppBundle\Repository\UserRepository
94+
factory: ["@platform.user.manager", "getRepository"]
95+
arguments: ['AppBundle\Entity\User']
96+
platform.user.provider:
97+
class: AppBundle\Provider\UserProvider
98+
arguments: ["@platform.user.repository"]
99+
100+
AppBundle\EventListener\:
101+
resource: "../../src/AppBundle/EventListener"
102+
tags:
103+
- {
104+
name: kernel.event_listener,
105+
event: kernel.exception,
106+
method: onKernelException,
107+
}
108+
109+
Doctrine\ORM\EntityRepository:
110+
alias: platform.user.repository
111+
112+
dtc_grid.command.source.list:
113+
class: Dtc\GridBundle\Command\SourceListCommand
114+
tags:
115+
- { name: "console.command" }
116+
dtc_grid.command.source.generate:
117+
class: Dtc\GridBundle\Command\GenerateGridSourceCommand
118+
tags:
119+
- { name: "console.command" }

src/AppBundle/Controller/BaseController.php

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Created by IntelliJ IDEA.
45
* User: leon
@@ -12,6 +13,10 @@
1213
use AppBundle\Exception\WrongInputExceptionArray;
1314
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1415
use Symfony\Component\HttpFoundation\Request;
16+
use Httpful\Response as HttpfulResponse;
17+
use AppBundle\Exception\LxdApiException;
18+
use AppBundle\Exception\LxdOpApiException;
19+
1520

1621
class BaseController extends Controller
1722
{
@@ -46,13 +51,12 @@ public function validation($object)
4651
* @return array
4752
* @throws WrongInputExceptionArray
4853
*/
49-
public function checkProfiles(Array $profiles, Array $profilesRequest)
54+
public function checkProfiles(array $profiles, array $profilesRequest)
5055
{
5156
$profilesDB = array();
5257
$profileNames = array();
5358

54-
foreach ($profiles as $profile)
55-
{
59+
foreach ($profiles as $profile) {
5660
$profilesDB[] = $profile->getId();
5761
$profileNames[] = $profile->getName();
5862
}
@@ -63,8 +67,7 @@ public function checkProfiles(Array $profiles, Array $profilesRequest)
6367
foreach ($errors as $error) {
6468
$errorArray[] = 'The profile with the id ' . $error . ' is not present in our database.';
6569
}
66-
if(count($errorArray) > 0)
67-
{
70+
if (count($errorArray) > 0) {
6871
throw new WrongInputExceptionArray($errorArray);
6972
}
7073
return $profileNames;
@@ -80,14 +83,61 @@ public function checkProfiles(Array $profiles, Array $profilesRequest)
8083
*/
8184
public function checkForNeededFields(Request $request, $neededFields)
8285
{
83-
foreach ($neededFields as $fieldName)
84-
{
85-
if(!$request->request->has($fieldName))
86-
{
86+
foreach ($neededFields as $fieldName) {
87+
if (!$request->request->has($fieldName)) {
8788
throw new WrongInputExceptionArray(
8889
[$fieldName => "This field is required"]
8990
);
9091
}
9192
}
9293
}
94+
95+
/**
96+
* Checks if the response has any errors
97+
* @param HttpfulResponse $response
98+
* @throws LxdApiException
99+
*/
100+
public function checkForErrors(HttpfulResponse $response)
101+
{
102+
if ($response->code !== 202 && $response->code !== 200) {
103+
if ($response->body->metadata) {
104+
if ($response->body->metadata->status_code !== 200 && $response->body->metadata->status_code !== 103) {
105+
throw new LxdApiException(
106+
$response->body->metadata->err,
107+
$response->body->metadata->status_code
108+
);
109+
}
110+
}
111+
throw new LxdApiException(
112+
$response->body->error,
113+
$response->code
114+
);
115+
}
116+
}
117+
118+
119+
/**
120+
* Checks if the operation response has any errors
121+
* @param HttpfulResponse $response
122+
* @throws LxdApiException
123+
*/
124+
public function checkForErrorsInOps(HttpfulResponse $response)
125+
{
126+
if ($response->code !== 200) {
127+
throw new LxdApiException(
128+
$response->body->error,
129+
$response->code
130+
);
131+
132+
}
133+
if ($response->body->metadata) {
134+
if ($response->body->metadata->status_code !== 200 && $response->body->metadata->status_code !== 103) {
135+
throw new LxdOpApiException(
136+
$response->body->metadata->err,
137+
$response->body->metadata->status_code,
138+
$response->body->metadata->description
139+
);
140+
}
141+
}
142+
}
93143
}

src/AppBundle/Controller/ContainerController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ public function showSingleAction(Request $request, int $containerId, ContainerAp
571571

572572
$result = $api->show($container->getHost(), $container->getName());
573573

574+
$this->checkForErrors($result);
575+
574576
$container->setArchitecture($result->body->metadata->architecture);
575577
$container->setConfig($result->body->metadata->config);
576578
$container->setDevices($result->body->metadata->devices);
@@ -586,6 +588,8 @@ public function showSingleAction(Request $request, int $containerId, ContainerAp
586588
$this->validation($container);
587589
$em->flush();
588590
}
591+
592+
$em->refresh($container);
589593
$serializer = $this->get('jms_serializer');
590594
$response = $serializer->serialize($container, 'json');
591595
return new Response($response);
@@ -746,11 +750,7 @@ public function updateAction(Request $request, int $containerId, EntityManagerIn
746750
if ($request->request->has("name")) {
747751
if ($container->getName() != $request->get("name")) {
748752

749-
$data = ["name" => $request->get("name")];
750-
751-
$container->setDataBody($data);
752-
$em->flush($container);
753-
$containerWorker->later()->renameContainer($container);
753+
$containerWorker->later()->renameContainer($container->getId(), $request->get("name"));
754754
} else {
755755
throw new WrongInputExceptionArray(["name" => "The new name is same as current name."]);
756756
}

0 commit comments

Comments
 (0)